]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Private api for nexthop_group manipulation 4323/head
authorStephen Worley <sworley@cumulusnetworks.com>
Mon, 24 Jun 2019 18:04:13 +0000 (14:04 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Wed, 26 Jun 2019 02:58:48 +0000 (22:58 -0400)
Add a file that exposes functions which modify nexthop groups.
Nexthop groups are techincally immutable but there are a
few special cases where we need direct access to add/remove
nexthops after the group has been made. This file provides a
way to expose those functions in a way that makes it clear
this is a private/hidden api.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
lib/nexthop_group.c
lib/nexthop_group.h
lib/nexthop_group_private.h [new file with mode: 0644]
lib/subdir.am
pbrd/pbr_nht.c
pbrd/pbr_vty.c
zebra/zebra_nhg.c
zebra/zebra_rib.c

index 7b3fb156255aa7044de8285722059d3078e48a8f..5602018b30c3889e48dbeb954f270b447f529722 100644 (file)
@@ -23,6 +23,7 @@
 #include <sockunion.h>
 #include <nexthop.h>
 #include <nexthop_group.h>
+#include <nexthop_group_private.h>
 #include <vty.h>
 #include <command.h>
 #include <jhash.h>
@@ -112,7 +113,7 @@ void nexthop_group_delete(struct nexthop_group **nhg)
 }
 
 /* Add nexthop to the end of a nexthop list.  */
-void nexthop_add(struct nexthop **target, struct nexthop *nexthop)
+void _nexthop_add(struct nexthop **target, struct nexthop *nexthop)
 {
        struct nexthop *last;
 
@@ -125,8 +126,8 @@ void nexthop_add(struct nexthop **target, struct nexthop *nexthop)
        nexthop->prev = last;
 }
 
