back to topotato report
topotato coverage report
Current view: top level - bgpd - bgp_debug.c (source / functions) Hit Total Coverage
Test: test_bgp_set_aspath_replace.py::BGPSetAspathReplace Lines: 134 1130 11.9 %
Date: 2023-02-24 18:37:49 Functions: 10 73 13.7 %

          Line data    Source code
       1             : /* BGP-4, BGP-4+ packet debug routine
       2             :  * Copyright (C) 1996, 97, 99 Kunihiro Ishiguro
       3             :  *
       4             :  * This file is part of GNU Zebra.
       5             :  *
       6             :  * GNU Zebra is free software; you can redistribute it and/or modify it
       7             :  * under the terms of the GNU General Public License as published by the
       8             :  * Free Software Foundation; either version 2, or (at your option) any
       9             :  * later version.
      10             :  *
      11             :  * GNU Zebra is distributed in the hope that it will be useful, but
      12             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public License along
      17             :  * with this program; see the file COPYING; if not, write to the Free Software
      18             :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      19             :  */
      20             : 
      21             : #include <zebra.h>
      22             : 
      23             : #include <lib/version.h>
      24             : #include "lib/bfd.h"
      25             : #include "lib/printfrr.h"
      26             : #include "prefix.h"
      27             : #include "linklist.h"
      28             : #include "stream.h"
      29             : #include "command.h"
      30             : #include "log.h"
      31             : #include "sockunion.h"
      32             : #include "memory.h"
      33             : #include "queue.h"
      34             : #include "filter.h"
      35             : 
      36             : #include "bgpd/bgpd.h"
      37             : #include "bgpd/bgp_aspath.h"
      38             : #include "bgpd/bgp_route.h"
      39             : #include "bgpd/bgp_attr.h"
      40             : #include "bgpd/bgp_debug.h"
      41             : #include "bgpd/bgp_community.h"
      42             : #include "bgpd/bgp_lcommunity.h"
      43             : #include "bgpd/bgp_updgrp.h"
      44             : #include "bgpd/bgp_mplsvpn.h"
      45             : #include "bgpd/bgp_ecommunity.h"
      46             : #include "bgpd/bgp_label.h"
      47             : #include "bgpd/bgp_evpn.h"
      48             : #include "bgpd/bgp_evpn_private.h"
      49             : #include "bgpd/bgp_evpn_vty.h"
      50             : #include "bgpd/bgp_vty.h"
      51             : #include "bgpd/bgp_flowspec.h"
      52             : #include "bgpd/bgp_packet.h"
      53             : 
      54             : #include "bgpd/bgp_debug_clippy.c"
      55             : 
      56             : unsigned long conf_bgp_debug_as4;
      57             : unsigned long conf_bgp_debug_neighbor_events;
      58             : unsigned long conf_bgp_debug_events;
      59             : unsigned long conf_bgp_debug_packet;
      60             : unsigned long conf_bgp_debug_filter;
      61             : unsigned long conf_bgp_debug_keepalive;
      62             : unsigned long conf_bgp_debug_update;
      63             : unsigned long conf_bgp_debug_bestpath;
      64             : unsigned long conf_bgp_debug_zebra;
      65             : unsigned long conf_bgp_debug_allow_martians;
      66             : unsigned long conf_bgp_debug_nht;
      67             : unsigned long conf_bgp_debug_update_groups;
      68             : unsigned long conf_bgp_debug_vpn;
      69             : unsigned long conf_bgp_debug_flowspec;
      70             : unsigned long conf_bgp_debug_labelpool;
      71             : unsigned long conf_bgp_debug_pbr;
      72             : unsigned long conf_bgp_debug_graceful_restart;
      73             : unsigned long conf_bgp_debug_evpn_mh;
      74             : unsigned long conf_bgp_debug_bfd;
      75             : unsigned long conf_bgp_debug_cond_adv;
      76             : 
      77             : unsigned long term_bgp_debug_as4;
      78             : unsigned long term_bgp_debug_neighbor_events;
      79             : unsigned long term_bgp_debug_events;
      80             : unsigned long term_bgp_debug_packet;
      81             : unsigned long term_bgp_debug_filter;
      82             : unsigned long term_bgp_debug_keepalive;
      83             : unsigned long term_bgp_debug_update;
      84             : unsigned long term_bgp_debug_bestpath;
      85             : unsigned long term_bgp_debug_zebra;
      86             : unsigned long term_bgp_debug_allow_martians;
      87             : unsigned long term_bgp_debug_nht;
      88             : unsigned long term_bgp_debug_update_groups;
      89             : unsigned long term_bgp_debug_vpn;
      90             : unsigned long term_bgp_debug_flowspec;
      91             : unsigned long term_bgp_debug_labelpool;
      92             : unsigned long term_bgp_debug_pbr;
      93             : unsigned long term_bgp_debug_graceful_restart;
      94             : unsigned long term_bgp_debug_evpn_mh;
      95             : unsigned long term_bgp_debug_bfd;
      96             : unsigned long term_bgp_debug_cond_adv;
      97             : 
      98             : struct list *bgp_debug_neighbor_events_peers = NULL;
      99             : struct list *bgp_debug_keepalive_peers = NULL;
     100             : struct list *bgp_debug_update_out_peers = NULL;
     101             : struct list *bgp_debug_update_in_peers = NULL;
     102             : struct list *bgp_debug_update_prefixes = NULL;
     103             : struct list *bgp_debug_bestpath_prefixes = NULL;
     104             : struct list *bgp_debug_zebra_prefixes = NULL;
     105             : 
     106             : /* messages for BGP-4 status */
     107             : const struct message bgp_status_msg[] = {{Idle, "Idle"},
     108             :                                          {Connect, "Connect"},
     109             :                                          {Active, "Active"},
     110             :                                          {OpenSent, "OpenSent"},
     111             :                                          {OpenConfirm, "OpenConfirm"},
     112             :                                          {Established, "Established"},
     113             :                                          {Clearing, "Clearing"},
     114             :                                          {Deleted, "Deleted"},
     115             :                                          {0}};
     116             : 
     117             : /* BGP message type string. */
     118             : const char *const bgp_type_str[] = {NULL,          "OPEN",      "UPDATE",
     119             :                               "NOTIFICATION", "KEEPALIVE", "ROUTE-REFRESH",
     120             :                               "CAPABILITY"};
     121             : 
     122             : /* message for BGP-4 Notify */
     123             : static const struct message bgp_notify_msg[] = {
     124             :         {BGP_NOTIFY_HEADER_ERR, "Message Header Error"},
     125             :         {BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"},
     126             :         {BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"},
     127             :         {BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"},
     128             :         {BGP_NOTIFY_FSM_ERR, "Neighbor Events Error"},
     129             :         {BGP_NOTIFY_CEASE, "Cease"},
     130             :         {BGP_NOTIFY_ROUTE_REFRESH_ERR, "ROUTE-REFRESH Message Error"},
     131             :         {0}};
     132             : 
     133             : static const struct message bgp_notify_head_msg[] = {
     134             :         {BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
     135             :         {BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
     136             :         {BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"},
     137             :         {0}};
     138             : 
     139             : static const struct message bgp_notify_open_msg[] = {
     140             :         {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
     141             :         {BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number"},
     142             :         {BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS"},
     143             :         {BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier"},
     144             :         {BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter"},
     145             :         {BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"},
     146             :         {BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
     147             :         {BGP_NOTIFY_OPEN_ROLE_MISMATCH, "/Role Mismatch"},
     148             :         {0}};
     149             : 
     150             : static const struct message bgp_notify_update_msg[] = {
     151             :         {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
     152             :         {BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List"},
     153             :         {BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute"},
     154             :         {BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute"},
     155             :         {BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error"},
     156             :         {BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error"},
     157             :         {BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute"},
     158             :         {BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute"},
     159             :         {BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
     160             :         {BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
     161             :         {BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
     162             :         {0}};
     163             : 
     164             : static const struct message bgp_notify_cease_msg[] = {
     165             :         {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
     166             :         {BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached"},
     167             :         {BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administrative Shutdown"},
     168             :         {BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer De-configured"},
     169             :         {BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administrative Reset"},
     170             :         {BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected"},
     171             :         {BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
     172             :         {BGP_NOTIFY_CEASE_COLLISION_RESOLUTION,
     173             :          "/Connection Collision Resolution"},
     174             :         {BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resources"},
     175             :         {BGP_NOTIFY_CEASE_HARD_RESET, "/Hard Reset"},
     176             :         {BGP_NOTIFY_CEASE_BFD_DOWN, "/BFD Down"},
     177             :         {0}};
     178             : 
     179             : static const struct message bgp_notify_route_refresh_msg[] = {
     180             :         {BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
     181             :         {BGP_NOTIFY_ROUTE_REFRESH_INVALID_MSG_LEN, "/Invalid Message Length"},
     182             :         {0}};
     183             : 
     184             : static const struct message bgp_notify_fsm_msg[] = {
     185             :         {BGP_NOTIFY_FSM_ERR_SUBCODE_UNSPECIFIC, "/Unspecific"},
     186             :         {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENSENT,
     187             :          "/Receive Unexpected Message in OpenSent State"},
     188             :         {BGP_NOTIFY_FSM_ERR_SUBCODE_OPENCONFIRM,
     189             :          "/Receive Unexpected Message in OpenConfirm State"},
     190             :         {BGP_NOTIFY_FSM_ERR_SUBCODE_ESTABLISHED,
     191             :          "/Receive Unexpected Message in Established State"},
     192             :         {0}};
     193             : 
     194             : /* Origin strings. */
     195             : const char *const bgp_origin_str[] = {"i", "e", "?"};
     196             : const char *const bgp_origin_long_str[] = {"IGP", "EGP", "incomplete"};
     197             : 
     198             : static void bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc,
     199             :                                         struct prefix *p);
     200             : /* Given a string return a pointer the corresponding peer structure */
     201           0 : static struct peer *bgp_find_peer(struct vty *vty, const char *peer_str)
     202             : {
     203           0 :         struct bgp *bgp = VTY_GET_CONTEXT(bgp);
     204           0 :         int ret;
     205           0 :         union sockunion su;
     206           0 :         struct peer *peer;
     207             : 
     208           0 :         if (!bgp) {
     209             :                 return NULL;
     210             :         }
     211           0 :         ret = str2sockunion(peer_str, &su);
     212             : 
     213             :         /* 'swpX' string */
     214           0 :         if (ret < 0) {
     215           0 :                 peer = peer_lookup_by_conf_if(bgp, peer_str);
     216             : 
     217           0 :                 if (!peer)
     218           0 :                         peer = peer_lookup_by_hostname(bgp, peer_str);
     219             : 
     220           0 :                 return peer;
     221             :         } else
     222           0 :                 return peer_lookup(bgp, &su);
     223             : }
     224             : 
     225           0 : static void bgp_debug_list_free(struct list *list)
     226             : {
     227           0 :         struct bgp_debug_filter *filter;
     228           0 :         struct listnode *node, *nnode;
     229             : 
     230           0 :         if (list)
     231           0 :                 for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
     232           0 :                         listnode_delete(list, filter);
     233           0 :                         prefix_free(&filter->p);
     234           0 :                         XFREE(MTYPE_BGP_DEBUG_STR, filter->host);
     235           0 :                         XFREE(MTYPE_BGP_DEBUG_FILTER, filter);
     236             :                 }
     237           0 : }
     238             : 
     239             : /*
     240             :  * Print the desc along with a list of peers/prefixes this debug is
     241             :  * enabled for
     242             :  */
     243           0 : static void bgp_debug_list_print(struct vty *vty, const char *desc,
     244             :                                  struct list *list)
     245             : {
     246           0 :         struct bgp_debug_filter *filter;
     247           0 :         struct listnode *node, *nnode;
     248             : 
     249           0 :         vty_out(vty, "%s", desc);
     250             : 
     251           0 :         if (list && !list_isempty(list)) {
     252           0 :                 vty_out(vty, " for");
     253           0 :                 for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
     254           0 :                         if (filter->host)
     255           0 :                                 vty_out(vty, " %s", filter->host);
     256             : 
     257           0 :                         if (filter->p && filter->p->family == AF_EVPN)
     258           0 :                                 bgp_debug_print_evpn_prefix(vty, "", filter->p);
     259           0 :                         else if (filter->p)
     260           0 :                                 vty_out(vty, " %pFX", filter->p);
     261             :                 }
     262             :         }
     263             : 
     264           0 :         vty_out(vty, "\n");
     265           0 : }
     266             : 
     267             : /*
     268             :  * Print the command to enable the debug for each peer/prefix this debug is
     269             :  * enabled for
     270             :  */
     271           0 : static int bgp_debug_list_conf_print(struct vty *vty, const char *desc,
     272             :                                      struct list *list)
     273             : {
     274           0 :         struct bgp_debug_filter *filter;
     275           0 :         struct listnode *node, *nnode;
     276           0 :         int write = 0;
     277             : 
     278           0 :         if (list && !list_isempty(list)) {
     279           0 :                 for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
     280           0 :                         if (filter->host) {
     281           0 :                                 vty_out(vty, "%s %s\n", desc, filter->host);
     282           0 :                                 write++;
     283             :                         }
     284             : 
     285           0 :                         if (filter->p && filter->p->family == AF_EVPN) {
     286           0 :                                 bgp_debug_print_evpn_prefix(vty, desc,
     287             :                                                             filter->p);
     288           0 :                                 write++;
     289           0 :                         } else if (filter->p) {
     290           0 :                                 vty_out(vty, "%s %pFX\n", desc, filter->p);
     291           0 :                                 write++;
     292             :                         }
     293             :                 }
     294             :         }
     295             : 
     296           0 :         if (!write) {
     297           0 :                 vty_out(vty, "%s\n", desc);
     298           0 :                 write++;
     299             :         }
     300             : 
     301           0 :         return write;
     302             : }
     303             : 
     304           0 : static void bgp_debug_list_add_entry(struct list *list, const char *host,
     305             :                                      const struct prefix *p)
     306             : {
     307           0 :         struct bgp_debug_filter *filter;
     308             : 
     309           0 :         filter = XCALLOC(MTYPE_BGP_DEBUG_FILTER,
     310             :                          sizeof(struct bgp_debug_filter));
     311             : 
     312           0 :         if (host) {
     313           0 :                 filter->host = XSTRDUP(MTYPE_BGP_DEBUG_STR, host);
     314           0 :                 filter->p = NULL;
     315           0 :         } else if (p) {
     316           0 :                 filter->host = NULL;
     317           0 :                 filter->p = prefix_new();
     318           0 :                 prefix_copy(filter->p, p);
     319             :         }
     320             : 
     321           0 :         listnode_add(list, filter);
     322           0 : }
     323             : 
     324           0 : static bool bgp_debug_list_remove_entry(struct list *list, const char *host,
     325             :                                         const struct prefix *p)
     326             : {
     327           0 :         struct bgp_debug_filter *filter;
     328           0 :         struct listnode *node, *nnode;
     329             : 
     330           0 :         for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
     331           0 :                 if (host && strcmp(filter->host, host) == 0) {
     332           0 :                         listnode_delete(list, filter);
     333           0 :                         XFREE(MTYPE_BGP_DEBUG_STR, filter->host);
     334           0 :                         XFREE(MTYPE_BGP_DEBUG_FILTER, filter);
     335           0 :                         return true;
     336           0 :                 } else if (p && filter->p->prefixlen == p->prefixlen
     337           0 :                            && prefix_match(filter->p, p)) {
     338           0 :                         listnode_delete(list, filter);
     339           0 :                         prefix_free(&filter->p);
     340           0 :                         XFREE(MTYPE_BGP_DEBUG_FILTER, filter);
     341           0 :                         return true;
     342             :                 }
     343             :         }
     344             : 
     345             :         return false;
     346             : }
     347             : 
     348          12 : static bool bgp_debug_list_has_entry(struct list *list, const char *host,
     349             :                                      const struct prefix *p)
     350             : {
     351          12 :         struct bgp_debug_filter *filter;
     352          12 :         struct listnode *node, *nnode;
     353             : 
     354          24 :         for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) {
     355           0 :                 if (host) {
     356           0 :                         if (strcmp(filter->host, host) == 0) {
     357             :                                 return true;
     358             :                         }
     359           0 :                 } else if (p) {
     360           0 :                         if (filter->p->prefixlen == p->prefixlen
     361           0 :                             && prefix_match(filter->p, p)) {
     362             :                                 return true;
     363             :                         }
     364             :                 }
     365             :         }
     366             : 
     367             :         return false;
     368             : }
     369             : 
     370          12 : bool bgp_debug_peer_updout_enabled(char *host)
     371             : {
     372          12 :         return (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host,
     373             :                                          NULL));
     374             : }
     375             : 
     376             : /* Dump attribute. */
     377           0 : bool bgp_dump_attr(struct attr *attr, char *buf, size_t size)
     378             : {
     379           0 :         if (!attr)
     380             :                 return false;
     381             : 
     382           0 :         buf[0] = '\0';
     383             : 
     384           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)))
     385           0 :                 snprintfrr(buf, size, "nexthop %pI4", &attr->nexthop);
     386             : 
     387           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN)))
     388           0 :                 snprintf(buf + strlen(buf), size - strlen(buf), ", origin %s",
     389           0 :                          bgp_origin_str[attr->origin]);
     390             : 
     391             :         /* Add MP case. */
     392           0 :         if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL
     393           0 :             || attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
     394           0 :                 snprintfrr(buf + strlen(buf), size - strlen(buf),
     395             :                            ", mp_nexthop %pI6", &attr->mp_nexthop_global);
     396             : 
     397           0 :         if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
     398           0 :                 snprintfrr(buf + strlen(buf), size - strlen(buf), "(%pI6)",
     399             :                            &attr->mp_nexthop_local);
     400             : 
     401           0 :         if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4)
     402           0 :                 snprintfrr(buf, size, "nexthop %pI4", &attr->nexthop);
     403             : 
     404           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)))
     405           0 :                 snprintf(buf + strlen(buf), size - strlen(buf),
     406             :                          ", localpref %u", attr->local_pref);
     407             : 
     408           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AIGP)))
     409           0 :                 snprintf(buf + strlen(buf), size - strlen(buf),
     410             :                          ", aigp-metric %" PRIu64,
     411           0 :                          (unsigned long long)bgp_attr_get_aigp_metric(attr));
     412             : 
     413           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)))
     414           0 :                 snprintf(buf + strlen(buf), size - strlen(buf), ", metric %u",
     415             :                          attr->med);
     416             : 
     417           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)))
     418           0 :                 snprintf(buf + strlen(buf), size - strlen(buf),
     419             :                          ", community %s",
     420             :                          community_str(bgp_attr_get_community(attr), false,
     421             :                                        true));
     422             : 
     423           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)))
     424           0 :                 snprintf(buf + strlen(buf), size - strlen(buf),
     425             :                          ", large-community %s",
     426             :                          lcommunity_str(bgp_attr_get_lcommunity(attr), false,
     427             :                                         true));
     428             : 
     429           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
     430           0 :                 snprintf(buf + strlen(buf), size - strlen(buf),
     431             :                          ", extcommunity %s",
     432             :                          ecommunity_str(bgp_attr_get_ecommunity(attr)));
     433             : 
     434           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)))
     435           0 :                 snprintf(buf + strlen(buf), size - strlen(buf),
     436             :                          ", atomic-aggregate");
     437             : 
     438           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)))
     439           0 :                 snprintfrr(buf + strlen(buf), size - strlen(buf),
     440             :                            ", aggregated by %u %pI4", attr->aggregator_as,
     441             :                            &attr->aggregator_addr);
     442             : 
     443           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)))
     444           0 :                 snprintfrr(buf + strlen(buf), size - strlen(buf),
     445             :                            ", originator %pI4", &attr->originator_id);
     446             : 
     447           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))) {
     448           0 :                 struct cluster_list *cluster;
     449           0 :                 int i;
     450             : 
     451           0 :                 snprintf(buf + strlen(buf), size - strlen(buf),
     452             :                          ", clusterlist");
     453             : 
     454           0 :                 cluster = bgp_attr_get_cluster(attr);
     455           0 :                 for (i = 0; i < cluster->length / 4; i++)
     456           0 :                         snprintfrr(buf + strlen(buf), size - strlen(buf),
     457           0 :                                    " %pI4", &cluster->list[i]);
     458             :         }
     459             : 
     460           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL)))
     461           0 :                 snprintf(buf + strlen(buf), size - strlen(buf),
     462           0 :                          ", pmsi tnltype %u", bgp_attr_get_pmsi_tnl_type(attr));
     463             : 
     464           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)))
     465           0 :                 snprintf(buf + strlen(buf), size - strlen(buf), ", path %s",
     466             :                          aspath_print(attr->aspath));
     467             : 
     468           0 :         if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID))) {
     469           0 :                 if (attr->label_index != BGP_INVALID_LABEL_INDEX)
     470           0 :                         snprintf(buf + strlen(buf), size - strlen(buf),
     471             :                                  ", label-index %u", attr->label_index);
     472             :         }
     473             : 
     474           0 :         if (strlen(buf) > 1)
     475             :                 return true;
     476             :         else
     477             :                 return false;
     478             : }
     479             : 
     480           0 : const char *bgp_notify_code_str(char code)
     481             : {
     482           0 :         return lookup_msg(bgp_notify_msg, code, "Unrecognized Error Code");
     483             : }
     484             : 
     485           0 : const char *bgp_notify_subcode_str(char code, char subcode)
     486             : {
     487             : 
     488           0 :         switch (code) {
     489           0 :         case BGP_NOTIFY_HEADER_ERR:
     490           0 :                 return lookup_msg(bgp_notify_head_msg, subcode,
     491             :                                   "Unrecognized Error Subcode");
     492           0 :         case BGP_NOTIFY_OPEN_ERR:
     493           0 :                 return lookup_msg(bgp_notify_open_msg, subcode,
     494             :                                   "Unrecognized Error Subcode");
     495           0 :         case BGP_NOTIFY_UPDATE_ERR:
     496           0 :                 return lookup_msg(bgp_notify_update_msg, subcode,
     497             :                                   "Unrecognized Error Subcode");
     498             :         case BGP_NOTIFY_HOLD_ERR:
     499             :                 break;
     500           0 :         case BGP_NOTIFY_FSM_ERR:
     501           0 :                 return lookup_msg(bgp_notify_fsm_msg, subcode,
     502             :                                   "Unrecognized Error Subcode");
     503           0 :         case BGP_NOTIFY_CEASE:
     504           0 :                 return lookup_msg(bgp_notify_cease_msg, subcode,
     505             :                                   "Unrecognized Error Subcode");
     506           0 :         case BGP_NOTIFY_ROUTE_REFRESH_ERR:
     507           0 :                 return lookup_msg(bgp_notify_route_refresh_msg, subcode,
     508             :                                   "Unrecognized Error Subcode");
     509             :         }
     510             :         return "";
     511             : }
     512             : 
     513             : /* extract notify admin reason if correctly present */
     514           0 : const char *bgp_notify_admin_message(char *buf, size_t bufsz, uint8_t *data,
     515             :                                      size_t datalen)
     516             : {
     517           0 :         if (!data || datalen < 1)
     518             :                 return NULL;
     519             : 
     520           0 :         uint8_t len = data[0];
     521           0 :         if (!len || len > datalen - 1)
     522             :                 return NULL;
     523             : 
     524           0 :         return zlog_sanitize(buf, bufsz, data + 1, len);
     525             : }
     526             : 
     527             : /* dump notify packet */
     528           4 : void bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify,
     529             :                       const char *direct, bool hard_reset)
     530             : {
     531           4 :         const char *subcode_str;
     532           4 :         const char *code_str;
     533           4 :         const char *msg_str = NULL;
     534           4 :         char msg_buf[1024];
     535             : 
     536           4 :         if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS)
     537           4 :             || CHECK_FLAG(peer->bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) {
     538           0 :                 code_str = bgp_notify_code_str(bgp_notify->code);
     539           0 :                 subcode_str = bgp_notify_subcode_str(bgp_notify->code,
     540           0 :                                                      bgp_notify->subcode);
     541             : 
     542           0 :                 if (bgp_notify->code == BGP_NOTIFY_CEASE
     543           0 :                     && (bgp_notify->subcode == BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN
     544           0 :                         || bgp_notify->subcode
     545             :                                    == BGP_NOTIFY_CEASE_ADMIN_RESET)) {
     546           0 :                         msg_str = bgp_notify_admin_message(
     547             :                                 msg_buf, sizeof(msg_buf), bgp_notify->raw_data,
     548           0 :                                 bgp_notify->length);
     549             :                 }
     550             : 
     551           0 :                 if (msg_str) {
     552           0 :                         zlog_info(
     553             :                                 "%%NOTIFICATION%s: %s neighbor %s %d/%d (%s%s) \"%s\"",
     554             :                                 hard_reset ? "(Hard Reset)" : "",
     555             :                                 strcmp(direct, "received") == 0
     556             :                                         ? "received from"
     557             :                                         : "sent to",
     558             :                                 peer->host, bgp_notify->code,
     559             :                                 bgp_notify->subcode, code_str, subcode_str,
     560             :                                 msg_str);
     561             :                 } else {
     562           0 :                         msg_str = bgp_notify->data ? bgp_notify->data : "";
     563           0 :                         zlog_info(
     564             :                                 "%%NOTIFICATION%s: %s neighbor %s %d/%d (%s%s) %d bytes %s",
     565             :                                 hard_reset ? "(Hard Reset)" : "",
     566             :                                 strcmp(direct, "received") == 0
     567             :                                         ? "received from"
     568             :                                         : "sent to",
     569             :                                 peer->host, bgp_notify->code,
     570             :                                 bgp_notify->subcode, code_str, subcode_str,
     571             :                                 bgp_notify->length, msg_str);
     572             :                 }
     573             :         }
     574           4 : }
     575             : 
     576           0 : static void bgp_debug_clear_updgrp_update_dbg(struct bgp *bgp)
     577             : {
     578           0 :         if (!bgp)
     579           0 :                 bgp = bgp_get_default();
     580           0 :         update_group_walk(bgp, update_group_clear_update_dbg, NULL);
     581           0 : }
     582             : 
     583           0 : static void bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc,
     584             :                                         struct prefix *p)
     585             : {
     586           0 :         char evpn_desc[PREFIX2STR_BUFFER + INET_ADDRSTRLEN];
     587           0 :         char buf[PREFIX2STR_BUFFER];
     588           0 :         char buf2[ETHER_ADDR_STRLEN];
     589             : 
     590           0 :         if (p->u.prefix_evpn.route_type == BGP_EVPN_MAC_IP_ROUTE) {
     591           0 :                 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn *)p)) {
     592           0 :                         snprintf(
     593             :                                 evpn_desc, sizeof(evpn_desc),
     594             :                                 "l2vpn evpn type macip mac %s",
     595           0 :                                 prefix_mac2str(&p->u.prefix_evpn.macip_addr.mac,
     596             :                                                buf2, sizeof(buf2)));
     597             :                 } else {
     598           0 :                         uint8_t family = is_evpn_prefix_ipaddr_v4(
     599             :                                                 (struct prefix_evpn *)p) ?
     600             :                                                         AF_INET : AF_INET6;
     601           0 :                         snprintf(
     602             :                                 evpn_desc, sizeof(evpn_desc),
     603             :                                 "l2vpn evpn type macip mac %s ip %s",
     604           0 :                                 prefix_mac2str(&p->u.prefix_evpn.macip_addr.mac,
     605             :                                                buf2, sizeof(buf2)),
     606             :                                 inet_ntop(
     607             :                                         family,
     608           0 :                                         &p->u.prefix_evpn.macip_addr.ip.ip.addr,
     609             :                                         buf, PREFIX2STR_BUFFER));
     610             :                 }
     611           0 :         } else if (p->u.prefix_evpn.route_type == BGP_EVPN_IMET_ROUTE) {
     612           0 :                 snprintfrr(evpn_desc, sizeof(evpn_desc),
     613             :                            "l2vpn evpn type multicast ip %pI4",
     614             :                            &p->u.prefix_evpn.imet_addr.ip.ipaddr_v4);
     615           0 :         } else if (p->u.prefix_evpn.route_type == BGP_EVPN_IP_PREFIX_ROUTE) {
     616           0 :                 uint8_t family = is_evpn_prefix_ipaddr_v4(
     617             :                                         (struct prefix_evpn *)p) ? AF_INET
     618             :                                                                 : AF_INET6;
     619           0 :                 snprintf(evpn_desc, sizeof(evpn_desc),
     620             :                          "l2vpn evpn type prefix ip %s/%d",
     621             :                          inet_ntop(family,
     622           0 :                                    &p->u.prefix_evpn.prefix_addr.ip.ip.addr,
     623             :                                    buf, PREFIX2STR_BUFFER),
     624           0 :                          p->u.prefix_evpn.prefix_addr.ip_prefix_length);
     625             :         }
     626             : 
     627           0 :         vty_out(vty, "%s %s\n", desc, evpn_desc);
     628           0 : }
     629             : 
     630           0 : static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv,
     631             :                                        int argc, struct prefix *argv_p)
     632             : {
     633           0 :         struct ethaddr mac = {};
     634           0 :         struct ipaddr ip = {};
     635           0 :         int evpn_type = 0;
     636           0 :         int mac_idx = 0;
     637           0 :         int ip_idx = 0;
     638             : 
     639           0 :         if (bgp_evpn_cli_parse_type(&evpn_type, argv, argc) < 0)
     640             :                 return CMD_WARNING;
     641             : 
     642           0 :         if (evpn_type == BGP_EVPN_MAC_IP_ROUTE) {
     643           0 :                 memset(&ip, 0, sizeof(ip));
     644             : 
     645           0 :                 if (argv_find(argv, argc, "mac", &mac_idx))
     646           0 :                         if (!prefix_str2mac(argv[mac_idx + 1]->arg, &mac)) {
     647           0 :                                 vty_out(vty, "%% Malformed MAC address\n");
     648           0 :                                 return CMD_WARNING;
     649             :                         }
     650             : 
     651           0 :                 if (argv_find(argv, argc, "ip", &ip_idx))
     652           0 :                         if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) {
     653           0 :                                 vty_out(vty, "%% Malformed IP address\n");
     654           0 :                                 return CMD_WARNING;
     655             :                         }
     656             : 
     657           0 :                 build_evpn_type2_prefix((struct prefix_evpn *)argv_p,
     658             :                                         &mac, &ip);
     659           0 :         } else if (evpn_type == BGP_EVPN_IMET_ROUTE) {
     660           0 :                 memset(&ip, 0, sizeof(ip));
     661             : 
     662           0 :                 if (argv_find(argv, argc, "ip", &ip_idx))
     663           0 :                         if (str2ipaddr(argv[ip_idx + 1]->arg, &ip) != 0) {
     664           0 :                                 vty_out(vty, "%% Malformed IP address\n");
     665           0 :                                 return CMD_WARNING;
     666             :                         }
     667             : 
     668           0 :                 build_evpn_type3_prefix((struct prefix_evpn *)argv_p,
     669             :                                         ip.ipaddr_v4);
     670           0 :         } else if (evpn_type == BGP_EVPN_IP_PREFIX_ROUTE) {
     671           0 :                 struct prefix ip_prefix;
     672             : 
     673           0 :                 memset(&ip_prefix, 0, sizeof(ip_prefix));
     674           0 :                 if (argv_find(argv, argc, "ip", &ip_idx)) {
     675           0 :                         (void)str2prefix(argv[ip_idx + 1]->arg, &ip_prefix);
     676           0 :                         apply_mask(&ip_prefix);
     677             :                 }
     678           0 :                 build_type5_prefix_from_ip_prefix(
     679             :                                         (struct prefix_evpn *)argv_p,
     680             :                                         &ip_prefix);
     681             :         }
     682             : 
     683             :         return CMD_SUCCESS;
     684             : }
     685             : 
     686             : /* Debug option setting interface. */
     687             : unsigned long bgp_debug_option = 0;
     688             : 
     689           0 : int debug(unsigned int option)
     690             : {
     691           0 :         return bgp_debug_option & option;
     692             : }
     693             : 
     694           0 : DEFUN (debug_bgp_as4,
     695             :        debug_bgp_as4_cmd,
     696             :        "debug bgp as4",
     697             :        DEBUG_STR
     698             :        BGP_STR
     699             :        "BGP AS4 actions\n")
     700             : {
     701           0 :         if (vty->node == CONFIG_NODE)
     702           0 :                 DEBUG_ON(as4, AS4);
     703             :         else {
     704           0 :                 TERM_DEBUG_ON(as4, AS4);
     705           0 :                 vty_out(vty, "BGP as4 debugging is on\n");
     706             :         }
     707           0 :         return CMD_SUCCESS;
     708             : }
     709             : 
     710           0 : DEFUN (no_debug_bgp_as4,
     711             :        no_debug_bgp_as4_cmd,
     712             :        "no debug bgp as4",
     713             :        NO_STR
     714             :        DEBUG_STR
     715             :        BGP_STR
     716             :        "BGP AS4 actions\n")
     717             : {
     718           0 :         if (vty->node == CONFIG_NODE)
     719           0 :                 DEBUG_OFF(as4, AS4);
     720             :         else {
     721           0 :                 TERM_DEBUG_OFF(as4, AS4);
     722           0 :                 vty_out(vty, "BGP as4 debugging is off\n");
     723             :         }
     724           0 :         return CMD_SUCCESS;
     725             : }
     726             : 
     727           0 : DEFUN (debug_bgp_as4_segment,
     728             :        debug_bgp_as4_segment_cmd,
     729             :        "debug bgp as4 segment",
     730             :        DEBUG_STR
     731             :        BGP_STR
     732             :        "BGP AS4 actions\n"
     733             :        "BGP AS4 aspath segment handling\n")
     734             : {
     735           0 :         if (vty->node == CONFIG_NODE)
     736           0 :                 DEBUG_ON(as4, AS4_SEGMENT);
     737             :         else {
     738           0 :                 TERM_DEBUG_ON(as4, AS4_SEGMENT);
     739           0 :                 vty_out(vty, "BGP as4 segment debugging is on\n");
     740             :         }
     741           0 :         return CMD_SUCCESS;
     742             : }
     743             : 
     744           0 : DEFUN (no_debug_bgp_as4_segment,
     745             :        no_debug_bgp_as4_segment_cmd,
     746             :        "no debug bgp as4 segment",
     747             :        NO_STR
     748             :        DEBUG_STR
     749             :        BGP_STR
     750             :        "BGP AS4 actions\n"
     751             :        "BGP AS4 aspath segment handling\n")
     752             : {
     753           0 :         if (vty->node == CONFIG_NODE)
     754           0 :                 DEBUG_OFF(as4, AS4_SEGMENT);
     755             :         else {
     756           0 :                 TERM_DEBUG_OFF(as4, AS4_SEGMENT);
     757           0 :                 vty_out(vty, "BGP as4 segment debugging is off\n");
     758             :         }
     759           0 :         return CMD_SUCCESS;
     760             : }
     761             : 
     762             : /* debug bgp neighbor_events */
     763           0 : DEFUN (debug_bgp_neighbor_events,
     764             :        debug_bgp_neighbor_events_cmd,
     765             :        "debug bgp neighbor-events",
     766             :        DEBUG_STR
     767             :        BGP_STR
     768             :        "BGP Neighbor Events\n")
     769             : {
     770           0 :         bgp_debug_list_free(bgp_debug_neighbor_events_peers);
     771             : 
     772           0 :         if (vty->node == CONFIG_NODE)
     773           0 :                 DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
     774             :         else {
     775           0 :                 TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
     776           0 :                 vty_out(vty, "BGP neighbor-events debugging is on\n");
     777             :         }
     778           0 :         return CMD_SUCCESS;
     779             : }
     780             : 
     781           0 : DEFUN (debug_bgp_neighbor_events_peer,
     782             :        debug_bgp_neighbor_events_peer_cmd,
     783             :        "debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
     784             :        DEBUG_STR
     785             :        BGP_STR
     786             :        "BGP Neighbor Events\n"
     787             :        "BGP neighbor IP address to debug\n"
     788             :        "BGP IPv6 neighbor to debug\n"
     789             :        "BGP neighbor on interface to debug\n")
     790             : {
     791           0 :         int idx_peer = 3;
     792           0 :         const char *host = argv[idx_peer]->arg;
     793             : 
     794           0 :         if (!bgp_debug_neighbor_events_peers)
     795           0 :                 bgp_debug_neighbor_events_peers = list_new();
     796             : 
     797           0 :         if (bgp_debug_list_has_entry(bgp_debug_neighbor_events_peers, host,
     798             :                                      NULL)) {
     799           0 :                 vty_out(vty,
     800             :                         "BGP neighbor-events debugging is already enabled for %s\n",
     801             :                         host);
     802           0 :                 return CMD_SUCCESS;
     803             :         }
     804             : 
     805           0 :         bgp_debug_list_add_entry(bgp_debug_neighbor_events_peers, host, NULL);
     806             : 
     807           0 :         if (vty->node == CONFIG_NODE)
     808           0 :                 DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
     809             :         else {
     810           0 :                 TERM_DEBUG_ON(neighbor_events, NEIGHBOR_EVENTS);
     811           0 :                 vty_out(vty, "BGP neighbor-events debugging is on for %s\n",
     812             :                         host);
     813             :         }
     814             :         return CMD_SUCCESS;
     815             : }
     816             : 
     817           0 : DEFUN (no_debug_bgp_neighbor_events,
     818             :        no_debug_bgp_neighbor_events_cmd,
     819             :        "no debug bgp neighbor-events",
     820             :        NO_STR
     821             :        DEBUG_STR
     822             :        BGP_STR
     823             :        "Neighbor Events\n")
     824             : {
     825           0 :         bgp_debug_list_free(bgp_debug_neighbor_events_peers);
     826             : 
     827           0 :         if (vty->node == CONFIG_NODE)
     828           0 :                 DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
     829             :         else {
     830           0 :                 TERM_DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
     831           0 :                 vty_out(vty, "BGP neighbor-events debugging is off\n");
     832             :         }
     833           0 :         return CMD_SUCCESS;
     834             : }
     835             : 
     836           0 : DEFUN (no_debug_bgp_neighbor_events_peer,
     837             :        no_debug_bgp_neighbor_events_peer_cmd,
     838             :        "no debug bgp neighbor-events <A.B.C.D|X:X::X:X|WORD>",
     839             :        NO_STR
     840             :        DEBUG_STR
     841             :        BGP_STR
     842             :        "Neighbor Events\n"
     843             :        "BGP neighbor IP address to debug\n"
     844             :        "BGP IPv6 neighbor to debug\n"
     845             :        "BGP neighbor on interface to debug\n")
     846             : {
     847           0 :         int idx_peer = 4;
     848           0 :         int found_peer = 0;
     849           0 :         const char *host = argv[idx_peer]->arg;
     850             : 
     851           0 :         if (bgp_debug_neighbor_events_peers
     852           0 :             && !list_isempty(bgp_debug_neighbor_events_peers)) {
     853           0 :                 found_peer = bgp_debug_list_remove_entry(
     854             :                         bgp_debug_neighbor_events_peers, host, NULL);
     855             : 
     856           0 :                 if (list_isempty(bgp_debug_neighbor_events_peers)) {
     857           0 :                         if (vty->node == CONFIG_NODE)
     858           0 :                                 DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
     859             :                         else
     860           0 :                                 TERM_DEBUG_OFF(neighbor_events,
     861             :                                                NEIGHBOR_EVENTS);
     862             :                 }
     863             :         }
     864             : 
     865           0 :         if (found_peer)
     866           0 :                 vty_out(vty, "BGP neighbor-events debugging is off for %s\n",
     867             :                         host);
     868             :         else
     869           0 :                 vty_out(vty,
     870             :                         "BGP neighbor-events debugging was not enabled for %s\n",
     871             :                         host);
     872             : 
     873           0 :         return CMD_SUCCESS;
     874             : }
     875             : 
     876             : /* debug bgp nht */
     877           0 : DEFUN (debug_bgp_nht,
     878             :        debug_bgp_nht_cmd,
     879             :        "debug bgp nht",
     880             :        DEBUG_STR
     881             :        BGP_STR
     882             :        "BGP nexthop tracking events\n")
     883             : {
     884           0 :         if (vty->node == CONFIG_NODE)
     885           0 :                 DEBUG_ON(nht, NHT);
     886             :         else {
     887           0 :                 TERM_DEBUG_ON(nht, NHT);
     888           0 :                 vty_out(vty, "BGP nexthop tracking debugging is on\n");
     889             :         }
     890           0 :         return CMD_SUCCESS;
     891             : }
     892             : 
     893           0 : DEFUN (no_debug_bgp_nht,
     894             :        no_debug_bgp_nht_cmd,
     895             :        "no debug bgp nht",
     896             :        NO_STR
     897             :        DEBUG_STR
     898             :        BGP_STR
     899             :        "BGP nexthop tracking events\n")
     900             : {
     901           0 :         if (vty->node == CONFIG_NODE)
     902           0 :                 DEBUG_OFF(nht, NHT);
     903             :         else {
     904           0 :                 TERM_DEBUG_OFF(nht, NHT);
     905           0 :                 vty_out(vty, "BGP nexthop tracking debugging is off\n");
     906             :         }
     907           0 :         return CMD_SUCCESS;
     908             : }
     909             : 
     910             : /* debug bgp keepalives */
     911           0 : DEFUN (debug_bgp_keepalive,
     912             :        debug_bgp_keepalive_cmd,
     913             :        "debug bgp keepalives",
     914             :        DEBUG_STR
     915             :        BGP_STR
     916             :        "BGP keepalives\n")
     917             : {
     918           0 :         bgp_debug_list_free(bgp_debug_keepalive_peers);
     919             : 
     920           0 :         if (vty->node == CONFIG_NODE)
     921           0 :                 DEBUG_ON(keepalive, KEEPALIVE);
     922             :         else {
     923           0 :                 TERM_DEBUG_ON(keepalive, KEEPALIVE);
     924           0 :                 vty_out(vty, "BGP keepalives debugging is on\n");
     925             :         }
     926           0 :         return CMD_SUCCESS;
     927             : }
     928             : 
     929           0 : DEFUN (debug_bgp_keepalive_peer,
     930             :        debug_bgp_keepalive_peer_cmd,
     931             :        "debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
     932             :        DEBUG_STR
     933             :        BGP_STR
     934             :        "BGP keepalives\n"
     935             :        "BGP IPv4 neighbor to debug\n"
     936             :        "BGP IPv6 neighbor to debug\n"
     937             :        "BGP neighbor on interface to debug\n")
     938             : {
     939           0 :         int idx_peer = 3;
     940           0 :         const char *host = argv[idx_peer]->arg;
     941             : 
     942           0 :         if (!bgp_debug_keepalive_peers)
     943           0 :                 bgp_debug_keepalive_peers = list_new();
     944             : 
     945           0 :         if (bgp_debug_list_has_entry(bgp_debug_keepalive_peers, host, NULL)) {
     946           0 :                 vty_out(vty,
     947             :                         "BGP keepalive debugging is already enabled for %s\n",
     948             :                         host);
     949           0 :                 return CMD_SUCCESS;
     950             :         }
     951             : 
     952           0 :         bgp_debug_list_add_entry(bgp_debug_keepalive_peers, host, NULL);
     953             : 
     954           0 :         if (vty->node == CONFIG_NODE)
     955           0 :                 DEBUG_ON(keepalive, KEEPALIVE);
     956             :         else {
     957           0 :                 TERM_DEBUG_ON(keepalive, KEEPALIVE);
     958           0 :                 vty_out(vty, "BGP keepalives debugging is on for %s\n", host);
     959             :         }
     960             :         return CMD_SUCCESS;
     961             : }
     962             : 
     963           0 : DEFUN (no_debug_bgp_keepalive,
     964             :        no_debug_bgp_keepalive_cmd,
     965             :        "no debug bgp keepalives",
     966             :        NO_STR
     967             :        DEBUG_STR
     968             :        BGP_STR
     969             :        "BGP keepalives\n")
     970             : {
     971           0 :         bgp_debug_list_free(bgp_debug_keepalive_peers);
     972             : 
     973           0 :         if (vty->node == CONFIG_NODE)
     974           0 :                 DEBUG_OFF(keepalive, KEEPALIVE);
     975             :         else {
     976           0 :                 TERM_DEBUG_OFF(keepalive, KEEPALIVE);
     977           0 :                 vty_out(vty, "BGP keepalives debugging is off\n");
     978             :         }
     979           0 :         return CMD_SUCCESS;
     980             : }
     981             : 
     982           0 : DEFUN (no_debug_bgp_keepalive_peer,
     983             :        no_debug_bgp_keepalive_peer_cmd,
     984             :        "no debug bgp keepalives <A.B.C.D|X:X::X:X|WORD>",
     985             :        NO_STR
     986             :        DEBUG_STR
     987             :        BGP_STR
     988             :        "BGP keepalives\n"
     989             :        "BGP neighbor IP address to debug\n"
     990             :        "BGP IPv6 neighbor to debug\n"
     991             :        "BGP neighbor on interface to debug\n")
     992             : {
     993           0 :         int idx_peer = 4;
     994           0 :         int found_peer = 0;
     995           0 :         const char *host = argv[idx_peer]->arg;
     996             : 
     997           0 :         if (bgp_debug_keepalive_peers
     998           0 :             && !list_isempty(bgp_debug_keepalive_peers)) {
     999           0 :                 found_peer = bgp_debug_list_remove_entry(
    1000             :                         bgp_debug_keepalive_peers, host, NULL);
    1001             : 
    1002           0 :                 if (list_isempty(bgp_debug_keepalive_peers)) {
    1003           0 :                         if (vty->node == CONFIG_NODE)
    1004           0 :                                 DEBUG_OFF(keepalive, KEEPALIVE);
    1005             :                         else
    1006           0 :                                 TERM_DEBUG_OFF(keepalive, KEEPALIVE);
    1007             :                 }
    1008             :         }
    1009             : 
    1010           0 :         if (found_peer)
    1011           0 :                 vty_out(vty, "BGP keepalives debugging is off for %s\n", host);
    1012             :         else
    1013           0 :                 vty_out(vty,
    1014             :                         "BGP keepalives debugging was not enabled for %s\n",
    1015             :                         host);
    1016             : 
    1017           0 :         return CMD_SUCCESS;
    1018             : }
    1019             : 
    1020             : /* debug bgp bestpath */
    1021           0 : DEFPY (debug_bgp_bestpath_prefix,
    1022             :        debug_bgp_bestpath_prefix_cmd,
    1023             :        "debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>$prefix",
    1024             :        DEBUG_STR
    1025             :        BGP_STR
    1026             :        "BGP bestpath\n"
    1027             :        "IPv4 prefix\n"
    1028             :        "IPv6 prefix\n")
    1029             : {
    1030           0 :         if (!bgp_debug_bestpath_prefixes)
    1031           0 :                 bgp_debug_bestpath_prefixes = list_new();
    1032             : 
    1033           0 :         if (bgp_debug_list_has_entry(bgp_debug_bestpath_prefixes, NULL,
    1034             :                                      prefix)) {
    1035           0 :                 vty_out(vty,
    1036             :                         "BGP bestpath debugging is already enabled for %s\n",
    1037             :                         prefix_str);
    1038           0 :                 return CMD_SUCCESS;
    1039             :         }
    1040             : 
    1041           0 :         bgp_debug_list_add_entry(bgp_debug_bestpath_prefixes, NULL, prefix);
    1042             : 
    1043           0 :         if (vty->node == CONFIG_NODE) {
    1044           0 :                 DEBUG_ON(bestpath, BESTPATH);
    1045             :         } else {
    1046           0 :                 TERM_DEBUG_ON(bestpath, BESTPATH);
    1047           0 :                 vty_out(vty, "BGP bestpath debugging is on for %s\n",
    1048             :                         prefix_str);
    1049             :         }
    1050             : 
    1051             :         return CMD_SUCCESS;
    1052             : }
    1053             : 
    1054           0 : DEFPY (no_debug_bgp_bestpath_prefix,
    1055             :        no_debug_bgp_bestpath_prefix_cmd,
    1056             :        "no debug bgp bestpath <A.B.C.D/M|X:X::X:X/M>$prefix",
    1057             :        NO_STR
    1058             :        DEBUG_STR
    1059             :        BGP_STR
    1060             :        "BGP bestpath\n"
    1061             :        "IPv4 prefix\n"
    1062             :        "IPv6 prefix\n")
    1063             : {
    1064           0 :         bool found_prefix = false;
    1065             : 
    1066           0 :         if (bgp_debug_bestpath_prefixes
    1067           0 :             && !list_isempty(bgp_debug_bestpath_prefixes)) {
    1068           0 :                 found_prefix = bgp_debug_list_remove_entry(
    1069             :                         bgp_debug_bestpath_prefixes, NULL, prefix);
    1070             : 
    1071           0 :                 if (list_isempty(bgp_debug_bestpath_prefixes)) {
    1072           0 :                         if (vty->node == CONFIG_NODE) {
    1073           0 :                                 DEBUG_OFF(bestpath, BESTPATH);
    1074             :                         } else {
    1075           0 :                                 TERM_DEBUG_OFF(bestpath, BESTPATH);
    1076           0 :                                 vty_out(vty,
    1077             :                                         "BGP bestpath debugging (per prefix) is off\n");
    1078             :                         }
    1079             :                 }
    1080             :         }
    1081             : 
    1082           0 :         if (found_prefix)
    1083           0 :                 vty_out(vty, "BGP bestpath debugging is off for %s\n",
    1084             :                         prefix_str);
    1085             :         else
    1086           0 :                 vty_out(vty, "BGP bestpath debugging was not enabled for %s\n",
    1087             :                         prefix_str);
    1088             : 
    1089           0 :         return CMD_SUCCESS;
    1090             : }
    1091             : 
    1092           0 : DEFUN (no_debug_bgp_bestpath,
    1093             :        no_debug_bgp_bestpath_cmd,
    1094             :        "no debug bgp bestpath",
    1095             :        NO_STR
    1096             :        DEBUG_STR
    1097             :        BGP_STR
    1098             :        "BGP bestpath\n")
    1099             : {
    1100           0 :         bgp_debug_list_free(bgp_debug_bestpath_prefixes);
    1101             : 
    1102           0 :         if (vty->node == CONFIG_NODE)
    1103           0 :                 DEBUG_OFF(bestpath, BESTPATH);
    1104             :         else {
    1105           0 :                 TERM_DEBUG_OFF(bestpath, BESTPATH);
    1106           0 :                 vty_out(vty, "BGP bestpath debugging is off\n");
    1107             :         }
    1108           0 :         return CMD_SUCCESS;
    1109             : }
    1110             : 
    1111             : /* debug bgp updates */
    1112           0 : DEFUN (debug_bgp_update,
    1113             :        debug_bgp_update_cmd,
    1114             :        "debug bgp updates",
    1115             :        DEBUG_STR
    1116             :        BGP_STR
    1117             :        "BGP updates\n")
    1118             : {
    1119           0 :         bgp_debug_list_free(bgp_debug_update_in_peers);
    1120           0 :         bgp_debug_list_free(bgp_debug_update_out_peers);
    1121           0 :         bgp_debug_list_free(bgp_debug_update_prefixes);
    1122             : 
    1123           0 :         if (vty->node == CONFIG_NODE) {
    1124           0 :                 DEBUG_ON(update, UPDATE_IN);
    1125           0 :                 DEBUG_ON(update, UPDATE_OUT);
    1126             :         } else {
    1127           0 :                 TERM_DEBUG_ON(update, UPDATE_IN);
    1128           0 :                 TERM_DEBUG_ON(update, UPDATE_OUT);
    1129           0 :                 vty_out(vty, "BGP updates debugging is on\n");
    1130             :         }
    1131           0 :         return CMD_SUCCESS;
    1132             : }
    1133             : 
    1134           0 : DEFUN (debug_bgp_update_direct,
    1135             :        debug_bgp_update_direct_cmd,
    1136             :        "debug bgp updates <in|out>",
    1137             :        DEBUG_STR
    1138             :        BGP_STR
    1139             :        "BGP updates\n"
    1140             :        "Inbound updates\n"
    1141             :        "Outbound updates\n")
    1142             : {
    1143           0 :         int idx_in_out = 3;
    1144             : 
    1145           0 :         if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
    1146           0 :                 bgp_debug_list_free(bgp_debug_update_in_peers);
    1147             :         else
    1148           0 :                 bgp_debug_list_free(bgp_debug_update_out_peers);
    1149             : 
    1150           0 :         if (vty->node == CONFIG_NODE) {
    1151           0 :                 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
    1152           0 :                         DEBUG_ON(update, UPDATE_IN);
    1153             :                 else
    1154           0 :                         DEBUG_ON(update, UPDATE_OUT);
    1155             :         } else {
    1156           0 :                 if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) {
    1157           0 :                         TERM_DEBUG_ON(update, UPDATE_IN);
    1158           0 :                         vty_out(vty, "BGP updates debugging is on (inbound)\n");
    1159             :                 } else {
    1160           0 :                         TERM_DEBUG_ON(update, UPDATE_OUT);
    1161           0 :                         vty_out(vty,
    1162             :                                 "BGP updates debugging is on (outbound)\n");
    1163             :                 }
    1164             :         }
    1165           0 :         return CMD_SUCCESS;
    1166             : }
    1167             : 
    1168           0 : DEFUN (debug_bgp_update_direct_peer,
    1169             :        debug_bgp_update_direct_peer_cmd,
    1170             :        "debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
    1171             :        DEBUG_STR
    1172             :        BGP_STR
    1173             :        "BGP updates\n"
    1174             :        "Inbound updates\n"
    1175             :        "Outbound updates\n"
    1176             :        "BGP neighbor IP address to debug\n"
    1177             :        "BGP IPv6 neighbor to debug\n"
    1178             :        "BGP neighbor on interface to debug\n")
    1179             : {
    1180           0 :         int idx_in_out = 3;
    1181           0 :         int idx_peer = 4;
    1182           0 :         const char *host = argv[idx_peer]->arg;
    1183           0 :         int inbound;
    1184             : 
    1185           0 :         if (!bgp_debug_update_in_peers)
    1186           0 :                 bgp_debug_update_in_peers = list_new();
    1187             : 
    1188           0 :         if (!bgp_debug_update_out_peers)
    1189           0 :                 bgp_debug_update_out_peers = list_new();
    1190             : 
    1191           0 :         if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
    1192             :                 inbound = 1;
    1193             :         else
    1194           0 :                 inbound = 0;
    1195             : 
    1196           0 :         if (inbound) {
    1197           0 :                 if (bgp_debug_list_has_entry(bgp_debug_update_in_peers, host,
    1198             :                                              NULL)) {
    1199           0 :                         vty_out(vty,
    1200             :                                 "BGP inbound update debugging is already enabled for %s\n",
    1201             :                                 host);
    1202           0 :                         return CMD_SUCCESS;
    1203             :                 }
    1204             :         }
    1205             : 
    1206             :         else {
    1207           0 :                 if (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host,
    1208             :                                              NULL)) {
    1209           0 :                         vty_out(vty,
    1210             :                                 "BGP outbound update debugging is already enabled for %s\n",
    1211             :                                 host);
    1212           0 :                         return CMD_SUCCESS;
    1213             :                 }
    1214             :         }
    1215             : 
    1216           0 :         if (inbound)
    1217           0 :                 bgp_debug_list_add_entry(bgp_debug_update_in_peers, host, NULL);
    1218             :         else {
    1219           0 :                 struct peer *peer;
    1220           0 :                 struct peer_af *paf;
    1221           0 :                 int afidx;
    1222             : 
    1223           0 :                 bgp_debug_list_add_entry(bgp_debug_update_out_peers, host,
    1224             :                                          NULL);
    1225           0 :                 peer = bgp_find_peer(vty, host);
    1226             : 
    1227           0 :                 if (peer) {
    1228           0 :                         for (afidx = BGP_AF_START; afidx < BGP_AF_MAX;
    1229           0 :                              afidx++) {
    1230           0 :                                 paf = peer->peer_af_array[afidx];
    1231           0 :                                 if (paf != NULL) {
    1232           0 :                                         if (PAF_SUBGRP(paf)) {
    1233           0 :                                                 UPDGRP_PEER_DBG_EN(
    1234             :                                                         PAF_SUBGRP(paf)
    1235             :                                                                 ->update_group);
    1236             :                                         }
    1237             :                                 }
    1238             :                         }
    1239             :                 }
    1240             :         }
    1241             : 
    1242           0 :         if (vty->node == CONFIG_NODE) {
    1243           0 :                 if (inbound)
    1244           0 :                         DEBUG_ON(update, UPDATE_IN);
    1245             :                 else
    1246           0 :                         DEBUG_ON(update, UPDATE_OUT);
    1247             :         } else {
    1248           0 :                 if (inbound) {
    1249           0 :                         TERM_DEBUG_ON(update, UPDATE_IN);
    1250           0 :                         vty_out(vty,
    1251             :                                 "BGP updates debugging is on (inbound) for %s\n",
    1252           0 :                                 argv[idx_peer]->arg);
    1253             :                 } else {
    1254           0 :                         TERM_DEBUG_ON(update, UPDATE_OUT);
    1255           0 :                         vty_out(vty,
    1256             :                                 "BGP updates debugging is on (outbound) for %s\n",
    1257           0 :                                 argv[idx_peer]->arg);
    1258             :                 }
    1259             :         }
    1260             :         return CMD_SUCCESS;
    1261             : }
    1262             : 
    1263           0 : DEFUN (no_debug_bgp_update_direct,
    1264             :        no_debug_bgp_update_direct_cmd,
    1265             :        "no debug bgp updates <in|out>",
    1266             :        NO_STR
    1267             :        DEBUG_STR
    1268             :        BGP_STR
    1269             :        "BGP updates\n"
    1270             :        "Inbound updates\n"
    1271             :        "Outbound updates\n")
    1272             : {
    1273           0 :         int idx_in_out = 4;
    1274           0 :         if (strncmp("i", argv[idx_in_out]->arg, 1) == 0) {
    1275           0 :                 bgp_debug_list_free(bgp_debug_update_in_peers);
    1276             : 
    1277           0 :                 if (vty->node == CONFIG_NODE) {
    1278           0 :                         DEBUG_OFF(update, UPDATE_IN);
    1279             :                 } else {
    1280           0 :                         TERM_DEBUG_OFF(update, UPDATE_IN);
    1281           0 :                         vty_out(vty,
    1282             :                                 "BGP updates debugging is off (inbound)\n");
    1283             :                 }
    1284             :         } else {
    1285           0 :                 bgp_debug_list_free(bgp_debug_update_out_peers);
    1286             : 
    1287           0 :                 if (vty->node == CONFIG_NODE) {
    1288           0 :                         DEBUG_OFF(update, UPDATE_OUT);
    1289             :                 } else {
    1290           0 :                         TERM_DEBUG_OFF(update, UPDATE_OUT);
    1291           0 :                         vty_out(vty,
    1292             :                                 "BGP updates debugging is off (outbound)\n");
    1293             :                 }
    1294             :         }
    1295             : 
    1296           0 :         return CMD_SUCCESS;
    1297             : }
    1298             : 
    1299           0 : DEFUN (no_debug_bgp_update_direct_peer,
    1300             :        no_debug_bgp_update_direct_peer_cmd,
    1301             :        "no debug bgp updates <in|out> <A.B.C.D|X:X::X:X|WORD>",
    1302             :        NO_STR
    1303             :        DEBUG_STR
    1304             :        BGP_STR
    1305             :        "BGP updates\n"
    1306             :        "Inbound updates\n"
    1307             :        "Outbound updates\n"
    1308             :        "BGP neighbor IP address to debug\n"
    1309             :        "BGP IPv6 neighbor to debug\n"
    1310             :        "BGP neighbor on interface to debug\n")
    1311             : {
    1312           0 :         int idx_in_out = 4;
    1313           0 :         int idx_peer = 5;
    1314           0 :         int inbound;
    1315           0 :         int found_peer = 0;
    1316           0 :         const char *host = argv[idx_peer]->arg;
    1317             : 
    1318           0 :         if (strncmp("i", argv[idx_in_out]->arg, 1) == 0)
    1319             :                 inbound = 1;
    1320             :         else
    1321           0 :                 inbound = 0;
    1322             : 
    1323           0 :         if (inbound && bgp_debug_update_in_peers
    1324           0 :             && !list_isempty(bgp_debug_update_in_peers)) {
    1325           0 :                 found_peer = bgp_debug_list_remove_entry(
    1326             :                         bgp_debug_update_in_peers, host, NULL);
    1327             : 
    1328           0 :                 if (list_isempty(bgp_debug_update_in_peers)) {
    1329           0 :                         if (vty->node == CONFIG_NODE)
    1330           0 :                                 DEBUG_OFF(update, UPDATE_IN);
    1331             :                         else {
    1332           0 :                                 TERM_DEBUG_OFF(update, UPDATE_IN);
    1333           0 :                                 vty_out(vty,
    1334             :                                         "BGP updates debugging (inbound) is off\n");
    1335             :                         }
    1336             :                 }
    1337             :         }
    1338             : 
    1339           0 :         if (!inbound && bgp_debug_update_out_peers
    1340           0 :             && !list_isempty(bgp_debug_update_out_peers)) {
    1341           0 :                 found_peer = bgp_debug_list_remove_entry(
    1342             :                         bgp_debug_update_out_peers, host, NULL);
    1343             : 
    1344           0 :                 if (list_isempty(bgp_debug_update_out_peers)) {
    1345           0 :                         if (vty->node == CONFIG_NODE)
    1346           0 :                                 DEBUG_OFF(update, UPDATE_OUT);
    1347             :                         else {
    1348           0 :                                 TERM_DEBUG_OFF(update, UPDATE_OUT);
    1349           0 :                                 vty_out(vty,
    1350             :                                         "BGP updates debugging (outbound) is off\n");
    1351             :                         }
    1352             :                 }
    1353             : 
    1354           0 :                 struct peer *peer;
    1355           0 :                 struct peer_af *paf;
    1356           0 :                 int afidx;
    1357           0 :                 peer = bgp_find_peer(vty, host);
    1358             : 
    1359           0 :                 if (peer) {
    1360           0 :                         for (afidx = BGP_AF_START; afidx < BGP_AF_MAX;
    1361           0 :                              afidx++) {
    1362           0 :                                 paf = peer->peer_af_array[afidx];
    1363           0 :                                 if (paf != NULL) {
    1364           0 :                                         if (PAF_SUBGRP(paf)) {
    1365           0 :                                                 UPDGRP_PEER_DBG_DIS(
    1366             :                                                         PAF_SUBGRP(paf)
    1367             :                                                                 ->update_group);
    1368             :                                         }
    1369             :                                 }
    1370             :                         }
    1371             :                 }
    1372             :         }
    1373             : 
    1374           0 :         if (found_peer)
    1375           0 :                 if (inbound)
    1376           0 :                         vty_out(vty,
    1377             :                                 "BGP updates debugging (inbound) is off for %s\n",
    1378             :                                 host);
    1379             :                 else
    1380           0 :                         vty_out(vty,
    1381             :                                 "BGP updates debugging (outbound) is off for %s\n",
    1382             :                                 host);
    1383           0 :         else if (inbound)
    1384           0 :                 vty_out(vty,
    1385             :                         "BGP updates debugging (inbound) was not enabled for %s\n",
    1386             :                         host);
    1387             :         else
    1388           0 :                 vty_out(vty,
    1389             :                         "BGP updates debugging (outbound) was not enabled for %s\n",
    1390             :                         host);
    1391             : 
    1392           0 :         return CMD_SUCCESS;
    1393             : }
    1394             : 
    1395           0 : DEFPY (debug_bgp_update_prefix_afi_safi,
    1396             :        debug_bgp_update_prefix_afi_safi_cmd,
    1397             :        "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>>",
    1398             :        DEBUG_STR
    1399             :        BGP_STR
    1400             :        "BGP updates\n"
    1401             :        "Specify a prefix to debug\n"
    1402             :        L2VPN_HELP_STR
    1403             :        EVPN_HELP_STR
    1404             :        EVPN_TYPE_HELP_STR
    1405             :        EVPN_TYPE_2_HELP_STR
    1406             :        EVPN_TYPE_2_HELP_STR
    1407             :        MAC_STR MAC_STR MAC_STR
    1408             :        IP_STR
    1409             :        "IPv4 address\n"
    1410             :        "IPv6 address\n"
    1411             :        EVPN_TYPE_3_HELP_STR
    1412             :        EVPN_TYPE_3_HELP_STR
    1413             :        IP_STR
    1414             :        "IPv4 address\n"
    1415             :        "IPv6 address\n"
    1416             :        EVPN_TYPE_5_HELP_STR
    1417             :        EVPN_TYPE_5_HELP_STR
    1418             :        IP_STR
    1419             :        "IPv4 prefix\n"
    1420             :        "IPv6 prefix\n")
    1421             : {
    1422           0 :         struct prefix argv_p;
    1423           0 :         int ret = CMD_SUCCESS;
    1424             : 
    1425           0 :         ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p);
    1426           0 :         if (ret != CMD_SUCCESS)
    1427             :                 return ret;
    1428             : 
    1429           0 :         if (!bgp_debug_update_prefixes)
    1430           0 :                 bgp_debug_update_prefixes = list_new();
    1431             : 
    1432           0 :         if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL,
    1433             :                                      &argv_p)) {
    1434           0 :                 vty_out(vty,
    1435             :                         "BGP updates debugging is already enabled for %pFX\n",
    1436             :                         &argv_p);
    1437           0 :                 return CMD_SUCCESS;
    1438             :         }
    1439             : 
    1440           0 :         bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, &argv_p);
    1441             : 
    1442           0 :         if (vty->node == CONFIG_NODE) {
    1443           0 :                 DEBUG_ON(update, UPDATE_PREFIX);
    1444             :         } else {
    1445           0 :                 TERM_DEBUG_ON(update, UPDATE_PREFIX);
    1446           0 :                 vty_out(vty, "BGP updates debugging is on for %pFX\n", &argv_p);
    1447             :         }
    1448             : 
    1449             :         return CMD_SUCCESS;
    1450             : }
    1451             : 
    1452           0 : DEFPY (no_debug_bgp_update_prefix_afi_safi,
    1453             :        no_debug_bgp_update_prefix_afi_safi_cmd,
    1454             :        "no 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>>",
    1455             :        NO_STR
    1456             :        DEBUG_STR
    1457             :        BGP_STR
    1458             :        "BGP updates\n"
    1459             :        "Specify a prefix to debug\n"
    1460             :        L2VPN_HELP_STR
    1461             :        EVPN_HELP_STR
    1462             :        EVPN_TYPE_HELP_STR
    1463             :        EVPN_TYPE_2_HELP_STR
    1464             :        EVPN_TYPE_2_HELP_STR
    1465             :        MAC_STR MAC_STR MAC_STR
    1466             :        IP_STR
    1467             :        "IPv4 address\n"
    1468             :        "IPv6 address\n"
    1469             :        EVPN_TYPE_3_HELP_STR
    1470             :        EVPN_TYPE_3_HELP_STR
    1471             :        IP_STR
    1472             :        "IPv4 address\n"
    1473             :        "IPv6 address\n"
    1474             :        EVPN_TYPE_5_HELP_STR
    1475             :        EVPN_TYPE_5_HELP_STR
    1476             :        IP_STR
    1477             :        "IPv4 prefix\n"
    1478             :        "IPv6 prefix\n")
    1479             : {
    1480           0 :         struct prefix argv_p;
    1481           0 :         bool found_prefix = false;
    1482           0 :         int ret = CMD_SUCCESS;
    1483             : 
    1484           0 :         ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p);
    1485           0 :         if (ret != CMD_SUCCESS)
    1486             :                 return ret;
    1487             : 
    1488           0 :         if (bgp_debug_update_prefixes
    1489           0 :             && !list_isempty(bgp_debug_update_prefixes)) {
    1490           0 :                 found_prefix = bgp_debug_list_remove_entry(
    1491             :                         bgp_debug_update_prefixes, NULL, &argv_p);
    1492             : 
    1493           0 :                 if (list_isempty(bgp_debug_update_prefixes)) {
    1494           0 :                         if (vty->node == CONFIG_NODE) {
    1495           0 :                                 DEBUG_OFF(update, UPDATE_PREFIX);
    1496             :                         } else {
    1497           0 :                                 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
    1498           0 :                                 vty_out(vty,
    1499             :                                         "BGP updates debugging (per prefix) is off\n");
    1500             :                         }
    1501             :                 }
    1502             :         }
    1503             : 
    1504           0 :         if (found_prefix)
    1505           0 :                 vty_out(vty, "BGP updates debugging is off for %pFX\n",
    1506             :                         &argv_p);
    1507             :         else
    1508           0 :                 vty_out(vty, "BGP updates debugging was not enabled for %pFX\n",
    1509             :                         &argv_p);
    1510             : 
    1511             :         return ret;
    1512             : }
    1513             : 
    1514             : 
    1515           0 : DEFPY (debug_bgp_update_prefix,
    1516             :        debug_bgp_update_prefix_cmd,
    1517             :        "debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>$prefix",
    1518             :        DEBUG_STR
    1519             :        BGP_STR
    1520             :        "BGP updates\n"
    1521             :        "Specify a prefix to debug\n"
    1522             :        "IPv4 prefix\n"
    1523             :        "IPv6 prefix\n")
    1524             : {
    1525           0 :         if (!bgp_debug_update_prefixes)
    1526           0 :                 bgp_debug_update_prefixes = list_new();
    1527             : 
    1528           0 :         if (bgp_debug_list_has_entry(bgp_debug_update_prefixes, NULL, prefix)) {
    1529           0 :                 vty_out(vty,
    1530             :                         "BGP updates debugging is already enabled for %s\n",
    1531             :                         prefix_str);
    1532           0 :                 return CMD_SUCCESS;
    1533             :         }
    1534             : 
    1535           0 :         bgp_debug_list_add_entry(bgp_debug_update_prefixes, NULL, prefix);
    1536             : 
    1537           0 :         if (vty->node == CONFIG_NODE) {
    1538           0 :                 DEBUG_ON(update, UPDATE_PREFIX);
    1539             :         } else {
    1540           0 :                 TERM_DEBUG_ON(update, UPDATE_PREFIX);
    1541           0 :                 vty_out(vty, "BGP updates debugging is on for %s\n",
    1542             :                         prefix_str);
    1543             :         }
    1544             : 
    1545             :         return CMD_SUCCESS;
    1546             : }
    1547             : 
    1548           0 : DEFPY (no_debug_bgp_update_prefix,
    1549             :        no_debug_bgp_update_prefix_cmd,
    1550             :        "no debug bgp updates prefix <A.B.C.D/M|X:X::X:X/M>$prefix",
    1551             :        NO_STR
    1552             :        DEBUG_STR
    1553             :        BGP_STR
    1554             :        "BGP updates\n"
    1555             :        "Specify a prefix to debug\n"
    1556             :        "IPv4 prefix\n"
    1557             :        "IPv6 prefix\n")
    1558             : {
    1559           0 :         bool found_prefix = false;
    1560             : 
    1561           0 :         if (bgp_debug_update_prefixes
    1562           0 :             && !list_isempty(bgp_debug_update_prefixes)) {
    1563           0 :                 found_prefix = bgp_debug_list_remove_entry(
    1564             :                         bgp_debug_update_prefixes, NULL, prefix);
    1565             : 
    1566           0 :                 if (list_isempty(bgp_debug_update_prefixes)) {
    1567           0 :                         if (vty->node == CONFIG_NODE) {
    1568           0 :                                 DEBUG_OFF(update, UPDATE_PREFIX);
    1569             :                         } else {
    1570           0 :                                 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
    1571           0 :                                 vty_out(vty,
    1572             :                                         "BGP updates debugging (per prefix) is off\n");
    1573             :                         }
    1574             :                 }
    1575             :         }
    1576             : 
    1577           0 :         if (found_prefix)
    1578           0 :                 vty_out(vty, "BGP updates debugging is off for %s\n",
    1579             :                         prefix_str);
    1580             :         else
    1581           0 :                 vty_out(vty, "BGP updates debugging was not enabled for %s\n",
    1582             :                         prefix_str);
    1583             : 
    1584           0 :         return CMD_SUCCESS;
    1585             : }
    1586             : 
    1587           0 : DEFUN (no_debug_bgp_update,
    1588             :        no_debug_bgp_update_cmd,
    1589             :        "no debug bgp updates",
    1590             :        NO_STR
    1591             :        DEBUG_STR
    1592             :        BGP_STR
    1593             :        "BGP updates\n")
    1594             : {
    1595           0 :         struct listnode *ln;
    1596           0 :         struct bgp *bgp;
    1597             : 
    1598           0 :         bgp_debug_list_free(bgp_debug_update_in_peers);
    1599           0 :         bgp_debug_list_free(bgp_debug_update_out_peers);
    1600           0 :         bgp_debug_list_free(bgp_debug_update_prefixes);
    1601             : 
    1602           0 :         for (ALL_LIST_ELEMENTS_RO(bm->bgp, ln, bgp))
    1603           0 :                 bgp_debug_clear_updgrp_update_dbg(bgp);
    1604             : 
    1605           0 :         if (vty->node == CONFIG_NODE) {
    1606           0 :                 DEBUG_OFF(update, UPDATE_IN);
    1607           0 :                 DEBUG_OFF(update, UPDATE_OUT);
    1608           0 :                 DEBUG_OFF(update, UPDATE_PREFIX);
    1609             :         } else {
    1610           0 :                 TERM_DEBUG_OFF(update, UPDATE_IN);
    1611           0 :                 TERM_DEBUG_OFF(update, UPDATE_OUT);
    1612           0 :                 TERM_DEBUG_OFF(update, UPDATE_PREFIX);
    1613           0 :                 vty_out(vty, "BGP updates debugging is off\n");
    1614             :         }
    1615           0 :         return CMD_SUCCESS;
    1616             : }
    1617             : 
    1618             : /* debug bgp zebra */
    1619           0 : DEFUN (debug_bgp_zebra,
    1620             :        debug_bgp_zebra_cmd,
    1621             :        "debug bgp zebra",
    1622             :        DEBUG_STR
    1623             :        BGP_STR
    1624             :        "BGP Zebra messages\n")
    1625             : {
    1626           0 :         if (vty->node == CONFIG_NODE)
    1627           0 :                 DEBUG_ON(zebra, ZEBRA);
    1628             :         else {
    1629           0 :                 TERM_DEBUG_ON(zebra, ZEBRA);
    1630           0 :                 vty_out(vty, "BGP zebra debugging is on\n");
    1631             :         }
    1632           0 :         return CMD_SUCCESS;
    1633             : }
    1634             : 
    1635           0 : DEFUN (debug_bgp_graceful_restart,
    1636             :        debug_bgp_graceful_restart_cmd,
    1637             :        "debug bgp graceful-restart",
    1638             :        DEBUG_STR
    1639             :        BGP_STR
    1640             :        GR_DEBUG)
    1641             : {
    1642           0 :         if (vty->node == CONFIG_NODE) {
    1643           0 :                 DEBUG_ON(graceful_restart, GRACEFUL_RESTART);
    1644             :         } else {
    1645           0 :                 TERM_DEBUG_ON(graceful_restart, GRACEFUL_RESTART);
    1646           0 :                 vty_out(vty, "BGP Graceful Restart debugging is on\n");
    1647             :         }
    1648           0 :         return CMD_SUCCESS;
    1649             : }
    1650             : 
    1651             : 
    1652           0 : DEFPY (debug_bgp_zebra_prefix,
    1653             :        debug_bgp_zebra_prefix_cmd,
    1654             :        "debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>$prefix",
    1655             :        DEBUG_STR
    1656             :        BGP_STR
    1657             :        "BGP Zebra messages\n"
    1658             :        "Specify a prefix to debug\n"
    1659             :        "IPv4 prefix\n"
    1660             :        "IPv6 prefix\n")
    1661             : {
    1662           0 :         if (!bgp_debug_zebra_prefixes)
    1663           0 :                 bgp_debug_zebra_prefixes = list_new();
    1664             : 
    1665           0 :         if (bgp_debug_list_has_entry(bgp_debug_zebra_prefixes, NULL, prefix)) {
    1666           0 :                 vty_out(vty, "BGP zebra debugging is already enabled for %s\n",
    1667             :                         prefix_str);
    1668           0 :                 return CMD_SUCCESS;
    1669             :         }
    1670             : 
    1671           0 :         bgp_debug_list_add_entry(bgp_debug_zebra_prefixes, NULL, prefix);
    1672             : 
    1673           0 :         if (vty->node == CONFIG_NODE)
    1674           0 :                 DEBUG_ON(zebra, ZEBRA);
    1675             :         else {
    1676           0 :                 TERM_DEBUG_ON(zebra, ZEBRA);
    1677           0 :                 vty_out(vty, "BGP zebra debugging is on for %s\n", prefix_str);
    1678             :         }
    1679             : 
    1680             :         return CMD_SUCCESS;
    1681             : }
    1682             : 
    1683           0 : DEFUN (no_debug_bgp_zebra,
    1684             :        no_debug_bgp_zebra_cmd,
    1685             :        "no debug bgp zebra",
    1686             :        NO_STR
    1687             :        DEBUG_STR
    1688             :        BGP_STR
    1689             :        "BGP Zebra messages\n")
    1690             : {
    1691           0 :         bgp_debug_list_free(bgp_debug_zebra_prefixes);
    1692             : 
    1693           0 :         if (vty->node == CONFIG_NODE)
    1694           0 :                 DEBUG_OFF(zebra, ZEBRA);
    1695             :         else {
    1696           0 :                 TERM_DEBUG_OFF(zebra, ZEBRA);
    1697           0 :                 vty_out(vty, "BGP zebra debugging is off\n");
    1698             :         }
    1699           0 :         return CMD_SUCCESS;
    1700             : }
    1701             : 
    1702           0 : DEFUN (no_debug_bgp_graceful_restart,
    1703             :         no_debug_bgp_graceful_restart_cmd,
    1704             :         "no debug bgp graceful-restart",
    1705             :         DEBUG_STR
    1706             :         BGP_STR
    1707             :         GR_DEBUG
    1708             :         NO_STR)
    1709             : {
    1710           0 :         if (vty->node == CONFIG_NODE) {
    1711           0 :                 DEBUG_OFF(graceful_restart, GRACEFUL_RESTART);
    1712             :         } else {
    1713           0 :                 TERM_DEBUG_OFF(graceful_restart, GRACEFUL_RESTART);
    1714           0 :                 vty_out(vty, "BGP Graceful Restart debugging is off\n");
    1715             :         }
    1716           0 :         return CMD_SUCCESS;
    1717             : }
    1718             : 
    1719           0 : DEFPY (no_debug_bgp_zebra_prefix,
    1720             :        no_debug_bgp_zebra_prefix_cmd,
    1721             :        "no debug bgp zebra prefix <A.B.C.D/M|X:X::X:X/M>$prefix",
    1722             :        NO_STR
    1723             :        DEBUG_STR
    1724             :        BGP_STR
    1725             :        "BGP Zebra messages\n"
    1726             :        "Specify a prefix to debug\n"
    1727             :        "IPv4 prefix\n"
    1728             :        "IPv6 prefix\n")
    1729             : {
    1730           0 :         bool found_prefix = false;
    1731             : 
    1732           0 :         if (bgp_debug_zebra_prefixes
    1733           0 :             && !list_isempty(bgp_debug_zebra_prefixes)) {
    1734           0 :                 found_prefix = bgp_debug_list_remove_entry(
    1735             :                         bgp_debug_zebra_prefixes, NULL, prefix);
    1736             : 
    1737           0 :                 if (list_isempty(bgp_debug_zebra_prefixes)) {
    1738           0 :                         if (vty->node == CONFIG_NODE)
    1739           0 :                                 DEBUG_OFF(zebra, ZEBRA);
    1740             :                         else {
    1741           0 :                                 TERM_DEBUG_OFF(zebra, ZEBRA);
    1742           0 :                                 vty_out(vty, "BGP zebra debugging is off\n");
    1743             :                         }
    1744             :                 }
    1745             :         }
    1746             : 
    1747           0 :         if (found_prefix)
    1748           0 :                 vty_out(vty, "BGP zebra debugging is off for %s\n", prefix_str);
    1749             :         else
    1750           0 :                 vty_out(vty, "BGP zebra debugging was not enabled for %s\n",
    1751             :                         prefix_str);
    1752             : 
    1753           0 :         return CMD_SUCCESS;
    1754             : }
    1755             : 
    1756             : /* debug bgp update-groups */
    1757           0 : DEFUN (debug_bgp_update_groups,
    1758             :        debug_bgp_update_groups_cmd,
    1759             :        "debug bgp update-groups",
    1760             :        DEBUG_STR
    1761             :        BGP_STR
    1762             :        "BGP update-groups\n")
    1763             : {
    1764           0 :         if (vty->node == CONFIG_NODE)
    1765           0 :                 DEBUG_ON(update_groups, UPDATE_GROUPS);
    1766             :         else {
    1767           0 :                 TERM_DEBUG_ON(update_groups, UPDATE_GROUPS);
    1768           0 :                 vty_out(vty, "BGP update-groups debugging is on\n");
    1769             :         }
    1770           0 :         return CMD_SUCCESS;
    1771             : }
    1772             : 
    1773           0 : DEFUN (no_debug_bgp_update_groups,
    1774             :        no_debug_bgp_update_groups_cmd,
    1775             :        "no debug bgp update-groups",
    1776             :        NO_STR
    1777             :        DEBUG_STR
    1778             :        BGP_STR
    1779             :        "BGP update-groups\n")
    1780             : {
    1781           0 :         if (vty->node == CONFIG_NODE)
    1782           0 :                 DEBUG_OFF(update_groups, UPDATE_GROUPS);
    1783             :         else {
    1784           0 :                 TERM_DEBUG_OFF(update_groups, UPDATE_GROUPS);
    1785           0 :                 vty_out(vty, "BGP update-groups debugging is off\n");
    1786             :         }
    1787           0 :         return CMD_SUCCESS;
    1788             : }
    1789             : 
    1790           0 : DEFUN (debug_bgp_vpn,
    1791             :        debug_bgp_vpn_cmd,
    1792             :        "debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
    1793             :        DEBUG_STR
    1794             :        BGP_STR
    1795             :        "VPN routes\n"
    1796             :        "leaked from vrf to vpn\n"
    1797             :        "leaked to vrf from vpn\n"
    1798             :        "route-map updates\n"
    1799             :        "labels\n")
    1800             : {
    1801           0 :         int idx = 3;
    1802             : 
    1803           0 :         if (argv_find(argv, argc, "leak-from-vrf", &idx)) {
    1804           0 :                 if (vty->node == CONFIG_NODE)
    1805           0 :                         DEBUG_ON(vpn, VPN_LEAK_FROM_VRF);
    1806             :                 else
    1807           0 :                         TERM_DEBUG_ON(vpn, VPN_LEAK_FROM_VRF);
    1808           0 :         } else if (argv_find(argv, argc, "leak-to-vrf", &idx)) {
    1809           0 :                 if (vty->node == CONFIG_NODE)
    1810           0 :                         DEBUG_ON(vpn, VPN_LEAK_TO_VRF);
    1811             :                 else
    1812           0 :                         TERM_DEBUG_ON(vpn, VPN_LEAK_TO_VRF);
    1813           0 :         } else if (argv_find(argv, argc, "rmap-event", &idx)) {
    1814           0 :                 if (vty->node == CONFIG_NODE)
    1815           0 :                         DEBUG_ON(vpn, VPN_LEAK_RMAP_EVENT);
    1816             :                 else
    1817           0 :                         TERM_DEBUG_ON(vpn, VPN_LEAK_RMAP_EVENT);
    1818           0 :         } else if (argv_find(argv, argc, "label", &idx)) {
    1819           0 :                 if (vty->node == CONFIG_NODE)
    1820           0 :                         DEBUG_ON(vpn, VPN_LEAK_LABEL);
    1821             :                 else
    1822           0 :                         TERM_DEBUG_ON(vpn, VPN_LEAK_LABEL);
    1823             :         } else {
    1824           0 :                 vty_out(vty, "%% unknown debug bgp vpn keyword\n");
    1825           0 :                 return CMD_WARNING_CONFIG_FAILED;
    1826             :         }
    1827             : 
    1828           0 :         if (vty->node != CONFIG_NODE)
    1829           0 :                 vty_out(vty, "enabled debug bgp vpn %s\n", argv[idx]->text);
    1830             : 
    1831             :         return CMD_SUCCESS;
    1832             : }
    1833             : 
    1834           0 : DEFUN (no_debug_bgp_vpn,
    1835             :        no_debug_bgp_vpn_cmd,
    1836             :        "no debug bgp vpn <leak-from-vrf|leak-to-vrf|rmap-event|label>",
    1837             :        NO_STR
    1838             :        DEBUG_STR
    1839             :        BGP_STR
    1840             :        "VPN routes\n"
    1841             :        "leaked from vrf to vpn\n"
    1842             :        "leaked to vrf from vpn\n"
    1843             :        "route-map updates\n"
    1844             :        "labels\n")
    1845             : {
    1846           0 :         int idx = 4;
    1847             : 
    1848           0 :         if (argv_find(argv, argc, "leak-from-vrf", &idx)) {
    1849           0 :                 if (vty->node == CONFIG_NODE)
    1850           0 :                         DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF);
    1851             :                 else
    1852           0 :                         TERM_DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF);
    1853             : 
    1854           0 :         } else if (argv_find(argv, argc, "leak-to-vrf", &idx)) {
    1855           0 :                 if (vty->node == CONFIG_NODE)
    1856           0 :                         DEBUG_OFF(vpn, VPN_LEAK_TO_VRF);
    1857             :                 else
    1858           0 :                         TERM_DEBUG_OFF(vpn, VPN_LEAK_TO_VRF);
    1859           0 :         } else if (argv_find(argv, argc, "rmap-event", &idx)) {
    1860           0 :                 if (vty->node == CONFIG_NODE)
    1861           0 :                         DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT);
    1862             :                 else
    1863           0 :                         TERM_DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT);
    1864           0 :         } else if (argv_find(argv, argc, "label", &idx)) {
    1865           0 :                 if (vty->node == CONFIG_NODE)
    1866           0 :                         DEBUG_OFF(vpn, VPN_LEAK_LABEL);
    1867             :                 else
    1868           0 :                         TERM_DEBUG_OFF(vpn, VPN_LEAK_LABEL);
    1869             :         } else {
    1870           0 :                 vty_out(vty, "%% unknown debug bgp vpn keyword\n");
    1871           0 :                 return CMD_WARNING_CONFIG_FAILED;
    1872             :         }
    1873             : 
    1874           0 :         if (vty->node != CONFIG_NODE)
    1875           0 :                 vty_out(vty, "disabled debug bgp vpn %s\n", argv[idx]->text);
    1876             :         return CMD_SUCCESS;
    1877             : }
    1878             : 
    1879             : /* debug bgp pbr */
    1880           0 : DEFUN (debug_bgp_pbr,
    1881             :        debug_bgp_pbr_cmd,
    1882             :        "debug bgp pbr [error]",
    1883             :        DEBUG_STR
    1884             :        BGP_STR
    1885             :        "BGP policy based routing\n"
    1886             :        "BGP PBR error\n")
    1887             : {
    1888           0 :         int idx = 3;
    1889             : 
    1890           0 :         if (argv_find(argv, argc, "error", &idx)) {
    1891           0 :                 if (vty->node == CONFIG_NODE)
    1892           0 :                         DEBUG_ON(pbr, PBR_ERROR);
    1893             :                 else {
    1894           0 :                         TERM_DEBUG_ON(pbr, PBR_ERROR);
    1895           0 :                         vty_out(vty, "BGP policy based routing error is on\n");
    1896             :                 }
    1897           0 :                 return CMD_SUCCESS;
    1898             :         }
    1899           0 :         if (vty->node == CONFIG_NODE)
    1900           0 :                 DEBUG_ON(pbr, PBR);
    1901             :         else {
    1902           0 :                 TERM_DEBUG_ON(pbr, PBR);
    1903           0 :                 vty_out(vty, "BGP policy based routing is on\n");
    1904             :         }
    1905             :         return CMD_SUCCESS;
    1906             : }
    1907             : 
    1908           0 : DEFUN (no_debug_bgp_pbr,
    1909             :        no_debug_bgp_pbr_cmd,
    1910             :        "no debug bgp pbr [error]",
    1911             :        NO_STR
    1912             :        DEBUG_STR
    1913             :        BGP_STR
    1914             :        "BGP policy based routing\n"
    1915             :        "BGP PBR Error\n")
    1916             : {
    1917           0 :         int idx = 3;
    1918             : 
    1919           0 :         if (argv_find(argv, argc, "error", &idx)) {
    1920           0 :                 if (vty->node == CONFIG_NODE)
    1921           0 :                         DEBUG_OFF(pbr, PBR_ERROR);
    1922             :                 else {
    1923           0 :                         TERM_DEBUG_OFF(pbr, PBR_ERROR);
    1924           0 :                         vty_out(vty, "BGP policy based routing error is off\n");
    1925             :                 }
    1926           0 :                 return CMD_SUCCESS;
    1927             :         }
    1928           0 :         if (vty->node == CONFIG_NODE)
    1929           0 :                 DEBUG_OFF(pbr, PBR);
    1930             :         else {
    1931           0 :                 TERM_DEBUG_OFF(pbr, PBR);
    1932           0 :                 vty_out(vty, "BGP policy based routing is off\n");
    1933             :         }
    1934             :         return CMD_SUCCESS;
    1935             : }
    1936             : 
    1937           0 : DEFPY (debug_bgp_evpn_mh,
    1938             :        debug_bgp_evpn_mh_cmd,
    1939             :        "[no$no] debug bgp evpn mh <es$es|route$rt>",
    1940             :        NO_STR
    1941             :        DEBUG_STR
    1942             :        BGP_STR
    1943             :        "EVPN\n"
    1944             :        "Multihoming\n"
    1945             :        "Ethernet Segment debugging\n"
    1946             :        "Route debugging\n")
    1947             : {
    1948           0 :         if (es) {
    1949           0 :                 if (vty->node == CONFIG_NODE) {
    1950           0 :                         if (no)
    1951           0 :                                 DEBUG_OFF(evpn_mh, EVPN_MH_ES);
    1952             :                         else
    1953           0 :                                 DEBUG_ON(evpn_mh, EVPN_MH_ES);
    1954             :                 } else {
    1955           0 :                         if (no) {
    1956           0 :                                 TERM_DEBUG_OFF(evpn_mh, EVPN_MH_ES);
    1957           0 :                                 vty_out(vty,
    1958             :                                         "BGP EVPN-MH ES debugging is off\n");
    1959             :                         } else {
    1960           0 :                                 TERM_DEBUG_ON(evpn_mh, EVPN_MH_ES);
    1961           0 :                                 vty_out(vty,
    1962             :                                         "BGP EVPN-MH ES debugging is on\n");
    1963             :                         }
    1964             :                 }
    1965             :         }
    1966           0 :         if (rt) {
    1967           0 :                 if (vty->node == CONFIG_NODE) {
    1968           0 :                         if (no)
    1969           0 :                                 DEBUG_OFF(evpn_mh, EVPN_MH_RT);
    1970             :                         else
    1971           0 :                                 DEBUG_ON(evpn_mh, EVPN_MH_RT);
    1972             :                 } else {
    1973           0 :                         if (no) {
    1974           0 :                                 TERM_DEBUG_OFF(evpn_mh, EVPN_MH_RT);
    1975           0 :                                 vty_out(vty,
    1976             :                                         "BGP EVPN-MH route debugging is off\n");
    1977             :                         } else {
    1978           0 :                                 TERM_DEBUG_ON(evpn_mh, EVPN_MH_RT);
    1979           0 :                                 vty_out(vty,
    1980             :                                         "BGP EVPN-MH route debugging is on\n");
    1981             :                         }
    1982             :                 }
    1983             :         }
    1984             : 
    1985           0 :         return CMD_SUCCESS;
    1986             : }
    1987             : 
    1988           0 : DEFUN (debug_bgp_labelpool,
    1989             :        debug_bgp_labelpool_cmd,
    1990             :        "debug bgp labelpool",
    1991             :        DEBUG_STR
    1992             :        BGP_STR
    1993             :        "label pool\n")
    1994             : {
    1995           0 :         if (vty->node == CONFIG_NODE)
    1996           0 :                 DEBUG_ON(labelpool, LABELPOOL);
    1997             :         else
    1998           0 :                 TERM_DEBUG_ON(labelpool, LABELPOOL);
    1999             : 
    2000           0 :         if (vty->node != CONFIG_NODE)
    2001           0 :                 vty_out(vty, "enabled debug bgp labelpool\n");
    2002             : 
    2003           0 :         return CMD_SUCCESS;
    2004             : }
    2005             : 
    2006           0 : DEFUN (no_debug_bgp_labelpool,
    2007             :        no_debug_bgp_labelpool_cmd,
    2008             :        "no debug bgp labelpool",
    2009             :        NO_STR
    2010             :        DEBUG_STR
    2011             :        BGP_STR
    2012             :        "label pool\n")
    2013             : {
    2014           0 :         if (vty->node == CONFIG_NODE)
    2015           0 :                 DEBUG_OFF(labelpool, LABELPOOL);
    2016             :         else
    2017           0 :                 TERM_DEBUG_OFF(labelpool, LABELPOOL);
    2018             : 
    2019             : 
    2020           0 :         if (vty->node != CONFIG_NODE)
    2021           0 :                 vty_out(vty, "disabled debug bgp labelpool\n");
    2022             : 
    2023           0 :         return CMD_SUCCESS;
    2024             : }
    2025             : 
    2026           0 : DEFPY(debug_bgp_bfd, debug_bgp_bfd_cmd,
    2027             :       "[no] debug bgp bfd",
    2028             :       NO_STR
    2029             :       DEBUG_STR
    2030             :       BGP_STR
    2031             :       "Bidirection Forwarding Detection\n")
    2032             : {
    2033           0 :         if (vty->node == CONFIG_NODE) {
    2034           0 :                 if (no) {
    2035           0 :                         DEBUG_OFF(bfd, BFD_LIB);
    2036           0 :                         bfd_protocol_integration_set_debug(false);
    2037             :                 } else {
    2038           0 :                         DEBUG_ON(bfd, BFD_LIB);
    2039           0 :                         bfd_protocol_integration_set_debug(true);
    2040             :                 }
    2041             :         } else {
    2042           0 :                 if (no) {
    2043           0 :                         TERM_DEBUG_OFF(bfd, BFD_LIB);
    2044           0 :                         bfd_protocol_integration_set_debug(false);
    2045             :                 } else {
    2046           0 :                         TERM_DEBUG_ON(bfd, BFD_LIB);
    2047           0 :                         bfd_protocol_integration_set_debug(true);
    2048             :                 }
    2049             :         }
    2050             : 
    2051           0 :         return CMD_SUCCESS;
    2052             : }
    2053             : 
    2054           0 : DEFPY (debug_bgp_cond_adv,
    2055             :        debug_bgp_cond_adv_cmd,
    2056             :        "[no$no] debug bgp conditional-advertisement",
    2057             :        NO_STR
    2058             :        DEBUG_STR
    2059             :        BGP_STR
    2060             :        "BGP conditional advertisement\n")
    2061             : {
    2062           0 :         if (vty->node == CONFIG_NODE) {
    2063           0 :                 if (no)
    2064           0 :                         DEBUG_OFF(cond_adv, COND_ADV);
    2065             :                 else
    2066           0 :                         DEBUG_ON(cond_adv, COND_ADV);
    2067             :         } else {
    2068           0 :                 if (no) {
    2069           0 :                         TERM_DEBUG_OFF(cond_adv, COND_ADV);
    2070           0 :                         vty_out(vty,
    2071             :                                 "BGP conditional advertisement debugging is off\n");
    2072             :                 } else {
    2073           0 :                         TERM_DEBUG_ON(cond_adv, COND_ADV);
    2074           0 :                         vty_out(vty,
    2075             :                                 "BGP conditional advertisement debugging is on\n");
    2076             :                 }
    2077             :         }
    2078           0 :         return CMD_SUCCESS;
    2079             : }
    2080             : 
    2081           0 : DEFUN (no_debug_bgp,
    2082             :        no_debug_bgp_cmd,
    2083             :        "no debug bgp",
    2084             :        NO_STR
    2085             :        DEBUG_STR
    2086             :        BGP_STR)
    2087             : {
    2088           0 :         struct bgp *bgp;
    2089           0 :         struct listnode *ln;
    2090             : 
    2091           0 :         bgp_debug_list_free(bgp_debug_neighbor_events_peers);
    2092           0 :         bgp_debug_list_free(bgp_debug_keepalive_peers);
    2093           0 :         bgp_debug_list_free(bgp_debug_update_in_peers);
    2094           0 :         bgp_debug_list_free(bgp_debug_update_out_peers);
    2095           0 :         bgp_debug_list_free(bgp_debug_update_prefixes);
    2096           0 :         bgp_debug_list_free(bgp_debug_bestpath_prefixes);
    2097           0 :         bgp_debug_list_free(bgp_debug_zebra_prefixes);
    2098             : 
    2099           0 :         for (ALL_LIST_ELEMENTS_RO(bm->bgp, ln, bgp))
    2100           0 :                 bgp_debug_clear_updgrp_update_dbg(bgp);
    2101             : 
    2102           0 :         TERM_DEBUG_OFF(keepalive, KEEPALIVE);
    2103           0 :         TERM_DEBUG_OFF(update, UPDATE_IN);
    2104           0 :         TERM_DEBUG_OFF(update, UPDATE_OUT);
    2105           0 :         TERM_DEBUG_OFF(update, UPDATE_PREFIX);
    2106           0 :         TERM_DEBUG_OFF(bestpath, BESTPATH);
    2107           0 :         TERM_DEBUG_OFF(as4, AS4);
    2108           0 :         TERM_DEBUG_OFF(as4, AS4_SEGMENT);
    2109           0 :         TERM_DEBUG_OFF(neighbor_events, NEIGHBOR_EVENTS);
    2110           0 :         TERM_DEBUG_OFF(zebra, ZEBRA);
    2111           0 :         TERM_DEBUG_OFF(allow_martians, ALLOW_MARTIANS);
    2112           0 :         TERM_DEBUG_OFF(nht, NHT);
    2113           0 :         TERM_DEBUG_OFF(vpn, VPN_LEAK_FROM_VRF);
    2114           0 :         TERM_DEBUG_OFF(vpn, VPN_LEAK_TO_VRF);
    2115           0 :         TERM_DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT);
    2116           0 :         TERM_DEBUG_OFF(vpn, VPN_LEAK_LABEL);
    2117           0 :         TERM_DEBUG_OFF(flowspec, FLOWSPEC);
    2118           0 :         TERM_DEBUG_OFF(labelpool, LABELPOOL);
    2119           0 :         TERM_DEBUG_OFF(pbr, PBR);
    2120           0 :         TERM_DEBUG_OFF(pbr, PBR_ERROR);
    2121           0 :         TERM_DEBUG_OFF(graceful_restart, GRACEFUL_RESTART);
    2122           0 :         TERM_DEBUG_OFF(evpn_mh, EVPN_MH_ES);
    2123           0 :         TERM_DEBUG_OFF(evpn_mh, EVPN_MH_RT);
    2124           0 :         TERM_DEBUG_OFF(bfd, BFD_LIB);
    2125           0 :         TERM_DEBUG_OFF(cond_adv, COND_ADV);
    2126             : 
    2127           0 :         vty_out(vty, "All possible debugging has been turned off\n");
    2128             : 
    2129           0 :         return CMD_SUCCESS;
    2130             : }
    2131             : 
    2132           0 : DEFUN_NOSH (show_debugging_bgp,
    2133             :             show_debugging_bgp_cmd,
    2134             :             "show debugging [bgp]",
    2135             :             SHOW_STR
    2136             :             DEBUG_STR
    2137             :             BGP_STR)
    2138             : {
    2139           0 :         vty_out(vty, "BGP debugging status:\n");
    2140             : 
    2141           0 :         if (BGP_DEBUG(as4, AS4))
    2142           0 :                 vty_out(vty, "  BGP as4 debugging is on\n");
    2143             : 
    2144           0 :         if (BGP_DEBUG(as4, AS4_SEGMENT))
    2145           0 :                 vty_out(vty, "  BGP as4 aspath segment debugging is on\n");
    2146             : 
    2147           0 :         if (BGP_DEBUG(bestpath, BESTPATH))
    2148           0 :                 bgp_debug_list_print(vty, "  BGP bestpath debugging is on",
    2149             :                                      bgp_debug_bestpath_prefixes);
    2150             : 
    2151           0 :         if (BGP_DEBUG(keepalive, KEEPALIVE))
    2152           0 :                 bgp_debug_list_print(vty, "  BGP keepalives debugging is on",
    2153             :                                      bgp_debug_keepalive_peers);
    2154             : 
    2155           0 :         if (BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS))
    2156           0 :                 bgp_debug_list_print(vty,
    2157             :                                      "  BGP neighbor-events debugging is on",
    2158             :                                      bgp_debug_neighbor_events_peers);
    2159             : 
    2160           0 :         if (BGP_DEBUG(nht, NHT))
    2161           0 :                 vty_out(vty, "  BGP next-hop tracking debugging is on\n");
    2162             : 
    2163           0 :         if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
    2164           0 :                 vty_out(vty, "  BGP update-groups debugging is on\n");
    2165             : 
    2166           0 :         if (BGP_DEBUG(update, UPDATE_PREFIX))
    2167           0 :                 bgp_debug_list_print(vty, "  BGP updates debugging is on",
    2168             :                                      bgp_debug_update_prefixes);
    2169             : 
    2170           0 :         if (BGP_DEBUG(update, UPDATE_IN))
    2171           0 :                 bgp_debug_list_print(vty,
    2172             :                                      "  BGP updates debugging is on (inbound)",
    2173             :                                      bgp_debug_update_in_peers);
    2174             : 
    2175           0 :         if (BGP_DEBUG(update, UPDATE_OUT))
    2176           0 :                 bgp_debug_list_print(vty,
    2177             :                                      "  BGP updates debugging is on (outbound)",
    2178             :                                      bgp_debug_update_out_peers);
    2179             : 
    2180           0 :         if (BGP_DEBUG(zebra, ZEBRA))
    2181           0 :                 bgp_debug_list_print(vty, "  BGP zebra debugging is on",
    2182             :                                      bgp_debug_zebra_prefixes);
    2183             : 
    2184           0 :         if (BGP_DEBUG(graceful_restart, GRACEFUL_RESTART))
    2185           0 :                 vty_out(vty, "  BGP graceful-restart debugging is on\n");
    2186             : 
    2187           0 :         if (BGP_DEBUG(allow_martians, ALLOW_MARTIANS))
    2188           0 :                 vty_out(vty, "  BGP allow martian next hop debugging is on\n");
    2189             : 
    2190           0 :         if (BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF))
    2191           0 :                 vty_out(vty,
    2192             :                         "  BGP route leak from vrf to vpn debugging is on\n");
    2193           0 :         if (BGP_DEBUG(vpn, VPN_LEAK_TO_VRF))
    2194           0 :                 vty_out(vty,
    2195             :                         "  BGP route leak to vrf from vpn debugging is on\n");
    2196           0 :         if (BGP_DEBUG(vpn, VPN_LEAK_RMAP_EVENT))
    2197           0 :                 vty_out(vty, "  BGP vpn route-map event debugging is on\n");
    2198           0 :         if (BGP_DEBUG(vpn, VPN_LEAK_LABEL))
    2199           0 :                 vty_out(vty, "  BGP vpn label event debugging is on\n");
    2200           0 :         if (BGP_DEBUG(flowspec, FLOWSPEC))
    2201           0 :                 vty_out(vty, "  BGP flowspec debugging is on\n");
    2202           0 :         if (BGP_DEBUG(labelpool, LABELPOOL))
    2203           0 :                 vty_out(vty, "  BGP labelpool debugging is on\n");
    2204             : 
    2205           0 :         if (BGP_DEBUG(pbr, PBR))
    2206           0 :                 vty_out(vty, "  BGP policy based routing debugging is on\n");
    2207           0 :         if (BGP_DEBUG(pbr, PBR_ERROR))
    2208           0 :                 vty_out(vty, "  BGP policy based routing error debugging is on\n");
    2209             : 
    2210           0 :         if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
    2211           0 :                 vty_out(vty, "  BGP EVPN-MH ES debugging is on\n");
    2212           0 :         if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
    2213           0 :                 vty_out(vty, "  BGP EVPN-MH route debugging is on\n");
    2214             : 
    2215           0 :         if (BGP_DEBUG(bfd, BFD_LIB))
    2216           0 :                 vty_out(vty, "  BGP BFD library debugging is on\n");
    2217             : 
    2218           0 :         if (BGP_DEBUG(cond_adv, COND_ADV))
    2219           0 :                 vty_out(vty,
    2220             :                         "  BGP conditional advertisement debugging is on\n");
    2221             : 
    2222           0 :         cmd_show_lib_debugs(vty);
    2223             : 
    2224           0 :         return CMD_SUCCESS;
    2225             : }
    2226             : 
    2227           0 : static int bgp_config_write_debug(struct vty *vty)
    2228             : {
    2229           0 :         int write = 0;
    2230             : 
    2231           0 :         if (CONF_BGP_DEBUG(as4, AS4)) {
    2232           0 :                 vty_out(vty, "debug bgp as4\n");
    2233           0 :                 write++;
    2234             :         }
    2235             : 
    2236           0 :         if (CONF_BGP_DEBUG(as4, AS4_SEGMENT)) {
    2237           0 :                 vty_out(vty, "debug bgp as4 segment\n");
    2238           0 :                 write++;
    2239             :         }
    2240             : 
    2241           0 :         if (CONF_BGP_DEBUG(bestpath, BESTPATH)) {
    2242           0 :                 write += bgp_debug_list_conf_print(vty, "debug bgp bestpath",
    2243             :                                                    bgp_debug_bestpath_prefixes);
    2244             :         }
    2245             : 
    2246           0 :         if (CONF_BGP_DEBUG(keepalive, KEEPALIVE)) {
    2247           0 :                 write += bgp_debug_list_conf_print(vty, "debug bgp keepalives",
    2248             :                                                    bgp_debug_keepalive_peers);
    2249             :         }
    2250             : 
    2251           0 :         if (CONF_BGP_DEBUG(neighbor_events, NEIGHBOR_EVENTS)) {
    2252           0 :                 write += bgp_debug_list_conf_print(
    2253             :                         vty, "debug bgp neighbor-events",
    2254             :                         bgp_debug_neighbor_events_peers);
    2255             :         }
    2256             : 
    2257           0 :         if (CONF_BGP_DEBUG(nht, NHT)) {
    2258           0 :                 vty_out(vty, "debug bgp nht\n");
    2259           0 :                 write++;
    2260             :         }
    2261             : 
    2262           0 :         if (CONF_BGP_DEBUG(update_groups, UPDATE_GROUPS)) {
    2263           0 :                 vty_out(vty, "debug bgp update-groups\n");
    2264           0 :                 write++;
    2265             :         }
    2266             : 
    2267           0 :         if (CONF_BGP_DEBUG(update, UPDATE_PREFIX)) {
    2268           0 :                 write += bgp_debug_list_conf_print(vty,
    2269             :                                                    "debug bgp updates prefix",
    2270             :                                                    bgp_debug_update_prefixes);
    2271             :         }
    2272             : 
    2273           0 :         if (CONF_BGP_DEBUG(update, UPDATE_IN)) {
    2274           0 :                 write += bgp_debug_list_conf_print(vty, "debug bgp updates in",
    2275             :                                                    bgp_debug_update_in_peers);
    2276             :         }
    2277             : 
    2278           0 :         if (CONF_BGP_DEBUG(update, UPDATE_OUT)) {
    2279           0 :                 write += bgp_debug_list_conf_print(vty, "debug bgp updates out",
    2280             :                                                    bgp_debug_update_out_peers);
    2281             :         }
    2282             : 
    2283           0 :         if (CONF_BGP_DEBUG(zebra, ZEBRA)) {
    2284           0 :                 if (!bgp_debug_zebra_prefixes
    2285           0 :                     || list_isempty(bgp_debug_zebra_prefixes)) {
    2286           0 :                         vty_out(vty, "debug bgp zebra\n");
    2287           0 :                         write++;
    2288             :                 } else {
    2289           0 :                         write += bgp_debug_list_conf_print(
    2290             :                                 vty, "debug bgp zebra prefix",
    2291             :                                 bgp_debug_zebra_prefixes);
    2292             :                 }
    2293             :         }
    2294             : 
    2295           0 :         if (CONF_BGP_DEBUG(allow_martians, ALLOW_MARTIANS)) {
    2296           0 :                 vty_out(vty, "debug bgp allow-martians\n");
    2297           0 :                 write++;
    2298             :         }
    2299             : 
    2300           0 :         if (CONF_BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF)) {
    2301           0 :                 vty_out(vty, "debug bgp vpn leak-from-vrf\n");
    2302           0 :                 write++;
    2303             :         }
    2304           0 :         if (CONF_BGP_DEBUG(vpn, VPN_LEAK_TO_VRF)) {
    2305           0 :                 vty_out(vty, "debug bgp vpn leak-to-vrf\n");
    2306           0 :                 write++;
    2307             :         }
    2308           0 :         if (CONF_BGP_DEBUG(vpn, VPN_LEAK_RMAP_EVENT)) {
    2309           0 :                 vty_out(vty, "debug bgp vpn rmap-event\n");
    2310           0 :                 write++;
    2311             :         }
    2312           0 :         if (CONF_BGP_DEBUG(vpn, VPN_LEAK_LABEL)) {
    2313           0 :                 vty_out(vty, "debug bgp vpn label\n");
    2314           0 :                 write++;
    2315             :         }
    2316           0 :         if (CONF_BGP_DEBUG(flowspec, FLOWSPEC)) {
    2317           0 :                 vty_out(vty, "debug bgp flowspec\n");
    2318           0 :                 write++;
    2319             :         }
    2320           0 :         if (CONF_BGP_DEBUG(labelpool, LABELPOOL)) {
    2321           0 :                 vty_out(vty, "debug bgp labelpool\n");
    2322           0 :                 write++;
    2323             :         }
    2324             : 
    2325           0 :         if (CONF_BGP_DEBUG(pbr, PBR)) {
    2326           0 :                 vty_out(vty, "debug bgp pbr\n");
    2327           0 :                 write++;
    2328             :         }
    2329           0 :         if (CONF_BGP_DEBUG(pbr, PBR_ERROR)) {
    2330           0 :                 vty_out(vty, "debug bgp pbr error\n");
    2331           0 :                 write++;
    2332             :         }
    2333             : 
    2334           0 :         if (CONF_BGP_DEBUG(graceful_restart, GRACEFUL_RESTART)) {
    2335           0 :                 vty_out(vty, "debug bgp graceful-restart\n");
    2336           0 :                 write++;
    2337             :         }
    2338             : 
    2339           0 :         if (CONF_BGP_DEBUG(evpn_mh, EVPN_MH_ES)) {
    2340           0 :                 vty_out(vty, "debug bgp evpn mh es\n");
    2341           0 :                 write++;
    2342             :         }
    2343           0 :         if (CONF_BGP_DEBUG(evpn_mh, EVPN_MH_RT)) {
    2344           0 :                 vty_out(vty, "debug bgp evpn mh route\n");
    2345           0 :                 write++;
    2346             :         }
    2347             : 
    2348           0 :         if (CONF_BGP_DEBUG(bfd, BFD_LIB)) {
    2349           0 :                 vty_out(vty, "debug bgp bfd\n");
    2350           0 :                 write++;
    2351             :         }
    2352             : 
    2353           0 :         if (CONF_BGP_DEBUG(cond_adv, COND_ADV)) {
    2354           0 :                 vty_out(vty, "debug bgp conditional-advertisement\n");
    2355           0 :                 write++;
    2356             :         }
    2357             : 
    2358           0 :         return write;
    2359             : }
    2360             : 
    2361             : static int bgp_config_write_debug(struct vty *vty);
    2362             : static struct cmd_node debug_node = {
    2363             :         .name = "debug",
    2364             :         .node = DEBUG_NODE,
    2365             :         .prompt = "",
    2366             :         .config_write = bgp_config_write_debug,
    2367             : };
    2368             : 
    2369           3 : void bgp_debug_init(void)
    2370             : {
    2371           3 :         install_node(&debug_node);
    2372             : 
    2373           3 :         install_element(ENABLE_NODE, &show_debugging_bgp_cmd);
    2374             : 
    2375           3 :         install_element(ENABLE_NODE, &debug_bgp_as4_cmd);
    2376           3 :         install_element(CONFIG_NODE, &debug_bgp_as4_cmd);
    2377           3 :         install_element(ENABLE_NODE, &debug_bgp_as4_segment_cmd);
    2378           3 :         install_element(CONFIG_NODE, &debug_bgp_as4_segment_cmd);
    2379             : 
    2380           3 :         install_element(ENABLE_NODE, &debug_bgp_neighbor_events_cmd);
    2381           3 :         install_element(CONFIG_NODE, &debug_bgp_neighbor_events_cmd);
    2382           3 :         install_element(ENABLE_NODE, &debug_bgp_nht_cmd);
    2383           3 :         install_element(CONFIG_NODE, &debug_bgp_nht_cmd);
    2384           3 :         install_element(ENABLE_NODE, &debug_bgp_keepalive_cmd);
    2385           3 :         install_element(CONFIG_NODE, &debug_bgp_keepalive_cmd);
    2386           3 :         install_element(ENABLE_NODE, &debug_bgp_update_cmd);
    2387           3 :         install_element(CONFIG_NODE, &debug_bgp_update_cmd);
    2388           3 :         install_element(ENABLE_NODE, &debug_bgp_zebra_cmd);
    2389           3 :         install_element(CONFIG_NODE, &debug_bgp_zebra_cmd);
    2390           3 :         install_element(ENABLE_NODE, &debug_bgp_update_groups_cmd);
    2391           3 :         install_element(CONFIG_NODE, &debug_bgp_update_groups_cmd);
    2392           3 :         install_element(ENABLE_NODE, &debug_bgp_bestpath_prefix_cmd);
    2393           3 :         install_element(CONFIG_NODE, &debug_bgp_bestpath_prefix_cmd);
    2394             : 
    2395           3 :         install_element(ENABLE_NODE, &debug_bgp_graceful_restart_cmd);
    2396           3 :         install_element(CONFIG_NODE, &debug_bgp_graceful_restart_cmd);
    2397             : 
    2398             :         /* debug bgp updates (in|out) */
    2399           3 :         install_element(ENABLE_NODE, &debug_bgp_update_direct_cmd);
    2400           3 :         install_element(CONFIG_NODE, &debug_bgp_update_direct_cmd);
    2401           3 :         install_element(ENABLE_NODE, &no_debug_bgp_update_direct_cmd);
    2402           3 :         install_element(CONFIG_NODE, &no_debug_bgp_update_direct_cmd);
    2403             : 
    2404             :         /* debug bgp updates (in|out) A.B.C.D */
    2405           3 :         install_element(ENABLE_NODE, &debug_bgp_update_direct_peer_cmd);
    2406           3 :         install_element(CONFIG_NODE, &debug_bgp_update_direct_peer_cmd);
    2407           3 :         install_element(ENABLE_NODE, &no_debug_bgp_update_direct_peer_cmd);
    2408           3 :         install_element(CONFIG_NODE, &no_debug_bgp_update_direct_peer_cmd);
    2409             : 
    2410             :         /* debug bgp updates prefix A.B.C.D/M */
    2411           3 :         install_element(ENABLE_NODE, &debug_bgp_update_prefix_cmd);
    2412           3 :         install_element(CONFIG_NODE, &debug_bgp_update_prefix_cmd);
    2413           3 :         install_element(ENABLE_NODE, &no_debug_bgp_update_prefix_cmd);
    2414           3 :         install_element(CONFIG_NODE, &no_debug_bgp_update_prefix_cmd);
    2415           3 :         install_element(ENABLE_NODE, &debug_bgp_update_prefix_afi_safi_cmd);
    2416           3 :         install_element(CONFIG_NODE, &debug_bgp_update_prefix_afi_safi_cmd);
    2417           3 :         install_element(ENABLE_NODE, &no_debug_bgp_update_prefix_afi_safi_cmd);
    2418           3 :         install_element(CONFIG_NODE, &no_debug_bgp_update_prefix_afi_safi_cmd);
    2419             : 
    2420             :         /* debug bgp zebra prefix A.B.C.D/M */
    2421           3 :         install_element(ENABLE_NODE, &debug_bgp_zebra_prefix_cmd);
    2422           3 :         install_element(CONFIG_NODE, &debug_bgp_zebra_prefix_cmd);
    2423           3 :         install_element(ENABLE_NODE, &no_debug_bgp_zebra_prefix_cmd);
    2424           3 :         install_element(CONFIG_NODE, &no_debug_bgp_zebra_prefix_cmd);
    2425             : 
    2426           3 :         install_element(ENABLE_NODE, &no_debug_bgp_as4_cmd);
    2427           3 :         install_element(CONFIG_NODE, &no_debug_bgp_as4_cmd);
    2428           3 :         install_element(ENABLE_NODE, &no_debug_bgp_as4_segment_cmd);
    2429           3 :         install_element(CONFIG_NODE, &no_debug_bgp_as4_segment_cmd);
    2430             : 
    2431             :         /* debug bgp neighbor-events A.B.C.D */
    2432           3 :         install_element(ENABLE_NODE, &debug_bgp_neighbor_events_peer_cmd);
    2433           3 :         install_element(CONFIG_NODE, &debug_bgp_neighbor_events_peer_cmd);
    2434           3 :         install_element(ENABLE_NODE, &no_debug_bgp_neighbor_events_peer_cmd);
    2435           3 :         install_element(CONFIG_NODE, &no_debug_bgp_neighbor_events_peer_cmd);
    2436             : 
    2437             :         /* debug bgp keepalive A.B.C.D */
    2438           3 :         install_element(ENABLE_NODE, &debug_bgp_keepalive_peer_cmd);
    2439           3 :         install_element(CONFIG_NODE, &debug_bgp_keepalive_peer_cmd);
    2440           3 :         install_element(ENABLE_NODE, &no_debug_bgp_keepalive_peer_cmd);
    2441           3 :         install_element(CONFIG_NODE, &no_debug_bgp_keepalive_peer_cmd);
    2442             : 
    2443           3 :         install_element(ENABLE_NODE, &no_debug_bgp_neighbor_events_cmd);
    2444           3 :         install_element(CONFIG_NODE, &no_debug_bgp_neighbor_events_cmd);
    2445           3 :         install_element(ENABLE_NODE, &no_debug_bgp_nht_cmd);
    2446           3 :         install_element(CONFIG_NODE, &no_debug_bgp_nht_cmd);
    2447           3 :         install_element(ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
    2448           3 :         install_element(CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
    2449           3 :         install_element(ENABLE_NODE, &no_debug_bgp_update_cmd);
    2450           3 :         install_element(CONFIG_NODE, &no_debug_bgp_update_cmd);
    2451           3 :         install_element(ENABLE_NODE, &no_debug_bgp_zebra_cmd);
    2452           3 :         install_element(CONFIG_NODE, &no_debug_bgp_zebra_cmd);
    2453           3 :         install_element(ENABLE_NODE, &no_debug_bgp_update_groups_cmd);
    2454           3 :         install_element(CONFIG_NODE, &no_debug_bgp_update_groups_cmd);
    2455           3 :         install_element(ENABLE_NODE, &no_debug_bgp_cmd);
    2456           3 :         install_element(ENABLE_NODE, &no_debug_bgp_bestpath_cmd);
    2457           3 :         install_element(CONFIG_NODE, &no_debug_bgp_bestpath_cmd);
    2458           3 :         install_element(ENABLE_NODE, &no_debug_bgp_bestpath_prefix_cmd);
    2459           3 :         install_element(CONFIG_NODE, &no_debug_bgp_bestpath_prefix_cmd);
    2460             : 
    2461           3 :         install_element(ENABLE_NODE, &no_debug_bgp_graceful_restart_cmd);
    2462           3 :         install_element(CONFIG_NODE, &no_debug_bgp_graceful_restart_cmd);
    2463             : 
    2464           3 :         install_element(ENABLE_NODE, &debug_bgp_vpn_cmd);
    2465           3 :         install_element(CONFIG_NODE, &debug_bgp_vpn_cmd);
    2466           3 :         install_element(ENABLE_NODE, &no_debug_bgp_vpn_cmd);
    2467           3 :         install_element(CONFIG_NODE, &no_debug_bgp_vpn_cmd);
    2468             : 
    2469           3 :         install_element(ENABLE_NODE, &debug_bgp_labelpool_cmd);
    2470           3 :         install_element(CONFIG_NODE, &debug_bgp_labelpool_cmd);
    2471           3 :         install_element(ENABLE_NODE, &no_debug_bgp_labelpool_cmd);
    2472           3 :         install_element(CONFIG_NODE, &no_debug_bgp_labelpool_cmd);
    2473             : 
    2474             :         /* debug bgp pbr */
    2475           3 :         install_element(ENABLE_NODE, &debug_bgp_pbr_cmd);
    2476           3 :         install_element(CONFIG_NODE, &debug_bgp_pbr_cmd);
    2477           3 :         install_element(ENABLE_NODE, &no_debug_bgp_pbr_cmd);
    2478           3 :         install_element(CONFIG_NODE, &no_debug_bgp_pbr_cmd);
    2479             : 
    2480           3 :         install_element(ENABLE_NODE, &debug_bgp_evpn_mh_cmd);
    2481           3 :         install_element(CONFIG_NODE, &debug_bgp_evpn_mh_cmd);
    2482             : 
    2483             :         /* debug bgp bfd */
    2484           3 :         install_element(ENABLE_NODE, &debug_bgp_bfd_cmd);
    2485           3 :         install_element(CONFIG_NODE, &debug_bgp_bfd_cmd);
    2486             : 
    2487             :         /* debug bgp conditional advertisement */
    2488           3 :         install_element(ENABLE_NODE, &debug_bgp_cond_adv_cmd);
    2489           3 :         install_element(CONFIG_NODE, &debug_bgp_cond_adv_cmd);
    2490           3 : }
    2491             : 
    2492             : /* Return true if this prefix is on the per_prefix_list of prefixes to debug
    2493             :  * for BGP_DEBUG_TYPE
    2494             :  */
    2495           0 : static int bgp_debug_per_prefix(const struct prefix *p,
    2496             :                                 unsigned long term_bgp_debug_type,
    2497             :                                 unsigned int BGP_DEBUG_TYPE,
    2498             :                                 struct list *per_prefix_list)
    2499             : {
    2500           0 :         struct bgp_debug_filter *filter;
    2501           0 :         struct listnode *node, *nnode;
    2502             : 
    2503           0 :         if (term_bgp_debug_type & BGP_DEBUG_TYPE) {
    2504             :                 /* We are debugging all prefixes so return true */
    2505           0 :                 if (!per_prefix_list || list_isempty(per_prefix_list))
    2506             :                         return 1;
    2507             : 
    2508             :                 else {
    2509           0 :                         if (!p)
    2510             :                                 return 0;
    2511             : 
    2512           0 :                         for (ALL_LIST_ELEMENTS(per_prefix_list, node, nnode,
    2513             :                                                filter))
    2514           0 :                                 if (filter->p->prefixlen == p->prefixlen
    2515           0 :                                     && prefix_match(filter->p, p))
    2516             :                                         return 1;
    2517             : 
    2518             :                         return 0;
    2519             :                 }
    2520             :         }
    2521             : 
    2522             :         return 0;
    2523             : }
    2524             : 
    2525             : /* Return true if this peer is on the per_peer_list of peers to debug
    2526             :  * for BGP_DEBUG_TYPE
    2527             :  */
    2528         394 : static bool bgp_debug_per_peer(char *host, unsigned long term_bgp_debug_type,
    2529             :                                unsigned int BGP_DEBUG_TYPE,
    2530             :                                struct list *per_peer_list)
    2531             : {
    2532         394 :         struct bgp_debug_filter *filter;
    2533         394 :         struct listnode *node, *nnode;
    2534             : 
    2535         394 :         if (term_bgp_debug_type & BGP_DEBUG_TYPE) {
    2536             :                 /* We are debugging all peers so return true */
    2537           0 :                 if (!per_peer_list || list_isempty(per_peer_list))
    2538             :                         return true;
    2539             : 
    2540             :                 else {
    2541           0 :                         if (!host)
    2542             :                                 return false;
    2543             : 
    2544           0 :                         for (ALL_LIST_ELEMENTS(per_peer_list, node, nnode,
    2545             :                                                filter))
    2546           0 :                                 if (strcmp(filter->host, host) == 0)
    2547             :                                         return true;
    2548             : 
    2549             :                         return false;
    2550             :                 }
    2551             :         }
    2552             : 
    2553             :         return false;
    2554             : }
    2555             : 
    2556         317 : bool bgp_debug_neighbor_events(const struct peer *peer)
    2557             : {
    2558         317 :         char *host = NULL;
    2559             : 
    2560         317 :         if (peer)
    2561         317 :                 host = peer->host;
    2562             : 
    2563         317 :         return bgp_debug_per_peer(host, term_bgp_debug_neighbor_events,
    2564             :                                   BGP_DEBUG_NEIGHBOR_EVENTS,
    2565             :                                   bgp_debug_neighbor_events_peers);
    2566             : }
    2567             : 
    2568          20 : bool bgp_debug_keepalive(const struct peer *peer)
    2569             : {
    2570          20 :         char *host = NULL;
    2571             : 
    2572          20 :         if (peer)
    2573          20 :                 host = peer->host;
    2574             : 
    2575          20 :         return bgp_debug_per_peer(host, term_bgp_debug_keepalive,
    2576             :                                   BGP_DEBUG_KEEPALIVE,
    2577             :                                   bgp_debug_keepalive_peers);
    2578             : }
    2579             : 
    2580          57 : bool bgp_debug_update(const struct peer *peer, const struct prefix *p,
    2581             :                       struct update_group *updgrp, unsigned int inbound)
    2582             : {
    2583          57 :         char *host = NULL;
    2584             : 
    2585          57 :         if (peer)
    2586          31 :                 host = peer->host;
    2587             : 
    2588          57 :         if (inbound) {
    2589          21 :                 if (bgp_debug_per_peer(host, term_bgp_debug_update,
    2590             :                                        BGP_DEBUG_UPDATE_IN,
    2591             :                                        bgp_debug_update_in_peers))
    2592             :                         return true;
    2593             :         }
    2594             : 
    2595             :         /* outbound */
    2596             :         else {
    2597          36 :                 if (bgp_debug_per_peer(host, term_bgp_debug_update,
    2598             :                                        BGP_DEBUG_UPDATE_OUT,
    2599             :                                        bgp_debug_update_out_peers))
    2600             :                         return true;
    2601             : 
    2602             :                 /* Check if update debugging implicitly enabled for the group.
    2603             :                  */
    2604          36 :                 if (updgrp && UPDGRP_DBG_ON(updgrp))
    2605             :                         return true;
    2606             :         }
    2607             : 
    2608             : 
    2609          57 :         if (BGP_DEBUG(update, UPDATE_PREFIX)) {
    2610           0 :                 if (bgp_debug_per_prefix(p, term_bgp_debug_update,
    2611             :                                          BGP_DEBUG_UPDATE_PREFIX,
    2612             :                                          bgp_debug_update_prefixes))
    2613             :                         return true;
    2614             :         }
    2615             : 
    2616             :         return false;
    2617             : }
    2618             : 
    2619          60 : bool bgp_debug_bestpath(struct bgp_dest *dest)
    2620             : {
    2621          60 :         if (BGP_DEBUG(bestpath, BESTPATH)) {
    2622           0 :                 if (bgp_debug_per_prefix(
    2623             :                             bgp_dest_get_prefix(dest), term_bgp_debug_bestpath,
    2624             :                             BGP_DEBUG_BESTPATH, bgp_debug_bestpath_prefixes))
    2625             :                         return true;
    2626             :         }
    2627             : 
    2628             :         return false;
    2629             : }
    2630             : 
    2631          93 : bool bgp_debug_zebra(const struct prefix *p)
    2632             : {
    2633          93 :         if (BGP_DEBUG(zebra, ZEBRA)) {
    2634           0 :                 if (bgp_debug_per_prefix(p, term_bgp_debug_zebra,
    2635             :                                          BGP_DEBUG_ZEBRA,
    2636             :                                          bgp_debug_zebra_prefixes))
    2637             :                         return true;
    2638             :         }
    2639             : 
    2640             :         return false;
    2641             : }
    2642             : 
    2643           0 : const char *bgp_debug_rdpfxpath2str(afi_t afi, safi_t safi,
    2644             :                                     const struct prefix_rd *prd,
    2645             :                                     union prefixconstptr pu,
    2646             :                                     mpls_label_t *label, uint32_t num_labels,
    2647             :                                     int addpath_valid, uint32_t addpath_id,
    2648             :                                     struct bgp_route_evpn *overlay_index,
    2649             :                                     char *str, int size)
    2650             : {
    2651           0 :         char tag_buf[30];
    2652           0 :         char overlay_index_buf[INET6_ADDRSTRLEN + 14];
    2653           0 :         const struct prefix_evpn *evp;
    2654             : 
    2655             :         /* ' with addpath ID '          17
    2656             :          * max strlen of uint32       + 10
    2657             :          * +/- (just in case)         +  1
    2658             :          * null terminator            +  1
    2659             :          * ============================ 29 */
    2660           0 :         char pathid_buf[30];
    2661             : 
    2662           0 :         if (size < BGP_PRD_PATH_STRLEN)
    2663             :                 return NULL;
    2664             : 
    2665             :         /* Note: Path-id is created by default, but only included in update
    2666             :          * sometimes. */
    2667           0 :         pathid_buf[0] = '\0';
    2668           0 :         if (addpath_valid)
    2669           0 :                 snprintf(pathid_buf, sizeof(pathid_buf), " with addpath ID %u",
    2670             :                          addpath_id);
    2671             : 
    2672           0 :         overlay_index_buf[0] = '\0';
    2673           0 :         if (overlay_index && overlay_index->type == OVERLAY_INDEX_GATEWAY_IP) {
    2674           0 :                 char obuf[INET6_ADDRSTRLEN];
    2675             : 
    2676           0 :                 obuf[0] = '\0';
    2677           0 :                 evp = pu.evp;
    2678           0 :                 if (is_evpn_prefix_ipaddr_v4(evp))
    2679           0 :                         inet_ntop(AF_INET, &overlay_index->gw_ip, obuf,
    2680             :                                   sizeof(obuf));
    2681           0 :                 else if (is_evpn_prefix_ipaddr_v6(evp))
    2682           0 :                         inet_ntop(AF_INET6, &overlay_index->gw_ip, obuf,
    2683             :                                   sizeof(obuf));
    2684             : 
    2685           0 :                 snprintf(overlay_index_buf, sizeof(overlay_index_buf),
    2686             :                          " gateway IP %s", obuf);
    2687             :         }
    2688             : 
    2689           0 :         tag_buf[0] = '\0';
    2690           0 :         if (bgp_labeled_safi(safi) && num_labels) {
    2691             : 
    2692           0 :                 if (safi == SAFI_EVPN) {
    2693           0 :                         char tag_buf2[20];
    2694             : 
    2695           0 :                         bgp_evpn_label2str(label, num_labels, tag_buf2, 20);
    2696           0 :                         snprintf(tag_buf, sizeof(tag_buf), " label %s",
    2697             :                                  tag_buf2);
    2698             :                 } else {
    2699           0 :                         uint32_t label_value;
    2700             : 
    2701           0 :                         label_value = decode_label(label);
    2702           0 :                         snprintf(tag_buf, sizeof(tag_buf), " label %u",
    2703             :                                  label_value);
    2704             :                 }
    2705             :         }
    2706             : 
    2707           0 :         if (prd)
    2708           0 :                 snprintfrr(str, size, "RD %pRD %pFX%s%s%s %s %s", prd, pu.p,
    2709             :                            overlay_index_buf, tag_buf, pathid_buf, afi2str(afi),
    2710             :                            safi2str(safi));
    2711           0 :         else if (safi == SAFI_FLOWSPEC) {
    2712           0 :                 char return_string[BGP_FLOWSPEC_NLRI_STRING_MAX];
    2713           0 :                 const struct prefix_fs *fs = pu.fs;
    2714             : 
    2715           0 :                 bgp_fs_nlri_get_string((unsigned char *)fs->prefix.ptr,
    2716           0 :                                        fs->prefix.prefixlen,
    2717             :                                        return_string,
    2718             :                                        NLRI_STRING_FORMAT_DEBUG, NULL,
    2719           0 :                                        family2afi(fs->prefix.family));
    2720           0 :                 snprintf(str, size, "FS %s Match{%s}", afi2str(afi),
    2721             :                          return_string);
    2722             :         } else
    2723           0 :                 snprintfrr(str, size, "%pFX%s%s %s %s", pu.p, tag_buf,
    2724             :                            pathid_buf, afi2str(afi), safi2str(safi));
    2725             : 
    2726             :         return str;
    2727             : }

Generated by: LCOV version v1.16-topotato