paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Zebra debug related function |
| 3 | * Copyright (C) 1999 Kunihiro Ishiguro |
| 4 | * |
| 5 | * This file is part of GNU Zebra. |
| 6 | * |
| 7 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Zebra; see the file COPYING. If not, write to the |
| 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | * Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | #include "command.h" |
| 25 | #include "debug.h" |
| 26 | |
| 27 | /* For debug statement. */ |
| 28 | unsigned long zebra_debug_event; |
| 29 | unsigned long zebra_debug_packet; |
| 30 | unsigned long zebra_debug_kernel; |
Paul Jakma | b0498dc | 2006-07-27 21:35:33 +0000 | [diff] [blame] | 31 | unsigned long zebra_debug_rib; |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 32 | unsigned long zebra_debug_fpm; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | |
| 34 | DEFUN (show_debugging_zebra, |
| 35 | show_debugging_zebra_cmd, |
| 36 | "show debugging zebra", |
| 37 | SHOW_STR |
| 38 | "Zebra configuration\n" |
| 39 | "Debugging information\n") |
| 40 | { |
| 41 | vty_out (vty, "Zebra debugging status:%s", VTY_NEWLINE); |
| 42 | |
| 43 | if (IS_ZEBRA_DEBUG_EVENT) |
| 44 | vty_out (vty, " Zebra event debugging is on%s", VTY_NEWLINE); |
| 45 | |
| 46 | if (IS_ZEBRA_DEBUG_PACKET) |
| 47 | { |
| 48 | if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV) |
| 49 | { |
| 50 | vty_out (vty, " Zebra packet%s debugging is on%s", |
| 51 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 52 | VTY_NEWLINE); |
| 53 | } |
| 54 | else |
| 55 | { |
| 56 | if (IS_ZEBRA_DEBUG_SEND) |
| 57 | vty_out (vty, " Zebra packet send%s debugging is on%s", |
| 58 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 59 | VTY_NEWLINE); |
| 60 | else |
| 61 | vty_out (vty, " Zebra packet receive%s debugging is on%s", |
| 62 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 63 | VTY_NEWLINE); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if (IS_ZEBRA_DEBUG_KERNEL) |
| 68 | vty_out (vty, " Zebra kernel debugging is on%s", VTY_NEWLINE); |
| 69 | |
Paul Jakma | b0498dc | 2006-07-27 21:35:33 +0000 | [diff] [blame] | 70 | if (IS_ZEBRA_DEBUG_RIB) |
| 71 | vty_out (vty, " Zebra RIB debugging is on%s", VTY_NEWLINE); |
| 72 | if (IS_ZEBRA_DEBUG_RIB_Q) |
| 73 | vty_out (vty, " Zebra RIB queue debugging is on%s", VTY_NEWLINE); |
| 74 | |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 75 | if (IS_ZEBRA_DEBUG_FPM) |
| 76 | vty_out (vty, " Zebra FPM debugging is on%s", VTY_NEWLINE); |
| 77 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 78 | return CMD_SUCCESS; |
| 79 | } |
| 80 | |
| 81 | DEFUN (debug_zebra_events, |
| 82 | debug_zebra_events_cmd, |
| 83 | "debug zebra events", |
| 84 | DEBUG_STR |
| 85 | "Zebra configuration\n" |
| 86 | "Debug option set for zebra events\n") |
| 87 | { |
| 88 | zebra_debug_event = ZEBRA_DEBUG_EVENT; |
| 89 | return CMD_WARNING; |
| 90 | } |
| 91 | |
| 92 | DEFUN (debug_zebra_packet, |
| 93 | debug_zebra_packet_cmd, |
| 94 | "debug zebra packet", |
| 95 | DEBUG_STR |
| 96 | "Zebra configuration\n" |
| 97 | "Debug option set for zebra packet\n") |
| 98 | { |
| 99 | zebra_debug_packet = ZEBRA_DEBUG_PACKET; |
| 100 | zebra_debug_packet |= ZEBRA_DEBUG_SEND; |
| 101 | zebra_debug_packet |= ZEBRA_DEBUG_RECV; |
| 102 | return CMD_SUCCESS; |
| 103 | } |
| 104 | |
| 105 | DEFUN (debug_zebra_packet_direct, |
| 106 | debug_zebra_packet_direct_cmd, |
| 107 | "debug zebra packet (recv|send)", |
| 108 | DEBUG_STR |
| 109 | "Zebra configuration\n" |
| 110 | "Debug option set for zebra packet\n" |
| 111 | "Debug option set for receive packet\n" |
| 112 | "Debug option set for send packet\n") |
| 113 | { |
| 114 | zebra_debug_packet = ZEBRA_DEBUG_PACKET; |
| 115 | if (strncmp ("send", argv[0], strlen (argv[0])) == 0) |
| 116 | zebra_debug_packet |= ZEBRA_DEBUG_SEND; |
| 117 | if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) |
| 118 | zebra_debug_packet |= ZEBRA_DEBUG_RECV; |
| 119 | zebra_debug_packet &= ~ZEBRA_DEBUG_DETAIL; |
| 120 | return CMD_SUCCESS; |
| 121 | } |
| 122 | |
| 123 | DEFUN (debug_zebra_packet_detail, |
| 124 | debug_zebra_packet_detail_cmd, |
| 125 | "debug zebra packet (recv|send) detail", |
| 126 | DEBUG_STR |
| 127 | "Zebra configuration\n" |
| 128 | "Debug option set for zebra packet\n" |
| 129 | "Debug option set for receive packet\n" |
| 130 | "Debug option set for send packet\n" |
| 131 | "Debug option set detaied information\n") |
| 132 | { |
| 133 | zebra_debug_packet = ZEBRA_DEBUG_PACKET; |
| 134 | if (strncmp ("send", argv[0], strlen (argv[0])) == 0) |
| 135 | zebra_debug_packet |= ZEBRA_DEBUG_SEND; |
| 136 | if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) |
| 137 | zebra_debug_packet |= ZEBRA_DEBUG_RECV; |
| 138 | zebra_debug_packet |= ZEBRA_DEBUG_DETAIL; |
| 139 | return CMD_SUCCESS; |
| 140 | } |
| 141 | |
| 142 | DEFUN (debug_zebra_kernel, |
| 143 | debug_zebra_kernel_cmd, |
| 144 | "debug zebra kernel", |
| 145 | DEBUG_STR |
| 146 | "Zebra configuration\n" |
| 147 | "Debug option set for zebra between kernel interface\n") |
| 148 | { |
| 149 | zebra_debug_kernel = ZEBRA_DEBUG_KERNEL; |
| 150 | return CMD_SUCCESS; |
| 151 | } |
| 152 | |
Paul Jakma | b0498dc | 2006-07-27 21:35:33 +0000 | [diff] [blame] | 153 | DEFUN (debug_zebra_rib, |
| 154 | debug_zebra_rib_cmd, |
| 155 | "debug zebra rib", |
| 156 | DEBUG_STR |
| 157 | "Zebra configuration\n" |
| 158 | "Debug RIB events\n") |
| 159 | { |
| 160 | SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB); |
| 161 | return CMD_SUCCESS; |
| 162 | } |
| 163 | |
| 164 | DEFUN (debug_zebra_rib_q, |
| 165 | debug_zebra_rib_q_cmd, |
| 166 | "debug zebra rib queue", |
| 167 | DEBUG_STR |
| 168 | "Zebra configuration\n" |
| 169 | "Debug RIB events\n" |
| 170 | "Debug RIB queueing\n") |
| 171 | { |
| 172 | SET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q); |
| 173 | return CMD_SUCCESS; |
| 174 | } |
| 175 | |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 176 | DEFUN (debug_zebra_fpm, |
| 177 | debug_zebra_fpm_cmd, |
| 178 | "debug zebra fpm", |
| 179 | DEBUG_STR |
| 180 | "Zebra configuration\n" |
| 181 | "Debug zebra FPM events\n") |
| 182 | { |
| 183 | SET_FLAG (zebra_debug_fpm, ZEBRA_DEBUG_FPM); |
| 184 | return CMD_SUCCESS; |
| 185 | } |
| 186 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 187 | DEFUN (no_debug_zebra_events, |
| 188 | no_debug_zebra_events_cmd, |
| 189 | "no debug zebra events", |
| 190 | NO_STR |
| 191 | DEBUG_STR |
| 192 | "Zebra configuration\n" |
| 193 | "Debug option set for zebra events\n") |
| 194 | { |
| 195 | zebra_debug_event = 0; |
| 196 | return CMD_SUCCESS; |
| 197 | } |
| 198 | |
| 199 | DEFUN (no_debug_zebra_packet, |
| 200 | no_debug_zebra_packet_cmd, |
| 201 | "no debug zebra packet", |
| 202 | NO_STR |
| 203 | DEBUG_STR |
| 204 | "Zebra configuration\n" |
| 205 | "Debug option set for zebra packet\n") |
| 206 | { |
| 207 | zebra_debug_packet = 0; |
| 208 | return CMD_SUCCESS; |
| 209 | } |
| 210 | |
| 211 | DEFUN (no_debug_zebra_packet_direct, |
| 212 | no_debug_zebra_packet_direct_cmd, |
| 213 | "no debug zebra packet (recv|send)", |
| 214 | NO_STR |
| 215 | DEBUG_STR |
| 216 | "Zebra configuration\n" |
| 217 | "Debug option set for zebra packet\n" |
| 218 | "Debug option set for receive packet\n" |
| 219 | "Debug option set for send packet\n") |
| 220 | { |
| 221 | if (strncmp ("send", argv[0], strlen (argv[0])) == 0) |
| 222 | zebra_debug_packet &= ~ZEBRA_DEBUG_SEND; |
| 223 | if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) |
| 224 | zebra_debug_packet &= ~ZEBRA_DEBUG_RECV; |
| 225 | return CMD_SUCCESS; |
| 226 | } |
| 227 | |
| 228 | DEFUN (no_debug_zebra_kernel, |
| 229 | no_debug_zebra_kernel_cmd, |
| 230 | "no debug zebra kernel", |
| 231 | NO_STR |
| 232 | DEBUG_STR |
| 233 | "Zebra configuration\n" |
| 234 | "Debug option set for zebra between kernel interface\n") |
| 235 | { |
| 236 | zebra_debug_kernel = 0; |
| 237 | return CMD_SUCCESS; |
| 238 | } |
| 239 | |
Paul Jakma | b0498dc | 2006-07-27 21:35:33 +0000 | [diff] [blame] | 240 | DEFUN (no_debug_zebra_rib, |
| 241 | no_debug_zebra_rib_cmd, |
| 242 | "no debug zebra rib", |
| 243 | NO_STR |
| 244 | DEBUG_STR |
| 245 | "Zebra configuration\n" |
| 246 | "Debug zebra RIB\n") |
| 247 | { |
| 248 | zebra_debug_rib = 0; |
| 249 | return CMD_SUCCESS; |
| 250 | } |
| 251 | |
| 252 | DEFUN (no_debug_zebra_rib_q, |
| 253 | no_debug_zebra_rib_q_cmd, |
Stephen Hemminger | e524843 | 2008-08-17 18:08:24 +0100 | [diff] [blame] | 254 | "no debug zebra rib queue", |
Paul Jakma | b0498dc | 2006-07-27 21:35:33 +0000 | [diff] [blame] | 255 | NO_STR |
| 256 | DEBUG_STR |
| 257 | "Zebra configuration\n" |
| 258 | "Debug zebra RIB\n" |
| 259 | "Debug RIB queueing\n") |
| 260 | { |
| 261 | UNSET_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB_Q); |
| 262 | return CMD_SUCCESS; |
| 263 | } |
| 264 | |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 265 | DEFUN (no_debug_zebra_fpm, |
| 266 | no_debug_zebra_fpm_cmd, |
| 267 | "no debug zebra fpm", |
| 268 | NO_STR |
| 269 | DEBUG_STR |
| 270 | "Zebra configuration\n" |
| 271 | "Debug zebra FPM events\n") |
| 272 | { |
| 273 | zebra_debug_fpm = 0; |
| 274 | return CMD_SUCCESS; |
| 275 | } |
| 276 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 277 | /* Debug node. */ |
| 278 | struct cmd_node debug_node = |
| 279 | { |
| 280 | DEBUG_NODE, |
| 281 | "", /* Debug node has no interface. */ |
| 282 | 1 |
| 283 | }; |
| 284 | |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 285 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 286 | config_write_debug (struct vty *vty) |
| 287 | { |
| 288 | int write = 0; |
| 289 | |
| 290 | if (IS_ZEBRA_DEBUG_EVENT) |
| 291 | { |
| 292 | vty_out (vty, "debug zebra events%s", VTY_NEWLINE); |
| 293 | write++; |
| 294 | } |
| 295 | if (IS_ZEBRA_DEBUG_PACKET) |
| 296 | { |
| 297 | if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV) |
| 298 | { |
| 299 | vty_out (vty, "debug zebra packet%s%s", |
| 300 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 301 | VTY_NEWLINE); |
| 302 | write++; |
| 303 | } |
| 304 | else |
| 305 | { |
| 306 | if (IS_ZEBRA_DEBUG_SEND) |
| 307 | vty_out (vty, "debug zebra packet send%s%s", |
| 308 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 309 | VTY_NEWLINE); |
| 310 | else |
| 311 | vty_out (vty, "debug zebra packet recv%s%s", |
| 312 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 313 | VTY_NEWLINE); |
| 314 | write++; |
| 315 | } |
| 316 | } |
| 317 | if (IS_ZEBRA_DEBUG_KERNEL) |
| 318 | { |
| 319 | vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE); |
| 320 | write++; |
| 321 | } |
Paul Jakma | b0498dc | 2006-07-27 21:35:33 +0000 | [diff] [blame] | 322 | if (IS_ZEBRA_DEBUG_RIB) |
| 323 | { |
| 324 | vty_out (vty, "debug zebra rib%s", VTY_NEWLINE); |
| 325 | write++; |
| 326 | } |
| 327 | if (IS_ZEBRA_DEBUG_RIB_Q) |
| 328 | { |
| 329 | vty_out (vty, "debug zebra rib queue%s", VTY_NEWLINE); |
| 330 | write++; |
| 331 | } |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 332 | if (IS_ZEBRA_DEBUG_FPM) |
| 333 | { |
| 334 | vty_out (vty, "debug zebra fpm%s", VTY_NEWLINE); |
| 335 | write++; |
| 336 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 337 | return write; |
| 338 | } |
| 339 | |
| 340 | void |
paul | a1ac18c | 2005-06-28 17:17:12 +0000 | [diff] [blame] | 341 | zebra_debug_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 342 | { |
| 343 | zebra_debug_event = 0; |
| 344 | zebra_debug_packet = 0; |
Paul Jakma | b0498dc | 2006-07-27 21:35:33 +0000 | [diff] [blame] | 345 | zebra_debug_kernel = 0; |
| 346 | zebra_debug_rib = 0; |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 347 | zebra_debug_fpm = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 348 | |
| 349 | install_node (&debug_node, config_write_debug); |
| 350 | |
| 351 | install_element (VIEW_NODE, &show_debugging_zebra_cmd); |
| 352 | |
| 353 | install_element (ENABLE_NODE, &show_debugging_zebra_cmd); |
| 354 | install_element (ENABLE_NODE, &debug_zebra_events_cmd); |
| 355 | install_element (ENABLE_NODE, &debug_zebra_packet_cmd); |
| 356 | install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd); |
| 357 | install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd); |
| 358 | install_element (ENABLE_NODE, &debug_zebra_kernel_cmd); |
Paul Jakma | b0498dc | 2006-07-27 21:35:33 +0000 | [diff] [blame] | 359 | install_element (ENABLE_NODE, &debug_zebra_rib_cmd); |
| 360 | install_element (ENABLE_NODE, &debug_zebra_rib_q_cmd); |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 361 | install_element (ENABLE_NODE, &debug_zebra_fpm_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 362 | install_element (ENABLE_NODE, &no_debug_zebra_events_cmd); |
| 363 | install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd); |
| 364 | install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd); |
Paul Jakma | b0498dc | 2006-07-27 21:35:33 +0000 | [diff] [blame] | 365 | install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd); |
| 366 | install_element (ENABLE_NODE, &no_debug_zebra_rib_q_cmd); |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 367 | install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 368 | |
| 369 | install_element (CONFIG_NODE, &debug_zebra_events_cmd); |
| 370 | install_element (CONFIG_NODE, &debug_zebra_packet_cmd); |
| 371 | install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd); |
| 372 | install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd); |
| 373 | install_element (CONFIG_NODE, &debug_zebra_kernel_cmd); |
Paul Jakma | b0498dc | 2006-07-27 21:35:33 +0000 | [diff] [blame] | 374 | install_element (CONFIG_NODE, &debug_zebra_rib_cmd); |
| 375 | install_element (CONFIG_NODE, &debug_zebra_rib_q_cmd); |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 376 | install_element (CONFIG_NODE, &debug_zebra_fpm_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 377 | install_element (CONFIG_NODE, &no_debug_zebra_events_cmd); |
| 378 | install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd); |
| 379 | install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd); |
Paul Jakma | b0498dc | 2006-07-27 21:35:33 +0000 | [diff] [blame] | 380 | install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd); |
| 381 | install_element (CONFIG_NODE, &no_debug_zebra_rib_q_cmd); |
Avneesh Sachdev | 5adc252 | 2012-11-13 22:48:59 +0000 | [diff] [blame] | 382 | install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 383 | } |