mac80211: b43: Expose PIO mode fallback
[openwrt.git] / package / ppp / files / ppp.sh
1 stop_interface_ppp() {
2 local cfg="$1"
3
4 local proto
5 config_get proto "$cfg" proto
6
7 local link="$proto-$cfg"
8 service_kill pppd "/var/run/ppp-${link}.pid"
9
10 remove_dns "$cfg"
11
12 local lock="/var/lock/ppp-$link"
13 [ -f "$lock" ] && lock -u "$lock"
14 }
15
16 start_pppd() {
17 local cfg="$1"; shift
18
19 local proto
20 config_get proto "$cfg" proto
21
22 # unique link identifier
23 local link="${proto:-ppp}-$cfg"
24
25 # make sure only one pppd process is started
26 lock "/var/lock/ppp-${link}"
27 local pid="$(head -n1 /var/run/ppp-${link}.pid 2>/dev/null)"
28 [ -d "/proc/$pid" ] && grep pppd "/proc/$pid/cmdline" 2>/dev/null >/dev/null && {
29 lock -u "/var/lock/ppp-${link}"
30 return 0
31 }
32
33 # Workaround: sometimes hotplug2 doesn't deliver the hotplug event for creating
34 # /dev/ppp fast enough to be used here
35 [ -e /dev/ppp ] || mknod /dev/ppp c 108 0
36
37 local device
38 config_get device "$cfg" device
39
40 local username
41 config_get username "$cfg" username
42
43 local password
44 config_get password "$cfg" password
45
46 local keepalive
47 config_get keepalive "$cfg" keepalive
48
49 local connect
50 config_get connect "$cfg" connect
51
52 local disconnect
53 config_get disconnect "$cfg" disconnect
54
55 local pppd_options
56 config_get pppd_options "$cfg" pppd_options
57
58 local defaultroute
59 config_get_bool defaultroute "$cfg" defaultroute 1
60 [ "$defaultroute" -eq 1 ] && \
61 defaultroute="defaultroute replacedefaultroute" || defaultroute="nodefaultroute"
62
63 local interval="${keepalive##*[, ]}"
64 [ "$interval" != "$keepalive" ] || interval=5
65
66 local dns
67 config_get dns "$config" dns
68
69 local has_dns=0
70 local peer_default=1
71 [ -n "$dns" ] && {
72 has_dns=1
73 peer_default=0
74 }
75
76 local peerdns
77 config_get_bool peerdns "$cfg" peerdns $peer_default
78
79 [ "$peerdns" -eq 1 ] && {
80 peerdns="usepeerdns"
81 } || {
82 peerdns=""
83 add_dns "$cfg" $dns
84 }
85
86 local demand
87 config_get demand "$cfg" demand 0
88
89 local demandargs
90 [ "$demand" -gt 0 ] && {
91 demandargs="precompiled-active-filter /etc/ppp/filter demand idle $demand"
92 [ "$has_dns" -eq 0 ] && add_dns "$cfg" 1.1.1.1
93 } || {
94 demandargs="persist"
95 }
96
97 local ipv6
98 config_get_bool ipv6 "$cfg" ipv6 0
99 [ "$ipv6" -eq 1 ] && ipv6="+ipv6" || ipv6=""
100
101 start-stop-daemon -S -b -x /usr/sbin/pppd -m -p /var/run/ppp-$link.pid -- "$@" \
102 ${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}} \
103 $demandargs \
104 $peerdns \
105 $defaultroute \
106 ${username:+user "$username" password "$password"} \
107 ipparam "$cfg" \
108 ifname "$link" \
109 ${connect:+connect "$connect"} \
110 ${disconnect:+disconnect "$disconnect"} \
111 ${ipv6} \
112 ${pppd_options} \
113 nodetach
114
115 lock -u "/var/lock/ppp-${link}"
116 }
117
118 setup_interface_ppp() {
119 local iface="$1"
120 local config="$2"
121
122 local device
123 config_get device "$config" device
124
125 local mtu
126 config_get mtu "$config" mtu
127
128 mtu=${mtu:-1492}
129 start_pppd "$config" \
130 mtu $mtu mru $mtu \
131 "$device"
132 }
133
This page took 0.049122 seconds and 5 git commands to generate.