diff options
author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-08-25 14:31:03 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-08-25 16:48:30 +0200 |
commit | 9ca25fedba875265f191af92f1887d35076b6403 (patch) | |
tree | fc57ad9703a4adadfdad3f0776c683b81a858188 /zebra/zebra_routemap.c | |
parent | *: fix assorted issues detected by Coverity Scan (diff) | |
download | frr-9ca25fedba875265f191af92f1887d35076b6403.tar.xz frr-9ca25fedba875265f191af92f1887d35076b6403.zip |
*: Add RMAP_COMPILE_SUCCESS to enum
Add the RMAP_COMPILE_SUCCESS and switch over to using it.
Refactoring allows a removal of a if statement to just
use the switch statement already in place. Additionally
the reworking cleans up memory freeing in a couple of spots.
In one spot we no longer will leak memory too.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'zebra/zebra_routemap.c')
-rw-r--r-- | zebra/zebra_routemap.c | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index c738cde0a..0fa616bef 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -62,23 +62,26 @@ static int zebra_route_match_add(struct vty *vty, const char *command, { VTY_DECLVAR_CONTEXT(route_map_index, index); int ret; + int retval = CMD_SUCCESS; ret = route_map_add_match(index, command, arg); - if (ret) { - switch (ret) { - case RMAP_RULE_MISSING: - vty_out(vty, "%% Zebra Can't find rule.\n"); - return CMD_WARNING_CONFIG_FAILED; - case RMAP_COMPILE_ERROR: - vty_out(vty, "%% Zebra Argument is malformed.\n"); - return CMD_WARNING_CONFIG_FAILED; + switch (ret) { + case RMAP_RULE_MISSING: + vty_out(vty, "%% Zebra Can't find rule.\n"); + retval = CMD_WARNING_CONFIG_FAILED; + break; + case RMAP_COMPILE_ERROR: + vty_out(vty, "%% Zebra Argument is malformed.\n"); + retval = CMD_WARNING_CONFIG_FAILED; + break; + case RMAP_COMPILE_SUCCESS: + if (type != RMAP_EVENT_MATCH_ADDED) { + route_map_upd8_dependency(type, arg, index->map->name); } + break; } - if (type != RMAP_EVENT_MATCH_ADDED) { - route_map_upd8_dependency(type, arg, index->map->name); - } - return CMD_SUCCESS; + return retval; } /* Delete zebra route map rule. */ @@ -87,6 +90,7 @@ static int zebra_route_match_delete(struct vty *vty, const char *command, { VTY_DECLVAR_CONTEXT(route_map_index, index); int ret; + int retval = CMD_SUCCESS; char *dep_name = NULL; const char *tmpstr; char *rmap_name = NULL; @@ -105,26 +109,27 @@ static int zebra_route_match_delete(struct vty *vty, const char *command, } ret = route_map_delete_match(index, command, arg); - if (ret) { - switch (ret) { - case RMAP_RULE_MISSING: - vty_out(vty, "%% Zebra Can't find rule.\n"); - return CMD_WARNING_CONFIG_FAILED; - case RMAP_COMPILE_ERROR: - vty_out(vty, "%% Zebra Argument is malformed.\n"); - return CMD_WARNING_CONFIG_FAILED; - } + switch (ret) { + case RMAP_RULE_MISSING: + vty_out(vty, "%% Zebra Can't find rule.\n"); + retval = CMD_WARNING_CONFIG_FAILED; + break; + case RMAP_COMPILE_ERROR: + vty_out(vty, "%% Zebra Argument is malformed.\n"); + retval = CMD_WARNING_CONFIG_FAILED; + break; + case RMAP_COMPILE_SUCCESS: + if (type != RMAP_EVENT_MATCH_DELETED && dep_name) + route_map_upd8_dependency(type, dep_name, rmap_name); + break; } - if (type != RMAP_EVENT_MATCH_DELETED && dep_name) - route_map_upd8_dependency(type, dep_name, rmap_name); - if (dep_name) XFREE(MTYPE_ROUTE_MAP_RULE, dep_name); if (rmap_name) XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name); - return CMD_SUCCESS; + return retval; } /* 'match tag TAG' |