Skip to content

Commit

Permalink
pbrd: display reason string in show pbr map
Browse files Browse the repository at this point in the history
Signed-off-by: Don Slice <[email protected]>
  • Loading branch information
dslicenc authored and donaldsharp committed Feb 23, 2018
1 parent c2a41c6 commit ae027d3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
23 changes: 23 additions & 0 deletions pbrd/pbr_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ static int pbr_map_interface_compare(const struct interface *ifp1,
return strcmp(ifp1->name, ifp2->name);
}

static const char *pbr_map_reason_str[] = {
"Invalid NH-group", "Invalid NH", "No Nexthops",
"Both NH and NH-Group", "Invalid Src or Dst", "Deleting Sequence",
};

void pbr_map_reason_string(unsigned int reason, char *buf, int size)
{
unsigned int bit;
int len = 0;

if (!buf)
return;

for (bit = 0; bit < array_size(pbr_map_reason_str); bit++) {
if ((reason & (1 << bit)) && (len < size)) {
len += snprintf((buf + len), (size - len), "%s%s",
(len > 0) ? ", " : "",
pbr_map_reason_str[bit]);
}
}
}


void pbr_map_interface_delete(struct pbr_map *pbrm, struct interface *ifp_del)
{

Expand Down
2 changes: 1 addition & 1 deletion pbrd/pbr_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ extern bool pbr_map_check_valid(const char *name);
extern void pbr_map_check(const char *name, uint32_t seqno);
extern void pbr_map_check_nh_group_change(const char *nh_group);
extern void pbr_map_check_policy_change(const char *name);

extern void pbr_map_reason_string(unsigned int reason, char *buf, int size);
extern void pbr_map_add_interfaces(const char *name);

extern void pbr_map_schedule_policy_from_nhg(const char *nh_group);
Expand Down
11 changes: 8 additions & 3 deletions pbrd/pbr_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ DEFPY (show_pbr_map,
struct pbr_map *pbrm;
struct listnode *node;
char buf[PREFIX_STRLEN];
char rbuf[64];

RB_FOREACH (pbrm, pbr_map_entry_head, &pbr_maps) {
if (!name || (strcmp(name, pbrm->name) == 0)) {
Expand All @@ -302,11 +303,15 @@ DEFPY (show_pbr_map,

for (ALL_LIST_ELEMENTS_RO(pbrm->seqnumbers, node,
pbrms)) {
if (pbrms->reason)
pbr_map_reason_string(pbrms->reason,
rbuf,
sizeof(rbuf));
vty_out(vty,
" Seq: %u rule: %u Reason: %" PRIu64
"\n",
" Seq: %u rule: %u Reason: %s\n",
pbrms->seqno, pbrms->ruleno,
pbrms->reason);
pbrms->reason ? rbuf : "Valid");

if (pbrms->src)
vty_out(vty, "\tSRC Match: %s\n",
prefix2str(pbrms->src, buf,
Expand Down

0 comments on commit ae027d3

Please sign in to comment.