From cd545ff9e2df87114ed7133334e959e182cec880 Mon Sep 17 00:00:00 2001 From: Don Slice Date: Thu, 15 Feb 2018 21:22:44 +0000 Subject: [PATCH] pbrd: add ability to delete pbr-policy from interface Signed-off-by: Don Slice --- pbrd/pbr_map.c | 21 +++++++++++++++++++-- pbrd/pbr_map.h | 2 ++ pbrd/pbr_vty.c | 34 ++++++++++++++++++---------------- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/pbrd/pbr_map.c b/pbrd/pbr_map.c index c7c9674fc604..3582d8fba547 100644 --- a/pbrd/pbr_map.c +++ b/pbrd/pbr_map.c @@ -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) diff --git a/pbrd/pbr_map.h b/pbrd/pbr_map.h index cb8e96a968c1..070b630e2d0d 100644 --- a/pbrd/pbr_map.h +++ b/pbrd/pbr_map.h @@ -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); diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index ef2ad4c70c43..7e1fee5f0a7b 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -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; }