Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pbrd: add ability to delete pbr-policy from interface #8

Merged
merged 1 commit into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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