]> git.proxmox.com Git - mirror_frr.git/blob - ldpd/ldp_debug.c
*: move CLI node names to cmd_node->name
[mirror_frr.git] / ldpd / ldp_debug.c
1 /*
2 * Copyright (C) 2016 by Open Source Routing.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; see the file COPYING; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19
20 #include <zebra.h>
21
22 #include "command.h"
23 #include "vty.h"
24
25 #include "ldpd.h"
26 #include "ldp_debug.h"
27 #include "ldp_vty.h"
28
29 struct ldp_debug conf_ldp_debug;
30 struct ldp_debug ldp_debug;
31
32 static int ldp_debug_config_write(struct vty *);
33
34 /* Debug node. */
35 struct cmd_node ldp_debug_node = {
36 .name = "debug",
37 .node = DEBUG_NODE,
38 .prompt = "",
39 .config_write = ldp_debug_config_write,
40 };
41
42 int
43 ldp_vty_debug(struct vty *vty, const char *negate, const char *type_str,
44 const char *dir_str, const char *all)
45 {
46 if (type_str == NULL)
47 return (CMD_WARNING_CONFIG_FAILED);
48
49 if (strcmp(type_str, "discovery") == 0) {
50 if (dir_str == NULL)
51 return (CMD_WARNING_CONFIG_FAILED);
52
53 if (dir_str[0] == 'r') {
54 if (negate)
55 DEBUG_OFF(hello, LDP_DEBUG_HELLO_RECV);
56 else
57 DEBUG_ON(hello, LDP_DEBUG_HELLO_RECV);
58 } else {
59 if (negate)
60 DEBUG_OFF(hello, LDP_DEBUG_HELLO_SEND);
61 else
62 DEBUG_ON(hello, LDP_DEBUG_HELLO_SEND);
63 }
64 } else if (strcmp(type_str, "errors") == 0) {
65 if (negate)
66 DEBUG_OFF(errors, LDP_DEBUG_ERRORS);
67 else
68 DEBUG_ON(errors, LDP_DEBUG_ERRORS);
69 } else if (strcmp(type_str, "event") == 0) {
70 if (negate)
71 DEBUG_OFF(event, LDP_DEBUG_EVENT);
72 else
73 DEBUG_ON(event, LDP_DEBUG_EVENT);
74 } else if (strcmp(type_str, "labels") == 0) {
75 if (negate)
76 DEBUG_OFF(labels, LDP_DEBUG_LABELS);
77 else
78 DEBUG_ON(labels, LDP_DEBUG_LABELS);
79 } else if (strcmp(type_str, "messages") == 0) {
80 if (dir_str == NULL)
81 return (CMD_WARNING_CONFIG_FAILED);
82
83 if (dir_str[0] == 'r') {
84 if (negate) {
85 DEBUG_OFF(msg, LDP_DEBUG_MSG_RECV);
86 DEBUG_OFF(msg, LDP_DEBUG_MSG_RECV_ALL);
87 } else {
88 DEBUG_ON(msg, LDP_DEBUG_MSG_RECV);
89 if (all)
90 DEBUG_ON(msg, LDP_DEBUG_MSG_RECV_ALL);
91 }
92 } else {
93 if (negate) {
94 DEBUG_OFF(msg, LDP_DEBUG_MSG_SEND);
95 DEBUG_OFF(msg, LDP_DEBUG_MSG_SEND_ALL);
96 } else {
97 DEBUG_ON(msg, LDP_DEBUG_MSG_SEND);
98 if (all)
99 DEBUG_ON(msg, LDP_DEBUG_MSG_SEND_ALL);
100 }
101 }
102 } else if (strcmp(type_str, "zebra") == 0) {
103 if (negate)
104 DEBUG_OFF(zebra, LDP_DEBUG_ZEBRA);
105 else
106 DEBUG_ON(zebra, LDP_DEBUG_ZEBRA);
107 }
108
109 main_imsg_compose_both(IMSG_DEBUG_UPDATE, &ldp_debug,
110 sizeof(ldp_debug));
111
112 return (CMD_SUCCESS);
113 }
114
115 int
116 ldp_vty_show_debugging(struct vty *vty)
117 {
118 vty_out (vty, "LDP debugging status:\n");
119
120 if (LDP_DEBUG(hello, LDP_DEBUG_HELLO_RECV))
121 vty_out (vty," LDP discovery debugging is on (inbound)\n");
122 if (LDP_DEBUG(hello, LDP_DEBUG_HELLO_SEND))
123 vty_out (vty," LDP discovery debugging is on (outbound)\n");
124 if (LDP_DEBUG(errors, LDP_DEBUG_ERRORS))
125 vty_out (vty, " LDP errors debugging is on\n");
126 if (LDP_DEBUG(event, LDP_DEBUG_EVENT))
127 vty_out (vty, " LDP events debugging is on\n");
128 if (LDP_DEBUG(labels, LDP_DEBUG_LABELS))
129 vty_out (vty, " LDP labels debugging is on\n");
130 if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV_ALL))
131 vty_out (vty,
132 " LDP detailed messages debugging is on (inbound)\n");
133 else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV))
134 vty_out (vty," LDP messages debugging is on (inbound)\n");
135 if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND_ALL))
136 vty_out (vty,
137 " LDP detailed messages debugging is on (outbound)\n");
138 else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND))
139 vty_out (vty," LDP messages debugging is on (outbound)\n");
140 if (LDP_DEBUG(zebra, LDP_DEBUG_ZEBRA))
141 vty_out (vty, " LDP zebra debugging is on\n");
142 vty_out (vty, "\n");
143
144 return (CMD_SUCCESS);
145 }
146
147 static int
148 ldp_debug_config_write(struct vty *vty)
149 {
150 int write = 0;
151
152 if (CONF_LDP_DEBUG(hello, LDP_DEBUG_HELLO_RECV)) {
153 vty_out (vty,"debug mpls ldp discovery hello recv\n");
154 write = 1;
155 }
156
157 if (CONF_LDP_DEBUG(hello, LDP_DEBUG_HELLO_SEND)) {
158 vty_out (vty,"debug mpls ldp discovery hello sent\n");
159 write = 1;
160 }
161
162 if (CONF_LDP_DEBUG(errors, LDP_DEBUG_ERRORS)) {
163 vty_out (vty, "debug mpls ldp errors\n");
164 write = 1;
165 }
166
167 if (CONF_LDP_DEBUG(event, LDP_DEBUG_EVENT)) {
168 vty_out (vty, "debug mpls ldp event\n");
169 write = 1;
170 }
171
172 if (CONF_LDP_DEBUG(labels, LDP_DEBUG_LABELS)) {
173 vty_out (vty, "debug mpls ldp labels\n");
174 write = 1;
175 }
176
177 if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV_ALL)) {
178 vty_out (vty, "debug mpls ldp messages recv all\n");
179 write = 1;
180 } else if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV)) {
181 vty_out (vty, "debug mpls ldp messages recv\n");
182 write = 1;
183 }
184
185 if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND_ALL)) {
186 vty_out (vty, "debug mpls ldp messages sent all\n");
187 write = 1;
188 } else if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND)) {
189 vty_out (vty, "debug mpls ldp messages sent\n");
190 write = 1;
191 }
192
193 if (CONF_LDP_DEBUG(zebra, LDP_DEBUG_ZEBRA)) {
194 vty_out (vty, "debug mpls ldp zebra\n");
195 write = 1;
196 }
197
198 return (write);
199 }