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