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