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 | |
gdt | 5e4fa16 | 2004-03-16 14:38:36 +0000 | [diff] [blame] | 23 | #include <lib/version.h> |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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"}, |
hasso | 3950fda | 2004-05-20 10:22:49 +0000 | [diff] [blame] | 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"} |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 100 | }; |
| 101 | int bgp_notify_head_msg_max = BGP_NOTIFY_HEADER_MAX; |
| 102 | |
| 103 | struct message bgp_notify_open_msg[] = |
| 104 | { |
| 105 | { 0, "null" }, |
hasso | 3950fda | 2004-05-20 10:22:49 +0000 | [diff] [blame] | 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"}, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 113 | }; |
| 114 | int bgp_notify_open_msg_max = BGP_NOTIFY_OPEN_MAX; |
| 115 | |
| 116 | struct message bgp_notify_update_msg[] = |
| 117 | { |
| 118 | { 0, "null"}, |
hasso | 3950fda | 2004-05-20 10:22:49 +0000 | [diff] [blame] | 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"}, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 130 | }; |
| 131 | int bgp_notify_update_msg_max = BGP_NOTIFY_UPDATE_MAX; |
| 132 | |
| 133 | struct message bgp_notify_cease_msg[] = |
| 134 | { |
| 135 | { 0, ""}, |
hasso | 3950fda | 2004-05-20 10:22:49 +0000 | [diff] [blame] | 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 | { BGP_NOTIFY_CEASE_COLLISION_RESOLUTION, "/Connection collision resolution"}, |
| 143 | { BGP_NOTIFY_CEASE_OUT_OF_RESOURCE, "/Out of Resource"}, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 144 | }; |
| 145 | int bgp_notify_cease_msg_max = BGP_NOTIFY_CEASE_MAX; |
| 146 | |
| 147 | struct message bgp_notify_capability_msg[] = |
| 148 | { |
| 149 | { 0, "null" }, |
hasso | 3950fda | 2004-05-20 10:22:49 +0000 | [diff] [blame] | 150 | { BGP_NOTIFY_CAPABILITY_INVALID_ACTION, "/Invalid Action Value" }, |
| 151 | { BGP_NOTIFY_CAPABILITY_INVALID_LENGTH, "/Invalid Capability Length"}, |
| 152 | { BGP_NOTIFY_CAPABILITY_MALFORMED_CODE, "/Malformed Capability Value"}, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 153 | }; |
| 154 | int bgp_notify_capability_msg_max = BGP_NOTIFY_CAPABILITY_MAX; |
| 155 | |
| 156 | /* Origin strings. */ |
| 157 | char *bgp_origin_str[] = {"i","e","?"}; |
| 158 | char *bgp_origin_long_str[] = {"IGP","EGP","incomplete"}; |
| 159 | |
| 160 | /* Dump attribute. */ |
| 161 | void |
| 162 | bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size) |
| 163 | { |
| 164 | |
| 165 | if (! attr) |
| 166 | return; |
| 167 | |
| 168 | snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop)); |
| 169 | snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s", |
| 170 | bgp_origin_str[attr->origin]); |
| 171 | |
| 172 | #ifdef HAVE_IPV6 |
| 173 | { |
| 174 | char addrbuf[BUFSIZ]; |
| 175 | |
| 176 | /* Add MP case. */ |
| 177 | if (attr->mp_nexthop_len == 16 || attr->mp_nexthop_len == 32) |
| 178 | snprintf (buf + strlen (buf), size - strlen (buf), ", mp_nexthop %s", |
| 179 | inet_ntop (AF_INET6, &attr->mp_nexthop_global, |
| 180 | addrbuf, BUFSIZ)); |
| 181 | |
| 182 | if (attr->mp_nexthop_len == 32) |
| 183 | snprintf (buf + strlen (buf), size - strlen (buf), "(%s)", |
| 184 | inet_ntop (AF_INET6, &attr->mp_nexthop_local, |
| 185 | addrbuf, BUFSIZ)); |
| 186 | } |
| 187 | #endif /* HAVE_IPV6 */ |
| 188 | |
| 189 | if (peer_sort (peer) == BGP_PEER_IBGP) |
| 190 | snprintf (buf + strlen (buf), size - strlen (buf), ", localpref %d", |
| 191 | attr->local_pref); |
| 192 | |
| 193 | if (attr->med) |
| 194 | snprintf (buf + strlen (buf), size - strlen (buf), ", metric %d", |
| 195 | attr->med); |
| 196 | |
| 197 | if (attr->community) |
| 198 | snprintf (buf + strlen (buf), size - strlen (buf), ", community %s", |
| 199 | community_str (attr->community)); |
| 200 | |
| 201 | if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)) |
| 202 | snprintf (buf + strlen (buf), size - strlen (buf), ", atomic-aggregate"); |
| 203 | |
| 204 | if (attr->aggregator_as) |
| 205 | snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %d %s", |
| 206 | attr->aggregator_as, inet_ntoa (attr->aggregator_addr)); |
| 207 | |
| 208 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)) |
| 209 | snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s", |
| 210 | inet_ntoa (attr->originator_id)); |
| 211 | |
| 212 | if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST)) |
| 213 | { |
| 214 | int i; |
| 215 | |
| 216 | snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist "); |
| 217 | for (i = 0; i < attr->cluster->length / 4; i++) |
| 218 | snprintf (buf + strlen (buf), size - strlen (buf), "%s", |
| 219 | inet_ntoa (attr->cluster->list[i])); |
| 220 | } |
| 221 | |
| 222 | if (attr->aspath) |
| 223 | snprintf (buf + strlen (buf), size - strlen (buf), ", path %s", |
| 224 | aspath_print (attr->aspath)); |
| 225 | } |
| 226 | |
| 227 | /* dump notify packet */ |
| 228 | void |
| 229 | bgp_notify_print(struct peer *peer, struct bgp_notify *bgp_notify, char *direct) |
| 230 | { |
| 231 | char *subcode_str; |
| 232 | |
| 233 | subcode_str = ""; |
| 234 | |
| 235 | switch (bgp_notify->code) |
| 236 | { |
| 237 | case BGP_NOTIFY_HEADER_ERR: |
| 238 | subcode_str = LOOKUP (bgp_notify_head_msg, bgp_notify->subcode); |
| 239 | break; |
| 240 | case BGP_NOTIFY_OPEN_ERR: |
| 241 | subcode_str = LOOKUP (bgp_notify_open_msg, bgp_notify->subcode); |
| 242 | break; |
| 243 | case BGP_NOTIFY_UPDATE_ERR: |
| 244 | subcode_str = LOOKUP (bgp_notify_update_msg, bgp_notify->subcode); |
| 245 | break; |
| 246 | case BGP_NOTIFY_HOLD_ERR: |
| 247 | subcode_str = ""; |
| 248 | break; |
| 249 | case BGP_NOTIFY_FSM_ERR: |
| 250 | subcode_str = ""; |
| 251 | break; |
| 252 | case BGP_NOTIFY_CEASE: |
| 253 | subcode_str = LOOKUP (bgp_notify_cease_msg, bgp_notify->subcode); |
| 254 | break; |
| 255 | case BGP_NOTIFY_CAPABILITY_ERR: |
| 256 | subcode_str = LOOKUP (bgp_notify_capability_msg, bgp_notify->subcode); |
| 257 | break; |
| 258 | } |
hasso | 3950fda | 2004-05-20 10:22:49 +0000 | [diff] [blame] | 259 | |
| 260 | if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) |
| 261 | zlog_info ("%%NOTIFICATION: %s neighbor %s %d/%d (%s%s) %d bytes %s", |
| 262 | strcmp (direct, "received") == 0 ? "received from" : "sent to", |
| 263 | peer->host, bgp_notify->code, bgp_notify->subcode, |
| 264 | LOOKUP (bgp_notify_msg, bgp_notify->code), |
| 265 | subcode_str, bgp_notify->length, |
| 266 | bgp_notify->data ? bgp_notify->data : ""); |
| 267 | else if (BGP_DEBUG (normal, NORMAL)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 268 | plog_info (peer->log, "%s %s NOTIFICATION %d/%d (%s%s) %d bytes %s", |
| 269 | peer ? peer->host : "", |
| 270 | direct, bgp_notify->code, bgp_notify->subcode, |
| 271 | LOOKUP (bgp_notify_msg, bgp_notify->code), |
| 272 | subcode_str, bgp_notify->length, |
| 273 | bgp_notify->data ? bgp_notify->data : ""); |
| 274 | } |
| 275 | |
| 276 | /* Debug option setting interface. */ |
| 277 | unsigned long bgp_debug_option = 0; |
| 278 | |
| 279 | int |
| 280 | debug (unsigned int option) |
| 281 | { |
| 282 | return bgp_debug_option & option; |
| 283 | } |
| 284 | |
| 285 | DEFUN (debug_bgp_fsm, |
| 286 | debug_bgp_fsm_cmd, |
| 287 | "debug bgp fsm", |
| 288 | DEBUG_STR |
| 289 | BGP_STR |
| 290 | "BGP Finite State Machine\n") |
| 291 | { |
| 292 | if (vty->node == CONFIG_NODE) |
| 293 | DEBUG_ON (fsm, FSM); |
| 294 | else |
| 295 | { |
| 296 | TERM_DEBUG_ON (fsm, FSM); |
| 297 | vty_out (vty, "BGP fsm debugging is on%s", VTY_NEWLINE); |
| 298 | } |
| 299 | return CMD_SUCCESS; |
| 300 | } |
| 301 | |
| 302 | DEFUN (no_debug_bgp_fsm, |
| 303 | no_debug_bgp_fsm_cmd, |
| 304 | "no debug bgp fsm", |
| 305 | NO_STR |
| 306 | DEBUG_STR |
| 307 | BGP_STR |
| 308 | "Finite State Machine\n") |
| 309 | { |
| 310 | if (vty->node == CONFIG_NODE) |
| 311 | DEBUG_OFF (fsm, FSM); |
| 312 | else |
| 313 | { |
| 314 | TERM_DEBUG_OFF (fsm, FSM); |
| 315 | vty_out (vty, "BGP fsm debugging is off%s", VTY_NEWLINE); |
| 316 | } |
| 317 | return CMD_SUCCESS; |
| 318 | } |
| 319 | |
| 320 | ALIAS (no_debug_bgp_fsm, |
| 321 | undebug_bgp_fsm_cmd, |
| 322 | "undebug bgp fsm", |
| 323 | UNDEBUG_STR |
| 324 | DEBUG_STR |
| 325 | BGP_STR |
| 326 | "Finite State Machine\n") |
| 327 | |
| 328 | DEFUN (debug_bgp_events, |
| 329 | debug_bgp_events_cmd, |
| 330 | "debug bgp events", |
| 331 | DEBUG_STR |
| 332 | BGP_STR |
| 333 | "BGP events\n") |
| 334 | { |
| 335 | if (vty->node == CONFIG_NODE) |
| 336 | DEBUG_ON (events, EVENTS); |
| 337 | else |
| 338 | { |
| 339 | TERM_DEBUG_ON (events, EVENTS); |
| 340 | vty_out (vty, "BGP events debugging is on%s", VTY_NEWLINE); |
| 341 | } |
| 342 | return CMD_SUCCESS; |
| 343 | } |
| 344 | |
| 345 | DEFUN (no_debug_bgp_events, |
| 346 | no_debug_bgp_events_cmd, |
| 347 | "no debug bgp events", |
| 348 | NO_STR |
| 349 | DEBUG_STR |
| 350 | BGP_STR |
| 351 | "BGP events\n") |
| 352 | { |
| 353 | if (vty->node == CONFIG_NODE) |
| 354 | DEBUG_OFF (events, EVENTS); |
| 355 | else |
| 356 | { |
| 357 | TERM_DEBUG_OFF (events, EVENTS); |
| 358 | vty_out (vty, "BGP events debugging is off%s", VTY_NEWLINE); |
| 359 | } |
| 360 | return CMD_SUCCESS; |
| 361 | } |
| 362 | |
| 363 | ALIAS (no_debug_bgp_events, |
| 364 | undebug_bgp_events_cmd, |
| 365 | "undebug bgp events", |
| 366 | UNDEBUG_STR |
| 367 | BGP_STR |
| 368 | "BGP events\n") |
| 369 | |
| 370 | DEFUN (debug_bgp_filter, |
| 371 | debug_bgp_filter_cmd, |
| 372 | "debug bgp filters", |
| 373 | DEBUG_STR |
| 374 | BGP_STR |
| 375 | "BGP filters\n") |
| 376 | { |
| 377 | if (vty->node == CONFIG_NODE) |
| 378 | DEBUG_ON (filter, FILTER); |
| 379 | else |
| 380 | { |
| 381 | TERM_DEBUG_ON (filter, FILTER); |
| 382 | vty_out (vty, "BGP filters debugging is on%s", VTY_NEWLINE); |
| 383 | } |
| 384 | return CMD_SUCCESS; |
| 385 | } |
| 386 | |
| 387 | DEFUN (no_debug_bgp_filter, |
| 388 | no_debug_bgp_filter_cmd, |
| 389 | "no debug bgp filters", |
| 390 | NO_STR |
| 391 | DEBUG_STR |
| 392 | BGP_STR |
| 393 | "BGP filters\n") |
| 394 | { |
| 395 | if (vty->node == CONFIG_NODE) |
| 396 | DEBUG_OFF (filter, FILTER); |
| 397 | else |
| 398 | { |
| 399 | TERM_DEBUG_OFF (filter, FILTER); |
| 400 | vty_out (vty, "BGP filters debugging is off%s", VTY_NEWLINE); |
| 401 | } |
| 402 | return CMD_SUCCESS; |
| 403 | } |
| 404 | |
| 405 | ALIAS (no_debug_bgp_filter, |
| 406 | undebug_bgp_filter_cmd, |
| 407 | "undebug bgp filters", |
| 408 | UNDEBUG_STR |
| 409 | BGP_STR |
| 410 | "BGP filters\n") |
| 411 | |
| 412 | DEFUN (debug_bgp_keepalive, |
| 413 | debug_bgp_keepalive_cmd, |
| 414 | "debug bgp keepalives", |
| 415 | DEBUG_STR |
| 416 | BGP_STR |
| 417 | "BGP keepalives\n") |
| 418 | { |
| 419 | if (vty->node == CONFIG_NODE) |
| 420 | DEBUG_ON (keepalive, KEEPALIVE); |
| 421 | else |
| 422 | { |
| 423 | TERM_DEBUG_ON (keepalive, KEEPALIVE); |
| 424 | vty_out (vty, "BGP keepalives debugging is on%s", VTY_NEWLINE); |
| 425 | } |
| 426 | return CMD_SUCCESS; |
| 427 | } |
| 428 | |
| 429 | DEFUN (no_debug_bgp_keepalive, |
| 430 | no_debug_bgp_keepalive_cmd, |
| 431 | "no debug bgp keepalives", |
| 432 | NO_STR |
| 433 | DEBUG_STR |
| 434 | BGP_STR |
| 435 | "BGP keepalives\n") |
| 436 | { |
| 437 | if (vty->node == CONFIG_NODE) |
| 438 | DEBUG_OFF (keepalive, KEEPALIVE); |
| 439 | else |
| 440 | { |
| 441 | TERM_DEBUG_OFF (keepalive, KEEPALIVE); |
| 442 | vty_out (vty, "BGP keepalives debugging is off%s", VTY_NEWLINE); |
| 443 | } |
| 444 | return CMD_SUCCESS; |
| 445 | } |
| 446 | |
| 447 | ALIAS (no_debug_bgp_keepalive, |
| 448 | undebug_bgp_keepalive_cmd, |
| 449 | "undebug bgp keepalives", |
| 450 | UNDEBUG_STR |
| 451 | BGP_STR |
| 452 | "BGP keepalives\n") |
| 453 | |
| 454 | DEFUN (debug_bgp_update, |
| 455 | debug_bgp_update_cmd, |
| 456 | "debug bgp updates", |
| 457 | DEBUG_STR |
| 458 | BGP_STR |
| 459 | "BGP updates\n") |
| 460 | { |
| 461 | if (vty->node == CONFIG_NODE) |
| 462 | { |
| 463 | DEBUG_ON (update, UPDATE_IN); |
| 464 | DEBUG_ON (update, UPDATE_OUT); |
| 465 | } |
| 466 | else |
| 467 | { |
| 468 | TERM_DEBUG_ON (update, UPDATE_IN); |
| 469 | TERM_DEBUG_ON (update, UPDATE_OUT); |
| 470 | vty_out (vty, "BGP updates debugging is on%s", VTY_NEWLINE); |
| 471 | } |
| 472 | return CMD_SUCCESS; |
| 473 | } |
| 474 | |
| 475 | DEFUN (debug_bgp_update_direct, |
| 476 | debug_bgp_update_direct_cmd, |
| 477 | "debug bgp updates (in|out)", |
| 478 | DEBUG_STR |
| 479 | BGP_STR |
| 480 | "BGP updates\n" |
| 481 | "Inbound updates\n" |
| 482 | "Outbound updates\n") |
| 483 | { |
| 484 | if (vty->node == CONFIG_NODE) |
| 485 | { |
| 486 | if (strncmp ("i", argv[0], 1) == 0) |
| 487 | { |
| 488 | DEBUG_OFF (update, UPDATE_OUT); |
| 489 | DEBUG_ON (update, UPDATE_IN); |
| 490 | } |
| 491 | else |
| 492 | { |
| 493 | DEBUG_OFF (update, UPDATE_IN); |
| 494 | DEBUG_ON (update, UPDATE_OUT); |
| 495 | } |
| 496 | } |
| 497 | else |
| 498 | { |
| 499 | if (strncmp ("i", argv[0], 1) == 0) |
| 500 | { |
| 501 | TERM_DEBUG_OFF (update, UPDATE_OUT); |
| 502 | TERM_DEBUG_ON (update, UPDATE_IN); |
| 503 | vty_out (vty, "BGP updates debugging is on (inbound)%s", VTY_NEWLINE); |
| 504 | } |
| 505 | else |
| 506 | { |
| 507 | TERM_DEBUG_OFF (update, UPDATE_IN); |
| 508 | TERM_DEBUG_ON (update, UPDATE_OUT); |
| 509 | vty_out (vty, "BGP updates debugging is on (outbound)%s", VTY_NEWLINE); |
| 510 | } |
| 511 | } |
| 512 | return CMD_SUCCESS; |
| 513 | } |
| 514 | |
| 515 | DEFUN (no_debug_bgp_update, |
| 516 | no_debug_bgp_update_cmd, |
| 517 | "no debug bgp updates", |
| 518 | NO_STR |
| 519 | DEBUG_STR |
| 520 | BGP_STR |
| 521 | "BGP updates\n") |
| 522 | { |
| 523 | if (vty->node == CONFIG_NODE) |
| 524 | { |
| 525 | DEBUG_OFF (update, UPDATE_IN); |
| 526 | DEBUG_OFF (update, UPDATE_OUT); |
| 527 | } |
| 528 | else |
| 529 | { |
| 530 | TERM_DEBUG_OFF (update, UPDATE_IN); |
| 531 | TERM_DEBUG_OFF (update, UPDATE_OUT); |
| 532 | vty_out (vty, "BGP updates debugging is off%s", VTY_NEWLINE); |
| 533 | } |
| 534 | return CMD_SUCCESS; |
| 535 | } |
| 536 | |
| 537 | ALIAS (no_debug_bgp_update, |
| 538 | undebug_bgp_update_cmd, |
| 539 | "undebug bgp updates", |
| 540 | UNDEBUG_STR |
| 541 | BGP_STR |
| 542 | "BGP updates\n") |
| 543 | |
| 544 | DEFUN (debug_bgp_normal, |
| 545 | debug_bgp_normal_cmd, |
| 546 | "debug bgp", |
| 547 | DEBUG_STR |
| 548 | BGP_STR) |
| 549 | { |
| 550 | if (vty->node == CONFIG_NODE) |
| 551 | DEBUG_ON (normal, NORMAL); |
| 552 | else |
| 553 | { |
| 554 | TERM_DEBUG_ON (normal, NORMAL); |
| 555 | vty_out (vty, "BGP debugging is on%s", VTY_NEWLINE); |
| 556 | } |
| 557 | return CMD_SUCCESS; |
| 558 | } |
| 559 | |
| 560 | DEFUN (no_debug_bgp_normal, |
| 561 | no_debug_bgp_normal_cmd, |
| 562 | "no debug bgp", |
| 563 | NO_STR |
| 564 | DEBUG_STR |
| 565 | BGP_STR) |
| 566 | { |
| 567 | if (vty->node == CONFIG_NODE) |
| 568 | DEBUG_OFF (normal, NORMAL); |
| 569 | else |
| 570 | { |
| 571 | TERM_DEBUG_OFF (normal, NORMAL); |
| 572 | vty_out (vty, "BGP debugging is off%s", VTY_NEWLINE); |
| 573 | } |
| 574 | return CMD_SUCCESS; |
| 575 | } |
| 576 | |
| 577 | ALIAS (no_debug_bgp_normal, |
| 578 | undebug_bgp_normal_cmd, |
| 579 | "undebug bgp", |
| 580 | UNDEBUG_STR |
| 581 | BGP_STR) |
| 582 | |
| 583 | DEFUN (no_debug_bgp_all, |
| 584 | no_debug_bgp_all_cmd, |
| 585 | "no debug all bgp", |
| 586 | NO_STR |
| 587 | DEBUG_STR |
| 588 | "Enable all debugging\n" |
| 589 | BGP_STR) |
| 590 | { |
| 591 | TERM_DEBUG_OFF (normal, NORMAL); |
| 592 | TERM_DEBUG_OFF (events, EVENTS); |
| 593 | TERM_DEBUG_OFF (keepalive, KEEPALIVE); |
| 594 | TERM_DEBUG_OFF (update, UPDATE_IN); |
| 595 | TERM_DEBUG_OFF (update, UPDATE_OUT); |
| 596 | TERM_DEBUG_OFF (fsm, FSM); |
| 597 | TERM_DEBUG_OFF (filter, FILTER); |
| 598 | vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE); |
| 599 | |
| 600 | return CMD_SUCCESS; |
| 601 | } |
| 602 | |
| 603 | ALIAS (no_debug_bgp_all, |
| 604 | undebug_bgp_all_cmd, |
| 605 | "undebug all bgp", |
| 606 | UNDEBUG_STR |
| 607 | "Enable all debugging\n" |
| 608 | BGP_STR) |
| 609 | |
| 610 | DEFUN (show_debugging_bgp, |
| 611 | show_debugging_bgp_cmd, |
| 612 | "show debugging bgp", |
| 613 | SHOW_STR |
| 614 | DEBUG_STR |
| 615 | BGP_STR) |
| 616 | { |
| 617 | vty_out (vty, "BGP debugging status:%s", VTY_NEWLINE); |
| 618 | |
| 619 | if (BGP_DEBUG (normal, NORMAL)) |
| 620 | vty_out (vty, " BGP debugging is on%s", VTY_NEWLINE); |
| 621 | if (BGP_DEBUG (events, EVENTS)) |
| 622 | vty_out (vty, " BGP events debugging is on%s", VTY_NEWLINE); |
| 623 | if (BGP_DEBUG (keepalive, KEEPALIVE)) |
| 624 | vty_out (vty, " BGP keepalives debugging is on%s", VTY_NEWLINE); |
| 625 | if (BGP_DEBUG (update, UPDATE_IN) && BGP_DEBUG (update, UPDATE_OUT)) |
| 626 | vty_out (vty, " BGP updates debugging is on%s", VTY_NEWLINE); |
| 627 | else if (BGP_DEBUG (update, UPDATE_IN)) |
| 628 | vty_out (vty, " BGP updates debugging is on (inbound)%s", VTY_NEWLINE); |
| 629 | else if (BGP_DEBUG (update, UPDATE_OUT)) |
| 630 | vty_out (vty, " BGP updates debugging is on (outbound)%s", VTY_NEWLINE); |
| 631 | if (BGP_DEBUG (fsm, FSM)) |
| 632 | vty_out (vty, " BGP fsm debugging is on%s", VTY_NEWLINE); |
| 633 | if (BGP_DEBUG (filter, FILTER)) |
| 634 | vty_out (vty, " BGP filter debugging is on%s", VTY_NEWLINE); |
| 635 | vty_out (vty, "%s", VTY_NEWLINE); |
| 636 | return CMD_SUCCESS; |
| 637 | } |
| 638 | |
| 639 | int |
| 640 | bgp_config_write_debug (struct vty *vty) |
| 641 | { |
| 642 | int write = 0; |
| 643 | |
| 644 | if (CONF_BGP_DEBUG (normal, NORMAL)) |
| 645 | { |
| 646 | vty_out (vty, "debug bgp%s", VTY_NEWLINE); |
| 647 | write++; |
| 648 | } |
| 649 | |
| 650 | if (CONF_BGP_DEBUG (events, EVENTS)) |
| 651 | { |
| 652 | vty_out (vty, "debug bgp events%s", VTY_NEWLINE); |
| 653 | write++; |
| 654 | } |
| 655 | |
| 656 | if (CONF_BGP_DEBUG (keepalive, KEEPALIVE)) |
| 657 | { |
| 658 | vty_out (vty, "debug bgp keepalives%s", VTY_NEWLINE); |
| 659 | write++; |
| 660 | } |
| 661 | |
| 662 | if (CONF_BGP_DEBUG (update, UPDATE_IN) && CONF_BGP_DEBUG (update, UPDATE_OUT)) |
| 663 | { |
| 664 | vty_out (vty, "debug bgp updates%s", VTY_NEWLINE); |
| 665 | write++; |
| 666 | } |
| 667 | else if (CONF_BGP_DEBUG (update, UPDATE_IN)) |
| 668 | { |
| 669 | vty_out (vty, "debug bgp updates in%s", VTY_NEWLINE); |
| 670 | write++; |
| 671 | } |
| 672 | else if (CONF_BGP_DEBUG (update, UPDATE_OUT)) |
| 673 | { |
| 674 | vty_out (vty, "debug bgp updates out%s", VTY_NEWLINE); |
| 675 | write++; |
| 676 | } |
| 677 | |
| 678 | if (CONF_BGP_DEBUG (fsm, FSM)) |
| 679 | { |
| 680 | vty_out (vty, "debug bgp fsm%s", VTY_NEWLINE); |
| 681 | write++; |
| 682 | } |
| 683 | |
| 684 | if (CONF_BGP_DEBUG (filter, FILTER)) |
| 685 | { |
| 686 | vty_out (vty, "debug bgp filters%s", VTY_NEWLINE); |
| 687 | write++; |
| 688 | } |
| 689 | |
| 690 | return write; |
| 691 | } |
| 692 | |
| 693 | struct cmd_node debug_node = |
| 694 | { |
| 695 | DEBUG_NODE, |
| 696 | "", |
| 697 | 1 |
| 698 | }; |
| 699 | |
| 700 | void |
| 701 | bgp_debug_init () |
| 702 | { |
| 703 | install_node (&debug_node, bgp_config_write_debug); |
| 704 | |
| 705 | install_element (ENABLE_NODE, &show_debugging_bgp_cmd); |
| 706 | |
| 707 | install_element (ENABLE_NODE, &debug_bgp_fsm_cmd); |
| 708 | install_element (CONFIG_NODE, &debug_bgp_fsm_cmd); |
| 709 | install_element (ENABLE_NODE, &debug_bgp_events_cmd); |
| 710 | install_element (CONFIG_NODE, &debug_bgp_events_cmd); |
| 711 | install_element (ENABLE_NODE, &debug_bgp_filter_cmd); |
| 712 | install_element (CONFIG_NODE, &debug_bgp_filter_cmd); |
| 713 | install_element (ENABLE_NODE, &debug_bgp_keepalive_cmd); |
| 714 | install_element (CONFIG_NODE, &debug_bgp_keepalive_cmd); |
| 715 | install_element (ENABLE_NODE, &debug_bgp_update_cmd); |
| 716 | install_element (CONFIG_NODE, &debug_bgp_update_cmd); |
| 717 | install_element (ENABLE_NODE, &debug_bgp_update_direct_cmd); |
| 718 | install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd); |
| 719 | install_element (ENABLE_NODE, &debug_bgp_normal_cmd); |
| 720 | install_element (CONFIG_NODE, &debug_bgp_normal_cmd); |
| 721 | |
| 722 | install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd); |
| 723 | install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd); |
| 724 | install_element (CONFIG_NODE, &no_debug_bgp_fsm_cmd); |
| 725 | install_element (ENABLE_NODE, &no_debug_bgp_events_cmd); |
| 726 | install_element (ENABLE_NODE, &undebug_bgp_events_cmd); |
| 727 | install_element (CONFIG_NODE, &no_debug_bgp_events_cmd); |
| 728 | install_element (ENABLE_NODE, &no_debug_bgp_filter_cmd); |
| 729 | install_element (ENABLE_NODE, &undebug_bgp_filter_cmd); |
| 730 | install_element (CONFIG_NODE, &no_debug_bgp_filter_cmd); |
| 731 | install_element (ENABLE_NODE, &no_debug_bgp_keepalive_cmd); |
| 732 | install_element (ENABLE_NODE, &undebug_bgp_keepalive_cmd); |
| 733 | install_element (CONFIG_NODE, &no_debug_bgp_keepalive_cmd); |
| 734 | install_element (ENABLE_NODE, &no_debug_bgp_update_cmd); |
| 735 | install_element (ENABLE_NODE, &undebug_bgp_update_cmd); |
| 736 | install_element (CONFIG_NODE, &no_debug_bgp_update_cmd); |
| 737 | install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd); |
| 738 | install_element (ENABLE_NODE, &undebug_bgp_normal_cmd); |
| 739 | install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd); |
| 740 | install_element (ENABLE_NODE, &no_debug_bgp_all_cmd); |
| 741 | install_element (ENABLE_NODE, &undebug_bgp_all_cmd); |
| 742 | } |