source: trunk/package/ppp/files/ppp.sh @ 19093

Last change on this file since 19093 was 19093, checked in by jow, 7 years ago

[package] ppp: process option dns if peerdns is off (#6474)

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1scan_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
18start_pppd() {
19        local cfg="$1"; shift
20        local ifname
21
22        # make sure the network state references the correct ifname
23        scan_ppp "$cfg"
24        config_get ifname "$cfg" ifname
25        set_interface_ifname "$cfg" "$ifname"
26
27        # make sure only one pppd process is started
28        lock "/var/lock/ppp-${cfg}"
29        local pid="$(head -n1 /var/run/ppp-${cfg}.pid 2>/dev/null)"
30        [ -d "/proc/$pid" ] && grep pppd "/proc/$pid/cmdline" 2>/dev/null >/dev/null && {
31                lock -u "/var/lock/ppp-${cfg}"
32                return 0
33        }
34
35        # Workaround: sometimes hotplug2 doesn't deliver the hotplug event for creating
36        # /dev/ppp fast enough to be used here
37        [ -e /dev/ppp ] || mknod /dev/ppp c 108 0
38
39        config_get device "$cfg" device
40        config_get unit "$cfg" unit
41        config_get username "$cfg" username
42        config_get password "$cfg" password
43        config_get keepalive "$cfg" keepalive
44
45        config_get connect "$cfg" connect
46        config_get disconnect "$cfg" disconnect
47        config_get pppd_options "$cfg" pppd_options
48        config_get_bool defaultroute "$cfg" defaultroute 1
49        [ "$defaultroute" -eq 1 ] && defaultroute="defaultroute replacedefaultroute" || defaultroute=""
50
51        interval="${keepalive##*[, ]}"
52        [ "$interval" != "$keepalive" ] || interval=5
53
54        config_get_bool peerdns "$cfg" peerdns 1
55        [ "$peerdns" -eq 1 ] && peerdns="usepeerdns" || {
56                peerdns=""
57                config_get dns "$config" dns
58                for dns in $dns; do
59                        grep -q "$dns" /tmp/resolv.conf.auto 2>/dev/null || \
60                                echo "nameserver $dns" >> /tmp/resolv.conf.auto
61                done
62        }
63
64        config_get demand "$cfg" demand
65        [ -n "$demand" ] && echo "nameserver 1.1.1.1" > /tmp/resolv.conf.auto
66
67        config_get_bool ipv6 "$cfg" ipv6 0
68        [ "$ipv6" -eq 1 ] && ipv6="+ipv6" || ipv6=""
69
70        /usr/sbin/pppd "$@" \
71                ${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}} \
72                ${demand:+precompiled-active-filter /etc/ppp/filter demand idle }${demand:-persist} \
73                $peerdns \
74                $defaultroute \
75                ${username:+user "$username" password "$password"} \
76                unit "$unit" \
77                linkname "$cfg" \
78                ipparam "$cfg" \
79                ${connect:+connect "$connect"} \
80                ${disconnect:+disconnect "$disconnect"} \
81                ${ipv6} \
82                ${pppd_options}
83
84        lock -u "/var/lock/ppp-${cfg}"
85}
86
87setup_interface_ppp() {
88        local iface="$1"
89        local config="$2"
90
91        config_get device "$config" device
92
93        config_get mtu "$config" mtu
94        mtu=${mtu:-1492}
95        start_pppd "$config" \
96                mtu $mtu mru $mtu \
97                "$device"
98}
99
Note: See TracBrowser for help on using the repository browser.