Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion net/xl2tpd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 41 additions & 2 deletions net/xl2tpd/files/l2tp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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##*[, ]}"
Expand All @@ -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
Expand All @@ -88,6 +126,7 @@ $keepalive
$username
$ipv6
$mtu
$localip
$pppd_options
EOF

Expand Down
Loading