c95895d9fa7c0d746537eaa54fdc5cdda16211b7
[openwrt/svn-archive/archive.git] / package / pptp / files / pptp.sh
1 find_gw() {
2 route -n | awk '$1 == "0.0.0.0" { print $2; exit }'
3 }
4
5 stop_interface_pptp() {
6 stop_interface_ppp "$1"
7 }
8
9 coldplug_interface_pptp() {
10 setup_interface_pptp "pptp-$1" "$1"
11 }
12
13 setup_interface_pptp() {
14 local config="$2"
15 local ifname
16
17 local device
18 config_get device "$config" device
19
20 local ipproto
21 config_get ipproto "$config" ipproto
22
23 local server
24 config_get server "$config" server
25
26 local buffering
27 config_get_bool buffering "$config" buffering 1
28 [ "$buffering" == 0 ] && buffering="--nobuffer" || buffering=
29
30 for module in slhc ppp_generic ppp_async ip_gre; do
31 /sbin/insmod $module 2>&- >&-
32 done
33 sleep 1
34
35 setup_interface "$device" "$config" "${ipproto:-dhcp}"
36 local gw="$(find_gw)"
37 [ -n "$gw" ] && {
38 [ "$gw" != 0.0.0.0 ] && route delete "$server" 2>/dev/null >/dev/null
39 route add "$server" gw "$gw"
40 }
41
42 # fix up the netmask
43 config_get netmask "$config" netmask
44 [ -z "$netmask" -o -z "$device" ] || ifconfig $device netmask $netmask
45
46 config_get mtu "$config" mtu
47 mtu=${mtu:-1452}
48 start_pppd "$config" \
49 pty "/usr/sbin/pptp $server --loglevel 0 --nolaunchpppd $buffering" \
50 file /etc/ppp/options.pptp \
51 mtu $mtu mru $mtu
52 }