From 3fb481296623a3c7101e884c12ae33e113e42658 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sun, 12 Feb 2023 12:28:10 -0500 Subject: [PATCH 01/11] zebra: Use string for type instead of number Let's make it easier to debug instead of guessing Signed-off-by: Donald Sharp --- zebra/redistribute.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 4a8fe938ed..32d28f8002 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -118,13 +118,15 @@ static void zebra_redistribute(struct zserv *client, int type, RNODE_FOREACH_RE (rn, newre) { if (IS_ZEBRA_DEBUG_RIB) zlog_debug( - "%s: client %s %pRN(%u:%u) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d", + "%s: client %s %pRN(%u:%u) checking: selected=%d, type=%s, instance=%u, distance=%d, metric=%d zebra_check_addr=%d", __func__, zebra_route_string(client->proto), rn, vrf_id, newre->instance, !!CHECK_FLAG(newre->flags, ZEBRA_FLAG_SELECTED), - newre->type, newre->distance, + zebra_route_string(newre->type), + newre->instance, + newre->distance, newre->metric, zebra_check_addr(&rn->p)); From b7d234f21823d808587576cb685c07a7e340c4be Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sun, 12 Feb 2023 12:33:49 -0500 Subject: [PATCH 02/11] bgpd: Add warning when access list does not exist in route-map When using `match ip[v6] next-hop ` warn when creating the access-list that the access list does not yet exist and nothing can be done with it yet. Signed-off-by: Donald Sharp --- bgpd/bgp_routemap.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index d00bdd2571..139b306fdd 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -489,6 +489,13 @@ route_match_ip_address(void *rule, const struct prefix *prefix, void *object) access-list name. */ static void *route_match_ip_address_compile(const char *arg) { + struct access_list *alist; + + alist = access_list_lookup(AFI_IP, arg); + if (!alist) + zlog_warn( + "Access List specified %s does not exist yet, default will be NO_MATCH until it is created", + arg); return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } @@ -506,7 +513,7 @@ static const struct route_map_rule_cmd route_match_ip_address_cmd = { route_match_ip_address_free }; -/* `match ip next-hop IP_ADDRESS' */ +/* `match ip next-hop ' */ /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t @@ -3218,6 +3225,14 @@ route_match_ipv6_address(void *rule, const struct prefix *prefix, void *object) static void *route_match_ipv6_address_compile(const char *arg) { + struct access_list *alist; + + alist = access_list_lookup(AFI_IP6, arg); + if (!alist) + zlog_warn( + "Access List specified %s does not exist yet, default will be NO_MATCH until it is created", + arg); + return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg); } @@ -3332,7 +3347,7 @@ static const struct route_map_rule_cmd route_match_ipv6_next_hop_address_cmd = { route_match_ipv6_next_hop_address_free }; -/* `match ip next-hop IP_ADDRESS' */ +/* `match ip next-hop address IP_ADDRESS' */ static enum route_map_cmd_result_t route_match_ipv4_next_hop(void *rule, const struct prefix *prefix, void *object) From 5913a17a5b39353e82baf7e7c180c6ad0493522a Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 13 Feb 2023 09:06:56 -0500 Subject: [PATCH 03/11] lib: Start partitioning of rmap_debug to allow detail level Change the bool to a uint32_t and setup a flag to test for and set against. Future commits will allow a debug detail which should be used by match/set statements to give further context of what is going on. Signed-off-by: Donald Sharp --- lib/routemap.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/routemap.c b/lib/routemap.c index f56e6a6122..0ca7eaa555 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -613,7 +613,9 @@ static unsigned int route_map_dep_hash_make_key(const void *p); static void route_map_clear_all_references(char *rmap_name); static void route_map_rule_delete(struct route_map_rule_list *, struct route_map_rule *); -static bool rmap_debug; + +#define DEBUG_ROUTEMAP 0x01 +static uint32_t rmap_debug; /* New route map allocation. Please note route map's name must be specified. */ @@ -681,7 +683,7 @@ static struct route_map *route_map_add(const char *name) if (!map->ipv6_prefix_table) map->ipv6_prefix_table = route_table_init(); - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug("Add route-map %s", name); return map; } @@ -701,7 +703,7 @@ static void route_map_free_map(struct route_map *map) while ((index = map->head) != NULL) route_map_index_delete(index, 0); - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug("Deleting route-map %s", map->name); list = &route_map_master; @@ -1132,7 +1134,7 @@ void route_map_index_delete(struct route_map_index *index, int notify) QOBJ_UNREG(index); - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug("Deleting route-map %s sequence %d", index->map->name, index->pref); @@ -1243,7 +1245,7 @@ route_map_index_add(struct route_map *map, enum route_map_type type, int pref) route_map_notify_dependencies(map->name, RMAP_EVENT_CALL_ADDED); } - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug("Route-map %s add sequence %d, type: %s", map->name, pref, route_map_type_str(type)); @@ -2580,13 +2582,13 @@ route_map_result_t route_map_apply_ext(struct route_map *map, &match_ret); if (index) { index->applied++; - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug( "Best match route-map: %s, sequence: %d for pfx: %pFX, result: %s", map->name, index->pref, prefix, route_map_cmd_result_str(match_ret)); } else { - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug( "No best match sequence for pfx: %pFX in route-map: %s, result: %s", prefix, map->name, @@ -2612,7 +2614,7 @@ route_map_result_t route_map_apply_ext(struct route_map *map, /* Apply this index. */ match_ret = route_map_apply_match(&index->match_list, prefix, match_object); - if (rmap_debug) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) { zlog_debug( "Route-map: %s, sequence: %d, prefix: %pFX, result: %s", map->name, index->pref, prefix, @@ -2725,7 +2727,7 @@ route_map_result_t route_map_apply_ext(struct route_map *map, } route_map_apply_end: - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug("Route-map: %s, prefix: %pFX, result: %s", (map ? map->name : "null"), prefix, route_map_result_str(ret)); @@ -2780,7 +2782,7 @@ static void route_map_clear_reference(struct hash_bucket *bucket, void *arg) tmp_dep_data.rname = arg; dep_data = hash_release(dep->dep_rmap_hash, &tmp_dep_data); if (dep_data) { - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug("Clearing reference for %s to %s count: %d", dep->dep_name, tmp_dep_data.rname, dep_data->refcnt); @@ -2800,7 +2802,7 @@ static void route_map_clear_all_references(char *rmap_name) { int i; - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug("Clearing references for %s", rmap_name); for (i = 1; i < ROUTE_MAP_DEP_MAX; i++) { @@ -2876,7 +2878,7 @@ static int route_map_dep_update(struct hash *dephash, const char *dep_name, case RMAP_EVENT_LLIST_ADDED: case RMAP_EVENT_CALL_ADDED: case RMAP_EVENT_FILTER_ADDED: - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug("Adding dependency for filter %s in route-map %s", dep_name, rmap_name); dep = (struct route_map_dep *)hash_get( @@ -2905,7 +2907,7 @@ static int route_map_dep_update(struct hash *dephash, const char *dep_name, case RMAP_EVENT_LLIST_DELETED: case RMAP_EVENT_CALL_DELETED: case RMAP_EVENT_FILTER_DELETED: - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug("Deleting dependency for filter %s in route-map %s", dep_name, rmap_name); dep = (struct route_map_dep *)hash_get(dephash, dname, NULL); @@ -2959,7 +2961,7 @@ static int route_map_dep_update(struct hash *dephash, const char *dep_name, } if (dep) { - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) hash_iterate(dep->dep_rmap_hash, route_map_print_dependency, dname); } @@ -3031,7 +3033,7 @@ static void route_map_process_dependency(struct hash_bucket *bucket, void *data) dep_data = bucket->data; rmap_name = dep_data->rname; - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug("Notifying %s of dependency", rmap_name); if (route_map_master.event_hook) (*route_map_master.event_hook)(rmap_name); @@ -3079,7 +3081,7 @@ void route_map_notify_dependencies(const char *affected_name, if (!dep->this_hash) dep->this_hash = upd8_hash; - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) zlog_debug("Filter %s updated", dep->dep_name); hash_iterate(dep->dep_rmap_hash, route_map_process_dependency, (void *)event); @@ -3163,7 +3165,7 @@ DEFUN (debug_rmap, DEBUG_STR "Debug option set for route-maps\n") { - rmap_debug = true; + SET_FLAG(rmap_debug, DEBUG_ROUTEMAP); return CMD_SUCCESS; } @@ -3174,7 +3176,7 @@ DEFUN (no_debug_rmap, DEBUG_STR "Debug option set for route-maps\n") { - rmap_debug = false; + UNSET_FLAG(rmap_debug, DEBUG_ROUTEMAP); return CMD_SUCCESS; } @@ -3189,7 +3191,7 @@ static struct cmd_node rmap_debug_node = { void route_map_show_debug(struct vty *vty) { - if (rmap_debug) + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) vty_out(vty, "debug route-map\n"); } @@ -3198,7 +3200,7 @@ static int rmap_config_write_debug(struct vty *vty) { int write = 0; - if (rmap_debug) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP)) { vty_out(vty, "debug route-map\n"); write++; } @@ -3400,7 +3402,7 @@ void route_map_init(void) 8, route_map_dep_hash_make_key, route_map_dep_hash_cmp, "Route Map Dep Hash"); - rmap_debug = false; + UNSET_FLAG(rmap_debug, DEBUG_ROUTEMAP); route_map_cli_init(); From 1c950f37b74dd589b21246e7abbd7772b2632a5f Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 13 Feb 2023 09:14:56 -0500 Subject: [PATCH 04/11] lib: Add `debug routemap [detail]` Add the ability to turn on `debug routemap detail` for FRR. Signed-off-by: Donald Sharp --- lib/routemap.c | 31 +++++++++++++++++++++---------- lib/routemap.h | 4 ++++ lib/subdir.am | 1 + 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/routemap.c b/lib/routemap.c index 0ca7eaa555..4b9033594c 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -36,6 +36,8 @@ #include "json.h" #include "jhash.h" +#include "lib/routemap_clippy.c" + DEFINE_MTYPE_STATIC(LIB, ROUTE_MAP, "Route map"); DEFINE_MTYPE(LIB, ROUTE_MAP_NAME, "Route map name"); DEFINE_MTYPE_STATIC(LIB, ROUTE_MAP_INDEX, "Route map index"); @@ -614,8 +616,7 @@ static void route_map_clear_all_references(char *rmap_name); static void route_map_rule_delete(struct route_map_rule_list *, struct route_map_rule *); -#define DEBUG_ROUTEMAP 0x01 -static uint32_t rmap_debug; +uint32_t rmap_debug; /* New route map allocation. Please note route map's name must be specified. */ @@ -3159,24 +3160,34 @@ DEFUN (rmap_show_unused, return vty_show_unused_route_map(vty); } -DEFUN (debug_rmap, +DEFPY (debug_rmap, debug_rmap_cmd, - "debug route-map", + "debug route-map [detail]$detail", DEBUG_STR - "Debug option set for route-maps\n") + "Debug option set for route-maps\n" + "Detailed output\n") { - SET_FLAG(rmap_debug, DEBUG_ROUTEMAP); + if (!detail) + SET_FLAG(rmap_debug, DEBUG_ROUTEMAP); + else + SET_FLAG(rmap_debug, DEBUG_ROUTEMAP | DEBUG_ROUTEMAP_DETAIL); + return CMD_SUCCESS; } -DEFUN (no_debug_rmap, +DEFPY (no_debug_rmap, no_debug_rmap_cmd, - "no debug route-map", + "no debug route-map [detail]$detail", NO_STR DEBUG_STR - "Debug option set for route-maps\n") + "Debug option set for route-maps\n" + "Detailed output\n") { - UNSET_FLAG(rmap_debug, DEBUG_ROUTEMAP); + if (!detail) + UNSET_FLAG(rmap_debug, DEBUG_ROUTEMAP); + else + UNSET_FLAG(rmap_debug, DEBUG_ROUTEMAP | DEBUG_ROUTEMAP_DETAIL); + return CMD_SUCCESS; } diff --git a/lib/routemap.h b/lib/routemap.h index 9c78e15735..ddcb8f2ddb 100644 --- a/lib/routemap.h +++ b/lib/routemap.h @@ -37,6 +37,10 @@ DECLARE_MTYPE(ROUTE_MAP_NAME); DECLARE_MTYPE(ROUTE_MAP_RULE); DECLARE_MTYPE(ROUTE_MAP_COMPILED); +#define DEBUG_ROUTEMAP 0x01 +#define DEBUG_ROUTEMAP_DETAIL 0x02 +extern uint32_t rmap_debug; + /* Route map's type. */ enum route_map_type { RMAP_PERMIT, RMAP_DENY, RMAP_ANY }; diff --git a/lib/subdir.am b/lib/subdir.am index 18e9825a7a..dcff31ebba 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -152,6 +152,7 @@ clippy_scan += \ lib/nexthop_group.c \ lib/northbound_cli.c \ lib/plist.c \ + lib/routemap.c \ lib/routemap_cli.c \ lib/thread.c \ lib/vty.c \ From 819547b223c21d10e64ac5ce3ca3d0e615455506 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 13 Feb 2023 09:22:36 -0500 Subject: [PATCH 05/11] bgpd: Add access list lookup failure to `debug routemap detail` Let's give the operator some inkling as to why a routemap is not working the way they thing it should be when something goes wrong using it. Signed-off-by: Donald Sharp --- bgpd/bgp_routemap.c | 55 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 139b306fdd..c8cab1aa8e 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -475,8 +475,13 @@ route_match_ip_address(void *rule, const struct prefix *prefix, void *object) if (prefix->family == AF_INET) { alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) + if (alist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } return (access_list_apply(alist, prefix) == FILTER_DENY ? RMAP_NOMATCH @@ -530,8 +535,14 @@ route_match_ip_next_hop(void *rule, const struct prefix *prefix, void *object) p.prefixlen = IPV4_MAX_BITLEN; alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) + if (alist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", + __func__, (char *)rule); + return RMAP_NOMATCH; + } return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH @@ -584,8 +595,14 @@ route_match_ip_route_source(void *rule, const struct prefix *pfx, void *object) p.prefixlen = IPV4_MAX_BITLEN; alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) + if (alist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", + __func__, (char *)rule); + return RMAP_NOMATCH; + } return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH @@ -933,11 +950,21 @@ route_match_mac_address(void *rule, const struct prefix *prefix, void *object) struct prefix p; alist = access_list_lookup(AFI_L2VPN, (char *)rule); - if (alist == NULL) - return RMAP_NOMATCH; + if (alist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", + __func__, (char *)rule); - if (prefix->u.prefix_evpn.route_type != BGP_EVPN_MAC_IP_ROUTE) return RMAP_NOMATCH; + } + if (prefix->u.prefix_evpn.route_type != BGP_EVPN_MAC_IP_ROUTE) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Prefix %pFX is not a EVPN MAC IP ROUTE defaulting to NO_MATCH", + __func__, prefix); + return RMAP_NOMATCH; + } p.family = AF_ETHERNET; p.prefixlen = ETH_ALEN * 8; @@ -3213,8 +3240,14 @@ route_match_ipv6_address(void *rule, const struct prefix *prefix, void *object) if (prefix->family == AF_INET6) { alist = access_list_lookup(AFI_IP6, (char *)rule); - if (alist == NULL) + if (alist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", + __func__, (char *)rule); + return RMAP_NOMATCH; + } return (access_list_apply(alist, prefix) == FILTER_DENY ? RMAP_NOMATCH @@ -3264,8 +3297,14 @@ route_match_ipv6_next_hop(void *rule, const struct prefix *prefix, void *object) p.prefixlen = IPV6_MAX_BITLEN; alist = access_list_lookup(AFI_IP6, (char *)rule); - if (!alist) + if (!alist) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", + __func__, (char *)rule); + return RMAP_NOMATCH; + } if (access_list_apply(alist, &p) == FILTER_PERMIT) return RMAP_MATCH; From 2a3ffbb239ac16906c112a7be2fd927c71dafc27 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 13 Feb 2023 09:26:30 -0500 Subject: [PATCH 06/11] bgpd: Add useful information to prefix list lookup failures in routemaps When a routemap lookup of the prefix fails, add some useful data to the end operator about what has just gone wrong when they are using `debug routemap detail` Signed-off-by: Donald Sharp --- bgpd/bgp_routemap.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index c8cab1aa8e..5aa3ec4fd1 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -690,8 +690,13 @@ route_match_address_prefix_list(void *rule, afi_t afi, struct prefix_list *plist; plist = prefix_list_lookup(afi, (char *)rule); - if (plist == NULL) + if (plist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Prefix List %s specified does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } if (prefix->family == AF_FLOWSPEC) return route_match_prefix_list_flowspec(afi, plist, @@ -746,8 +751,13 @@ route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, p.prefixlen = IPV4_MAX_BITLEN; plist = prefix_list_lookup(AFI_IP, (char *)rule); - if (plist == NULL) + if (plist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Prefix List %s specified does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } return (prefix_list_apply(plist, &p) == PREFIX_DENY ? RMAP_NOMATCH @@ -790,8 +800,13 @@ route_match_ipv6_next_hop_prefix_list(void *rule, const struct prefix *prefix, p.prefixlen = IPV6_MAX_BITLEN; plist = prefix_list_lookup(AFI_IP6, (char *)rule); - if (!plist) + if (!plist) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Prefix List %s specified does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } if (prefix_list_apply(plist, &p) == PREFIX_PERMIT) return RMAP_MATCH; @@ -890,8 +905,13 @@ route_match_ip_route_source_prefix_list(void *rule, const struct prefix *prefix, p.prefixlen = IPV4_MAX_BITLEN; plist = prefix_list_lookup(AFI_IP, (char *)rule); - if (plist == NULL) + if (plist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Prefix List %s specified does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } return (prefix_list_apply(plist, &p) == PREFIX_DENY ? RMAP_NOMATCH From 46b2a036a54669766b5baf6c0caeda6bacef982a Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 13 Feb 2023 09:30:44 -0500 Subject: [PATCH 07/11] ospfd: Add access-list lookup failures to routemap code When using access-list and the access-list is not specified let's give the operator some clue about what is going on. Signed-off-by: Donald Sharp --- ospfd/ospf_routemap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ospfd/ospf_routemap.c b/ospfd/ospf_routemap.c index b1216626c4..703d342b33 100644 --- a/ospfd/ospf_routemap.c +++ b/ospfd/ospf_routemap.c @@ -134,8 +134,13 @@ route_match_ip_nexthop(void *rule, const struct prefix *prefix, void *object) p.prefixlen = IPV4_MAX_BITLEN; alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) + if (alist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH : RMAP_MATCH); @@ -249,8 +254,13 @@ route_match_ip_address(void *rule, const struct prefix *prefix, void *object) /* struct prefix_ipv4 match; */ alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) + if (alist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } return (access_list_apply(alist, prefix) == FILTER_DENY ? RMAP_NOMATCH : RMAP_MATCH); From 1df4bd1854d431adf0d51cb428e9a8658f967bd9 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 13 Feb 2023 09:32:25 -0500 Subject: [PATCH 08/11] ospfd: Warn operator about prefix lists not existing in routemaps Signed-off-by: Donald Sharp --- ospfd/ospf_routemap.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ospfd/ospf_routemap.c b/ospfd/ospf_routemap.c index 703d342b33..63460c773e 100644 --- a/ospfd/ospf_routemap.c +++ b/ospfd/ospf_routemap.c @@ -182,8 +182,13 @@ route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, p.prefixlen = IPV4_MAX_BITLEN; plist = prefix_list_lookup(AFI_IP, (char *)rule); - if (plist == NULL) + if (plist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Prefix List %s specified does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } return (prefix_list_apply(plist, &p) == PREFIX_DENY ? RMAP_NOMATCH : RMAP_MATCH); @@ -295,8 +300,14 @@ route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix, struct prefix_list *plist; plist = prefix_list_lookup(AFI_IP, (char *)rule); - if (plist == NULL) + if (plist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Prefix List %s specified does not exist defaulting to NO_MATCH", + __func__, (char *)rule); + return RMAP_NOMATCH; + } return (prefix_list_apply(plist, prefix) == PREFIX_DENY ? RMAP_NOMATCH : RMAP_MATCH); From ca4795dae6443cf5c3c16306ae5646b17c401df9 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 13 Feb 2023 09:34:38 -0500 Subject: [PATCH 09/11] zebra: Add prefix-list lookup failures to routemap debug detail Signed-off-by: Donald Sharp --- zebra/zebra_routemap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 5f307f95e3..7a0bb5bf46 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -1113,8 +1113,13 @@ route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix, return RMAP_NOMATCH; } plist = prefix_list_lookup(AFI_IP, (char *)rule); - if (plist == NULL) + if (plist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Prefix List %s specified does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } return (prefix_list_apply(plist, &p) == PREFIX_DENY ? RMAP_NOMATCH : RMAP_MATCH); @@ -1206,8 +1211,13 @@ route_match_address_prefix_list(void *rule, const struct prefix *prefix, struct prefix_list *plist; plist = prefix_list_lookup(afi, (char *)rule); - if (plist == NULL) + if (plist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Prefix List %s specified does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } return (prefix_list_apply(plist, prefix) == PREFIX_DENY ? RMAP_NOMATCH : RMAP_MATCH); From 774cd0cd6c55f293fabbda8fc717aed5ccc5d029 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 13 Feb 2023 09:35:55 -0500 Subject: [PATCH 10/11] zebra: Add access-list lookup failures to debug routemap detail Signed-off-by: Donald Sharp --- zebra/zebra_routemap.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 7a0bb5bf46..8f24404a44 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -1055,8 +1055,13 @@ route_match_ip_next_hop(void *rule, const struct prefix *prefix, void *object) return RMAP_NOMATCH; } alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) + if (alist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH : RMAP_MATCH); @@ -1154,8 +1159,13 @@ route_match_address(afi_t afi, void *rule, const struct prefix *prefix, struct access_list *alist; alist = access_list_lookup(afi, (char *)rule); - if (alist == NULL) + if (alist == NULL) { + if (CHECK_FLAG(rmap_debug, DEBUG_ROUTEMAP_DETAIL)) + zlog_debug( + "%s: Access-List Specified: %s does not exist defaulting to NO_MATCH", + __func__, (char *)rule); return RMAP_NOMATCH; + } return (access_list_apply(alist, prefix) == FILTER_DENY ? RMAP_NOMATCH : RMAP_MATCH); From 0c896167f36f0f3d264d96a03a959372a88a3b3d Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 13 Feb 2023 09:39:57 -0500 Subject: [PATCH 11/11] doc: Add documentation for `debug routemap [detail]` Signed-off-by: Donald Sharp --- doc/user/basic.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/user/basic.rst b/doc/user/basic.rst index 4a64d8f949..254dad8303 100644 --- a/doc/user/basic.rst +++ b/doc/user/basic.rst @@ -294,6 +294,12 @@ Basic Config Commands log files to quickly balloon in size. Remember to disable backtraces when they're no longer needed. +.. clicmd:: debug routemap [detail] + + This command turns on debugging of routemaps. When detail is specified + more data is provided to the operator about the reasoning about what + is going on in the routemap code. + .. clicmd:: service password-encryption Encrypt password.