]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
508e53e2 | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
718e3744 | 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 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with GNU Zebra; see the file COPYING. If not, write to the | |
18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | * Boston, MA 02111-1307, USA. | |
20 | */ | |
21 | ||
508e53e2 | 22 | #include <zebra.h> |
23 | ||
24 | #include "log.h" | |
25 | #include "vty.h" | |
26 | #include "command.h" | |
27 | #include "prefix.h" | |
28 | #include "stream.h" | |
29 | #include "zclient.h" | |
30 | #include "memory.h" | |
718e3744 | 31 | |
508e53e2 | 32 | #include "ospf6_proto.h" |
33 | #include "ospf6_top.h" | |
718e3744 | 34 | #include "ospf6_interface.h" |
508e53e2 | 35 | #include "ospf6_route.h" |
36 | #include "ospf6_lsa.h" | |
049207c3 | 37 | #include "ospf6_lsdb.h" |
718e3744 | 38 | #include "ospf6_asbr.h" |
508e53e2 | 39 | #include "ospf6_zebra.h" |
049207c3 | 40 | #include "ospf6d.h" |
718e3744 | 41 | |
508e53e2 | 42 | unsigned char conf_debug_ospf6_zebra = 0; |
718e3744 | 43 | |
44 | /* information about zebra. */ | |
45 | struct zclient *zclient = NULL; | |
46 | ||
18a6dce6 | 47 | struct in_addr router_id_zebra; |
48 | ||
49 | /* Router-id update message from zebra. */ | |
6ac29a51 | 50 | static int |
18a6dce6 | 51 | ospf6_router_id_update_zebra (int command, struct zclient *zclient, |
7076bb2f | 52 | zebra_size_t length, vrf_id_t vrf_id) |
18a6dce6 | 53 | { |
54 | struct prefix router_id; | |
55 | struct ospf6 *o = ospf6; | |
56 | ||
57 | zebra_router_id_update_read(zclient->ibuf,&router_id); | |
58 | router_id_zebra = router_id.u.prefix4; | |
59 | ||
c1ba9e8a | 60 | if (o == NULL) |
61 | return 0; | |
62 | ||
18a6dce6 | 63 | if (o->router_id == 0) |
64 | o->router_id = (u_int32_t) router_id_zebra.s_addr; | |
65 | ||
66 | return 0; | |
67 | } | |
68 | ||
718e3744 | 69 | /* redistribute function */ |
70 | void | |
71 | ospf6_zebra_redistribute (int type) | |
72 | { | |
7076bb2f | 73 | if (vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT)) |
718e3744 | 74 | return; |
7076bb2f FL |
75 | vrf_bitmap_set (zclient->redist[AFI_IP6][type], VRF_DEFAULT); |
76 | ||
718e3744 | 77 | if (zclient->sock > 0) |
7076bb2f FL |
78 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0, |
79 | VRF_DEFAULT); | |
718e3744 | 80 | } |
81 | ||
82 | void | |
83 | ospf6_zebra_no_redistribute (int type) | |
84 | { | |
7076bb2f | 85 | if (!vrf_bitmap_check (zclient->redist[AFI_IP6][type], VRF_DEFAULT)) |
718e3744 | 86 | return; |
7076bb2f | 87 | vrf_bitmap_unset (zclient->redist[AFI_IP6][type], VRF_DEFAULT); |
718e3744 | 88 | if (zclient->sock > 0) |
7076bb2f FL |
89 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP6, type, |
90 | 0, VRF_DEFAULT); | |
718e3744 | 91 | } |
92 | ||
718e3744 | 93 | /* Inteface addition message from zebra. */ |
6ac29a51 | 94 | static int |
7076bb2f FL |
95 | ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length, |
96 | vrf_id_t vrf_id) | |
718e3744 | 97 | { |
98 | struct interface *ifp; | |
99 | ||
7076bb2f | 100 | ifp = zebra_interface_add_read (zclient->ibuf, vrf_id); |
508e53e2 | 101 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
c6487d61 | 102 | zlog_debug ("Zebra Interface add: %s index %d mtu %d", |
103 | ifp->name, ifp->ifindex, ifp->mtu6); | |
718e3744 | 104 | ospf6_interface_if_add (ifp); |
718e3744 | 105 | return 0; |
106 | } | |
107 | ||
6ac29a51 | 108 | static int |
7076bb2f FL |
109 | ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length, |
110 | vrf_id_t vrf_id) | |
718e3744 | 111 | { |
508e53e2 | 112 | struct interface *ifp; |
718e3744 | 113 | |
7076bb2f | 114 | if (!(ifp = zebra_interface_state_read (zclient->ibuf, vrf_id))) |
d2fc8896 | 115 | return 0; |
116 | ||
117 | if (if_is_up (ifp)) | |
118 | zlog_warn ("Zebra: got delete of %s, but interface is still up", ifp->name); | |
119 | ||
508e53e2 | 120 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
c6487d61 | 121 | zlog_debug ("Zebra Interface delete: %s index %d mtu %d", |
122 | ifp->name, ifp->ifindex, ifp->mtu6); | |
718e3744 | 123 | |
d2fc8896 | 124 | #if 0 |
d9628728 CF |
125 | /* XXX: ospf6_interface_if_del is not the right way to handle this, |
126 | * because among other thinkable issues, it will also clear all | |
127 | * settings as they are contained in the struct ospf6_interface. */ | |
718e3744 | 128 | ospf6_interface_if_del (ifp); |
508e53e2 | 129 | #endif /*0*/ |
d2fc8896 | 130 | |
84361d61 | 131 | ifp->ifindex = IFINDEX_DELETED; |
718e3744 | 132 | return 0; |
133 | } | |
134 | ||
6ac29a51 | 135 | static int |
718e3744 | 136 | ospf6_zebra_if_state_update (int command, struct zclient *zclient, |
7076bb2f | 137 | zebra_size_t length, vrf_id_t vrf_id) |
718e3744 | 138 | { |
139 | struct interface *ifp; | |
140 | ||
7076bb2f | 141 | ifp = zebra_interface_state_read (zclient->ibuf, vrf_id); |
57c4f4f4 IF |
142 | if (ifp == NULL) |
143 | return 0; | |
144 | ||
508e53e2 | 145 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
c6487d61 | 146 | zlog_debug ("Zebra Interface state change: " |
c19543b2 | 147 | "%s index %d flags %llx metric %d mtu %d bandwidth %d", |
30d20590 | 148 | ifp->name, ifp->ifindex, (unsigned long long)ifp->flags, |
c19543b2 | 149 | ifp->metric, ifp->mtu6, ifp->bandwidth); |
718e3744 | 150 | |
151 | ospf6_interface_state_update (ifp); | |
152 | return 0; | |
153 | } | |
154 | ||
6ac29a51 | 155 | static int |
718e3744 | 156 | ospf6_zebra_if_address_update_add (int command, struct zclient *zclient, |
7076bb2f | 157 | zebra_size_t length, vrf_id_t vrf_id) |
718e3744 | 158 | { |
159 | struct connected *c; | |
160 | char buf[128]; | |
161 | ||
7076bb2f FL |
162 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf, |
163 | vrf_id); | |
718e3744 | 164 | if (c == NULL) |
165 | return 0; | |
166 | ||
508e53e2 | 167 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
c6487d61 | 168 | zlog_debug ("Zebra Interface address add: %s %5s %s/%d", |
169 | c->ifp->name, prefix_family_str (c->address), | |
170 | inet_ntop (c->address->family, &c->address->u.prefix, | |
171 | buf, sizeof (buf)), c->address->prefixlen); | |
718e3744 | 172 | |
173 | if (c->address->family == AF_INET6) | |
b13c1d92 CF |
174 | { |
175 | ospf6_interface_state_update (c->ifp); | |
176 | ospf6_interface_connected_route_update (c->ifp); | |
177 | } | |
718e3744 | 178 | return 0; |
179 | } | |
180 | ||
6ac29a51 | 181 | static int |
718e3744 | 182 | ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient, |
7076bb2f | 183 | zebra_size_t length, vrf_id_t vrf_id) |
718e3744 | 184 | { |
185 | struct connected *c; | |
186 | char buf[128]; | |
187 | ||
7076bb2f FL |
188 | c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf, |
189 | vrf_id); | |
718e3744 | 190 | if (c == NULL) |
191 | return 0; | |
192 | ||
508e53e2 | 193 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
c6487d61 | 194 | zlog_debug ("Zebra Interface address delete: %s %5s %s/%d", |
195 | c->ifp->name, prefix_family_str (c->address), | |
196 | inet_ntop (c->address->family, &c->address->u.prefix, | |
197 | buf, sizeof (buf)), c->address->prefixlen); | |
718e3744 | 198 | |
199 | if (c->address->family == AF_INET6) | |
b13c1d92 CF |
200 | { |
201 | ospf6_interface_connected_route_update (c->ifp); | |
202 | ospf6_interface_state_update (c->ifp); | |
203 | } | |
718e3744 | 204 | |
205 | return 0; | |
206 | } | |
207 | ||
6ac29a51 | 208 | static int |
718e3744 | 209 | ospf6_zebra_read_ipv6 (int command, struct zclient *zclient, |
7076bb2f | 210 | zebra_size_t length, vrf_id_t vrf_id) |
718e3744 | 211 | { |
212 | struct stream *s; | |
213 | struct zapi_ipv6 api; | |
214 | unsigned long ifindex; | |
215 | struct prefix_ipv6 p; | |
216 | struct in6_addr *nexthop; | |
718e3744 | 217 | |
87bb7354 DS |
218 | if (ospf6 == NULL) |
219 | return 0; | |
220 | ||
718e3744 | 221 | s = zclient->ibuf; |
222 | ifindex = 0; | |
223 | nexthop = NULL; | |
224 | memset (&api, 0, sizeof (api)); | |
225 | ||
226 | /* Type, flags, message. */ | |
227 | api.type = stream_getc (s); | |
7c8ff89e | 228 | api.instance = stream_getw (s); |
718e3744 | 229 | api.flags = stream_getc (s); |
230 | api.message = stream_getc (s); | |
231 | ||
232 | /* IPv6 prefix. */ | |
233 | memset (&p, 0, sizeof (struct prefix_ipv6)); | |
234 | p.family = AF_INET6; | |
235 | p.prefixlen = stream_getc (s); | |
236 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); | |
237 | ||
238 | /* Nexthop, ifindex, distance, metric. */ | |
239 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) | |
240 | { | |
241 | api.nexthop_num = stream_getc (s); | |
242 | nexthop = (struct in6_addr *) | |
243 | malloc (api.nexthop_num * sizeof (struct in6_addr)); | |
244 | stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr)); | |
245 | } | |
246 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) | |
247 | { | |
248 | api.ifindex_num = stream_getc (s); | |
249 | ifindex = stream_getl (s); | |
250 | } | |
251 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) | |
252 | api.distance = stream_getc (s); | |
253 | else | |
254 | api.distance = 0; | |
255 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) | |
256 | api.metric = stream_getl (s); | |
257 | else | |
258 | api.metric = 0; | |
259 | ||
508e53e2 | 260 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
718e3744 | 261 | { |
4690c7d7 | 262 | char prefixstr[PREFIX2STR_BUFFER], nexthopstr[128]; |
718e3744 | 263 | prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr)); |
508e53e2 | 264 | if (nexthop) |
265 | inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr)); | |
718e3744 | 266 | else |
508e53e2 | 267 | snprintf (nexthopstr, sizeof (nexthopstr), "::"); |
268 | ||
c6487d61 | 269 | zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld", |
270 | (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"), | |
f52d13cb | 271 | zebra_route_string(api.type), prefixstr, nexthopstr, ifindex); |
718e3744 | 272 | } |
273 | ||
5048fe14 | 274 | if (command == ZEBRA_REDISTRIBUTE_IPV6_ADD) |
508e53e2 | 275 | ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p, |
276 | api.nexthop_num, nexthop); | |
718e3744 | 277 | else |
508e53e2 | 278 | ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p); |
718e3744 | 279 | |
280 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) | |
281 | free (nexthop); | |
282 | ||
283 | return 0; | |
284 | } | |
285 | ||
508e53e2 | 286 | |
287 | ||
6b0655a2 | 288 | |
718e3744 | 289 | DEFUN (show_zebra, |
290 | show_zebra_cmd, | |
291 | "show zebra", | |
292 | SHOW_STR | |
293 | "Zebra information\n") | |
294 | { | |
295 | int i; | |
508e53e2 | 296 | if (zclient == NULL) |
297 | { | |
049207c3 | 298 | vty_out (vty, "Not connected to zebra%s", VNL); |
508e53e2 | 299 | return CMD_SUCCESS; |
300 | } | |
718e3744 | 301 | |
049207c3 | 302 | vty_out (vty, "Zebra Infomation%s", VNL); |
508e53e2 | 303 | vty_out (vty, " enable: %d fail: %d%s", |
049207c3 | 304 | zclient->enable, zclient->fail, VNL); |
7076bb2f FL |
305 | vty_out (vty, " redistribute default: %d%s", |
306 | vrf_bitmap_check (zclient->default_information, VRF_DEFAULT), | |
049207c3 | 307 | VNL); |
508e53e2 | 308 | vty_out (vty, " redistribute:"); |
718e3744 | 309 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
508e53e2 | 310 | { |
7076bb2f | 311 | if (vrf_bitmap_check (zclient->redist[AFI_IP6][i], VRF_DEFAULT)) |
f52d13cb | 312 | vty_out (vty, " %s", zebra_route_string(i)); |
508e53e2 | 313 | } |
049207c3 | 314 | vty_out (vty, "%s", VNL); |
718e3744 | 315 | return CMD_SUCCESS; |
316 | } | |
317 | ||
318 | DEFUN (router_zebra, | |
319 | router_zebra_cmd, | |
320 | "router zebra", | |
321 | "Enable a routing process\n" | |
322 | "Make connection to zebra daemon\n") | |
323 | { | |
718e3744 | 324 | vty->node = ZEBRA_NODE; |
325 | zclient->enable = 1; | |
326 | zclient_start (zclient); | |
327 | return CMD_SUCCESS; | |
328 | } | |
329 | ||
330 | DEFUN (no_router_zebra, | |
331 | no_router_zebra_cmd, | |
332 | "no router zebra", | |
333 | NO_STR | |
334 | "Configure routing process\n" | |
335 | "Disable connection to zebra daemon\n") | |
336 | { | |
718e3744 | 337 | zclient->enable = 0; |
338 | zclient_stop (zclient); | |
339 | return CMD_SUCCESS; | |
340 | } | |
341 | ||
342 | /* Zebra configuration write function. */ | |
6ac29a51 | 343 | static int |
508e53e2 | 344 | config_write_ospf6_zebra (struct vty *vty) |
718e3744 | 345 | { |
346 | if (! zclient->enable) | |
347 | { | |
049207c3 | 348 | vty_out (vty, "no router zebra%s", VNL); |
349 | vty_out (vty, "!%s", VNL); | |
718e3744 | 350 | } |
7076bb2f FL |
351 | else if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], |
352 | VRF_DEFAULT)) | |
718e3744 | 353 | { |
049207c3 | 354 | vty_out (vty, "router zebra%s", VNL); |
355 | vty_out (vty, " no redistribute ospf6%s", VNL); | |
356 | vty_out (vty, "!%s", VNL); | |
718e3744 | 357 | } |
358 | return 0; | |
359 | } | |
360 | ||
361 | /* Zebra node structure. */ | |
7fc626de | 362 | static struct cmd_node zebra_node = |
718e3744 | 363 | { |
364 | ZEBRA_NODE, | |
365 | "%s(config-zebra)# ", | |
366 | }; | |
367 | ||
368 | #define ADD 0 | |
508e53e2 | 369 | #define REM 1 |
718e3744 | 370 | static void |
508e53e2 | 371 | ospf6_zebra_route_update (int type, struct ospf6_route *request) |
718e3744 | 372 | { |
718e3744 | 373 | struct zapi_ipv6 api; |
4690c7d7 | 374 | char buf[PREFIX2STR_BUFFER]; |
508e53e2 | 375 | int nhcount; |
718e3744 | 376 | struct in6_addr **nexthops; |
377 | unsigned int *ifindexes; | |
c3c0ac83 | 378 | int ret = 0; |
508e53e2 | 379 | struct prefix_ipv6 *dest; |
718e3744 | 380 | |
508e53e2 | 381 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
718e3744 | 382 | { |
508e53e2 | 383 | prefix2str (&request->prefix, buf, sizeof (buf)); |
c6487d61 | 384 | zlog_debug ("Send %s route: %s", |
385 | (type == REM ? "remove" : "add"), buf); | |
718e3744 | 386 | } |
387 | ||
388 | if (zclient->sock < 0) | |
389 | { | |
508e53e2 | 390 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
c6487d61 | 391 | zlog_debug (" Not connected to Zebra"); |
718e3744 | 392 | return; |
393 | } | |
394 | ||
395 | if (request->path.origin.adv_router == ospf6->router_id && | |
396 | (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 || | |
397 | request->path.type == OSPF6_PATH_TYPE_EXTERNAL2)) | |
398 | { | |
508e53e2 | 399 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
c6487d61 | 400 | zlog_debug (" Ignore self-originated external route"); |
718e3744 | 401 | return; |
402 | } | |
403 | ||
508e53e2 | 404 | /* If removing is the best path and if there's another path, |
405 | treat this request as add the secondary path */ | |
406 | if (type == REM && ospf6_route_is_best (request) && | |
407 | request->next && ospf6_route_is_same (request, request->next)) | |
718e3744 | 408 | { |
508e53e2 | 409 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
c6487d61 | 410 | zlog_debug (" Best-path removal resulted Sencondary addition"); |
508e53e2 | 411 | type = ADD; |
412 | request = request->next; | |
718e3744 | 413 | } |
414 | ||
508e53e2 | 415 | /* Only the best path will be sent to zebra. */ |
416 | if (! ospf6_route_is_best (request)) | |
718e3744 | 417 | { |
508e53e2 | 418 | /* this is not preferred best route, ignore */ |
419 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) | |
c6487d61 | 420 | zlog_debug (" Ignore non-best route"); |
508e53e2 | 421 | return; |
718e3744 | 422 | } |
423 | ||
c3c0ac83 | 424 | nhcount = ospf6_route_num_nexthops (request); |
508e53e2 | 425 | if (nhcount == 0) |
718e3744 | 426 | { |
508e53e2 | 427 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) |
c6487d61 | 428 | zlog_debug (" No nexthop, ignore"); |
718e3744 | 429 | return; |
430 | } | |
431 | ||
432 | /* allocate memory for nexthop_list */ | |
433 | nexthops = XCALLOC (MTYPE_OSPF6_OTHER, | |
508e53e2 | 434 | nhcount * sizeof (struct in6_addr *)); |
435 | if (nexthops == NULL) | |
718e3744 | 436 | { |
508e53e2 | 437 | zlog_warn ("Can't send route to zebra: malloc failed"); |
718e3744 | 438 | return; |
439 | } | |
440 | ||
441 | /* allocate memory for ifindex_list */ | |
442 | ifindexes = XCALLOC (MTYPE_OSPF6_OTHER, | |
508e53e2 | 443 | nhcount * sizeof (unsigned int)); |
444 | if (ifindexes == NULL) | |
718e3744 | 445 | { |
508e53e2 | 446 | zlog_warn ("Can't send route to zebra: malloc failed"); |
718e3744 | 447 | XFREE (MTYPE_OSPF6_OTHER, nexthops); |
448 | return; | |
449 | } | |
450 | ||
c3c0ac83 | 451 | ospf6_route_zebra_copy_nexthops (request, ifindexes, nexthops, nhcount); |
718e3744 | 452 | |
7076bb2f | 453 | api.vrf_id = VRF_DEFAULT; |
718e3744 | 454 | api.type = ZEBRA_ROUTE_OSPF6; |
7c8ff89e | 455 | api.instance = 0; |
718e3744 | 456 | api.flags = 0; |
457 | api.message = 0; | |
b4e45f67 | 458 | api.safi = SAFI_UNICAST; |
718e3744 | 459 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
508e53e2 | 460 | api.nexthop_num = nhcount; |
718e3744 | 461 | api.nexthop = nexthops; |
508e53e2 | 462 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
463 | api.ifindex_num = nhcount; | |
718e3744 | 464 | api.ifindex = ifindexes; |
508e53e2 | 465 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
466 | api.metric = (request->path.metric_type == 2 ? | |
c3c0ac83 | 467 | request->path.u.cost_e2 : request->path.cost); |
718e3744 | 468 | |
508e53e2 | 469 | dest = (struct prefix_ipv6 *) &request->prefix; |
470 | if (type == REM) | |
471 | ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api); | |
718e3744 | 472 | else |
508e53e2 | 473 | ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api); |
718e3744 | 474 | |
475 | if (ret < 0) | |
508e53e2 | 476 | zlog_err ("zapi_ipv6_route() %s failed: %s", |
6099b3b5 | 477 | (type == REM ? "delete" : "add"), safe_strerror (errno)); |
718e3744 | 478 | |
718e3744 | 479 | XFREE (MTYPE_OSPF6_OTHER, nexthops); |
480 | XFREE (MTYPE_OSPF6_OTHER, ifindexes); | |
481 | ||
482 | return; | |
483 | } | |
484 | ||
485 | void | |
508e53e2 | 486 | ospf6_zebra_route_update_add (struct ospf6_route *request) |
718e3744 | 487 | { |
7076bb2f FL |
488 | if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], |
489 | VRF_DEFAULT)) | |
718e3744 | 490 | { |
508e53e2 | 491 | ospf6->route_table->hook_add = NULL; |
492 | ospf6->route_table->hook_remove = NULL; | |
493 | return; | |
718e3744 | 494 | } |
508e53e2 | 495 | ospf6_zebra_route_update (ADD, request); |
718e3744 | 496 | } |
497 | ||
508e53e2 | 498 | void |
499 | ospf6_zebra_route_update_remove (struct ospf6_route *request) | |
718e3744 | 500 | { |
7076bb2f FL |
501 | if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], |
502 | VRF_DEFAULT)) | |
718e3744 | 503 | { |
508e53e2 | 504 | ospf6->route_table->hook_add = NULL; |
505 | ospf6->route_table->hook_remove = NULL; | |
506 | return; | |
718e3744 | 507 | } |
508e53e2 | 508 | ospf6_zebra_route_update (REM, request); |
718e3744 | 509 | } |
510 | ||
c3c0ac83 DS |
511 | void |
512 | ospf6_zebra_add_discard (struct ospf6_route *request) | |
513 | { | |
514 | struct zapi_ipv6 api; | |
515 | char buf[INET6_ADDRSTRLEN]; | |
516 | struct prefix_ipv6 *dest; | |
517 | ||
7076bb2f FL |
518 | if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], |
519 | VRF_DEFAULT)) | |
c3c0ac83 DS |
520 | { |
521 | if (!CHECK_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) | |
522 | { | |
1a1f4efa | 523 | api.vrf_id = VRF_DEFAULT; |
c3c0ac83 DS |
524 | api.type = ZEBRA_ROUTE_OSPF6; |
525 | api.flags = ZEBRA_FLAG_BLACKHOLE; | |
7c8ff89e | 526 | api.instance = 0; |
c3c0ac83 DS |
527 | api.message = 0; |
528 | api.safi = SAFI_UNICAST; | |
529 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); | |
530 | api.nexthop_num = 0; | |
531 | api.ifindex_num = 0; | |
532 | ||
533 | dest = (struct prefix_ipv6 *) &request->prefix; | |
534 | ||
535 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api); | |
536 | ||
537 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) | |
538 | zlog_debug ("Zebra: Route add discard %s/%d", | |
539 | inet_ntop (AF_INET6, &dest->prefix, | |
540 | buf, INET6_ADDRSTRLEN), | |
541 | dest->prefixlen); | |
542 | SET_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED); | |
543 | } | |
544 | else | |
545 | { | |
546 | dest = (struct prefix_ipv6 *) &request->prefix; | |
547 | ||
548 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) | |
549 | zlog_debug ("Zebra: Blackhole route present already %s/%d", | |
550 | inet_ntop (AF_INET6, &dest->prefix, | |
551 | buf, INET6_ADDRSTRLEN), | |
552 | dest->prefixlen); | |
553 | } | |
554 | } | |
555 | } | |
556 | ||
557 | void | |
558 | ospf6_zebra_delete_discard (struct ospf6_route *request) | |
559 | { | |
560 | struct zapi_ipv6 api; | |
561 | char buf[INET6_ADDRSTRLEN]; | |
562 | struct prefix_ipv6 *dest; | |
563 | ||
7076bb2f | 564 | if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT)) |
c3c0ac83 DS |
565 | { |
566 | if (CHECK_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) | |
567 | { | |
1a1f4efa | 568 | api.vrf_id = VRF_DEFAULT; |
c3c0ac83 DS |
569 | api.type = ZEBRA_ROUTE_OSPF6; |
570 | api.flags = ZEBRA_FLAG_BLACKHOLE; | |
7c8ff89e | 571 | api.instance = 0; |
c3c0ac83 DS |
572 | api.message = 0; |
573 | api.safi = SAFI_UNICAST; | |
574 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); | |
575 | api.nexthop_num = 0; | |
576 | api.ifindex_num = 0; | |
577 | ||
578 | dest = (struct prefix_ipv6 *) &request->prefix; | |
579 | ||
580 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api); | |
581 | ||
582 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) | |
583 | zlog_debug ("Zebra: Route delete discard %s/%d", | |
584 | inet_ntop (AF_INET6, &dest->prefix, buf, | |
585 | INET6_ADDRSTRLEN), dest->prefixlen); | |
586 | UNSET_FLAG (request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED); | |
587 | } | |
588 | else | |
589 | { | |
590 | dest = (struct prefix_ipv6 *) &request->prefix; | |
591 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) | |
592 | zlog_debug ("Zebra: Blackhole route already deleted %s/%d", | |
593 | inet_ntop (AF_INET6, &dest->prefix, buf, | |
594 | INET6_ADDRSTRLEN), dest->prefixlen); | |
595 | } | |
596 | } | |
597 | } | |
598 | ||
718e3744 | 599 | DEFUN (redistribute_ospf6, |
600 | redistribute_ospf6_cmd, | |
601 | "redistribute ospf6", | |
602 | "Redistribute control\n" | |
603 | "OSPF6 route\n") | |
604 | { | |
508e53e2 | 605 | struct ospf6_route *route; |
606 | ||
7076bb2f | 607 | if (vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT)) |
508e53e2 | 608 | return CMD_SUCCESS; |
718e3744 | 609 | |
7076bb2f | 610 | vrf_bitmap_set (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT); |
718e3744 | 611 | |
508e53e2 | 612 | if (ospf6 == NULL) |
613 | return CMD_SUCCESS; | |
614 | ||
615 | /* send ospf6 route to zebra route table */ | |
616 | for (route = ospf6_route_head (ospf6->route_table); route; | |
617 | route = ospf6_route_next (route)) | |
618 | ospf6_zebra_route_update_add (route); | |
619 | ||
620 | ospf6->route_table->hook_add = ospf6_zebra_route_update_add; | |
621 | ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove; | |
718e3744 | 622 | |
623 | return CMD_SUCCESS; | |
624 | } | |
625 | ||
626 | DEFUN (no_redistribute_ospf6, | |
627 | no_redistribute_ospf6_cmd, | |
628 | "no redistribute ospf6", | |
629 | NO_STR | |
630 | "Redistribute control\n" | |
631 | "OSPF6 route\n") | |
632 | { | |
508e53e2 | 633 | struct ospf6_route *route; |
634 | ||
7076bb2f | 635 | if (! vrf_bitmap_check (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT)) |
508e53e2 | 636 | return CMD_SUCCESS; |
718e3744 | 637 | |
7076bb2f | 638 | vrf_bitmap_unset (zclient->redist[AFI_IP6][ZEBRA_ROUTE_OSPF6], VRF_DEFAULT); |
718e3744 | 639 | |
508e53e2 | 640 | if (ospf6 == NULL) |
718e3744 | 641 | return CMD_SUCCESS; |
642 | ||
508e53e2 | 643 | ospf6->route_table->hook_add = NULL; |
644 | ospf6->route_table->hook_remove = NULL; | |
718e3744 | 645 | |
508e53e2 | 646 | /* withdraw ospf6 route from zebra route table */ |
647 | for (route = ospf6_route_head (ospf6->route_table); route; | |
648 | route = ospf6_route_next (route)) | |
649 | ospf6_zebra_route_update_remove (route); | |
718e3744 | 650 | |
651 | return CMD_SUCCESS; | |
652 | } | |
653 | ||
7076bb2f FL |
654 | static void |
655 | ospf6_zebra_connected (struct zclient *zclient) | |
656 | { | |
0e5223e7 | 657 | zclient_send_reg_requests (zclient, VRF_DEFAULT); |
7076bb2f FL |
658 | } |
659 | ||
718e3744 | 660 | void |
4140ca4d | 661 | ospf6_zebra_init (struct thread_master *master) |
718e3744 | 662 | { |
663 | /* Allocate zebra structure. */ | |
4140ca4d | 664 | zclient = zclient_new(master); |
7c8ff89e | 665 | zclient_init (zclient, ZEBRA_ROUTE_OSPF6, 0); |
7076bb2f | 666 | zclient->zebra_connected = ospf6_zebra_connected; |
18a6dce6 | 667 | zclient->router_id_update = ospf6_router_id_update_zebra; |
718e3744 | 668 | zclient->interface_add = ospf6_zebra_if_add; |
669 | zclient->interface_delete = ospf6_zebra_if_del; | |
670 | zclient->interface_up = ospf6_zebra_if_state_update; | |
671 | zclient->interface_down = ospf6_zebra_if_state_update; | |
672 | zclient->interface_address_add = ospf6_zebra_if_address_update_add; | |
673 | zclient->interface_address_delete = ospf6_zebra_if_address_update_delete; | |
674 | zclient->ipv4_route_add = NULL; | |
675 | zclient->ipv4_route_delete = NULL; | |
5048fe14 | 676 | zclient->redistribute_route_ipv4_add = NULL; |
677 | zclient->redistribute_route_ipv4_del = NULL; | |
718e3744 | 678 | zclient->ipv6_route_add = ospf6_zebra_read_ipv6; |
679 | zclient->ipv6_route_delete = ospf6_zebra_read_ipv6; | |
5048fe14 | 680 | zclient->redistribute_route_ipv6_add = ospf6_zebra_read_ipv6; |
681 | zclient->redistribute_route_ipv6_del = ospf6_zebra_read_ipv6; | |
718e3744 | 682 | |
683 | /* redistribute connected route by default */ | |
684 | /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */ | |
685 | ||
686 | /* Install zebra node. */ | |
508e53e2 | 687 | install_node (&zebra_node, config_write_ospf6_zebra); |
718e3744 | 688 | |
689 | /* Install command element for zebra node. */ | |
690 | install_element (VIEW_NODE, &show_zebra_cmd); | |
691 | install_element (ENABLE_NODE, &show_zebra_cmd); | |
692 | install_element (CONFIG_NODE, &router_zebra_cmd); | |
693 | install_element (CONFIG_NODE, &no_router_zebra_cmd); | |
508e53e2 | 694 | |
718e3744 | 695 | install_default (ZEBRA_NODE); |
696 | install_element (ZEBRA_NODE, &redistribute_ospf6_cmd); | |
697 | install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd); | |
698 | ||
718e3744 | 699 | return; |
700 | } | |
701 | ||
508e53e2 | 702 | /* Debug */ |
6b0655a2 | 703 | |
508e53e2 | 704 | DEFUN (debug_ospf6_zebra_sendrecv, |
705 | debug_ospf6_zebra_sendrecv_cmd, | |
706 | "debug ospf6 zebra (send|recv)", | |
707 | DEBUG_STR | |
708 | OSPF6_STR | |
709 | "Debug connection between zebra\n" | |
710 | "Debug Sending zebra\n" | |
711 | "Debug Receiving zebra\n" | |
712 | ) | |
713 | { | |
714 | unsigned char level = 0; | |
715 | ||
716 | if (argc) | |
717 | { | |
718 | if (! strncmp (argv[0], "s", 1)) | |
719 | level = OSPF6_DEBUG_ZEBRA_SEND; | |
720 | else if (! strncmp (argv[0], "r", 1)) | |
721 | level = OSPF6_DEBUG_ZEBRA_RECV; | |
722 | } | |
723 | else | |
724 | level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; | |
725 | ||
726 | OSPF6_DEBUG_ZEBRA_ON (level); | |
727 | return CMD_SUCCESS; | |
728 | } | |
729 | ||
730 | ALIAS (debug_ospf6_zebra_sendrecv, | |
731 | debug_ospf6_zebra_cmd, | |
732 | "debug ospf6 zebra", | |
733 | DEBUG_STR | |
734 | OSPF6_STR | |
735 | "Debug connection between zebra\n" | |
6ac29a51 | 736 | ) |
508e53e2 | 737 | |
738 | ||
739 | DEFUN (no_debug_ospf6_zebra_sendrecv, | |
740 | no_debug_ospf6_zebra_sendrecv_cmd, | |
741 | "no debug ospf6 zebra (send|recv)", | |
742 | NO_STR | |
743 | DEBUG_STR | |
744 | OSPF6_STR | |
745 | "Debug connection between zebra\n" | |
746 | "Debug Sending zebra\n" | |
747 | "Debug Receiving zebra\n" | |
748 | ) | |
749 | { | |
750 | unsigned char level = 0; | |
751 | ||
752 | if (argc) | |
753 | { | |
754 | if (! strncmp (argv[0], "s", 1)) | |
755 | level = OSPF6_DEBUG_ZEBRA_SEND; | |
756 | else if (! strncmp (argv[0], "r", 1)) | |
757 | level = OSPF6_DEBUG_ZEBRA_RECV; | |
758 | } | |
759 | else | |
760 | level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; | |
761 | ||
762 | OSPF6_DEBUG_ZEBRA_OFF (level); | |
763 | return CMD_SUCCESS; | |
764 | } | |
765 | ||
766 | ALIAS (no_debug_ospf6_zebra_sendrecv, | |
767 | no_debug_ospf6_zebra_cmd, | |
768 | "no debug ospf6 zebra", | |
769 | NO_STR | |
770 | DEBUG_STR | |
771 | OSPF6_STR | |
772 | "Debug connection between zebra\n" | |
6ac29a51 | 773 | ) |
508e53e2 | 774 | |
775 | int | |
776 | config_write_ospf6_debug_zebra (struct vty *vty) | |
777 | { | |
778 | if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV)) | |
049207c3 | 779 | vty_out (vty, "debug ospf6 zebra%s", VNL); |
508e53e2 | 780 | else |
781 | { | |
782 | if (IS_OSPF6_DEBUG_ZEBRA (SEND)) | |
049207c3 | 783 | vty_out (vty, "debug ospf6 zebra send%s", VNL); |
508e53e2 | 784 | if (IS_OSPF6_DEBUG_ZEBRA (RECV)) |
049207c3 | 785 | vty_out (vty, "debug ospf6 zebra recv%s", VNL); |
508e53e2 | 786 | } |
787 | return 0; | |
788 | } | |
789 | ||
718e3744 | 790 | void |
6ac29a51 | 791 | install_element_ospf6_debug_zebra (void) |
718e3744 | 792 | { |
508e53e2 | 793 | install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd); |
794 | install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd); | |
795 | install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd); | |
796 | install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); | |
797 | install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd); | |
798 | install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd); | |
799 | install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd); | |
800 | install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); | |
718e3744 | 801 | } |
802 | ||
508e53e2 | 803 |