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 no pbr-map capability #16

Merged
merged 1 commit into from
Feb 22, 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
2 changes: 1 addition & 1 deletion lib/nexthop_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions pbrd/pbr_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions pbrd/pbr_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pbrd/pbr_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
55 changes: 48 additions & 7 deletions pbrd/pbr_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 <A.B.C.D/M|X:X::X:X/M>$prefix",
NO_STR
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions vtysh/vtysh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down