-scan_ppp() {
- config_get ifname "$1" ifname
- pppdev="${pppdev:-0}"
- config_set "$1" device "$ifname"
- config_set "$1" ifname "ppp$pppdev"
- config_set "$1" unit "$pppdev"
-}
-
-start_pppd() {
- local cfg="$1"; shift
- config_get device "$cfg" device
- config_get unit "$cfg" unit
- config_get username "$cfg" username
- config_get password "$cfg" password
- config_get keepalive "$cfg" keepalive
- config_get demand "$cfg" demand
- [ -n "$demand" ] && echo "nameserver 1.1.1.1" > /tmp/resolv.conf
- /usr/sbin/pppd "$@" \
- ${keepalive:+lcp-echo-interval 5 lcp-echo-failure $keepalive} \
- ${demand:+precompiled-active-filter /etc/ppp/filter demand idle }${demand:-persist} \
- usepeerdns \
- defaultroute \
- replacedefaultroute \
+#!/bin/sh
+
+[ -x /usr/sbin/pppd ] || exit 0
+
+[ -n "$INCLUDE_ONLY" ] || {
+ . /etc/functions.sh
+ . ../netifd-proto.sh
+ init_proto "$@"
+}
+
+ppp_generic_init_config() {
+ proto_config_add_string "username"
+ proto_config_add_string "password"
+ proto_config_add_string "keepalive"
+ proto_config_add_int "demand"
+ proto_config_add_string "pppd_options"
+ proto_config_add_string "connect"
+ proto_config_add_string "disconnect"
+ proto_config_add_boolean "defaultroute"
+ proto_config_add_boolean "peerdns"
+ proto_config_add_boolean "ipv6"
+ proto_config_add_int "mtu"
+}
+
+ppp_generic_setup() {
+ local config="$1"; shift
+
+ json_get_var ipv6 ipv6
+ [ "$ipv6" = 1 ] || ipv6=""
+
+ json_get_var peerdns peerdns
+ [ "$peerdns" = 0 ] && peerdns="" || peerdns="1"
+
+ json_get_var defaultroute defaultroute
+ if [ "$defaultroute" = 1 ]; then
+ defaultroute="defaultroute replacedefaultroute";
+ else
+ defaultroute="nodefaultroute"
+ fi
+
+ json_get_var demand demand
+ if [ "${demand:-0}" -gt 0 ]; then
+ demand="precompiled-active-filter /etc/ppp/filter demand idle $demand"
+ else
+ demand="persist"
+ fi
+
+ [ -n "$mtu" ] || json_get_var mtu mtu
+
+ json_get_var keepalive keepalive
+ local interval="${keepalive##*[, ]}"
+ [ "$interval" != "$keepalive" ] || interval=5
+
+ json_get_var username username
+ json_get_var password password
+
+ [ -n "$connect" ] || json_get_var connect connect
+ [ -n "$disconnect" ] || json_get_var disconnect disconnect
+ json_get_var pppd_options pppd_options
+
+ proto_run_command "$config" /usr/sbin/pppd \
+ nodetach ipparam "$config" \
+ ifname "${proto:-ppp}-$config" \
+ ${keepalive:+lcp-echo-interval $interval lcp-echo-failure ${keepalive%%[, ]*}} \
+ ${ipv6:++ipv6} $defaultroute \
+ ${peerdns:+usepeerdns} \
+ $demand maxfail 1 \