Skip to content

Commit 3c2c1e0

Browse files
committed
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. openwrt/openwrt@48a95ef Signed-off-by: Martin Schiller <[email protected]>
1 parent 8bf5f68 commit 3c2c1e0

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

net/xl2tpd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
99

1010
PKG_NAME:=xl2tpd
1111
PKG_VERSION:=1.3.18
12-
PKG_RELEASE:=2
12+
PKG_RELEASE:=3
1313
PKG_MAINTAINER:=Yousong Zhou <[email protected]>
1414
PKG_LICENSE:=GPL-2.0
1515
PKG_LICENSE_FILES:=LICENSE

net/xl2tpd/files/l2tp.sh

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,35 @@
44

55
[ -n "$INCLUDE_ONLY" ] || {
66
. /lib/functions.sh
7+
. /lib/functions/network.sh
78
. ../netifd-proto.sh
89
init_proto "$@"
910
}
1011

12+
proto_l2tp_select_ipaddr()
13+
{
14+
local subnets=$1
15+
local res
16+
local res_mask
17+
18+
for subnet in $subnets; do
19+
local addr="${subnet%%/*}"
20+
local mask="${subnet#*/}"
21+
22+
if [ -n "$res_mask" -a "$mask" != 32 ]; then
23+
[ "$mask" -gt "$res_mask" ] || [ "$res_mask" = 32 ] && {
24+
res="$addr"
25+
res_mask="$mask"
26+
}
27+
elif [ -z "$res_mask" ]; then
28+
res="$addr"
29+
res_mask="$mask"
30+
fi
31+
done
32+
33+
echo "$res"
34+
}
35+
1136
proto_l2tp_init_config() {
1237
proto_config_add_string "username"
1338
proto_config_add_string "password"
@@ -18,6 +43,7 @@ proto_l2tp_init_config() {
1843
proto_config_add_int "checkup_interval"
1944
proto_config_add_string "server"
2045
proto_config_add_string "hostname"
46+
proto_config_add_string "unnumbered"
2147
available=1
2248
no_device=1
2349
no_proto_task=1
@@ -60,8 +86,8 @@ proto_l2tp_setup() {
6086
done
6187
fi
6288

63-
local ipv6 keepalive username password pppd_options mtu
64-
json_get_vars ipv6 keepalive username password pppd_options mtu
89+
local ipv6 keepalive username password pppd_options mtu unnumbered localip
90+
json_get_vars ipv6 keepalive username password pppd_options mtu unnumbered
6591
[ "$ipv6" = 1 ] || ipv6=""
6692

6793
local interval="${keepalive##*[, ]}"
@@ -72,6 +98,18 @@ proto_l2tp_setup() {
7298
ipv6="${ipv6:++ipv6}"
7399
mtu="${mtu:+mtu $mtu mru $mtu}"
74100

101+
[ -n "$unnumbered" ] && {
102+
local subnets
103+
( proto_add_host_dependency "$interface" "" "$unnumbered" )
104+
network_get_subnets subnets "$unnumbered"
105+
localip=$(proto_l2tp_select_ipaddr "$subnets")
106+
[ -n "$localip" ] || {
107+
proto_block_restart "$interface"
108+
return
109+
}
110+
localip="${localip:+$localip:}"
111+
}
112+
75113
mkdir -p /tmp/l2tp
76114
cat <<EOF >"$optfile"
77115
usepeerdns
@@ -88,6 +126,7 @@ $keepalive
88126
$username
89127
$ipv6
90128
$mtu
129+
$localip
91130
$pppd_options
92131
EOF
93132

0 commit comments

Comments
 (0)