Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
zebra: Remove afi field in nexthop hash entry
I do not believe we should be hashing based on AFI
in for our upper level nexthop group entries. These
should be ambiguous with regards to  address families since
an ipv4 or ipv6 address can have the same interface
nexthop. This can be seen in NEXTHOP_TYPE_IFINDEX.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
  • Loading branch information
sworleys committed Oct 25, 2019
1 parent 98fd055 commit 8b5bdc8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
14 changes: 4 additions & 10 deletions zebra/zebra_nhg.c
Expand Up @@ -45,7 +45,6 @@ static void *zebra_nhg_alloc(void *arg)
nhe = XMALLOC(MTYPE_TMP, sizeof(struct nhg_hash_entry));

nhe->vrf_id = copy->vrf_id;
nhe->afi = copy->afi;
nhe->refcnt = 0;
nhe->dplane_ref = zebra_router_get_next_sequence();
nhe->nhg.nexthop = NULL;
Expand All @@ -68,6 +67,7 @@ static uint32_t zebra_nhg_hash_key_nexthop_group(struct nexthop_group *nhg)
* resolved nexthops
*/
for (nh = nhg->nexthop; nh; nh = nh->next) {
key = jhash_1word(nh->type, key);
key = jhash_2words(nh->vrf_id, nh->nh_label_type, key);
/* gate and blackhole are together in a union */
key = jhash(&nh->gate, sizeof(nh->gate), key);
Expand Down Expand Up @@ -97,7 +97,7 @@ uint32_t zebra_nhg_hash_key(const void *arg)
const struct nhg_hash_entry *nhe = arg;
int key = 0x5a351234;

key = jhash_2words(nhe->vrf_id, nhe->afi, key);
key = jhash_1word(nhe->vrf_id, key);

return jhash_1word(zebra_nhg_hash_key_nexthop_group(&nhe->nhg), key);
}
Expand Down Expand Up @@ -127,9 +127,6 @@ bool zebra_nhg_hash_equal(const void *arg1, const void *arg2)
if (nhe1->vrf_id != nhe2->vrf_id)
return false;

if (nhe1->afi != nhe2->afi)
return false;

/*
* Again we are not interested in looking at any recursively
* resolved nexthops. Top level only
Expand Down Expand Up @@ -183,25 +180,22 @@ void zebra_nhg_find_id(uint32_t id, struct nexthop_group *nhg)
zebra_nhg_lookup_get(zrouter.nhgs_id, &lookup);
}

void zebra_nhg_find(afi_t afi, struct nexthop_group *nhg,
struct route_entry *re)
void zebra_nhg_find(struct nexthop_group *nhg, struct route_entry *re)
{
struct nhg_hash_entry lookup;

memset(&lookup, 0, sizeof(lookup));
lookup.vrf_id = re->vrf_id;
lookup.afi = afi;
lookup.nhg = *nhg;

re->nhe = zebra_nhg_lookup_get(zrouter.nhgs, &lookup);
}

void zebra_nhg_release(afi_t afi, struct route_entry *re)
void zebra_nhg_release(struct route_entry *re)
{
struct nhg_hash_entry lookup, *nhe;

lookup.vrf_id = re->vrf_id;
lookup.afi = afi;
lookup.nhg = *re->ng;

nhe = hash_lookup(zrouter.nhgs, &lookup);
Expand Down
10 changes: 4 additions & 6 deletions zebra/zebra_nhg.h
Expand Up @@ -26,11 +26,8 @@
#include "zebra/rib.h"
#include "lib/nexthop_group.h"

extern int nexthop_active_update(struct route_node *rn, struct route_entry *re);

struct nhg_hash_entry {
uint32_t id;
afi_t afi;
vrf_id_t vrf_id;

struct nexthop_group nhg;
Expand Down Expand Up @@ -63,8 +60,9 @@ extern uint32_t zebra_nhg_id_key(const void *arg);
extern bool zebra_nhg_hash_equal(const void *arg1, const void *arg2);
extern bool zebra_nhg_id_equal(const void *arg1, const void *arg2);

extern void zebra_nhg_find(afi_t afi, struct nexthop_group *nhg,
struct route_entry *re);
extern void zebra_nhg_find(struct nexthop_group *nhg, struct route_entry *re);
extern void zebra_nhg_find_id(uint32_t id, struct nexthop_group *nhg);
void zebra_nhg_release(afi_t afi, struct route_entry *re);
void zebra_nhg_release(struct route_entry *re);

extern int nexthop_active_update(struct route_node *rn, struct route_entry *re);
#endif
5 changes: 2 additions & 3 deletions zebra/zebra_rib.c
Expand Up @@ -2411,8 +2411,7 @@ void rib_unlink(struct route_node *rn, struct route_entry *re)
if (dest->selected_fib == re)
dest->selected_fib = NULL;

info = srcdest_rnode_table_info(rn);
zebra_nhg_release(info->afi, re);
zebra_nhg_release(re);

nexthops_free(re->ng->nexthop);
nexthop_group_delete(&re->ng);
Expand Down Expand Up @@ -2659,7 +2658,7 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p,
if (src_p)
apply_mask_ipv6(src_p);

zebra_nhg_find(afi, re->ng, re);
zebra_nhg_find(re->ng, re);
/* Set default distance by route type. */
if (re->distance == 0)
re->distance = route_distance(re->type);
Expand Down
18 changes: 6 additions & 12 deletions zebra/zebra_vty.c
Expand Up @@ -1103,7 +1103,7 @@ DEFUN (ip_nht_default_route,
}

