Skip to content

Commit

Permalink
Merge pull request #12796 from donaldsharp/routemap_debugging
Browse files Browse the repository at this point in the history
Routemap debugging
  • Loading branch information
riw777 authored Feb 14, 2023
2 parents b291ddb + 0c89616 commit bb7f023
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 51 deletions.
102 changes: 88 additions & 14 deletions bgpd/bgp_routemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -489,6 +494,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);
}

Expand All @@ -506,7 +518,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 <IP_ADDRESS_ACCESS_LIST_NAME>' */

/* Match function return 1 if match is success else return zero. */
static enum route_map_cmd_result_t
Expand All @@ -523,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
Expand Down Expand Up @@ -577,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
Expand Down Expand Up @@ -666,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,
Expand Down Expand Up @@ -722,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
Expand Down Expand Up @@ -766,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;
Expand Down Expand Up @@ -866,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
Expand Down Expand Up @@ -926,11 +970,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;
Expand Down Expand Up @@ -3206,8 +3260,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
Expand All @@ -3218,6 +3278,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);
}

Expand Down Expand Up @@ -3249,8 +3317,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;
Expand Down Expand Up @@ -3332,7 +3406,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)
Expand Down
6 changes: 6 additions & 0 deletions doc/user/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit bb7f023

Please sign in to comment.