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

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)))
                    197:     snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %d",
                    198:              attr->local_pref);
                    199: 
                    200:   if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))) 
                    201:     snprintf (buf + strlen (buf), size - strlen (buf), ", metric %d",
                    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;
                    246: 
                    247:   subcode_str = "";
                    248: 
                    249:   switch (bgp_notify->code) 
                    250:     {
                    251:     case BGP_NOTIFY_HEADER_ERR:
                    252:       subcode_str = LOOKUP (bgp_notify_head_msg, bgp_notify->subcode);
                    253:       break;
                    254:     case BGP_NOTIFY_OPEN_ERR:
                    255:       subcode_str = LOOKUP (bgp_notify_open_msg, bgp_notify->subcode);
                    256:       break;
                    257:     case BGP_NOTIFY_UPDATE_ERR:
                    258:       subcode_str = LOOKUP (bgp_notify_update_msg, bgp_notify->subcode);
                    259:       break;
                    260:     case BGP_NOTIFY_HOLD_ERR:
                    261:       subcode_str = "";
                    262:       break;
                    263:     case BGP_NOTIFY_FSM_ERR:
                    264:       subcode_str = "";
                    265:       break;
                    266:     case BGP_NOTIFY_CEASE:
                    267:       subcode_str = LOOKUP (bgp_notify_cease_msg, bgp_notify->subcode);
                    268:       break;
                    269:     case BGP_NOTIFY_CAPABILITY_ERR:
                    270:       subcode_str = LOOKUP (bgp_notify_capability_msg, bgp_notify->subcode);
                    271:       break;
                    272:     }
                    273: 
                    274:   if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES))
                    275:     zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s",
                    276:               strcmp (direct, "received") == 0 ? "received from" : "sent to",
                    277:               peer->host, bgp_notify->code, bgp_notify->subcode,
                    278:                LOOKUP (bgp_notify_msg, bgp_notify->code),
                    279:               subcode_str, bgp_notify->length,
                    280:               bgp_notify->data ? bgp_notify->data : "");
                    281:   else if (BGP_DEBUG (normal, NORMAL))
                    282:     plog_debug (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s",
                    283:               peer ? peer->host : "",
                    284:               direct, bgp_notify->code, bgp_notify->subcode,
                    285:               LOOKUP (bgp_notify_msg, bgp_notify->code),
                    286:               subcode_str, bgp_notify->length,
                    287:               bgp_notify->data ? bgp_notify->data : "");
                    288: }
                    289: 
                    290: /* Debug option setting interface. */
                    291: unsigned long bgp_debug_option = 0;
                    292: 
                    293: int  
                    294: debug (unsigned int option)
                    295: {
                    296:   return bgp_debug_option & option; 
                    297: }
                    298: 
                    299: DEFUN (debug_bgp_as4,
                    300:        debug_bgp_as4_cmd,
                    301:        "debug bgp as4",
                    302:        DEBUG_STR
                    303:        BGP_STR
                    304:        "BGP AS4 actions\n")
                    305: {
                    306:   if (vty->node == CONFIG_NODE)
                    307:     DEBUG_ON (as4, AS4);
                    308:   else
                    309:     {
                    310:       TERM_DEBUG_ON (as4, AS4);
                    311:       vty_out (vty, "BGP as4 debugging is on%s", VTY_NEWLINE);
                    312:     }
                    313:   return CMD_SUCCESS;
                    314: }
                    315: 
                    316: DEFUN (no_debug_bgp_as4,
                    317:        no_debug_bgp_as4_cmd,
                    318:        "no debug bgp as4",
                    319:        NO_STR
                    320:        DEBUG_STR
                    321:        BGP_STR
                    322:        "BGP AS4 actions\n")
                    323: {
                    324:   if (vty->node == CONFIG_NODE)
                    325:     DEBUG_OFF (as4, AS4);
                    326:   else
                    327:     {
                    328:       TERM_DEBUG_OFF (as4, AS4);
                    329:       vty_out (vty, "BGP as4 debugging is off%s", VTY_NEWLINE);
                    330:     }
                    331:   return CMD_SUCCESS;
                    332: }
                    333: 
                    334: ALIAS (no_debug_bgp_as4,
                    335:        undebug_bgp_as4_cmd,
                    336:        "undebug bgp as4",
                    337:        UNDEBUG_STR
                    338:        BGP_STR
                    339:        "BGP AS4 actions\n")
                    340: 
                    341: DEFUN (debug_bgp_as4_segment,
                    342:        debug_bgp_as4_segment_cmd,
                    343:        "debug bgp as4 segment",
                    344:        DEBUG_STR
                    345:        BGP_STR
                    346:        "BGP AS4 actions\n"
                    347:        "BGP AS4 aspath segment handling\n")
                    348: {
                    349:   if (vty->node == CONFIG_NODE)
                    350:     DEBUG_ON (as4, AS4_SEGMENT);
                    351:   else
                    352:     {
                    353:       TERM_DEBUG_ON (as4, AS4_SEGMENT);
                    354:       vty_out (vty, "BGP as4 segment debugging is on%s", VTY_NEWLINE);
                    355:     }
                    356:   return CMD_SUCCESS;
                    357: }
                    358: 
                    359: DEFUN (no_debug_bgp_as4_segment,
                    360:        no_debug_bgp_as4_segment_cmd,
                    361:        "no debug bgp as4 segment",
                    362:        NO_STR
                    363:        DEBUG_STR
                    364:        BGP_STR
                    365:        "BGP AS4 actions\n"
                    366:        "BGP AS4 aspath segment handling\n")
                    367: {
                    368:   if (vty->node == CONFIG_NODE)
                    369:     DEBUG_OFF (as4, AS4_SEGMENT);
                    370:   else
                    371:     {
                    372:       TERM_DEBUG_OFF (as4, AS4_SEGMENT);
                    373:       vty_out (vty, "BGP as4 segment debugging is off%s", VTY_NEWLINE);
                    374:     }
                    375:   return CMD_SUCCESS;
                    376: }
                    377: 
                    378: ALIAS (no_debug_bgp_as4_segment,
                    379:        undebug_bgp_as4_segment_cmd,
                    380:        "undebug bgp as4 segment",
                    381:        UNDEBUG_STR
                    382:        BGP_STR
                    383:        "BGP AS4 actions\n"
                    384:        "BGP AS4 aspath segment handling\n")
                    385: 
                    386: DEFUN (debug_bgp_fsm,
                    387:        debug_bgp_fsm_cmd,
                    388:        "debug bgp fsm",
                    389:        DEBUG_STR
                    390:        BGP_STR
                    391:        "BGP Finite State Machine\n")
                    392: {
                    393:   if (vty->node == CONFIG_NODE)
                    394:     DEBUG_ON (fsm, FSM);
                    395:   else
                    396:     {
                    397:       TERM_DEBUG_ON (fsm, FSM);
                    398:       vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE);
                    399:     }
                    400:   return CMD_SUCCESS;
                    401: }
                    402: 
                    403: DEFUN (no_debug_bgp_fsm,
                    404:        no_debug_bgp_fsm_cmd,
                    405:        "no debug bgp fsm",
                    406:        NO_STR
                    407:        DEBUG_STR
                    408:        BGP_STR
                    409:        "Finite State Machine\n")
                    410: {
                    411:   if (vty->node == CONFIG_NODE)
                    412:     DEBUG_OFF (fsm, FSM);
                    413:   else
                    414:     {
                    415:       TERM_DEBUG_OFF (fsm, FSM);
                    416:       vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE);
                    417:     }
                    418:   return CMD_SUCCESS;
                    419: }
                    420: 
                    421: ALIAS (no_debug_bgp_fsm,
                    422:        undebug_bgp_fsm_cmd,
                    423:        "undebug bgp fsm",
                    424:        UNDEBUG_STR
                    425:        BGP_STR
                    426:        "Finite State Machine\n")
                    427: 
                    428: DEFUN (debug_bgp_events,
                    429:        debug_bgp_events_cmd,
                    430:        "debug bgp events",
                    431:        DEBUG_STR
                    432:        BGP_STR
                    433:        "BGP events\n")
                    434: {
                    435:   if (vty->node == CONFIG_NODE)
                    436:     DEBUG_ON (events, EVENTS);
                    437:   else
                    438:     {
                    439:       TERM_DEBUG_ON (events, EVENTS);
                    440:       vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE);
                    441:     }
                    442:   return CMD_SUCCESS;
                    443: }
                    444: 
                    445: DEFUN (no_debug_bgp_events,
                    446:        no_debug_bgp_events_cmd,
                    447:        "no debug bgp events",
                    448:        NO_STR
                    449:        DEBUG_STR
                    450:        BGP_STR
                    451:        "BGP events\n")
                    452: {
                    453:   if (vty->node == CONFIG_NODE)
                    454:     DEBUG_OFF (events, EVENTS);
                    455:   else
                    456:     {
                    457:       TERM_DEBUG_OFF (events, EVENTS);
                    458:       vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE);
                    459:     }
                    460:   return CMD_SUCCESS;
                    461: }
                    462: 
                    463: ALIAS (no_debug_bgp_events,
                    464:        undebug_bgp_events_cmd,
                    465:        "undebug bgp events",
                    466:        UNDEBUG_STR
                    467:        BGP_STR
                    468:        "BGP events\n")
                    469: 
                    470: DEFUN (debug_bgp_filter,
                    471:        debug_bgp_filter_cmd,
                    472:        "debug bgp filters",
                    473:        DEBUG_STR
                    474:        BGP_STR
                    475:        "BGP filters\n")
                    476: {
                    477:   if (vty->node == CONFIG_NODE)
                    478:     DEBUG_ON (filter, FILTER);
                    479:   else
                    480:     {
                    481:       TERM_DEBUG_ON (filter, FILTER);
                    482:       vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE);
                    483:     }
                    484:   return CMD_SUCCESS;
                    485: }
                    486: 
                    487: DEFUN (no_debug_bgp_filter,
                    488:        no_debug_bgp_filter_cmd,
                    489:        "no debug bgp filters",
                    490:        NO_STR
                    491:        DEBUG_STR
                    492:        BGP_STR
                    493:        "BGP filters\n")
                    494: {
                    495:   if (vty->node == CONFIG_NODE)
                    496:     DEBUG_OFF (filter, FILTER);
                    497:   else
                    498:     {
                    499:       TERM_DEBUG_OFF (filter, FILTER);
                    500:       vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE);
                    501:     }
                    502:   return CMD_SUCCESS;
                    503: }
                    504: 
                    505: ALIAS (no_debug_bgp_filter,
                    506:        undebug_bgp_filter_cmd,
                    507:        "undebug bgp filters",
                    508:        UNDEBUG_STR
                    509:        BGP_STR
                    510:        "BGP filters\n")
                    511: 
                    512: DEFUN (debug_bgp_keepalive,
                    513:        debug_bgp_keepalive_cmd,
                    514:        "debug bgp keepalives",
                    515:        DEBUG_STR
                    516:        BGP_STR
                    517:        "BGP keepalives\n")
                    518: {
                    519:   if (vty->node == CONFIG_NODE)
                    520:     DEBUG_ON (keepalive, KEEPALIVE);
                    521:   else
                    522:     {
                    523:       TERM_DEBUG_ON (keepalive, KEEPALIVE);
                    524:       vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE);
                    525:     }
                    526:   return CMD_SUCCESS;
                    527: }
                    528: 
                    529: DEFUN (no_debug_bgp_keepalive,
                    530:        no_debug_bgp_keepalive_cmd,
                    531:        "no debug bgp keepalives",
                    532:        NO_STR
                    533:        DEBUG_STR
                    534:        BGP_STR
                    535:        "BGP keepalives\n")
                    536: {
                    537:   if (vty->node == CONFIG_NODE)
                    538:     DEBUG_OFF (keepalive, KEEPALIVE);
                    539:   else
                    540:     {
                    541:       TERM_DEBUG_OFF (keepalive, KEEPALIVE);
                    542:       vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE);
                    543:     }
                    544:   return CMD_SUCCESS;
                    545: }
                    546: 
                    547: ALIAS (no_debug_bgp_keepalive,
                    548:        undebug_bgp_keepalive_cmd,
                    549:        "undebug bgp keepalives",
                    550:        UNDEBUG_STR
                    551:        BGP_STR
                    552:        "BGP keepalives\n")
                    553: 
                    554: DEFUN (debug_bgp_update,
                    555:        debug_bgp_update_cmd,
                    556:        "debug bgp updates",
                    557:        DEBUG_STR
                    558:        BGP_STR
                    559:        "BGP updates\n")
                    560: {
                    561:   if (vty->node == CONFIG_NODE)
                    562:     {
                    563:       DEBUG_ON (update, UPDATE_IN);
                    564:       DEBUG_ON (update, UPDATE_OUT);
                    565:     }
                    566:   else
                    567:     {
                    568:       TERM_DEBUG_ON (update, UPDATE_IN);
                    569:       TERM_DEBUG_ON (update, UPDATE_OUT);
                    570:       vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE);
                    571:     }
                    572:   return CMD_SUCCESS;
                    573: }
                    574: 
                    575: DEFUN (debug_bgp_update_direct,
                    576:        debug_bgp_update_direct_cmd,
                    577:        "debug bgp updates (in|out)",
                    578:        DEBUG_STR
                    579:        BGP_STR
                    580:        "BGP updates\n"
                    581:        "Inbound updates\n"
                    582:        "Outbound updates\n")
                    583: {
                    584:   if (vty->node == CONFIG_NODE)
                    585:     {
                    586:       if (strncmp ("i", argv[0], 1) == 0)
                    587:        {
                    588:          DEBUG_OFF (update, UPDATE_OUT);
                    589:          DEBUG_ON (update, UPDATE_IN);
                    590:        }
                    591:       else
                    592:        {       
                    593:          DEBUG_OFF (update, UPDATE_IN);
                    594:          DEBUG_ON (update, UPDATE_OUT);
                    595:        }
                    596:     }
                    597:   else
                    598:     {
                    599:       if (strncmp ("i", argv[0], 1) == 0)
                    600:        {
                    601:          TERM_DEBUG_OFF (update, UPDATE_OUT);
                    602:          TERM_DEBUG_ON (update, UPDATE_IN);
                    603:          vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
                    604:        }
                    605:       else
                    606:        {
                    607:          TERM_DEBUG_OFF (update, UPDATE_IN);
                    608:          TERM_DEBUG_ON (update, UPDATE_OUT);
                    609:          vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
                    610:        }
                    611:     }
                    612:   return CMD_SUCCESS;
                    613: }
                    614: 
                    615: DEFUN (no_debug_bgp_update,
                    616:        no_debug_bgp_update_cmd,
                    617:        "no debug bgp updates",
                    618:        NO_STR
                    619:        DEBUG_STR
                    620:        BGP_STR
                    621:        "BGP updates\n")
                    622: {
                    623:   if (vty->node == CONFIG_NODE)
                    624:     {
                    625:       DEBUG_OFF (update, UPDATE_IN);
                    626:       DEBUG_OFF (update, UPDATE_OUT);
                    627:     }
                    628:   else
                    629:     {
                    630:       TERM_DEBUG_OFF (update, UPDATE_IN);
                    631:       TERM_DEBUG_OFF (update, UPDATE_OUT);
                    632:       vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE);
                    633:     }
                    634:   return CMD_SUCCESS;
                    635: }
                    636: 
                    637: ALIAS (no_debug_bgp_update,
                    638:        undebug_bgp_update_cmd,
                    639:        "undebug bgp updates",
                    640:        UNDEBUG_STR
                    641:        BGP_STR
                    642:        "BGP updates\n")
                    643: 
                    644: DEFUN (debug_bgp_normal,
                    645:        debug_bgp_normal_cmd,
                    646:        "debug bgp",
                    647:        DEBUG_STR
                    648:        BGP_STR)
                    649: {
                    650:   if (vty->node == CONFIG_NODE)
                    651:     DEBUG_ON (normal, NORMAL);
                    652:   else
                    653:     {
                    654:       TERM_DEBUG_ON (normal, NORMAL);
                    655:       vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE);
                    656:     }
                    657:   return CMD_SUCCESS;
                    658: }
                    659: 
                    660: DEFUN (no_debug_bgp_normal,
                    661:        no_debug_bgp_normal_cmd,
                    662:        "no debug bgp",
                    663:        NO_STR
                    664:        DEBUG_STR
                    665:        BGP_STR)
                    666: {
                    667:   if (vty->node == CONFIG_NODE)
                    668:     DEBUG_OFF (normal, NORMAL);
                    669:   else
                    670:     {
                    671:       TERM_DEBUG_OFF (normal, NORMAL);
                    672:       vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE);
                    673:     }
                    674:   return CMD_SUCCESS;
                    675: }
                    676: 
                    677: ALIAS (no_debug_bgp_normal,
                    678:        undebug_bgp_normal_cmd,
                    679:        "undebug bgp",
                    680:        UNDEBUG_STR
                    681:        BGP_STR)
                    682: 
                    683: DEFUN (debug_bgp_zebra,
                    684:        debug_bgp_zebra_cmd,
                    685:        "debug bgp zebra",
                    686:        DEBUG_STR
                    687:        BGP_STR
                    688:        "BGP Zebra messages\n")
                    689: {
                    690:   if (vty->node == CONFIG_NODE)
                    691:     DEBUG_ON (zebra, ZEBRA);
                    692:   else
                    693:     {
                    694:       TERM_DEBUG_ON (zebra, ZEBRA);
                    695:       vty_out (vty, "BGP zebra debugging is on%s", VTY_NEWLINE);
                    696:     }
                    697:   return CMD_SUCCESS;
                    698: }
                    699: 
                    700: DEFUN (no_debug_bgp_zebra,
                    701:        no_debug_bgp_zebra_cmd,
                    702:        "no debug bgp zebra",
                    703:        NO_STR
                    704:        DEBUG_STR
                    705:        BGP_STR
                    706:        "BGP Zebra messages\n")
                    707: {
                    708:   if (vty->node == CONFIG_NODE)
                    709:     DEBUG_OFF (zebra, ZEBRA);
                    710:   else
                    711:     {
                    712:       TERM_DEBUG_OFF (zebra, ZEBRA);
                    713:       vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE);
                    714:     }
                    715:   return CMD_SUCCESS;
                    716: }
                    717: 
                    718: ALIAS (no_debug_bgp_zebra,
                    719:        undebug_bgp_zebra_cmd,
                    720:        "undebug bgp zebra",
                    721:        UNDEBUG_STR
                    722:        BGP_STR
                    723:        "BGP Zebra messages\n")
                    724: 
                    725: DEFUN (no_debug_bgp_all,
                    726:        no_debug_bgp_all_cmd,
                    727:        "no debug all bgp",
                    728:        NO_STR
                    729:        DEBUG_STR
                    730:        "Enable all debugging\n"
                    731:        BGP_STR)
                    732: {
                    733:   TERM_DEBUG_OFF (normal, NORMAL);
                    734:   TERM_DEBUG_OFF (events, EVENTS);
                    735:   TERM_DEBUG_OFF (keepalive, KEEPALIVE);
                    736:   TERM_DEBUG_OFF (update, UPDATE_IN);
                    737:   TERM_DEBUG_OFF (update, UPDATE_OUT);
                    738:   TERM_DEBUG_OFF (as4, AS4);
                    739:   TERM_DEBUG_OFF (as4, AS4_SEGMENT);
                    740:   TERM_DEBUG_OFF (fsm, FSM);
                    741:   TERM_DEBUG_OFF (filter, FILTER);
                    742:   TERM_DEBUG_OFF (zebra, ZEBRA);
                    743:   vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE);
                    744:       
                    745:   return CMD_SUCCESS;
                    746: }
                    747: 
                    748: ALIAS (no_debug_bgp_all,
                    749:        undebug_bgp_all_cmd,
                    750:        "undebug all bgp",
                    751:        UNDEBUG_STR
                    752:        "Enable all debugging\n"
                    753:        BGP_STR)
                    754: 
                    755: DEFUN (show_debugging_bgp,
                    756:        show_debugging_bgp_cmd,
                    757:        "show debugging bgp",
                    758:        SHOW_STR
                    759:        DEBUG_STR
                    760:        BGP_STR)
                    761: {
                    762:   vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE);
                    763: 
                    764:   if (BGP_DEBUG (normal, NORMAL))
                    765:     vty_out (vty, "  BGP debugging is on%s", VTY_NEWLINE);
                    766:   if (BGP_DEBUG (events, EVENTS))
                    767:     vty_out (vty, "  BGP events debugging is on%s", VTY_NEWLINE);
                    768:   if (BGP_DEBUG (keepalive, KEEPALIVE))
                    769:     vty_out (vty, "  BGP keepalives debugging is on%s", VTY_NEWLINE);
                    770:   if (BGP_DEBUG (update, UPDATE_IN) && BGP_DEBUG (update, UPDATE_OUT))
                    771:     vty_out (vty, "  BGP updates debugging is on%s", VTY_NEWLINE);
                    772:   else if (BGP_DEBUG (update, UPDATE_IN))
                    773:     vty_out (vty, "  BGP updates debugging is on (inbound)%s", VTY_NEWLINE);
                    774:   else if (BGP_DEBUG (update, UPDATE_OUT))
                    775:     vty_out (vty, "  BGP updates debugging is on (outbound)%s", VTY_NEWLINE);
                    776:   if (BGP_DEBUG (fsm, FSM))
                    777:     vty_out (vty, "  BGP fsm debugging is on%s", VTY_NEWLINE);
                    778:   if (BGP_DEBUG (filter, FILTER))
                    779:     vty_out (vty, "  BGP filter debugging is on%s", VTY_NEWLINE);
                    780:   if (BGP_DEBUG (zebra, ZEBRA))
                    781:     vty_out (vty, "  BGP zebra debugging is on%s", VTY_NEWLINE);
                    782:   if (BGP_DEBUG (as4, AS4))
                    783:     vty_out (vty, "  BGP as4 debugging is on%s", VTY_NEWLINE);
                    784:   if (BGP_DEBUG (as4, AS4_SEGMENT))
                    785:     vty_out (vty, "  BGP as4 aspath segment debugging is on%s", VTY_NEWLINE);
                    786:   vty_out (vty, "%s", VTY_NEWLINE);
                    787:   return CMD_SUCCESS;
                    788: }
                    789: 
                    790: static int
                    791: bgp_config_write_debug (struct vty *vty)
                    792: {
                    793:   int write = 0;
                    794: 
                    795:   if (CONF_BGP_DEBUG (normal, NORMAL))
                    796:     {
                    797:       vty_out (vty, "debug bgp%s", VTY_NEWLINE);
                    798:       write++;
                    799:     }
                    800: 
                    801:   if (CONF_BGP_DEBUG (as4, AS4))
                    802:     {
                    803:       vty_out (vty, "debug bgp as4%s", VTY_NEWLINE);
                    804:       write++;
                    805:     }
                    806: 
                    807:   if (CONF_BGP_DEBUG (as4, AS4_SEGMENT))
                    808:     {
                    809:       vty_out (vty, "debug bgp as4 segment%s", VTY_NEWLINE);
                    810:       write++;
                    811:     }
                    812: 
                    813:   if (CONF_BGP_DEBUG (events, EVENTS))
                    814:     {
                    815:       vty_out (vty, "debug bgp events%s", VTY_NEWLINE);
                    816:       write++;
                    817:     }
                    818: 
                    819:   if (CONF_BGP_DEBUG (keepalive, KEEPALIVE))
                    820:     {
                    821:       vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE);
                    822:       write++;
                    823:     }
                    824: 
                    825:   if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT))
                    826:     {
                    827:       vty_out (vty, "debug bgp updates%s", VTY_NEWLINE);
                    828:       write++;
                    829:     }
                    830:   else if (CONF_BGP_DEBUG (update, UPDATE_IN))
                    831:     {
                    832:       vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE);
                    833:       write++;
                    834:     }
                    835:   else if (CONF_BGP_DEBUG (update, UPDATE_OUT))
                    836:     {
                    837:       vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE);
                    838:       write++;
                    839:     }
                    840: 
                    841:   if (CONF_BGP_DEBUG (fsm, FSM))
                    842:     {
                    843:       vty_out (vty, "debug bgp fsm%s", VTY_NEWLINE);
                    844:       write++;
                    845:     }
                    846: 
                    847:   if (CONF_BGP_DEBUG (filter, FILTER))
                    848:     {
                    849:       vty_out (vty, "debug bgp filters%s", VTY_NEWLINE);
                    850:       write++;
                    851:     }
                    852: 
                    853:   if (CONF_BGP_DEBUG (zebra, ZEBRA))
                    854:     {
                    855:       vty_out (vty, "debug bgp zebra%s", VTY_NEWLINE);
                    856:       write++;
                    857:     }
                    858: 
                    859:   return write;
                    860: }
                    861: 
                    862: static struct cmd_node debug_node =
                    863: {
                    864:   DEBUG_NODE,
                    865:   "",
                    866:   1
                    867: };
                    868: 
                    869: void
                    870: bgp_debug_init (void)
                    871: {
                    872:   install_node (&debug_node, bgp_config_write_debug);
                    873: 
                    874:   install_element (ENABLE_NODE, &show_debugging_bgp_cmd);
                    875: 
                    876:   install_element (ENABLE_NODE, &debug_bgp_as4_cmd);
                    877:   install_element (CONFIG_NODE, &debug_bgp_as4_cmd);
                    878:   install_element (ENABLE_NODE, &debug_bgp_as4_segment_cmd);
                    879:   install_element (CONFIG_NODE, &debug_bgp_as4_segment_cmd);
                    880: 
                    881:   install_element (ENABLE_NODE, &debug_bgp_fsm_cmd);
                    882:   install_element (CONFIG_NODE, &debug_bgp_fsm_cmd);
                    883:   install_element (ENABLE_NODE, &debug_bgp_events_cmd);
                    884:   install_element (CONFIG_NODE, &debug_bgp_events_cmd);
                    885:   install_element (ENABLE_NODE, &debug_bgp_filter_cmd);
                    886:   install_element (CONFIG_NODE, &debug_bgp_filter_cmd);
                    887:   install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd);
                    888:   install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd);
                    889:   install_element (ENABLE_NODE, &debug_bgp_update_cmd);
                    890:   install_element (CONFIG_NODE, &debug_bgp_update_cmd);
                    891:   install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd);
                    892:   install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd);
                    893:   install_element (ENABLE_NODE, &debug_bgp_normal_cmd);
                    894:   install_element (CONFIG_NODE, &debug_bgp_normal_cmd);
                    895:   install_element (ENABLE_NODE, &debug_bgp_zebra_cmd);
                    896:   install_element (CONFIG_NODE, &debug_bgp_zebra_cmd);
                    897: 
                    898:   install_element (ENABLE_NODE, &no_debug_bgp_as4_cmd);
                    899:   install_element (ENABLE_NODE, &undebug_bgp_as4_cmd);
                    900:   install_element (CONFIG_NODE, &no_debug_bgp_as4_cmd);
                    901:   install_element (ENABLE_NODE, &no_debug_bgp_as4_segment_cmd);
                    902:   install_element (ENABLE_NODE, &undebug_bgp_as4_segment_cmd);
                    903:   install_element (CONFIG_NODE, &no_debug_bgp_as4_segment_cmd);
                    904: 
                    905:   install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd);
                    906:   install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd);
                    907:   install_element (CONFIG_NODE, &no_debug_bgp_fsm_cmd);
                    908:   install_element (ENABLE_NODE, &no_debug_bgp_events_cmd);
                    909:   install_element (ENABLE_NODE, &undebug_bgp_events_cmd);
                    910:   install_element (CONFIG_NODE, &no_debug_bgp_events_cmd);
                    911:   install_element (ENABLE_NODE, &no_debug_bgp_filter_cmd);
                    912:   install_element (ENABLE_NODE, &undebug_bgp_filter_cmd);
                    913:   install_element (CONFIG_NODE, &no_debug_bgp_filter_cmd);
                    914:   install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd);
                    915:   install_element (ENABLE_NODE, &undebug_bgp_keepalive_cmd);
                    916:   install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd);
                    917:   install_element (ENABLE_NODE, &no_debug_bgp_update_cmd);
                    918:   install_element (ENABLE_NODE, &undebug_bgp_update_cmd);
                    919:   install_element (CONFIG_NODE, &no_debug_bgp_update_cmd);
                    920:   install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd);
                    921:   install_element (ENABLE_NODE, &undebug_bgp_normal_cmd);
                    922:   install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd);
                    923:   install_element (ENABLE_NODE, &no_debug_bgp_zebra_cmd);
                    924:   install_element (ENABLE_NODE, &undebug_bgp_zebra_cmd);
                    925:   install_element (CONFIG_NODE, &no_debug_bgp_zebra_cmd);
                    926:   install_element (ENABLE_NODE, &no_debug_bgp_all_cmd);
                    927:   install_element (ENABLE_NODE, &undebug_bgp_all_cmd);
                    928: }

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