]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_dump.c
Start of new ospf6d merge from Zebra.
[mirror_frr.git] / ospf6d / ospf6_dump.c
CommitLineData
718e3744 1/*
2 * Logging function
3 * Copyright (C) 1999-2002 Yasuhiro Ohara
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
25/* Include other stuffs */
26#include "log.h"
27#include "command.h"
28#include "ospf6_dump.h"
29
30#define CMD_SHOW 0
31#define CMD_ENABLE 1
32#define CMD_DISABLE 2
33#define CMD_MAX 3
34
35struct ospf6_dump
36{
37 struct cmd_element cmd[CMD_MAX];
38 char *name;
39 int config;
40};
41
42#define DUMP_MAX 512
43struct ospf6_dump *ospf6_dump[DUMP_MAX];
44unsigned int dump_size = 0;
45
46static int
47ospf6_dump_index (struct cmd_element *cmd, int command)
48{
49 int i;
50
51 for (i = 0; i < DUMP_MAX; i++)
52 {
53 if (cmd != &ospf6_dump[i]->cmd[command])
54 continue;
55 break;
56 }
57
58 if (i == DUMP_MAX)
59 return -1;
60 return i;
61}
62
63int
64ospf6_dump_is_on (int index)
65{
66 if (ospf6_dump[index] == NULL)
67 return 0;
68
69 return ospf6_dump[index]->config;
70}
71
72int
73ospf6_dump_show (struct cmd_element *cmd,
74 struct vty *vty, int argc, char **argv)
75{
76 int index;
77
78 index = ospf6_dump_index (cmd, CMD_SHOW);
79 assert (index != -1);
80
81 vty_out (vty, " %-16s: %s%s", ospf6_dump[index]->name,
82 (ospf6_dump[index]->config ? "on" : "off"),
83 VTY_NEWLINE);
84 return CMD_SUCCESS;
85}
86
87int
88ospf6_dump_enable (struct cmd_element *cmd,
89 struct vty *vty, int argc, char **argv)
90{
91 int index;
92
93 index = ospf6_dump_index (cmd, CMD_ENABLE);
94 assert (index != -1);
95
96 ospf6_dump[index]->config = 1;
97 return CMD_SUCCESS;
98}
99
100int
101ospf6_dump_disable (struct cmd_element *cmd,
102 struct vty *vty, int argc, char **argv)
103{
104 int index;
105
106 index = ospf6_dump_index (cmd, CMD_DISABLE);
107 assert (index != -1);
108
109 ospf6_dump[index]->config = 0;
110 return CMD_SUCCESS;
111}
112
113int
114ospf6_dump_install (char *name, char *help)
115{
116 struct cmd_element *cmd;
117 char string[256];
118 char helpstring[256];
119
120 if (dump_size + 1 >= DUMP_MAX)
121 return -1;
122
123 ospf6_dump[dump_size] = malloc (sizeof (struct ospf6_dump));
124 if (ospf6_dump[dump_size] == NULL)
125 return -1;
126 memset (ospf6_dump[dump_size], 0, sizeof (struct ospf6_dump));
127
128 ospf6_dump[dump_size]->name = strdup (name);
129
130 cmd = &ospf6_dump[dump_size]->cmd[CMD_SHOW];
131 snprintf (string, sizeof (string), "show debugging ospf6 %s", name);
132 snprintf (helpstring, sizeof (helpstring), "%s%s%s%s",
133 SHOW_STR, DEBUG_STR, OSPF6_STR, help);
134 memset (cmd, 0, sizeof (struct cmd_element));
135 cmd->string = strdup (string);
136 cmd->func = ospf6_dump_show;
137 cmd->doc = strdup (helpstring);
138 install_element (VIEW_NODE, cmd);
139 install_element (ENABLE_NODE, cmd);
140
141 cmd = &ospf6_dump[dump_size]->cmd[CMD_ENABLE];
142 snprintf (string, sizeof (string), "debug ospf6 %s", name);
143 snprintf (helpstring, sizeof (helpstring), "%s%s%s",
144 DEBUG_STR, OSPF6_STR, help);
145 memset (cmd, 0, sizeof (struct cmd_element));
146 cmd->string = strdup (string);
147 cmd->func = ospf6_dump_enable;
148 cmd->doc = strdup (helpstring);
149 install_element (CONFIG_NODE, cmd);
150
151 cmd = &ospf6_dump[dump_size]->cmd[CMD_DISABLE];
152 snprintf (string, sizeof (string), "no debug ospf6 %s", name);
153 snprintf (helpstring, sizeof (helpstring), "%s%s%s%s",
154 NO_STR, DEBUG_STR, OSPF6_STR, help);
155 memset (cmd, 0, sizeof (struct cmd_element));
156 cmd->string = strdup (string);
157 cmd->func = ospf6_dump_disable;
158 cmd->doc = strdup (helpstring);
159 install_element (CONFIG_NODE, cmd);
160
161 return dump_size++;
162}
163
164DEFUN(show_debug_ospf6,
165 show_debug_ospf6_cmd,
166 "show debugging ospf6",
167 SHOW_STR
168 DEBUG_STR
169 OSPF6_STR)
170{
171 int i;
172
173 vty_out (vty, "OSPF6 debugging status:%s", VTY_NEWLINE);
174
175 for (i = 0; i < DUMP_MAX; i++)
176 {
177 if (ospf6_dump[i] == NULL)
178 continue;
179 ospf6_dump_show (&ospf6_dump[i]->cmd[CMD_SHOW], vty, 0, NULL);
180 }
181
182 return CMD_SUCCESS;
183}
184
185DEFUN (debug_ospf6_all,
186 debug_ospf6_all_cmd,
187 "debug ospf6 all",
188 DEBUG_STR
189 OSPF6_STR
190 "Turn on ALL OSPFv3 debugging\n")
191{
192 int i;
193
194 for (i = 0; i < DUMP_MAX; i++)
195 {
196 if (ospf6_dump[i] == NULL)
197 continue;
198 ospf6_dump_enable (&ospf6_dump[i]->cmd[CMD_ENABLE], vty, 0, NULL);
199 }
200
201 return CMD_SUCCESS;
202}
203
204DEFUN (no_debug_ospf6_all,
205 no_debug_ospf6_all_cmd,
206 "no debug ospf6 all",
207 NO_STR
208 DEBUG_STR
209 OSPF6_STR
210 "Turn off ALL OSPFv3 debugging\n")
211{
212 int i;
213
214 for (i = 0; i < DUMP_MAX; i++)
215 {
216 if (ospf6_dump[i] == NULL)
217 continue;
218 ospf6_dump_disable (&ospf6_dump[i]->cmd[CMD_DISABLE], vty, 0, NULL);
219 }
220
221 return CMD_SUCCESS;
222}
223
224struct cmd_node debug_node =
225{
226 DEBUG_NODE,
733e8102 227 "",
228 vtysh: 1
718e3744 229};
230
231int
232ospf6_dump_config_write (struct vty *vty)
233{
234 int i;
235
236 for (i = 0; i < dump_size; i++)
237 {
238 if (ospf6_dump[i] == NULL)
239 continue;
240
241 if (ospf6_dump[i]->config == 0)
242 continue;
243
244 vty_out (vty, "debug ospf6 %s%s", ospf6_dump[i]->name, VTY_NEWLINE);
245 }
246
247 vty_out (vty, "!%s", VTY_NEWLINE);
248 return 0;
249}
250
251char dump_index[OSPF6_DUMP_MAX];
252
253void
254ospf6_dump_init ()
255{
256 memset (ospf6_dump, 0, sizeof (ospf6_dump));
257
258 install_node (&debug_node, ospf6_dump_config_write);
259
260 install_element (VIEW_NODE, &show_debug_ospf6_cmd);
261 install_element (ENABLE_NODE, &show_debug_ospf6_cmd);
262
263 install_element (CONFIG_NODE, &debug_ospf6_all_cmd);
264 install_element (CONFIG_NODE, &no_debug_ospf6_all_cmd);
265
266 /* bellow is for backward compatibility
267 should be moved to each modules */
268
269#define MESSAGE_STR "OSPFv3 Messages\n"
270
271 dump_index[OSPF6_DUMP_HELLO] =
272 ospf6_dump_install ("message hello",
273 MESSAGE_STR "Hello\n");
274 dump_index[OSPF6_DUMP_DBDESC] =
275 ospf6_dump_install ("message dbdesc",
276 MESSAGE_STR "Database Description\n");
277 dump_index[OSPF6_DUMP_LSREQ] =
278 ospf6_dump_install ("message lsreq",
279 MESSAGE_STR "Link State Request\n");
280 dump_index[OSPF6_DUMP_LSUPDATE] =
281 ospf6_dump_install ("message lsupdate",
282 MESSAGE_STR "Link State Update\n");
283 dump_index[OSPF6_DUMP_LSACK] =
284 ospf6_dump_install ("message lsack",
285 MESSAGE_STR "Link State Acknowledge\n");
286 dump_index[OSPF6_DUMP_NEIGHBOR] =
287 ospf6_dump_install ("neighbor", "Neighbors\n");
288 dump_index[OSPF6_DUMP_INTERFACE] =
289 ospf6_dump_install ("interface", "Interfaces\n");
290 dump_index[OSPF6_DUMP_LSA] =
291 ospf6_dump_install ("lsa", "Link State Advertisement\n");
292 dump_index[OSPF6_DUMP_ZEBRA] =
293 ospf6_dump_install ("zebra", "Communication with zebra\n");
294 dump_index[OSPF6_DUMP_CONFIG] =
295 ospf6_dump_install ("config", "Configuration Changes\n");
296 dump_index[OSPF6_DUMP_DBEX] =
297 ospf6_dump_install ("dbex", "Database Exchange/Flooding\n");
298 dump_index[OSPF6_DUMP_SPF] =
299 ospf6_dump_install ("spf", "SPF Calculation\n");
300 dump_index[OSPF6_DUMP_ROUTE] =
301 ospf6_dump_install ("route", "Route Calculation\n");
302 dump_index[OSPF6_DUMP_LSDB] =
303 ospf6_dump_install ("lsdb", "Link State Database\n");
304 dump_index[OSPF6_DUMP_REDISTRIBUTE] =
305 ospf6_dump_install ("redistribute",
306 "Route Exchange with other protocols\n");
307 dump_index[OSPF6_DUMP_HOOK] =
308 ospf6_dump_install ("hook", "Hooks\n");
309 dump_index[OSPF6_DUMP_ASBR] =
310 ospf6_dump_install ("asbr", "AS Boundary Router function\n");
311 dump_index[OSPF6_DUMP_PREFIX] =
312 ospf6_dump_install ("prefix", "Prefix\n");
313}
314
315