3 [ -x /usr
/sbin
/pppd
] ||
exit 0
5 [ -n "$INCLUDE_ONLY" ] ||
{
7 .
/lib
/functions
/network.sh
18 for subnet
in $subnets; do
19 local addr
="${subnet%%/*}"
20 local mask
="${subnet#*/}"
22 if [ -n "$res_mask" -a "$mask" != 32 ]; then
23 [ "$mask" -gt "$res_mask" ] ||
[ "$res_mask" = 32 ] && {
27 elif [ -z "$res_mask" ]; then
36 ppp_exitcode_tostring
()
39 [ -n "$errorcode" ] || errorcode
=5
43 1) echo "FATAL_ERROR" ;;
44 2) echo "OPTION_ERROR" ;;
46 4) echo "NO_KERNEL_SUPPORT" ;;
47 5) echo "USER_REQUEST" ;;
48 6) echo "LOCK_FAILED" ;;
49 7) echo "OPEN_FAILED" ;;
50 8) echo "CONNECT_FAILED" ;;
51 9) echo "PTYCMD_FAILED" ;;
52 10) echo "NEGOTIATION_FAILED" ;;
53 11) echo "PEER_AUTH_FAILED" ;;
54 12) echo "IDLE_TIMEOUT" ;;
55 13) echo "CONNECT_TIME" ;;
56 14) echo "CALLBACK" ;;
57 15) echo "PEER_DEAD" ;;
59 17) echo "LOOPBACK" ;;
60 18) echo "INIT_FAILED" ;;
61 19) echo "AUTH_TOPEER_FAILED" ;;
62 20) echo "TRAFFIC_LIMIT" ;;
63 21) echo "CNID_AUTH_FAILED";;
64 *) echo "UNKNOWN_ERROR" ;;
68 ppp_generic_init_config
() {
69 proto_config_add_string username
70 proto_config_add_string password
71 proto_config_add_string keepalive
72 proto_config_add_boolean keepalive_adaptive
73 proto_config_add_int demand
74 proto_config_add_string pppd_options
75 proto_config_add_string
'connect:file'
76 proto_config_add_string
'disconnect:file'
77 proto_config_add_string ipv6
78 proto_config_add_boolean authfail
79 proto_config_add_int mtu
80 proto_config_add_string pppname
81 proto_config_add_string unnumbered
82 proto_config_add_boolean persist
83 proto_config_add_int maxfail
84 proto_config_add_int holdoff
88 local config
="$1"; shift
91 json_get_vars ipv6 ip6table demand keepalive keepalive_adaptive username password pppd_options pppname unnumbered persist maxfail holdoff peerdns
92 if [ "$ipv6" = 0 ]; then
94 elif [ -z "$ipv6" -o "$ipv6" = auto
]; then
99 if [ "${demand:-0}" -gt 0 ]; then
100 demand
="precompiled-active-filter /etc/ppp/filter demand idle $demand"
104 if [ -n "$persist" ]; then
105 [ "${persist}" -lt 1 ] && persist
="nopersist" || persist
="persist"
107 if [ -z "$maxfail" ]; then
108 [ "$persist" = "persist" ] && maxfail
=0 || maxfail
=1
110 [ -n "$mtu" ] || json_get_var mtu mtu
111 [ -n "$pppname" ] || pppname
="${proto:-ppp}-$config"
112 [ -n "$unnumbered" ] && {
114 ( proto_add_host_dependency
"$config" "" "$unnumbered" )
115 network_get_subnets subnets
"$unnumbered"
116 localip
=$
(ppp_select_ipaddr
"$subnets")
117 [ -n "$localip" ] ||
{
118 proto_block_restart
"$config"
123 local lcp_failure
="${keepalive%%[, ]*}"
124 local lcp_interval
="${keepalive##*[, ]}"
125 local lcp_adaptive
="lcp-echo-adaptive"
126 [ "${lcp_failure:-0}" -lt 1 ] && lcp_failure
=""
127 [ "$lcp_interval" != "$keepalive" ] || lcp_interval
=5
128 [ "${keepalive_adaptive:-1}" -lt 1 ] && lcp_adaptive
=""
129 [ -n "$connect" ] || json_get_var connect connect
130 [ -n "$disconnect" ] || json_get_var disconnect disconnect
132 proto_run_command
"$config" /usr
/sbin
/pppd \
133 nodetach ipparam
"$config" \
135 ${localip:+$localip:} \
136 ${lcp_failure:+lcp-echo-interval $lcp_interval lcp-echo-failure $lcp_failure $lcp_adaptive} \
138 ${autoipv6:+set AUTOIPV6=1} \
139 ${ip6table:+set IP6TABLE=$ip6table} \
140 ${peerdns:+set PEERDNS=$peerdns} \
143 $demand $persist maxfail
$maxfail \
144 ${holdoff:+holdoff "$holdoff"} \
145 ${username:+user "$username" password "$password"} \
146 ${connect:+connect "$connect"} \
147 ${disconnect:+disconnect "$disconnect"} \
148 ip-up-script
/lib
/netifd
/ppp-up \
149 ipv6-up-script
/lib
/netifd
/ppp6-up \
150 ip-down-script
/lib
/netifd
/ppp-down \
151 ipv6-down-script
/lib
/netifd
/ppp-down \
152 ${mtu:+mtu $mtu mru $mtu} \
156 ppp_generic_teardown
() {
158 local errorstring
=$
(ppp_exitcode_tostring
$ERROR)
164 proto_notify_error
"$interface" "$errorstring"
165 proto_block_restart
"$interface"
168 json_get_var authfail authfail
169 proto_notify_error
"$interface" "$errorstring"
170 if [ "${authfail:-0}" -gt 0 ]; then
171 proto_block_restart
"$interface"
175 proto_notify_error
"$interface" "$errorstring"
179 proto_kill_command
"$interface"
182 # PPP on serial device
184 proto_ppp_init_config
() {
185 proto_config_add_string
"device"
186 ppp_generic_init_config
195 json_get_var device device
196 ppp_generic_setup
"$config" "$device"
199 proto_ppp_teardown
() {
200 ppp_generic_teardown
"$@"
203 proto_pppoe_init_config
() {
204 ppp_generic_init_config
205 proto_config_add_string
"ac"
206 proto_config_add_string
"service"
207 proto_config_add_string
"host_uniq"
211 proto_pppoe_setup
() {
215 for module
in slhc ppp_generic pppox pppoe
; do
216 /sbin
/insmod
$module 2>&- >&-
223 json_get_var service service
224 json_get_var host_uniq host_uniq
226 ppp_generic_setup
"$config" \
228 ${ac:+rp_pppoe_ac "$ac"} \
229 ${service:+rp_pppoe_service "$service"} \
230 ${host_uniq:+host-uniq "$host_uniq"} \
234 proto_pppoe_teardown
() {
235 ppp_generic_teardown
"$@"
238 proto_pppoa_init_config
() {
239 ppp_generic_init_config
240 proto_config_add_int
"atmdev"
241 proto_config_add_int
"vci"
242 proto_config_add_int
"vpi"
243 proto_config_add_string
"encaps"
249 proto_pppoa_setup
() {
253 for module
in slhc ppp_generic pppox pppoatm
; do
254 /sbin
/insmod
$module 2>&- >&-
257 json_get_vars atmdev vci vpi encaps
260 1|vc
) encaps
="vc-encaps" ;;
261 *) encaps
="llc-encaps" ;;
264 ppp_generic_setup
"$config" \
266 ${atmdev:+$atmdev.}${vpi:-8}.${vci:-35} \
270 proto_pppoa_teardown
() {
271 ppp_generic_teardown
"$@"
274 proto_pptp_init_config
() {
275 ppp_generic_init_config
276 proto_config_add_string
"server"
277 proto_config_add_string
"interface"
287 local ip serv_addr server interface
288 json_get_vars interface server
289 [ -n "$server" ] && {
290 for ip
in $
(resolveip
-t 5 "$server"); do
291 ( proto_add_host_dependency
"$config" "$ip" $interface )
295 [ -n "$serv_addr" ] ||
{
296 echo "Could not resolve server address"
298 proto_setup_failed
"$config"
303 for module
in slhc ppp_generic ppp_async ppp_mppe ip_gre gre pptp
; do
304 grep -q "^$module " /proc
/modules
&& continue
305 /sbin
/insmod
$module 2>&- >&-
308 [ "$load" = "1" ] && sleep 1
310 ppp_generic_setup
"$config" \
312 pptp_server
$server \
313 file /etc
/ppp
/options.pptp
316 proto_pptp_teardown
() {
317 ppp_generic_teardown
"$@"
320 [ -n "$INCLUDE_ONLY" ] ||
{
322 [ -f /usr
/lib
/pppd
/*/rp-pppoe.so
] && add_protocol pppoe
323 [ -f /usr
/lib
/pppd
/*/pppoatm.so
] && add_protocol pppoa
324 [ -f /usr
/lib
/pppd
/*/pptp.so
] && add_protocol pptp