2 Copyright 2011 by Matthieu Boutier and Juliusz Chroboczek
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 #include "babel_zebra.h"
31 #include "babel_interface.h"
35 void babelz_zebra_init(void);
38 /* we must use a pointer because of zclient.c's functions (new, free). */
39 struct zclient
*zclient
;
47 {BABEL_DEBUG_COMMON
, 1, "common"},
48 {BABEL_DEBUG_KERNEL
, 1, "kernel"},
49 {BABEL_DEBUG_FILTER
, 1, "filter"},
50 {BABEL_DEBUG_TIMEOUT
, 1, "timeout"},
51 {BABEL_DEBUG_IF
, 1, "interface"},
52 {BABEL_DEBUG_ROUTE
, 1, "route"},
53 {BABEL_DEBUG_ALL
, 1, "all"},
57 /* Zebra route add and delete treatment. */
59 babel_zebra_read_route (ZAPI_CALLBACK_ARGS
)
61 struct zapi_route api
;
63 if (zapi_route_decode(zclient
->ibuf
, &api
) < 0)
66 /* we completely ignore srcdest routes for now. */
67 if (CHECK_FLAG(api
.message
, ZAPI_MESSAGE_SRCPFX
))
70 if (cmd
== ZEBRA_REDISTRIBUTE_ROUTE_ADD
) {
71 babel_route_add(&api
);
73 babel_route_delete(&api
);
80 DEFUN (babel_redistribute_type
,
81 babel_redistribute_type_cmd
,
82 "[no] redistribute <ipv4 " FRR_IP_REDIST_STR_BABELD
"|ipv6 " FRR_IP6_REDIST_STR_BABELD
">",
85 "Redistribute IPv4 routes\n"
86 FRR_IP_REDIST_HELP_STR_BABELD
87 "Redistribute IPv6 routes\n"
88 FRR_IP6_REDIST_HELP_STR_BABELD
)
96 if (argv_find(argv
, argc
, "no", &idx
))
98 argv_find(argv
, argc
, "redistribute", &idx
);
99 family
= str2family(argv
[idx
+ 1]->text
);
101 return CMD_WARNING_CONFIG_FAILED
;
103 afi
= family2afi(family
);
105 return CMD_WARNING_CONFIG_FAILED
;
107 type
= proto_redistnum(afi
, argv
[idx
+ 2]->text
);
109 vty_out (vty
, "Invalid type %s\n", argv
[idx
+ 2]->arg
);
110 return CMD_WARNING_CONFIG_FAILED
;
114 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD
, zclient
, afi
, type
, 0, VRF_DEFAULT
);
116 zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE
, zclient
, afi
, type
, 0, VRF_DEFAULT
);
117 /* perhaps should we remove xroutes having the same type... */
123 /* [Babel Command] */
126 "debug babel <common|kernel|filter|timeout|interface|route|all>",
127 "Enable debug messages for specific or all part.\n"
128 "Babel information\n"
129 "Common messages (default)\n"
133 "Interface messages\n"
139 for(i
= 0; debug_type
[i
].str
!= NULL
; i
++) {
140 if (strncmp (debug_type
[i
].str
, argv
[2]->arg
,
141 debug_type
[i
].str_min_len
) == 0) {
142 debug
|= debug_type
[i
].type
;
147 vty_out (vty
, "Invalid type %s\n", argv
[2]->arg
);
149 return CMD_WARNING_CONFIG_FAILED
;
152 /* [Babel Command] */
153 DEFUN (no_debug_babel
,
155 "no debug babel <common|kernel|filter|timeout|interface|route|all>",
157 "Disable debug messages for specific or all part.\n"
158 "Babel information\n"
159 "Common messages (default)\n"
163 "Interface messages\n"
169 for (i
= 0; debug_type
[i
].str
; i
++) {
170 if (strncmp(debug_type
[i
].str
, argv
[3]->arg
,
171 debug_type
[i
].str_min_len
) == 0) {
172 debug
&= ~debug_type
[i
].type
;
177 vty_out (vty
, "Invalid type %s\n", argv
[3]->arg
);
179 return CMD_WARNING_CONFIG_FAILED
;
181 #endif /* NO_DEBUG */
183 /* Output "debug" statement lines, if necessary. */
185 debug_babel_config_write (struct vty
* vty
)
192 if (debug
== BABEL_DEBUG_ALL
)
194 vty_out (vty
, "debug babel all\n");
198 for (i
= 0; debug_type
[i
].str
!= NULL
; i
++)
201 debug_type
[i
].type
!= BABEL_DEBUG_ALL
202 && CHECK_FLAG (debug
, debug_type
[i
].type
)
205 vty_out (vty
, "debug babel %s\n", debug_type
[i
].str
);
210 vty_out (vty
, "!\n");
214 #endif /* NO_DEBUG */
217 DEFUN_NOSH (show_debugging_babel
,
218 show_debugging_babel_cmd
,
219 "show debugging [babel]",
224 vty_out(vty
, "BABEL debugging status\n");
226 debug_babel_config_write(vty
);
232 babel_zebra_connected (struct zclient
*zclient
)
234 zclient_send_reg_requests (zclient
, VRF_DEFAULT
);
237 void babelz_zebra_init(void)
239 zclient
= zclient_new(master
, &zclient_options_default
);
240 zclient_init(zclient
, ZEBRA_ROUTE_BABEL
, 0, &babeld_privs
);
242 zclient
->zebra_connected
= babel_zebra_connected
;
243 zclient
->interface_address_add
= babel_interface_address_add
;
244 zclient
->interface_address_delete
= babel_interface_address_delete
;
245 zclient
->redistribute_route_add
= babel_zebra_read_route
;
246 zclient
->redistribute_route_del
= babel_zebra_read_route
;
248 install_element(BABEL_NODE
, &babel_redistribute_type_cmd
);
249 install_element(ENABLE_NODE
, &debug_babel_cmd
);
250 install_element(ENABLE_NODE
, &no_debug_babel_cmd
);
251 install_element(CONFIG_NODE
, &debug_babel_cmd
);
252 install_element(CONFIG_NODE
, &no_debug_babel_cmd
);
254 install_element(ENABLE_NODE
, &show_debugging_babel_cmd
);
258 babel_zebra_close_connexion(void)
260 zclient_stop(zclient
);
261 zclient_free(zclient
);