#!/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 cmd_run "ip-route" "ip route add table ${RTABLE} ${ROUTE}" "-nolog" 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}" }