#include "hook.h"
#include "zebra/zebra_l2.h"
-#include "zebra/zebra_nhg.h"
+#include "zebra/zebra_nhg_private.h"
#ifdef __cplusplus
extern "C" {
zebra/zebra_mpls.h \
zebra/zebra_mroute.h \
zebra/zebra_nhg.h \
+ zebra/zebra_nhg_private.h \
zebra/zebra_ns.h \
zebra/zebra_pbr.h \
zebra/zebra_ptm.h \
#include "zebra/connected.h"
#include "zebra/debug.h"
#include "zebra/zebra_router.h"
-#include "zebra/zebra_nhg.h"
+#include "zebra/zebra_nhg_private.h"
#include "zebra/zebra_rnh.h"
#include "zebra/zebra_routemap.h"
#include "zebra/zebra_memory.h"
static void depends_decrement_free(struct nhg_connected_tree_head *head);
-void nhg_connected_free(struct nhg_connected *dep)
+static void nhg_connected_free(struct nhg_connected *dep)
{
XFREE(MTYPE_NHG_CONNECTED, dep);
}
-struct nhg_connected *nhg_connected_new(struct nhg_hash_entry *nhe)
+static struct nhg_connected *nhg_connected_new(struct nhg_hash_entry *nhe)
{
struct nhg_connected *new = NULL;
return nhe;
}
-uint32_t zebra_nhg_get_resolved_id(uint32_t id)
-{
- struct nhg_hash_entry *nhe = NULL;
-
- nhe = zebra_nhg_lookup_id(id);
-
- if (!nhe) {
- flog_err(
- EC_ZEBRA_TABLE_LOOKUP_FAILED,
- "Zebra failed to lookup a resolved nexthop hash entry id=%u",
- id);
- return id;
- }
-
- if (CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_RECURSIVE))
- nhe = zebra_nhg_resolve(nhe);
-
- return nhe->id;
-}
-
unsigned int zebra_nhg_depends_count(const struct nhg_hash_entry *nhe)
{
return nhg_connected_tree_count(&nhe->nhg_depends);
return nhg_connected_tree_is_empty(&nhe->nhg_depends);
}
-void zebra_nhg_depends_del(struct nhg_hash_entry *from,
- struct nhg_hash_entry *depend)
+static void zebra_nhg_depends_del(struct nhg_hash_entry *from,
+ struct nhg_hash_entry *depend)
{
nhg_connected_tree_del_nhe(&from->nhg_depends, depend);
}
-void zebra_nhg_depends_add(struct nhg_hash_entry *to,
- struct nhg_hash_entry *depend)
-{
- nhg_connected_tree_add_nhe(&to->nhg_depends, depend);
-}
-
-void zebra_nhg_depends_init(struct nhg_hash_entry *nhe)
+static void zebra_nhg_depends_init(struct nhg_hash_entry *nhe)
{
nhg_connected_tree_init(&nhe->nhg_depends);
}
-/* Release this nhe from anything that it depends on */
-static void zebra_nhg_depends_release(struct nhg_hash_entry *nhe)
-{
- if (!zebra_nhg_depends_is_empty(nhe)) {
- struct nhg_connected *rb_node_dep = NULL;
-
- frr_each_safe(nhg_connected_tree, &nhe->nhg_depends,
- rb_node_dep) {
- zebra_nhg_dependents_del(rb_node_dep->nhe, nhe);
- }
- }
-}
-
unsigned int zebra_nhg_dependents_count(const struct nhg_hash_entry *nhe)
{
return nhg_connected_tree_count(&nhe->nhg_dependents);
}
+
bool zebra_nhg_dependents_is_empty(const struct nhg_hash_entry *nhe)
{
return nhg_connected_tree_is_empty(&nhe->nhg_dependents);
}
-void zebra_nhg_dependents_del(struct nhg_hash_entry *from,
- struct nhg_hash_entry *dependent)
+static void zebra_nhg_dependents_del(struct nhg_hash_entry *from,
+ struct nhg_hash_entry *dependent)
{
nhg_connected_tree_del_nhe(&from->nhg_dependents, dependent);
}
-void zebra_nhg_dependents_add(struct nhg_hash_entry *to,
- struct nhg_hash_entry *dependent)
+static void zebra_nhg_dependents_add(struct nhg_hash_entry *to,
+ struct nhg_hash_entry *dependent)
{
nhg_connected_tree_add_nhe(&to->nhg_dependents, dependent);
}
-void zebra_nhg_dependents_init(struct nhg_hash_entry *nhe)
+static void zebra_nhg_dependents_init(struct nhg_hash_entry *nhe)
{
nhg_connected_tree_init(&nhe->nhg_dependents);
}
}
}
+/* Release this nhe from anything that it depends on */
+static void zebra_nhg_depends_release(struct nhg_hash_entry *nhe)
+{
+ if (!zebra_nhg_depends_is_empty(nhe)) {
+ struct nhg_connected *rb_node_dep = NULL;
+
+ frr_each_safe(nhg_connected_tree, &nhe->nhg_depends,
+ rb_node_dep) {
+ zebra_nhg_dependents_del(rb_node_dep->nhe, nhe);
+ }
+ }
+}
+
+
struct nhg_hash_entry *zebra_nhg_lookup_id(uint32_t id)
{
struct nhg_hash_entry lookup = {};
return hash_lookup(zrouter.nhgs_id, &lookup);
}
-int zebra_nhg_insert_id(struct nhg_hash_entry *nhe)
+static int zebra_nhg_insert_id(struct nhg_hash_entry *nhe)
{
if (hash_lookup(zrouter.nhgs_id, nhe)) {
flog_err(
return 0;
}
+static void zebra_nhg_set_if(struct nhg_hash_entry *nhe, struct interface *ifp)
+{
+ nhe->ifp = ifp;
+ if_nhg_dependents_add(ifp, nhe);
+}
+
static void
zebra_nhg_connect_depends(struct nhg_hash_entry *nhe,
struct nhg_connected_tree_head nhg_depends)
lookup.nhg_depends = *nhg_depends;
else {
if (nhg->nexthop->next) {
- nhg_connected_tree_init(&lookup.nhg_depends);
+ zebra_nhg_depends_init(&lookup);
/* If its a group, create a dependency tree */
struct nexthop *nh = NULL;
nh, afi);
} else if (CHECK_FLAG(nhg->nexthop->flags,
NEXTHOP_FLAG_RECURSIVE)) {
- nhg_connected_tree_init(&lookup.nhg_depends);
+ zebra_nhg_depends_init(&lookup);
handle_recursive_depend(&lookup.nhg_depends,
nhg->nexthop->resolved,
afi);
return nhe;
}
-void zebra_nhg_free_members(struct nhg_hash_entry *nhe)
+static void zebra_nhg_free_members(struct nhg_hash_entry *nhe)
{
nexthop_group_delete(&nhe->nhg);
/* Decrement to remove connection ref */
nhg_connected_tree_increment_ref(&nhe->nhg_depends);
}
-void zebra_nhg_set_if(struct nhg_hash_entry *nhe, struct interface *ifp)
-{
- nhe->ifp = ifp;
- if_nhg_dependents_add(ifp, nhe);
-}
-
static void nexthop_set_resolved(afi_t afi, const struct nexthop *newhop,
struct nexthop *nexthop)
{
PREDECL_RBTREE_UNIQ(nhg_connected_tree);
-
/*
* Hashtables contiaining entries found in `zebra_router`.
*/
/* Was this one we created, either this session or previously? */
#define ZEBRA_NHG_CREATED(NHE) ((NHE->type) == ZEBRA_ROUTE_NHG)
-/* Abstraction for connected trees */
-struct nhg_connected {
- struct nhg_connected_tree_item tree_item;
- struct nhg_hash_entry *nhe;
-};
-
-static int nhg_connected_cmp(const struct nhg_connected *con1,
- const struct nhg_connected *con2)
-{
- return (con1->nhe->id - con2->nhe->id);
-}
-
-DECLARE_RBTREE_UNIQ(nhg_connected_tree, struct nhg_connected, tree_item,
- nhg_connected_cmp);
-
enum nhg_ctx_op_e {
NHG_CTX_OP_NONE = 0,
};
-extern void nhg_connected_free(struct nhg_connected *dep);
-extern struct nhg_connected *nhg_connected_new(struct nhg_hash_entry *nhe);
-
-/* nhg connected tree direct access functions */
-extern void nhg_connected_tree_init(struct nhg_connected_tree_head *head);
-extern void nhg_connected_tree_free(struct nhg_connected_tree_head *head);
-extern bool
-nhg_connected_tree_is_empty(const struct nhg_connected_tree_head *head);
-extern struct nhg_connected *
-nhg_connected_tree_root(struct nhg_connected_tree_head *head);
-extern void nhg_connected_tree_del_nhe(struct nhg_connected_tree_head *head,
- struct nhg_hash_entry *nhe);
-extern void nhg_connected_tree_add_nhe(struct nhg_connected_tree_head *head,
- struct nhg_hash_entry *nhe);
-
/**
* NHE abstracted tree functions.
* Use these where possible instead of the direct ones access ones.
*/
-
-
extern struct nhg_hash_entry *zebra_nhg_resolve(struct nhg_hash_entry *nhe);
-extern uint32_t zebra_nhg_get_resolved_id(uint32_t id);
-/* Depends */
extern unsigned int zebra_nhg_depends_count(const struct nhg_hash_entry *nhe);
extern bool zebra_nhg_depends_is_empty(const struct nhg_hash_entry *nhe);
-extern void zebra_nhg_depends_del(struct nhg_hash_entry *from,
- struct nhg_hash_entry *depend);
-extern void zebra_nhg_depends_add(struct nhg_hash_entry *to,
- struct nhg_hash_entry *depend);
-extern void zebra_nhg_depends_init(struct nhg_hash_entry *nhe);
-/* Dependents */
+
extern unsigned int
zebra_nhg_dependents_count(const struct nhg_hash_entry *nhe);
extern bool zebra_nhg_dependents_is_empty(const struct nhg_hash_entry *nhe);
-extern void zebra_nhg_dependents_del(struct nhg_hash_entry *from,
- struct nhg_hash_entry *dependent);
-extern void zebra_nhg_dependents_add(struct nhg_hash_entry *to,
- struct nhg_hash_entry *dependent);
-extern void zebra_nhg_dependents_init(struct nhg_hash_entry *nhe);
-
+/* Lookup ID, doesn't create */
extern struct nhg_hash_entry *zebra_nhg_lookup_id(uint32_t id);
-extern int zebra_nhg_insert_id(struct nhg_hash_entry *nhe);
+/* Hash functions */
extern uint32_t zebra_nhg_hash_key(const void *arg);
extern uint32_t zebra_nhg_id_key(const void *arg);
extern struct nhg_hash_entry *
zebra_nhg_rib_find(uint32_t id, struct nexthop_group *nhg, afi_t rt_afi);
-
-void zebra_nhg_free_members(struct nhg_hash_entry *nhe);
-void zebra_nhg_free(void *arg);
-void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe);
-void zebra_nhg_increment_ref(struct nhg_hash_entry *nhe);
-
-void zebra_nhg_check_valid(struct nhg_hash_entry *nhe);
-void zebra_nhg_set_if(struct nhg_hash_entry *nhe, struct interface *ifp);
-
-extern int nexthop_active_update(struct route_node *rn, struct route_entry *re);
-
+/* Reference counter functions */
+extern void zebra_nhg_decrement_ref(struct nhg_hash_entry *nhe);
+extern void zebra_nhg_increment_ref(struct nhg_hash_entry *nhe);
extern int zebra_nhg_re_update_ref(struct route_entry *re,
struct nhg_hash_entry *nhe);
+/* Check validity of nhe, if invalid will update dependents as well */
+extern void zebra_nhg_check_valid(struct nhg_hash_entry *nhe);
+
+/* Convert nhe depends to a grp context that can be passed around safely */
extern uint8_t zebra_nhg_nhe2grp(struct nh_grp *grp, struct nhg_hash_entry *nhe,
int size);
-void zebra_nhg_install_kernel(struct nhg_hash_entry *nhe);
-void zebra_nhg_uninstall_kernel(struct nhg_hash_entry *nhe);
+/* Dataplane install/uninstall */
+extern void zebra_nhg_install_kernel(struct nhg_hash_entry *nhe);
+extern void zebra_nhg_uninstall_kernel(struct nhg_hash_entry *nhe);
/* Forward ref of dplane update context type */
struct zebra_dplane_ctx;
-void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx);
+extern void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx);
+
-void zebra_nhg_sweep_table(struct hash *hash);
+/* Sweet the nhg hash tables for old entries on restart */
+extern void zebra_nhg_sweep_table(struct hash *hash);
+
+/* Nexthop resolution processing */
+extern int nexthop_active_update(struct route_node *rn, struct route_entry *re);
#endif
--- /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 nhg_hash_entry
+ * manipulation and in certain special cases.
+ *
+ * Please use `zebra/zebra_nhg.h` for any general nhg_hash_entry api needs.
+ */
+
+#ifndef __ZEBRA_NHG_PRIVATE_H__
+#define __ZEBRA_NHG_PRIVATE_H__
+
+#include "zebra/zebra_nhg.h"
+
+/* Abstraction for connected trees */
+struct nhg_connected {
+ struct nhg_connected_tree_item tree_item;
+ struct nhg_hash_entry *nhe;
+};
+
+static int nhg_connected_cmp(const struct nhg_connected *con1,
+ const struct nhg_connected *con2)
+{
+ return (con1->nhe->id - con2->nhe->id);
+}
+
+DECLARE_RBTREE_UNIQ(nhg_connected_tree, struct nhg_connected, tree_item,
+ nhg_connected_cmp);
+
+/* nhg connected tree direct access functions */
+extern void nhg_connected_tree_init(struct nhg_connected_tree_head *head);
+extern void nhg_connected_tree_free(struct nhg_connected_tree_head *head);
+extern bool
+nhg_connected_tree_is_empty(const struct nhg_connected_tree_head *head);
+extern struct nhg_connected *
+nhg_connected_tree_root(struct nhg_connected_tree_head *head);
+extern void nhg_connected_tree_del_nhe(struct nhg_connected_tree_head *head,
+ struct nhg_hash_entry *nhe);
+extern void nhg_connected_tree_add_nhe(struct nhg_connected_tree_head *head,
+ struct nhg_hash_entry *nhe);
+
+extern void zebra_nhg_free(void *arg);
+
+#endif /* __ZEBRA_NHG_PRIVATE_H__ */
#include "zebra_pbr.h"
#include "zebra_vxlan.h"
#include "zebra_mlag.h"
-#include "zebra_nhg.h"
+#include "zebra_nhg_private.h"
#include "debug.h"
DEFINE_MTYPE_STATIC(ZEBRA, RIB_TABLE_INFO, "RIB table info")