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

various nexthop group fixes #14885

Merged
merged 6 commits into from
Dec 4, 2023
Merged
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
20 changes: 4 additions & 16 deletions lib/nexthop_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,6 @@ uint8_t nexthop_group_active_nexthop_num(const struct nexthop_group *nhg)
return num;
}

uint8_t
nexthop_group_active_nexthop_num_no_recurse(const struct nexthop_group *nhg)
{
struct nexthop *nhop;
uint8_t num = 0;

for (nhop = nhg->nexthop; nhop; nhop = nhop->next) {
if (CHECK_FLAG(nhop->flags, NEXTHOP_FLAG_ACTIVE))
num++;
}

return num;
}

bool nexthop_group_has_label(const struct nexthop_group *nhg)
{
struct nexthop *nhop;
Expand Down Expand Up @@ -1248,9 +1234,9 @@ void nexthop_group_disable_vrf(struct vrf *vrf)
struct nexthop_hold *nhh;

RB_FOREACH (nhgc, nhgc_entry_head, &nhgc_entries) {
struct listnode *node;
struct listnode *node, *nnode;

for (ALL_LIST_ELEMENTS_RO(nhgc->nhg_list, node, nhh)) {
for (ALL_LIST_ELEMENTS(nhgc->nhg_list, node, nnode, nhh)) {
struct nexthop nhop;
struct nexthop *nh;

Expand All @@ -1271,6 +1257,8 @@ void nexthop_group_disable_vrf(struct vrf *vrf)
nhg_hooks.del_nexthop(nhgc, nh);

nexthop_free(nh);

list_delete_node(nhgc->nhg_list, node);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions lib/nexthop_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ extern uint8_t
nexthop_group_nexthop_num_no_recurse(const struct nexthop_group *nhg);
extern uint8_t
nexthop_group_active_nexthop_num(const struct nexthop_group *nhg);
extern uint8_t
nexthop_group_active_nexthop_num_no_recurse(const struct nexthop_group *nhg);

extern bool nexthop_group_has_label(const struct nexthop_group *nhg);

Expand Down
12 changes: 9 additions & 3 deletions sharpd/sharp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,15 @@ void nhg_add(uint32_t id, const struct nexthop_group *nhg,
}

if (api_nhg.nexthop_num == 0) {
zlog_debug("%s: nhg %u not sent: no valid nexthops", __func__,
id);
is_valid = false;
if (sharp_nhgroup_id_is_installed(id)) {
zlog_debug("%s: nhg %u: no nexthops, deleting nexthop group", __func__,
id);
zclient_nhg_send(zclient, ZEBRA_NHG_DEL, &api_nhg);
} else {
zlog_debug("%s: nhg %u not sent: no valid nexthops", __func__,
id);
is_valid = false;
}
goto done;
}

Expand Down
2 changes: 1 addition & 1 deletion zebra/rt_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2624,7 +2624,7 @@ static bool _netlink_nexthop_build_group(struct nlmsghdr *n, size_t req_size,

if (IS_ZEBRA_DEBUG_KERNEL) {
if (i == 0)
snprintf(buf, sizeof(buf1), "group %u",
snprintf(buf, sizeof(buf), "group %u",
grp[i].id);
else {
snprintf(buf1, sizeof(buf1), "/%u",
Expand Down
10 changes: 9 additions & 1 deletion zebra/zapi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,8 @@ static void zread_nhg_del(ZAPI_HANDLER_ARGS)
zsend_nhg_notify(api_nhg.proto, client->instance,
client->session_id, api_nhg.id,
ZAPI_NHG_REMOVE_FAIL);
/* Stats */
client->nhg_del_cnt++;
}

static void zread_nhg_add(ZAPI_HANDLER_ARGS)
Expand All @@ -1981,7 +1983,7 @@ static void zread_nhg_add(ZAPI_HANDLER_ARGS)
struct zapi_nhg api_nhg = {};
struct nexthop_group *nhg = NULL;
struct nhg_backup_info *bnhg = NULL;
struct nhg_hash_entry *nhe;
struct nhg_hash_entry *nhe, *nhe_tmp;

s = msg;
if (zapi_nhg_decode(s, hdr->command, &api_nhg) < 0) {
Expand Down Expand Up @@ -2039,6 +2041,12 @@ static void zread_nhg_add(ZAPI_HANDLER_ARGS)
nexthop_group_delete(&nhg);
zebra_nhg_backup_free(&bnhg);

/* Stats */
nhe_tmp = zebra_nhg_lookup_id(api_nhg.id);
if (nhe_tmp)
client->nhg_upd8_cnt++;
else
client->nhg_add_cnt++;
}

static void zread_route_add(ZAPI_HANDLER_ARGS)
Expand Down
8 changes: 7 additions & 1 deletion zebra/zebra_nhg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,13 @@ zebra_nhg_rib_find_nhe(struct nhg_hash_entry *rt_nhe, afi_t rt_afi)
{
struct nhg_hash_entry *nhe = NULL;

if (!(rt_nhe && rt_nhe->nhg.nexthop)) {
if (!rt_nhe) {
flog_err(EC_ZEBRA_TABLE_LOOKUP_FAILED,
"No nhg_hash_entry passed to %s", __func__);
return NULL;
}

if (!rt_nhe->nhg.nexthop) {
flog_err(EC_ZEBRA_TABLE_LOOKUP_FAILED,
"No nexthop passed to %s", __func__);
return NULL;
Expand Down
2 changes: 2 additions & 0 deletions zebra/zserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,8 @@ static void zebra_show_client_detail(struct vty *vty, struct zserv *client)
0, client->redist_v4_del_cnt);
vty_out(vty, "Redist:v6 %-12u%-12u%-12u\n", client->redist_v6_add_cnt,
0, client->redist_v6_del_cnt);
vty_out(vty, "NHG %-12u%-12u%-12u\n", client->nhg_add_cnt,
client->nhg_upd8_cnt, client->nhg_del_cnt);
vty_out(vty, "VRF %-12u%-12u%-12u\n", client->vrfadd_cnt, 0,
client->vrfdel_cnt);
vty_out(vty, "Connected %-12u%-12u%-12u\n", client->ifadd_cnt, 0,
Expand Down
3 changes: 3 additions & 0 deletions zebra/zserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ struct zserv {
uint32_t local_es_evi_add_cnt;
uint32_t local_es_evi_del_cnt;
uint32_t error_cnt;
uint32_t nhg_add_cnt;
uint32_t nhg_upd8_cnt;
uint32_t nhg_del_cnt;

time_t nh_reg_time;
time_t nh_dereg_time;
Expand Down
Loading