Skip to content

Commit

Permalink
Merge pull request #6197 from sworleys/PBR-Atomic
Browse files Browse the repository at this point in the history
pbrd,zebra: implement `set *` and `match *` replace
  • Loading branch information
riw777 authored Apr 14, 2020
2 parents e68a7db + f732636 commit 82d86ab
Show file tree
Hide file tree
Showing 12 changed files with 354 additions and 226 deletions.
35 changes: 18 additions & 17 deletions pbrd/pbr_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static bool pbr_map_interface_is_valid(const struct pbr_map_interface *pmi)
}

static void pbr_map_pbrms_update_common(struct pbr_map_sequence *pbrms,
bool install)
bool install, bool changed)
{
struct pbr_map *pbrm;
struct listnode *node;
Expand All @@ -161,19 +161,19 @@ static void pbr_map_pbrms_update_common(struct pbr_map_sequence *pbrms,
if (install && !pbr_map_interface_is_valid(pmi))
continue;

pbr_send_pbr_map(pbrms, pmi, install);
pbr_send_pbr_map(pbrms, pmi, install, changed);
}
}
}

static void pbr_map_pbrms_install(struct pbr_map_sequence *pbrms)
static void pbr_map_pbrms_install(struct pbr_map_sequence *pbrms, bool changed)
{
pbr_map_pbrms_update_common(pbrms, true);
pbr_map_pbrms_update_common(pbrms, true, changed);
}

static void pbr_map_pbrms_uninstall(struct pbr_map_sequence *pbrms)
{
pbr_map_pbrms_update_common(pbrms, false);
pbr_map_pbrms_update_common(pbrms, false, false);
}

static const char *const pbr_map_reason_str[] = {
Expand Down Expand Up @@ -292,7 +292,7 @@ void pbr_map_policy_interface_update(const struct interface *ifp, bool state_up)
for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms))
for (ALL_LIST_ELEMENTS_RO(pbrm->incoming, inode, pmi))
if (pmi->ifp == ifp && pbr_map_interface_is_valid(pmi))
pbr_send_pbr_map(pbrms, pmi, state_up);
pbr_send_pbr_map(pbrms, pmi, state_up, false);
}

static void pbrms_vrf_update(struct pbr_map_sequence *pbrms,
Expand All @@ -306,7 +306,7 @@ static void pbrms_vrf_update(struct pbr_map_sequence *pbrms,
DEBUGD(&pbr_dbg_map, "\tSeq %u uses vrf %s (%u), updating map",
pbrms->seqno, vrf_name, pbr_vrf_id(pbr_vrf));

pbr_map_check(pbrms);
pbr_map_check(pbrms, false);
}
}

Expand Down Expand Up @@ -360,7 +360,7 @@ extern void pbr_map_delete(struct pbr_map_sequence *pbrms)
pbrm = pbrms->parent;

for (ALL_LIST_ELEMENTS_RO(pbrm->incoming, inode, pmi))
pbr_send_pbr_map(pbrms, pmi, false);
pbr_send_pbr_map(pbrms, pmi, false, false);

if (pbrms->nhg)
pbr_nht_delete_individual_nexthop(pbrms);
Expand All @@ -384,7 +384,7 @@ static void pbr_map_delete_common(struct pbr_map_sequence *pbrms)
pbrm->valid = false;
pbrms->nhs_installed = false;
pbrms->reason |= PBR_MAP_INVALID_NO_NEXTHOPS;
pbrms->nhgrp_name = NULL;
XFREE(MTYPE_TMP, pbrms->nhgrp_name);
}

void pbr_map_delete_nexthops(struct pbr_map_sequence *pbrms)
Expand Down Expand Up @@ -619,15 +619,15 @@ void pbr_map_schedule_policy_from_nhg(const char *nh_group)
&& (strcmp(nh_group, pbrms->nhgrp_name) == 0)) {
pbrms->nhs_installed = true;

pbr_map_check(pbrms);
pbr_map_check(pbrms, false);
}

if (pbrms->nhg
&& (strcmp(nh_group, pbrms->internal_nhg_name)
== 0)) {
pbrms->nhs_installed = true;

pbr_map_check(pbrms);
pbr_map_check(pbrms, false);
}
}
}
Expand Down Expand Up @@ -656,7 +656,8 @@ void pbr_map_policy_install(const char *name)
pbrms->seqno);
for (ALL_LIST_ELEMENTS_RO(pbrm->incoming, inode, pmi))
if (pbr_map_interface_is_valid(pmi))
pbr_send_pbr_map(pbrms, pmi, true);
pbr_send_pbr_map(pbrms, pmi, true,
false);
}
}
}
Expand All @@ -668,7 +669,7 @@ void pbr_map_policy_delete(struct pbr_map *pbrm, struct pbr_map_interface *pmi)


for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms))
pbr_send_pbr_map(pbrms, pmi, false);
pbr_send_pbr_map(pbrms, pmi, false, false);

pmi->delete = true;
}
Expand Down Expand Up @@ -710,13 +711,13 @@ void pbr_map_check_nh_group_change(const char *nh_group)
pbrm->incoming, inode,
pmi))
pbr_send_pbr_map(pbrms, pmi,
false);
false, false);
}
}
}
}

