123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #!/bin/sh
- source /jffs/scripts/aiop/aiop-func
- route_vpn () {
- IFACE="${1}"
- IFACE_TUN="${2}"
- if [ `ifconfig ${IFACE_TUN} 2&> /dev/null | grep -ice "UP"` -ne 1 ]; then
- logger "openvpn: ${IFACE_TUN} not UP"
- return
- fi
- if [ `ifconfig ${IFACE} 2&> /dev/null | grep -ice "UP"` -ne 1 ]; then
- logger "dnsmasq-dhcp: Unknown interface ${IFACE}."
- return
- fi
- IFACE_INET_ADDR="$(ifconfig "${IFACE}" | sed -ne's/.*inet addr:\([^ ]*\).*$/\1/p')"
- IFACE_NWRK_ADDR="${IFACE_INET_ADDR%.*}.0"
- RTABLE=`echo ${IFACE_TUN} | sed -E 's/([a-z]+)([0-9]+).*/\2/'`
- CIDR=24
- if [ $# -eq 3 ]; then
- CIDR="${3}"
- fi
- ip route show table main | grep -Ev ^default | while read ROUTE; do
- # Remote interface != ${IFACE_TUN} && != ${IFACE} entries from this table.
- if [ $(echo "${ROUTE}" | grep -ice "tun") -eq 0 ] || [ $(echo "${ROUTE}" | grep -ice "${IFACE_TUN}") -ne 0 ]; then
- if [ $(echo "${ROUTE}" | grep -icE "wl[0-9]\.[0-9]") -eq 0 ] || [ $(echo "${ROUTE}" | grep -ice "${IFACE}") -ne 0 ]; then
- cmd_run "ip-route" "ip route add table ${RTABLE} ${ROUTE}" "-nolog"
- fi
- fi
- done
-
- cmd_run "ip-route" "ip route add default dev ${IFACE_TUN} table ${RTABLE}"
- cmd_run "ip-rule" "ip rule add dev ${IFACE} table ${RTABLE}"
- cmd_run "ip-route" "ip route flush cache"
-
- iptable "${IFACE}" "I" "FORWARD" "ACCEPT" "${IFACE_TUN}"
- iptable "${IFACE_TUN}" "I" "${IFACE_NWRK_ADDR}/${CIDR}"
- }
- unroute_vpn () {
- IFACE="${1}"
- IFACE_TUN="${2}"
- if [ `ifconfig ${IFACE} 2&> /dev/null | grep -ice "UP"` -ne 1 ]; then
- logger "dnsmasq-dhcp: Unknown interface ${IFACE}."
- return
- fi
- IFACE_INET_ADDR="$(ifconfig "${IFACE}" | sed -ne's/.*inet addr:\([^ ]*\).*$/\1/p')"
- IFACE_NWRK_ADDR="${IFACE_INET_ADDR%.*}.0"
- RTABLE=`echo ${IFACE_TUN} | sed -E 's/([a-z]+)([0-9]+).*/\2/'`
- CIDR=24
- if [ $# -eq 3 ]; then
- CIDR="${3}"
- fi
- cmd_run "ip-route" "ip route flush table ${RTABLE}" "-nolog"
- iptable "${IFACE}" "D" "FORWARD" "ACCEPT" "${IFACE_TUN}"
- iptable "${IFACE_TUN}" "D" "${IFACE_NWRK_ADDR}/${CIDR}"
- }
|