Skip to content

Commit

Permalink
pbrd: add ability to delete routes and rules correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
  • Loading branch information
dslicenc authored and donaldsharp committed Mar 21, 2018
1 parent 6c7c252 commit 52a7c7a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 30 deletions.
14 changes: 10 additions & 4 deletions pbrd/pbr_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,10 @@ void pbr_map_check_nh_group_change(const char *nh_group)
{
struct pbr_map_sequence *pbrms;
struct pbr_map *pbrm;
struct listnode *node;
struct listnode *node, *inode;
struct pbr_map_interface *pmi;
bool found_name;

zlog_warn("*** %s for %s ***", __func__, nh_group);
RB_FOREACH (pbrm, pbr_map_entry_head, &pbr_maps) {
for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms)) {
found_name = false;
Expand All @@ -496,9 +496,15 @@ void pbr_map_check_nh_group_change(const char *nh_group)

pbr_map_check_valid_internal(pbrm);

if (original != pbrm->valid)
if (pbrm->valid && (original != pbrm->valid))
pbr_map_install(pbrm);
break;

if (pbrm->valid == false)
for (ALL_LIST_ELEMENTS_RO(
pbrm->incoming, inode,
pmi))
pbr_send_pbr_map(pbrms, pmi,
false);
}
}
}
Expand Down
72 changes: 46 additions & 26 deletions pbrd/pbr_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ static bool nhg_tableid[65535];

static void pbr_nht_install_nexthop_group(struct pbr_nexthop_group_cache *pnhgc,
struct nexthop_group nhg);
static void
pbr_nht_uninstall_nexthop_group(struct pbr_nexthop_group_cache *pnhgc,
struct nexthop_group nhg,
enum nexthop_types_t nh_afi);

/*
* Nexthop refcount.
Expand Down Expand Up @@ -255,6 +259,7 @@ void pbr_nhgroup_del_nexthop_cb(const struct nexthop_group_cmd *nhgc,
struct pbr_nexthop_group_cache *pnhgc;
struct pbr_nexthop_cache pnhc_find = {};
struct pbr_nexthop_cache *pnhc;
enum nexthop_types_t nh_afi = nhop->type;

/* find pnhgc by name */
strlcpy(pnhgc_find.name, nhgc->name, sizeof(pnhgc_find.name));
Expand All @@ -273,18 +278,22 @@ void pbr_nhgroup_del_nexthop_cb(const struct nexthop_group_cmd *nhgc,
__PRETTY_FUNCTION__, debugstr, nhgc->name);
}

pbr_nht_install_nexthop_group(pnhgc, nhgc->nhg);
if (pnhgc->nhh->count)
pbr_nht_install_nexthop_group(pnhgc, nhgc->nhg);
else
pbr_nht_uninstall_nexthop_group(pnhgc, nhgc->nhg, nh_afi);

pbr_map_check_nh_group_change(nhgc->name);
}

void pbr_nhgroup_delete_cb(const char *name)
{
/* delete group from all pbrms's */
pbr_nht_delete_group(name);

DEBUGD(&pbr_dbg_nht, "%s: Removed nexthop-group %s",
__PRETTY_FUNCTION__, name);

/* delete group from all pbrms's */
pbr_nht_delete_group(name);

pbr_map_check_nh_group_change(name);
}

Expand Down Expand Up @@ -339,35 +348,41 @@ void pbr_nht_route_removed_for_table(uint32_t table_id)
* - AFI of last nexthop in the group
* - AFI_MAX on error
*/
static afi_t pbr_nht_which_afi(struct nexthop_group nhg)
static afi_t pbr_nht_which_afi(struct nexthop_group nhg,
enum nexthop_types_t nh_afi)
{
struct nexthop *nexthop;
afi_t install_afi = AFI_MAX;
bool v6, v4, bh;

v6 = v4 = bh = false;

for (ALL_NEXTHOPS(nhg, nexthop)) {
switch (nexthop->type) {
case NEXTHOP_TYPE_IFINDEX:
break;
case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX:
v6 = true;
install_afi = AFI_IP;
break;
case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX:
v4 = true;
install_afi = AFI_IP6;
break;
case NEXTHOP_TYPE_BLACKHOLE:
bh = true;
install_afi = AFI_MAX;
if (!nh_afi) {
for (ALL_NEXTHOPS(nhg, nexthop)) {
nh_afi = nexthop->type;
break;
}
}

switch (nh_afi) {
case NEXTHOP_TYPE_IFINDEX:
break;
case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX:
v6 = true;
install_afi = AFI_IP;
break;
case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX:
v4 = true;
install_afi = AFI_IP6;
break;
case NEXTHOP_TYPE_BLACKHOLE:
bh = true;
install_afi = AFI_MAX;
break;
}

if (!bh && v6 && v4)
DEBUGD(&pbr_dbg_nht,
"%s: Saw both V6 and V4 nexthops...using %s",
Expand All @@ -385,20 +400,23 @@ static void pbr_nht_install_nexthop_group(struct pbr_nexthop_group_cache *pnhgc,
struct nexthop_group nhg)
{
afi_t install_afi;
enum nexthop_types_t nh_afi = 0;

install_afi = pbr_nht_which_afi(nhg);
install_afi = pbr_nht_which_afi(nhg, nh_afi);

pnhgc->installed = false;

route_add(pnhgc, nhg, install_afi);
}

static void
pbr_nht_uninstall_nexthop_group(struct pbr_nexthop_group_cache *pnhgc,
struct nexthop_group nhg)
struct nexthop_group nhg,
enum nexthop_types_t nh_afi)
{
afi_t install_afi;

install_afi = pbr_nht_which_afi(nhg);
install_afi = pbr_nht_which_afi(nhg, nh_afi);

pnhgc->installed = false;
pnhgc->valid = false;
Expand Down Expand Up @@ -477,6 +495,7 @@ void pbr_nht_delete_individual_nexthop(struct pbr_map_sequence *pbrms)
struct listnode *node;
struct pbr_map_interface *pmi;
struct nexthop *nh;
enum nexthop_types_t nh_afi = 0;

if (pbrm->valid && pbrms->nhs_installed && pbrm->incoming->count) {
for (ALL_LIST_ELEMENTS_RO(pbrm->incoming, node, pmi))
Expand All @@ -493,12 +512,13 @@ void pbr_nht_delete_individual_nexthop(struct pbr_map_sequence *pbrms)
pnhgc = hash_lookup(pbr_nhg_hash, &find);

nh = pbrms->nhg->nexthop;
nh_afi = nh->type;
lup.nexthop = nh;
pnhc = hash_lookup(pnhgc->nhh, &lup);
pnhc->parent = NULL;
hash_release(pnhgc->nhh, pnhc);
pbr_nh_delete(&pnhc);
pbr_nht_uninstall_nexthop_group(pnhgc, *pbrms->nhg);
pbr_nht_uninstall_nexthop_group(pnhgc, *pbrms->nhg, nh_afi);

hash_release(pbr_nhg_hash, pnhgc);

Expand Down

0 comments on commit 52a7c7a

Please sign in to comment.