]> git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_debug.c
Merge pull request #13349 from opensourcerouting/pim6-mld-coverity-20230421
[mirror_frr.git] / ripd / rip_debug.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* RIP debug routines
3 * Copyright (C) 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
4 */
5
6 #include <zebra.h>
7 #include "command.h"
8 #include "ripd/rip_debug.h"
9
10 /* For debug statement. */
11 unsigned long rip_debug_event = 0;
12 unsigned long rip_debug_packet = 0;
13 unsigned long rip_debug_zebra = 0;
14
15 DEFUN_NOSH (show_debugging_rip,
16 show_debugging_rip_cmd,
17 "show debugging [rip]",
18 SHOW_STR
19 DEBUG_STR
20 RIP_STR)
21 {
22 vty_out(vty, "RIP debugging status:\n");
23
24 if (IS_RIP_DEBUG_EVENT)
25 vty_out(vty, " RIP event debugging is on\n");
26
27 if (IS_RIP_DEBUG_PACKET) {
28 if (IS_RIP_DEBUG_SEND && IS_RIP_DEBUG_RECV) {
29 vty_out(vty, " RIP packet debugging is on\n");
30 } else {
31 if (IS_RIP_DEBUG_SEND)
32 vty_out(vty,
33 " RIP packet send debugging is on\n");
34 else
35 vty_out(vty,
36 " RIP packet receive debugging is on\n");
37 }
38 }
39
40 if (IS_RIP_DEBUG_ZEBRA)
41 vty_out(vty, " RIP zebra debugging is on\n");
42
43 cmd_show_lib_debugs(vty);
44
45 return CMD_SUCCESS;
46 }
47
48 DEFUN (debug_rip_events,
49 debug_rip_events_cmd,
50 "debug rip events",
51 DEBUG_STR
52 RIP_STR
53 "RIP events\n")
54 {
55 rip_debug_event = RIP_DEBUG_EVENT;
56 return CMD_SUCCESS;
57 }
58
59 DEFUN (debug_rip_packet,
60 debug_rip_packet_cmd,
61 "debug rip packet",
62 DEBUG_STR
63 RIP_STR
64 "RIP packet\n")
65 {
66 rip_debug_packet = RIP_DEBUG_PACKET;
67 rip_debug_packet |= RIP_DEBUG_SEND;
68 rip_debug_packet |= RIP_DEBUG_RECV;
69 return CMD_SUCCESS;
70 }
71
72 DEFUN (debug_rip_packet_direct,
73 debug_rip_packet_direct_cmd,
74 "debug rip packet <recv|send>",
75 DEBUG_STR
76 RIP_STR
77 "RIP packet\n"
78 "RIP receive packet\n"
79 "RIP send packet\n")
80 {
81 int idx_recv_send = 3;
82 rip_debug_packet |= RIP_DEBUG_PACKET;
83 if (strcmp("send", argv[idx_recv_send]->text) == 0)
84 rip_debug_packet |= RIP_DEBUG_SEND;
85 if (strcmp("recv", argv[idx_recv_send]->text) == 0)
86 rip_debug_packet |= RIP_DEBUG_RECV;
87 return CMD_SUCCESS;
88 }
89
90 DEFUN (debug_rip_zebra,
91 debug_rip_zebra_cmd,
92 "debug rip zebra",
93 DEBUG_STR
94 RIP_STR
95 "RIP and ZEBRA communication\n")
96 {
97 rip_debug_zebra = RIP_DEBUG_ZEBRA;
98 return CMD_SUCCESS;
99 }
100
101 DEFUN (no_debug_rip_events,
102 no_debug_rip_events_cmd,
103 "no debug rip events",
104 NO_STR
105 DEBUG_STR
106 RIP_STR
107 "RIP events\n")
108 {
109 rip_debug_event = 0;
110 return CMD_SUCCESS;
111 }
112
113 DEFUN (no_debug_rip_packet,
114 no_debug_rip_packet_cmd,
115 "no debug rip packet",
116 NO_STR
117 DEBUG_STR
118 RIP_STR
119 "RIP packet\n")
120 {
121 rip_debug_packet = 0;
122 return CMD_SUCCESS;
123 }
124
125 DEFUN (no_debug_rip_packet_direct,
126 no_debug_rip_packet_direct_cmd,
127 "no debug rip packet <recv|send>",
128 NO_STR
129 DEBUG_STR
130 RIP_STR
131 "RIP packet\n"
132 "RIP option set for receive packet\n"
133 "RIP option set for send packet\n")
134 {
135 int idx_recv_send = 4;
136 if (strcmp("send", argv[idx_recv_send]->text) == 0) {
137 if (IS_RIP_DEBUG_RECV)
138 rip_debug_packet &= ~RIP_DEBUG_SEND;
139 else
140 rip_debug_packet = 0;
141 } else if (strcmp("recv", argv[idx_recv_send]->text) == 0) {
142 if (IS_RIP_DEBUG_SEND)
143 rip_debug_packet &= ~RIP_DEBUG_RECV;
144 else
145 rip_debug_packet = 0;
146 }
147 return CMD_SUCCESS;
148 }
149
150 DEFUN (no_debug_rip_zebra,
151 no_debug_rip_zebra_cmd,
152 "no debug rip zebra",
153 NO_STR
154 DEBUG_STR
155 RIP_STR
156 "RIP and ZEBRA communication\n")
157 {
158 rip_debug_zebra = 0;
159 return CMD_SUCCESS;
160 }
161
162 static int config_write_debug(struct vty *vty);
163 /* Debug node. */
164 static struct cmd_node debug_node = {
165 .name = "debug",
166 .node = DEBUG_NODE,
167 .prompt = "",
168 .config_write = config_write_debug,
169 };
170
171 static int config_write_debug(struct vty *vty)
172 {
173 int write = 0;
174
175 if (IS_RIP_DEBUG_EVENT) {
176 vty_out(vty, "debug rip events\n");
177 write++;
178 }
179 if (IS_RIP_DEBUG_PACKET) {
180 if (IS_RIP_DEBUG_SEND && IS_RIP_DEBUG_RECV) {
181 vty_out(vty, "debug rip packet\n");
182 write++;
183 } else {
184 if (IS_RIP_DEBUG_SEND)
185 vty_out(vty, "debug rip packet send\n");
186 else
187 vty_out(vty, "debug rip packet recv\n");
188 write++;
189 }
190 }
191 if (IS_RIP_DEBUG_ZEBRA) {
192 vty_out(vty, "debug rip zebra\n");
193 write++;
194 }
195 return write;
196 }
197
198 void rip_debug_init(void)
199 {
200 rip_debug_event = 0;
201 rip_debug_packet = 0;
202 rip_debug_zebra = 0;
203
204 install_node(&debug_node);
205
206 install_element(ENABLE_NODE, &show_debugging_rip_cmd);
207 install_element(ENABLE_NODE, &debug_rip_events_cmd);
208 install_element(ENABLE_NODE, &debug_rip_packet_cmd);
209 install_element(ENABLE_NODE, &debug_rip_packet_direct_cmd);
210 install_element(ENABLE_NODE, &debug_rip_zebra_cmd);
211 install_element(ENABLE_NODE, &no_debug_rip_events_cmd);
212 install_element(ENABLE_NODE, &no_debug_rip_packet_cmd);
213 install_element(ENABLE_NODE, &no_debug_rip_packet_direct_cmd);
214 install_element(ENABLE_NODE, &no_debug_rip_zebra_cmd);
215
216 install_element(CONFIG_NODE, &debug_rip_events_cmd);
217 install_element(CONFIG_NODE, &debug_rip_packet_cmd);
218 install_element(CONFIG_NODE, &debug_rip_packet_direct_cmd);
219 install_element(CONFIG_NODE, &debug_rip_zebra_cmd);
220 install_element(CONFIG_NODE, &no_debug_rip_events_cmd);
221 install_element(CONFIG_NODE, &no_debug_rip_packet_cmd);
222 install_element(CONFIG_NODE, &no_debug_rip_packet_direct_cmd);
223 install_element(CONFIG_NODE, &no_debug_rip_zebra_cmd);
224 }