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 [ -e /proc/sys/net/ipv6 ] && 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 ip6table demand keepalive keepalive_adaptive username password pppd_options pppname unnumbered persist maxfail holdoff peerdns
93 [ ! -e /proc/sys/net/ipv6 ] && ipv6=0 || json_get_var ipv6 ipv6
95 if [ "$ipv6" = 0 ]; then
97 elif [ -z "$ipv6" -o "$ipv6" = auto ]; then
102 if [ "${demand:-0}" -gt 0 ]; then
103 demand="precompiled-active-filter /etc/ppp/filter demand idle $demand"
107 if [ -n "$persist" ]; then
108 [ "${persist}" -lt 1 ] && persist="nopersist" || persist="persist"
110 if [ -z "$maxfail" ]; then
111 [ "$persist" = "persist" ] && maxfail=0 || maxfail=1
113 [ -n "$mtu" ] || json_get_var mtu mtu
114 [ -n "$pppname" ] || pppname="${proto:-ppp}-$config"
115 [ -n "$unnumbered" ] && {
117 ( proto_add_host_dependency "$config" "" "$unnumbered" )
118 network_get_subnets subnets "$unnumbered"
119 localip=$(ppp_select_ipaddr "$subnets")
120 [ -n "$localip" ] || {
121 proto_block_restart "$config"
126 [ -n "$keepalive" ] || keepalive="5 1"
128 local lcp_failure="${keepalive%%[, ]*}"
129 local lcp_interval="${keepalive##*[, ]}"
130 local lcp_adaptive="lcp-echo-adaptive"
131 [ "${lcp_failure:-0}" -lt 1 ] && lcp_failure=""
132 [ "$lcp_interval" != "$keepalive" ] || lcp_interval=5
133 [ "${keepalive_adaptive:-1}" -lt 1 ] && lcp_adaptive=""
134 [ -n "$connect" ] || json_get_var connect connect
135 [ -n "$disconnect" ] || json_get_var disconnect disconnect
137 proto_run_command "$config" /usr/sbin/pppd \
138 nodetach ipparam "$config" \
140 ${localip:+$localip:} \
141 ${lcp_failure:+lcp-echo-interval $lcp_interval lcp-echo-failure $lcp_failure $lcp_adaptive} \
143 ${autoipv6:+set AUTOIPV6=1} \
144 ${ip6table:+set IP6TABLE=$ip6table} \
145 ${peerdns:+set PEERDNS=$peerdns} \
148 $demand $persist maxfail $maxfail \
149 ${holdoff:+holdoff "$holdoff"} \
150 ${username:+user "$username" password "$password"} \
151 ${connect:+connect "$connect"} \
152 ${disconnect:+disconnect "$disconnect"} \
153 ip-up-script /lib/netifd/ppp-up \
154 ${ipv6:+ipv6-up-script /lib/netifd/ppp6-up} \
155 ip-down-script /lib/netifd/ppp-down \
156 ${ipv6:+ipv6-down-script /lib/netifd/ppp-down} \
157 ${mtu:+mtu $mtu mru $mtu} \
161 ppp_generic_teardown() {
163 local errorstring=$(ppp_exitcode_tostring $ERROR)
169 proto_notify_error "$interface" "$errorstring"
170 proto_block_restart "$interface"
173 json_get_var authfail authfail
174 proto_notify_error "$interface" "$errorstring"
175 if [ "${authfail:-0}" -gt 0 ]; then
176 proto_block_restart "$interface"
180 proto_notify_error "$interface" "$errorstring"
184 proto_kill_command "$interface"
187 # PPP on serial device
189 proto_ppp_init_config() {
190 proto_config_add_string "device"
191 ppp_generic_init_config
200 json_get_var device device
201 ppp_generic_setup "$config" "$device"
204 proto_ppp_teardown() {
205 ppp_generic_teardown "$@"
208 proto_pppoe_init_config() {
209 ppp_generic_init_config
210 proto_config_add_string "ac"
211 proto_config_add_string "service"
212 proto_config_add_string "host_uniq"
216 proto_pppoe_setup() {
220 for module in slhc ppp_generic pppox pppoe; do
221 /sbin/insmod $module 2>&- >&-
228 json_get_var service service
229 json_get_var host_uniq host_uniq
231 ppp_generic_setup "$config" \
233 ${ac:+rp_pppoe_ac "$ac"} \
234 ${service:+rp_pppoe_service "$service"} \
235 ${host_uniq:+host-uniq "$host_uniq"} \
239 proto_pppoe_teardown() {
240 ppp_generic_teardown "$@"
243 proto_pppoa_init_config() {
244 ppp_generic_init_config
245 proto_config_add_int "atmdev"
246 proto_config_add_int "vci"
247 proto_config_add_int "vpi"
248 proto_config_add_string "encaps"
254 proto_pppoa_setup() {
258 for module in slhc ppp_generic pppox pppoatm; do
259 /sbin/insmod $module 2>&- >&-
262 json_get_vars atmdev vci vpi encaps
265 1|vc) encaps="vc-encaps" ;;
266 *) encaps="llc-encaps" ;;
269 ppp_generic_setup "$config" \
271 ${atmdev:+$atmdev.}${vpi:-8}.${vci:-35} \
275 proto_pppoa_teardown() {
276 ppp_generic_teardown "$@"
279 proto_pptp_init_config() {
280 ppp_generic_init_config
281 proto_config_add_string "server"
282 proto_config_add_string "interface"
292 local ip serv_addr server interface
293 json_get_vars interface server
294 [ -n "$server" ] && {
295 for ip in $(resolveip -t 5 "$server"); do
296 ( proto_add_host_dependency "$config" "$ip" $interface )
300 [ -n "$serv_addr" ] || {
301 echo "Could not resolve server address"
303 proto_setup_failed "$config"
308 for module in slhc ppp_generic ppp_async ppp_mppe ip_gre gre pptp; do
309 grep -q "^$module " /proc/modules && continue
310 /sbin/insmod $module 2>&- >&-
313 [ "$load" = "1" ] && sleep 1
315 ppp_generic_setup "$config" \
317 pptp_server $server \
318 file /etc/ppp/options.pptp
321 proto_pptp_teardown() {
322 ppp_generic_teardown "$@"
325 [ -n "$INCLUDE_ONLY" ] || {
327 [ -f /usr/lib/pppd/*/rp-pppoe.so ] && add_protocol pppoe
328 [ -f /usr/lib/pppd/*/pppoatm.so ] && add_protocol pppoa
329 [ -f /usr/lib/pppd/*/pptp.so ] && add_protocol pptp