]> git.proxmox.com Git - mirror_frr.git/blame - babeld/babel_zebra.c
Merge pull request #13163 from isabelladeleon12/isis_log_drops
[mirror_frr.git] / babeld / babel_zebra.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: MIT
ca10883e
DS
2/*
3Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
ca10883e
DS
4*/
5
6/* FRR's includes */
7#include <zebra.h>
8#include "command.h"
9#include "zclient.h"
10#include "stream.h"
11
12/* babel's includes*/
13#include "babel_zebra.h"
14#include "babel_interface.h"
15#include "xroute.h"
16#include "util.h"
17
18void babelz_zebra_init(void);
19
20
21/* we must use a pointer because of zclient.c's functions (new, free). */
22struct zclient *zclient;
ca10883e
DS
23
24/* Debug types */
2b64873d 25static const struct {
ca10883e
DS
26 int type;
27 int str_min_len;
28 const char *str;
29} debug_type[] = {
30 {BABEL_DEBUG_COMMON, 1, "common"},
31 {BABEL_DEBUG_KERNEL, 1, "kernel"},
32 {BABEL_DEBUG_FILTER, 1, "filter"},
33 {BABEL_DEBUG_TIMEOUT, 1, "timeout"},
34 {BABEL_DEBUG_IF, 1, "interface"},
35 {BABEL_DEBUG_ROUTE, 1, "route"},
36 {BABEL_DEBUG_ALL, 1, "all"},
37 {0, 0, NULL}
38};
39
74489921 40/* Zebra route add and delete treatment. */
ca10883e 41static int
121f9dee 42babel_zebra_read_route (ZAPI_CALLBACK_ARGS)
ca10883e 43{
74489921 44 struct zapi_route api;
ca10883e 45
74489921
RW
46 if (zapi_route_decode(zclient->ibuf, &api) < 0)
47 return -1;
ca10883e 48
74489921
RW
49 /* we completely ignore srcdest routes for now. */
50 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX))
51 return 0;
ca10883e 52
121f9dee 53 if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD) {
74489921 54 babel_route_add(&api);
ca10883e 55 } else {
74489921 56 babel_route_delete(&api);
ca10883e
DS
57 }
58
59 return 0;
60}
61
ca10883e
DS
62/* [Babel Command] */
63DEFUN (babel_redistribute_type,
64 babel_redistribute_type_cmd,
dd8765ca
RW
65 "[no] redistribute <ipv4 " FRR_IP_REDIST_STR_BABELD "|ipv6 " FRR_IP6_REDIST_STR_BABELD ">",
66 NO_STR
ca10883e 67 "Redistribute\n"
dd8765ca
RW
68 "Redistribute IPv4 routes\n"
69 FRR_IP_REDIST_HELP_STR_BABELD
70 "Redistribute IPv6 routes\n"
71 FRR_IP6_REDIST_HELP_STR_BABELD)
ca10883e 72{
dd8765ca
RW
73 int negate = 0;
74 int family;
75 int afi;
ca10883e 76 int type;
dd8765ca 77 int idx = 0;
ca10883e 78
dd8765ca
RW
79 if (argv_find(argv, argc, "no", &idx))
80 negate = 1;
81 argv_find(argv, argc, "redistribute", &idx);
82 family = str2family(argv[idx + 1]->text);
83 if (family < 0)
f1a05de9 84 return CMD_WARNING_CONFIG_FAILED;
ca10883e 85
dd8765ca
RW
86 afi = family2afi(family);
87 if (!afi)
88 return CMD_WARNING_CONFIG_FAILED;
ca10883e 89
dd8765ca 90 type = proto_redistnum(afi, argv[idx + 2]->text);
ca10883e 91 if (type < 0) {
dd8765ca 92 vty_out (vty, "Invalid type %s\n", argv[idx + 2]->arg);
f1a05de9 93 return CMD_WARNING_CONFIG_FAILED;
ca10883e
DS
94 }
95
dd8765ca
RW
96 if (!negate)
97 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, 0, VRF_DEFAULT);
98 else {
99 zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, type, 0, VRF_DEFAULT);
100 /* perhaps should we remove xroutes having the same type... */
101 }
ca10883e
DS
102 return CMD_SUCCESS;
103}
104
105#ifndef NO_DEBUG
106/* [Babel Command] */
107DEFUN (debug_babel,
108 debug_babel_cmd,
f7bf422e 109 "debug babel <common|kernel|filter|timeout|interface|route|all>",
ca10883e
DS
110 "Enable debug messages for specific or all part.\n"
111 "Babel information\n"
112 "Common messages (default)\n"
113 "Kernel messages\n"
114 "Filter messages\n"
115 "Timeout messages\n"
116 "Interface messages\n"
117 "Route messages\n"
118 "All messages\n")
119{
120 int i;
121
122 for(i = 0; debug_type[i].str != NULL; i++) {
123 if (strncmp (debug_type[i].str, argv[2]->arg,
124 debug_type[i].str_min_len) == 0) {
03b7208c 125 SET_FLAG(debug, debug_type[i].type);
ca10883e
DS
126 return CMD_SUCCESS;
127 }
128 }
129
5c7571d4 130 vty_out (vty, "Invalid type %s\n", argv[2]->arg);
ca10883e 131
f1a05de9 132 return CMD_WARNING_CONFIG_FAILED;
ca10883e
DS
133}
134
135/* [Babel Command] */
136DEFUN (no_debug_babel,
137 no_debug_babel_cmd,
f7bf422e 138 "no debug babel <common|kernel|filter|timeout|interface|route|all>",
ca10883e
DS
139 NO_STR
140 "Disable debug messages for specific or all part.\n"
141 "Babel information\n"
142 "Common messages (default)\n"
143 "Kernel messages\n"
144 "Filter messages\n"
145 "Timeout messages\n"
146 "Interface messages\n"
147 "Route messages\n"
148 "All messages\n")
149{
150 int i;
151
152 for (i = 0; debug_type[i].str; i++) {
153 if (strncmp(debug_type[i].str, argv[3]->arg,
154 debug_type[i].str_min_len) == 0) {
03b7208c 155 UNSET_FLAG(debug, debug_type[i].type);
ca10883e
DS
156 return CMD_SUCCESS;
157 }
158 }
159
5c7571d4 160 vty_out (vty, "Invalid type %s\n", argv[3]->arg);
ca10883e 161
f1a05de9 162 return CMD_WARNING_CONFIG_FAILED;
ca10883e
DS
163}
164#endif /* NO_DEBUG */
165
166/* Output "debug" statement lines, if necessary. */
167int
168debug_babel_config_write (struct vty * vty)
169{
170#ifdef NO_DEBUG
171 return 0;
172#else
173 int i, lines = 0;
174
175 if (debug == BABEL_DEBUG_ALL)
176 {
5c7571d4 177 vty_out (vty, "debug babel all\n");
ca10883e
DS
178 lines++;
179 }
180 else
03b7208c 181 {
ca10883e 182 for (i = 0; debug_type[i].str != NULL; i++)
03b7208c 183 {
184 if (debug_type[i].type != BABEL_DEBUG_ALL
185 && CHECK_FLAG (debug, debug_type[i].type))
ca10883e 186 {
5c7571d4 187 vty_out (vty, "debug babel %s\n", debug_type[i].str);
ca10883e
DS
188 lines++;
189 }
03b7208c 190 }
191 }
192
ca10883e
DS
193 if (lines)
194 {
5c7571d4 195 vty_out (vty, "!\n");
ca10883e
DS
196 lines++;
197 }
198 return lines;
199#endif /* NO_DEBUG */
200}
201
87f6dc50
DS
202DEFUN_NOSH (show_debugging_babel,
203 show_debugging_babel_cmd,
204 "show debugging [babel]",
205 SHOW_STR
206 DEBUG_STR
207 "Babel")
208{
209 vty_out(vty, "BABEL debugging status\n");
210
211 debug_babel_config_write(vty);
212
cf00164b
DS
213 cmd_show_lib_debugs(vty);
214
87f6dc50
DS
215 return CMD_SUCCESS;
216}
217
abdcf266
DS
218static void
219babel_zebra_connected (struct zclient *zclient)
220{
221 zclient_send_reg_requests (zclient, VRF_DEFAULT);
222}
223
a243d1db
DL
224static zclient_handler *const babel_handlers[] = {
225 [ZEBRA_INTERFACE_ADDRESS_ADD] = babel_interface_address_add,
226 [ZEBRA_INTERFACE_ADDRESS_DELETE] = babel_interface_address_delete,
227 [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = babel_zebra_read_route,
228 [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = babel_zebra_read_route,
229};
230
ca10883e
DS
231void babelz_zebra_init(void)
232{
a243d1db
DL
233 zclient = zclient_new(master, &zclient_options_default, babel_handlers,
234 array_size(babel_handlers));
342213ea 235 zclient_init(zclient, ZEBRA_ROUTE_BABEL, 0, &babeld_privs);
ca10883e 236
abdcf266 237 zclient->zebra_connected = babel_zebra_connected;
ca10883e 238
ca10883e 239 install_element(BABEL_NODE, &babel_redistribute_type_cmd);
ca10883e
DS
240 install_element(ENABLE_NODE, &debug_babel_cmd);
241 install_element(ENABLE_NODE, &no_debug_babel_cmd);
242 install_element(CONFIG_NODE, &debug_babel_cmd);
243 install_element(CONFIG_NODE, &no_debug_babel_cmd);
87f6dc50 244
dd73744d 245 install_element(ENABLE_NODE, &show_debugging_babel_cmd);
ca10883e
DS
246}
247
ca10883e
DS
248void
249babel_zebra_close_connexion(void)
250{
251 zclient_stop(zclient);
6b02aecb 252 zclient_free(zclient);
ca10883e 253}