diff options
author | Donald Sharp <sharpd@cumulusnetworks.com> | 2020-04-29 18:32:53 +0200 |
---|---|---|
committer | Stephen Worley <sworley@cumulusnetworks.com> | 2020-09-28 18:40:59 +0200 |
commit | 569e87c0c831252f46fc9a8ddcbc5e268bff8327 (patch) | |
tree | 65729356e0eb0a9b7eaf028558b1af51f6a586dc /sharpd/sharp_nht.c | |
parent | lib, zebra: Add ability to send down a nhgid over route install (diff) | |
download | frr-569e87c0c831252f46fc9a8ddcbc5e268bff8327.tar.xz frr-569e87c0c831252f46fc9a8ddcbc5e268bff8327.zip |
sharpd: add abilty to send a nhg to zebra
Modify the sharpd program to have the ability to pass down
a NHG and then operate on it for route installation.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'sharpd/sharp_nht.c')
-rw-r--r-- | sharpd/sharp_nht.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/sharpd/sharp_nht.c b/sharpd/sharp_nht.c index 174f18686..414879290 100644 --- a/sharpd/sharp_nht.c +++ b/sharpd/sharp_nht.c @@ -25,11 +25,15 @@ #include "nexthop.h" #include "nexthop_group.h" #include "vty.h" +#include "typesafe.h" +#include "zclient.h" #include "sharp_nht.h" #include "sharp_globals.h" +#include "sharp_zebra.h" DEFINE_MTYPE_STATIC(SHARPD, NH_TRACKER, "Nexthop Tracker") +DEFINE_MTYPE_STATIC(SHARPD, NHG, "Nexthop Group") struct sharp_nh_tracker *sharp_nh_tracker_get(struct prefix *p) { @@ -65,3 +69,109 @@ void sharp_nh_tracker_dump(struct vty *vty) nht->updates); } } + +PREDECL_RBTREE_UNIQ(sharp_nhg_rb); + +struct sharp_nhg { + struct sharp_nhg_rb_item mylistitem; + + uint32_t id; + + char name[256]; +}; + +static uint32_t nhg_id; + +static uint32_t sharp_get_next_nhid(void) +{ + zlog_debug("Id assigned: %u", nhg_id + 1); + return nhg_id++; +} + +struct sharp_nhg_rb_head nhg_head; + +static int sharp_nhg_compare_func(const struct sharp_nhg *a, + const struct sharp_nhg *b) +{ + return strncmp(a->name, b->name, strlen(a->name)); +} + +DECLARE_RBTREE_UNIQ(sharp_nhg_rb, struct sharp_nhg, mylistitem, + sharp_nhg_compare_func); + +static void sharp_nhgroup_add_cb(const char *name) +{ + struct sharp_nhg *snhg; + + snhg = XCALLOC(MTYPE_NHG, sizeof(*snhg)); + snhg->id = sharp_get_next_nhid(); + strncpy(snhg->name, name, sizeof(snhg->name)); + + sharp_nhg_rb_add(&nhg_head, snhg); + return; +} + +static void sharp_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhgc, + const struct nexthop *nhop) +{ + struct sharp_nhg lookup; + struct sharp_nhg *snhg; + + strncpy(lookup.name, nhgc->name, sizeof(lookup.name)); + snhg = sharp_nhg_rb_find(&nhg_head, &lookup); + + nhg_add(snhg->id, &nhgc->nhg); + return; +} + +static void sharp_nhgroup_del_nexthop_cb(const struct nexthop_group_cmd *nhgc, + const struct nexthop *nhop) +{ + struct sharp_nhg lookup; + struct sharp_nhg *snhg; + + strncpy(lookup.name, nhgc->name, sizeof(lookup.name)); + snhg = sharp_nhg_rb_find(&nhg_head, &lookup); + + nhg_add(snhg->id, &nhgc->nhg); + return; +} + +static void sharp_nhgroup_delete_cb(const char *name) +{ + struct sharp_nhg lookup; + struct sharp_nhg *snhg; + + strncpy(lookup.name, name, sizeof(lookup.name)); + snhg = sharp_nhg_rb_find(&nhg_head, &lookup); + if (!snhg) + return; + + nhg_del(snhg->id); + sharp_nhg_rb_del(&nhg_head, snhg); + XFREE(MTYPE_NHG, snhg); + return; +} + +uint32_t sharp_nhgroup_get_id(const char *name) +{ + struct sharp_nhg lookup; + struct sharp_nhg *snhg; + + strncpy(lookup.name, name, sizeof(lookup.name)); + snhg = sharp_nhg_rb_find(&nhg_head, &lookup); + if (!snhg) + return 0; + + return snhg->id; +} + +void sharp_nhgroup_init(void) +{ + sharp_nhg_rb_init(&nhg_head); + nhg_id = zclient_get_nhg_start(ZEBRA_ROUTE_SHARP); + + nexthop_group_init(sharp_nhgroup_add_cb, sharp_nhgroup_add_nexthop_cb, + sharp_nhgroup_del_nexthop_cb, + sharp_nhgroup_delete_cb); +} |