Root/package/netifd/files/lib/netifd/proto/ppp.sh

1#!/bin/sh
2
3[ -x /usr/sbin/pppd ] || exit 0
4
5[ -n "$INCLUDE_ONLY" ] || {
6    . /etc/functions.sh
7    . ../netifd-proto.sh
8    init_proto "$@"
9}
10
11ppp_generic_init_config() {
12    proto_config_add_string "username"
13    proto_config_add_string "password"
14    proto_config_add_string "keepalive"
15    proto_config_add_int "demand"
16    proto_config_add_string "pppd_options"
17    proto_config_add_string "connect"
18    proto_config_add_string "disconnect"
19    proto_config_add_boolean "defaultroute"
20    proto_config_add_boolean "peerdns"
21    proto_config_add_boolean "ipv6"
22    proto_config_add_int "mtu"
23}
24
25ppp_generic_setup() {
26    local config="$1"; shift
27
28    json_get_var ipv6 ipv6
29    [ "$ipv6" = 1 ] || ipv6=""
30
31    json_get_var peerdns peerdns
32    [ "$peerdns" = 0 ] && peerdns="" || peerdns="1"
33
34    json_get_var defaultroute defaultroute
35    if [ "$defaultroute" = 1 ]; then
36        defaultroute="defaultroute replacedefaultroute";
37    else
38        defaultroute="nodefaultroute"
39    fi
40
41    json_get_var demand demand
42    if [ "${demand:-0}" -gt 0 ]; then
43        demand="precompiled-active-filter /etc/ppp/filter demand idle $demand"
44    else
45        demand="persist"
46    fi
47
48    [ -n "$mtu" ] || json_get_var mtu mtu
49
50    json_get_var keepalive keepalive
51    local interval="${keepalive##*[, ]}"
52    [ "$interval" != "$keepalive" ] || interval=5
53
54    json_get_var username username
55    json_get_var password password
56
57    [ -n "$connect" ] || json_get_var connect connect
58    [ -n "$disconnect" ] || json_get_var disconnect disconnect
59    json_get_var pppd_options pppd_options
60
61    proto_run_command "$config" /usr/sbin/pppd \
62        nodetach ipparam "$config" \
63        ifname "${proto:-ppp}-$config" \
64        ${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}} \
65        ${ipv6:++ipv6} $defaultroute \
66        ${peerdns:+usepeerdns} \
67        $demand maxfail 1 \
68        ${username:+user "$username" password "$password"} \
69        ${connect:+connect "$connect"} \
70        ${disconnect:+disconnect "$disconnect"} \
71        ip-up-script /lib/netifd/ppp-up \
72        ipv6-up-script /lib/netifd/ppp-up \
73        ip-down-script /lib/netifd/ppp-down \
74        ipv6-down-script /lib/netifd/ppp-down \
75        ${mtu:+mtu $mtu mru $mtu} \
76        $pppd_options "$@"
77}
78
79ppp_generic_teardown() {
80    local interface="$1"
81
82    case "$ERROR" in
83        11|19)
84            proto_notify_error "$interface" AUTH_FAILED
85            proto_block_restart "$interface"
86        ;;
87    esac
88    proto_kill_command "$interface"
89}
90
91# PPP on serial device
92
93proto_ppp_init_config() {
94    proto_config_add_string "device"
95    ppp_generic_init_config
96    no_device=1
97    available=1
98}
99
100proto_ppp_setup() {
101    local config="$1"
102
103    json_get_var device device
104    ppp_generic_setup "$config" "$device"
105}
106
107proto_ppp_teardown() {
108    ppp_generic_teardown "$@"
109}
110
111proto_pppoe_init_config() {
112    ppp_generic_init_config
113    proto_config_add_string "ac"
114    proto_config_add_string "service"
115}
116
117proto_pppoe_setup() {
118    local config="$1"
119    local iface="$2"
120
121    for module in slhc ppp_generic pppox pppoe; do
122        /sbin/insmod $module 2>&- >&-
123    done
124
125    json_get_var mtu mtu
126    mtu="${mtu:-1492}"
127
128    json_get_var ac ac
129    json_get_var service service
130
131    ppp_generic_setup "$config" \
132        plugin rp-pppoe.so \
133        ${ac:+rp_pppoe_ac "$ac"} \
134        ${service:+rp_pppoe_service "$service"} \
135        "nic-$iface"
136}
137
138proto_pppoe_teardown() {
139    ppp_generic_teardown "$@"
140}
141
142proto_pppoa_init_config() {
143    ppp_generic_init_config
144    proto_config_add_int "atmdev"
145    proto_config_add_int "vci"
146    proto_config_add_int "vpi"
147    proto_config_add_string "encaps"
148}
149
150proto_pppoa_setup() {
151    local config="$1"
152    local iface="$2"
153
154    for module in slhc ppp_generic pppox pppoatm; do
155        /sbin/insmod $module 2>&- >&-
156    done
157
158    json_get_var atmdev atmdev
159    json_get_var vci vci
160    json_get_var vpi vpi
161
162    json_get_var encaps encaps
163    case "$encaps" in
164        1|vc) encaps="vc-encaps" ;;
165        *) encaps="llc-encaps" ;;
166    esac
167
168    ppp_generic_setup "$config" \
169        plugin pppoatm.so \
170        ${atmdev:+$atmdev.}${vpi:-8}.${vci:-35} \
171        ${encaps}
172}
173
174proto_pppoa_teardown() {
175    ppp_generic_teardown "$@"
176}
177
178[ -n "$INCLUDE_ONLY" ] || {
179    add_protocol ppp
180    [ -f /usr/lib/pppd/*/rp-pppoe.so ] && add_protocol pppoe
181    [ -f /usr/lib/pppd/*/pppoatm.so ] && add_protocol pppoa
182}
183
184

Archive Download this file



interactive