blob: 662e5843a6ced9042d76b4982b56276edb7ec347 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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. */
27unsigned long rip_debug_event = 0;
28unsigned long rip_debug_packet = 0;
29unsigned long rip_debug_zebra = 0;
30
31DEFUN (show_debugging_rip,
32 show_debugging_rip_cmd,
33 "show debugging rip",
34 SHOW_STR
35 DEBUG_STR
36 RIP_STR)
37{
hassodf43a132004-08-31 12:04:33 +000038 vty_out (vty, "RIP debugging status:%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000039
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 {
Andrew J. Schorr0fa03352011-02-24 13:52:14 +030047 vty_out (vty, " RIP packet debugging is on%s",
paul718e3742002-12-13 20:15:29 +000048 VTY_NEWLINE);
49 }
50 else
51 {
52 if (IS_RIP_DEBUG_SEND)
Andrew J. Schorr0fa03352011-02-24 13:52:14 +030053 vty_out (vty, " RIP packet send debugging is on%s",
paul718e3742002-12-13 20:15:29 +000054 VTY_NEWLINE);
55 else
Andrew J. Schorr0fa03352011-02-24 13:52:14 +030056 vty_out (vty, " RIP packet receive debugging is on%s",
paul718e3742002-12-13 20:15:29 +000057 VTY_NEWLINE);
58 }
59 }
60
61 if (IS_RIP_DEBUG_ZEBRA)
62 vty_out (vty, " RIP zebra debugging is on%s", VTY_NEWLINE);
63
64 return CMD_SUCCESS;
65}
66
67DEFUN (debug_rip_events,
68 debug_rip_events_cmd,
69 "debug rip events",
70 DEBUG_STR
71 RIP_STR
72 "RIP events\n")
73{
74 rip_debug_event = RIP_DEBUG_EVENT;
75 return CMD_WARNING;
76}
77
78DEFUN (debug_rip_packet,
79 debug_rip_packet_cmd,
80 "debug rip packet",
81 DEBUG_STR
82 RIP_STR
83 "RIP packet\n")
84{
85 rip_debug_packet = RIP_DEBUG_PACKET;
86 rip_debug_packet |= RIP_DEBUG_SEND;
87 rip_debug_packet |= RIP_DEBUG_RECV;
88 return CMD_SUCCESS;
89}
90
91DEFUN (debug_rip_packet_direct,
92 debug_rip_packet_direct_cmd,
93 "debug rip packet (recv|send)",
94 DEBUG_STR
95 RIP_STR
96 "RIP packet\n"
97 "RIP receive packet\n"
98 "RIP send packet\n")
99{
100 rip_debug_packet |= RIP_DEBUG_PACKET;
101 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
102 rip_debug_packet |= RIP_DEBUG_SEND;
103 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
104 rip_debug_packet |= RIP_DEBUG_RECV;
paul718e3742002-12-13 20:15:29 +0000105 return CMD_SUCCESS;
106}
107
Andrew J. Schorr0fa03352011-02-24 13:52:14 +0300108/* N.B. the "detail" modifier is a no-op. we leave this command
109 for legacy compatibility. */
110DEFUN_DEPRECATED (debug_rip_packet_detail,
paul718e3742002-12-13 20:15:29 +0000111 debug_rip_packet_detail_cmd,
112 "debug rip packet (recv|send) detail",
113 DEBUG_STR
114 RIP_STR
115 "RIP packet\n"
116 "RIP receive packet\n"
117 "RIP send packet\n"
118 "Detailed information display\n")
119{
120 rip_debug_packet |= RIP_DEBUG_PACKET;
121 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
122 rip_debug_packet |= RIP_DEBUG_SEND;
123 if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
124 rip_debug_packet |= RIP_DEBUG_RECV;
paul718e3742002-12-13 20:15:29 +0000125 return CMD_SUCCESS;
126}
127
128DEFUN (debug_rip_zebra,
129 debug_rip_zebra_cmd,
130 "debug rip zebra",
131 DEBUG_STR
132 RIP_STR
133 "RIP and ZEBRA communication\n")
134{
135 rip_debug_zebra = RIP_DEBUG_ZEBRA;
136 return CMD_WARNING;
137}
138
139DEFUN (no_debug_rip_events,
140 no_debug_rip_events_cmd,
141 "no debug rip events",
142 NO_STR
143 DEBUG_STR
144 RIP_STR
145 "RIP events\n")
146{
147 rip_debug_event = 0;
148 return CMD_SUCCESS;
149}
150
151DEFUN (no_debug_rip_packet,
152 no_debug_rip_packet_cmd,
153 "no debug rip packet",
154 NO_STR
155 DEBUG_STR
156 RIP_STR
157 "RIP packet\n")
158{
159 rip_debug_packet = 0;
160 return CMD_SUCCESS;
161}
162
163DEFUN (no_debug_rip_packet_direct,
164 no_debug_rip_packet_direct_cmd,
165 "no debug rip packet (recv|send)",
166 NO_STR
167 DEBUG_STR
168 RIP_STR
169 "RIP packet\n"
170 "RIP option set for receive packet\n"
171 "RIP option set for send packet\n")
172{
173 if (strncmp ("send", argv[0], strlen (argv[0])) == 0)
174 {
175 if (IS_RIP_DEBUG_RECV)
176 rip_debug_packet &= ~RIP_DEBUG_SEND;
177 else
178 rip_debug_packet = 0;
179 }
180 else if (strncmp ("recv", argv[0], strlen (argv[0])) == 0)
181 {
182 if (IS_RIP_DEBUG_SEND)
183 rip_debug_packet &= ~RIP_DEBUG_RECV;
184 else
185 rip_debug_packet = 0;
186 }
187 return CMD_SUCCESS;
188}
189
190DEFUN (no_debug_rip_zebra,
191 no_debug_rip_zebra_cmd,
192 "no debug rip zebra",
193 NO_STR
194 DEBUG_STR
195 RIP_STR
196 "RIP and ZEBRA communication\n")
197{
198 rip_debug_zebra = 0;
199 return CMD_WARNING;
200}
201
202/* Debug node. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800203static struct cmd_node debug_node =
paul718e3742002-12-13 20:15:29 +0000204{
205 DEBUG_NODE,
206 "", /* Debug node has no interface. */
207 1
208};
209
pauldc63bfd2005-10-25 23:31:05 +0000210static int
paul718e3742002-12-13 20:15:29 +0000211config_write_debug (struct vty *vty)
212{
213 int write = 0;
214
215 if (IS_RIP_DEBUG_EVENT)
216 {
217 vty_out (vty, "debug rip events%s", VTY_NEWLINE);
218 write++;
219 }
220 if (IS_RIP_DEBUG_PACKET)
221 {
222 if (IS_RIP_DEBUG_SEND && IS_RIP_DEBUG_RECV)
223 {
Andrew J. Schorr0fa03352011-02-24 13:52:14 +0300224 vty_out (vty, "debug rip packet%s",
paul718e3742002-12-13 20:15:29 +0000225 VTY_NEWLINE);
226 write++;
227 }
228 else
229 {
230 if (IS_RIP_DEBUG_SEND)
Andrew J. Schorr0fa03352011-02-24 13:52:14 +0300231 vty_out (vty, "debug rip packet send%s",
paul718e3742002-12-13 20:15:29 +0000232 VTY_NEWLINE);
233 else
Andrew J. Schorr0fa03352011-02-24 13:52:14 +0300234 vty_out (vty, "debug rip packet recv%s",
paul718e3742002-12-13 20:15:29 +0000235 VTY_NEWLINE);
236 write++;
237 }
238 }
239 if (IS_RIP_DEBUG_ZEBRA)
240 {
241 vty_out (vty, "debug rip zebra%s", VTY_NEWLINE);
242 write++;
243 }
244 return write;
245}
246
247void
pauldc63bfd2005-10-25 23:31:05 +0000248rip_debug_reset (void)
paul718e3742002-12-13 20:15:29 +0000249{
250 rip_debug_event = 0;
251 rip_debug_packet = 0;
252 rip_debug_zebra = 0;
253}
254
255void
pauldc63bfd2005-10-25 23:31:05 +0000256rip_debug_init (void)
paul718e3742002-12-13 20:15:29 +0000257{
258 rip_debug_event = 0;
259 rip_debug_packet = 0;
260 rip_debug_zebra = 0;
261
262 install_node (&debug_node, config_write_debug);
263
264 install_element (ENABLE_NODE, &show_debugging_rip_cmd);
265 install_element (ENABLE_NODE, &debug_rip_events_cmd);
266 install_element (ENABLE_NODE, &debug_rip_packet_cmd);
267 install_element (ENABLE_NODE, &debug_rip_packet_direct_cmd);
268 install_element (ENABLE_NODE, &debug_rip_packet_detail_cmd);
269 install_element (ENABLE_NODE, &debug_rip_zebra_cmd);
270 install_element (ENABLE_NODE, &no_debug_rip_events_cmd);
271 install_element (ENABLE_NODE, &no_debug_rip_packet_cmd);
272 install_element (ENABLE_NODE, &no_debug_rip_packet_direct_cmd);
273 install_element (ENABLE_NODE, &no_debug_rip_zebra_cmd);
274
275 install_element (CONFIG_NODE, &debug_rip_events_cmd);
276 install_element (CONFIG_NODE, &debug_rip_packet_cmd);
277 install_element (CONFIG_NODE, &debug_rip_packet_direct_cmd);
278 install_element (CONFIG_NODE, &debug_rip_packet_detail_cmd);
279 install_element (CONFIG_NODE, &debug_rip_zebra_cmd);
280 install_element (CONFIG_NODE, &no_debug_rip_events_cmd);
281 install_element (CONFIG_NODE, &no_debug_rip_packet_cmd);
282 install_element (CONFIG_NODE, &no_debug_rip_packet_direct_cmd);
283 install_element (CONFIG_NODE, &no_debug_rip_zebra_cmd);
284}