diff options
author | Russ White <russ@riw.us> | 2017-06-29 17:06:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-29 17:06:52 +0200 |
commit | 5bee21f37c2d33d512fd0e7505a647e7f00eb2bb (patch) | |
tree | ef51007d56d222e4d4542631e23f84b7e6004be3 | |
parent | Merge pull request #754 from qlyoung/fix-argv-arg (diff) | |
parent | lib: some minor cli fixups for routemap (diff) | |
download | frr-5bee21f37c2d33d512fd0e7505a647e7f00eb2bb.tar.xz frr-5bee21f37c2d33d512fd0e7505a647e7f00eb2bb.zip |
Merge pull request #735 from qlyoung/fix-routemap
Fix routemap
-rw-r--r-- | lib/routemap.c | 32 | ||||
-rw-r--r-- | ospfd/ospf_routemap.c | 110 |
2 files changed, 36 insertions, 106 deletions
diff --git a/lib/routemap.c b/lib/routemap.c index 531a1faa1..7044550db 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -521,10 +521,12 @@ generic_match_add (struct vty *vty, struct route_map_index *index, switch (ret) { case RMAP_RULE_MISSING: - vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE); + vty_out (vty, "%% [%s] Can't find rule.%s", frr_protonameinst, + VTY_NEWLINE); return CMD_WARNING; case RMAP_COMPILE_ERROR: - vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE); + vty_out (vty, "%% [%s] Argument form is unsupported or malformed.%s", + frr_protonameinst, VTY_NEWLINE); return CMD_WARNING; } } @@ -567,10 +569,12 @@ generic_match_delete (struct vty *vty, struct route_map_index *index, switch (ret) { case RMAP_RULE_MISSING: - vty_out (vty, "%% BGP Can't find rule.%s", VTY_NEWLINE); + vty_out (vty, "%% [%s] Can't find rule.%s", frr_protonameinst, + VTY_NEWLINE); break; case RMAP_COMPILE_ERROR: - vty_out (vty, "%% BGP Argument is malformed.%s", VTY_NEWLINE); + vty_out (vty, "%% [%s] Argument form is unsupported or malformed.%s", + frr_protonameinst, VTY_NEWLINE); break; } if (dep_name) @@ -603,10 +607,12 @@ generic_set_add (struct vty *vty, struct route_map_index *index, switch (ret) { case RMAP_RULE_MISSING: - vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE); + vty_out (vty, "%% [%s] Can't find rule.%s", frr_protonameinst, + VTY_NEWLINE); return CMD_WARNING; case RMAP_COMPILE_ERROR: - vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE); + vty_out (vty, "%% [%s] Argument form is unsupported or malformed.%s", + frr_protonameinst, VTY_NEWLINE); return CMD_WARNING; } } @@ -625,10 +631,12 @@ generic_set_delete (struct vty *vty, struct route_map_index *index, switch (ret) { case RMAP_RULE_MISSING: - vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE); + vty_out (vty, "%% [%s] Can't find rule.%s", frr_protonameinst, + VTY_NEWLINE); return CMD_WARNING; case RMAP_COMPILE_ERROR: - vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE); + vty_out (vty, "%% [%s] Argument form is unsupported or malformed.%s", + frr_protonameinst, VTY_NEWLINE); return CMD_WARNING; } } @@ -2464,8 +2472,11 @@ DEFUN (set_metric, int idx_number = 2; VTY_DECLVAR_CONTEXT (route_map_index, index); + const char *pass = (argv[idx_number]->type == RANGE_TKN) ? + argv[idx_number]->arg : argv[idx_number]->text; + if (rmap_match_set_hook.set_metric) - return rmap_match_set_hook.set_metric (vty, index, "metric", argv[idx_number]->arg); + return rmap_match_set_hook.set_metric (vty, index, "metric", pass); return CMD_SUCCESS; } @@ -2595,7 +2606,8 @@ DEFUN (no_route_map, struct route_map *map; struct route_map_index *index; char *endptr = NULL; - int permit = argv[idx_permit_deny]->arg[0] == 'p' ? RMAP_PERMIT : RMAP_DENY; + int permit = strmatch (argv[idx_permit_deny]->text, "permit") ? + RMAP_PERMIT : RMAP_DENY; const char *prefstr = argv[idx_number]->arg; const char *mapname = argv[idx_word]->arg; unsigned long pref = strtoul (prefstr, &endptr, 10); diff --git a/ospfd/ospf_routemap.c b/ospfd/ospf_routemap.c index e2656e516..7032cbe1e 100644 --- a/ospfd/ospf_routemap.c +++ b/ospfd/ospf_routemap.c @@ -117,55 +117,6 @@ ospf_route_map_event (route_map_event_t event, const char *name) } } -/* Delete rip route map rule. */ -static int -ospf_route_match_delete (struct vty *vty, - const char *command, const char *arg) -{ - VTY_DECLVAR_CONTEXT(route_map_index, index); - int ret; - - ret = route_map_delete_match (index, command, arg); - if (ret) - { - switch (ret) - { - case RMAP_RULE_MISSING: - vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE); - return CMD_WARNING; - case RMAP_COMPILE_ERROR: - vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE); - return CMD_WARNING; - } - } - - return CMD_SUCCESS; -} - -static int -ospf_route_match_add (struct vty *vty, - const char *command, const char *arg) -{ - VTY_DECLVAR_CONTEXT(route_map_index, index); - int ret; - - ret = route_map_add_match (index, command, arg); - if (ret) - { - switch (ret) - { - case RMAP_RULE_MISSING: - vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE); - return CMD_WARNING; - case RMAP_COMPILE_ERROR: - vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE); - return CMD_WARNING; - } - } - - return CMD_SUCCESS; -} - /* `match ip netxthop ' */ /* Match function return 1 if match is success else return zero. */ static route_map_result_t @@ -449,35 +400,28 @@ static void * route_set_metric_compile (const char *arg) { u_int32_t *metric; - int32_t ret; /* OSPF doesn't support the +/- in set metric <+/-metric> check Ignore the +/- component */ if (! all_digit (arg)) { - if ((strncmp (arg, "+", 1) == 0 || strncmp (arg, "-", 1) == 0) && - all_digit (arg+1)) + if ((arg[0] == '+' || arg[0] == '-') && all_digit (arg+1)) { zlog_warn ("OSPF does not support 'set metric +/-'"); arg++; } else - { - return NULL; - } + { + if (strmatch (arg, "+rtt") || strmatch (arg, "-rtt")) + zlog_warn ("OSPF does not support 'set metric +rtt / -rtt'"); + return NULL; + } } metric = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); - ret = atoi (arg); + *metric = strtoul (arg, NULL, 10); - if (ret >= 0) - { - *metric = (u_int32_t)ret; - return metric; - } - - XFREE (MTYPE_ROUTE_MAP_COMPILED, metric); - return NULL; + return metric; } /* Free route map's compiled `set metric' value. */ @@ -581,35 +525,6 @@ static struct route_map_rule_cmd route_set_tag_cmd = route_map_rule_tag_free, }; -DEFUN (match_ip_nexthop, - match_ip_nexthop_cmd, - "match ip next-hop <(1-199)|(1300-2699)|WORD>", - MATCH_STR - IP_STR - "Match next-hop address of route\n" - "IP access-list number\n" - "IP access-list number (expanded range)\n" - "IP access-list name\n") -{ - int idx_acl = 3; - return ospf_route_match_add (vty, "ip next-hop", argv[idx_acl]->arg); -} - -DEFUN (no_match_ip_nexthop, - no_match_ip_nexthop_cmd, - "no match ip next-hop [<(1-199)|(1300-2699)|WORD>]", - NO_STR - MATCH_STR - IP_STR - "Match next-hop address of route\n" - "IP access-list number\n" - "IP access-list number (expanded range)\n" - "IP access-list name\n") -{ - char *al = (argc == 5) ? argv[4]->arg : NULL; - return ospf_route_match_delete (vty, "ip next-hop", al); -} - DEFUN (set_metric_type, set_metric_type_cmd, "set metric-type <type-1|type-2>", @@ -647,6 +562,12 @@ ospf_route_map_init (void) route_map_delete_hook (ospf_route_map_update); route_map_event_hook (ospf_route_map_event); + route_map_set_metric_hook (generic_set_add); + route_map_no_set_metric_hook (generic_set_delete); + + route_map_match_ip_next_hop_hook (generic_match_add); + route_map_no_match_ip_next_hop_hook (generic_match_delete); + route_map_match_interface_hook (generic_match_add); route_map_no_match_interface_hook (generic_match_delete); @@ -679,9 +600,6 @@ ospf_route_map_init (void) route_map_install_set (&route_set_metric_type_cmd); route_map_install_set (&route_set_tag_cmd); - install_element (RMAP_NODE, &match_ip_nexthop_cmd); - install_element (RMAP_NODE, &no_match_ip_nexthop_cmd); - install_element (RMAP_NODE, &set_metric_type_cmd); install_element (RMAP_NODE, &no_set_metric_type_cmd); } |