paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* RIP debug routines |
| 2 | * Copyright (C) 1999 Kunihiro Ishiguro <kunihiro@zebra.org> |
| 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 | |
| 22 | #include <zebra.h> |
| 23 | #include "command.h" |
| 24 | #include "ripd/rip_debug.h" |
| 25 | |
| 26 | /* For debug statement. */ |
| 27 | unsigned long rip_debug_event = 0; |
| 28 | unsigned long rip_debug_packet = 0; |
| 29 | unsigned long rip_debug_zebra = 0; |
| 30 | |
| 31 | DEFUN (show_debugging_rip, |
| 32 | show_debugging_rip_cmd, |
| 33 | "show debugging rip", |
| 34 | SHOW_STR |
| 35 | DEBUG_STR |
| 36 | RIP_STR) |
| 37 | { |
hasso | df43a13 | 2004-08-31 12:04:33 +0000 | [diff] [blame] | 38 | vty_out (vty, "RIP debugging status:%s", VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 39 | |
| 40 | if (IS_RIP_DEBUG_EVENT) |
| 41 | vty_out (vty, " RIP event debugging is on%s", VTY_NEWLINE); |
| 42 | |
| 43 | if (IS_RIP_DEBUG_PACKET) |
| 44 | { |
| 45 | if (IS_RIP_DEBUG_SEND && IS_RIP_DEBUG_RECV) |
| 46 | { |
| 47 | vty_out (vty, " RIP packet%s debugging is on%s", |
| 48 | IS_RIP_DEBUG_DETAIL ? " detail" : "", |
| 49 | VTY_NEWLINE); |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | if (IS_RIP_DEBUG_SEND) |
| 54 | vty_out (vty, " RIP packet send%s debugging is on%s", |
| 55 | IS_RIP_DEBUG_DETAIL ? " detail" : "", |
| 56 | VTY_NEWLINE); |
| 57 | else |
| 58 | vty_out (vty, " RIP packet receive%s debugging is on%s", |
| 59 | IS_RIP_DEBUG_DETAIL ? " detail" : "", |
| 60 | VTY_NEWLINE); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if (IS_RIP_DEBUG_ZEBRA) |
| 65 | vty_out (vty, " RIP zebra debugging is on%s", VTY_NEWLINE); |
| 66 | |
| 67 | return CMD_SUCCESS; |
| 68 | } |
| 69 | |
| 70 | DEFUN (debug_rip_events, |
| 71 | debug_rip_events_cmd, |
| 72 | "debug rip events", |
| 73 | DEBUG_STR |
| 74 | RIP_STR |
| 75 | "RIP events\n") |
| 76 | { |
| 77 | rip_debug_event = RIP_DEBUG_EVENT; |
| 78 | return CMD_WARNING; |
| 79 | } |
| 80 | |
| 81 | DEFUN (debug_rip_packet, |
| 82 | debug_rip_packet_cmd, |
| 83 | "debug rip packet", |
| 84 | DEBUG_STR |
| 85 | RIP_STR |
| 86 | "RIP packet\n") |
| 87 | { |
| 88 | rip_debug_packet = RIP_DEBUG_PACKET; |
| 89 | rip_debug_packet |= RIP_DEBUG_SEND; |
| 90 | rip_debug_packet |= RIP_DEBUG_RECV; |
| 91 | return CMD_SUCCESS; |
| 92 | } |
| 93 | |
| 94 | DEFUN (debug_rip_packet_direct, |
| 95 | debug_rip_packet_direct_cmd, |
| 96 | "debug rip packet (recv|send)", |
| 97 | DEBUG_STR |
| 98 | RIP_STR |
| 99 | "RIP packet\n" |
| 100 | "RIP receive packet\n" |
| 101 | "RIP send packet\n") |
| 102 | { |
| 103 | rip_debug_packet |= RIP_DEBUG_PACKET; |
| 104 | if (strncmp ("send", argv[0], strlen (argv[0])) == 0) |
| 105 | rip_debug_packet |= RIP_DEBUG_SEND; |
| 106 | if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) |
| 107 | rip_debug_packet |= RIP_DEBUG_RECV; |
| 108 | rip_debug_packet &= ~RIP_DEBUG_DETAIL; |
| 109 | return CMD_SUCCESS; |
| 110 | } |
| 111 | |
| 112 | DEFUN (debug_rip_packet_detail, |
| 113 | debug_rip_packet_detail_cmd, |
| 114 | "debug rip packet (recv|send) detail", |
| 115 | DEBUG_STR |
| 116 | RIP_STR |
| 117 | "RIP packet\n" |
| 118 | "RIP receive packet\n" |
| 119 | "RIP send packet\n" |
| 120 | "Detailed information display\n") |
| 121 | { |
| 122 | rip_debug_packet |= RIP_DEBUG_PACKET; |
| 123 | if (strncmp ("send", argv[0], strlen (argv[0])) == 0) |
| 124 | rip_debug_packet |= RIP_DEBUG_SEND; |
| 125 | if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) |
| 126 | rip_debug_packet |= RIP_DEBUG_RECV; |
| 127 | rip_debug_packet |= RIP_DEBUG_DETAIL; |
| 128 | return CMD_SUCCESS; |
| 129 | } |
| 130 | |
| 131 | DEFUN (debug_rip_zebra, |
| 132 | debug_rip_zebra_cmd, |
| 133 | "debug rip zebra", |
| 134 | DEBUG_STR |
| 135 | RIP_STR |
| 136 | "RIP and ZEBRA communication\n") |
| 137 | { |
| 138 | rip_debug_zebra = RIP_DEBUG_ZEBRA; |
| 139 | return CMD_WARNING; |
| 140 | } |
| 141 | |
| 142 | DEFUN (no_debug_rip_events, |
| 143 | no_debug_rip_events_cmd, |
| 144 | "no debug rip events", |
| 145 | NO_STR |
| 146 | DEBUG_STR |
| 147 | RIP_STR |
| 148 | "RIP events\n") |
| 149 | { |
| 150 | rip_debug_event = 0; |
| 151 | return CMD_SUCCESS; |
| 152 | } |
| 153 | |
| 154 | DEFUN (no_debug_rip_packet, |
| 155 | no_debug_rip_packet_cmd, |
| 156 | "no debug rip packet", |
| 157 | NO_STR |
| 158 | DEBUG_STR |
| 159 | RIP_STR |
| 160 | "RIP packet\n") |
| 161 | { |
| 162 | rip_debug_packet = 0; |
| 163 | return CMD_SUCCESS; |
| 164 | } |
| 165 | |
| 166 | DEFUN (no_debug_rip_packet_direct, |
| 167 | no_debug_rip_packet_direct_cmd, |
| 168 | "no debug rip packet (recv|send)", |
| 169 | NO_STR |
| 170 | DEBUG_STR |
| 171 | RIP_STR |
| 172 | "RIP packet\n" |
| 173 | "RIP option set for receive packet\n" |
| 174 | "RIP option set for send packet\n") |
| 175 | { |
| 176 | if (strncmp ("send", argv[0], strlen (argv[0])) == 0) |
| 177 | { |
| 178 | if (IS_RIP_DEBUG_RECV) |
| 179 | rip_debug_packet &= ~RIP_DEBUG_SEND; |
| 180 | else |
| 181 | rip_debug_packet = 0; |
| 182 | } |
| 183 | else if (strncmp ("recv", argv[0], strlen (argv[0])) == 0) |
| 184 | { |
| 185 | if (IS_RIP_DEBUG_SEND) |
| 186 | rip_debug_packet &= ~RIP_DEBUG_RECV; |
| 187 | else |
| 188 | rip_debug_packet = 0; |
| 189 | } |
| 190 | return CMD_SUCCESS; |
| 191 | } |
| 192 | |
| 193 | DEFUN (no_debug_rip_zebra, |
| 194 | no_debug_rip_zebra_cmd, |
| 195 | "no debug rip zebra", |
| 196 | NO_STR |
| 197 | DEBUG_STR |
| 198 | RIP_STR |
| 199 | "RIP and ZEBRA communication\n") |
| 200 | { |
| 201 | rip_debug_zebra = 0; |
| 202 | return CMD_WARNING; |
| 203 | } |
| 204 | |
| 205 | /* Debug node. */ |
Stephen Hemminger | 7fc626d | 2008-12-01 11:10:34 -0800 | [diff] [blame^] | 206 | static struct cmd_node debug_node = |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 207 | { |
| 208 | DEBUG_NODE, |
| 209 | "", /* Debug node has no interface. */ |
| 210 | 1 |
| 211 | }; |
| 212 | |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 213 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 214 | config_write_debug (struct vty *vty) |
| 215 | { |
| 216 | int write = 0; |
| 217 | |
| 218 | if (IS_RIP_DEBUG_EVENT) |
| 219 | { |
| 220 | vty_out (vty, "debug rip events%s", VTY_NEWLINE); |
| 221 | write++; |
| 222 | } |
| 223 | if (IS_RIP_DEBUG_PACKET) |
| 224 | { |
| 225 | if (IS_RIP_DEBUG_SEND && IS_RIP_DEBUG_RECV) |
| 226 | { |
| 227 | vty_out (vty, "debug rip packet%s%s", |
| 228 | IS_RIP_DEBUG_DETAIL ? " detail" : "", |
| 229 | VTY_NEWLINE); |
| 230 | write++; |
| 231 | } |
| 232 | else |
| 233 | { |
| 234 | if (IS_RIP_DEBUG_SEND) |
| 235 | vty_out (vty, "debug rip packet send%s%s", |
| 236 | IS_RIP_DEBUG_DETAIL ? " detail" : "", |
| 237 | VTY_NEWLINE); |
| 238 | else |
| 239 | vty_out (vty, "debug rip packet recv%s%s", |
| 240 | IS_RIP_DEBUG_DETAIL ? " detail" : "", |
| 241 | VTY_NEWLINE); |
| 242 | write++; |
| 243 | } |
| 244 | } |
| 245 | if (IS_RIP_DEBUG_ZEBRA) |
| 246 | { |
| 247 | vty_out (vty, "debug rip zebra%s", VTY_NEWLINE); |
| 248 | write++; |
| 249 | } |
| 250 | return write; |
| 251 | } |
| 252 | |
| 253 | void |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 254 | rip_debug_reset (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 255 | { |
| 256 | rip_debug_event = 0; |
| 257 | rip_debug_packet = 0; |
| 258 | rip_debug_zebra = 0; |
| 259 | } |
| 260 | |
| 261 | void |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 262 | rip_debug_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 263 | { |
| 264 | rip_debug_event = 0; |
| 265 | rip_debug_packet = 0; |
| 266 | rip_debug_zebra = 0; |
| 267 | |
| 268 | install_node (&debug_node, config_write_debug); |
| 269 | |
| 270 | install_element (ENABLE_NODE, &show_debugging_rip_cmd); |
| 271 | install_element (ENABLE_NODE, &debug_rip_events_cmd); |
| 272 | install_element (ENABLE_NODE, &debug_rip_packet_cmd); |
| 273 | install_element (ENABLE_NODE, &debug_rip_packet_direct_cmd); |
| 274 | install_element (ENABLE_NODE, &debug_rip_packet_detail_cmd); |
| 275 | install_element (ENABLE_NODE, &debug_rip_zebra_cmd); |
| 276 | install_element (ENABLE_NODE, &no_debug_rip_events_cmd); |
| 277 | install_element (ENABLE_NODE, &no_debug_rip_packet_cmd); |
| 278 | install_element (ENABLE_NODE, &no_debug_rip_packet_direct_cmd); |
| 279 | install_element (ENABLE_NODE, &no_debug_rip_zebra_cmd); |
| 280 | |
| 281 | install_element (CONFIG_NODE, &debug_rip_events_cmd); |
| 282 | install_element (CONFIG_NODE, &debug_rip_packet_cmd); |
| 283 | install_element (CONFIG_NODE, &debug_rip_packet_direct_cmd); |
| 284 | install_element (CONFIG_NODE, &debug_rip_packet_detail_cmd); |
| 285 | install_element (CONFIG_NODE, &debug_rip_zebra_cmd); |
| 286 | install_element (CONFIG_NODE, &no_debug_rip_events_cmd); |
| 287 | install_element (CONFIG_NODE, &no_debug_rip_packet_cmd); |
| 288 | install_element (CONFIG_NODE, &no_debug_rip_packet_direct_cmd); |
| 289 | install_element (CONFIG_NODE, &no_debug_rip_zebra_cmd); |
| 290 | } |