[ovs-dev] [PATCH 3/3] ovs-router: Fix selection of source IP address when a gateway ip is introduced

Thadeu Lima de Souza Cascardo cascardo at redhat.com
Tue Nov 15 09:49:47 UTC 2016


From: Ariel Waizel <ariel.waizel at hpe.com>

When adding a VXLAN tunnel that connects to a VTEP residing in a different IP
network, the tunnel source ip needs to be selected by best fit (longest
matching netmask), based on the destination VTEP ip, and the specific route's
gateway ip.

A bug in ovs-router.c made the source ip to be decided only based on the
destination ip. Thus, if all source ips available to OVS and the destination ip
are in different ip networks - no source ip is selected, and an error is
returned.

This error occurred when using OVS-DPDK and configuring a VXLAN tunnel, where
source ip and destination ip are in different networks, and a gateway ip was in
place for the specific route.

The fix tries to match a source ip based on the gateway ip, if no matching
source ip was found based on the destination ip. This way, the gateway becomes
the first hop only if the tunnel crosses between ip networks.

Signed-off-by: Ariel Waizel <ariel.waizel at hpe.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo at redhat.com>
---
 lib/ovs-router.c    |  3 +++
 tests/automake.mk   |  1 +
 tests/ovs-router.at | 13 +++++++++++++
 tests/testsuite.at  |  1 +
 4 files changed, 18 insertions(+)
 create mode 100644 tests/ovs-router.at

diff --git a/lib/ovs-router.c b/lib/ovs-router.c
index e29d462..637cad9 100644
--- a/lib/ovs-router.c
+++ b/lib/ovs-router.c
@@ -198,6 +198,9 @@ ovs_router_insert__(uint8_t priority, const struct in6_addr *ip6_dst,
     p->plen = plen;
     p->priority = priority;
     err = get_src_addr(ip6_dst, output_bridge, &p->src_addr);
+    if (err && ipv6_addr_is_set(gw)) {
+        err = get_src_addr(gw, output_bridge, &p->src_addr);
+    }
     if (err) {
         free(p);
         return err;
diff --git a/tests/automake.mk b/tests/automake.mk
index 92380d2..4939d7c 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -52,6 +52,7 @@ TESTSUITE_AT = \
 	tests/tunnel.at \
 	tests/tunnel-push-pop.at \
 	tests/tunnel-push-pop-ipv6.at \
+	tests/ovs-router.at \
 	tests/lockfile.at \
 	tests/reconnect.at \
 	tests/ovs-vswitchd.at \
diff --git a/tests/ovs-router.at b/tests/ovs-router.at
new file mode 100644
index 0000000..96c051e
--- /dev/null
+++ b/tests/ovs-router.at
@@ -0,0 +1,13 @@
+AT_BANNER([appctl route/add with gateway])
+AT_SETUP([appctl - route/add with gateway])
+AT_KEYWORDS([ovs_router])
+AT_XFAIL_IF([test "$IS_WIN32" = "yes"])
+OVS_VSWITCHD_START([add-port br0 p2 -- set Interface p2 type=gre \
+			options:local_ip=2.2.2.2 options:remote_ip=1.1.1.1 \
+			-- add-port br0 p1  -- set interface p1 type=dummy])
+AT_CHECK([ovs-appctl netdev-dummy/ip4addr br0 2.2.2.2/24], [0], [OK
+])
+AT_CHECK([ovs-appctl ovs/route/add 1.1.1.0/24 br0 2.2.2.10], [0], [OK
+])
+OVS_VSWITCHD_STOP
+AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 72fa545..26f7357 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -51,6 +51,7 @@ m4_include([tests/jsonrpc-py.at])
 m4_include([tests/tunnel.at])
 m4_include([tests/tunnel-push-pop.at])
 m4_include([tests/tunnel-push-pop-ipv6.at])
+m4_include([tests/ovs-router.at])
 m4_include([tests/lockfile.at])
 m4_include([tests/reconnect.at])
 m4_include([tests/ovs-vswitchd.at])
-- 
2.7.4



More information about the dev mailing list