]> git.puffer.fish Git - mirror/frr.git/commitdiff
ripd/ripngd: use the new API to send routes to zebra
authorRenato Westphal <renato@opensourcerouting.org>
Mon, 21 Aug 2017 00:17:09 +0000 (21:17 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Wed, 23 Aug 2017 21:58:35 +0000 (18:58 -0300)
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripd/rip_zebra.c
ripngd/ripng_zebra.c

index f9d2d33f1920503a47474ff5952b7f3f1a0cbbb2..9a9bac51e09074ef0c3a6d1e8608c61bc392d7be 100644 (file)
@@ -39,40 +39,32 @@ struct zclient *zclient = NULL;
 /* Send ECMP routes to zebra. */
 static void rip_zebra_ipv4_send(struct route_node *rp, u_char cmd)
 {
-       static struct in_addr **nexthops = NULL;
-       static unsigned int nexthops_len = 0;
-
        struct list *list = (struct list *)rp->info;
-       struct zapi_ipv4 api;
+       struct zapi_route api;
+       struct zapi_nexthop *api_nh;
        struct listnode *listnode = NULL;
        struct rip_info *rinfo = NULL;
        int count = 0;
 
+       memset(&api, 0, sizeof(api));
        api.vrf_id = VRF_DEFAULT;
        api.type = ZEBRA_ROUTE_RIP;
-       api.instance = 0;
-       api.flags = 0;
-       api.message = 0;
        api.safi = SAFI_UNICAST;
 
-       if (nexthops_len < listcount(list)) {
-               nexthops_len = listcount(list);
-               nexthops = XREALLOC(MTYPE_TMP, nexthops,
-                                   nexthops_len * sizeof(struct in_addr *));
-       }
-
        SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
        for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
-               nexthops[count++] = &rinfo->nexthop;
-               if (cmd == ZEBRA_IPV4_ROUTE_ADD)
+               api_nh = &api.nexthops[count];
+               api_nh->gate.ipv4 = rinfo->nexthop;
+               api_nh->type = NEXTHOP_TYPE_IPV4;
+               if (cmd == ZEBRA_ROUTE_ADD)
                        SET_FLAG(rinfo->flags, RIP_RTF_FIB);
                else
                        UNSET_FLAG(rinfo->flags, RIP_RTF_FIB);
+               count++;
        }
 
-       api.nexthop = nexthops;
+       api.prefix = rp->p;
        api.nexthop_num = count;
-       api.ifindex_num = 0;
 
        rinfo = listgetdata(listhead(list));
 
@@ -89,19 +81,19 @@ static void rip_zebra_ipv4_send(struct route_node *rp, u_char cmd)
                api.tag = rinfo->tag;
        }
 
