*: Add ability for daemons to notice resilience changes

This patch just introduces the callback mechanism for the
resilient nexthop changes so that upper level daemons
can take advantage of the change.  This does nothing
at this point but just call some code.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2022-10-24 09:25:54 -04:00
parent f0f618dcdb
commit f3c6dd49f4
7 changed files with 38 additions and 6 deletions

View File

@ -1390,14 +1390,21 @@ static uint32_t bgp_l3nhg_start;
static void bgp_l3nhg_add_cb(const char *name)
{
}
static void bgp_l3nhg_modify_cb(const struct nexthop_group_cmd *nhgc)
{
}
static void bgp_l3nhg_add_nexthop_cb(const struct nexthop_group_cmd *nhgc,
const struct nexthop *nhop)
{
}
static void bgp_l3nhg_del_nexthop_cb(const struct nexthop_group_cmd *nhgc,
const struct nexthop *nhop)
{
}
static void bgp_l3nhg_del_cb(const char *name)
{
}
@ -1410,8 +1417,9 @@ static void bgp_l3nhg_zebra_init(void)
bgp_l3nhg_zebra_inited = true;
bgp_l3nhg_start = zclient_get_nhg_start(ZEBRA_ROUTE_BGP);
nexthop_group_init(bgp_l3nhg_add_cb, bgp_l3nhg_add_nexthop_cb,
bgp_l3nhg_del_nexthop_cb, bgp_l3nhg_del_cb);
nexthop_group_init(bgp_l3nhg_add_cb, bgp_l3nhg_modify_cb,
bgp_l3nhg_add_nexthop_cb, bgp_l3nhg_del_nexthop_cb,
bgp_l3nhg_del_cb);
}

View File

@ -47,6 +47,7 @@ struct nexthop_hold {
struct nexthop_group_hooks {
void (*new)(const char *name);
void (*modify)(const struct nexthop_group_cmd *nhgc);
void (*add_nexthop)(const struct nexthop_group_cmd *nhg,
const struct nexthop *nhop);
void (*del_nexthop)(const struct nexthop_group_cmd *nhg,
@ -691,6 +692,9 @@ DEFPY(nexthop_group_resilience,
nhgc->nhg.nhgr.idle_timer = idle_timer;
nhgc->nhg.nhgr.unbalanced_timer = unbalanced_timer;
if (nhg_hooks.modify)
nhg_hooks.modify(nhgc);
return CMD_SUCCESS;
}
@ -1347,6 +1351,7 @@ static const struct cmd_variable_handler nhg_name_handlers[] = {
{.completions = NULL}};
void nexthop_group_init(void (*new)(const char *name),
void (*modify)(const struct nexthop_group_cmd *nhgc),
void (*add_nexthop)(const struct nexthop_group_cmd *nhg,
const struct nexthop *nhop),
void (*del_nexthop)(const struct nexthop_group_cmd *nhg,
@ -1373,6 +1378,8 @@ void nexthop_group_init(void (*new)(const char *name),
if (new)
nhg_hooks.new = new;
if (modify)
nhg_hooks.modify = modify;
if (add_nexthop)
nhg_hooks.add_nexthop = add_nexthop;
if (del_nexthop)

View File

@ -118,9 +118,17 @@ DECLARE_QOBJ_TYPE(nexthop_group_cmd);
* a nexthop_group is added/deleted/modified, then set the
* appropriate callback functions to handle it in your
* code
*
* create - The creation of the nexthop group
* modify - Modification of the nexthop group when not changing a nexthop
* ( resilience as an example )
* add_nexthop - A nexthop is added to the NHG
* del_nexthop - A nexthop is deleted from the NHG
* destroy - The NHG is deleted
*/
void nexthop_group_init(
void (*create)(const char *name),
void (*modify)(const struct nexthop_group_cmd *nhgc),
void (*add_nexthop)(const struct nexthop_group_cmd *nhgc,
const struct nexthop *nhop),
void (*del_nexthop)(const struct nexthop_group_cmd *nhgc,

View File

@ -160,10 +160,9 @@ int main(int argc, char **argv, char **envp)
pbr_debug_init();
nexthop_group_init(pbr_nhgroup_add_cb,
nexthop_group_init(pbr_nhgroup_add_cb, pbr_nhgroup_modify_cb,
pbr_nhgroup_add_nexthop_cb,
pbr_nhgroup_del_nexthop_cb,
pbr_nhgroup_delete_cb);
pbr_nhgroup_del_nexthop_cb, pbr_nhgroup_delete_cb);
/*
* So we safely ignore these commands since

View File

@ -229,6 +229,10 @@ void pbr_nhgroup_add_cb(const char *name)
pbr_map_check_nh_group_change(name);
}
void pbr_nhgroup_modify_cb(const struct nexthop_group_cmd *nhgc)
{
}
void pbr_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhgc,
const struct nexthop *nhop)
{

View File

@ -96,6 +96,7 @@ extern void pbr_nht_set_rule_range(uint32_t low, uint32_t high);
extern uint32_t pbr_nht_get_next_rule(uint32_t seqno);
extern void pbr_nhgroup_add_cb(const char *name);
extern void pbr_nhgroup_modify_cb(const struct nexthop_group_cmd *nhgc);
extern void pbr_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhg,
const struct nexthop *nhop);
extern void pbr_nhgroup_del_nexthop_cb(const struct nexthop_group_cmd *nhg,

View File

@ -124,6 +124,10 @@ static void sharp_nhgroup_add_cb(const char *name)
sharp_nhg_rb_add(&nhg_head, snhg);
}
static void sharp_nhgroup_modify_cb(const struct nexthop_group_cmd *nhgc)
{
}
static void sharp_nhgroup_add_nexthop_cb(const struct nexthop_group_cmd *nhgc,
const struct nexthop *nhop)
{
@ -215,7 +219,8 @@ 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,
nexthop_group_init(sharp_nhgroup_add_cb, sharp_nhgroup_modify_cb,
sharp_nhgroup_add_nexthop_cb,
sharp_nhgroup_del_nexthop_cb,
sharp_nhgroup_delete_cb);
}