uclibc 0.9.29: fix isinf, finite prototypes
[openwrt.git] / package / ppp / files / ppp.sh
1 scan_ppp() {
2 config_get ifname "$1" ifname
3 pppdev="${pppdev:-0}"
4 config_get unit "$1" unit
5 [ -z "$unit" ] && {
6 unit="$pppdev"
7 if [ "${ifname%%[0-9]*}" = ppp ]; then
8 unit="${ifname##ppp}"
9 [ "$pppdev" -le "$unit" ] && pppdev="$(($unit + 1))"
10 else
11 pppdev="$(($pppdev + 1))"
12 fi
13 config_set "$1" ifname "ppp$unit"
14 config_set "$1" unit "$unit"
15 }
16 }
17
18 start_pppd() {
19 local cfg="$1"; shift
20
21 # make sure only one pppd process is started
22 lock "/var/lock/ppp-${cfg}"
23 local pid="$(head -n1 /var/run/ppp-${cfg}.pid 2>/dev/null)"
24 [ -d "/proc/$pid" ] && grep pppd "/proc/$pid/cmdline" 2>/dev/null >/dev/null && {
25 lock -u "/var/lock/ppp-${cfg}"
26 return 0
27 }
28
29 # Workaround: sometimes hotplug2 doesn't deliver the hotplug event for creating
30 # /dev/ppp fast enough to be used here
31 [ -e /dev/ppp ] || mknod /dev/ppp c 108 0
32
33 config_get device "$cfg" device
34 config_get unit "$cfg" unit
35 config_get username "$cfg" username
36 config_get password "$cfg" password
37 config_get keepalive "$cfg" keepalive
38
39 config_get connect "$cfg" connect
40 config_get disconnect "$cfg" disconnect
41 config_get pppd_options "$cfg" pppd_options
42 config_get_bool defaultroute "$cfg" defaultroute 1
43 [ "$defaultroute" -eq 1 ] && defaultroute="defaultroute replacedefaultroute" || defaultroute=""
44
45 interval="${keepalive##*[, ]}"
46 [ "$interval" != "$keepalive" ] || interval=5
47
48 config_get_bool peerdns "$cfg" peerdns 1
49 [ "$peerdns" -eq 1 ] && peerdns="usepeerdns" || peerdns=""
50
51 config_get demand "$cfg" demand
52 [ -n "$demand" ] && echo "nameserver 1.1.1.1" > /tmp/resolv.conf.auto
53
54 config_get_bool ipv6 "$cfg" ipv6 0
55 [ "$ipv6" -eq 1 ] && ipv6="+ipv6" || ipv6=""
56
57 /usr/sbin/pppd "$@" \
58 ${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}} \
59 ${demand:+precompiled-active-filter /etc/ppp/filter demand idle }${demand:-persist} \
60 $peerdns \
61 $defaultroute \
62 ${username:+user "$username" password "$password"} \
63 unit "$unit" \
64 linkname "$cfg" \
65 ipparam "$cfg" \
66 ${connect:+connect "$connect"} \
67 ${disconnect:+disconnect "$disconnect"} \
68 ${ipv6} \
69 ${pppd_options}
70
71 lock -u "/var/lock/ppp-${cfg}"
72 }
73
74 setup_interface_ppp() {
75 local iface="$1"
76 local config="$2"
77
78 config_get device "$config" device
79
80 config_get mtu "$config" mtu
81 mtu=${mtu:-1492}
82 start_pppd "$config" \
83 mtu $mtu mru $mtu \
84 "$device"
85 }
86
This page took 0.048929 seconds and 5 git commands to generate.