Skip to content

Commit faa7df0

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 faa7df0

2 files changed

Lines changed: 15 additions & 7 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: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ expand_phase2alg() {
7878
phase2alg_proposal="${encryption_algorithm:+${encryption_algorithm// /+}${hash_algorithm:+-${hash_algorithm// /+}${dh_group:+-${dh_group// /+}}}}"
7979
}
8080

81+
append_subnet() {
82+
local subnet="$1"
83+
local var="$2"
84+
85+
[ "$subnet" = "0.0.0.0" ] && subnet="0.0.0.0/0"
86+
append "$var" "$subnet" ","
87+
}
88+
8189
generate_tunnel_config() {
8290
local id=$1
8391
local config_file="$IPSEC_CONF_DIR/$id.conf"
@@ -95,8 +103,6 @@ generate_tunnel_config() {
95103
config_get rightid "$id" rightid "$right"
96104
config_get leftsourceip "$id" leftsourceip
97105
config_get rightsourceip "$id" rightsourceip
98-
config_get leftsubnets "$id" leftsubnets
99-
config_get rightsubnets "$id" rightsubnets
100106
config_get_bool ikev2 "$id" ikev2
101107
[ "$ikev2" = "1" ] && ikev2=yes || ikev2=no
102108
config_get_bool rekey "$id" rekey
@@ -111,20 +117,22 @@ generate_tunnel_config() {
111117
config_get nflog "$id" nflog 0
112118
[ "$nflog" = "0" ] && unset nflog
113119

120+
leftsubnets=""
121+
rightsubnets=""
114122
config_list_foreach "$id" ike expand_ike
115123
config_list_foreach "$id" phase2alg expand_phase2alg
124+
config_list_foreach "$id" leftsubnets append_subnet leftsubnets
125+
config_list_foreach "$id" rightsubnets append_subnet rightsubnets
116126

117127
config_get authby "$id" authby
118128
config_get psk "$id" psk
119129

120130
if [ -n "$leftsubnets" ]; then
121-
[[ "$leftsubnets" =~ 0.0.0.0* ]] && leftsubnets="0.0.0.0/0"
122-
leftsubnets="{${leftsubnets// /,}}"
131+
leftsubnets="{${leftsubnets}}"
123132
fi
124133

125134
if [ -n "$rightsubnets" ]; then
126-
[[ "$rightsubnets" =~ 0.0.0.0* ]] && rightsubnets="0.0.0.0/0"
127-
rightsubnets="{${rightsubnets// /,}}"
135+
rightsubnets="{${rightsubnets}}"
128136
fi
129137

130138
config_get interface "$id" interface

0 commit comments

Comments
 (0)