Skip to content

Commit

Permalink
pbrd: add ability to delete pbr-policy from interface
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 Feb 15, 2018
1 parent fb84254 commit cd545ff
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
21 changes: 19 additions & 2 deletions pbrd/pbr_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,26 @@ static int pbr_map_interface_compare(const struct interface *ifp1,
return strcmp(ifp1->name, ifp2->name);
}

static void pbr_map_interface_delete(struct interface *ifp)
void pbr_map_interface_delete(struct pbr_map *pbrm, struct interface *ifp_del)
{
return;

struct listnode *node;
struct interface *ifp;
struct pbr_event *pbre;

for (ALL_LIST_ELEMENTS_RO(pbrm->incoming, node, ifp)) {
if (ifp_del == ifp)
break;
}

if (ifp) {
listnode_delete(pbrm->incoming, ifp_del);

pbre = pbr_event_new();
pbre->event = PBR_POLICY_CHANGED;
strcpy(pbre->name, pbrm->name);
pbr_event_enqueue(pbre);
}
}

void pbr_map_add_interface(struct pbr_map *pbrm, struct interface *ifp_add)
Expand Down
2 changes: 2 additions & 0 deletions pbrd/pbr_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ extern struct pbr_map_sequence *pbrms_get(const char *name, uint32_t seqno);
extern struct pbr_map *pbrm_find(const char *name);

extern void pbr_map_add_interface(struct pbr_map *pbrm, struct interface *ifp);
extern void pbr_map_interface_delete(struct pbr_map *pbrm,
struct interface *ifp);
extern void pbr_map_write_interfaces(struct vty *vty, struct interface *ifp);
extern void pbr_map_init(void);

Expand Down
34 changes: 18 additions & 16 deletions pbrd/pbr_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,28 +175,30 @@ DEFPY (pbr_rule_range,
}

DEFPY (pbr_policy,
pbr_policy_cmd,
"pbr-policy NAME$mapname",
"Policy to use\n"
"Name of the pbr-map to apply\n")
pbr_policy_cmd,
"[no] pbr-policy NAME$mapname",
NO_STR
"Policy to use\n"
"Name of the pbr-map to apply\n")
{
VTY_DECLVAR_CONTEXT(interface, ifp);
struct pbr_map *pbrm;
struct pbr_interface *pbr_ifp = ifp->info;

/*
* In the future we would probably want to
* allow pre-creation of the pbr-map
* here. But for getting something
* up and running let's not do that yet.
*/
pbrm = pbrm_find(mapname);
if (!pbrm) {
struct pbr_interface *pbr_ifp = ifp->info;

strcpy(pbr_ifp->mapname, mapname);
vty_out (vty, "storing mapname %s on pbr_ifp\n", pbr_ifp->mapname);
} else
pbr_map_add_interface(pbrm, ifp);
if (no) {
if (pbrm)
pbr_map_interface_delete(pbrm, ifp);
else
if (strcmp(pbr_ifp->mapname, mapname) == 0)
strcpy(pbr_ifp->mapname, "");
} else {
if (pbrm)
pbr_map_add_interface(pbrm, ifp);
else
strcpy(pbr_ifp->mapname, mapname);
}

return CMD_SUCCESS;
}
Expand Down

0 comments on commit cd545ff

Please sign in to comment.