]> git.puffer.fish Git - mirror/frr.git/commitdiff
isisd: unify ipv4/ipv6 zebra-tx functions
authorRenato Westphal <renato@opensourcerouting.org>
Mon, 21 Aug 2017 00:29:35 +0000 (21:29 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Wed, 23 Aug 2017 23:25:45 +0000 (20:25 -0300)
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
isisd/isis_zebra.c

index 35b2091e989065177ae330f996e1f04db42a59cb..e3537e2a0cdcea007a7767efaa213ca41374c5ce 100644 (file)
@@ -245,12 +245,13 @@ static int isis_zebra_link_params(int command, struct zclient *zclient,
        return 0;
 }
 
-static void isis_zebra_route_add_ipv4(struct prefix *prefix,
-                                     struct isis_route_info *route_info)
+static void isis_zebra_route_add_route(struct prefix *prefix,
+                                      struct isis_route_info *route_info)
 {
        struct zapi_route api;
        struct zapi_nexthop *api_nh;
        struct isis_nexthop *nexthop;
+       struct isis_nexthop6 *nexthop6;
        struct listnode *node;
        int count = 0;
 
@@ -270,82 +271,38 @@ static void isis_zebra_route_add_ipv4(struct prefix *prefix,
        api.distance = route_info->depth;
 #endif
 
-       /* Nexthop, ifindex, distance and metric information */
-       for (ALL_LIST_ELEMENTS_RO(route_info->nexthops, node, nexthop)) {
-               api_nh = &api.nexthops[count];
-               /* FIXME: can it be ? */
-               if (nexthop->ip.s_addr != INADDR_ANY) {
-                       api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
-                       api_nh->gate.ipv4 = nexthop->ip;
-               } else {
-                       api_nh->type = NEXTHOP_TYPE_IFINDEX;
+       /* Nexthops */
+       switch (prefix->family) {
+       case AF_INET:
+               for (ALL_LIST_ELEMENTS_RO(route_info->nexthops, node,
+                                         nexthop)) {
+                       api_nh = &api.nexthops[count];
+                       /* FIXME: can it be ? */
+                       if (nexthop->ip.s_addr != INADDR_ANY) {
+                               api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
+                               api_nh->gate.ipv4 = nexthop->ip;
+                       } else {
+                               api_nh->type = NEXTHOP_TYPE_IFINDEX;
+                       }
+                       api_nh->ifindex = nexthop->ifindex;
+                       count++;
                }
-               api_nh->ifindex = nexthop->ifindex;
-               count++;
-       }
-       if (!count)
-               return;
-
-       api.nexthop_num = count;
-
-       zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
-       SET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
-       UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC);
-}
-
-static void isis_zebra_route_del_ipv4(struct prefix *prefix,
-                                     struct isis_route_info *route_info)
-{
-       struct zapi_route api;
-
-       UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED);
-
-       memset(&api, 0, sizeof(api));
-       api.vrf_id = VRF_DEFAULT;
-       api.type = ZEBRA_ROUTE_ISIS;
-       api.safi = SAFI_UNICAST;
-       api.prefix = *prefix;
-
-       zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
-}
-
-static void isis_zebra_route_add_ipv6(struct prefix *prefix,
-                                     struct isis_route_info *route_info)
-{
-       struct zapi_route api;
-       struct zapi_nexthop *api_nh;
-       struct isis_nexthop6 *nexthop6;
-       struct listnode *node;
-       int count = 0;
-
-       if (CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_SYNCED))
-               return;
-
-       memset(&api, 0, sizeof(api));
-       api.vrf_id = VRF_DEFAULT;
-       api.type = ZEBRA_ROUTE_ISIS;
-       api.safi = SAFI_UNICAST;
-       SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
-       SET_FLAG(api.message, ZAPI_MESSAGE_METRIC);
-       api.metric = route_info->cost;
-#if 0
-       SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
-       api.distance = route_info->depth;
-#endif
-       api.prefix = *prefix;
-
-       /* for each nexthop */
-       for (ALL_LIST_ELEMENTS_RO(route_info->nexthops6, node, nexthop6)) {
-               if (!IN6_IS_ADDR_LINKLOCAL(&nexthop6->ip6)
-                   && !IN6_IS_ADDR_UNSPECIFIED(&nexthop6->ip6)) {
-                       continue;
+               break;
+       case AF_INET6:
+               for (ALL_LIST_ELEMENTS_RO(route_info->nexthops6, node,
+                                         nexthop6)) {
+                       if (!IN6_IS_ADDR_LINKLOCAL(&nexthop6->ip6)
+                           && !IN6_IS_ADDR_UNSPECIFIED(&nexthop6->ip6)) {
+                               continue;
+                       }
+
+                       api_nh = &api.nexthops[count];
+                       api_nh->gate.ipv6 = nexthop6->ip6;
+                       api_nh->ifindex = nexthop6->ifindex;
+                       api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX;
+                       count++;
                }
-
-               api_nh = &api.nexthops[count];
-               api_nh->gate.ipv6 = nexthop6->ip6;
-               api_nh->ifindex = nexthop6->ifindex;
-               api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX;
-               count++;
+               break;
        }
        if (!count)
                return;
@@ -357,8 +314,8 @@ static void isis_zebra_route_add_ipv6(struct prefix *prefix,
        UNSET_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ZEBRA_RESYNC);
 }
 
-static void isis_zebra_route_del_ipv6(struct prefix *prefix,
-                                     struct isis_route_info *route_info)
+static void isis_zebra_route_del_route(struct prefix *prefix,
+                                      struct isis_route_info *route_info)
 {
        struct zapi_route api;
 
@@ -381,18 +338,10 @@ void isis_zebra_route_update(struct prefix *prefix,
        if (zclient->sock < 0)
                return;
 
-       if (CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ACTIVE)) {
-               if (prefix->family == AF_INET)
-                       isis_zebra_route_add_ipv4(prefix, route_info);
-               else if (prefix->family == AF_INET6)
-                       isis_zebra_route_add_ipv6(prefix, route_info);
-       } else {
-               if (prefix->family == AF_INET)
-                       isis_zebra_route_del_ipv4(prefix, route_info);
-               else if (prefix->family == AF_INET6)
-                       isis_zebra_route_del_ipv6(prefix, route_info);
-       }
-       return;
+       if (CHECK_FLAG(route_info->flag, ISIS_ROUTE_FLAG_ACTIVE))
+               isis_zebra_route_add_route(prefix, route_info);
+       else
+               isis_zebra_route_del_route(prefix, route_info);
 }
 
 static int isis_zebra_read_ipv4(int command, struct zclient *zclient,