]>
Commit | Line | Data |
---|---|---|
65efcfce LB |
1 | /* |
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 { | |
d5bd3e0a DL |
37 | unsigned long bit; |
38 | const char *name; | |
65efcfce LB |
39 | }; |
40 | ||
41 | struct vnc_debug vncdebug[] = | |
42 | { | |
d5bd3e0a DL |
43 | {VNC_DEBUG_RFAPI_QUERY, "rfapi-query"}, |
44 | {VNC_DEBUG_IMPORT_BI_ATTACH, "import-bi-attach"}, | |
45 | {VNC_DEBUG_IMPORT_DEL_REMOTE, "import-del-remote"}, | |
46 | {VNC_DEBUG_EXPORT_BGP_GETCE, "export-bgp-getce"}, | |
47 | {VNC_DEBUG_EXPORT_BGP_DIRECT_ADD, "export-bgp-direct-add"}, | |
48 | {VNC_DEBUG_IMPORT_BGP_ADD_ROUTE, "import-bgp-add-route"}, | |
49 | {VNC_DEBUG_VERBOSE, "verbose"}, | |
65efcfce LB |
50 | }; |
51 | ||
52 | #define VNC_STR "VNC information\n" | |
53 | ||
54 | /*********************************************************************** | |
55 | * debug bgp vnc <foo> | |
56 | ***********************************************************************/ | |
57 | DEFUN (debug_bgp_vnc, | |
58 | debug_bgp_vnc_cmd, | |
d5bd3e0a | 59 | "debug bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>", |
65efcfce LB |
60 | DEBUG_STR |
61 | BGP_STR | |
62 | VNC_STR | |
63 | "rfapi query handling\n" | |
64 | "import BI atachment\n" | |
a3b55c25 LB |
65 | "import delete remote routes\n" |
66 | "verbose logging\n") | |
65efcfce LB |
67 | { |
68 | size_t i; | |
69 | ||
70 | for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) | |
71 | { | |
7e045c3d | 72 | if (strmatch(argv[3]->text, vncdebug[i].name)) |
65efcfce LB |
73 | { |
74 | if (vty->node == CONFIG_NODE) | |
75 | { | |
76 | conf_vnc_debug |= vncdebug[i].bit; | |
77 | term_vnc_debug |= vncdebug[i].bit; | |
78 | } | |
79 | else | |
80 | { | |
81 | term_vnc_debug |= vncdebug[i].bit; | |
96ade3ed QY |
82 | vty_outln (vty, "BGP vnc %s debugging is on", |
83 | vncdebug[i].name); | |
65efcfce LB |
84 | } |
85 | return CMD_SUCCESS; | |
86 | } | |
87 | } | |
96ade3ed | 88 | vty_outln (vty, "Unknown debug flag: %s", argv[3]->arg); |
f1a05de9 | 89 | return CMD_WARNING_CONFIG_FAILED; |
65efcfce LB |
90 | } |
91 | ||
92 | DEFUN (no_debug_bgp_vnc, | |
93 | no_debug_bgp_vnc_cmd, | |
d5bd3e0a | 94 | "<no debug|undebug> bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>", |
65efcfce LB |
95 | NO_STR |
96 | DEBUG_STR | |
bdffbcef | 97 | "Undebug\n" |
65efcfce LB |
98 | BGP_STR |
99 | VNC_STR | |
100 | "rfapi query handling\n" | |
101 | "import BI atachment\n" | |
a3b55c25 LB |
102 | "import delete remote routes\n" |
103 | "verbose logging\n") | |
65efcfce LB |
104 | { |
105 | size_t i; | |
106 | ||
7e045c3d | 107 | if (strmatch(argv[0]->text, "no")) |
aed3273f | 108 | argc--, argv++; |
65efcfce LB |
109 | for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) |
110 | { | |
7e045c3d | 111 | if (strmatch(argv[3]->text, vncdebug[i].name)) |
65efcfce LB |
112 | { |
113 | if (vty->node == CONFIG_NODE) | |
114 | { | |
115 | conf_vnc_debug &= ~vncdebug[i].bit; | |
116 | term_vnc_debug &= ~vncdebug[i].bit; | |
117 | } | |
118 | else | |
119 | { | |
120 | term_vnc_debug &= ~vncdebug[i].bit; | |
96ade3ed QY |
121 | vty_outln (vty, "BGP vnc %s debugging is off", |
122 | vncdebug[i].name); | |
65efcfce LB |
123 | } |
124 | return CMD_SUCCESS; | |
125 | } | |
126 | } | |
96ade3ed | 127 | vty_outln (vty, "Unknown debug flag: %s", argv[3]->arg); |
f1a05de9 | 128 | return CMD_WARNING_CONFIG_FAILED; |
65efcfce LB |
129 | } |
130 | ||
65efcfce LB |
131 | |
132 | /*********************************************************************** | |
133 | * no debug bgp vnc all | |
134 | ***********************************************************************/ | |
135 | ||
136 | DEFUN (no_debug_bgp_vnc_all, | |
137 | no_debug_bgp_vnc_all_cmd, | |
aed3273f | 138 | "<no debug|undebug> all bgp vnc", |
65efcfce LB |
139 | NO_STR |
140 | DEBUG_STR | |
034d2de2 | 141 | "Undebug command\n" |
65efcfce LB |
142 | "Disable all VNC debugging\n" |
143 | BGP_STR | |
144 | VNC_STR) | |
145 | { | |
146 | term_vnc_debug = 0; | |
96ade3ed | 147 | vty_outln (vty, "All possible VNC debugging has been turned off"); |
65efcfce LB |
148 | |
149 | return CMD_SUCCESS; | |
150 | } | |
151 | ||
65efcfce LB |
152 | /*********************************************************************** |
153 | * show/save | |
154 | ***********************************************************************/ | |
155 | ||
156 | DEFUN (show_debugging_bgp_vnc, | |
157 | show_debugging_bgp_vnc_cmd, | |
158 | "show debugging bgp vnc", | |
159 | SHOW_STR | |
160 | DEBUG_STR | |
161 | BGP_STR | |
162 | VNC_STR) | |
163 | { | |
164 | size_t i; | |
165 | ||
96ade3ed | 166 | vty_outln (vty, "BGP VNC debugging status:"); |
65efcfce LB |
167 | |
168 | for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) | |
169 | { | |
170 | if (term_vnc_debug & vncdebug[i].bit) | |
171 | { | |
96ade3ed QY |
172 | vty_outln (vty, " BGP VNC %s debugging is on", |
173 | vncdebug[i].name); | |
65efcfce LB |
174 | } |
175 | } | |
e31b6333 | 176 | vty_out (vty, VTYNL); |
65efcfce LB |
177 | return CMD_SUCCESS; |
178 | } | |
179 | ||
180 | static int | |
181 | bgp_vnc_config_write_debug (struct vty *vty) | |
182 | { | |
183 | int write = 0; | |
184 | size_t i; | |
185 | ||
186 | for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) | |
187 | { | |
188 | if (conf_vnc_debug & vncdebug[i].bit) | |
189 | { | |
96ade3ed | 190 | vty_outln (vty, "debug bgp vnc %s", vncdebug[i].name); |
65efcfce LB |
191 | write++; |
192 | } | |
193 | } | |
194 | return write; | |
195 | } | |
196 | ||
197 | static struct cmd_node debug_node = | |
198 | { | |
199 | DEBUG_VNC_NODE, | |
200 | "", | |
201 | 1 | |
202 | }; | |
203 | ||
204 | void | |
205 | vnc_debug_init (void) | |
206 | { | |
207 | install_node (&debug_node, bgp_vnc_config_write_debug); | |
208 | install_element (ENABLE_NODE, &show_debugging_bgp_vnc_cmd); | |
209 | ||
210 | install_element (ENABLE_NODE, &debug_bgp_vnc_cmd); | |
211 | install_element (CONFIG_NODE, &debug_bgp_vnc_cmd); | |
212 | install_element (ENABLE_NODE, &no_debug_bgp_vnc_cmd); | |
65efcfce LB |
213 | |
214 | install_element (ENABLE_NODE, &no_debug_bgp_vnc_all_cmd); | |
65efcfce | 215 | } |