5eb007da1fe367b7a67c59d15f50ef5a2fba9924
[openwrt/svn-archive/archive.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 # set 'auto' to 0, so that hotplug does not attempt to
8 # reconfigure an interface that is managed by pppd
9 config_set "$1" auto 0
10 }
11
12 start_pppd() {
13 local cfg="$1"; shift
14
15 # make sure only one pppd process is started
16 lock "/var/lock/ppp-${cfg}"
17 local pid="$(head -n1 /var/run/ppp-${cfg}.pid 2>/dev/null)"
18 [ -d "/proc/$pid" ] && grep pppd "/proc/$pid/cmdline" 2>/dev/null >/dev/null && {
19 lock -u "/var/lock/ppp-${cfg}"
20 return 0
21 }
22
23 config_get device "$cfg" device
24 config_get unit "$cfg" unit
25 config_get username "$cfg" username
26 config_get password "$cfg" password
27 config_get keepalive "$cfg" keepalive
28 interval="${keepalive##*[, ]}"
29 [ "$interval" != "$keepalive" ] || interval=5
30
31 config_get demand "$cfg" demand
32 [ -n "$demand" ] && echo "nameserver 1.1.1.1" > /tmp/resolv.conf.auto
33 /usr/sbin/pppd "$@" \
34 ${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}} \
35 ${demand:+precompiled-active-filter /etc/ppp/filter demand idle }${demand:-persist} \
36 usepeerdns \
37 defaultroute \
38 replacedefaultroute \
39 ${username:+user "$username" password "$password"} \
40 linkname "$cfg" \
41 ipparam "$cfg"
42
43 lock -u "/var/lock/ppp-${cfg}"
44 }