[PATCH] vxlan: allow for dynamic source ip selection

Johannes Kimmel fff at bareminimum.eu
Mon Nov 23 01:39:27 EST 2020


By setting 'auto', the zero address or the empty string as source
address, vxlan will choose one dynamically. This helps in setups where
a wan ip or prefix changes.

This corresponse to setting up an vxlan tunnel with:

proto vxlan6:
    # ip link add vx0 type vxlan id ID local :: ...
proto vxlan:
    # ip link add vx0 type vxlan id ID local 0.0.0.0 ...

While it is possible to not specify a source ip at all, the kernel will
default to setting up a ipv4 tunnel. The kernel will take any hint from
source and peer ips to figure out, what tunnel type to use. To make sure
we setup an ipv6 tunnel for proto vxlan6, this workaround is needed.

Specifying 'inherit' as source ip, the old behaviour is used whereby
a source ip is calculated once from the tunlink interface.

This change also lifts the currently very strict behaviour and should
fix the following bug:

Fixes: FS#3426
Ref: https://bugs.openwrt.org/index.php?do=details&task_id=3426

Signed-off-by: Johannes Kimmel <fff at bareminimum.eu>
---
 package/network/config/vxlan/files/vxlan.sh | 55 ++++++++++++---------
 1 file changed, 33 insertions(+), 22 deletions(-)

diff --git a/package/network/config/vxlan/files/vxlan.sh b/package/network/config/vxlan/files/vxlan.sh
index 5c1c484c47..579964b385 100755
--- a/package/network/config/vxlan/files/vxlan.sh
+++ b/package/network/config/vxlan/files/vxlan.sh
@@ -114,18 +114,23 @@ proto_vxlan_setup() {
 
 	( proto_add_host_dependency "$cfg" '' "$tunlink" )
 
-	[ -z "$ipaddr" ] && {
-		local wanif="$tunlink"
-		if [ -z "$wanif" ] && ! network_find_wan wanif; then
-			proto_notify_error "$cfg" "NO_WAN_LINK"
-			exit
-		fi
+	case "$ipaddr" in
+		"inherit")
+			local wanif="$tunlink"
+			if [ -z "$wanif" ] && ! network_find_wan wanif; then
+				proto_notify_error "$cfg" "NO_WAN_LINK"
+				exit
+			fi
 
-		if ! network_get_ipaddr ipaddr "$wanif"; then
-			proto_notify_error "$cfg" "NO_WAN_LINK"
-			exit
-		fi
-	}
+			if ! network_get_ipaddr ipaddr "$wanif"; then
+				proto_notify_error "$cfg" "NO_WAN_LINK"
+				exit
+			fi
+			;;
+		"auto"|"")
+			ipaddr="0.0.0.0"
+			;;
+	esac
 
 	vxlan_generic_setup "$cfg" 'vxlan' "$ipaddr" "$peeraddr"
 }
@@ -138,18 +143,24 @@ proto_vxlan6_setup() {
 
 	( proto_add_host_dependency "$cfg" '' "$tunlink" )
 
-	[ -z "$ip6addr" ] && {
-		local wanif="$tunlink"
-		if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
-			proto_notify_error "$cfg" "NO_WAN_LINK"
-			exit
-		fi
+	case "$ip6addr" in
+		"inherit")
+			local wanif="$tunlink"
+			if [ -z "$wanif" ] && ! network_find_wan6 wanif; then
+				proto_notify_error "$cfg" "NO_WAN_LINK"
+				exit
+			fi
 
-		if ! network_get_ipaddr6 ip6addr "$wanif"; then
-			proto_notify_error "$cfg" "NO_WAN_LINK"
-			exit
-		fi
-	}
+			if ! network_get_ipaddr6 ip6addr "$wanif"; then
+				proto_notify_error "$cfg" "NO_WAN_LINK"
+				exit
+			fi
+			;;
+		"auto"|"")
+			# ensure tunnel via ipv6
+			ip6addr="::"
+			;;
+	esac
 
 	vxlan_generic_setup "$cfg" 'vxlan6' "$ip6addr" "$peer6addr"
 }
-- 
2.29.2




More information about the openwrt-devel mailing list