]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: abstract route src determiniation into func
authorStephen Worley <sworley@cumulusnetworks.com>
Tue, 24 Mar 2020 21:10:08 +0000 (17:10 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Thu, 2 Apr 2020 14:58:32 +0000 (10:58 -0400)
Abstraction the route src determination from a nexthop in the
netlink code into a function for both singlepath and mutlipath
to call.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
(cherry picked from commit 762288f50f5fa29512864fcc7814be83e1b58ff4)

zebra/rt_netlink.c

index 705536595b5d5c11833201e4ca1c9ae1e953ea65..dcaf2155f01f637af7a654f1290fd141757a99c2 100644 (file)
@@ -1513,6 +1513,30 @@ static int netlink_neigh_update(int cmd, int ifindex, uint32_t addr, char *lla,
                            0);
 }
 
+static bool nexthop_set_src(const struct nexthop *nexthop, int family,
+                           union g_addr *src)
+{
+       if (family == AF_INET) {
+               if (nexthop->rmap_src.ipv4.s_addr != INADDR_ANY) {
+                       src->ipv4 = nexthop->rmap_src.ipv4;
+                       return true;
+               } else if (nexthop->src.ipv4.s_addr != INADDR_ANY) {
+                       src->ipv4 = nexthop->src.ipv4;
+                       return true;
+               }
+       } else if (family == AF_INET6) {
+               if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->rmap_src.ipv6)) {
+                       src->ipv6 = nexthop->rmap_src.ipv6;
+                       return true;
+               } else if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->src.ipv6)) {
+                       src->ipv6 = nexthop->src.ipv6;
+                       return true;
+               }
+       }
+
+       return false;
+}
+
 /*
  * Routing table change via netlink interface, using a dataplane context object
  */
@@ -1523,7 +1547,7 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx)
        unsigned int nexthop_num;
        int family;
        const char *routedesc;
-       int setsrc = 0;
+       bool setsrc = false;
        union g_addr src;
        const struct prefix *p, *src_p;
        uint32_t table_id;
@@ -1689,32 +1713,8 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx)
                                if (setsrc)
                                        continue;
 
-                               if (family == AF_INET) {
-                                       if (nexthop->rmap_src.ipv4.s_addr
-                                           != 0) {
-                                               src.ipv4 =
-                                                       nexthop->rmap_src.ipv4;
-                                               setsrc = 1;
-                                       } else if (nexthop->src.ipv4.s_addr
-                                                  != 0) {
-                                               src.ipv4 =
-                                                       nexthop->src.ipv4;
-                                               setsrc = 1;
-                                       }
-                               } else if (family == AF_INET6) {
-                                       if (!IN6_IS_ADDR_UNSPECIFIED(
-                                                   &nexthop->rmap_src.ipv6)) {
-                                               src.ipv6 =
-                                                       nexthop->rmap_src.ipv6;
-                                               setsrc = 1;
-                                       } else if (
-                                               !IN6_IS_ADDR_UNSPECIFIED(
-                                                       &nexthop->src.ipv6)) {
-                                               src.ipv6 =
-                                                       nexthop->src.ipv6;
-                                               setsrc = 1;
-                                       }
-                               }
+                               setsrc = nexthop_set_src(nexthop, family, &src);
+
                                continue;
                        }
 
@@ -1757,32 +1757,7 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx)
                                if (setsrc)
                                        continue;
 
-                               if (family == AF_INET) {
-                                       if (nexthop->rmap_src.ipv4.s_addr
-                                           != 0) {
-                                               src.ipv4 =
-                                                       nexthop->rmap_src.ipv4;
-                                               setsrc = 1;
-                                       } else if (nexthop->src.ipv4.s_addr
-                                                  != 0) {
-                                               src.ipv4 =
-                                                       nexthop->src.ipv4;
-                                               setsrc = 1;
-                                       }
-                               } else if (family == AF_INET6) {
-                                       if (!IN6_IS_ADDR_UNSPECIFIED(
-                                                   &nexthop->rmap_src.ipv6)) {
-                                               src.ipv6 =
-                                                       nexthop->rmap_src.ipv6;
-                                               setsrc = 1;
-                                       } else if (
-                                               !IN6_IS_ADDR_UNSPECIFIED(
-                                                       &nexthop->src.ipv6)) {
-                                               src.ipv6 =
-                                                       nexthop->src.ipv6;
-                                               setsrc = 1;
-                                       }
-                               }
+                               setsrc = nexthop_set_src(nexthop, family, &src);
 
                                continue;
                        }