-void nexthop_group_add_sorted(struct nexthop_group *nhg,
-                             struct nexthop *nexthop)
+void _nexthop_group_add_sorted(struct nexthop_group *nhg,
+                              struct nexthop *nexthop)
 {
        struct nexthop *position, *prev;
 
@@ -151,11 +152,10 @@ void nexthop_group_add_sorted(struct nexthop_group *nhg,
                prev->next = nexthop;
        else
                nhg->nexthop = nexthop;
-
 }
 
 /* Delete nexthop from a nexthop list.  */
-void nexthop_del(struct nexthop_group *nhg, struct nexthop *nh)
+void _nexthop_del(struct nexthop_group *nhg, struct nexthop *nh)
 {
        struct nexthop *nexthop;
 
@@ -186,7 +186,7 @@ void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh,
 
        for (nh1 = nh; nh1; nh1 = nh1->next) {
                nexthop = nexthop_dup(nh1, rparent);
-               nexthop_add(tnh, nexthop);
+               _nexthop_add(tnh, nexthop);
 
                if (CHECK_FLAG(nh1->flags, NEXTHOP_FLAG_RECURSIVE))
                        copy_nexthops(&nexthop->resolved, nh1->resolved,
@@ -217,7 +217,7 @@ static void nhgc_delete_nexthops(struct nexthop_group_cmd *nhgc)
        while (nexthop) {
                struct nexthop *next = nexthop_next(nexthop);
 
-               nexthop_del(&nhgc->nhg, nexthop);
+               _nexthop_del(&nhgc->nhg, nexthop);
                if (nhg_hooks.del_nexthop)
                        nhg_hooks.del_nexthop(nhgc, nexthop);
 
@@ -481,7 +481,7 @@ DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
        if (no) {
                nexthop_group_unsave_nhop(nhgc, name, addr, intf);
                if (nh) {
-                       nexthop_del(&nhgc->nhg, nh);
+                       _nexthop_del(&nhgc->nhg, nh);
 
                        if (nhg_hooks.del_nexthop)
                                nhg_hooks.del_nexthop(nhgc, nh);
@@ -494,7 +494,7 @@ DEFPY(ecmp_nexthops, ecmp_nexthops_cmd,
                        nh = nexthop_new();
 
                        memcpy(nh, &nhop, sizeof(nhop));
-                       nexthop_add(&nhgc->nhg.nexthop, nh);
+                       _nexthop_add(&nhgc->nhg.nexthop, nh);
                }
 
                nexthop_group_save_nhop(nhgc, name, addr, intf);
@@ -618,7 +618,7 @@ void nexthop_group_enable_vrf(struct vrf *vrf)
                        nh = nexthop_new();
 
                        memcpy(nh, &nhop, sizeof(nhop));
-                       nexthop_add(&nhgc->nhg.nexthop, nh);
+                       _nexthop_add(&nhgc->nhg.nexthop, nh);
 
                        if (nhg_hooks.add_nexthop)
                                nhg_hooks.add_nexthop(nhgc, nh);
@@ -651,7 +651,7 @@ void nexthop_group_disable_vrf(struct vrf *vrf)
                        if (nh->vrf_id != vrf->vrf_id)
                                continue;
 
-                       nexthop_del(&nhgc->nhg, nh);
+                       _nexthop_del(&nhgc->nhg, nh);
 
                        if (nhg_hooks.del_nexthop)
                                nhg_hooks.del_nexthop(nhgc, nh);
@@ -701,7 +701,7 @@ void nexthop_group_interface_state_change(struct interface *ifp,
                                nh = nexthop_new();
 
                                memcpy(nh, &nhop, sizeof(nhop));
-                               nexthop_add(&nhgc->nhg.nexthop, nh);
+                               _nexthop_add(&nhgc->nhg.nexthop, nh);
 
                                if (nhg_hooks.add_nexthop)
                                        nhg_hooks.add_nexthop(nhgc, nh);
@@ -725,7 +725,7 @@ void nexthop_group_interface_state_change(struct interface *ifp,
                                if (oldifindex != nh->ifindex)
                                        continue;
 
-                               nexthop_del(&nhgc->nhg, nh);
+                               _nexthop_del(&nhgc->nhg, nh);
 
                                if (nhg_hooks.del_nexthop)
                                        nhg_hooks.del_nexthop(nhgc, nh);
index 104e2051f5e66038351d987ace373ed7bbec7a96..4f4d40eb331eb623a0d676e7fc89dc40af6f481e 100644 (file)
@@ -42,12 +42,8 @@ struct nexthop_group {
 struct nexthop_group *nexthop_group_new(void);
 void nexthop_group_delete(struct nexthop_group **nhg);
 
-void nexthop_add(struct nexthop **target, struct nexthop *nexthop);
-void nexthop_group_add_sorted(struct nexthop_group *nhg,
-                             struct nexthop *nexthop);
 void nexthop_group_copy(struct nexthop_group *to,
                        struct nexthop_group *from);
-void nexthop_del(struct nexthop_group *nhg, struct nexthop *nexthop);
 void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh,
                   struct nexthop *rparent);
 
diff --git a/lib/nexthop_group_private.h b/lib/nexthop_group_private.h
new file mode 100644 (file)
index 0000000..cdd0df0
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Nexthop Group Private Functions.
+ * Copyright (C) 2019 Cumulus Networks, Inc.
+ *                    Stephen Worley
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * These functions should only be used internally for nexthop groups
+ * and in certain special cases. Please use `lib/nexthop_group.h` for
+ * any general nexthop_group api needs.
+ */
+
+#ifndef __NEXTHOP_GROUP_PRIVATE__
+#define __NEXTHOP_GROUP_PRIVATE__
+
+#include <nexthop_group.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void _nexthop_add(struct nexthop **target, struct nexthop *nexthop);
+void _nexthop_del(struct nexthop_group *nhg, struct nexthop *nexthop);
+void _nexthop_group_add_sorted(struct nexthop_group *nhg,
+                              struct nexthop *nexthop);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __NEXTHOP_GROUP_PRIVATE__ */
index 8b6cbe2aeb2f8b93d06c249a99da329efcac7194..8223bd547c88e69b231487c4044a0d7062831379 100644 (file)
@@ -188,6 +188,7 @@ pkginclude_HEADERS += \
        lib/network.h \
        lib/nexthop.h \
        lib/nexthop_group.h \
+       lib/nexthop_group_private.h \
        lib/northbound.h \
        lib/northbound_cli.h \
        lib/northbound_db.h \
index 22dd6f1a38337cd91018153e8441dd8329cc6591..a69bb00848a8d28f980ab4c88e6681bca148faaa 100644 (file)
@@ -21,7 +21,8 @@
 
 #include <log.h>
 #include <nexthop.h>
-#include <nexthop_group.h>
+#include "nexthop_group.h"
+#include "nexthop_group_private.h"
 #include <hash.h>
 #include <jhash.h>
 #include <vty.h>
@@ -576,7 +577,7 @@ void pbr_nht_delete_individual_nexthop(struct pbr_map_sequence *pbrms)
 
        hash_release(pbr_nhg_hash, pnhgc);
 
-       nexthop_del(pbrms->nhg, nh);
+       _nexthop_del(pbrms->nhg, nh);
        nexthop_free(nh);
        nexthop_group_delete(&pbrms->nhg);
        XFREE(MTYPE_TMP, pbrms->internal_nhg_name);
@@ -723,7 +724,7 @@ static void pbr_nexthop_group_cache_iterate_to_group(struct hash_bucket *b,
 
        copy_nexthops(&nh, pnhc->nexthop, NULL);
 
-       nexthop_add(&nhg->nexthop, nh);
+       _nexthop_add(&nhg->nexthop, nh);
 }
 
 static void
index a71c712ea71e9b28584721e2c40dfa362d979241..95f38563b1de07140ed30c223329d2c6b8fe6af8 100644 (file)
@@ -25,6 +25,7 @@
 #include "vrf.h"
 #include "nexthop.h"
 #include "nexthop_group.h"
+#include "nexthop_group_private.h"
 #include "log.h"
 #include "debug.h"
 #include "pbr.h"
@@ -329,7 +330,7 @@ DEFPY(pbr_map_nexthop, pbr_map_nexthop_cmd,
                nh = nexthop_new();
 
                memcpy(nh, &nhop, sizeof(nhop));
-               nexthop_add(&pbrms->nhg->nexthop, nh);
+               _nexthop_add(&pbrms->nhg->nexthop, nh);
 
                pbr_nht_add_individual_nexthop(pbrms);
                pbr_map_check(pbrms);
index f2a76d1c5297e8e1d8b3c77c016bfa3f50dc77e5..4a88296051a9a79efd7a578fad73d14c715da36c 100644 (file)
@@ -23,6 +23,7 @@
 #include <zebra.h>
 
 #include "lib/nexthop.h"
+#include "lib/nexthop_group_private.h"
 #include "lib/routemap.h"
 
 #include "zebra/connected.h"
@@ -100,7 +101,7 @@ static void nexthop_set_resolved(afi_t afi, const struct nexthop *newhop,
                                   &newhop->nh_label->label[0]);
 
        resolved_hop->rparent = nexthop;
-       nexthop_add(&nexthop->resolved, resolved_hop);
+       _nexthop_add(&nexthop->resolved, resolved_hop);
 }
 
 /*
index 2df24f75c5e1ed1b1d6a85c68218aeee94e2106e..5b0ca6570e72836a6f524a6818d0793150dcbf22 100644 (file)
@@ -36,6 +36,7 @@
 #include "thread.h"
 #include "vrf.h"
 #include "workqueue.h"
+#include "nexthop_group_private.h"
 
 #include "zebra/zebra_router.h"
 #include "zebra/connected.h"
@@ -192,7 +193,7 @@ int zebra_check_addr(const struct prefix *p)
 /* Add nexthop to the end of a rib node's nexthop list */
 void route_entry_nexthop_add(struct route_entry *re, struct nexthop *nexthop)
 {
-       nexthop_add(&re->ng.nexthop, nexthop);
+       _nexthop_add(&re->ng.nexthop, nexthop);
        re->nexthop_num++;
 }
 
@@ -1589,7 +1590,7 @@ static bool rib_update_re_from_ctx(struct route_entry *re,
                 */
                nexthop = nexthop_new();
                nexthop->type = NEXTHOP_TYPE_IPV4;
-               nexthop_add(&(re->fib_ng.nexthop), nexthop);
+               _nexthop_add(&(re->fib_ng.nexthop), nexthop);
        }
 
 done: