Skip to content

Commit 69bdf97

Browse files
committed
libreswan: fix default subnet matching
Match only explicit default-route subnet tokens when normalizing leftsubnets and rightsubnets. The previous regex treated dots as wildcards. Values such as 10.250.0.0/16 and 10.0.0.0/8 were rewritten to 0.0.0.0/0. Fixes: openwrt/openwrt#23795 Signed-off-by: Dharmik Parmar <dharmikparmar2004@yahoo.com>
1 parent 0627b41 commit 69bdf97

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

net/libreswan/Makefile

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

99
PKG_NAME:=libreswan
1010
PKG_VERSION:=4.12
11-
PKG_RELEASE:=4
11+
PKG_RELEASE:=5
1212

1313
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
1414
PKG_SOURCE_URL:=https://download.libreswan.org/

net/libreswan/files/etc/init.d/ipsec

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ expand_phase2alg() {
7878
phase2alg_proposal="${encryption_algorithm:+${encryption_algorithm// /+}${hash_algorithm:+-${hash_algorithm// /+}${dh_group:+-${dh_group// /+}}}}"
7979
}
8080

81+
has_default_subnet() {
82+
local subnet
83+
84+
for subnet in $1; do
85+
case "$subnet" in
86+
0.0.0.0|0.0.0.0/0)
87+
return 0
88+
;;
89+
esac
90+
done
91+
92+
return 1
93+
}
94+
8195
generate_tunnel_config() {
8296
local id=$1
8397
local config_file="$IPSEC_CONF_DIR/$id.conf"
@@ -118,12 +132,12 @@ generate_tunnel_config() {
118132
config_get psk "$id" psk
119133

120134
if [ -n "$leftsubnets" ]; then
121-
[[ "$leftsubnets" =~ 0.0.0.0* ]] && leftsubnets="0.0.0.0/0"
135+
has_default_subnet "$leftsubnets" && leftsubnets="0.0.0.0/0"
122136
leftsubnets="{${leftsubnets// /,}}"
123137
fi
124138

125139
if [ -n "$rightsubnets" ]; then
126-
[[ "$rightsubnets" =~ 0.0.0.0* ]] && rightsubnets="0.0.0.0/0"
140+
has_default_subnet "$rightsubnets" && rightsubnets="0.0.0.0/0"
127141
rightsubnets="{${rightsubnets// /,}}"
128142
fi
129143

0 commit comments

Comments
 (0)