xl2tp: add PPP unnumbered support to proto handler

Adds the PPP unnumbered support from openwrt commit 48a95ef ("ppp :
Unnumbered support") to the xl2tp proto handler.

48a95eff38

Signed-off-by: Martin Schiller <ms@dev.tdt.de>
This commit is contained in:
Martin Schiller
2025-11-24 13:46:22 +01:00
committed by Hannu Nyman
parent 495e4e9287
commit 21019d063d
2 changed files with 42 additions and 3 deletions

View 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 <yszhou4tech@gmail.com>
PKG_LICENSE:=GPL-2.0
PKG_LICENSE_FILES:=LICENSE

View 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