]> git.puffer.fish Git - matthieu/frr.git/commitdiff
sharpd: Re-arrange route_add|delete
authorDonald Sharp <sharpd@nvidia.com>
Fri, 6 Nov 2020 13:19:53 +0000 (08:19 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Sun, 15 Nov 2020 19:50:17 +0000 (14:50 -0500)
These functions are never called outside of sharp_zebra.c, re-arrange
a little to make the inclusions in sharp_zebra.h not needed and
to also have these functions return whether or not the underlying
buffering system was invoked in stream sending.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
sharpd/sharp_zebra.c
sharpd/sharp_zebra.h

index 7a335fca3b67a19b9dfa0f62a7f0cf9e933122c6..bdefad060a67e49a978ed1324a01b387a120723c 100644 (file)
@@ -216,6 +216,91 @@ int sharp_install_lsps_helper(bool install_p, bool update_p,
        return ret;
 }
 
+/*
+ * route_add - Encodes a route to zebra
+ *
+ * This function returns true when the route was buffered
+ * by the underlying stream system
+ */
+static bool route_add(const struct prefix *p, vrf_id_t vrf_id, uint8_t instance,
+                     uint32_t nhgid, const struct nexthop_group *nhg,
+                     const struct nexthop_group *backup_nhg)
+{
+       struct zapi_route api;
+       struct zapi_nexthop *api_nh;
+       struct nexthop *nh;
+       int i = 0;
+
+       memset(&api, 0, sizeof(api));
+       api.vrf_id = vrf_id;
+       api.type = ZEBRA_ROUTE_SHARP;
+       api.instance = instance;
+       api.safi = SAFI_UNICAST;
+       memcpy(&api.prefix, p, sizeof(*p));
+
+       SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION);
+       SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
+
+       /* Only send via ID if nhgroup has been successfully installed */
+       if (nhgid && sharp_nhgroup_id_is_installed(nhgid)) {
+               SET_FLAG(api.message, ZAPI_MESSAGE_NHG);
+               api.nhgid = nhgid;
+       } else {
+               for (ALL_NEXTHOPS_PTR(nhg, nh)) {
+                       api_nh = &api.nexthops[i];
+
+                       zapi_nexthop_from_nexthop(api_nh, nh);
+
+                       i++;
+               }
+               api.nexthop_num = i;
+       }
+
+       /* Include backup nexthops, if present */
+       if (backup_nhg && backup_nhg->nexthop) {
+               SET_FLAG(api.message, ZAPI_MESSAGE_BACKUP_NEXTHOPS);
+
+               i = 0;
+               for (ALL_NEXTHOPS_PTR(backup_nhg, nh)) {
+                       api_nh = &api.backup_nexthops[i];
+
+                       zapi_backup_nexthop_from_nexthop(api_nh, nh);
+
+                       i++;
+               }
+
+               api.backup_nexthop_num = i;
+       }
+
+       if (zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api) == 1)
+               return true;
+       else
+               return false;
+}
+
+/*
+ * route_delete - Encodes a route for deletion to zebra
+ *
+ * This function returns true when the route sent was
+ * buffered by the underlying stream system.
+ */
+static bool route_delete(struct prefix *p, vrf_id_t vrf_id, uint8_t instance)
+{
+       struct zapi_route api;
+
+       memset(&api, 0, sizeof(api));
+       api.vrf_id = vrf_id;
+       api.type = ZEBRA_ROUTE_SHARP;
+       api.safi = SAFI_UNICAST;
+       api.instance = instance;
+       memcpy(&api.prefix, p, sizeof(*p));
+
+       if (zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api) == 1)
+               return true;
+       else
+               return false;
+}
+
 void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id,
                                 uint8_t instance, uint32_t nhgid,
                                 const struct nexthop_group *nhg,
@@ -408,74 +493,6 @@ void nhg_del(uint32_t id)
        zclient_nhg_send(zclient, ZEBRA_NHG_DEL, &api_nhg);
 }
 
-void route_add(const struct prefix *p, vrf_id_t vrf_id, uint8_t instance,
-              uint32_t nhgid, const struct nexthop_group *nhg,
-              const struct nexthop_group *backup_nhg)
-{
-       struct zapi_route api;
-       struct zapi_nexthop *api_nh;
-       struct nexthop *nh;
-       int i = 0;
-
-       memset(&api, 0, sizeof(api));
-       api.vrf_id = vrf_id;
-       api.type = ZEBRA_ROUTE_SHARP;
-       api.instance = instance;
-       api.safi = SAFI_UNICAST;
-       memcpy(&api.prefix, p, sizeof(*p));
-
-       SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION);
-       SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
-
-       /* Only send via ID if nhgroup has been successfully installed */
-       if (nhgid && sharp_nhgroup_id_is_installed(nhgid)) {
-               SET_FLAG(api.message, ZAPI_MESSAGE_NHG);
-               api.nhgid = nhgid;
-       } else {
-               for (ALL_NEXTHOPS_PTR(nhg, nh)) {
-                       api_nh = &api.nexthops[i];
-
-                       zapi_nexthop_from_nexthop(api_nh, nh);
-
-                       i++;
-               }
-               api.nexthop_num = i;
-       }
-
-       /* Include backup nexthops, if present */
-       if (backup_nhg && backup_nhg->nexthop) {
-               SET_FLAG(api.message, ZAPI_MESSAGE_BACKUP_NEXTHOPS);
-
-               i = 0;
-               for (ALL_NEXTHOPS_PTR(backup_nhg, nh)) {
-                       api_nh = &api.backup_nexthops[i];
-
-                       zapi_backup_nexthop_from_nexthop(api_nh, nh);
-
-                       i++;
-               }
-
-               api.backup_nexthop_num = i;
-       }
-
-       zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
-}
-
-void route_delete(struct prefix *p, vrf_id_t vrf_id, uint8_t instance)
-{
-       struct zapi_route api;
-
-       memset(&api, 0, sizeof(api));
-       api.vrf_id = vrf_id;
-       api.type = ZEBRA_ROUTE_SHARP;
-       api.safi = SAFI_UNICAST;
-       api.instance = instance;
-       memcpy(&api.prefix, p, sizeof(*p));
-       zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);
-
-       return;
-}
-
 void sharp_zebra_nexthop_watch(struct prefix *p, vrf_id_t vrf_id, bool import,
                               bool watch, bool connected)
 {
index 4a767ababf20833dd29596c2221f627617de2339..8c5fa5e15e06261edbad4b1a5ec4cee9954cb477 100644 (file)
@@ -32,10 +32,6 @@ extern void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label);
 extern void nhg_add(uint32_t id, const struct nexthop_group *nhg,
                    const struct nexthop_group *backup_nhg);
 extern void nhg_del(uint32_t id);
-extern void route_add(const struct prefix *p, vrf_id_t, uint8_t instance,
-                     uint32_t nhgid, const struct nexthop_group *nhg,
-                     const struct nexthop_group *backup_nhg);
-extern void route_delete(struct prefix *p, vrf_id_t vrf_id, uint8_t instance);
 extern void sharp_zebra_nexthop_watch(struct prefix *p, vrf_id_t vrf_id,
                                      bool import, bool watch, bool connected);