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