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