summaryrefslogtreecommitdiff
path: root/zebra/interface.c
diff options
context:
space:
mode:
authorStephen Worley <sworley@cumulusnetworks.com>2019-05-14 09:53:19 -0700
committerStephen Worley <sworley@cumulusnetworks.com>2019-10-25 11:13:39 -0400
commitfe593b781d8a927bd496c77799312cc64a565141 (patch)
treecb9b598e38087db08bd6bb6232010396f30af262 /zebra/interface.c
parenta15d4c0089a6b8f59932df39357725feadfb9f91 (diff)
zebra: Re-organize/expose nhg_connected
Re-organize and expose the nhg_connected functions so that it can be used outside zebra_nhg.c. And then abstract those into zebra_nhg_depends_* and zebra_nhg_depenents_* functons. Switch the ifp struct to use an RB tree for its dependents, making use of the nhg_connected functions. Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
Diffstat (limited to 'zebra/interface.c')
-rw-r--r--zebra/interface.c105
1 files changed, 55 insertions, 50 deletions
diff --git a/zebra/interface.c b/zebra/interface.c
index 3eb0e68537..8fe7af3f2a 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -53,7 +53,6 @@
#include "zebra/zebra_errors.h"
DEFINE_MTYPE_STATIC(ZEBRA, ZINFO, "Zebra Interface Information")
-DEFINE_MTYPE_STATIC(ZEBRA, NHE_CONNECTED, "Nexthops Connected")
#define ZEBRA_PTM_SUPPORT
@@ -108,6 +107,17 @@ static void zebra_if_node_destroy(route_table_delegate_t *delegate,
route_node_destroy(delegate, table, node);
}
+static void zebra_if_nhg_dependents_free(struct zebra_if *zebra_if)
+{
+ nhg_connected_head_free(&zebra_if->nhg_dependents);
+}
+
+static void zebra_if_nhg_dependents_init(struct zebra_if *zebra_if)
+{
+ nhg_connected_head_init(&zebra_if->nhg_dependents);
+}
+
+
route_table_delegate_t zebra_if_table_delegate = {
.create_node = route_node_create,
.destroy_node = zebra_if_node_destroy};
@@ -122,8 +132,7 @@ static int if_zebra_new_hook(struct interface *ifp)
zebra_if->multicast = IF_ZEBRA_MULTICAST_UNSPEC;
zebra_if->shutdown = IF_ZEBRA_SHUTDOWN_OFF;
- zebra_if->nhe_connected = list_new();
- zebra_if->nhe_connected->del = (void (*)(void *))nhe_connected_free;
+ zebra_if_nhg_dependents_init(zebra_if);
zebra_ptm_if_init(zebra_if);
@@ -201,9 +210,10 @@ static int if_zebra_delete_hook(struct interface *ifp)
list_delete(&rtadv->AdvDNSSLList);
#endif /* HAVE_RTADV */
- list_delete(&zebra_if->nhe_connected);
+ zebra_if_nhg_dependents_free(zebra_if);
XFREE(MTYPE_TMP, zebra_if->desc);
+
THREAD_OFF(zebra_if->speed_update);
XFREE(MTYPE_ZINFO, zebra_if);
@@ -932,48 +942,48 @@ static void if_down_del_nbr_connected(struct interface *ifp)
}
}
-/**
- * nhe_connected_add() - Add the nexthop entry to the interfaces connected list
- *
- * @ifp: Interface to add to
- * @nhe: Nexthop hash entry to add
- *
- * Return: nhe_connected struct created and added
- */
-struct nhe_connected *nhe_connected_add(struct interface *ifp,
- struct nhg_hash_entry *nhe)
+void if_nhg_dependents_add(struct interface *ifp, struct nhg_hash_entry *nhe)
{
- struct nhe_connected *if_nhec = NULL;
- struct zebra_if *zif = (struct zebra_if *)ifp->info;
+ if (ifp->info) {
+ struct zebra_if *zif = (struct zebra_if *)ifp->info;
- if_nhec = nhe_connected_new();
+ nhg_connected_head_add(&zif->nhg_dependents, nhe);
+ }
+}
- /* Attach the nhe */
- if_nhec->nhe = nhe;
+void if_nhg_dependents_del(struct interface *ifp, struct nhg_hash_entry *nhe)
+{
+ if (ifp->info) {
+ struct zebra_if *zif = (struct zebra_if *)ifp->info;
- /* Add connected nexthop to the interface */
- listnode_add(zif->nhe_connected, if_nhec);
- return if_nhec;
+ nhg_connected_head_del(&zif->nhg_dependents, nhe);
+ }
}
-/**
- * nhe_connected() - Allocate nhe connected structure
- *
- * Return: Allocated nhe_connected structure
- */
-struct nhe_connected *nhe_connected_new(void)
+unsigned int if_nhg_dependents_count(const struct interface *ifp)
{
- return XCALLOC(MTYPE_NHE_CONNECTED, sizeof(struct nhe_connected));
+ if (ifp->info) {
+ struct zebra_if *zif = (struct zebra_if *)ifp->info;
+
+ return nhg_connected_head_count(&zif->nhg_dependents);
+ }
+
+ return 0;
+}
+
+
+bool if_nhg_dependents_is_empty(const struct interface *ifp)
+{
+ if (ifp->info) {
+ struct zebra_if *zif = (struct zebra_if *)ifp->info;
+
+ return nhg_connected_head_is_empty(&zif->nhg_dependents);
+ }
+
+ return false;
}
-/**
- * nhe_connected_free() - Free nhe_connected structure
- *
- * @nhe_connected: nhe_connected structure to free
- */
-void nhe_connected_free(struct nhe_connected *connected)
{
- XFREE(MTYPE_NHE_CONNECTED, connected);
}
/* Interface is up. */
@@ -1183,16 +1193,9 @@ static void nbr_connected_dump_vty(struct vty *vty,
vty_out(vty, "\n");
}
-/**
- * nhe_connected_dump() - Dump nexthops connected to this interface to vty
- *
- * @vty: Vty output
- * @nhe_connected: List of connected nexthop hash entries
- */
-static void nhe_connected_dump_vty(struct vty *vty,
- struct nhe_connected *connected)
+static void nhg_dependent_dump_vty(struct vty *vty,
+ struct nhg_connected *connected)
{
- /* Just outputing ID for now. */
vty_out(vty, " (%u)", connected->nhe->id);
}
@@ -1343,7 +1346,6 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp)
{
struct connected *connected;
struct nbr_connected *nbr_connected;
- struct nhe_connected *nhe_connected;
struct listnode *node;
struct route_node *rn;
struct zebra_if *zebra_if;
@@ -1429,11 +1431,14 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp)
connected_dump_vty(vty, connected);
}
- if (listhead(zebra_if->nhe_connected)) {
+ if (!if_nhg_dependents_is_empty(ifp)) {
+ struct nhg_connected *rb_node_dep = NULL;
+
vty_out(vty, " Nexthop IDs connected:");
- for (ALL_LIST_ELEMENTS_RO(zebra_if->nhe_connected, node,
- nhe_connected))
- nhe_connected_dump_vty(vty, nhe_connected);
+ RB_FOREACH (rb_node_dep, nhg_connected_head,
+ &zebra_if->nhg_dependents) {
+ nhg_dependent_dump_vty(vty, rb_node_dep);
+ }
vty_out(vty, "\n");
}