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