3 [ -x /usr/sbin/pppd ] || exit 0
5 [ -n "$INCLUDE_ONLY" ] || {
11 ppp_exitcode_tostring()
14 [ -n "$errorcode" ] || errorcode=5
18 1) echo "FATAL_ERROR" ;;
19 2) echo "OPTION_ERROR" ;;
21 4) echo "NO_KERNEL_SUPPORT" ;;
22 5) echo "USER_REQUEST" ;;
23 6) echo "LOCK_FAILED" ;;
24 7) echo "OPEN_FAILED" ;;
25 8) echo "CONNECT_FAILED" ;;
26 9) echo "PTYCMD_FAILED" ;;
27 10) echo "NEGOTIATION_FAILED" ;;
28 11) echo "PEER_AUTH_FAILED" ;;
29 12) echo "IDLE_TIMEOUT" ;;
30 13) echo "CONNECT_TIME" ;;
31 14) echo "CALLBACK" ;;
32 15) echo "PEER_DEAD" ;;
34 17) echo "LOOPBACK" ;;
35 18) echo "INIT_FAILED" ;;
36 19) echo "AUTH_TOPEER_FAILED" ;;
37 20) echo "TRAFFIC_LIMIT" ;;
38 21) echo "CNID_AUTH_FAILED";;
39 *) echo "UNKNOWN_ERROR" ;;
43 ppp_generic_init_config() {
44 proto_config_add_string username
45 proto_config_add_string password
46 proto_config_add_string keepalive
47 proto_config_add_boolean keepalive_adaptive
48 proto_config_add_int demand
49 proto_config_add_string pppd_options
50 proto_config_add_string 'connect:file'
51 proto_config_add_string 'disconnect:file'
52 proto_config_add_string ipv6
53 proto_config_add_boolean authfail
54 proto_config_add_int mtu
55 proto_config_add_string pppname
59 local config="$1"; shift
61 json_get_vars ipv6 demand keepalive keepalive_adaptive username password pppd_options pppname
62 if [ "$ipv6" = 0 ]; then
64 elif [ -z "$ipv6" -o "$ipv6" = auto ]; then
66 proto_export "AUTOIPV6=1"
69 if [ "${demand:-0}" -gt 0 ]; then
70 demand="precompiled-active-filter /etc/ppp/filter demand idle $demand"
74 [ -n "$mtu" ] || json_get_var mtu mtu
75 [ -n "$pppname" ] || pppname="${proto:-ppp}-$config"
77 local lcp_failure="${keepalive%%[, ]*}"
78 local lcp_interval="${keepalive##*[, ]}"
79 local lcp_adaptive="lcp-echo-adaptive"
80 [ "${lcp_failure:-0}" -lt 1 ] && lcp_failure=""
81 [ "$lcp_interval" != "$keepalive" ] || lcp_interval=5
82 [ "${keepalive_adaptive:-1}" -lt 1 ] && lcp_adaptive=""
83 [ -n "$connect" ] || json_get_var connect connect
84 [ -n "$disconnect" ] || json_get_var disconnect disconnect
86 proto_run_command "$config" /usr/sbin/pppd \
87 nodetach ipparam "$config" \
89 ${lcp_failure:+lcp-echo-interval $lcp_interval lcp-echo-failure $lcp_failure $lcp_adaptive} \
94 ${username:+user "$username" password "$password"} \
95 ${connect:+connect "$connect"} \
96 ${disconnect:+disconnect "$disconnect"} \
97 ip-up-script /lib/netifd/ppp-up \
98 ipv6-up-script /lib/netifd/ppp-up \
99 ip-down-script /lib/netifd/ppp-down \
100 ipv6-down-script /lib/netifd/ppp-down \
101 ${mtu:+mtu $mtu mru $mtu} \
105 ppp_generic_teardown() {
107 local errorstring=$(ppp_exitcode_tostring $ERROR)
113 proto_notify_error "$interface" "$errorstring"
114 proto_block_restart "$interface"
117 json_get_var authfail authfail
118 proto_notify_error "$interface" "$errorstring"
119 if [ "${authfail:-0}" -gt 0 ]; then
120 proto_block_restart "$interface"
124 proto_notify_error "$interface" "$errorstring"
128 proto_kill_command "$interface"
131 # PPP on serial device
133 proto_ppp_init_config() {
134 proto_config_add_string "device"
135 ppp_generic_init_config
144 json_get_var device device
145 ppp_generic_setup "$config" "$device"
148 proto_ppp_teardown() {
149 ppp_generic_teardown "$@"
152 proto_pppoe_init_config() {
153 ppp_generic_init_config
154 proto_config_add_string "ac"
155 proto_config_add_string "service"
156 proto_config_add_string "host_uniq"
160 proto_pppoe_setup() {
164 for module in slhc ppp_generic pppox pppoe; do
165 /sbin/insmod $module 2>&- >&-
172 json_get_var service service
173 json_get_var host_uniq host_uniq
175 ppp_generic_setup "$config" \
177 ${ac:+rp_pppoe_ac "$ac"} \
178 ${service:+rp_pppoe_service "$service"} \
179 ${host_uniq:+host-uniq "$host_uniq"} \
183 proto_pppoe_teardown() {
184 ppp_generic_teardown "$@"
187 proto_pppoa_init_config() {
188 ppp_generic_init_config
189 proto_config_add_int "atmdev"
190 proto_config_add_int "vci"
191 proto_config_add_int "vpi"
192 proto_config_add_string "encaps"
198 proto_pppoa_setup() {
202 for module in slhc ppp_generic pppox pppoatm; do
203 /sbin/insmod $module 2>&- >&-
206 json_get_vars atmdev vci vpi encaps
209 1|vc) encaps="vc-encaps" ;;
210 *) encaps="llc-encaps" ;;
213 ppp_generic_setup "$config" \
215 ${atmdev:+$atmdev.}${vpi:-8}.${vci:-35} \
219 proto_pppoa_teardown() {
220 ppp_generic_teardown "$@"
223 proto_pptp_init_config() {
224 ppp_generic_init_config
225 proto_config_add_string "server"
226 proto_config_add_string "interface"
236 local ip serv_addr server interface
237 json_get_vars interface server
238 [ -n "$server" ] && {
239 for ip in $(resolveip -t 5 "$server"); do
240 ( proto_add_host_dependency "$config" "$ip" $interface )
244 [ -n "$serv_addr" ] || {
245 echo "Could not resolve server address"
247 proto_setup_failed "$config"
252 for module in slhc ppp_generic ppp_async ppp_mppe ip_gre gre pptp; do
253 grep -q "^$module " /proc/modules && continue
254 /sbin/insmod $module 2>&- >&-
257 [ "$load" = "1" ] && sleep 1
259 ppp_generic_setup "$config" \
261 pptp_server $server \
262 file /etc/ppp/options.pptp
265 proto_pptp_teardown() {
266 ppp_generic_teardown "$@"
269 [ -n "$INCLUDE_ONLY" ] || {
271 [ -f /usr/lib/pppd/*/rp-pppoe.so ] && add_protocol pppoe
272 [ -f /usr/lib/pppd/*/pppoatm.so ] && add_protocol pppoa
273 [ -f /usr/lib/pppd/*/pptp.so ] && add_protocol pptp