1 // SPDX-License-Identifier: MIT
3 Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
13 #include "babel_zebra.h"
14 #include "babel_interface.h"
18 void babelz_zebra_init(void);
21 /* we must use a pointer because of zclient.c's functions (new, free). */
22 struct zclient
*zclient
;
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"},
40 /* Zebra route add and delete treatment. */
42 babel_zebra_read_route (ZAPI_CALLBACK_ARGS
)
44 struct zapi_route api
;
46 if (zapi_route_decode(zclient
->ibuf
, &api
) < 0)
49 /* we completely ignore srcdest routes for now. */
50 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_SRCPFX
))
53 if (cmd
== ZEBRA_REDISTRIBUTE_ROUTE_ADD
) {
54 babel_route_add(&api
);
56 babel_route_delete(&api
);
63 DEFUN (babel_redistribute_type
,
64 babel_redistribute_type_cmd
,
65 "[no] redistribute <ipv4 " FRR_IP_REDIST_STR_BABELD
"|ipv6 " FRR_IP6_REDIST_STR_BABELD
">",
68 "Redistribute IPv4 routes\n"
69 FRR_IP_REDIST_HELP_STR_BABELD
70 "Redistribute IPv6 routes\n"
71 FRR_IP6_REDIST_HELP_STR_BABELD
)
79 if (argv_find(argv
, argc
, "no", &idx
))
81 argv_find(argv
, argc
, "redistribute", &idx
);
82 family
= str2family(argv
[idx
+ 1]->text
);
84 return CMD_WARNING_CONFIG_FAILED
;
86 afi
= family2afi(family
);
88 return CMD_WARNING_CONFIG_FAILED
;
90 type
= proto_redistnum(afi
, argv
[idx
+ 2]->text
);
92 vty_out (vty
, "Invalid type %s\n", argv
[idx
+ 2]->arg
);
93 return CMD_WARNING_CONFIG_FAILED
;
97 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD
, zclient
, afi
, type
, 0, VRF_DEFAULT
);
99 zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE
, zclient
, afi
, type
, 0, VRF_DEFAULT
);
100 /* perhaps should we remove xroutes having the same type... */
106 /* [Babel Command] */
109 "debug babel <common|kernel|filter|timeout|interface|route|all>",
110 "Enable debug messages for specific or all part.\n"
111 "Babel information\n"
112 "Common messages (default)\n"
116 "Interface messages\n"
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) {
125 SET_FLAG(debug
, debug_type
[i
].type
);
130 vty_out (vty
, "Invalid type %s\n", argv
[2]->arg
);
132 return CMD_WARNING_CONFIG_FAILED
;
135 /* [Babel Command] */
136 DEFUN (no_debug_babel
,
138 "no debug babel <common|kernel|filter|timeout|interface|route|all>",
140 "Disable debug messages for specific or all part.\n"
141 "Babel information\n"
142 "Common messages (default)\n"
146 "Interface messages\n"
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) {
155 UNSET_FLAG(debug
, debug_type
[i
].type
);
160 vty_out (vty
, "Invalid type %s\n", argv
[3]->arg
);
162 return CMD_WARNING_CONFIG_FAILED
;
164 #endif /* NO_DEBUG */
166 /* Output "debug" statement lines, if necessary. */
168 debug_babel_config_write (struct vty
* vty
)
175 if (debug
== BABEL_DEBUG_ALL
)
177 vty_out (vty
, "debug babel all\n");
182 for (i
= 0; debug_type
[i
].str
!= NULL
; i
++)
184 if (debug_type
[i
].type
!= BABEL_DEBUG_ALL
185 && CHECK_FLAG (debug
, debug_type
[i
].type
))
187 vty_out (vty
, "debug babel %s\n", debug_type
[i
].str
);
195 vty_out (vty
, "!\n");
199 #endif /* NO_DEBUG */
202 DEFUN_NOSH (show_debugging_babel
,
203 show_debugging_babel_cmd
,
204 "show debugging [babel]",
209 vty_out(vty
, "BABEL debugging status\n");
211 debug_babel_config_write(vty
);
213 cmd_show_lib_debugs(vty
);
219 babel_zebra_connected (struct zclient
*zclient
)
221 zclient_send_reg_requests (zclient
, VRF_DEFAULT
);
224 static 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
,
231 void babelz_zebra_init(void)
233 zclient
= zclient_new(master
, &zclient_options_default
, babel_handlers
,
234 array_size(babel_handlers
));
235 zclient_init(zclient
, ZEBRA_ROUTE_BABEL
, 0, &babeld_privs
);
237 zclient
->zebra_connected
= babel_zebra_connected
;
239 install_element(BABEL_NODE
, &babel_redistribute_type_cmd
);
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
);
245 install_element(ENABLE_NODE
, &show_debugging_babel_cmd
);
249 babel_zebra_close_connexion(void)
251 zclient_stop(zclient
);
252 zclient_free(zclient
);