-       zapi_ipv4_route(cmd, zclient, (struct prefix_ipv4 *)&rp->p, &api);
+       zclient_route_send(cmd, zclient, &api);
 
        if (IS_RIP_DEBUG_ZEBRA) {
                if (rip->ecmp)
                        zlog_debug("%s: %s/%d nexthops %d",
-                                  (cmd == ZEBRA_IPV4_ROUTE_ADD)
+                                  (cmd == ZEBRA_ROUTE_ADD)
                                           ? "Install into zebra"
                                           : "Delete from zebra",
                                   inet_ntoa(rp->p.u.prefix4), rp->p.prefixlen,
                                   count);
                else
                        zlog_debug("%s: %s/%d",
-                                  (cmd == ZEBRA_IPV4_ROUTE_ADD)
+                                  (cmd == ZEBRA_ROUTE_ADD)
                                           ? "Install into zebra"
                                           : "Delete from zebra",
                                   inet_ntoa(rp->p.u.prefix4), rp->p.prefixlen);
@@ -113,13 +105,13 @@ static void rip_zebra_ipv4_send(struct route_node *rp, u_char cmd)
 /* Add/update ECMP routes to zebra. */
 void rip_zebra_ipv4_add(struct route_node *rp)
 {
-       rip_zebra_ipv4_send(rp, ZEBRA_IPV4_ROUTE_ADD);
+       rip_zebra_ipv4_send(rp, ZEBRA_ROUTE_ADD);
 }
 
 /* Delete ECMP routes from zebra. */
 void rip_zebra_ipv4_delete(struct route_node *rp)
 {
-       rip_zebra_ipv4_send(rp, ZEBRA_IPV4_ROUTE_DELETE);
+       rip_zebra_ipv4_send(rp, ZEBRA_ROUTE_DELETE);
 }
 
 /* Zebra route add and delete treatment. */
index 3845028264c5ee77a1a3f730659e74afc9af72f2..a5ed5c7b2c507b78d99f03a9626e2b1a46ab3385 100644 (file)
@@ -39,47 +39,33 @@ struct zclient *zclient = NULL;
 /* Send ECMP routes to zebra. */
 static void ripng_zebra_ipv6_send(struct route_node *rp, u_char cmd)
 {
-       static struct in6_addr **nexthops = NULL;
-       static ifindex_t *ifindexes = NULL;
-       static unsigned int nexthops_len = 0;
-
        struct list *list = (struct list *)rp->info;
-       struct zapi_ipv6 api;
+       struct zapi_route api;
+       struct zapi_nexthop *api_nh;
        struct listnode *listnode = NULL;
        struct ripng_info *rinfo = NULL;
        int count = 0;
 
+       memset(&api, 0, sizeof(api));
        api.vrf_id = VRF_DEFAULT;
        api.type = ZEBRA_ROUTE_RIPNG;
-       api.instance = 0;
-       api.flags = 0;
-       api.message = 0;
        api.safi = SAFI_UNICAST;
-
-       if (nexthops_len < listcount(list)) {
-               nexthops_len = listcount(list);
-               nexthops = XREALLOC(MTYPE_TMP, nexthops,
-                                   nexthops_len * sizeof(struct in6_addr *));
-               ifindexes = XREALLOC(MTYPE_TMP, ifindexes,
-                                    nexthops_len * sizeof(unsigned int));
-       }
+       api.prefix = rp->p;
 
        SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
-       SET_FLAG(api.message, ZAPI_MESSAGE_IFINDEX);
        for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) {
-               nexthops[count] = &rinfo->nexthop;
-               ifindexes[count] = rinfo->ifindex;
+               api_nh = &api.nexthops[count];
+               api_nh->gate.ipv6 = rinfo->nexthop;
+               api_nh->ifindex = rinfo->ifindex;
+               api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX;
                count++;
-               if (cmd == ZEBRA_IPV6_ROUTE_ADD)
+               if (cmd == ZEBRA_ROUTE_ADD)
                        SET_FLAG(rinfo->flags, RIPNG_RTF_FIB);
                else
                        UNSET_FLAG(rinfo->flags, RIPNG_RTF_FIB);
        }
 
-       api.nexthop = nexthops;
        api.nexthop_num = count;
-       api.ifindex = ifindexes;
-       api.ifindex_num = count;
 
        rinfo = listgetdata(listhead(list));
 
@@ -91,36 +77,35 @@ static void ripng_zebra_ipv6_send(struct route_node *rp, u_char cmd)
                api.tag = rinfo->tag;
        }
 
-       zapi_ipv6_route(cmd, zclient, (struct prefix_ipv6 *)&rp->p, NULL, &api);
+       zclient_route_send(cmd, zclient, &api);
 
        if (IS_RIPNG_DEBUG_ZEBRA) {
                if (ripng->ecmp)
                        zlog_debug("%s: %s/%d nexthops %d",
-                                  (cmd == ZEBRA_IPV6_ROUTE_ADD)
+                                  (cmd == ZEBRA_ROUTE_ADD)
                                           ? "Install into zebra"
                                           : "Delete from zebra",
                                   inet6_ntoa(rp->p.u.prefix6), rp->p.prefixlen,
                                   count);
                else
-                       zlog_debug("%s: %s/%d",
-                                  (cmd == ZEBRA_IPV6_ROUTE_ADD)
-                                          ? "Install into zebra"
-                                          : "Delete from zebra",
-                                  inet6_ntoa(rp->p.u.prefix6),
-                                  rp->p.prefixlen);
+                       zlog_debug(
+                               "%s: %s/%d",
+                               (cmd == ZEBRA_ROUTE_ADD) ? "Install into zebra"
+                                                        : "Delete from zebra",
+                               inet6_ntoa(rp->p.u.prefix6), rp->p.prefixlen);
        }
 }
 
 /* Add/update ECMP routes to zebra. */
 void ripng_zebra_ipv6_add(struct route_node *rp)
 {
-       ripng_zebra_ipv6_send(rp, ZEBRA_IPV6_ROUTE_ADD);
+       ripng_zebra_ipv6_send(rp, ZEBRA_ROUTE_ADD);
 }
 
 /* Delete ECMP routes from zebra. */
 void ripng_zebra_ipv6_delete(struct route_node *rp)
 {
-       ripng_zebra_ipv6_send(rp, ZEBRA_IPV6_ROUTE_DELETE);
+       ripng_zebra_ipv6_send(rp, ZEBRA_ROUTE_DELETE);
 }
 
 /* Zebra route add and delete treatment. */