add pppd options patch from #2114
[openwrt/staging/mkresin.git] / package / ppp / files / ppp.sh
1 scan_ppp() {
2 config_get ifname "$1" ifname
3 pppdev="${pppdev:-0}"
4 config_set "$1" ifname "ppp$pppdev"
5 config_set "$1" unit "$pppdev"
6 }
7
8 start_pppd() {
9 local cfg="$1"; shift
10
11 # make sure only one pppd process is started
12 lock "/var/lock/ppp-${cfg}"
13 local pid="$(head -n1 /var/run/ppp-${cfg}.pid 2>/dev/null)"
14 [ -d "/proc/$pid" ] && grep pppd "/proc/$pid/cmdline" 2>/dev/null >/dev/null && {
15 lock -u "/var/lock/ppp-${cfg}"
16 return 0
17 }
18
19 config_get device "$cfg" device
20 config_get unit "$cfg" unit
21 config_get username "$cfg" username
22 config_get password "$cfg" password
23 config_get keepalive "$cfg" keepalive
24
25 config_get connect "$cfg" connect
26 config_get disconnect "$cfg" disconnect
27 config_get pppd_options "$cfg" pppd_options
28
29 interval="${keepalive##*[, ]}"
30 [ "$interval" != "$keepalive" ] || interval=5
31
32 config_get demand "$cfg" demand
33 [ -n "$demand" ] && echo "nameserver 1.1.1.1" > /tmp/resolv.conf.auto
34 /usr/sbin/pppd "$@" \
35 ${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}} \
36 ${demand:+precompiled-active-filter /etc/ppp/filter demand idle }${demand:-persist} \
37 usepeerdns \
38 defaultroute \
39 replacedefaultroute \
40 ${username:+user "$username" password "$password"} \
41 linkname "$cfg" \
42 ipparam "$cfg" \
43 ${connect:+connect "$connect"} \
44 ${disconnect:+disconnect "$disconnect"} \
45 ${pppd_options}
46
47 lock -u "/var/lock/ppp-${cfg}"
48 }
49
50 setup_interface_ppp() {
51 local iface="$1"
52 local config="$2"
53
54 config_get device "$config" device
55
56 config_get mtu "$cfg" mtu
57 mtu=${mtu:-1492}
58 start_pppd "$config" \
59 mtu $mtu mru $mtu \
60 "$device"
61 }
62