]> git.proxmox.com Git - mirror_frr.git/blob - ldpd/ldp_debug.c
Merge pull request #7830 from volta-networks/misc_fixes_2021
[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, "sync") == 0) {
103 if (negate)
104 DEBUG_OFF(sync, LDP_DEBUG_SYNC);
105 else
106 DEBUG_ON(sync, LDP_DEBUG_SYNC);
107 } else if (strcmp(type_str, "zebra") == 0) {
108 if (negate)
109 DEBUG_OFF(zebra, LDP_DEBUG_ZEBRA);
110 else
111 DEBUG_ON(zebra, LDP_DEBUG_ZEBRA);
112 }
113
114 main_imsg_compose_both(IMSG_DEBUG_UPDATE, &ldp_debug,
115 sizeof(ldp_debug));
116
117 return (CMD_SUCCESS);
118 }
119
120 int
121 ldp_vty_show_debugging(struct vty *vty)
122 {
123 vty_out (vty, "LDP debugging status:\n");
124
125 if (LDP_DEBUG(hello, LDP_DEBUG_HELLO_RECV))
126 vty_out (vty," LDP discovery debugging is on (inbound)\n");
127 if (LDP_DEBUG(hello, LDP_DEBUG_HELLO_SEND))
128 vty_out (vty," LDP discovery debugging is on (outbound)\n");
129 if (LDP_DEBUG(errors, LDP_DEBUG_ERRORS))
130 vty_out (vty, " LDP errors debugging is on\n");
131 if (LDP_DEBUG(event, LDP_DEBUG_EVENT))
132 vty_out (vty, " LDP events debugging is on\n");
133 if (LDP_DEBUG(labels, LDP_DEBUG_LABELS))
134 vty_out (vty, " LDP labels debugging is on\n");
135 if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV_ALL))
136 vty_out (vty,
137 " LDP detailed messages debugging is on (inbound)\n");
138 else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV))
139 vty_out (vty," LDP messages debugging is on (inbound)\n");
140 if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND_ALL))
141 vty_out (vty,
142 " LDP detailed messages debugging is on (outbound)\n");
143 else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND))
144 vty_out (vty," LDP messages debugging is on (outbound)\n");
145 if (LDP_DEBUG(sync, LDP_DEBUG_SYNC))
146 vty_out (vty, " LDP sync debugging is on\n");
147 if (LDP_DEBUG(zebra, LDP_DEBUG_ZEBRA))
148 vty_out (vty, " LDP zebra debugging is on\n");
149 vty_out (vty, "\n");
150
151 return (CMD_SUCCESS);
152 }
153
154 static int
155 ldp_debug_config_write(struct vty *vty)
156 {
157 int write = 0;
158
159 if (CONF_LDP_DEBUG(hello, LDP_DEBUG_HELLO_RECV)) {
160 vty_out (vty,"debug mpls ldp discovery hello recv\n");
161 write = 1;
162 }
163
164 if (CONF_LDP_DEBUG(hello, LDP_DEBUG_HELLO_SEND)) {
165 vty_out (vty,"debug mpls ldp discovery hello sent\n");
166 write = 1;
167 }
168
169 if (CONF_LDP_DEBUG(errors, LDP_DEBUG_ERRORS)) {
170 vty_out (vty, "debug mpls ldp errors\n");
171 write = 1;
172 }
173
174 if (CONF_LDP_DEBUG(event, LDP_DEBUG_EVENT)) {
175 vty_out (vty, "debug mpls ldp event\n");
176 write = 1;
177 }
178
179 if (CONF_LDP_DEBUG(labels, LDP_DEBUG_LABELS)) {
180 vty_out (vty, "debug mpls ldp labels\n");
181 write = 1;
182 }
183
184 if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV_ALL)) {
185 vty_out (vty, "debug mpls ldp messages recv all\n");
186 write = 1;
187 } else if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV)) {
188 vty_out (vty, "debug mpls ldp messages recv\n");
189 write = 1;
190 }
191
192 if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND_ALL)) {
193 vty_out (vty, "debug mpls ldp messages sent all\n");
194 write = 1;
195 } else if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND)) {
196 vty_out (vty, "debug mpls ldp messages sent\n");
197 write = 1;
198 }
199
200 if (CONF_LDP_DEBUG(zebra, LDP_DEBUG_ZEBRA)) {
201 vty_out (vty, "debug mpls ldp zebra\n");
202 write = 1;
203 }
204
205 if (CONF_LDP_DEBUG(sync, LDP_DEBUG_SYNC)) {
206 vty_out (vty, "debug mpls ldp sync\n");
207 write = 1;
208 }
209
210 return (write);
211 }