]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/rfapi/vnc_debug.c
*: reindent
[mirror_frr.git] / bgpd / rfapi / vnc_debug.c
CommitLineData
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 */
33unsigned long conf_vnc_debug;
34unsigned long term_vnc_debug;
35
36struct vnc_debug {
d62a17ae 37 unsigned long bit;
38 const char *name;
65efcfce
LB
39};
40
d62a17ae 41struct vnc_debug vncdebug[] = {
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 ***********************************************************************/
56DEFUN (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
86DEFUN (no_debug_bgp_vnc,
87 no_debug_bgp_vnc_cmd,
d5bd3e0a 88 "<no debug|undebug> bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>",
65efcfce
LB
89 NO_STR
90 DEBUG_STR
bdffbcef 91 "Undebug\n"
65efcfce
LB
92 BGP_STR
93 VNC_STR
94 "rfapi query handling\n"
95 "import BI atachment\n"
a3b55c25
LB
96 "import delete remote routes\n"
97 "verbose logging\n")
65efcfce 98{
d62a17ae 99 size_t i;
100
101 if (strmatch(argv[0]->text, "no"))
102 argc--, argv++;
103 for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
104 if (strmatch(argv[3]->text, vncdebug[i].name)) {
105 if (vty->node == CONFIG_NODE) {
106 conf_vnc_debug &= ~vncdebug[i].bit;
107 term_vnc_debug &= ~vncdebug[i].bit;
108 } else {
109 term_vnc_debug &= ~vncdebug[i].bit;
110 vty_out(vty, "BGP vnc %s debugging is off\n",
111 vncdebug[i].name);
112 }
113 return CMD_SUCCESS;
114 }
65efcfce 115 }
d62a17ae 116 vty_out(vty, "Unknown debug flag: %s\n", argv[3]->arg);
117 return CMD_WARNING_CONFIG_FAILED;
65efcfce
LB
118}
119
65efcfce
LB
120
121/***********************************************************************
122 * no debug bgp vnc all
123 ***********************************************************************/
124
125DEFUN (no_debug_bgp_vnc_all,
126 no_debug_bgp_vnc_all_cmd,
aed3273f 127 "<no debug|undebug> all bgp vnc",
65efcfce
LB
128 NO_STR
129 DEBUG_STR
034d2de2 130 "Undebug command\n"
65efcfce
LB
131 "Disable all VNC debugging\n"
132 BGP_STR
133 VNC_STR)
134{
d62a17ae 135 term_vnc_debug = 0;
136 vty_out(vty, "All possible VNC debugging has been turned off\n");
137
138 return CMD_SUCCESS;
65efcfce
LB
139}
140
65efcfce
LB
141/***********************************************************************
142 * show/save
143 ***********************************************************************/
144
145DEFUN (show_debugging_bgp_vnc,
146 show_debugging_bgp_vnc_cmd,
147 "show debugging bgp vnc",
148 SHOW_STR
149 DEBUG_STR
150 BGP_STR
151 VNC_STR)
152{
d62a17ae 153 size_t i;
65efcfce 154
d62a17ae 155 vty_out(vty, "BGP VNC debugging status:\n");
65efcfce 156
d62a17ae 157 for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
158 if (term_vnc_debug & vncdebug[i].bit) {
159 vty_out(vty, " BGP VNC %s debugging is on\n",
160 vncdebug[i].name);
161 }
65efcfce 162 }
d62a17ae 163 vty_out(vty, "\n");
164 return CMD_SUCCESS;
65efcfce
LB
165}
166
d62a17ae 167static int bgp_vnc_config_write_debug(struct vty *vty)
65efcfce 168{
d62a17ae 169 int write = 0;
170 size_t i;
171
172 for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) {
173 if (conf_vnc_debug & vncdebug[i].bit) {
174 vty_out(vty, "debug bgp vnc %s\n", vncdebug[i].name);
175 write++;
176 }
65efcfce 177 }
d62a17ae 178 return write;
65efcfce
LB
179}
180
d62a17ae 181static struct cmd_node debug_node = {DEBUG_VNC_NODE, "", 1};
65efcfce 182
d62a17ae 183void vnc_debug_init(void)
65efcfce 184{
d62a17ae 185 install_node(&debug_node, bgp_vnc_config_write_debug);
186 install_element(ENABLE_NODE, &show_debugging_bgp_vnc_cmd);
65efcfce 187
d62a17ae 188 install_element(ENABLE_NODE, &debug_bgp_vnc_cmd);
189 install_element(CONFIG_NODE, &debug_bgp_vnc_cmd);
190 install_element(ENABLE_NODE, &no_debug_bgp_vnc_cmd);
65efcfce 191
d62a17ae 192 install_element(ENABLE_NODE, &no_debug_bgp_vnc_all_cmd);
65efcfce 193}