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

Waizel, Ariel ariel.waizel at hpe.com
Thu Oct 27 13:33:35 UTC 2016


No problem:
> 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 accorded 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>

diff --git a/lib/ovs-router.c b/lib/ovs-router.c
index e27514a..18d0f8e 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 c170ae7..0383933 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -93,7 +93,8 @@ TESTSUITE_AT = \
        tests/ovn-nbctl.at \
        tests/ovn-sbctl.at \
        tests/ovn-controller.at \
-       tests/ovn-controller-vtep.at
+       tests/ovn-controller-vtep.at \
+       tests/ovs-route.at
 
 SYSTEM_KMOD_TESTSUITE_AT = \
        tests/system-common-macros.at \
diff --git a/tests/ovs-route.at b/tests/ovs-route.at
new file mode 100644
index 0000000..ac11847
--- /dev/null
+++ b/tests/ovs-route.at
@@ -0,0 +1,10 @@
+AT_BANNER([appctl route/add with gateway])
+AT_SETUP([appctl - route/add with gateway])
+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])
+ovs-appctl netdev-dummy/ip4addr br0 2.2.2.2/24
+AT_CHECK([ovs-appctl ovs/route/add 1.1.1.0/24 br0 2.2.2.10], [0], [OK
+])
+AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 2123bee..a2c707d 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -75,3 +75,4 @@ m4_include([tests/ovn-nbctl.at])
 m4_include([tests/ovn-sbctl.at])
 m4_include([tests/ovn-controller.at])
 m4_include([tests/ovn-controller-vtep.at])
+m4_include([tests/ovs-route.at])


-----Original Message-----
From: Thadeu Lima de Souza Cascardo [mailto:cascardo at redhat.com] 
Sent: Tuesday, October 4, 2016 7:48 PM
To: Waizel, Ariel <ariel.waizel at hpe.com>
Cc: dev at openvswitch.org; Dotan, Alon <alon.dotan at hpe.com>
Subject: Re: [ovs-dev] [PATCH] ovs-router: Fix selection of source IP address when a gateway ip is introduced

On Tue, Sep 13, 2016 at 07:08:52AM +0000, Waizel, Ariel wrote:
> 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 accorded 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>
> 
> diff --git a/lib/ovs-router.c b/lib/ovs-router.c index 
> e27514a..18d0f8e 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;

Hi, Ariel.

Thanks for that. Can you resend wrapping the log text to 72 columns and add a test? At least one test verifying that adding such routes with ovs/route/add work as expected.

Acked-by: Thadeu Lima de Souza Cascardo <cascardo at redhat.com>

Cascardo.



More information about the dev mailing list