]> git.proxmox.com Git - mirror_frr.git/blob - ldpd/ldp_debug.c
Merge pull request #12780 from opensourcerouting/spdx-license-id
[mirror_frr.git] / ldpd / ldp_debug.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2016 by Open Source Routing.
4 */
5
6 #include <zebra.h>
7
8 #include "command.h"
9 #include "vty.h"
10
11 #include "ldpd.h"
12 #include "ldp_debug.h"
13 #include "ldp_vty.h"
14
15 struct ldp_debug conf_ldp_debug;
16 struct ldp_debug ldp_debug;
17
18 static int ldp_debug_config_write(struct vty *);
19
20 /* Debug node. */
21 struct cmd_node ldp_debug_node = {
22 .name = "debug",
23 .node = DEBUG_NODE,
24 .prompt = "",
25 .config_write = ldp_debug_config_write,
26 };
27
28 int
29 ldp_vty_debug(struct vty *vty, const char *negate, const char *type_str,
30 const char *dir_str, const char *all)
31 {
32 if (type_str == NULL)
33 return (CMD_WARNING_CONFIG_FAILED);
34
35 if (strcmp(type_str, "discovery") == 0) {
36 if (dir_str == NULL)
37 return (CMD_WARNING_CONFIG_FAILED);
38
39 if (dir_str[0] == 'r') {
40 if (negate)
41 DEBUG_OFF(hello, LDP_DEBUG_HELLO_RECV);
42 else
43 DEBUG_ON(hello, LDP_DEBUG_HELLO_RECV);
44 } else {
45 if (negate)
46 DEBUG_OFF(hello, LDP_DEBUG_HELLO_SEND);
47 else
48 DEBUG_ON(hello, LDP_DEBUG_HELLO_SEND);
49 }
50 } else if (strcmp(type_str, "errors") == 0) {
51 if (negate)
52 DEBUG_OFF(errors, LDP_DEBUG_ERRORS);
53 else
54 DEBUG_ON(errors, LDP_DEBUG_ERRORS);
55 } else if (strcmp(type_str, "event") == 0) {
56 if (negate)
57 DEBUG_OFF(event, LDP_DEBUG_EVENT);
58 else
59 DEBUG_ON(event, LDP_DEBUG_EVENT);
60 } else if (strcmp(type_str, "labels") == 0) {
61 if (negate)
62 DEBUG_OFF(labels, LDP_DEBUG_LABELS);
63 else
64 DEBUG_ON(labels, LDP_DEBUG_LABELS);
65 } else if (strcmp(type_str, "messages") == 0) {
66 if (dir_str == NULL)
67 return (CMD_WARNING_CONFIG_FAILED);
68
69 if (dir_str[0] == 'r') {
70 if (negate) {
71 DEBUG_OFF(msg, LDP_DEBUG_MSG_RECV);
72 DEBUG_OFF(msg, LDP_DEBUG_MSG_RECV_ALL);
73 } else {
74 DEBUG_ON(msg, LDP_DEBUG_MSG_RECV);
75 if (all)
76 DEBUG_ON(msg, LDP_DEBUG_MSG_RECV_ALL);
77 }
78 } else {
79 if (negate) {
80 DEBUG_OFF(msg, LDP_DEBUG_MSG_SEND);
81 DEBUG_OFF(msg, LDP_DEBUG_MSG_SEND_ALL);
82 } else {
83 DEBUG_ON(msg, LDP_DEBUG_MSG_SEND);
84 if (all)
85 DEBUG_ON(msg, LDP_DEBUG_MSG_SEND_ALL);
86 }
87 }
88 } else if (strcmp(type_str, "sync") == 0) {
89 if (negate)
90 DEBUG_OFF(sync, LDP_DEBUG_SYNC);
91 else
92 DEBUG_ON(sync, LDP_DEBUG_SYNC);
93 } else if (strcmp(type_str, "zebra") == 0) {
94 if (negate)
95 DEBUG_OFF(zebra, LDP_DEBUG_ZEBRA);
96 else
97 DEBUG_ON(zebra, LDP_DEBUG_ZEBRA);
98 }
99
100 main_imsg_compose_both(IMSG_DEBUG_UPDATE, &ldp_debug,
101 sizeof(ldp_debug));
102
103 return (CMD_SUCCESS);
104 }
105
106 int
107 ldp_vty_show_debugging(struct vty *vty)
108 {
109 vty_out (vty, "LDP debugging status:\n");
110
111 if (LDP_DEBUG(hello, LDP_DEBUG_HELLO_RECV))
112 vty_out (vty," LDP discovery debugging is on (inbound)\n");
113 if (LDP_DEBUG(hello, LDP_DEBUG_HELLO_SEND))
114 vty_out (vty," LDP discovery debugging is on (outbound)\n");
115 if (LDP_DEBUG(errors, LDP_DEBUG_ERRORS))
116 vty_out (vty, " LDP errors debugging is on\n");
117 if (LDP_DEBUG(event, LDP_DEBUG_EVENT))
118 vty_out (vty, " LDP events debugging is on\n");
119 if (LDP_DEBUG(labels, LDP_DEBUG_LABELS))
120 vty_out (vty, " LDP labels debugging is on\n");
121 if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV_ALL))
122 vty_out (vty,
123 " LDP detailed messages debugging is on (inbound)\n");
124 else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV))
125 vty_out (vty," LDP messages debugging is on (inbound)\n");
126 if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND_ALL))
127 vty_out (vty,
128 " LDP detailed messages debugging is on (outbound)\n");
129 else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND))
130 vty_out (vty," LDP messages debugging is on (outbound)\n");
131 if (LDP_DEBUG(sync, LDP_DEBUG_SYNC))
132 vty_out (vty, " LDP sync debugging is on\n");
133 if (LDP_DEBUG(zebra, LDP_DEBUG_ZEBRA))
134 vty_out (vty, " LDP zebra debugging is on\n");
135 vty_out (vty, "\n");
136
137 return (CMD_SUCCESS);
138 }
139
140 static int
141 ldp_debug_config_write(struct vty *vty)
142 {
143 int write = 0;
144
145 if (CONF_LDP_DEBUG(hello, LDP_DEBUG_HELLO_RECV)) {
146 vty_out (vty,"debug mpls ldp discovery hello recv\n");
147 write = 1;
148 }
149
150 if (CONF_LDP_DEBUG(hello, LDP_DEBUG_HELLO_SEND)) {
151 vty_out (vty,"debug mpls ldp discovery hello sent\n");
152 write = 1;
153 }
154
155 if (CONF_LDP_DEBUG(errors, LDP_DEBUG_ERRORS)) {
156 vty_out (vty, "debug mpls ldp errors\n");
157 write = 1;
158 }
159
160 if (CONF_LDP_DEBUG(event, LDP_DEBUG_EVENT)) {
161 vty_out (vty, "debug mpls ldp event\n");
162 write = 1;
163 }
164
165 if (CONF_LDP_DEBUG(labels, LDP_DEBUG_LABELS)) {
166 vty_out (vty, "debug mpls ldp labels\n");
167 write = 1;
168 }
169
170 if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV_ALL)) {
171 vty_out (vty, "debug mpls ldp messages recv all\n");
172 write = 1;
173 } else if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV)) {
174 vty_out (vty, "debug mpls ldp messages recv\n");
175 write = 1;
176 }
177
178 if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND_ALL)) {
179 vty_out (vty, "debug mpls ldp messages sent all\n");
180 write = 1;
181 } else if (CONF_LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND)) {
182 vty_out (vty, "debug mpls ldp messages sent\n");
183 write = 1;
184 }
185
186 if (CONF_LDP_DEBUG(zebra, LDP_DEBUG_ZEBRA)) {
187 vty_out (vty, "debug mpls ldp zebra\n");
188 write = 1;
189 }
190
191 if (CONF_LDP_DEBUG(sync, LDP_DEBUG_SYNC)) {
192 vty_out (vty, "debug mpls ldp sync\n");
193 write = 1;
194 }
195
196 return (write);
197 }