]> git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_debug.c
*: reindent
[mirror_frr.git] / ripd / rip_debug.c
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 {
38 vty_out(vty, "RIP debugging status:%s", VTY_NEWLINE);
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 if (IS_RIP_DEBUG_SEND && IS_RIP_DEBUG_RECV) {
45 vty_out(vty, " RIP packet debugging is on%s",
46 VTY_NEWLINE);
47 } else {
48 if (IS_RIP_DEBUG_SEND)
49 vty_out(vty,
50 " RIP packet send debugging is on%s",
51 VTY_NEWLINE);
52 else
53 vty_out(vty,
54 " RIP packet receive debugging is on%s",
55 VTY_NEWLINE);
56 }
57 }
58
59 if (IS_RIP_DEBUG_ZEBRA)
60 vty_out(vty, " RIP zebra debugging is on%s", VTY_NEWLINE);
61
62 return CMD_SUCCESS;
63 }
64
65 DEFUN (debug_rip_events,
66 debug_rip_events_cmd,
67 "debug rip events",
68 DEBUG_STR
69 RIP_STR
70 "RIP events\n")
71 {
72 rip_debug_event = RIP_DEBUG_EVENT;
73 return CMD_WARNING;
74 }
75
76 DEFUN (debug_rip_packet,
77 debug_rip_packet_cmd,
78 "debug rip packet",
79 DEBUG_STR
80 RIP_STR
81 "RIP packet\n")
82 {
83 rip_debug_packet = RIP_DEBUG_PACKET;
84 rip_debug_packet |= RIP_DEBUG_SEND;
85 rip_debug_packet |= RIP_DEBUG_RECV;
86 return CMD_SUCCESS;
87 }
88
89 DEFUN (debug_rip_packet_direct,
90 debug_rip_packet_direct_cmd,
91 "debug rip packet <recv|send>",
92 DEBUG_STR
93 RIP_STR
94 "RIP packet\n"
95 "RIP receive packet\n"
96 "RIP send packet\n")
97 {
98 int idx_recv_send = 3;
99 rip_debug_packet |= RIP_DEBUG_PACKET;
100 if (strncmp("send", argv[idx_recv_send]->arg,
101 strlen(argv[idx_recv_send]->arg))
102 == 0)
103 rip_debug_packet |= RIP_DEBUG_SEND;
104 if (strncmp("recv", argv[idx_recv_send]->arg,
105 strlen(argv[idx_recv_send]->arg))
106 == 0)
107 rip_debug_packet |= RIP_DEBUG_RECV;
108 return CMD_SUCCESS;
109 }
110
111 DEFUN (debug_rip_zebra,
112 debug_rip_zebra_cmd,
113 "debug rip zebra",
114 DEBUG_STR
115 RIP_STR
116 "RIP and ZEBRA communication\n")
117 {
118 rip_debug_zebra = RIP_DEBUG_ZEBRA;
119 return CMD_WARNING;
120 }
121
122 DEFUN (no_debug_rip_events,
123 no_debug_rip_events_cmd,
124 "no debug rip events",
125 NO_STR
126 DEBUG_STR
127 RIP_STR
128 "RIP events\n")
129 {
130 rip_debug_event = 0;
131 return CMD_SUCCESS;
132 }
133
134 DEFUN (no_debug_rip_packet,
135 no_debug_rip_packet_cmd,
136 "no debug rip packet",
137 NO_STR
138 DEBUG_STR
139 RIP_STR
140 "RIP packet\n")
141 {
142 rip_debug_packet = 0;
143 return CMD_SUCCESS;
144 }
145
146 DEFUN (no_debug_rip_packet_direct,
147 no_debug_rip_packet_direct_cmd,
148 "no debug rip packet <recv|send>",
149 NO_STR
150 DEBUG_STR
151 RIP_STR
152 "RIP packet\n"
153 "RIP option set for receive packet\n"
154 "RIP option set for send packet\n")
155 {
156 int idx_recv_send = 4;
157 if (strncmp("send", argv[idx_recv_send]->arg,
158 strlen(argv[idx_recv_send]->arg))
159 == 0) {
160 if (IS_RIP_DEBUG_RECV)
161 rip_debug_packet &= ~RIP_DEBUG_SEND;
162 else
163 rip_debug_packet = 0;
164 } else if (strncmp("recv", argv[idx_recv_send]->arg,
165 strlen(argv[idx_recv_send]->arg))
166 == 0) {
167 if (IS_RIP_DEBUG_SEND)
168 rip_debug_packet &= ~RIP_DEBUG_RECV;
169 else
170 rip_debug_packet = 0;
171 }
172 return CMD_SUCCESS;
173 }
174
175 DEFUN (no_debug_rip_zebra,
176 no_debug_rip_zebra_cmd,
177 "no debug rip zebra",
178 NO_STR
179 DEBUG_STR
180 RIP_STR
181 "RIP and ZEBRA communication\n")
182 {
183 rip_debug_zebra = 0;
184 return CMD_WARNING;
185 }
186
187 /* Debug node. */
188 static struct cmd_node debug_node = {DEBUG_NODE,
189 "", /* Debug node has no interface. */
190 1};
191
192 static int config_write_debug(struct vty *vty)
193 {
194 int write = 0;
195
196 if (IS_RIP_DEBUG_EVENT) {
197 vty_out(vty, "debug rip events%s", VTY_NEWLINE);
198 write++;
199 }
200 if (IS_RIP_DEBUG_PACKET) {
201 if (IS_RIP_DEBUG_SEND && IS_RIP_DEBUG_RECV) {
202 vty_out(vty, "debug rip packet%s", VTY_NEWLINE);
203 write++;
204 } else {
205 if (IS_RIP_DEBUG_SEND)
206 vty_out(vty, "debug rip packet send%s",
207 VTY_NEWLINE);
208 else
209 vty_out(vty, "debug rip packet recv%s",
210 VTY_NEWLINE);
211 write++;
212 }
213 }
214 if (IS_RIP_DEBUG_ZEBRA) {
215 vty_out(vty, "debug rip zebra%s", VTY_NEWLINE);
216 write++;
217 }
218 return write;
219 }
220
221 void rip_debug_reset(void)
222 {
223 rip_debug_event = 0;
224 rip_debug_packet = 0;
225 rip_debug_zebra = 0;
226 }
227
228 void rip_debug_init(void)
229 {
230 rip_debug_event = 0;
231 rip_debug_packet = 0;
232 rip_debug_zebra = 0;
233
234 install_node(&debug_node, config_write_debug);
235
236 install_element(ENABLE_NODE, &show_debugging_rip_cmd);
237 install_element(ENABLE_NODE, &debug_rip_events_cmd);
238 install_element(ENABLE_NODE, &debug_rip_packet_cmd);
239 install_element(ENABLE_NODE, &debug_rip_packet_direct_cmd);
240 install_element(ENABLE_NODE, &debug_rip_zebra_cmd);
241 install_element(ENABLE_NODE, &no_debug_rip_events_cmd);
242 install_element(ENABLE_NODE, &no_debug_rip_packet_cmd);
243 install_element(ENABLE_NODE, &no_debug_rip_packet_direct_cmd);
244 install_element(ENABLE_NODE, &no_debug_rip_zebra_cmd);
245
246 install_element(CONFIG_NODE, &debug_rip_events_cmd);
247 install_element(CONFIG_NODE, &debug_rip_packet_cmd);
248 install_element(CONFIG_NODE, &debug_rip_packet_direct_cmd);
249 install_element(CONFIG_NODE, &debug_rip_zebra_cmd);
250 install_element(CONFIG_NODE, &no_debug_rip_events_cmd);
251 install_element(CONFIG_NODE, &no_debug_rip_packet_cmd);
252 install_element(CONFIG_NODE, &no_debug_rip_packet_direct_cmd);
253 install_element(CONFIG_NODE, &no_debug_rip_zebra_cmd);
254 }