Annotation of embedaddon/quagga/bgpd/bgp_debug.c, revision 1.1.1.2

1.1       misho       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
                     17: along with GNU Zebra; see the file COPYING.  If not, write to the Free
                     18: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
                     19: 02111-1307, USA.  */
                     20: 
                     21: #include <zebra.h>
                     22: 
                     23: #include <lib/version.h>
                     24: #include "prefix.h"
                     25: #include "linklist.h"
                     26: #include "stream.h"
                     27: #include "command.h"
                     28: #include "str.h"
                     29: #include "log.h"
                     30: #include "sockunion.h"
                     31: 
                     32: #include "bgpd/bgpd.h"
                     33: #include "bgpd/bgp_aspath.h"
                     34: #include "bgpd/bgp_route.h"
                     35: #include "bgpd/bgp_attr.h"
                     36: #include "bgpd/bgp_debug.h"
                     37: #include "bgpd/bgp_community.h"
                     38: 
                     39: unsigned long conf_bgp_debug_as4;
                     40: unsigned long conf_bgp_debug_fsm;
                     41: unsigned long conf_bgp_debug_events;
                     42: unsigned long conf_bgp_debug_packet;
                     43: unsigned long conf_bgp_debug_filter;
                     44: unsigned long conf_bgp_debug_keepalive;
                     45: unsigned long conf_bgp_debug_update;
                     46: unsigned long conf_bgp_debug_normal;
                     47: unsigned long conf_bgp_debug_zebra;
                     48: 
                     49: unsigned long term_bgp_debug_as4;
                     50: unsigned long term_bgp_debug_fsm;
                     51: unsigned long term_bgp_debug_events;
                     52: unsigned long term_bgp_debug_packet;
                     53: unsigned long term_bgp_debug_filter;
                     54: unsigned long term_bgp_debug_keepalive;
                     55: unsigned long term_bgp_debug_update;
                     56: unsigned long term_bgp_debug_normal;
                     57: unsigned long term_bgp_debug_zebra;
                     58: 
                     59: /* messages for BGP-4 status */
                     60: const struct message bgp_status_msg[] = 
                     61: {
                     62:   { Idle, "Idle" },
                     63:   { Connect, "Connect" },
                     64:   { Active, "Active" },
                     65:   { OpenSent, "OpenSent" },
                     66:   { OpenConfirm, "OpenConfirm" },
                     67:   { Established, "Established" },
                     68:   { Clearing,    "Clearing"    },
                     69:   { Deleted,     "Deleted"     },
                     70: };
                     71: const int bgp_status_msg_max = BGP_STATUS_MAX;
                     72: 
                     73: /* BGP message type string. */
                     74: const char *bgp_type_str[] =
                     75: {
                     76:   NULL,
                     77:   "OPEN",
                     78:   "UPDATE",
                     79:   "NOTIFICATION",
                     80:   "KEEPALIVE",
                     81:   "ROUTE-REFRESH",
                     82:   "CAPABILITY"
                     83: };
                     84: 
                     85: /* message for BGP-4 Notify */
                     86: static const struct message bgp_notify_msg[] = 
                     87: {
                     88:   { BGP_NOTIFY_HEADER_ERR, "Message Header Error"},
                     89:   { BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"},
                     90:   { BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"},
                     91:   { BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"},
                     92:   { BGP_NOTIFY_FSM_ERR, "Finite State Machine Error"},
                     93:   { BGP_NOTIFY_CEASE, "Cease"},
                     94:   { BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"},
                     95: };
                     96: static const int bgp_notify_msg_max = BGP_NOTIFY_MAX;
                     97: 
                     98: static const struct message bgp_notify_head_msg[] = 
                     99: {
                    100:   { BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized"},
                    101:   { BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length"},
                    102:   { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type"}
                    103: };
                    104: static const int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX;
                    105: 
                    106: static const struct message bgp_notify_open_msg[] = 
                    107: {
                    108:   { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
                    109:   { BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number" },
                    110:   { BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS"},
                    111:   { BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier"},
                    112:   { BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter"},
                    113:   { BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure"},
                    114:   { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time"}, 
                    115:   { BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability"},
                    116: };
                    117: static const int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX;
                    118: 
                    119: static const struct message bgp_notify_update_msg[] = 
                    120: {
                    121:   { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
                    122:   { BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List"},
                    123:   { BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute"},
                    124:   { BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute"},
                    125:   { BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error"},
                    126:   { BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error"},
                    127:   { BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute"},
                    128:   { BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP, "/AS Routing Loop"},
                    129:   { BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute"},
                    130:   { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error"},
                    131:   { BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field"},
                    132:   { BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH"},
                    133: };
                    134: static const int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX;
                    135: 
                    136: static const struct message bgp_notify_cease_msg[] =
                    137: {
                    138:   { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
                    139:   { BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached"},
                    140:   { BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administratively Shutdown"},
                    141:   { BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer Unconfigured"},
                    142:   { BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administratively Reset"},
                    143:   { BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected"},
                    144:   { BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change"},
                    145:   { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"},
                    146:   { BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"},
                    147: };
                    148: static const int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX;
                    149: 
                    150: static const struct message bgp_notify_capability_msg[] = 
                    151: {
                    152:   { BGP_NOTIFY_SUBCODE_UNSPECIFIC, "/Unspecific"},
                    153:   { BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" },
                    154:   { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"},
                    155:   { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"},
                    156: };
                    157: static const int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX;
                    158: 
                    159: /* Origin strings. */
                    160: const char *bgp_origin_str[] = {"i","e","?"};
                    161: const char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"};
                    162: 
                    163: /* Dump attribute. */
                    164: int
                    165: bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
                    166: {
                    167:   if (! attr)
                    168:     return 0;
                    169: 
                    170:   if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)))
                    171:     snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop));
                    172: 
                    173:   if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN)))
                    174:     snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s",
                    175:              bgp_origin_str[attr->origin]);
                    176: 
                    177: #ifdef HAVE_IPV6
                    178:   if (attr->extra)
                    179:     {
                    180:       char addrbuf[BUFSIZ];
                    181: 
                    182:       /* Add MP case. */
                    183:       if (attr->extra->mp_nexthop_len == 16 
                    184:           || attr->extra->mp_nexthop_len == 32)
                    185:         snprintf (buf + strlen (buf), size - strlen (buf), ", mp_nexthop %s",
                    186:                   inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global, 
                    187:                              addrbuf, BUFSIZ));
                    188: 
                    189:       if (attr->extra->mp_nexthop_len == 32)
                    190:         snprintf (buf + strlen (buf), size - strlen (buf), "(%s)",
                    191:                   inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local, 
                    192:                              addrbuf, BUFSIZ));
                    193:     }
                    194: #endif /* HAVE_IPV6 */
                    195: 
                    196:   if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF)))
1.1.1.2 ! misho     197:     snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %u",
1.1       misho     198:              attr->local_pref);
                    199: 
                    200:   if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))) 
1.1.1.2 ! misho     201:     snprintf (buf + strlen (buf), size - strlen (buf), ", metric %u",
1.1       misho     202:              attr->med);
                    203: 
                    204:   if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_COMMUNITIES))) 
                    205:     snprintf (buf + strlen (buf), size - strlen (buf), ", community %s",
                    206:              community_str (attr->community));
                    207: 
                    208:   if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE)))
                    209:     snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate");
                    210: 
                    211:   if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
                    212:     snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %u %s",
                    213:              attr->extra->aggregator_as,
                    214:              inet_ntoa (attr->extra->aggregator_addr));
                    215: 
                    216:   if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)))
                    217:     snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s",
                    218:              inet_ntoa (attr->extra->originator_id));
                    219: 
                    220:   if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST)))
                    221:     {
                    222:       int i;
                    223: 
                    224:       snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist");
                    225:       for (i = 0; i < attr->extra->cluster->length / 4; i++)
                    226:        snprintf (buf + strlen (buf), size - strlen (buf), " %s",
                    227:                  inet_ntoa (attr->extra->cluster->list[i]));
                    228:     }
                    229: 
                    230:   if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH))) 
                    231:     snprintf (buf + strlen (buf), size - strlen (buf), ", path %s",
                    232:              aspath_print (attr->aspath));
                    233: 
                    234:   if (strlen (buf) > 1)
                    235:     return 1;
                    236:   else
                    237:     return 0;
                    238: }
                    239: 
                    240: /* dump notify packet */
                    241: void
                    242: bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify, 
                    243:                  const char *direct)
                    244: {
                    245:   const char *subcode_str;
1.1.1.2 ! misho     246:   const char *code_str;
1.1       misho     247: 
                    248:   subcode_str = "";
1.1.1.2 ! misho     249:   code_str = LOOKUP_DEF (bgp_notify_msg, bgp_notify->code,
        !           250:                          "Unrecognized Error Code");
1.1       misho     251: 
1.1.1.2 ! misho     252:   switch (bgp_notify->code)
1.1       misho     253:     {
                    254:     case BGP_NOTIFY_HEADER_ERR:
1.1.1.2 ! misho     255:       subcode_str = LOOKUP_DEF (bgp_notify_head_msg, bgp_notify->subcode,
        !           256:                                 "Unrecognized Error Subcode");
1.1       misho     257:       break;
                    258:     case BGP_NOTIFY_OPEN_ERR:
1.1.1.2 ! misho     259:       subcode_str = LOOKUP_DEF (bgp_notify_open_msg, bgp_notify->subcode,
        !           260:                                 "Unrecognized Error Subcode");
1.1       misho     261:       break;
                    262:     case BGP_NOTIFY_UPDATE_ERR:
1.1.1.2 ! misho     263:       subcode_str = LOOKUP_DEF (bgp_notify_update_msg, bgp_notify->subcode,
        !           264:                                 "Unrecognized Error Subcode");
1.1       misho     265:       break;
                    266:     case BGP_NOTIFY_HOLD_ERR:
                    267:       break;
                    268:     case BGP_NOTIFY_FSM_ERR:
                    269:       break;
                    270:     case BGP_NOTIFY_CEASE:
1.1.1.2 ! misho     271:       subcode_str = LOOKUP_DEF (bgp_notify_cease_msg, bgp_notify->subcode,
        !           272:                                 "Unrecognized Error Subcode");
1.1       misho     273:       break;
                    274:     case BGP_NOTIFY_CAPABILITY_ERR:
1.1.1.2 ! misho     275:       subcode_str = LOOKUP_DEF (bgp_notify_capability_msg, bgp_notify->subcode,
        !           276:                                 "Unrecognized Error Subcode");
1.1       misho     277:       break;
                    278:     }
                    279: 
                    280:   if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
                    281:     zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
                    282:               strcmp (direct, "received") == 0 ? "received from" : "sent to",
                    283:               peer->host, bgp_notify->code, bgp_notify->subcode,
1.1.1.2 ! misho     284:               code_str, subcode_str, bgp_notify->length,
1.1       misho     285:               bgp_notify->data ? bgp_notify->data : "");
                    286:   else if (BGP_DEBUG (normal, NORMAL))
                    287:     plog_debug (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
                    288:               peer ? peer->host : "",
                    289:               direct, bgp_notify->code, bgp_notify->subcode,
1.1.1.2 ! misho     290:               code_str, subcode_str, bgp_notify->length,
1.1       misho     291:               bgp_notify->data ? bgp_notify->data : "");
                    292: }
                    293: 
                    294: /* Debug option setting interface. */
                    295: unsigned long bgp_debug_option = 0;
                    296: 
                    297: int  
                    298: debug (unsigned int option)
                    299: {
                    300:   return bgp_debug_option & option; 
                    301: }
                    302: 
                    303: DEFUN (debug_bgp_as4,
                    304:        debug_bgp_as4_cmd,
                    305:        "debug bgp as4",
                    306:        DEBUG_STR
                    307:        BGP_STR
                    308:        "BGP AS4 actions\n")
                    309: {
                    310:   if (vty->node == CONFIG_NODE)
                    311:     DEBUG_ON (as4, AS4);
                    312:   else
                    313:     {
                    314:       TERM_DEBUG_ON (as4, AS4);
                    315:       vty_out (vty, "BGP as4 debugging is on%s", VTY_NEWLINE);
                    316:     }
                    317:   return CMD_SUCCESS;
                    318: }
                    319: 
                    320: DEFUN (no_debug_bgp_as4,
                    321:        no_debug_bgp_as4_cmd,
                    322:        "no debug bgp as4",
                    323:        NO_STR
                    324:        DEBUG_STR
                    325:        BGP_STR
                    326:        "BGP AS4 actions\n")
                    327: {
                    328:   if (vty->node == CONFIG_NODE)
                    329:     DEBUG_OFF (as4, AS4);
                    330:   else
                    331:     {
                    332:       TERM_DEBUG_OFF (as4, AS4);
                    333:       vty_out (vty, "BGP as4 debugging is off%s", VTY_NEWLINE);
                    334:     }
                    335:   return CMD_SUCCESS;
                    336: }
                    337: 
                    338: ALIAS (no_debug_bgp_as4,
                    339:        undebug_bgp_as4_cmd,
                    340:        "undebug bgp as4",
                    341:        UNDEBUG_STR
                    342:        BGP_STR
                    343:        "BGP AS4 actions\n")
                    344: 
                    345: DEFUN (debug_bgp_as4_segment,
                    346:        debug_bgp_as4_segment_cmd,
                    347:        "debug bgp as4 segment",
                    348:        DEBUG_STR
                    349:        BGP_STR
                    350:        "BGP AS4 actions\n"
                    351:        "BGP AS4 aspath segment handling\n")
                    352: {
                    353:   if (vty->node == CONFIG_NODE)
                    354:     DEBUG_ON (as4, AS4_SEGMENT);
                    355:   else
                    356:     {
                    357:       TERM_DEBUG_ON (as4, AS4_SEGMENT);
                    358:       vty_out (vty, "BGP as4 segment debugging is on%s", VTY_NEWLINE);
                    359:     }
                    360:   return CMD_SUCCESS;
                    361: }
                    362: 
                    363: DEFUN (no_debug_bgp_as4_segment,
                    364:        no_debug_bgp_as4_segment_cmd,
                    365:        "no debug bgp as4 segment",
                    366:        NO_STR
                    367:        DEBUG_STR
                    368:        BGP_STR
                    369:        "BGP AS4 actions\n"
                    370:        "BGP AS4 aspath segment handling\n")
                    371: {
                    372:   if (vty->node == CONFIG_NODE)
                    373:     DEBUG_OFF (as4, AS4_SEGMENT);
                    374:   else
                    375:     {
                    376:       TERM_DEBUG_OFF (as4, AS4_SEGMENT);
                    377:       vty_out (vty, "BGP as4 segment debugging is off%s", VTY_NEWLINE);
                    378:     }
                    379:   return CMD_SUCCESS;
                    380: }
                    381: 
                    382: ALIAS (no_debug_bgp_as4_segment,
                    383:        undebug_bgp_as4_segment_cmd,
                    384:        "undebug bgp as4 segment",
                    385:        UNDEBUG_STR
                    386:        BGP_STR
                    387:        "BGP AS4 actions\n"
                    388:        "BGP AS4 aspath segment handling\n")
                    389: 
                    390: DEFUN (debug_bgp_fsm,
                    391:        debug_bgp_fsm_cmd,
                    392:        "debug bgp fsm",
                    393:        DEBUG_STR
                    394:        BGP_STR
                    395:        "BGP Finite State Machine\n")
                    396: {
                    397:   if (vty->node == CONFIG_NODE)
                    398:     DEBUG_ON (fsm, FSM);
                    399:   else
                    400:     {
                    401:       TERM_DEBUG_ON (fsm, FSM);
                    402:       vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE);
                    403:     }
                    404:   return CMD_SUCCESS;
                    405: }
                    406: 
                    407: DEFUN (no_debug_bgp_fsm,
                    408:        no_debug_bgp_fsm_cmd,
                    409:        "no debug bgp fsm",
                    410:        NO_STR
                    411:        DEBUG_STR
                    412:        BGP_STR
                    413:        "Finite State Machine\n")
                    414: {
                    415:   if (vty->node == CONFIG_NODE)
                    416:     DEBUG_OFF (fsm, FSM);
                    417:   else
                    418:     {
                    419:       TERM_DEBUG_OFF (fsm, FSM);
                    420:       vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE);
                    421:     }
                    422:   return CMD_SUCCESS;
                    423: }
                    424: 
                    425: ALIAS (no_debug_bgp_fsm,
                    426:        undebug_bgp_fsm_cmd,
                    427:        "undebug bgp fsm",
                    428:        UNDEBUG_STR
                    429:        BGP_STR
                    430:        "Finite State Machine\n")
                    431: 
                    432: DEFUN (debug_bgp_events,
                    433:        debug_bgp_events_cmd,
                    434:        "debug bgp events",
                    435:        DEBUG_STR
                    436:        BGP_STR
                    437:        "BGP events\n")
                    438: {
                    439:   if (vty->node == CONFIG_NODE)
                    440:     DEBUG_ON (events, EVENTS);
                    441:   else
                    442:     {
                    443:       TERM_DEBUG_ON (events, EVENTS);
                    444:       vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE);
                    445:     }
                    446:   return CMD_SUCCESS;
                    447: }
                    448: 
                    449: DEFUN (no_debug_bgp_events,
                    450:        no_debug_bgp_events_cmd,
                    451:        "no debug bgp events",
                    452:        NO_STR
                    453:        DEBUG_STR
                    454:        BGP_STR
                    455:        "BGP events\n")
                    456: {
                    457:   if (vty->node == CONFIG_NODE)
                    458:     DEBUG_OFF (events, EVENTS);
                    459:   else
                    460:     {
                    461:       TERM_DEBUG_OFF (events, EVENTS);
                    462:       vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE);
                    463:     }
                    464:   return CMD_SUCCESS;
                    465: }
                    466: 
                    467: ALIAS (no_debug_bgp_events,
                    468:        undebug_bgp_events_cmd,
                    469:        "undebug bgp events",
                    470:        UNDEBUG_STR
                    471:        BGP_STR
                    472:        "BGP events\n")
                    473: 
                    474: DEFUN (debug_bgp_filter,
                    475:        debug_bgp_filter_cmd,
                    476:        "debug bgp filters",
                    477:        DEBUG_STR
                    478:        BGP_STR
                    479:        "BGP filters\n")
                    480: {
                    481:   if (vty->node == CONFIG_NODE)
                    482:     DEBUG_ON (filter, FILTER);
                    483:   else
                    484:     {
                    485:       TERM_DEBUG_ON (filter, FILTER);
                    486:       vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE);
                    487:     }
                    488:   return CMD_SUCCESS;
                    489: }
                    490: 
                    491: DEFUN (no_debug_bgp_filter,
                    492:        no_debug_bgp_filter_cmd,
                    493:        "no debug bgp filters",
                    494:        NO_STR
                    495:        DEBUG_STR
                    496:        BGP_STR
                    497:        "BGP filters\n")
                    498: {
                    499:   if (vty->node == CONFIG_NODE)
                    500:     DEBUG_OFF (filter, FILTER);
                    501:   else
                    502:     {
                    503:       TERM_DEBUG_OFF (filter, FILTER);
                    504:       vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE);
                    505:     }
                    506:   return CMD_SUCCESS;
                    507: }
                    508: 
                    509: ALIAS (no_debug_bgp_filter,
                    510:        undebug_bgp_filter_cmd,
                    511:        "undebug bgp filters",
                    512:        UNDEBUG_STR
                    513:        BGP_STR
                    514:        "BGP filters\n")
                    515: 
                    516: DEFUN (debug_bgp_keepalive,
                    517:        debug_bgp_keepalive_cmd,
                    518:        "debug bgp keepalives",
                    519:        DEBUG_STR
                    520:        BGP_STR
                    521:        "BGP keepalives\n")
                    522: {
                    523:   if (vty->node == CONFIG_NODE)
                    524:     DEBUG_ON (keepalive, KEEPALIVE);
                    525:   else
                    526:     {
                    527:       TERM_DEBUG_ON (keepalive, KEEPALIVE);
                    528:       vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE);
                    529:     }
                    530:   return CMD_SUCCESS;
                    531: }
                    532: 
                    533: DEFUN (no_debug_bgp_keepalive,
                    534:        no_debug_bgp_keepalive_cmd,
                    535:        "no debug bgp keepalives",
                    536:        NO_STR
                    537:        DEBUG_STR
                    538:        BGP_STR
                    539:        "BGP keepalives\n")
                    540: {
                    541:   if (vty->node == CONFIG_NODE)
                    542:     DEBUG_OFF (keepalive, KEEPALIVE);
                    543:   else
                    544:     {
                    545:       TERM_DEBUG_OFF (keepalive, KEEPALIVE);
                    546:       vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE);
                    547:     }
                    548:   return CMD_SUCCESS;
                    549: }
                    550: 
                    551: ALIAS (no_debug_bgp_keepalive,
                    552:        undebug_bgp_keepalive_cmd,
                    553:        "undebug bgp keepalives",
                    554:        UNDEBUG_STR
                    555:        BGP_STR
                    556:        "BGP keepalives\n")
                    557: 
                    558: DEFUN (debug_bgp_update,
                    559:        debug_bgp_update_cmd,
                    560:        "debug bgp updates",
                    561:        DEBUG_STR
                    562:        BGP_STR
                    563:        "BGP updates\n")
                    564: {
                    565:   if (vty->node == CONFIG_NODE)
                    566:     {
                    567:       DEBUG_ON (update, UPDATE_IN);
                    568:       DEBUG_ON (update, UPDATE_OUT);
                    569:     }
                    570:   else
                    571:     {
                    572:       TERM_DEBUG_ON (update, UPDATE_IN);
                    573:       TERM_DEBUG_ON (update, UPDATE_OUT);
                    574:       vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE);
                    575:     }
                    576:   return CMD_SUCCESS;
                    577: }
                    578: 
                    579: DEFUN (debug_bgp_update_direct,
                    580:        debug_bgp_update_direct_cmd,
                    581:        "debug bgp updates (in|out)",
                    582:        DEBUG_STR
                    583:        BGP_STR
                    584:        "BGP updates\n"
                    585:        "Inbound updates\n"
                    586:        "Outbound updates\n")
                    587: {
                    588:   if (vty->node == CONFIG_NODE)
                    589:     {
                    590:       if (strncmp ("i", argv[0], 1) == 0)
                    591:        {
                    592:          DEBUG_OFF (update, UPDATE_OUT);
                    593:          DEBUG_ON (update, UPDATE_IN);
                    594:        }
                    595:       else
                    596:        {       
                    597:          DEBUG_OFF (update, UPDATE_IN);
                    598:          DEBUG_ON (update, UPDATE_OUT);
                    599:        }
                    600:     }
                    601:   else
                    602:     {
                    603:       if (strncmp ("i", argv[0], 1) == 0)
                    604:        {
                    605:          TERM_DEBUG_OFF (update, UPDATE_OUT);
                    606:          TERM_DEBUG_ON (update, UPDATE_IN);
                    607:          vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
                    608:        }
                    609:       else
                    610:        {
                    611:          TERM_DEBUG_OFF (update, UPDATE_IN);
                    612:          TERM_DEBUG_ON (update, UPDATE_OUT);
                    613:          vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
                    614:        }
                    615:     }
                    616:   return CMD_SUCCESS;
                    617: }
                    618: 
                    619: DEFUN (no_debug_bgp_update,
                    620:        no_debug_bgp_update_cmd,
                    621:        "no debug bgp updates",
                    622:        NO_STR
                    623:        DEBUG_STR
                    624:        BGP_STR
                    625:        "BGP updates\n")
                    626: {
                    627:   if (vty->node == CONFIG_NODE)
                    628:     {
                    629:       DEBUG_OFF (update, UPDATE_IN);
                    630:       DEBUG_OFF (update, UPDATE_OUT);
                    631:     }
                    632:   else
                    633:     {
                    634:       TERM_DEBUG_OFF (update, UPDATE_IN);
                    635:       TERM_DEBUG_OFF (update, UPDATE_OUT);
                    636:       vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE);
                    637:     }
                    638:   return CMD_SUCCESS;
                    639: }
                    640: 
                    641: ALIAS (no_debug_bgp_update,
                    642:        undebug_bgp_update_cmd,
                    643:        "undebug bgp updates",
                    644:        UNDEBUG_STR
                    645:        BGP_STR
                    646:        "BGP updates\n")
                    647: 
                    648: DEFUN (debug_bgp_normal,
                    649:        debug_bgp_normal_cmd,
                    650:        "debug bgp",
                    651:        DEBUG_STR
                    652:        BGP_STR)
                    653: {
                    654:   if (vty->node == CONFIG_NODE)
                    655:     DEBUG_ON (normal, NORMAL);
                    656:   else
                    657:     {
                    658:       TERM_DEBUG_ON (normal, NORMAL);
                    659:       vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE);
                    660:     }
                    661:   return CMD_SUCCESS;
                    662: }
                    663: 
                    664: DEFUN (no_debug_bgp_normal,
                    665:        no_debug_bgp_normal_cmd,
                    666:        "no debug bgp",
                    667:        NO_STR
                    668:        DEBUG_STR
                    669:        BGP_STR)
                    670: {
                    671:   if (vty->node == CONFIG_NODE)
                    672:     DEBUG_OFF (normal, NORMAL);
                    673:   else
                    674:     {
                    675:       TERM_DEBUG_OFF (normal, NORMAL);
                    676:       vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE);
                    677:     }
                    678:   return CMD_SUCCESS;
                    679: }
                    680: 
                    681: ALIAS (no_debug_bgp_normal,
                    682:        undebug_bgp_normal_cmd,
                    683:        "undebug bgp",
                    684:        UNDEBUG_STR
                    685:        BGP_STR)
                    686: 
                    687: DEFUN (debug_bgp_zebra,
                    688:        debug_bgp_zebra_cmd,
                    689:        "debug bgp zebra",
                    690:        DEBUG_STR
                    691:        BGP_STR
                    692:        "BGP Zebra messages\n")
                    693: {
                    694:   if (vty->node == CONFIG_NODE)
                    695:     DEBUG_ON (zebra, ZEBRA);
                    696:   else
                    697:     {
                    698:       TERM_DEBUG_ON (zebra, ZEBRA);
                    699:       vty_out (vty, "BGP zebra debugging is on%s", VTY_NEWLINE);
                    700:     }
                    701:   return CMD_SUCCESS;
                    702: }
                    703: 
                    704: DEFUN (no_debug_bgp_zebra,
                    705:        no_debug_bgp_zebra_cmd,
                    706:        "no debug bgp zebra",
                    707:        NO_STR
                    708:        DEBUG_STR
                    709:        BGP_STR
                    710:        "BGP Zebra messages\n")
                    711: {
                    712:   if (vty->node == CONFIG_NODE)
                    713:     DEBUG_OFF (zebra, ZEBRA);
                    714:   else
                    715:     {
                    716:       TERM_DEBUG_OFF (zebra, ZEBRA);
                    717:       vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE);
                    718:     }
                    719:   return CMD_SUCCESS;
                    720: }
                    721: 
                    722: ALIAS (no_debug_bgp_zebra,
                    723:        undebug_bgp_zebra_cmd,
                    724:        "undebug bgp zebra",
                    725:        UNDEBUG_STR
                    726:        BGP_STR
                    727:        "BGP Zebra messages\n")
                    728: 
                    729: DEFUN (no_debug_bgp_all,
                    730:        no_debug_bgp_all_cmd,
                    731:        "no debug all bgp",
                    732:        NO_STR
                    733:        DEBUG_STR
                    734:        "Enable all debugging\n"
                    735:        BGP_STR)
                    736: {
                    737:   TERM_DEBUG_OFF (normal, NORMAL);
                    738:   TERM_DEBUG_OFF (events, EVENTS);
                    739:   TERM_DEBUG_OFF (keepalive, KEEPALIVE);
                    740:   TERM_DEBUG_OFF (update, UPDATE_IN);
                    741:   TERM_DEBUG_OFF (update, UPDATE_OUT);
                    742:   TERM_DEBUG_OFF (as4, AS4);
                    743:   TERM_DEBUG_OFF (as4, AS4_SEGMENT);
                    744:   TERM_DEBUG_OFF (fsm, FSM);
                    745:   TERM_DEBUG_OFF (filter, FILTER);
                    746:   TERM_DEBUG_OFF (zebra, ZEBRA);
                    747:   vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE);
                    748:       
                    749:   return CMD_SUCCESS;
                    750: }
                    751: 
                    752: ALIAS (no_debug_bgp_all,
                    753:        undebug_bgp_all_cmd,
                    754:        "undebug all bgp",
                    755:        UNDEBUG_STR
                    756:        "Enable all debugging\n"
                    757:        BGP_STR)
                    758: 
                    759: DEFUN (show_debugging_bgp,
                    760:        show_debugging_bgp_cmd,
                    761:        "show debugging bgp",
                    762:        SHOW_STR
                    763:        DEBUG_STR
                    764:        BGP_STR)
                    765: {
                    766:   vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE);
                    767: 
                    768:   if (BGP_DEBUG (normal, NORMAL))
                    769:     vty_out (vty, "  BGP debugging is on%s", VTY_NEWLINE);
                    770:   if (BGP_DEBUG (events, EVENTS))
                    771:     vty_out (vty, "  BGP events debugging is on%s", VTY_NEWLINE);
                    772:   if (BGP_DEBUG (keepalive, KEEPALIVE))
                    773:     vty_out (vty, "  BGP keepalives debugging is on%s", VTY_NEWLINE);
                    774:   if (BGP_DEBUG (update, UPDATE_IN) && BGP_DEBUG (update, UPDATE_OUT))
                    775:     vty_out (vty, "  BGP updates debugging is on%s", VTY_NEWLINE);
                    776:   else if (BGP_DEBUG (update, UPDATE_IN))
                    777:     vty_out (vty, "  BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
                    778:   else if (BGP_DEBUG (update, UPDATE_OUT))
                    779:     vty_out (vty, "  BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
                    780:   if (BGP_DEBUG (fsm, FSM))
                    781:     vty_out (vty, "  BGP fsm debugging is on%s", VTY_NEWLINE);
                    782:   if (BGP_DEBUG (filter, FILTER))
                    783:     vty_out (vty, "  BGP filter debugging is on%s", VTY_NEWLINE);
                    784:   if (BGP_DEBUG (zebra, ZEBRA))
                    785:     vty_out (vty, "  BGP zebra debugging is on%s", VTY_NEWLINE);
                    786:   if (BGP_DEBUG (as4, AS4))
                    787:     vty_out (vty, "  BGP as4 debugging is on%s", VTY_NEWLINE);
                    788:   if (BGP_DEBUG (as4, AS4_SEGMENT))
                    789:     vty_out (vty, "  BGP as4 aspath segment debugging is on%s", VTY_NEWLINE);
                    790:   vty_out (vty, "%s", VTY_NEWLINE);
                    791:   return CMD_SUCCESS;
                    792: }
                    793: 
                    794: static int
                    795: bgp_config_write_debug (struct vty *vty)
                    796: {
                    797:   int write = 0;
                    798: 
                    799:   if (CONF_BGP_DEBUG (normal, NORMAL))
                    800:     {
                    801:       vty_out (vty, "debug bgp%s", VTY_NEWLINE);
                    802:       write++;
                    803:     }
                    804: 
                    805:   if (CONF_BGP_DEBUG (as4, AS4))
                    806:     {
                    807:       vty_out (vty, "debug bgp as4%s", VTY_NEWLINE);
                    808:       write++;
                    809:     }
                    810: 
                    811:   if (CONF_BGP_DEBUG (as4, AS4_SEGMENT))
                    812:     {
                    813:       vty_out (vty, "debug bgp as4 segment%s", VTY_NEWLINE);
                    814:       write++;
                    815:     }
                    816: 
                    817:   if (CONF_BGP_DEBUG (events, EVENTS))
                    818:     {
                    819:       vty_out (vty, "debug bgp events%s", VTY_NEWLINE);
                    820:       write++;
                    821:     }
                    822: 
                    823:   if (CONF_BGP_DEBUG (keepalive, KEEPALIVE))
                    824:     {
                    825:       vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE);
                    826:       write++;
                    827:     }
                    828: 
                    829:   if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT))
                    830:     {
                    831:       vty_out (vty, "debug bgp updates%s", VTY_NEWLINE);
                    832:       write++;
                    833:     }
                    834:   else if (CONF_BGP_DEBUG (update, UPDATE_IN))
                    835:     {
                    836:       vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE);
                    837:       write++;
                    838:     }
                    839:   else if (CONF_BGP_DEBUG (update, UPDATE_OUT))
                    840:     {
                    841:       vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE);
                    842:       write++;
                    843:     }
                    844: 
                    845:   if (CONF_BGP_DEBUG (fsm, FSM))
                    846:     {
                    847:       vty_out (vty, "debug bgp fsm%s", VTY_NEWLINE);
                    848:       write++;
                    849:     }
                    850: 
                    851:   if (CONF_BGP_DEBUG (filter, FILTER))
                    852:     {
                    853:       vty_out (vty, "debug bgp filters%s", VTY_NEWLINE);
                    854:       write++;
                    855:     }
                    856: 
                    857:   if (CONF_BGP_DEBUG (zebra, ZEBRA))
                    858:     {
                    859:       vty_out (vty, "debug bgp zebra%s", VTY_NEWLINE);
                    860:       write++;
                    861:     }
                    862: 
                    863:   return write;
                    864: }
                    865: 
                    866: static struct cmd_node debug_node =
                    867: {
                    868:   DEBUG_NODE,
                    869:   "",
                    870:   1
                    871: };
                    872: 
                    873: void
                    874: bgp_debug_init (void)
                    875: {
                    876:   install_node (&debug_node, bgp_config_write_debug);
                    877: 
                    878:   install_element (ENABLE_NODE, &show_debugging_bgp_cmd);
                    879: 
                    880:   install_element (ENABLE_NODE, &debug_bgp_as4_cmd);
                    881:   install_element (CONFIG_NODE, &debug_bgp_as4_cmd);
                    882:   install_element (ENABLE_NODE, &debug_bgp_as4_segment_cmd);
                    883:   install_element (CONFIG_NODE, &debug_bgp_as4_segment_cmd);
                    884: 
                    885:   install_element (ENABLE_NODE, &debug_bgp_fsm_cmd);
                    886:   install_element (CONFIG_NODE, &debug_bgp_fsm_cmd);
                    887:   install_element (ENABLE_NODE, &debug_bgp_events_cmd);
                    888:   install_element (CONFIG_NODE, &debug_bgp_events_cmd);
                    889:   install_element (ENABLE_NODE, &debug_bgp_filter_cmd);
                    890:   install_element (CONFIG_NODE, &debug_bgp_filter_cmd);
                    891:   install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd);
                    892:   install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd);
                    893:   install_element (ENABLE_NODE, &debug_bgp_update_cmd);
                    894:   install_element (CONFIG_NODE, &debug_bgp_update_cmd);
                    895:   install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd);
                    896:   install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd);
                    897:   install_element (ENABLE_NODE, &debug_bgp_normal_cmd);
                    898:   install_element (CONFIG_NODE, &debug_bgp_normal_cmd);
                    899:   install_element (ENABLE_NODE, &debug_bgp_zebra_cmd);
                    900:   install_element (CONFIG_NODE, &debug_bgp_zebra_cmd);
                    901: 
                    902:   install_element (ENABLE_NODE, &no_debug_bgp_as4_cmd);
                    903:   install_element (ENABLE_NODE, &undebug_bgp_as4_cmd);
                    904:   install_element (CONFIG_NODE, &no_debug_bgp_as4_cmd);
                    905:   install_element (ENABLE_NODE, &no_debug_bgp_as4_segment_cmd);
                    906:   install_element (ENABLE_NODE, &undebug_bgp_as4_segment_cmd);
                    907:   install_element (CONFIG_NODE, &no_debug_bgp_as4_segment_cmd);
                    908: 
                    909:   install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd);
                    910:   install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd);
                    911:   install_element (CONFIG_NODE, &no_debug_bgp_fsm_cmd);
                    912:   install_element (ENABLE_NODE, &no_debug_bgp_events_cmd);
                    913:   install_element (ENABLE_NODE, &undebug_bgp_events_cmd);
                    914:   install_element (CONFIG_NODE, &no_debug_bgp_events_cmd);
                    915:   install_element (ENABLE_NODE, &no_debug_bgp_filter_cmd);
                    916:   install_element (ENABLE_NODE, &undebug_bgp_filter_cmd);
                    917:   install_element (CONFIG_NODE, &no_debug_bgp_filter_cmd);
                    918:   install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
                    919:   install_element (ENABLE_NODE, &undebug_bgp_keepalive_cmd);
                    920:   install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
                    921:   install_element (ENABLE_NODE, &no_debug_bgp_update_cmd);
                    922:   install_element (ENABLE_NODE, &undebug_bgp_update_cmd);
                    923:   install_element (CONFIG_NODE, &no_debug_bgp_update_cmd);
                    924:   install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd);
                    925:   install_element (ENABLE_NODE, &undebug_bgp_normal_cmd);
                    926:   install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd);
                    927:   install_element (ENABLE_NODE, &no_debug_bgp_zebra_cmd);
                    928:   install_element (ENABLE_NODE, &undebug_bgp_zebra_cmd);
                    929:   install_element (CONFIG_NODE, &no_debug_bgp_zebra_cmd);
                    930:   install_element (ENABLE_NODE, &no_debug_bgp_all_cmd);
                    931:   install_element (ENABLE_NODE, &undebug_bgp_all_cmd);
                    932: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>