12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #!/bin/sh
- source /jffs/scripts/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
- if [ `ip route show table "${RTABLE}" | grep -ice "${ROUTE}"` -eq 0 ]; then
- cmd_run "ip-route" "ip route add table ${RTABLE} ${ROUTE}"
- 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}"
- cmd_run "ip-rule" "ip rule flush table ${RTABLE}"
- iptable "${IFACE}" "D" "FORWARD" "ACCEPT" "${IFACE_TUN}"
- iptable "${IFACE_TUN}" "D" "${IFACE_NWRK_ADDR}/${CIDR}"
- }
|