]> git.proxmox.com Git - mirror_frr.git/blame - ldpd/ldp_debug.c
Merge pull request #718 from qlyoung/fix-vtysh-shit
[mirror_frr.git] / ldpd / ldp_debug.c
CommitLineData
eac6e3f0
RW
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 *
896014f4
DL
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
eac6e3f0
RW
19 */
20
21#include <zebra.h>
22
23#include "command.h"
24#include "vty.h"
25
26#include "ldpd.h"
27#include "ldp_debug.h"
28#include "ldp_vty.h"
29
30struct ldp_debug conf_ldp_debug;
31struct ldp_debug ldp_debug;
32
33/* Debug node. */
34struct cmd_node ldp_debug_node =
35{
36 DEBUG_NODE,
37 "",
38 1
39};
40
41int
42ldp_vty_debug(struct vty *vty, struct vty_arg *args[])
43{
44 const char *type_str, *dir_str;
45 int disable, all;
46
47 disable = (vty_get_arg_value(args, "no")) ? 1 : 0;
48 type_str = vty_get_arg_value(args, "type");
49
50 if (strcmp(type_str, "discovery") == 0) {
51 dir_str = vty_get_arg_value(args, "dir");
52 if (dir_str == NULL)
53 return (CMD_WARNING);
54
55 if (dir_str[0] == 'r') {
56 if (disable)
57 DEBUG_OFF(hello, HELLO_RECV);
58 else
59 DEBUG_ON(hello, HELLO_RECV);
60 } else {
61 if (disable)
62 DEBUG_OFF(hello, HELLO_SEND);
63 else
64 DEBUG_ON(hello, HELLO_SEND);
65 }
66 } else if (strcmp(type_str, "errors") == 0) {
67 if (disable)
68 DEBUG_OFF(errors, ERRORS);
69 else
70 DEBUG_ON(errors, ERRORS);
71 } else if (strcmp(type_str, "event") == 0) {
72 if (disable)
73 DEBUG_OFF(event, EVENT);
74 else
75 DEBUG_ON(event, EVENT);
7d3d7491 76 } else if (strcmp(type_str, "messages") == 0) {
eac6e3f0
RW
77 all = (vty_get_arg_value(args, "all")) ? 1 : 0;
78 dir_str = vty_get_arg_value(args, "dir");
79 if (dir_str == NULL)
80 return (CMD_WARNING);
81
82 if (dir_str[0] == 'r') {
83 if (disable) {
84 DEBUG_OFF(msg, MSG_RECV);
85 DEBUG_OFF(msg, MSG_RECV_ALL);
86 } else {
87 DEBUG_ON(msg, MSG_RECV);
88 if (all)
89 DEBUG_ON(msg, MSG_RECV_ALL);
90 }
91 } else {
92 if (disable) {
93 DEBUG_OFF(msg, MSG_SEND);
94 DEBUG_OFF(msg, MSG_SEND_ALL);
95 } else {
96 DEBUG_ON(msg, MSG_SEND);
97 if (all)
98 DEBUG_ON(msg, MSG_SEND_ALL);
99 }
100 }
7d3d7491 101 } else if (strcmp(type_str, "zebra") == 0) {
eac6e3f0
RW
102 if (disable)
103 DEBUG_OFF(zebra, ZEBRA);
104 else
105 DEBUG_ON(zebra, ZEBRA);
106 }
107
108 main_imsg_compose_both(IMSG_DEBUG_UPDATE, &ldp_debug,
109 sizeof(ldp_debug));
110
111 return (CMD_SUCCESS);
112}
113
114int
115ldp_vty_show_debugging(struct vty *vty, struct vty_arg *args[])
116{
117 vty_out(vty, "LDP debugging status:%s", VTY_NEWLINE);
118
119 if (LDP_DEBUG(hello, HELLO_RECV))
120 vty_out(vty, " LDP discovery debugging is on (inbound)%s",
121 VTY_NEWLINE);
122 if (LDP_DEBUG(hello, HELLO_SEND))
123 vty_out(vty, " LDP discovery debugging is on (outbound)%s",
124 VTY_NEWLINE);
125 if (LDP_DEBUG(errors, ERRORS))
126 vty_out(vty, " LDP errors debugging is on%s", VTY_NEWLINE);
127 if (LDP_DEBUG(event, EVENT))
128 vty_out(vty, " LDP events debugging is on%s", VTY_NEWLINE);
129 if (LDP_DEBUG(msg, MSG_RECV_ALL))
130 vty_out(vty, " LDP detailed messages debugging is on "
131 "(inbound)%s", VTY_NEWLINE);
132 else if (LDP_DEBUG(msg, MSG_RECV))
133 vty_out(vty, " LDP messages debugging is on (inbound)%s",
134 VTY_NEWLINE);
135 if (LDP_DEBUG(msg, MSG_SEND_ALL))
136 vty_out(vty, " LDP detailed messages debugging is on "
137 "(outbound)%s", VTY_NEWLINE);
138 else if (LDP_DEBUG(msg, MSG_SEND))
139 vty_out(vty, " LDP messages debugging is on (outbound)%s",
140 VTY_NEWLINE);
141 if (LDP_DEBUG(zebra, ZEBRA))
142 vty_out(vty, " LDP zebra debugging is on%s", VTY_NEWLINE);
143 vty_out (vty, "%s", VTY_NEWLINE);
144
145 return (CMD_SUCCESS);
146}
147
148int
149ldp_debug_config_write(struct vty *vty)
150{
151 int write = 0;
152
153 if (CONF_LDP_DEBUG(hello, HELLO_RECV)) {
154 vty_out(vty, "debug mpls ldp discovery hello recv%s",
155 VTY_NEWLINE);
156 write = 1;
157 }
158
159 if (CONF_LDP_DEBUG(hello, HELLO_SEND)) {
160 vty_out(vty, "debug mpls ldp discovery hello sent%s",
161 VTY_NEWLINE);
162 write = 1;
163 }
164
165 if (CONF_LDP_DEBUG(errors, ERRORS)) {
166 vty_out(vty, "debug mpls ldp errors%s", VTY_NEWLINE);
167 write = 1;
168 }
169
170 if (CONF_LDP_DEBUG(event, EVENT)) {
171 vty_out(vty, "debug mpls ldp event%s", VTY_NEWLINE);
172 write = 1;
173 }
174
175 if (CONF_LDP_DEBUG(msg, MSG_RECV_ALL)) {
176 vty_out(vty, "debug mpls ldp messages recv all%s", VTY_NEWLINE);
177 write = 1;
178 } else if (CONF_LDP_DEBUG(msg, MSG_RECV)) {
179 vty_out(vty, "debug mpls ldp messages recv%s", VTY_NEWLINE);
180 write = 1;
181 }
182
183 if (CONF_LDP_DEBUG(msg, MSG_SEND_ALL)) {
184 vty_out(vty, "debug mpls ldp messages sent all%s", VTY_NEWLINE);
185 write = 1;
186 } else if (CONF_LDP_DEBUG(msg, MSG_SEND)) {
187 vty_out(vty, "debug mpls ldp messages sent%s", VTY_NEWLINE);
188 write = 1;
189 }
190
191 if (CONF_LDP_DEBUG(zebra, ZEBRA)) {
192 vty_out(vty, "debug mpls ldp zebra%s", VTY_NEWLINE);
193 write = 1;
194 }
195
196 return (write);
197}