]>
Commit | Line | Data |
---|---|---|
d62a17ae | 1 | /* |
65efcfce LB |
2 | * |
3 | * Copyright 2016, LabN Consulting, L.L.C. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU General Public License | |
7 | * as published by the Free Software Foundation; either version 2 | |
8 | * of the License, or (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
896014f4 DL |
15 | * You should have received a copy of the GNU General Public License along |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
65efcfce LB |
18 | */ |
19 | ||
f8b6f499 | 20 | #include "lib/zebra.h" |
65efcfce LB |
21 | |
22 | #include <lib/version.h> | |
f8b6f499 LB |
23 | #include "lib/prefix.h" |
24 | #include "lib/linklist.h" | |
25 | #include "lib/stream.h" | |
26 | #include "lib/command.h" | |
f8b6f499 LB |
27 | #include "lib/log.h" |
28 | #include "bgpd/rfapi/vnc_debug.h" | |
65efcfce LB |
29 | |
30 | /* | |
31 | * debug state storage | |
32 | */ | |
33 | unsigned long conf_vnc_debug; | |
34 | unsigned long term_vnc_debug; | |
35 | ||
36 | struct vnc_debug { | |
d62a17ae | 37 | unsigned long bit; |
38 | const char *name; | |
65efcfce LB |
39 | }; |
40 | ||
2b64873d | 41 | static const struct vnc_debug vncdebug[] = { |
d62a17ae | 42 | {VNC_DEBUG_RFAPI_QUERY, "rfapi-query"}, |
43 | {VNC_DEBUG_IMPORT_BI_ATTACH, "import-bi-attach"}, | |
44 | {VNC_DEBUG_IMPORT_DEL_REMOTE, "import-del-remote"}, | |
45 | {VNC_DEBUG_EXPORT_BGP_GETCE, "export-bgp-getce"}, | |
46 | {VNC_DEBUG_EXPORT_BGP_DIRECT_ADD, "export-bgp-direct-add"}, | |
47 | {VNC_DEBUG_IMPORT_BGP_ADD_ROUTE, "import-bgp-add-route"}, | |
48 | {VNC_DEBUG_VERBOSE, "verbose"}, | |
65efcfce LB |
49 | }; |
50 | ||
51 | #define VNC_STR "VNC information\n" | |
52 | ||
53 | /*********************************************************************** | |
54 | * debug bgp vnc <foo> | |
55 | ***********************************************************************/ | |
56 | DEFUN (debug_bgp_vnc, | |
57 | debug_bgp_vnc_cmd, | |
d5bd3e0a | 58 | "debug bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>", |
65efcfce LB |
59 | DEBUG_STR |
60 | BGP_STR | |
61 | VNC_STR | |
62 | "rfapi query handling\n" | |
63 | "import BI atachment\n" | |
a3b55c25 LB |
64 | "import delete remote routes\n" |
65 | "verbose logging\n") | |
65efcfce | 66 | { |
d62a17ae | 67 | size_t i; |
68 | ||
69 | for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) { | |
70 | if (strmatch(argv[3]->text, vncdebug[i].name)) { | |
71 | if (vty->node == CONFIG_NODE) { | |
72 | conf_vnc_debug |= vncdebug[i].bit; | |
73 | term_vnc_debug |= vncdebug[i].bit; | |
74 | } else { | |
75 | term_vnc_debug |= vncdebug[i].bit; | |
76 | vty_out(vty, "BGP vnc %s debugging is on\n", | |
77 | vncdebug[i].name); | |
78 | } | |
79 | return CMD_SUCCESS; | |
80 | } | |
65efcfce | 81 | } |
d62a17ae | 82 | vty_out(vty, "Unknown debug flag: %s\n", argv[3]->arg); |
83 | return CMD_WARNING_CONFIG_FAILED; | |
65efcfce LB |
84 | } |
85 | ||
86 | DEFUN (no_debug_bgp_vnc, | |
87 | no_debug_bgp_vnc_cmd, | |
ef7eec74 | 88 | "no debug bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>", |
65efcfce LB |
89 | NO_STR |
90 | DEBUG_STR | |
91 | BGP_STR | |
92 | VNC_STR | |
93 | "rfapi query handling\n" | |
94 | "import BI atachment\n" | |
a3b55c25 LB |
95 | "import delete remote routes\n" |
96 | "verbose logging\n") | |
65efcfce | 97 | { |
d62a17ae | 98 | size_t i; |
99 | ||
d62a17ae | 100 | for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) { |
ef7eec74 | 101 | if (strmatch(argv[argc - 1]->text, vncdebug[i].name)) { |
d62a17ae | 102 | if (vty->node == CONFIG_NODE) { |
103 | conf_vnc_debug &= ~vncdebug[i].bit; | |
104 | term_vnc_debug &= ~vncdebug[i].bit; | |
105 | } else { | |
106 | term_vnc_debug &= ~vncdebug[i].bit; | |
107 | vty_out(vty, "BGP vnc %s debugging is off\n", | |
108 | vncdebug[i].name); | |
109 | } | |
110 | return CMD_SUCCESS; | |
111 | } | |
65efcfce | 112 | } |
d62a17ae | 113 | vty_out(vty, "Unknown debug flag: %s\n", argv[3]->arg); |
114 | return CMD_WARNING_CONFIG_FAILED; | |
65efcfce LB |
115 | } |
116 | ||
65efcfce LB |
117 | /*********************************************************************** |
118 | * no debug bgp vnc all | |
119 | ***********************************************************************/ | |
120 | ||
121 | DEFUN (no_debug_bgp_vnc_all, | |
122 | no_debug_bgp_vnc_all_cmd, | |
ef7eec74 | 123 | "no debug all bgp vnc", |
65efcfce LB |
124 | NO_STR |
125 | DEBUG_STR | |
126 | "Disable all VNC debugging\n" | |
127 | BGP_STR | |
128 | VNC_STR) | |
129 | { | |
d62a17ae | 130 | term_vnc_debug = 0; |
131 | vty_out(vty, "All possible VNC debugging has been turned off\n"); | |
132 | ||
133 | return CMD_SUCCESS; | |
65efcfce LB |
134 | } |
135 | ||
65efcfce LB |
136 | /*********************************************************************** |
137 | * show/save | |
138 | ***********************************************************************/ | |
139 | ||
87f6dc50 DS |
140 | DEFUN_NOSH (show_debugging_bgp_vnc, |
141 | show_debugging_bgp_vnc_cmd, | |
142 | "show debugging bgp vnc", | |
143 | SHOW_STR | |
144 | DEBUG_STR | |
145 | BGP_STR | |
146 | VNC_STR) | |
65efcfce | 147 | { |
d62a17ae | 148 | size_t i; |
65efcfce | 149 | |
d62a17ae | 150 | vty_out(vty, "BGP VNC debugging status:\n"); |
65efcfce | 151 | |
d62a17ae | 152 | for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) { |
153 | if (term_vnc_debug & vncdebug[i].bit) { | |
154 | vty_out(vty, " BGP VNC %s debugging is on\n", | |
155 | vncdebug[i].name); | |
156 | } | |
65efcfce | 157 | } |
d62a17ae | 158 | vty_out(vty, "\n"); |
159 | return CMD_SUCCESS; | |
65efcfce LB |
160 | } |
161 | ||
d62a17ae | 162 | static int bgp_vnc_config_write_debug(struct vty *vty) |
65efcfce | 163 | { |
d62a17ae | 164 | int write = 0; |
165 | size_t i; | |
166 | ||
97b5d752 | 167 | for (i = 0; i < array_size(vncdebug); ++i) { |
d62a17ae | 168 | if (conf_vnc_debug & vncdebug[i].bit) { |
169 | vty_out(vty, "debug bgp vnc %s\n", vncdebug[i].name); | |
170 | write++; | |
171 | } | |
65efcfce | 172 | } |
d62a17ae | 173 | return write; |
65efcfce LB |
174 | } |
175 | ||
612c2c15 | 176 | static int bgp_vnc_config_write_debug(struct vty *vty); |
62b346ee | 177 | static struct cmd_node debug_node = { |
f4b8291f | 178 | .name = "vnc debug", |
62b346ee DL |
179 | .node = DEBUG_VNC_NODE, |
180 | .prompt = "", | |
612c2c15 | 181 | .config_write = bgp_vnc_config_write_debug, |
62b346ee | 182 | }; |
65efcfce | 183 | |
d62a17ae | 184 | void vnc_debug_init(void) |
65efcfce | 185 | { |
612c2c15 | 186 | install_node(&debug_node); |
d62a17ae | 187 | install_element(ENABLE_NODE, &show_debugging_bgp_vnc_cmd); |
65efcfce | 188 | |
d62a17ae | 189 | install_element(ENABLE_NODE, &debug_bgp_vnc_cmd); |
190 | install_element(CONFIG_NODE, &debug_bgp_vnc_cmd); | |
191 | install_element(ENABLE_NODE, &no_debug_bgp_vnc_cmd); | |
ef7eec74 | 192 | install_element(CONFIG_NODE, &no_debug_bgp_vnc_cmd); |
65efcfce | 193 | |
d62a17ae | 194 | install_element(ENABLE_NODE, &no_debug_bgp_vnc_all_cmd); |
ef7eec74 | 195 | install_element(CONFIG_NODE, &no_debug_bgp_vnc_all_cmd); |
65efcfce | 196 | } |