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; |
| 31 | |
| 32 | DEFUN (show_debugging_zebra, |
| 33 | show_debugging_zebra_cmd, |
| 34 | "show debugging zebra", |
| 35 | SHOW_STR |
| 36 | "Zebra configuration\n" |
| 37 | "Debugging information\n") |
| 38 | { |
| 39 | vty_out (vty, "Zebra debugging status:%s", VTY_NEWLINE); |
| 40 | |
| 41 | if (IS_ZEBRA_DEBUG_EVENT) |
| 42 | vty_out (vty, " Zebra event debugging is on%s", VTY_NEWLINE); |
| 43 | |
| 44 | if (IS_ZEBRA_DEBUG_PACKET) |
| 45 | { |
| 46 | if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV) |
| 47 | { |
| 48 | vty_out (vty, " Zebra packet%s debugging is on%s", |
| 49 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 50 | VTY_NEWLINE); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | if (IS_ZEBRA_DEBUG_SEND) |
| 55 | vty_out (vty, " Zebra packet send%s debugging is on%s", |
| 56 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 57 | VTY_NEWLINE); |
| 58 | else |
| 59 | vty_out (vty, " Zebra packet receive%s debugging is on%s", |
| 60 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 61 | VTY_NEWLINE); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | if (IS_ZEBRA_DEBUG_KERNEL) |
| 66 | vty_out (vty, " Zebra kernel debugging is on%s", VTY_NEWLINE); |
| 67 | |
| 68 | return CMD_SUCCESS; |
| 69 | } |
| 70 | |
| 71 | DEFUN (debug_zebra_events, |
| 72 | debug_zebra_events_cmd, |
| 73 | "debug zebra events", |
| 74 | DEBUG_STR |
| 75 | "Zebra configuration\n" |
| 76 | "Debug option set for zebra events\n") |
| 77 | { |
| 78 | zebra_debug_event = ZEBRA_DEBUG_EVENT; |
| 79 | return CMD_WARNING; |
| 80 | } |
| 81 | |
| 82 | DEFUN (debug_zebra_packet, |
| 83 | debug_zebra_packet_cmd, |
| 84 | "debug zebra packet", |
| 85 | DEBUG_STR |
| 86 | "Zebra configuration\n" |
| 87 | "Debug option set for zebra packet\n") |
| 88 | { |
| 89 | zebra_debug_packet = ZEBRA_DEBUG_PACKET; |
| 90 | zebra_debug_packet |= ZEBRA_DEBUG_SEND; |
| 91 | zebra_debug_packet |= ZEBRA_DEBUG_RECV; |
| 92 | return CMD_SUCCESS; |
| 93 | } |
| 94 | |
| 95 | DEFUN (debug_zebra_packet_direct, |
| 96 | debug_zebra_packet_direct_cmd, |
| 97 | "debug zebra packet (recv|send)", |
| 98 | DEBUG_STR |
| 99 | "Zebra configuration\n" |
| 100 | "Debug option set for zebra packet\n" |
| 101 | "Debug option set for receive packet\n" |
| 102 | "Debug option set for send packet\n") |
| 103 | { |
| 104 | zebra_debug_packet = ZEBRA_DEBUG_PACKET; |
| 105 | if (strncmp ("send", argv[0], strlen (argv[0])) == 0) |
| 106 | zebra_debug_packet |= ZEBRA_DEBUG_SEND; |
| 107 | if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) |
| 108 | zebra_debug_packet |= ZEBRA_DEBUG_RECV; |
| 109 | zebra_debug_packet &= ~ZEBRA_DEBUG_DETAIL; |
| 110 | return CMD_SUCCESS; |
| 111 | } |
| 112 | |
| 113 | DEFUN (debug_zebra_packet_detail, |
| 114 | debug_zebra_packet_detail_cmd, |
| 115 | "debug zebra packet (recv|send) detail", |
| 116 | DEBUG_STR |
| 117 | "Zebra configuration\n" |
| 118 | "Debug option set for zebra packet\n" |
| 119 | "Debug option set for receive packet\n" |
| 120 | "Debug option set for send packet\n" |
| 121 | "Debug option set detaied information\n") |
| 122 | { |
| 123 | zebra_debug_packet = ZEBRA_DEBUG_PACKET; |
| 124 | if (strncmp ("send", argv[0], strlen (argv[0])) == 0) |
| 125 | zebra_debug_packet |= ZEBRA_DEBUG_SEND; |
| 126 | if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) |
| 127 | zebra_debug_packet |= ZEBRA_DEBUG_RECV; |
| 128 | zebra_debug_packet |= ZEBRA_DEBUG_DETAIL; |
| 129 | return CMD_SUCCESS; |
| 130 | } |
| 131 | |
| 132 | DEFUN (debug_zebra_kernel, |
| 133 | debug_zebra_kernel_cmd, |
| 134 | "debug zebra kernel", |
| 135 | DEBUG_STR |
| 136 | "Zebra configuration\n" |
| 137 | "Debug option set for zebra between kernel interface\n") |
| 138 | { |
| 139 | zebra_debug_kernel = ZEBRA_DEBUG_KERNEL; |
| 140 | return CMD_SUCCESS; |
| 141 | } |
| 142 | |
| 143 | DEFUN (no_debug_zebra_events, |
| 144 | no_debug_zebra_events_cmd, |
| 145 | "no debug zebra events", |
| 146 | NO_STR |
| 147 | DEBUG_STR |
| 148 | "Zebra configuration\n" |
| 149 | "Debug option set for zebra events\n") |
| 150 | { |
| 151 | zebra_debug_event = 0; |
| 152 | return CMD_SUCCESS; |
| 153 | } |
| 154 | |
| 155 | DEFUN (no_debug_zebra_packet, |
| 156 | no_debug_zebra_packet_cmd, |
| 157 | "no debug zebra packet", |
| 158 | NO_STR |
| 159 | DEBUG_STR |
| 160 | "Zebra configuration\n" |
| 161 | "Debug option set for zebra packet\n") |
| 162 | { |
| 163 | zebra_debug_packet = 0; |
| 164 | return CMD_SUCCESS; |
| 165 | } |
| 166 | |
| 167 | DEFUN (no_debug_zebra_packet_direct, |
| 168 | no_debug_zebra_packet_direct_cmd, |
| 169 | "no debug zebra packet (recv|send)", |
| 170 | NO_STR |
| 171 | DEBUG_STR |
| 172 | "Zebra configuration\n" |
| 173 | "Debug option set for zebra packet\n" |
| 174 | "Debug option set for receive packet\n" |
| 175 | "Debug option set for send packet\n") |
| 176 | { |
| 177 | if (strncmp ("send", argv[0], strlen (argv[0])) == 0) |
| 178 | zebra_debug_packet &= ~ZEBRA_DEBUG_SEND; |
| 179 | if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) |
| 180 | zebra_debug_packet &= ~ZEBRA_DEBUG_RECV; |
| 181 | return CMD_SUCCESS; |
| 182 | } |
| 183 | |
| 184 | DEFUN (no_debug_zebra_kernel, |
| 185 | no_debug_zebra_kernel_cmd, |
| 186 | "no debug zebra kernel", |
| 187 | NO_STR |
| 188 | DEBUG_STR |
| 189 | "Zebra configuration\n" |
| 190 | "Debug option set for zebra between kernel interface\n") |
| 191 | { |
| 192 | zebra_debug_kernel = 0; |
| 193 | return CMD_SUCCESS; |
| 194 | } |
| 195 | |
| 196 | /* Debug node. */ |
| 197 | struct cmd_node debug_node = |
| 198 | { |
| 199 | DEBUG_NODE, |
| 200 | "", /* Debug node has no interface. */ |
| 201 | 1 |
| 202 | }; |
| 203 | |
| 204 | int |
| 205 | config_write_debug (struct vty *vty) |
| 206 | { |
| 207 | int write = 0; |
| 208 | |
| 209 | if (IS_ZEBRA_DEBUG_EVENT) |
| 210 | { |
| 211 | vty_out (vty, "debug zebra events%s", VTY_NEWLINE); |
| 212 | write++; |
| 213 | } |
| 214 | if (IS_ZEBRA_DEBUG_PACKET) |
| 215 | { |
| 216 | if (IS_ZEBRA_DEBUG_SEND && IS_ZEBRA_DEBUG_RECV) |
| 217 | { |
| 218 | vty_out (vty, "debug zebra packet%s%s", |
| 219 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 220 | VTY_NEWLINE); |
| 221 | write++; |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | if (IS_ZEBRA_DEBUG_SEND) |
| 226 | vty_out (vty, "debug zebra packet send%s%s", |
| 227 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 228 | VTY_NEWLINE); |
| 229 | else |
| 230 | vty_out (vty, "debug zebra packet recv%s%s", |
| 231 | IS_ZEBRA_DEBUG_DETAIL ? " detail" : "", |
| 232 | VTY_NEWLINE); |
| 233 | write++; |
| 234 | } |
| 235 | } |
| 236 | if (IS_ZEBRA_DEBUG_KERNEL) |
| 237 | { |
| 238 | vty_out (vty, "debug zebra kernel%s", VTY_NEWLINE); |
| 239 | write++; |
| 240 | } |
| 241 | return write; |
| 242 | } |
| 243 | |
| 244 | void |
| 245 | zebra_debug_init () |
| 246 | { |
| 247 | zebra_debug_event = 0; |
| 248 | zebra_debug_packet = 0; |
| 249 | |
| 250 | install_node (&debug_node, config_write_debug); |
| 251 | |
| 252 | install_element (VIEW_NODE, &show_debugging_zebra_cmd); |
| 253 | |
| 254 | install_element (ENABLE_NODE, &show_debugging_zebra_cmd); |
| 255 | install_element (ENABLE_NODE, &debug_zebra_events_cmd); |
| 256 | install_element (ENABLE_NODE, &debug_zebra_packet_cmd); |
| 257 | install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd); |
| 258 | install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd); |
| 259 | install_element (ENABLE_NODE, &debug_zebra_kernel_cmd); |
| 260 | install_element (ENABLE_NODE, &no_debug_zebra_events_cmd); |
| 261 | install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd); |
| 262 | install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd); |
| 263 | |
| 264 | install_element (CONFIG_NODE, &debug_zebra_events_cmd); |
| 265 | install_element (CONFIG_NODE, &debug_zebra_packet_cmd); |
| 266 | install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd); |
| 267 | install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd); |
| 268 | install_element (CONFIG_NODE, &debug_zebra_kernel_cmd); |
| 269 | install_element (CONFIG_NODE, &no_debug_zebra_events_cmd); |
| 270 | install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd); |
| 271 | install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd); |
| 272 | } |