paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame^] | 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 "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_fsm; |
| 40 | unsigned long conf_bgp_debug_events; |
| 41 | unsigned long conf_bgp_debug_packet; |
| 42 | unsigned long conf_bgp_debug_filter; |
| 43 | unsigned long conf_bgp_debug_keepalive; |
| 44 | unsigned long conf_bgp_debug_update; |
| 45 | unsigned long conf_bgp_debug_normal; |
| 46 | |
| 47 | unsigned long term_bgp_debug_fsm; |
| 48 | unsigned long term_bgp_debug_events; |
| 49 | unsigned long term_bgp_debug_packet; |
| 50 | unsigned long term_bgp_debug_filter; |
| 51 | unsigned long term_bgp_debug_keepalive; |
| 52 | unsigned long term_bgp_debug_update; |
| 53 | unsigned long term_bgp_debug_normal; |
| 54 | |
| 55 | /* messages for BGP-4 status */ |
| 56 | struct message bgp_status_msg[] = |
| 57 | { |
| 58 | { 0, "null" }, |
| 59 | { Idle, "Idle" }, |
| 60 | { Connect, "Connect" }, |
| 61 | { Active, "Active" }, |
| 62 | { OpenSent, "OpenSent" }, |
| 63 | { OpenConfirm, "OpenConfirm" }, |
| 64 | { Established, "Established" }, |
| 65 | }; |
| 66 | int bgp_status_msg_max = BGP_STATUS_MAX; |
| 67 | |
| 68 | /* BGP message type string. */ |
| 69 | char *bgp_type_str[] = |
| 70 | { |
| 71 | NULL, |
| 72 | "OPEN", |
| 73 | "UPDATE", |
| 74 | "NOTIFICATION", |
| 75 | "KEEPALIVE", |
| 76 | "ROUTE-REFRESH", |
| 77 | "CAPABILITY" |
| 78 | }; |
| 79 | |
| 80 | /* message for BGP-4 Notify */ |
| 81 | struct message bgp_notify_msg[] = |
| 82 | { |
| 83 | { 0, "" }, |
| 84 | { BGP_NOTIFY_HEADER_ERR, "Message Header Error"}, |
| 85 | { BGP_NOTIFY_OPEN_ERR, "OPEN Message Error"}, |
| 86 | { BGP_NOTIFY_UPDATE_ERR, "UPDATE Message Error"}, |
| 87 | { BGP_NOTIFY_HOLD_ERR, "Hold Timer Expired"}, |
| 88 | { BGP_NOTIFY_FSM_ERR, "Finite State Machine Error"}, |
| 89 | { BGP_NOTIFY_CEASE, "Cease"}, |
| 90 | { BGP_NOTIFY_CAPABILITY_ERR, "CAPABILITY Message Error"}, |
| 91 | }; |
| 92 | int bgp_notify_msg_max = BGP_NOTIFY_MAX; |
| 93 | |
| 94 | struct message bgp_notify_head_msg[] = |
| 95 | { |
| 96 | { 0, "null"}, |
| 97 | { BGP_NOTIFY_HEADER_NOT_SYNC, "/Connection Not Synchronized."}, |
| 98 | { BGP_NOTIFY_HEADER_BAD_MESLEN, "/Bad Message Length."}, |
| 99 | { BGP_NOTIFY_HEADER_BAD_MESTYPE, "/Bad Message Type."} |
| 100 | }; |
| 101 | int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX; |
| 102 | |
| 103 | struct message bgp_notify_open_msg[] = |
| 104 | { |
| 105 | { 0, "null" }, |
| 106 | { BGP_NOTIFY_OPEN_UNSUP_VERSION, "/Unsupported Version Number." }, |
| 107 | { BGP_NOTIFY_OPEN_BAD_PEER_AS, "/Bad Peer AS."}, |
| 108 | { BGP_NOTIFY_OPEN_BAD_BGP_IDENT, "/Bad BGP Identifier."}, |
| 109 | { BGP_NOTIFY_OPEN_UNSUP_PARAM, "/Unsupported Optional Parameter."}, |
| 110 | { BGP_NOTIFY_OPEN_AUTH_FAILURE, "/Authentication Failure."}, |
| 111 | { BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, "/Unacceptable Hold Time."}, |
| 112 | { BGP_NOTIFY_OPEN_UNSUP_CAPBL, "/Unsupported Capability."}, |
| 113 | }; |
| 114 | int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX; |
| 115 | |
| 116 | struct message bgp_notify_update_msg[] = |
| 117 | { |
| 118 | { 0, "null"}, |
| 119 | { BGP_NOTIFY_UPDATE_MAL_ATTR, "/Malformed Attribute List."}, |
| 120 | { BGP_NOTIFY_UPDATE_UNREC_ATTR, "/Unrecognized Well-known Attribute."}, |
| 121 | { BGP_NOTIFY_UPDATE_MISS_ATTR, "/Missing Well-known Attribute."}, |
| 122 | { BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR, "/Attribute Flags Error."}, |
| 123 | { BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, "/Attribute Length Error."}, |
| 124 | { BGP_NOTIFY_UPDATE_INVAL_ORIGIN, "/Invalid ORIGIN Attribute."}, |
| 125 | { BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP, "/AS Routing Loop."}, |
| 126 | { BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, "/Invalid NEXT_HOP Attribute."}, |
| 127 | { BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, "/Optional Attribute Error."}, |
| 128 | { BGP_NOTIFY_UPDATE_INVAL_NETWORK, "/Invalid Network Field."}, |
| 129 | { BGP_NOTIFY_UPDATE_MAL_AS_PATH, "/Malformed AS_PATH."}, |
| 130 | }; |
| 131 | int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX; |
| 132 | |
| 133 | struct message bgp_notify_cease_msg[] = |
| 134 | { |
| 135 | { 0, ""}, |
| 136 | { BGP_NOTIFY_CEASE_MAX_PREFIX, "/Maximum Number of Prefixes Reached."}, |
| 137 | { BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN, "/Administratively Shutdown."}, |
| 138 | { BGP_NOTIFY_CEASE_PEER_UNCONFIG, "/Peer Unconfigured."}, |
| 139 | { BGP_NOTIFY_CEASE_ADMIN_RESET, "/Administratively Reset."}, |
| 140 | { BGP_NOTIFY_CEASE_CONNECT_REJECT, "/Connection Rejected."}, |
| 141 | { BGP_NOTIFY_CEASE_CONFIG_CHANGE, "/Other Configuration Change."}, |
| 142 | }; |
| 143 | int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX; |
| 144 | |
| 145 | struct message bgp_notify_capability_msg[] = |
| 146 | { |
| 147 | { 0, "null" }, |
| 148 | { BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value." }, |
| 149 | { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length."}, |
| 150 | { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value."}, |
| 151 | }; |
| 152 | int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX; |
| 153 | |
| 154 | /* Origin strings. */ |
| 155 | char *bgp_origin_str[] = {"i","e","?"}; |
| 156 | char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"}; |
| 157 | |
| 158 | /* Dump attribute. */ |
| 159 | void |
| 160 | bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size) |
| 161 | { |
| 162 | |
| 163 | if (! attr) |
| 164 | return; |
| 165 | |
| 166 | snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop)); |
| 167 | snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s", |
| 168 | bgp_origin_str[attr->origin]); |
| 169 | |
| 170 | #ifdef HAVE_IPV6 |
| 171 | { |
| 172 | char addrbuf[BUFSIZ]; |
| 173 | |
| 174 | /* Add MP case. */ |
| 175 | if (attr->mp_nexthop_len == 16 || attr->mp_nexthop_len == 32) |
| 176 | snprintf (buf + strlen (buf), size - strlen (buf), ", mp_nexthop %s", |
| 177 | inet_ntop (AF_INET6, &attr->mp_nexthop_global, |
| 178 | addrbuf, BUFSIZ)); |
| 179 | |
| 180 | if (attr->mp_nexthop_len == 32) |
| 181 | snprintf (buf + strlen (buf), size - strlen (buf), "(%s)", |
| 182 | inet_ntop (AF_INET6, &attr->mp_nexthop_local, |
| 183 | addrbuf, BUFSIZ)); |
| 184 | } |
| 185 | #endif /* HAVE_IPV6 */ |
| 186 | |
| 187 | if (peer_sort (peer) == BGP_PEER_IBGP) |
| 188 | snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %d", |
| 189 | attr->local_pref); |
| 190 | |
| 191 | if (attr->med) |
| 192 | snprintf (buf + strlen (buf), size - strlen (buf), ", metric %d", |
| 193 | attr->med); |
| 194 | |
| 195 | if (attr->community) |
| 196 | snprintf (buf + strlen (buf), size - strlen (buf), ", community %s", |
| 197 | community_str (attr->community)); |
| 198 | |
| 199 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) |
| 200 | snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate"); |
| 201 | |
| 202 | if (attr->aggregator_as) |
| 203 | snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %d %s", |
| 204 | attr->aggregator_as, inet_ntoa (attr->aggregator_addr)); |
| 205 | |
| 206 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)) |
| 207 | snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s", |
| 208 | inet_ntoa (attr->originator_id)); |
| 209 | |
| 210 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST)) |
| 211 | { |
| 212 | int i; |
| 213 | |
| 214 | snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist "); |
| 215 | for (i = 0; i < attr->cluster->length / 4; i++) |
| 216 | snprintf (buf + strlen (buf), size - strlen (buf), "%s", |
| 217 | inet_ntoa (attr->cluster->list[i])); |
| 218 | } |
| 219 | |
| 220 | if (attr->aspath) |
| 221 | snprintf (buf + strlen (buf), size - strlen (buf), ", path %s", |
| 222 | aspath_print (attr->aspath)); |
| 223 | } |
| 224 | |
| 225 | /* dump notify packet */ |
| 226 | void |
| 227 | bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify, char *direct) |
| 228 | { |
| 229 | char *subcode_str; |
| 230 | |
| 231 | subcode_str = ""; |
| 232 | |
| 233 | switch (bgp_notify->code) |
| 234 | { |
| 235 | case BGP_NOTIFY_HEADER_ERR: |
| 236 | subcode_str = LOOKUP (bgp_notify_head_msg, bgp_notify->subcode); |
| 237 | break; |
| 238 | case BGP_NOTIFY_OPEN_ERR: |
| 239 | subcode_str = LOOKUP (bgp_notify_open_msg, bgp_notify->subcode); |
| 240 | break; |
| 241 | case BGP_NOTIFY_UPDATE_ERR: |
| 242 | subcode_str = LOOKUP (bgp_notify_update_msg, bgp_notify->subcode); |
| 243 | break; |
| 244 | case BGP_NOTIFY_HOLD_ERR: |
| 245 | subcode_str = ""; |
| 246 | break; |
| 247 | case BGP_NOTIFY_FSM_ERR: |
| 248 | subcode_str = ""; |
| 249 | break; |
| 250 | case BGP_NOTIFY_CEASE: |
| 251 | subcode_str = LOOKUP (bgp_notify_cease_msg, bgp_notify->subcode); |
| 252 | break; |
| 253 | case BGP_NOTIFY_CAPABILITY_ERR: |
| 254 | subcode_str = LOOKUP (bgp_notify_capability_msg, bgp_notify->subcode); |
| 255 | break; |
| 256 | } |
| 257 | if (BGP_DEBUG (normal, NORMAL)) |
| 258 | plog_info (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s", |
| 259 | peer ? peer->host : "", |
| 260 | direct, bgp_notify->code, bgp_notify->subcode, |
| 261 | LOOKUP (bgp_notify_msg, bgp_notify->code), |
| 262 | subcode_str, bgp_notify->length, |
| 263 | bgp_notify->data ? bgp_notify->data : ""); |
| 264 | } |
| 265 | |
| 266 | /* Debug option setting interface. */ |
| 267 | unsigned long bgp_debug_option = 0; |
| 268 | |
| 269 | int |
| 270 | debug (unsigned int option) |
| 271 | { |
| 272 | return bgp_debug_option & option; |
| 273 | } |
| 274 | |
| 275 | DEFUN (debug_bgp_fsm, |
| 276 | debug_bgp_fsm_cmd, |
| 277 | "debug bgp fsm", |
| 278 | DEBUG_STR |
| 279 | BGP_STR |
| 280 | "BGP Finite State Machine\n") |
| 281 | { |
| 282 | if (vty->node == CONFIG_NODE) |
| 283 | DEBUG_ON (fsm, FSM); |
| 284 | else |
| 285 | { |
| 286 | TERM_DEBUG_ON (fsm, FSM); |
| 287 | vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE); |
| 288 | } |
| 289 | return CMD_SUCCESS; |
| 290 | } |
| 291 | |
| 292 | DEFUN (no_debug_bgp_fsm, |
| 293 | no_debug_bgp_fsm_cmd, |
| 294 | "no debug bgp fsm", |
| 295 | NO_STR |
| 296 | DEBUG_STR |
| 297 | BGP_STR |
| 298 | "Finite State Machine\n") |
| 299 | { |
| 300 | if (vty->node == CONFIG_NODE) |
| 301 | DEBUG_OFF (fsm, FSM); |
| 302 | else |
| 303 | { |
| 304 | TERM_DEBUG_OFF (fsm, FSM); |
| 305 | vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE); |
| 306 | } |
| 307 | return CMD_SUCCESS; |
| 308 | } |
| 309 | |
| 310 | ALIAS (no_debug_bgp_fsm, |
| 311 | undebug_bgp_fsm_cmd, |
| 312 | "undebug bgp fsm", |
| 313 | UNDEBUG_STR |
| 314 | DEBUG_STR |
| 315 | BGP_STR |
| 316 | "Finite State Machine\n") |
| 317 | |
| 318 | DEFUN (debug_bgp_events, |
| 319 | debug_bgp_events_cmd, |
| 320 | "debug bgp events", |
| 321 | DEBUG_STR |
| 322 | BGP_STR |
| 323 | "BGP events\n") |
| 324 | { |
| 325 | if (vty->node == CONFIG_NODE) |
| 326 | DEBUG_ON (events, EVENTS); |
| 327 | else |
| 328 | { |
| 329 | TERM_DEBUG_ON (events, EVENTS); |
| 330 | vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE); |
| 331 | } |
| 332 | return CMD_SUCCESS; |
| 333 | } |
| 334 | |
| 335 | DEFUN (no_debug_bgp_events, |
| 336 | no_debug_bgp_events_cmd, |
| 337 | "no debug bgp events", |
| 338 | NO_STR |
| 339 | DEBUG_STR |
| 340 | BGP_STR |
| 341 | "BGP events\n") |
| 342 | { |
| 343 | if (vty->node == CONFIG_NODE) |
| 344 | DEBUG_OFF (events, EVENTS); |
| 345 | else |
| 346 | { |
| 347 | TERM_DEBUG_OFF (events, EVENTS); |
| 348 | vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE); |
| 349 | } |
| 350 | return CMD_SUCCESS; |
| 351 | } |
| 352 | |
| 353 | ALIAS (no_debug_bgp_events, |
| 354 | undebug_bgp_events_cmd, |
| 355 | "undebug bgp events", |
| 356 | UNDEBUG_STR |
| 357 | BGP_STR |
| 358 | "BGP events\n") |
| 359 | |
| 360 | DEFUN (debug_bgp_filter, |
| 361 | debug_bgp_filter_cmd, |
| 362 | "debug bgp filters", |
| 363 | DEBUG_STR |
| 364 | BGP_STR |
| 365 | "BGP filters\n") |
| 366 | { |
| 367 | if (vty->node == CONFIG_NODE) |
| 368 | DEBUG_ON (filter, FILTER); |
| 369 | else |
| 370 | { |
| 371 | TERM_DEBUG_ON (filter, FILTER); |
| 372 | vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE); |
| 373 | } |
| 374 | return CMD_SUCCESS; |
| 375 | } |
| 376 | |
| 377 | DEFUN (no_debug_bgp_filter, |
| 378 | no_debug_bgp_filter_cmd, |
| 379 | "no debug bgp filters", |
| 380 | NO_STR |
| 381 | DEBUG_STR |
| 382 | BGP_STR |
| 383 | "BGP filters\n") |
| 384 | { |
| 385 | if (vty->node == CONFIG_NODE) |
| 386 | DEBUG_OFF (filter, FILTER); |
| 387 | else |
| 388 | { |
| 389 | TERM_DEBUG_OFF (filter, FILTER); |
| 390 | vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE); |
| 391 | } |
| 392 | return CMD_SUCCESS; |
| 393 | } |
| 394 | |
| 395 | ALIAS (no_debug_bgp_filter, |
| 396 | undebug_bgp_filter_cmd, |
| 397 | "undebug bgp filters", |
| 398 | UNDEBUG_STR |
| 399 | BGP_STR |
| 400 | "BGP filters\n") |
| 401 | |
| 402 | DEFUN (debug_bgp_keepalive, |
| 403 | debug_bgp_keepalive_cmd, |
| 404 | "debug bgp keepalives", |
| 405 | DEBUG_STR |
| 406 | BGP_STR |
| 407 | "BGP keepalives\n") |
| 408 | { |
| 409 | if (vty->node == CONFIG_NODE) |
| 410 | DEBUG_ON (keepalive, KEEPALIVE); |
| 411 | else |
| 412 | { |
| 413 | TERM_DEBUG_ON (keepalive, KEEPALIVE); |
| 414 | vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE); |
| 415 | } |
| 416 | return CMD_SUCCESS; |
| 417 | } |
| 418 | |
| 419 | DEFUN (no_debug_bgp_keepalive, |
| 420 | no_debug_bgp_keepalive_cmd, |
| 421 | "no debug bgp keepalives", |
| 422 | NO_STR |
| 423 | DEBUG_STR |
| 424 | BGP_STR |
| 425 | "BGP keepalives\n") |
| 426 | { |
| 427 | if (vty->node == CONFIG_NODE) |
| 428 | DEBUG_OFF (keepalive, KEEPALIVE); |
| 429 | else |
| 430 | { |
| 431 | TERM_DEBUG_OFF (keepalive, KEEPALIVE); |
| 432 | vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE); |
| 433 | } |
| 434 | return CMD_SUCCESS; |
| 435 | } |
| 436 | |
| 437 | ALIAS (no_debug_bgp_keepalive, |
| 438 | undebug_bgp_keepalive_cmd, |
| 439 | "undebug bgp keepalives", |
| 440 | UNDEBUG_STR |
| 441 | BGP_STR |
| 442 | "BGP keepalives\n") |
| 443 | |
| 444 | DEFUN (debug_bgp_update, |
| 445 | debug_bgp_update_cmd, |
| 446 | "debug bgp updates", |
| 447 | DEBUG_STR |
| 448 | BGP_STR |
| 449 | "BGP updates\n") |
| 450 | { |
| 451 | if (vty->node == CONFIG_NODE) |
| 452 | { |
| 453 | DEBUG_ON (update, UPDATE_IN); |
| 454 | DEBUG_ON (update, UPDATE_OUT); |
| 455 | } |
| 456 | else |
| 457 | { |
| 458 | TERM_DEBUG_ON (update, UPDATE_IN); |
| 459 | TERM_DEBUG_ON (update, UPDATE_OUT); |
| 460 | vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE); |
| 461 | } |
| 462 | return CMD_SUCCESS; |
| 463 | } |
| 464 | |
| 465 | DEFUN (debug_bgp_update_direct, |
| 466 | debug_bgp_update_direct_cmd, |
| 467 | "debug bgp updates (in|out)", |
| 468 | DEBUG_STR |
| 469 | BGP_STR |
| 470 | "BGP updates\n" |
| 471 | "Inbound updates\n" |
| 472 | "Outbound updates\n") |
| 473 | { |
| 474 | if (vty->node == CONFIG_NODE) |
| 475 | { |
| 476 | if (strncmp ("i", argv[0], 1) == 0) |
| 477 | { |
| 478 | DEBUG_OFF (update, UPDATE_OUT); |
| 479 | DEBUG_ON (update, UPDATE_IN); |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | DEBUG_OFF (update, UPDATE_IN); |
| 484 | DEBUG_ON (update, UPDATE_OUT); |
| 485 | } |
| 486 | } |
| 487 | else |
| 488 | { |
| 489 | if (strncmp ("i", argv[0], 1) == 0) |
| 490 | { |
| 491 | TERM_DEBUG_OFF (update, UPDATE_OUT); |
| 492 | TERM_DEBUG_ON (update, UPDATE_IN); |
| 493 | vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE); |
| 494 | } |
| 495 | else |
| 496 | { |
| 497 | TERM_DEBUG_OFF (update, UPDATE_IN); |
| 498 | TERM_DEBUG_ON (update, UPDATE_OUT); |
| 499 | vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE); |
| 500 | } |
| 501 | } |
| 502 | return CMD_SUCCESS; |
| 503 | } |
| 504 | |
| 505 | DEFUN (no_debug_bgp_update, |
| 506 | no_debug_bgp_update_cmd, |
| 507 | "no debug bgp updates", |
| 508 | NO_STR |
| 509 | DEBUG_STR |
| 510 | BGP_STR |
| 511 | "BGP updates\n") |
| 512 | { |
| 513 | if (vty->node == CONFIG_NODE) |
| 514 | { |
| 515 | DEBUG_OFF (update, UPDATE_IN); |
| 516 | DEBUG_OFF (update, UPDATE_OUT); |
| 517 | } |
| 518 | else |
| 519 | { |
| 520 | TERM_DEBUG_OFF (update, UPDATE_IN); |
| 521 | TERM_DEBUG_OFF (update, UPDATE_OUT); |
| 522 | vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE); |
| 523 | } |
| 524 | return CMD_SUCCESS; |
| 525 | } |
| 526 | |
| 527 | ALIAS (no_debug_bgp_update, |
| 528 | undebug_bgp_update_cmd, |
| 529 | "undebug bgp updates", |
| 530 | UNDEBUG_STR |
| 531 | BGP_STR |
| 532 | "BGP updates\n") |
| 533 | |
| 534 | DEFUN (debug_bgp_normal, |
| 535 | debug_bgp_normal_cmd, |
| 536 | "debug bgp", |
| 537 | DEBUG_STR |
| 538 | BGP_STR) |
| 539 | { |
| 540 | if (vty->node == CONFIG_NODE) |
| 541 | DEBUG_ON (normal, NORMAL); |
| 542 | else |
| 543 | { |
| 544 | TERM_DEBUG_ON (normal, NORMAL); |
| 545 | vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE); |
| 546 | } |
| 547 | return CMD_SUCCESS; |
| 548 | } |
| 549 | |
| 550 | DEFUN (no_debug_bgp_normal, |
| 551 | no_debug_bgp_normal_cmd, |
| 552 | "no debug bgp", |
| 553 | NO_STR |
| 554 | DEBUG_STR |
| 555 | BGP_STR) |
| 556 | { |
| 557 | if (vty->node == CONFIG_NODE) |
| 558 | DEBUG_OFF (normal, NORMAL); |
| 559 | else |
| 560 | { |
| 561 | TERM_DEBUG_OFF (normal, NORMAL); |
| 562 | vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE); |
| 563 | } |
| 564 | return CMD_SUCCESS; |
| 565 | } |
| 566 | |
| 567 | ALIAS (no_debug_bgp_normal, |
| 568 | undebug_bgp_normal_cmd, |
| 569 | "undebug bgp", |
| 570 | UNDEBUG_STR |
| 571 | BGP_STR) |
| 572 | |
| 573 | DEFUN (no_debug_bgp_all, |
| 574 | no_debug_bgp_all_cmd, |
| 575 | "no debug all bgp", |
| 576 | NO_STR |
| 577 | DEBUG_STR |
| 578 | "Enable all debugging\n" |
| 579 | BGP_STR) |
| 580 | { |
| 581 | TERM_DEBUG_OFF (normal, NORMAL); |
| 582 | TERM_DEBUG_OFF (events, EVENTS); |
| 583 | TERM_DEBUG_OFF (keepalive, KEEPALIVE); |
| 584 | TERM_DEBUG_OFF (update, UPDATE_IN); |
| 585 | TERM_DEBUG_OFF (update, UPDATE_OUT); |
| 586 | TERM_DEBUG_OFF (fsm, FSM); |
| 587 | TERM_DEBUG_OFF (filter, FILTER); |
| 588 | vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE); |
| 589 | |
| 590 | return CMD_SUCCESS; |
| 591 | } |
| 592 | |
| 593 | ALIAS (no_debug_bgp_all, |
| 594 | undebug_bgp_all_cmd, |
| 595 | "undebug all bgp", |
| 596 | UNDEBUG_STR |
| 597 | "Enable all debugging\n" |
| 598 | BGP_STR) |
| 599 | |
| 600 | DEFUN (show_debugging_bgp, |
| 601 | show_debugging_bgp_cmd, |
| 602 | "show debugging bgp", |
| 603 | SHOW_STR |
| 604 | DEBUG_STR |
| 605 | BGP_STR) |
| 606 | { |
| 607 | vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE); |
| 608 | |
| 609 | if (BGP_DEBUG (normal, NORMAL)) |
| 610 | vty_out (vty, " BGP debugging is on%s", VTY_NEWLINE); |
| 611 | if (BGP_DEBUG (events, EVENTS)) |
| 612 | vty_out (vty, " BGP events debugging is on%s", VTY_NEWLINE); |
| 613 | if (BGP_DEBUG (keepalive, KEEPALIVE)) |
| 614 | vty_out (vty, " BGP keepalives debugging is on%s", VTY_NEWLINE); |
| 615 | if (BGP_DEBUG (update, UPDATE_IN) && BGP_DEBUG (update, UPDATE_OUT)) |
| 616 | vty_out (vty, " BGP updates debugging is on%s", VTY_NEWLINE); |
| 617 | else if (BGP_DEBUG (update, UPDATE_IN)) |
| 618 | vty_out (vty, " BGP updates debugging is on (inbound)%s", VTY_NEWLINE); |
| 619 | else if (BGP_DEBUG (update, UPDATE_OUT)) |
| 620 | vty_out (vty, " BGP updates debugging is on (outbound)%s", VTY_NEWLINE); |
| 621 | if (BGP_DEBUG (fsm, FSM)) |
| 622 | vty_out (vty, " BGP fsm debugging is on%s", VTY_NEWLINE); |
| 623 | if (BGP_DEBUG (filter, FILTER)) |
| 624 | vty_out (vty, " BGP filter debugging is on%s", VTY_NEWLINE); |
| 625 | vty_out (vty, "%s", VTY_NEWLINE); |
| 626 | return CMD_SUCCESS; |
| 627 | } |
| 628 | |
| 629 | int |
| 630 | bgp_config_write_debug (struct vty *vty) |
| 631 | { |
| 632 | int write = 0; |
| 633 | |
| 634 | if (CONF_BGP_DEBUG (normal, NORMAL)) |
| 635 | { |
| 636 | vty_out (vty, "debug bgp%s", VTY_NEWLINE); |
| 637 | write++; |
| 638 | } |
| 639 | |
| 640 | if (CONF_BGP_DEBUG (events, EVENTS)) |
| 641 | { |
| 642 | vty_out (vty, "debug bgp events%s", VTY_NEWLINE); |
| 643 | write++; |
| 644 | } |
| 645 | |
| 646 | if (CONF_BGP_DEBUG (keepalive, KEEPALIVE)) |
| 647 | { |
| 648 | vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE); |
| 649 | write++; |
| 650 | } |
| 651 | |
| 652 | if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT)) |
| 653 | { |
| 654 | vty_out (vty, "debug bgp updates%s", VTY_NEWLINE); |
| 655 | write++; |
| 656 | } |
| 657 | else if (CONF_BGP_DEBUG (update, UPDATE_IN)) |
| 658 | { |
| 659 | vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE); |
| 660 | write++; |
| 661 | } |
| 662 | else if (CONF_BGP_DEBUG (update, UPDATE_OUT)) |
| 663 | { |
| 664 | vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE); |
| 665 | write++; |
| 666 | } |
| 667 | |
| 668 | if (CONF_BGP_DEBUG (fsm, FSM)) |
| 669 | { |
| 670 | vty_out (vty, "debug bgp fsm%s", VTY_NEWLINE); |
| 671 | write++; |
| 672 | } |
| 673 | |
| 674 | if (CONF_BGP_DEBUG (filter, FILTER)) |
| 675 | { |
| 676 | vty_out (vty, "debug bgp filters%s", VTY_NEWLINE); |
| 677 | write++; |
| 678 | } |
| 679 | |
| 680 | return write; |
| 681 | } |
| 682 | |
| 683 | struct cmd_node debug_node = |
| 684 | { |
| 685 | DEBUG_NODE, |
| 686 | "", |
| 687 | 1 |
| 688 | }; |
| 689 | |
| 690 | void |
| 691 | bgp_debug_init () |
| 692 | { |
| 693 | install_node (&debug_node, bgp_config_write_debug); |
| 694 | |
| 695 | install_element (ENABLE_NODE, &show_debugging_bgp_cmd); |
| 696 | |
| 697 | install_element (ENABLE_NODE, &debug_bgp_fsm_cmd); |
| 698 | install_element (CONFIG_NODE, &debug_bgp_fsm_cmd); |
| 699 | install_element (ENABLE_NODE, &debug_bgp_events_cmd); |
| 700 | install_element (CONFIG_NODE, &debug_bgp_events_cmd); |
| 701 | install_element (ENABLE_NODE, &debug_bgp_filter_cmd); |
| 702 | install_element (CONFIG_NODE, &debug_bgp_filter_cmd); |
| 703 | install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd); |
| 704 | install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd); |
| 705 | install_element (ENABLE_NODE, &debug_bgp_update_cmd); |
| 706 | install_element (CONFIG_NODE, &debug_bgp_update_cmd); |
| 707 | install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd); |
| 708 | install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd); |
| 709 | install_element (ENABLE_NODE, &debug_bgp_normal_cmd); |
| 710 | install_element (CONFIG_NODE, &debug_bgp_normal_cmd); |
| 711 | |
| 712 | install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd); |
| 713 | install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd); |
| 714 | install_element (CONFIG_NODE, &no_debug_bgp_fsm_cmd); |
| 715 | install_element (ENABLE_NODE, &no_debug_bgp_events_cmd); |
| 716 | install_element (ENABLE_NODE, &undebug_bgp_events_cmd); |
| 717 | install_element (CONFIG_NODE, &no_debug_bgp_events_cmd); |
| 718 | install_element (ENABLE_NODE, &no_debug_bgp_filter_cmd); |
| 719 | install_element (ENABLE_NODE, &undebug_bgp_filter_cmd); |
| 720 | install_element (CONFIG_NODE, &no_debug_bgp_filter_cmd); |
| 721 | install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd); |
| 722 | install_element (ENABLE_NODE, &undebug_bgp_keepalive_cmd); |
| 723 | install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd); |
| 724 | install_element (ENABLE_NODE, &no_debug_bgp_update_cmd); |
| 725 | install_element (ENABLE_NODE, &undebug_bgp_update_cmd); |
| 726 | install_element (CONFIG_NODE, &no_debug_bgp_update_cmd); |
| 727 | install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd); |
| 728 | install_element (ENABLE_NODE, &undebug_bgp_normal_cmd); |
| 729 | install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd); |
| 730 | install_element (ENABLE_NODE, &no_debug_bgp_all_cmd); |
| 731 | install_element (ENABLE_NODE, &undebug_bgp_all_cmd); |
| 732 | } |