-start_pppd() {
- local cfg="$1"; shift
-
- # make sure only one pppd process is started
- lock "/var/lock/ppp-${cfg}"
- local pid="$(head -n1 /var/run/ppp-${cfg}.pid 2>/dev/null)"
- [ -d "/proc/$pid" ] && grep pppd "/proc/$pid/cmdline" 2>/dev/null >/dev/null && {
- lock -u "/var/lock/ppp-${cfg}"
- return 0
- }
-
- # Workaround: sometimes hotplug2 doesn't deliver the hotplug event for creating
- # /dev/ppp fast enough to be used here
- [ -e /dev/ppp ] || mknod /dev/ppp c 108 0
-
- 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 connect "$cfg" connect
- config_get disconnect "$cfg" disconnect
- config_get pppd_options "$cfg" pppd_options
- config_get_bool defaultroute "$cfg" defaultroute 1
- [ "$defaultroute" -eq 1 ] && defaultroute="defaultroute replacedefaultroute" || defaultroute=""
-
- interval="${keepalive##*[, ]}"
+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##*[, ]}"