strongswan: fix local_gateway discovery
authorPhilip Prindeville <philipp@redfish-solutions.com>
Mon, 15 Feb 2021 21:51:02 +0000 (14:51 -0700)
committerRosen Penev <rosenp@gmail.com>
Tue, 6 Apr 2021 23:05:19 +0000 (16:05 -0700)
This has been observed by myself and @luizluca: ip route get is
appending uid0 to the output, as seen from:

root@OpenWrt2:~# ip route get 1.1.1.1
1.1.1.1 via 174.27.160.1 dev eth3 src 174.27.182.184 uid 0
    cache
root@OpenWrt2:~#

so the fix is an anchored match, discarding all else. Also, using
ip -o means never having to do multiline matches...

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
(cherry picked from commit ec72d3a9e47954f0be844fb32abb5ca1e4dda667)

net/strongswan/Makefile
net/strongswan/files/ipsec.init

index 2ff5ec51ad5401675f0392bc03f3b2f1e5dc2f67..f292290d4762931119cec59451304fe39e939d0c 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=strongswan
 PKG_VERSION:=5.9.1
-PKG_RELEASE:=2
+PKG_RELEASE:=3
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:=https://download.strongswan.org/ https://download2.strongswan.org/
index 63b7507a23340ee5c5555b741c4fff0222b2063b..1881e1f14f51f2f804c74c3827e7e8e7a0cf0412 100644 (file)
@@ -249,7 +249,7 @@ config_remote() {
                local ipdest
 
                [ "$remote_gateway" = "%any" ] && ipdest="1.1.1.1" || ipdest="$remote_gateway"
-               local_gateway=`ip route get $ipdest | awk -F"src" '/src/{gsub(/ /,"");print $2}'`
+               local_gateway=$(ip -o route get "$ipdest" | awk '/ src / { print gensub(/^.* src ([^ ]*) .*$/, "\\1", "g"); }')
        }
 
        [ -n "$local_identifier" ] && secret_xappend -n "$local_identifier " || secret_xappend -n "$local_gateway "