Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pbrd: add callbacks for adding/deleting nhg nexthops #6

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions lib/nexthop_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
#endif

struct nexthop_group_hooks {
void (*add)(const char *name);
void (*modify)(const char *name);
void (*new)(const char *name);
void (*add_nexthop)(const char *name);
void (*del_nexthop)(const char *name);
void (*delete)(const char *name);
};

Expand Down Expand Up @@ -137,8 +138,8 @@ static struct nexthop_group_cmd *nhgc_get(const char *name)
QOBJ_REG(nhgc, nexthop_group_cmd);
RB_INSERT(nhgc_entry_head, &nhgc_entries, nhgc);

if (nhg_hooks.add)
nhg_hooks.add(name);
if (nhg_hooks.new)
nhg_hooks.new(name);
}

return nhgc;
Expand Down Expand Up @@ -185,7 +186,8 @@ DEFUN_NOSH(no_nexthop_group, no_nexthop_group_cmd, "no nexthop-group NAME",

DEFPY(ecmp_nexthops,
ecmp_nexthops_cmd,
"nexthop <A.B.C.D|X:X::X:X>$addr [INTERFACE]$intf [nexthop-vrf NAME$name]",
"[no] nexthop <A.B.C.D|X:X::X:X>$addr [INTERFACE]$intf [nexthop-vrf NAME$name]",
NO_STR
"Specify one of the nexthops in this ECMP group\n"
"v4 Address\n"
"v6 Address\n"
Expand Down Expand Up @@ -245,8 +247,8 @@ DEFPY(ecmp_nexthops,
nexthop_add(&nhgc->nhg.nexthop, nh);
}

if (nhg_hooks.modify)
nhg_hooks.modify(nhgc->name);
if (nhg_hooks.add_nexthop)
nhg_hooks.add_nexthop(nhgc->name);

return CMD_SUCCESS;
}
Expand Down Expand Up @@ -307,8 +309,9 @@ static int nexthop_group_write(struct vty *vty)
}


