From 4a444b8ffe42354d0a54e955a1e7d2080eb30ec9 Mon Sep 17 00:00:00 2001 From: Don Slice Date: Thu, 22 Feb 2018 17:34:06 +0000 Subject: [PATCH] pbrd: add no pbr-map capability Signed-off-by: Don Slice --- lib/nexthop_group.c | 2 +- pbrd/pbr_event.c | 1 + pbrd/pbr_map.c | 21 +++++++++++++++++ pbrd/pbr_map.h | 2 +- pbrd/pbr_vty.c | 55 +++++++++++++++++++++++++++++++++++++++------ vtysh/vtysh.c | 12 +++++----- 6 files changed, 78 insertions(+), 15 deletions(-) diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index 614e1dab759a..e32733ee38a5 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -188,7 +188,7 @@ DEFUN_NOSH(nexthop_group, nexthop_group_cmd, "nexthop-group NAME", DEFUN_NOSH(no_nexthop_group, no_nexthop_group_cmd, "no nexthop-group NAME", NO_STR - "Enter into the nexthop-group submode\n" + "Delete the nexthop-group\n" "Specify the NAME of the nexthop-group\n") { const char *nhg_name = argv[2]->arg; diff --git a/pbrd/pbr_event.c b/pbrd/pbr_event.c index b6b5da5ad008..da22493c0d57 100644 --- a/pbrd/pbr_event.c +++ b/pbrd/pbr_event.c @@ -125,6 +125,7 @@ static wq_item_status pbr_event_process_wq(struct work_queue *wq, void *data) pbr_map_check(pbre->name, pbre->seqno); break; case PBR_MAP_DELETE: + pbr_map_delete(pbre->name, pbre->seqno); break; case PBR_NH_CHANGED: break; diff --git a/pbrd/pbr_map.c b/pbrd/pbr_map.c index 51e69dec112a..3f6f7e677c6a 100644 --- a/pbrd/pbr_map.c +++ b/pbrd/pbr_map.c @@ -133,6 +133,27 @@ struct pbr_map *pbrm_find(const char *name) return RB_FIND(pbr_map_entry_head, &pbr_maps, &pbrm); } +extern void pbr_map_delete(const char *name, uint32_t seqno) +{ + struct pbr_map *pbrm; + struct pbr_map_sequence *pbrms; + struct listnode *node, *next_node; + + pbrm = pbrm_find(name); + + if (pbrm->installed) + pbr_send_pbr_map(pbrm, 0); + + for (ALL_LIST_ELEMENTS(pbrm->seqnumbers, node, next_node, pbrms)) { + if (pbrms) + if (pbrms->reason & PBR_MAP_DEL_SEQUENCE_NUMBER) + listnode_delete(pbrm->seqnumbers, pbrms); + } + + if (pbrm->seqnumbers->count == 0) + RB_REMOVE(pbr_map_entry_head, &pbr_maps, pbrm); +} + extern struct pbr_map_sequence *pbrms_get(const char *name, uint32_t seqno) { struct pbr_map *pbrm; diff --git a/pbrd/pbr_map.h b/pbrd/pbr_map.h index 328f6aa99fae..18375319f8fa 100644 --- a/pbrd/pbr_map.h +++ b/pbrd/pbr_map.h @@ -106,7 +106,7 @@ extern struct pbr_map_entry_head pbr_maps; 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_delete(const char *name, uint32_t seqno); 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); diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index 5402b5d5ee64..8211a265d7b6 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -39,13 +39,11 @@ #include "pbrd/pbr_vty_clippy.c" #endif -DEFUN_NOSH (pbr_map, - pbr_map_cmd, - "pbr-map WORD seq (1-1000)", - "Create pbr-map or enter pbr-map command mode\n" - "The name of the PBR MAP\n" - "Sequence to insert to/delete from existing pbr-map entry\n" - "Sequence number\n") +DEFUN_NOSH(pbr_map, pbr_map_cmd, "pbr-map WORD seq (1-1000)", + "Create pbr-map or enter pbr-map command mode\n" + "The name of the PBR MAP\n" + "Sequence to insert in existing pbr-map entry\n" + "Sequence number\n") { const char *pbrm_name = argv[1]->arg; uint32_t seqno = atoi(argv[3]->arg); @@ -57,6 +55,48 @@ DEFUN_NOSH (pbr_map, return CMD_SUCCESS; } +DEFUN_NOSH(no_pbr_map, no_pbr_map_cmd, "no pbr-map WORD [seq (1-65535)]", + NO_STR + "Delete pbr-map\n" + "The name of the PBR MAP\n" + "Sequence to delete from existing pbr-map entry\n" + "Sequence number\n") +{ + const char *pbrm_name = argv[2]->arg; + uint32_t seqno = 0; + struct pbr_map *pbrm = pbrm_find(pbrm_name); + struct pbr_event *pbre; + struct pbr_map_sequence *pbrms; + struct listnode *node, *next_node; + + if (argc > 3) + seqno = atoi(argv[4]->arg); + + if (!pbrm) + vty_out(vty, "pbr-map %s not found\n", pbrm_name); + else { + if (seqno) { + pbrms = pbrms_get(pbrm->name, seqno); + pbrms->reason |= PBR_MAP_DEL_SEQUENCE_NUMBER; + } else { + for (ALL_LIST_ELEMENTS(pbrm->seqnumbers, node, + next_node, pbrms)) { + if (pbrms) + pbrms->reason |= + PBR_MAP_DEL_SEQUENCE_NUMBER; + } + } + + pbre = pbr_event_new(); + pbre->event = PBR_MAP_DELETE; + pbre->seqno = seqno; + strlcpy(pbre->name, pbrm_name, sizeof(pbre->name)); + pbr_event_enqueue(pbre); + } + + return CMD_SUCCESS; +} + DEFPY(pbr_map_match_src, pbr_map_match_src_cmd, "[no] match src-ip $prefix", NO_STR @@ -416,6 +456,7 @@ void pbr_vty_init(void) install_default(PBRMAP_NODE); install_element(CONFIG_NODE, &pbr_map_cmd); + install_element(CONFIG_NODE, &no_pbr_map_cmd); install_element(INTERFACE_NODE, &pbr_policy_cmd); install_element(CONFIG_NODE, &pbr_table_range_cmd); install_element(CONFIG_NODE, &pbr_rule_range_cmd); diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 1b394c2e905e..ed974e2e81aa 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -1483,12 +1483,12 @@ DEFUNSH(VTYSH_PBRD, vtysh_pbr_map, vtysh_pbr_map_cmd, return CMD_SUCCESS; } -DEFSH(VTYSH_PBRD, vtysh_no_pbr_map_cmd, "no pbr-map WORD seq (1-65535)", - NO_STR - "Create pbr-map or enter pbr-map command mode\n" - "The name of the PBR MAP\n" - "Sequence to insert to/delete from existing pbr-map entry\n" - "Sequence number\n") +DEFSH(VTYSH_PBRD, vtysh_no_pbr_map_cmd, "no pbr-map WORD [seq (1-65535)]", + NO_STR + "Delete pbr-map\n" + "The name of the PBR MAP\n" + "Sequence to delete from existing pbr-map entry\n" + "Sequence number\n") DEFUNSH(VTYSH_ALL, vtysh_line_vty, vtysh_line_vty_cmd, "line vty", "Configure a terminal line\n"