static void show_nexthop_group_cmd_helper(struct vty *vty,
struct zebra_vrf *zvrf, afi_t afi)
struct zebra_vrf *zvrf)
{
struct list *list = hash_to_list(zrouter.nhgs);
struct nhg_hash_entry *nhe;
Expand All @@ -1112,15 +1112,12 @@ static void show_nexthop_group_cmd_helper(struct vty *vty,
for (ALL_LIST_ELEMENTS_RO(list, node, nhe)) {
struct nexthop *nhop;

if (nhe->afi != afi)
continue;

if (nhe->vrf_id != zvrf->vrf->vrf_id)
continue;

vty_out(vty,
"Group: %u RefCnt: %u afi: %d Valid: %d Installed: %d\n",
nhe->dplane_ref, nhe->refcnt, nhe->afi,
"Group: %u ID: %u RefCnt: %d Valid: %d Installed: %d\n",
nhe->dplane_ref, nhe->id, nhe->refcnt,
nhe->flags & NEXTHOP_GROUP_VALID,
nhe->flags & NEXTHOP_GROUP_INSTALLED);

Expand All @@ -1135,14 +1132,11 @@ static void show_nexthop_group_cmd_helper(struct vty *vty,

DEFPY (show_nexthop_group,
show_nexthop_group_cmd,
"show nexthop-group <ipv4$v4|ipv6$v6> [vrf <NAME$vrf_name|all$vrf_all>]",
"show nexthop-group [vrf <NAME$vrf_name|all$vrf_all>]",
SHOW_STR
IP_STR
IP6_STR
"Show Nexthop Groups\n"
VRF_FULL_CMD_HELP_STR)
{
afi_t afi = v4 ? AFI_IP : AFI_IP6;
struct zebra_vrf *zvrf;

if (vrf_all) {
Expand All @@ -1156,7 +1150,7 @@ DEFPY (show_nexthop_group,
continue;

vty_out(vty, "VRF: %s\n", vrf->name);
show_nexthop_group_cmd_helper(vty, zvrf, afi);
show_nexthop_group_cmd_helper(vty, zvrf);
}

return CMD_SUCCESS;
Expand All @@ -1172,7 +1166,7 @@ DEFPY (show_nexthop_group,
return CMD_SUCCESS;
}

show_nexthop_group_cmd_helper(vty, zvrf, afi);
show_nexthop_group_cmd_helper(vty, zvrf);

return CMD_SUCCESS;
}
Expand Down

0 comments on commit 8b5bdc8

Please sign in to comment.