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
85 local config
="$1"; shift
88 json_get_vars ipv6 demand keepalive keepalive_adaptive username password pppd_options pppname unnumbered
89 if [ "$ipv6" = 0 ]; then
91 elif [ -z "$ipv6" -o "$ipv6" = auto
]; then
96 if [ "${demand:-0}" -gt 0 ]; then
97 demand
="precompiled-active-filter /etc/ppp/filter demand idle $demand"
101 [ -n "$mtu" ] || json_get_var mtu mtu
102 [ -n "$pppname" ] || pppname
="${proto:-ppp}-$config"
103 [ -n "$unnumbered" ] && {
105 ( proto_add_host_dependency
"$config" "" "$unnumbered" )
106 network_get_subnets subnets
"$unnumbered"
107 localip
=$
(ppp_select_ipaddr
"$subnets")
108 [ -n "$localip" ] ||
{
109 proto_block_restart
"$config"
114 local lcp_failure
="${keepalive%%[, ]*}"
115 local lcp_interval
="${keepalive##*[, ]}"
116 local lcp_adaptive
="lcp-echo-adaptive"
117 [ "${lcp_failure:-0}" -lt 1 ] && lcp_failure
=""
118 [ "$lcp_interval" != "$keepalive" ] || lcp_interval
=5
119 [ "${keepalive_adaptive:-1}" -lt 1 ] && lcp_adaptive
=""
120 [ -n "$connect" ] || json_get_var connect connect
121 [ -n "$disconnect" ] || json_get_var disconnect disconnect
123 proto_run_command
"$config" /usr
/sbin
/pppd \
124 nodetach ipparam
"$config" \
126 ${localip:+$localip:} \
127 ${lcp_failure:+lcp-echo-interval $lcp_interval lcp-echo-failure $lcp_failure $lcp_adaptive} \
129 ${autoipv6:+set AUTOIPV6=1} \
133 ${username:+user "$username" password "$password"} \
134 ${connect:+connect "$connect"} \
135 ${disconnect:+disconnect "$disconnect"} \
136 ip-up-script
/lib
/netifd
/ppp-up \
137 ipv6-up-script
/lib
/netifd
/ppp-up \
138 ip-down-script
/lib
/netifd
/ppp-down \
139 ipv6-down-script
/lib
/netifd
/ppp-down \
140 ${mtu:+mtu $mtu mru $mtu} \
144 ppp_generic_teardown
() {
146 local errorstring
=$
(ppp_exitcode_tostring
$ERROR)
152 proto_notify_error
"$interface" "$errorstring"
153 proto_block_restart
"$interface"
156 json_get_var authfail authfail
157 proto_notify_error
"$interface" "$errorstring"
158 if [ "${authfail:-0}" -gt 0 ]; then
159 proto_block_restart
"$interface"
163 proto_notify_error
"$interface" "$errorstring"
167 proto_kill_command
"$interface"
170 # PPP on serial device
172 proto_ppp_init_config
() {
173 proto_config_add_string
"device"
174 ppp_generic_init_config
183 json_get_var device device
184 ppp_generic_setup
"$config" "$device"
187 proto_ppp_teardown
() {
188 ppp_generic_teardown
"$@"
191 proto_pppoe_init_config
() {
192 ppp_generic_init_config
193 proto_config_add_string
"ac"
194 proto_config_add_string
"service"
195 proto_config_add_string
"host_uniq"
199 proto_pppoe_setup
() {
203 for module
in slhc ppp_generic pppox pppoe
; do
204 /sbin
/insmod
$module 2>&- >&-
211 json_get_var service service
212 json_get_var host_uniq host_uniq
214 ppp_generic_setup
"$config" \
216 ${ac:+rp_pppoe_ac "$ac"} \
217 ${service:+rp_pppoe_service "$service"} \
218 ${host_uniq:+host-uniq "$host_uniq"} \
222 proto_pppoe_teardown
() {
223 ppp_generic_teardown
"$@"
226 proto_pppoa_init_config
() {
227 ppp_generic_init_config
228 proto_config_add_int
"atmdev"
229 proto_config_add_int
"vci"
230 proto_config_add_int
"vpi"
231 proto_config_add_string
"encaps"
237 proto_pppoa_setup
() {
241 for module
in slhc ppp_generic pppox pppoatm
; do
242 /sbin
/insmod
$module 2>&- >&-
245 json_get_vars atmdev vci vpi encaps
248 1|vc
) encaps
="vc-encaps" ;;
249 *) encaps
="llc-encaps" ;;
252 ppp_generic_setup
"$config" \
254 ${atmdev:+$atmdev.}${vpi:-8}.${vci:-35} \
258 proto_pppoa_teardown
() {
259 ppp_generic_teardown
"$@"
262 proto_pptp_init_config
() {
263 ppp_generic_init_config
264 proto_config_add_string
"server"
265 proto_config_add_string
"interface"
275 local ip serv_addr server interface
276 json_get_vars interface server
277 [ -n "$server" ] && {
278 for ip
in $
(resolveip
-t 5 "$server"); do
279 ( proto_add_host_dependency
"$config" "$ip" $interface )
283 [ -n "$serv_addr" ] ||
{
284 echo "Could not resolve server address"
286 proto_setup_failed
"$config"
291 for module
in slhc ppp_generic ppp_async ppp_mppe ip_gre gre pptp
; do
292 grep -q "^$module " /proc
/modules
&& continue
293 /sbin
/insmod
$module 2>&- >&-
296 [ "$load" = "1" ] && sleep 1
298 ppp_generic_setup
"$config" \
300 pptp_server
$server \
301 file /etc
/ppp
/options.pptp
304 proto_pptp_teardown
() {
305 ppp_generic_teardown
"$@"
308 [ -n "$INCLUDE_ONLY" ] ||
{
310 [ -f /usr
/lib
/pppd
/*/rp-pppoe.so
] && add_protocol pppoe
311 [ -f /usr
/lib
/pppd
/*/pppoatm.so
] && add_protocol pppoa
312 [ -f /usr
/lib
/pppd
/*/pptp.so
] && add_protocol pptp