diff --git a/net/xl2tpd/Makefile b/net/xl2tpd/Makefile index b812d051784c5..5cbb19221ebc9 100644 --- a/net/xl2tpd/Makefile +++ b/net/xl2tpd/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=xl2tpd PKG_VERSION:=1.3.18 -PKG_RELEASE:=2 +PKG_RELEASE:=3 PKG_MAINTAINER:=Yousong Zhou PKG_LICENSE:=GPL-2.0 PKG_LICENSE_FILES:=LICENSE diff --git a/net/xl2tpd/files/l2tp.sh b/net/xl2tpd/files/l2tp.sh index 08c5fe5891b3d..16ac026d6eb2f 100644 --- a/net/xl2tpd/files/l2tp.sh +++ b/net/xl2tpd/files/l2tp.sh @@ -4,10 +4,35 @@ [ -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" @@ -18,6 +43,7 @@ proto_l2tp_init_config() { 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 @@ -60,8 +86,8 @@ proto_l2tp_setup() { 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##*[, ]}" @@ -72,6 +98,18 @@ proto_l2tp_setup() { 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 <"$optfile" usepeerdns @@ -88,6 +126,7 @@ $keepalive $username $ipv6 $mtu +$localip $pppd_options EOF