xl2tp: add PPP unnumbered support to proto handler
authorMartin Schiller <[email protected]>
Mon, 24 Nov 2025 12:46:22 +0000 (13:46 +0100)
committerHannu Nyman <[email protected]>
Fri, 12 Dec 2025 11:50:59 +0000 (12:50 +0100)
Adds the PPP unnumbered support from openwrt commit 48a95ef ("ppp :
Unnumbered support") to the xl2tp proto handler.

https://github.com/openwrt/openwrt/commit/48a95eff38ceaa13d497617ebd5e2201dd16ee77

Signed-off-by: Martin Schiller <[email protected]>
net/xl2tpd/Makefile
net/xl2tpd/files/l2tp.sh

index b812d051784c5b2b187e439b66b5340607d108b5..5cbb19221ebc963ea8a17910d37ea6abcd4aeed5 100644 (file)
@@ -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 <[email protected]>
 PKG_LICENSE:=GPL-2.0
 PKG_LICENSE_FILES:=LICENSE
index 08c5fe5891b3d9e52c476b12eb92224d84df5b26..16ac026d6eb2f44d9ec74dde1e7f69e7f5f3f65b 100644 (file)
@@ -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 <<EOF >"$optfile"
 usepeerdns
@@ -88,6 +126,7 @@ $keepalive
 $username
 $ipv6
 $mtu
+$localip
 $pppd_options
 EOF