[ -n "$INCLUDE_ONLY" ] || {
. /lib/functions.sh
+ . /lib/functions/network.sh
. ../netifd-proto.sh
init_proto "$@"
}
+proto_l2tp_select_ipaddr()
+{
+ local subnets=$1
+ local res
+ local res_mask
+
+ for subnet in $subnets; do
+ local addr="${subnet%%/*}"
+ local mask="${subnet#*/}"
+
+ if [ -n "$res_mask" -a "$mask" != 32 ]; then
+ [ "$mask" -gt "$res_mask" ] || [ "$res_mask" = 32 ] && {
+ res="$addr"
+ res_mask="$mask"
+ }
+ elif [ -z "$res_mask" ]; then
+ res="$addr"
+ res_mask="$mask"
+ fi
+ done
+
+ echo "$res"
+}
+
proto_l2tp_init_config() {
proto_config_add_string "username"
proto_config_add_string "password"
proto_config_add_int "checkup_interval"
proto_config_add_string "server"
proto_config_add_string "hostname"
+ proto_config_add_string "unnumbered"
available=1
no_device=1
no_proto_task=1
done
fi
- local ipv6 keepalive username password pppd_options mtu
- json_get_vars ipv6 keepalive username password pppd_options mtu
+ local ipv6 keepalive username password pppd_options mtu unnumbered localip
+ json_get_vars ipv6 keepalive username password pppd_options mtu unnumbered
[ "$ipv6" = 1 ] || ipv6=""
local interval="${keepalive##*[, ]}"
ipv6="${ipv6:++ipv6}"
mtu="${mtu:+mtu $mtu mru $mtu}"
+ [ -n "$unnumbered" ] && {
+ local subnets
+ ( proto_add_host_dependency "$interface" "" "$unnumbered" )
+ network_get_subnets subnets "$unnumbered"
+ localip=$(proto_l2tp_select_ipaddr "$subnets")
+ [ -n "$localip" ] || {
+ proto_block_restart "$interface"
+ return
+ }
+ localip="${localip:+$localip:}"
+ }
+
mkdir -p /tmp/l2tp
cat <<EOF >"$optfile"
usepeerdns
$username
$ipv6
$mtu
+$localip
$pppd_options
EOF