void nexthop_group_init(void (*add)(const char *name),
void (*modify)(const char *name),
void nexthop_group_init(void (*new)(const char *name),
void (*add_nexthop)(const char *name),
void (*del_nexthop)(const char *name),
void (*delete)(const char *name))
{
RB_INIT(nhgc_entry_head, &nhgc_entries);
Expand All @@ -321,10 +324,12 @@ void nexthop_group_init(void (*add)(const char *name),

memset(&nhg_hooks, 0, sizeof(nhg_hooks));

if (add)
nhg_hooks.add = add;
if (modify)
nhg_hooks.modify = modify;
if (new)
nhg_hooks.new = new;
if (add_nexthop)
nhg_hooks.add_nexthop = add_nexthop;
if (del_nexthop)
nhg_hooks.del_nexthop = del_nexthop;
if (delete)
nhg_hooks.delete = delete;
}
7 changes: 4 additions & 3 deletions lib/nexthop_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ struct nexthop_group {
* appropriate callback functions to handle it in your
* code
*/
void nexthop_group_init(void (*add)(const char *name),
void (*delete)(const char *name),
void (*modify)(const char *name));
void nexthop_group_init(void (*new)(const char *name),
void (*add_nexthop)(const char *name),
void (*del_nexthop)(const char *name),
void (*delete)(const char *name));

void nexthop_add(struct nexthop **target, struct nexthop *nexthop);
void copy_nexthops(struct nexthop **tnh, struct nexthop *nh,
Expand Down
18 changes: 13 additions & 5 deletions pbrd/pbr_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ static const char *pbr_event_wqentry2str(struct pbr_event *pbre,
char *buffer, size_t buflen)
{
switch(pbre->event) {
case PBR_NHG_ADD:
case PBR_NHG_NEW:
snprintf(buffer, buflen, "Nexthop Group Added %s",
pbre->name);
break;
case PBR_NHG_MODIFY:
snprintf(buffer, buflen, "Nexthop Group Modified %s",
case PBR_NHG_ADD_NEXTHOP:
snprintf(buffer, buflen, "Nexthop Group Nexthop Added %s",
pbre->name);
break;
case PBR_NHG_DEL_NEXTHOP:
snprintf(buffer, buflen, "Nexthop Group Nexthop Deleted %s",
pbre->name);
break;
case PBR_NHG_DELETE:
Expand Down Expand Up @@ -98,11 +102,15 @@ static wq_item_status pbr_event_process_wq(struct work_queue *wq, void *data)
pbr_event_wqentry2str(pbre, buffer, sizeof(buffer)));

switch (pbre->event) {
case PBR_NHG_ADD:
case PBR_NHG_NEW:
pbr_nht_add_group(pbre->name);
pbr_map_check_nh_group_change(pbre->name);
break;
case PBR_NHG_MODIFY:
case PBR_NHG_ADD_NEXTHOP:
pbr_nht_change_group(pbre->name);
pbr_map_check_nh_group_change(pbre->name);
break;
case PBR_NHG_DEL_NEXTHOP:
pbr_nht_change_group(pbre->name);
pbr_map_check_nh_group_change(pbre->name);
break;
Expand Down
11 changes: 8 additions & 3 deletions pbrd/pbr_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ enum pbr_events {
/*
* A NHG has been added to the system, handle it
*/
PBR_NHG_ADD,
PBR_NHG_NEW,

/*
* A NHG has been modified( added a new nexthop )
* A NHG has added a new nexthop
*/
PBR_NHG_MODIFY,
PBR_NHG_ADD_NEXTHOP,

/*
* A NHG has deleted a nexthop
*/
PBR_NHG_DEL_NEXTHOP,

/*
* A NHG has been deleted from the system
Expand Down
3 changes: 2 additions & 1 deletion pbrd/pbr_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ int main(int argc, char **argv, char **envp)

vrf_init(NULL, NULL, NULL, NULL);
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_event_init();
Expand Down
21 changes: 17 additions & 4 deletions pbrd/pbr_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,37 @@ void pbr_nhgroup_add_cb(const char *name)

pbre = pbr_event_new();

pbre->event = PBR_NHG_ADD;
pbre->event = PBR_NHG_NEW;
strlcpy(pbre->name, name, sizeof(pbre->name));

pbr_event_enqueue(pbre);
zlog_debug("Received ADD cb for %s", name);
}

void pbr_nhgroup_modify_cb(const char *name)
void pbr_nhgroup_add_nexthop_cb(const char *name)
{
struct pbr_event *pbre;

pbre = pbr_event_new();

pbre->event = PBR_NHG_MODIFY;
pbre->event = PBR_NHG_ADD_NEXTHOP;
strlcpy(pbre->name, name, sizeof(pbre->name));

pbr_event_enqueue(pbre);
zlog_debug("Received MODIFY cb for %s", name);
zlog_debug("Received NEXTHOP_ADD cb for %s", name);
}

void pbr_nhgroup_del_nexthop_cb(const char *name)
{
struct pbr_event *pbre;

pbre = pbr_event_new();

pbre->event = PBR_NHG_DEL_NEXTHOP;
strlcpy(pbre->name, name, sizeof(pbre->name));

pbr_event_enqueue(pbre);
zlog_debug("Received NEXTHOP_DEL cb for %s", name);
}

void pbr_nhgroup_delete_cb(const char *name)
Expand Down
3 changes: 2 additions & 1 deletion pbrd/pbr_nht.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ extern void pbr_nht_set_rule_range(uint32_t low, uint32_t high);
extern uint32_t pbr_nht_get_next_rule(void);

extern void pbr_nhgroup_add_cb(const char *name);
extern void pbr_nhgroup_modify_cb(const char *name);
extern void pbr_nhgroup_add_nexthop_cb(const char *name);
extern void pbr_nhgroup_del_nexthop_cb(const char *name);
extern void pbr_nhgroup_delete_cb(const char *name);

extern bool pbr_nht_nexthop_valid(struct nexthop *nhop);
Expand Down