From a162869ef0798ef98d756238c6b89108a69f5a5d Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Mon, 30 Sep 2019 15:02:15 -0300 Subject: [PATCH] lib: fix route map generic error output Two fixes here: * Don't attempt to use `vty` pointer in vty; * When `vty` is unavailable output to log; Signed-off-by: Rafael Zalamena --- lib/routemap.c | 68 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/lib/routemap.c b/lib/routemap.c index e07ad08123..5369fa771f 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -308,15 +308,21 @@ int generic_match_add(struct vty *vty, struct route_map_index *index, ret = route_map_add_match(index, command, arg, type); switch (ret) { case RMAP_RULE_MISSING: - vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst); + if (vty) + vty_out(vty, "%% [%s] Can't find rule.\n", + frr_protonameinst); + else + zlog_warn("Can't find rule: %s", command); return CMD_WARNING_CONFIG_FAILED; - break; case RMAP_COMPILE_ERROR: - vty_out(vty, - "%% [%s] Argument form is unsupported or malformed.\n", - frr_protonameinst); + if (vty) + vty_out(vty, + "%% [%s] Argument form is unsupported or malformed.\n", + frr_protonameinst); + else + zlog_warn("Argument form is unsupported or malformed: " + "%s %s", command, arg); return CMD_WARNING_CONFIG_FAILED; - break; case RMAP_COMPILE_SUCCESS: /* * Nothing to do here move along @@ -353,13 +359,21 @@ int generic_match_delete(struct vty *vty, struct route_map_index *index, ret = route_map_delete_match(index, command, dep_name, type); switch (ret) { case RMAP_RULE_MISSING: - vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst); + if (vty) + vty_out(vty, "%% [%s] Can't find rule.\n", + frr_protonameinst); + else + zlog_warn("Can't find rule: %s", command); retval = CMD_WARNING_CONFIG_FAILED; break; case RMAP_COMPILE_ERROR: - vty_out(vty, - "%% [%s] Argument form is unsupported or malformed.\n", - frr_protonameinst); + if (vty) + vty_out(vty, + "%% [%s] Argument form is unsupported or malformed.\n", + frr_protonameinst); + else + zlog_warn("Argument form is unsupported or malformed: " + "%s %s", command, arg); retval = CMD_WARNING_CONFIG_FAILED; break; case RMAP_COMPILE_SUCCESS: @@ -383,15 +397,20 @@ int generic_set_add(struct vty *vty, struct route_map_index *index, ret = route_map_add_set(index, command, arg); switch (ret) { case RMAP_RULE_MISSING: - vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst); + if (vty) + vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst); + else + zlog_warn("Can't find rule: %s", command); return CMD_WARNING_CONFIG_FAILED; - break; case RMAP_COMPILE_ERROR: - vty_out(vty, - "%% [%s] Argument form is unsupported or malformed.\n", - frr_protonameinst); + if (vty) + vty_out(vty, + "%% [%s] Argument form is unsupported or malformed.\n", + frr_protonameinst); + else + zlog_warn("Argument form is unsupported or malformed: " + "%s %s", command, arg); return CMD_WARNING_CONFIG_FAILED; - break; case RMAP_COMPILE_SUCCESS: break; } @@ -407,15 +426,20 @@ int generic_set_delete(struct vty *vty, struct route_map_index *index, ret = route_map_delete_set(index, command, arg); switch (ret) { case RMAP_RULE_MISSING: - vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst); + if (vty) + vty_out(vty, "%% [%s] Can't find rule.\n", frr_protonameinst); + else + zlog_warn("Can't find rule: %s", command); return CMD_WARNING_CONFIG_FAILED; - break; case RMAP_COMPILE_ERROR: - vty_out(vty, - "%% [%s] Argument form is unsupported or malformed.\n", - frr_protonameinst); + if (vty) + vty_out(vty, + "%% [%s] Argument form is unsupported or malformed.\n", + frr_protonameinst); + else + zlog_warn("Argument form is unsupported or malformed: " + "%s %s", command, arg); return CMD_WARNING_CONFIG_FAILED; - break; case RMAP_COMPILE_SUCCESS: break; }