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