From 412e5cd94f087fbb68a6c8805a8465f526e45bee Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Fri, 23 Sep 2016 22:12:11 +0000 Subject: [PATCH] lib: added strmatch() Signed-off-by: Daniel Walton --- lib/str.c | 8 ++++++++ lib/str.h | 2 ++ zebra/zebra_vty.c | 30 +++++++++++++++--------------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/str.c b/lib/str.c index 16f759c074..cfdb6e024e 100644 --- a/lib/str.c +++ b/lib/str.c @@ -133,3 +133,11 @@ strndup (const char *s, size_t maxlen) return (char *) memcpy (new, s, len); } #endif + +extern int +strmatch (const char *str1, const char *str2) +{ + if (!strcmp(str1, str2)) + return 1; + return 0; +} diff --git a/lib/str.h b/lib/str.h index 7b83fe1cb1..dc8e7e5d67 100644 --- a/lib/str.h +++ b/lib/str.h @@ -29,5 +29,7 @@ extern size_t strnlen(const char *s, size_t maxlen); extern char * strndup (const char *, size_t); #endif +extern int strmatch (const char *, const char *); + #endif /* _ZEBRA_STR_H */ diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 17e9538ba0..ebe0ca4054 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3014,7 +3014,7 @@ DEFUN (show_ip_route_tag, u_short tag = 0; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) { VRF_GET_ID (vrf_id, argv[4]->arg); tag = atoi(argv[6]->arg); @@ -3063,7 +3063,7 @@ DEFUN (show_ip_route_prefix_longer, int first = 1; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) { VRF_GET_ID (vrf_id, argv[4]->arg); ret = str2prefix (argv[5]->arg, &p); @@ -3114,7 +3114,7 @@ DEFUN (show_ip_route_supernets, int first = 1; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) VRF_GET_ID (vrf_id, argv[4]->arg); table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); @@ -3158,7 +3158,7 @@ DEFUN (show_ip_route_protocol, int first = 1; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) { type = proto_redistnum (AFI_IP, argv[5]->arg); VRF_GET_ID (vrf_id, argv[4]->arg); @@ -3246,7 +3246,7 @@ DEFUN (show_ip_route_addr, struct route_node *rn; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) { VRF_GET_ID (vrf_id, argv[4]->arg); ret = str2prefix_ipv4 (argv[5]->arg, &p); @@ -3295,7 +3295,7 @@ DEFUN (show_ip_route_prefix, struct route_node *rn; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) { VRF_GET_ID (vrf_id, argv[4]->arg); ret = str2prefix_ipv4 (argv[5]->arg, &p); @@ -3492,7 +3492,7 @@ DEFUN (show_ip_route_summary, struct route_table *table; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) VRF_GET_ID (vrf_id, argv[4]->arg); table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); @@ -3519,7 +3519,7 @@ DEFUN (show_ip_route_summary_prefix, struct route_table *table; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) VRF_GET_ID (vrf_id, argv[4]->arg); table = zebra_vrf_table (AFI_IP, SAFI_UNICAST, vrf_id); @@ -5510,7 +5510,7 @@ DEFUN (show_ipv6_route_tag, u_short tag = 0; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) { VRF_GET_ID (vrf_id, argv[4]->arg); tag = atoi(argv[6]->arg); @@ -5559,7 +5559,7 @@ DEFUN (show_ipv6_route_prefix_longer, int first = 1; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) { VRF_GET_ID (vrf_id, argv[4]->arg); ret = str2prefix (argv[5]->arg, &p); @@ -5669,7 +5669,7 @@ DEFUN (show_ipv6_route_addr, struct route_node *rn; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) { VRF_GET_ID (vrf_id, argv[4]->arg); ret = str2prefix_ipv6 (argv[5]->arg, &p); @@ -5718,7 +5718,7 @@ DEFUN (show_ipv6_route_prefix, struct route_node *rn; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) { VRF_GET_ID (vrf_id, argv[4]->arg); ret = str2prefix_ipv6 (argv[5]->arg, &p); @@ -5764,7 +5764,7 @@ DEFUN (show_ipv6_route_summary, struct route_table *table; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) VRF_GET_ID (vrf_id, argv[4]->arg); table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id); @@ -5791,7 +5791,7 @@ DEFUN (show_ipv6_route_summary_prefix, struct route_table *table; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) VRF_GET_ID (vrf_id, argv[4]->arg); table = zebra_vrf_table (AFI_IP6, SAFI_UNICAST, vrf_id); @@ -5822,7 +5822,7 @@ DEFUN (show_ipv6_mroute, int first = 1; vrf_id_t vrf_id = VRF_DEFAULT; - if (strcmp(argv[3]->text, "vrf")) + if (strmatch(argv[3]->text, "vrf")) VRF_GET_ID (vrf_id, argv[4]->arg); table = zebra_vrf_table (AFI_IP6, SAFI_MULTICAST, vrf_id); -- 2.39.5