diff options
Diffstat (limited to 'bgpd/bgp_debug.c')
| -rw-r--r-- | bgpd/bgp_debug.c | 174 |
1 files changed, 57 insertions, 117 deletions
diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index 92a22d71b3..9e540b63cb 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -51,6 +51,8 @@ #include "bgpd/bgp_flowspec.h" #include "bgpd/bgp_packet.h" +#include "bgpd/bgp_debug_clippy.c" + unsigned long conf_bgp_debug_as4; unsigned long conf_bgp_debug_neighbor_events; unsigned long conf_bgp_debug_events; @@ -324,7 +326,7 @@ static void bgp_debug_list_add_entry(struct list *list, const char *host, } static bool bgp_debug_list_remove_entry(struct list *list, const char *host, - struct prefix *p) + const struct prefix *p) { struct bgp_debug_filter *filter; struct listnode *node, *nnode; @@ -378,8 +380,6 @@ bool bgp_debug_peer_updout_enabled(char *host) /* Dump attribute. */ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size) { - char addrbuf[BUFSIZ]; - if (!attr) return false; @@ -395,15 +395,12 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size) /* Add MP case. */ if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL || attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) - snprintf(buf + strlen(buf), size - strlen(buf), - ", mp_nexthop %s", - inet_ntop(AF_INET6, &attr->mp_nexthop_global, addrbuf, - BUFSIZ)); + snprintfrr(buf + strlen(buf), size - strlen(buf), + ", mp_nexthop %pI6", &attr->mp_nexthop_global); if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) - snprintf(buf + strlen(buf), size - strlen(buf), "(%s)", - inet_ntop(AF_INET6, &attr->mp_nexthop_local, addrbuf, - BUFSIZ)); + snprintfrr(buf + strlen(buf), size - strlen(buf), "(%pI6)", + &attr->mp_nexthop_local); if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4) snprintfrr(buf, size, "nexthop %pI4", &attr->nexthop); @@ -635,17 +632,14 @@ static void bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc, } static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv, - int argc, struct prefix **argv_pp) + int argc, struct prefix *argv_p) { - struct prefix *argv_p; struct ethaddr mac = {}; struct ipaddr ip = {}; int evpn_type = 0; int mac_idx = 0; int ip_idx = 0; - argv_p = *argv_pp; - if (bgp_evpn_cli_parse_type(&evpn_type, argv, argc) < 0) return CMD_WARNING; @@ -1028,49 +1022,42 @@ DEFUN (no_debug_bgp_keepalive_peer, } /* debug bgp bestpath */ -DEFUN (debug_bgp_bestpath_prefix, +DEFPY (debug_bgp_bestpath_prefix, debug_bgp_bestpath_prefix_cmd, - "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>", + "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>$prefix", DEBUG_STR BGP_STR "BGP bestpath\n" "IPv4 prefix\n" "IPv6 prefix\n") { - struct prefix *argv_p; - int idx_ipv4_ipv6_prefixlen = 3; - - argv_p = prefix_new(); - (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); - apply_mask(argv_p); - if (!bgp_debug_bestpath_prefixes) bgp_debug_bestpath_prefixes = list_new(); if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes, NULL, - argv_p)) { + prefix)) { vty_out(vty, "BGP bestpath debugging is already enabled for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + prefix_str); return CMD_SUCCESS; } - bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes, NULL, argv_p); + bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes, NULL, prefix); if (vty->node == CONFIG_NODE) { DEBUG_ON(bestpath, BESTPATH); } else { TERM_DEBUG_ON(bestpath, BESTPATH); vty_out(vty, "BGP bestpath debugging is on for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + prefix_str); } return CMD_SUCCESS; } -DEFUN (no_debug_bgp_bestpath_prefix, +DEFPY (no_debug_bgp_bestpath_prefix, no_debug_bgp_bestpath_prefix_cmd, - "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>", + "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>$prefix", NO_STR DEBUG_STR BGP_STR @@ -1078,18 +1065,12 @@ DEFUN (no_debug_bgp_bestpath_prefix, "IPv4 prefix\n" "IPv6 prefix\n") { - int idx_ipv4_ipv6_prefixlen = 4; - struct prefix *argv_p; - int found_prefix = 0; - - argv_p = prefix_new(); - (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); - apply_mask(argv_p); + bool found_prefix = false; if (bgp_debug_bestpath_prefixes && !list_isempty(bgp_debug_bestpath_prefixes)) { found_prefix = bgp_debug_list_remove_entry( - bgp_debug_bestpath_prefixes, NULL, argv_p); + bgp_debug_bestpath_prefixes, NULL, prefix); if (list_isempty(bgp_debug_bestpath_prefixes)) { if (vty->node == CONFIG_NODE) { @@ -1104,10 +1085,10 @@ DEFUN (no_debug_bgp_bestpath_prefix, if (found_prefix) vty_out(vty, "BGP bestpath debugging is off for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + prefix_str); else vty_out(vty, "BGP bestpath debugging was not enabled for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + prefix_str); return CMD_SUCCESS; } @@ -1415,8 +1396,6 @@ DEFUN (no_debug_bgp_update_direct_peer, return CMD_SUCCESS; } -#include "bgpd/bgp_debug_clippy.c" - DEFPY (debug_bgp_update_prefix_afi_safi, debug_bgp_update_prefix_afi_safi_cmd, "debug bgp updates prefix l2vpn$afi evpn$safi type <<macip|2> mac <X:X:X:X:X:X|X:X:X:X:X:X/M> [ip <A.B.C.D|X:X::X:X>]|<multicast|3> ip <A.B.C.D|X:X::X:X>|<prefix|5> ip <A.B.C.D/M|X:X::X:X/M>>", @@ -1444,39 +1423,33 @@ DEFPY (debug_bgp_update_prefix_afi_safi, "IPv4 prefix\n" "IPv6 prefix\n") { - struct prefix *argv_p; + struct prefix argv_p; int ret = CMD_SUCCESS; - argv_p = prefix_new(); - ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p); - if (ret != CMD_SUCCESS) { - prefix_free(&argv_p); + if (ret != CMD_SUCCESS) return ret; - } if (!bgp_debug_update_prefixes) bgp_debug_update_prefixes = list_new(); - if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, argv_p)) { + if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, + &argv_p)) { vty_out(vty, "BGP updates debugging is already enabled for %pFX\n", - argv_p); - prefix_free(&argv_p); + &argv_p); return CMD_SUCCESS; } - bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, argv_p); + bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, &argv_p); if (vty->node == CONFIG_NODE) { DEBUG_ON(update, UPDATE_PREFIX); } else { TERM_DEBUG_ON(update, UPDATE_PREFIX); - vty_out(vty, "BGP updates debugging is on for %pFX\n", argv_p); + vty_out(vty, "BGP updates debugging is on for %pFX\n", &argv_p); } - prefix_free(&argv_p); - return CMD_SUCCESS; } @@ -1508,22 +1481,18 @@ DEFPY (no_debug_bgp_update_prefix_afi_safi, "IPv4 prefix\n" "IPv6 prefix\n") { - struct prefix *argv_p; + struct prefix argv_p; bool found_prefix = false; int ret = CMD_SUCCESS; - argv_p = prefix_new(); - ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p); - if (ret != CMD_SUCCESS) { - prefix_free(&argv_p); + if (ret != CMD_SUCCESS) return ret; - } if (bgp_debug_update_prefixes && !list_isempty(bgp_debug_update_prefixes)) { found_prefix = bgp_debug_list_remove_entry( - bgp_debug_update_prefixes, NULL, argv_p); + bgp_debug_update_prefixes, NULL, &argv_p); if (list_isempty(bgp_debug_update_prefixes)) { if (vty->node == CONFIG_NODE) { @@ -1537,20 +1506,19 @@ DEFPY (no_debug_bgp_update_prefix_afi_safi, } if (found_prefix) - vty_out(vty, "BGP updates debugging is off for %pFX\n", argv_p); + vty_out(vty, "BGP updates debugging is off for %pFX\n", + &argv_p); else vty_out(vty, "BGP updates debugging was not enabled for %pFX\n", - argv_p); - - prefix_free(&argv_p); + &argv_p); return ret; } -DEFUN (debug_bgp_update_prefix, +DEFPY (debug_bgp_update_prefix, debug_bgp_update_prefix_cmd, - "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>", + "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>$prefix", DEBUG_STR BGP_STR "BGP updates\n" @@ -1558,39 +1526,32 @@ DEFUN (debug_bgp_update_prefix, "IPv4 prefix\n" "IPv6 prefix\n") { - int idx_ipv4_ipv6_prefixlen = 4; - struct prefix *argv_p; - - argv_p = prefix_new(); - (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); - apply_mask(argv_p); - if (!bgp_debug_update_prefixes) bgp_debug_update_prefixes = list_new(); - if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, argv_p)) { + if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, prefix)) { vty_out(vty, "BGP updates debugging is already enabled for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + prefix_str); return CMD_SUCCESS; } - bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, argv_p); + bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, prefix); if (vty->node == CONFIG_NODE) { DEBUG_ON(update, UPDATE_PREFIX); } else { TERM_DEBUG_ON(update, UPDATE_PREFIX); vty_out(vty, "BGP updates debugging is on for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + prefix_str); } return CMD_SUCCESS; } -DEFUN (no_debug_bgp_update_prefix, +DEFPY (no_debug_bgp_update_prefix, no_debug_bgp_update_prefix_cmd, - "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>", + "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>$prefix", NO_STR DEBUG_STR BGP_STR @@ -1599,18 +1560,12 @@ DEFUN (no_debug_bgp_update_prefix, "IPv4 prefix\n" "IPv6 prefix\n") { - int idx_ipv4_ipv6_prefixlen = 5; - struct prefix *argv_p; - int found_prefix = 0; - - argv_p = prefix_new(); - (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); - apply_mask(argv_p); + bool found_prefix = false; if (bgp_debug_update_prefixes && !list_isempty(bgp_debug_update_prefixes)) { found_prefix = bgp_debug_list_remove_entry( - bgp_debug_update_prefixes, NULL, argv_p); + bgp_debug_update_prefixes, NULL, prefix); if (list_isempty(bgp_debug_update_prefixes)) { if (vty->node == CONFIG_NODE) { @@ -1625,10 +1580,10 @@ DEFUN (no_debug_bgp_update_prefix, if (found_prefix) vty_out(vty, "BGP updates debugging is off for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + prefix_str); else vty_out(vty, "BGP updates debugging was not enabled for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + prefix_str); return CMD_SUCCESS; } @@ -1698,9 +1653,9 @@ DEFUN (debug_bgp_graceful_restart, } -DEFUN (debug_bgp_zebra_prefix, +DEFPY (debug_bgp_zebra_prefix, debug_bgp_zebra_prefix_cmd, - "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>", + "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>$prefix", DEBUG_STR BGP_STR "BGP Zebra messages\n" @@ -1708,30 +1663,22 @@ DEFUN (debug_bgp_zebra_prefix, "IPv4 prefix\n" "IPv6 prefix\n") { - int idx_ipv4_ipv6_prefixlen = 4; - struct prefix *argv_p; - - argv_p = prefix_new(); - (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); - apply_mask(argv_p); - if (!bgp_debug_zebra_prefixes) bgp_debug_zebra_prefixes = list_new(); - if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes, NULL, argv_p)) { + if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes, NULL, prefix)) { vty_out(vty, "BGP zebra debugging is already enabled for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + prefix_str); return CMD_SUCCESS; } - bgp_debug_list_add_entry(bgp_debug_zebra_prefixes, NULL, argv_p); + bgp_debug_list_add_entry(bgp_debug_zebra_prefixes, NULL, prefix); if (vty->node == CONFIG_NODE) DEBUG_ON(zebra, ZEBRA); else { TERM_DEBUG_ON(zebra, ZEBRA); - vty_out(vty, "BGP zebra debugging is on for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + vty_out(vty, "BGP zebra debugging is on for %s\n", prefix_str); } return CMD_SUCCESS; @@ -1773,9 +1720,9 @@ DEFUN (no_debug_bgp_graceful_restart, return CMD_SUCCESS; } -DEFUN (no_debug_bgp_zebra_prefix, +DEFPY (no_debug_bgp_zebra_prefix, no_debug_bgp_zebra_prefix_cmd, - "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>", + "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>$prefix", NO_STR DEBUG_STR BGP_STR @@ -1784,18 +1731,12 @@ DEFUN (no_debug_bgp_zebra_prefix, "IPv4 prefix\n" "IPv6 prefix\n") { - int idx_ipv4_ipv6_prefixlen = 5; - struct prefix *argv_p; - int found_prefix = 0; - - argv_p = prefix_new(); - (void)str2prefix(argv[idx_ipv4_ipv6_prefixlen]->arg, argv_p); - apply_mask(argv_p); + bool found_prefix = false; if (bgp_debug_zebra_prefixes && !list_isempty(bgp_debug_zebra_prefixes)) { found_prefix = bgp_debug_list_remove_entry( - bgp_debug_zebra_prefixes, NULL, argv_p); + bgp_debug_zebra_prefixes, NULL, prefix); if (list_isempty(bgp_debug_zebra_prefixes)) { if (vty->node == CONFIG_NODE) @@ -1808,11 +1749,10 @@ DEFUN (no_debug_bgp_zebra_prefix, } if (found_prefix) - vty_out(vty, "BGP zebra debugging is off for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + vty_out(vty, "BGP zebra debugging is off for %s\n", prefix_str); else vty_out(vty, "BGP zebra debugging was not enabled for %s\n", - argv[idx_ipv4_ipv6_prefixlen]->arg); + prefix_str); return CMD_SUCCESS; } |
