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>
#include <sockunion.h>
#include <nexthop.h>
#include <nexthop_group.h>
+#include <nexthop_group_private.h>
#include <vty.h>
#include <command.h>
#include <jhash.h>
}
/* 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;
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;
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;
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,
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);
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);
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);
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);
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);
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);
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);
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);
--- /dev/null
+/*
+ * 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__ */
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 \
#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>
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);
copy_nexthops(&nh, pnhc->nexthop, NULL);
- nexthop_add(&nhg->nexthop, nh);
+ _nexthop_add(&nhg->nexthop, nh);
}
static void
#include "vrf.h"
#include "nexthop.h"
#include "nexthop_group.h"
+#include "nexthop_group_private.h"
#include "log.h"
#include "debug.h"
#include "pbr.h"
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);
#include <zebra.h>
#include "lib/nexthop.h"
+#include "lib/nexthop_group_private.h"
#include "lib/routemap.h"
#include "zebra/connected.h"
&newhop->nh_label->label[0]);
resolved_hop->rparent = nexthop;
- nexthop_add(&nexthop->resolved, resolved_hop);
+ _nexthop_add(&nexthop->resolved, resolved_hop);
}
/*
#include "thread.h"
#include "vrf.h"
#include "workqueue.h"
+#include "nexthop_group_private.h"
#include "zebra/zebra_router.h"
#include "zebra/connected.h"
/* 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++;
}
*/
nexthop = nexthop_new();
nexthop->type = NEXTHOP_TYPE_IPV4;
- nexthop_add(&(re->fib_ng.nexthop), nexthop);
+ _nexthop_add(&(re->fib_ng.nexthop), nexthop);
}
done: