paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
| 35 | struct ospf6_dump |
| 36 | { |
| 37 | struct cmd_element cmd[CMD_MAX]; |
| 38 | char *name; |
| 39 | int config; |
| 40 | }; |
| 41 | |
| 42 | #define DUMP_MAX 512 |
| 43 | struct ospf6_dump *ospf6_dump[DUMP_MAX]; |
| 44 | unsigned int dump_size = 0; |
| 45 | |
| 46 | static int |
| 47 | ospf6_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 | |
| 63 | int |
| 64 | ospf6_dump_is_on (int index) |
| 65 | { |
| 66 | if (ospf6_dump[index] == NULL) |
| 67 | return 0; |
| 68 | |
| 69 | return ospf6_dump[index]->config; |
| 70 | } |
| 71 | |
| 72 | int |
| 73 | ospf6_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 | |
| 87 | int |
| 88 | ospf6_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 | |
| 100 | int |
| 101 | ospf6_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 | |
| 113 | int |
| 114 | ospf6_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 | |
| 164 | DEFUN(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 | |
| 185 | DEFUN (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 | |
| 204 | DEFUN (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 | |
| 224 | struct cmd_node debug_node = |
| 225 | { |
| 226 | DEBUG_NODE, |
| 227 | "" |
| 228 | }; |
| 229 | |
| 230 | int |
| 231 | ospf6_dump_config_write (struct vty *vty) |
| 232 | { |
| 233 | int i; |
| 234 | |
| 235 | for (i = 0; i < dump_size; i++) |
| 236 | { |
| 237 | if (ospf6_dump[i] == NULL) |
| 238 | continue; |
| 239 | |
| 240 | if (ospf6_dump[i]->config == 0) |
| 241 | continue; |
| 242 | |
| 243 | vty_out (vty, "debug ospf6 %s%s", ospf6_dump[i]->name, VTY_NEWLINE); |
| 244 | } |
| 245 | |
| 246 | vty_out (vty, "!%s", VTY_NEWLINE); |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | char dump_index[OSPF6_DUMP_MAX]; |
| 251 | |
| 252 | void |
| 253 | ospf6_dump_init () |
| 254 | { |
| 255 | memset (ospf6_dump, 0, sizeof (ospf6_dump)); |
| 256 | |
| 257 | install_node (&debug_node, ospf6_dump_config_write); |
| 258 | |
| 259 | install_element (VIEW_NODE, &show_debug_ospf6_cmd); |
| 260 | install_element (ENABLE_NODE, &show_debug_ospf6_cmd); |
| 261 | |
| 262 | install_element (CONFIG_NODE, &debug_ospf6_all_cmd); |
| 263 | install_element (CONFIG_NODE, &no_debug_ospf6_all_cmd); |
| 264 | |
| 265 | /* bellow is for backward compatibility |
| 266 | should be moved to each modules */ |
| 267 | |
| 268 | #define MESSAGE_STR "OSPFv3 Messages\n" |
| 269 | |
| 270 | dump_index[OSPF6_DUMP_HELLO] = |
| 271 | ospf6_dump_install ("message hello", |
| 272 | MESSAGE_STR "Hello\n"); |
| 273 | dump_index[OSPF6_DUMP_DBDESC] = |
| 274 | ospf6_dump_install ("message dbdesc", |
| 275 | MESSAGE_STR "Database Description\n"); |
| 276 | dump_index[OSPF6_DUMP_LSREQ] = |
| 277 | ospf6_dump_install ("message lsreq", |
| 278 | MESSAGE_STR "Link State Request\n"); |
| 279 | dump_index[OSPF6_DUMP_LSUPDATE] = |
| 280 | ospf6_dump_install ("message lsupdate", |
| 281 | MESSAGE_STR "Link State Update\n"); |
| 282 | dump_index[OSPF6_DUMP_LSACK] = |
| 283 | ospf6_dump_install ("message lsack", |
| 284 | MESSAGE_STR "Link State Acknowledge\n"); |
| 285 | dump_index[OSPF6_DUMP_NEIGHBOR] = |
| 286 | ospf6_dump_install ("neighbor", "Neighbors\n"); |
| 287 | dump_index[OSPF6_DUMP_INTERFACE] = |
| 288 | ospf6_dump_install ("interface", "Interfaces\n"); |
| 289 | dump_index[OSPF6_DUMP_LSA] = |
| 290 | ospf6_dump_install ("lsa", "Link State Advertisement\n"); |
| 291 | dump_index[OSPF6_DUMP_ZEBRA] = |
| 292 | ospf6_dump_install ("zebra", "Communication with zebra\n"); |
| 293 | dump_index[OSPF6_DUMP_CONFIG] = |
| 294 | ospf6_dump_install ("config", "Configuration Changes\n"); |
| 295 | dump_index[OSPF6_DUMP_DBEX] = |
| 296 | ospf6_dump_install ("dbex", "Database Exchange/Flooding\n"); |
| 297 | dump_index[OSPF6_DUMP_SPF] = |
| 298 | ospf6_dump_install ("spf", "SPF Calculation\n"); |
| 299 | dump_index[OSPF6_DUMP_ROUTE] = |
| 300 | ospf6_dump_install ("route", "Route Calculation\n"); |
| 301 | dump_index[OSPF6_DUMP_LSDB] = |
| 302 | ospf6_dump_install ("lsdb", "Link State Database\n"); |
| 303 | dump_index[OSPF6_DUMP_REDISTRIBUTE] = |
| 304 | ospf6_dump_install ("redistribute", |
| 305 | "Route Exchange with other protocols\n"); |
| 306 | dump_index[OSPF6_DUMP_HOOK] = |
| 307 | ospf6_dump_install ("hook", "Hooks\n"); |
| 308 | dump_index[OSPF6_DUMP_ASBR] = |
| 309 | ospf6_dump_install ("asbr", "AS Boundary Router function\n"); |
| 310 | dump_index[OSPF6_DUMP_PREFIX] = |
| 311 | ospf6_dump_install ("prefix", "Prefix\n"); |
| 312 | } |
| 313 | |
| 314 | |