2012-05-03 09:39:01 +00:00
|
|
|
find_route() {
|
|
|
|
ip route get $1 | sed -e 's/ /\n/g' | \
|
|
|
|
sed -ne '1p;/via/{N;p};/dev/{N;p};/src/{N;p};/mtu/{N;p}'
|
2008-04-07 01:07:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 00:30:09 +00:00
|
|
|
scan_pptp() {
|
|
|
|
config_set "$1" device "pptp-$1"
|
|
|
|
}
|
|
|
|
|
2010-05-01 17:55:41 +00:00
|
|
|
stop_interface_pptp() {
|
|
|
|
stop_interface_ppp "$1"
|
2011-07-17 22:42:29 +00:00
|
|
|
for ip in $(uci_get_state network "$1" serv_addrs); do
|
2012-05-03 09:39:01 +00:00
|
|
|
ip route del "$ip" 2>/dev/null
|
2011-07-17 22:42:29 +00:00
|
|
|
done
|
2010-05-01 17:55:41 +00:00
|
|
|
}
|
2008-04-07 01:07:50 +00:00
|
|
|
|
2010-05-06 19:51:27 +00:00
|
|
|
coldplug_interface_pptp() {
|
|
|
|
setup_interface_pptp "pptp-$1" "$1"
|
|
|
|
}
|
|
|
|
|
2006-09-23 18:01:51 +00:00
|
|
|
setup_interface_pptp() {
|
2006-07-30 03:09:09 +00:00
|
|
|
local config="$2"
|
2007-08-30 16:53:22 +00:00
|
|
|
local ifname
|
2010-05-06 19:51:27 +00:00
|
|
|
|
2010-05-24 16:28:46 +00:00
|
|
|
local device
|
2006-07-30 03:09:09 +00:00
|
|
|
config_get device "$config" device
|
2010-05-24 16:28:46 +00:00
|
|
|
|
|
|
|
local server
|
2009-03-15 12:08:31 +00:00
|
|
|
config_get server "$config" server
|
2006-07-30 03:09:09 +00:00
|
|
|
|
2010-05-24 16:28:46 +00:00
|
|
|
local buffering
|
|
|
|
config_get_bool buffering "$config" buffering 1
|
|
|
|
[ "$buffering" == 0 ] && buffering="--nobuffer" || buffering=
|
|
|
|
|
2006-07-30 03:09:09 +00:00
|
|
|
for module in slhc ppp_generic ppp_async ip_gre; do
|
|
|
|
/sbin/insmod $module 2>&- >&-
|
|
|
|
done
|
2007-08-30 16:53:22 +00:00
|
|
|
sleep 1
|
|
|
|
|
2012-05-03 09:39:01 +00:00
|
|
|
local serv_addrs=""
|
|
|
|
for ip in $(resolveip -t 3 "${server}"); do
|
|
|
|
append serv_addrs "$ip"
|
|
|
|
ip route replace $(find_route $ip)
|
|
|
|
done
|
|
|
|
uci_toggle_state network "$config" serv_addrs "$serv_addrs"
|
|
|
|
}
|
2007-08-30 16:53:22 +00:00
|
|
|
|
|
|
|
# fix up the netmask
|
|
|
|
config_get netmask "$config" netmask
|
|
|
|
[ -z "$netmask" -o -z "$device" ] || ifconfig $device netmask $netmask
|
|
|
|
|
2009-03-15 13:40:11 +00:00
|
|
|
config_get mtu "$config" mtu
|
2006-07-30 03:09:09 +00:00
|
|
|
mtu=${mtu:-1452}
|
|
|
|
start_pppd "$config" \
|
2010-05-24 16:28:46 +00:00
|
|
|
pty "/usr/sbin/pptp $server --loglevel 0 --nolaunchpppd $buffering" \
|
2007-04-21 20:19:54 +00:00
|
|
|
file /etc/ppp/options.pptp \
|
2006-09-23 18:01:51 +00:00
|
|
|
mtu $mtu mru $mtu
|
2006-07-30 03:09:09 +00:00
|
|
|
}
|