void pbr_map_check(struct pbr_map_sequence *pbrms)
void pbr_map_check(struct pbr_map_sequence *pbrms, bool changed)
{
struct pbr_map *pbrm;
bool install;
Expand All @@ -741,7 +742,7 @@ void pbr_map_check(struct pbr_map_sequence *pbrms)
}

if (install)
pbr_map_pbrms_install(pbrms);
pbr_map_pbrms_install(pbrms, changed);
else
pbr_map_pbrms_uninstall(pbrms);
}
Expand All @@ -755,7 +756,7 @@ void pbr_map_install(struct pbr_map *pbrm)
return;

for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node, pbrms))
pbr_map_pbrms_install(pbrms);
pbr_map_pbrms_install(pbrms, false);
}

void pbr_map_init(void)
Expand Down
10 changes: 9 additions & 1 deletion pbrd/pbr_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,15 @@ extern void pbr_map_init(void);

extern bool pbr_map_check_valid(const char *name);

extern void pbr_map_check(struct pbr_map_sequence *pbrms);
/**
* Re-check the pbr map for validity.
*
* Install if valid, remove if not.
*
* If changed is set, the config on the on the map has changed somewhere
* and the rules need to be replaced if valid.
*/
extern void pbr_map_check(struct pbr_map_sequence *pbrms, bool changed);
extern void pbr_map_check_nh_group_change(const char *nh_group);
extern void pbr_map_reason_string(unsigned int reason, char *buf, int size);

Expand Down
28 changes: 24 additions & 4 deletions pbrd/pbr_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,26 @@ char *pbr_nht_nexthop_make_name(char *name, size_t l,
return buffer;
}

void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms)
void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms,
const struct nexthop *nhop)
{
struct pbr_nexthop_group_cache *pnhgc;
struct pbr_nexthop_group_cache find;
struct pbr_nexthop_cache *pnhc;
struct pbr_nexthop_cache lookup;
struct nexthop *nh;
char buf[PBR_NHC_NAMELEN];

pbrms->nhg = nexthop_group_new();
pbrms->internal_nhg_name = XSTRDUP(
MTYPE_TMP,
pbr_nht_nexthop_make_name(pbrms->parent->name, PBR_NHC_NAMELEN,
pbrms->seqno, buf));

nh = nexthop_new();
memcpy(nh, nhop, sizeof(*nh));

nexthop_group_add_sorted(pbrms->nhg, nh);

memset(&find, 0, sizeof(find));
pbr_nht_nexthop_make_name(pbrms->parent->name, PBR_NHC_NAMELEN,
Expand All @@ -539,7 +553,7 @@ void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms)
pbr_nht_install_nexthop_group(pnhgc, *pbrms->nhg);
}

void pbr_nht_delete_individual_nexthop(struct pbr_map_sequence *pbrms)
static void pbr_nht_release_individual_nexthop(struct pbr_map_sequence *pbrms)
{
struct pbr_nexthop_group_cache *pnhgc;
struct pbr_nexthop_group_cache find;
Expand All @@ -548,8 +562,6 @@ void pbr_nht_delete_individual_nexthop(struct pbr_map_sequence *pbrms)
struct nexthop *nh;
enum nexthop_types_t nh_type = 0;

pbr_map_delete_nexthops(pbrms);

memset(&find, 0, sizeof(find));
snprintf(find.name, sizeof(find.name), "%s", pbrms->internal_nhg_name);
pnhgc = hash_lookup(pbr_nhg_hash, &find);
Expand All @@ -564,11 +576,19 @@ void pbr_nht_delete_individual_nexthop(struct pbr_map_sequence *pbrms)
pbr_nht_uninstall_nexthop_group(pnhgc, *pbrms->nhg, nh_type);

hash_release(pbr_nhg_hash, pnhgc);
pbr_nhgc_delete(pnhgc);

nexthop_group_delete(&pbrms->nhg);
XFREE(MTYPE_TMP, pbrms->internal_nhg_name);
}

void pbr_nht_delete_individual_nexthop(struct pbr_map_sequence *pbrms)
{
pbr_map_delete_nexthops(pbrms);

pbr_nht_release_individual_nexthop(pbrms);
}

struct pbr_nexthop_group_cache *pbr_nht_add_group(const char *name)
{
struct nexthop *nhop;
Expand Down
3 changes: 2 additions & 1 deletion pbrd/pbr_nht.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ extern struct pbr_nexthop_group_cache *pbr_nht_add_group(const char *name);
extern void pbr_nht_change_group(const char *name);
extern void pbr_nht_delete_group(const char *name);

extern void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms);
extern void pbr_nht_add_individual_nexthop(struct pbr_map_sequence *pbrms,
const struct nexthop *nhop);
extern void pbr_nht_delete_individual_nexthop(struct pbr_map_sequence *pbrms);
/*
* Given the tableid of the installed default
Expand Down
Loading

0 comments on commit 82d86ab

Please sign in to comment.