From 9ca25fedba875265f191af92f1887d35076b6403 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 25 Aug 2017 08:31:03 -0400 Subject: *: 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 --- zebra/zebra_routemap.c | 55 +++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'zebra/zebra_routemap.c') 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' -- cgit v1.2.3