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