[lantiq]
[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 # Workaround for PPPoE service and AC name options,
20 # filter out the nic-* argument and append it as last option
21 local nic=""
22 case "$1" in
23 nic-*) nic="$1"; shift ;;
24 esac
25
26 local proto
27 config_get proto "$cfg" proto
28
29 # unique link identifier
30 local link="${proto:-ppp}-$cfg"
31
32 # make sure only one pppd process is started
33 lock "/var/lock/ppp-${link}"
34 local pid="$(head -n1 /var/run/ppp-${link}.pid 2>/dev/null)"
35 [ -d "/proc/$pid" ] && grep pppd "/proc/$pid/cmdline" 2>/dev/null >/dev/null && {
36 lock -u "/var/lock/ppp-${link}"
37 return 0
38 }
39
40 # Workaround: sometimes hotplug2 doesn't deliver the hotplug event for creating
41 # /dev/ppp fast enough to be used here
42 [ -e /dev/ppp ] || mknod /dev/ppp c 108 0
43
44 local device
45 config_get device "$cfg" device
46
47 local username
48 config_get username "$cfg" username
49
50 local password
51 config_get password "$cfg" password
52
53 local keepalive
54 config_get keepalive "$cfg" keepalive
55
56 local connect
57 config_get connect "$cfg" connect
58
59 local disconnect
60 config_get disconnect "$cfg" disconnect
61
62 local pppd_options
63 config_get pppd_options "$cfg" pppd_options
64
65 local defaultroute
66 config_get_bool defaultroute "$cfg" defaultroute 1
67 [ "$defaultroute" -eq 1 ] && \
68 defaultroute="defaultroute replacedefaultroute" || defaultroute="nodefaultroute"
69
70 local interval="${keepalive##*[, ]}"
71 [ "$interval" != "$keepalive" ] || interval=5
72
73 local dns
74 config_get dns "$config" dns
75
76 local has_dns=0
77 local peer_default=1
78 [ -n "$dns" ] && {
79 has_dns=1
80 peer_default=0
81 }
82
83 local peerdns
84 config_get_bool peerdns "$cfg" peerdns $peer_default
85
86 [ "$peerdns" -eq 1 ] && {
87 peerdns="usepeerdns"
88 } || {
89 peerdns=""
90 add_dns "$cfg" $dns
91 }
92
93 local demand
94 config_get demand "$cfg" demand 0
95
96 local demandargs
97 [ "$demand" -gt 0 ] && {
98 demandargs="precompiled-active-filter /etc/ppp/filter demand idle $demand"
99 [ "$has_dns" -eq 0 ] && add_dns "$cfg" 1.1.1.1
100 } || {
101 demandargs="persist"
102 }
103
104 local ipv6
105 config_get_bool ipv6 "$cfg" ipv6 0
106 [ "$ipv6" -eq 1 ] && ipv6="+ipv6" || ipv6=""
107
108 start-stop-daemon -S -b -x /usr/sbin/pppd -m -p /var/run/ppp-$link.pid -- "$@" \
109 ${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}} \
110 $demandargs \
111 $peerdns \
112 $defaultroute \
113 ${username:+user "$username" password "$password"} \
114 ipparam "$cfg" \
115 ifname "$link" \
116 ${connect:+connect "$connect"} \
117 ${disconnect:+disconnect "$disconnect"} \
118 ${ipv6} \
119 ${pppd_options} \
120 nodetach \
121 ${nic}
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.05716 seconds and 5 git commands to generate.