]>
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" |
4ba03be5 | 31 | #include "lib_errors.h" |
718e3744 | 32 | |
508e53e2 | 33 | #include "ospf6_proto.h" |
34 | #include "ospf6_top.h" | |
718e3744 | 35 | #include "ospf6_interface.h" |
508e53e2 | 36 | #include "ospf6_route.h" |
37 | #include "ospf6_lsa.h" | |
049207c3 | 38 | #include "ospf6_lsdb.h" |
718e3744 | 39 | #include "ospf6_asbr.h" |
508e53e2 | 40 | #include "ospf6_zebra.h" |
049207c3 | 41 | #include "ospf6d.h" |
beadc736 | 42 | #include "ospf6_area.h" |
9ebb75c5 | 43 | #include "lib/json.h" |
718e3744 | 44 | |
bf8d3d6a | 45 | DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_DISTANCE, "OSPF6 distance"); |
baff583e | 46 | |
508e53e2 | 47 | unsigned char conf_debug_ospf6_zebra = 0; |
718e3744 | 48 | |
49 | /* information about zebra. */ | |
50 | struct zclient *zclient = NULL; | |
51 | ||
beadc736 | 52 | void ospf6_zebra_vrf_register(struct ospf6 *ospf6) |
53 | { | |
54 | if (!zclient || zclient->sock < 0 || !ospf6) | |
55 | return; | |
56 | ||
57 | if (ospf6->vrf_id != VRF_UNKNOWN) { | |
58 | if (IS_OSPF6_DEBUG_ZEBRA(RECV)) { | |
59 | zlog_debug("%s: Register VRF %s id %u", __func__, | |
60 | ospf6_vrf_id_to_name(ospf6->vrf_id), | |
61 | ospf6->vrf_id); | |
62 | } | |
63 | zclient_send_reg_requests(zclient, ospf6->vrf_id); | |
64 | } | |
65 | } | |
66 | ||
67 | void ospf6_zebra_vrf_deregister(struct ospf6 *ospf6) | |
68 | { | |
69 | if (!zclient || zclient->sock < 0 || !ospf6) | |
70 | return; | |
71 | ||
72 | if (ospf6->vrf_id != VRF_DEFAULT && ospf6->vrf_id != VRF_UNKNOWN) { | |
73 | if (IS_OSPF6_DEBUG_ZEBRA(RECV)) { | |
74 | zlog_debug("%s: De-Register VRF %s id %u to Zebra.", | |
75 | __func__, | |
76 | ospf6_vrf_id_to_name(ospf6->vrf_id), | |
77 | ospf6->vrf_id); | |
78 | } | |
79 | /* Deregister for router-id, interfaces, | |
80 | * redistributed routes. */ | |
81 | zclient_send_dereg_requests(zclient, ospf6->vrf_id); | |
82 | } | |
83 | } | |
84 | ||
18a6dce6 | 85 | /* Router-id update message from zebra. */ |
121f9dee | 86 | static int ospf6_router_id_update_zebra(ZAPI_CALLBACK_ARGS) |
18a6dce6 | 87 | { |
d62a17ae | 88 | struct prefix router_id; |
beadc736 | 89 | struct ospf6 *o; |
18a6dce6 | 90 | |
d62a17ae | 91 | zebra_router_id_update_read(zclient->ibuf, &router_id); |
18a6dce6 | 92 | |
78c6ba61 | 93 | om6->zebra_router_id = router_id.u.prefix4.s_addr; |
beadc736 | 94 | o = ospf6_lookup_by_vrf_id(vrf_id); |
d62a17ae | 95 | if (o == NULL) |
96 | return 0; | |
c1ba9e8a | 97 | |
d6927cf3 | 98 | o->router_id_zebra = router_id.u.prefix4; |
d47b448d DS |
99 | if (IS_OSPF6_DEBUG_ZEBRA(RECV)) |
100 | zlog_debug("%s: zebra router-id %pI4 update", __func__, | |
101 | &router_id.u.prefix4); | |
d6927cf3 | 102 | |
beadc736 | 103 | ospf6_router_id_update(o); |
18a6dce6 | 104 | |
d62a17ae | 105 | return 0; |
18a6dce6 | 106 | } |
107 | ||
718e3744 | 108 | /* redistribute function */ |
c5d28568 | 109 | void ospf6_zebra_redistribute(int type, vrf_id_t vrf_id) |
718e3744 | 110 | { |
c5d28568 | 111 | if (vrf_bitmap_check(zclient->redist[AFI_IP6][type], vrf_id)) |
d62a17ae | 112 | return; |
c5d28568 | 113 | vrf_bitmap_set(zclient->redist[AFI_IP6][type], vrf_id); |
7076bb2f | 114 | |
d62a17ae | 115 | if (zclient->sock > 0) |
116 | zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, | |
c5d28568 | 117 | AFI_IP6, type, 0, vrf_id); |
718e3744 | 118 | } |
119 | ||
c5d28568 | 120 | void ospf6_zebra_no_redistribute(int type, vrf_id_t vrf_id) |
718e3744 | 121 | { |
c5d28568 | 122 | if (!vrf_bitmap_check(zclient->redist[AFI_IP6][type], vrf_id)) |
d62a17ae | 123 | return; |
c5d28568 | 124 | vrf_bitmap_unset(zclient->redist[AFI_IP6][type], vrf_id); |
d62a17ae | 125 | if (zclient->sock > 0) |
126 | zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE, zclient, | |
c5d28568 | 127 | AFI_IP6, type, 0, vrf_id); |
718e3744 | 128 | } |
129 | ||
121f9dee | 130 | static int ospf6_zebra_if_address_update_add(ZAPI_CALLBACK_ARGS) |
718e3744 | 131 | { |
d62a17ae | 132 | struct connected *c; |
f85b7619 | 133 | struct ospf6_interface *oi; |
134 | int ipv6_count = 0; | |
d62a17ae | 135 | |
136 | c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_ADD, | |
137 | zclient->ibuf, vrf_id); | |
138 | if (c == NULL) | |
139 | return 0; | |
140 | ||
f85b7619 | 141 | oi = (struct ospf6_interface *)c->ifp->info; |
142 | if (oi == NULL) | |
143 | oi = ospf6_interface_create(c->ifp); | |
144 | assert(oi); | |
145 | ||
d62a17ae | 146 | if (IS_OSPF6_DEBUG_ZEBRA(RECV)) |
299ce4b3 | 147 | zlog_debug("Zebra Interface address add: %s %5s %pFX", |
d62a17ae | 148 | c->ifp->name, prefix_family_str(c->address), |
299ce4b3 | 149 | c->address); |
d62a17ae | 150 | |
f85b7619 | 151 | ipv6_count = connected_count_by_family(c->ifp, AF_INET6); |
152 | if (oi->ifmtu == OSPF6_DEFAULT_MTU && ipv6_count > OSPF6_MAX_IF_ADDRS) { | |
153 | zlog_warn( | |
154 | "Zebra Interface : %s has too many interface addresses %d only support %d, increase MTU", | |
155 | c->ifp->name, ipv6_count, OSPF6_MAX_IF_ADDRS); | |
156 | return 0; | |
157 | } else if (oi->ifmtu >= OSPF6_JUMBO_MTU | |
158 | && ipv6_count > OSPF6_MAX_IF_ADDRS_JUMBO) { | |
159 | zlog_warn( | |
160 | "Zebra Interface : %s has too many interface addresses %d only support %d", | |
161 | c->ifp->name, ipv6_count, OSPF6_MAX_IF_ADDRS_JUMBO); | |
162 | return 0; | |
163 | } | |
164 | ||
d62a17ae | 165 | if (c->address->family == AF_INET6) { |
166 | ospf6_interface_state_update(c->ifp); | |
167 | ospf6_interface_connected_route_update(c->ifp); | |
168 | } | |
169 | return 0; | |
718e3744 | 170 | } |
171 | ||
121f9dee | 172 | static int ospf6_zebra_if_address_update_delete(ZAPI_CALLBACK_ARGS) |
718e3744 | 173 | { |
d62a17ae | 174 | struct connected *c; |
d62a17ae | 175 | |
176 | c = zebra_interface_address_read(ZEBRA_INTERFACE_ADDRESS_DELETE, | |
177 | zclient->ibuf, vrf_id); | |
178 | if (c == NULL) | |
179 | return 0; | |
180 | ||
181 | if (IS_OSPF6_DEBUG_ZEBRA(RECV)) | |
299ce4b3 | 182 | zlog_debug("Zebra Interface address delete: %s %5s %pFX", |
d62a17ae | 183 | c->ifp->name, prefix_family_str(c->address), |
299ce4b3 | 184 | c->address); |
d62a17ae | 185 | |
186 | if (c->address->family == AF_INET6) { | |
187 | ospf6_interface_connected_route_update(c->ifp); | |
188 | ospf6_interface_state_update(c->ifp); | |
189 | } | |
718e3744 | 190 | |
721c0857 | 191 | connected_free(&c); |
718e3744 | 192 | |
d62a17ae | 193 | return 0; |
194 | } | |
718e3744 | 195 | |
b19502d3 YR |
196 | static int is_prefix_default(struct prefix_ipv6 *p) |
197 | { | |
198 | struct prefix_ipv6 q = {}; | |
199 | ||
200 | q.family = AF_INET6; | |
201 | q.prefixlen = 0; | |
202 | ||
203 | return prefix_same((struct prefix *)p, (struct prefix *)&q); | |
204 | } | |
205 | ||
121f9dee | 206 | static int ospf6_zebra_read_route(ZAPI_CALLBACK_ARGS) |
d62a17ae | 207 | { |
74489921 | 208 | struct zapi_route api; |
d62a17ae | 209 | unsigned long ifindex; |
d62a17ae | 210 | struct in6_addr *nexthop; |
beadc736 | 211 | struct ospf6 *ospf6; |
b19502d3 | 212 | struct prefix_ipv6 p; |
beadc736 | 213 | |
214 | ospf6 = ospf6_lookup_by_vrf_id(vrf_id); | |
d62a17ae | 215 | |
216 | if (ospf6 == NULL) | |
217 | return 0; | |
218 | ||
74489921 RW |
219 | if (zapi_route_decode(zclient->ibuf, &api) < 0) |
220 | return -1; | |
d62a17ae | 221 | |
74489921 RW |
222 | /* we completely ignore srcdest routes for now. */ |
223 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) | |
d62a17ae | 224 | return 0; |
225 | ||
9fb2b879 DS |
226 | if (IN6_IS_ADDR_LINKLOCAL(&api.prefix.u.prefix6)) |
227 | return 0; | |
228 | ||
74489921 RW |
229 | ifindex = api.nexthops[0].ifindex; |
230 | nexthop = &api.nexthops[0].gate.ipv6; | |
d62a17ae | 231 | |
2dbe669b | 232 | if (IS_OSPF6_DEBUG_ZEBRA(RECV)) |
d62a17ae | 233 | zlog_debug( |
2dbe669b | 234 | "Zebra Receive route %s: %s %pFX nexthop %pI6 ifindex %ld tag %" ROUTE_TAG_PRI, |
121f9dee QY |
235 | (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD ? "add" |
236 | : "delete"), | |
2dbe669b | 237 | zebra_route_string(api.type), &api.prefix, nexthop, |
d62a17ae | 238 | ifindex, api.tag); |
718e3744 | 239 | |
b19502d3 YR |
240 | memcpy(&p, &api.prefix, sizeof(p)); |
241 | if (is_prefix_default(&p)) | |
242 | api.type = DEFAULT_ROUTE; | |
243 | ||
121f9dee | 244 | if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD) |
74489921 | 245 | ospf6_asbr_redistribute_add(api.type, ifindex, &api.prefix, |
beadc736 | 246 | api.nexthop_num, nexthop, api.tag, |
247 | ospf6); | |
d62a17ae | 248 | else |
beadc736 | 249 | ospf6_asbr_redistribute_remove(api.type, ifindex, &api.prefix, |
250 | ospf6); | |
718e3744 | 251 | |
d62a17ae | 252 | return 0; |
718e3744 | 253 | } |
254 | ||
9ebb75c5 | 255 | DEFUN(show_zebra, |
256 | show_ospf6_zebra_cmd, | |
257 | "show ipv6 ospf6 zebra [json]", | |
258 | SHOW_STR | |
259 | IPV6_STR | |
260 | OSPF6_STR | |
261 | ZEBRA_STR | |
262 | JSON_STR) | |
718e3744 | 263 | { |
d62a17ae | 264 | int i; |
9ebb75c5 | 265 | bool uj = use_json(argc, argv); |
266 | json_object *json; | |
267 | json_object *json_zebra; | |
268 | json_object *json_array; | |
269 | ||
d62a17ae | 270 | if (zclient == NULL) { |
271 | vty_out(vty, "Not connected to zebra\n"); | |
272 | return CMD_SUCCESS; | |
273 | } | |
274 | ||
9ebb75c5 | 275 | if (uj) { |
276 | json = json_object_new_object(); | |
277 | json_zebra = json_object_new_object(); | |
278 | json_array = json_object_new_array(); | |
279 | ||
280 | json_object_int_add(json_zebra, "fail", zclient->fail); | |
281 | json_object_int_add( | |
282 | json_zebra, "redistributeDefault", | |
283 | vrf_bitmap_check(zclient->default_information[AFI_IP6], | |
284 | VRF_DEFAULT)); | |
285 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { | |
286 | if (vrf_bitmap_check(zclient->redist[AFI_IP6][i], | |
287 | VRF_DEFAULT)) | |
288 | json_object_array_add( | |
289 | json_array, | |
290 | json_object_new_string( | |
291 | zebra_route_string(i))); | |
292 | } | |
293 | json_object_object_add(json_zebra, "redistribute", json_array); | |
294 | json_object_object_add(json, "zebraInformation", json_zebra); | |
295 | ||
296 | vty_out(vty, "%s\n", | |
297 | json_object_to_json_string_ext( | |
298 | json, JSON_C_TO_STRING_PRETTY)); | |
299 | } else { | |
300 | vty_out(vty, "Zebra Infomation\n"); | |
301 | vty_out(vty, " fail: %d\n", zclient->fail); | |
302 | vty_out(vty, " redistribute default: %d\n", | |
303 | vrf_bitmap_check(zclient->default_information[AFI_IP6], | |
304 | VRF_DEFAULT)); | |
305 | vty_out(vty, " redistribute:"); | |
306 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { | |
307 | if (vrf_bitmap_check(zclient->redist[AFI_IP6][i], | |
308 | VRF_DEFAULT)) | |
309 | vty_out(vty, " %s", zebra_route_string(i)); | |
310 | } | |
311 | vty_out(vty, "\n"); | |
d62a17ae | 312 | } |
d62a17ae | 313 | return CMD_SUCCESS; |
718e3744 | 314 | } |
315 | ||
718e3744 | 316 | #define ADD 0 |
508e53e2 | 317 | #define REM 1 |
beadc736 | 318 | static void ospf6_zebra_route_update(int type, struct ospf6_route *request, |
319 | struct ospf6 *ospf6) | |
718e3744 | 320 | { |
5afa1c6b | 321 | struct zapi_route api; |
d62a17ae | 322 | int nhcount; |
d62a17ae | 323 | int ret = 0; |
5afa1c6b | 324 | struct prefix *dest; |
d62a17ae | 325 | |
2dbe669b | 326 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) |
f85b7619 | 327 | zlog_debug("Zebra Send %s route: %pFX", |
2dbe669b | 328 | (type == REM ? "remove" : "add"), &request->prefix); |
d62a17ae | 329 | |
330 | if (zclient->sock < 0) { | |
331 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
332 | zlog_debug(" Not connected to Zebra"); | |
333 | return; | |
334 | } | |
335 | ||
336 | if (request->path.origin.adv_router == ospf6->router_id | |
337 | && (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 | |
338 | || request->path.type == OSPF6_PATH_TYPE_EXTERNAL2)) { | |
339 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
340 | zlog_debug(" Ignore self-originated external route"); | |
341 | return; | |
342 | } | |
343 | ||
344 | /* If removing is the best path and if there's another path, | |
345 | treat this request as add the secondary path */ | |
346 | if (type == REM && ospf6_route_is_best(request) && request->next | |
347 | && ospf6_route_is_same(request, request->next)) { | |
348 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
349 | zlog_debug( | |
84b7a388 | 350 | " Best-path removal resulted Secondary addition"); |
d62a17ae | 351 | type = ADD; |
352 | request = request->next; | |
353 | } | |
354 | ||
355 | /* Only the best path will be sent to zebra. */ | |
356 | if (!ospf6_route_is_best(request)) { | |
357 | /* this is not preferred best route, ignore */ | |
358 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
359 | zlog_debug(" Ignore non-best route"); | |
360 | return; | |
361 | } | |
362 | ||
363 | nhcount = ospf6_route_num_nexthops(request); | |
364 | if (nhcount == 0) { | |
365 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
366 | zlog_debug(" No nexthop, ignore"); | |
367 | return; | |
368 | } | |
369 | ||
5afa1c6b | 370 | dest = &request->prefix; |
d62a17ae | 371 | |
5afa1c6b | 372 | memset(&api, 0, sizeof(api)); |
c5d28568 | 373 | api.vrf_id = ospf6->vrf_id; |
d62a17ae | 374 | api.type = ZEBRA_ROUTE_OSPF6; |
d62a17ae | 375 | api.safi = SAFI_UNICAST; |
5afa1c6b | 376 | api.prefix = *dest; |
d62a17ae | 377 | SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); |
1958143e MR |
378 | |
379 | if (nhcount > ospf6->max_multipath) { | |
380 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
381 | zlog_debug( | |
382 | " Nexthop count is greater than configured maximum-path, hence ignore the extra nexthops"); | |
383 | } | |
384 | api.nexthop_num = MIN(nhcount, ospf6->max_multipath); | |
385 | ||
1fa58587 IR |
386 | ospf6_route_zebra_copy_nexthops(request, api.nexthops, api.nexthop_num, |
387 | api.vrf_id); | |
d62a17ae | 388 | SET_FLAG(api.message, ZAPI_MESSAGE_METRIC); |
389 | api.metric = (request->path.metric_type == 2 ? request->path.u.cost_e2 | |
390 | : request->path.cost); | |
391 | if (request->path.tag) { | |
392 | SET_FLAG(api.message, ZAPI_MESSAGE_TAG); | |
393 | api.tag = request->path.tag; | |
394 | } | |
395 | ||
d62a17ae | 396 | SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE); |
beadc736 | 397 | api.distance = ospf6_distance_apply((struct prefix_ipv6 *)dest, request, |
398 | ospf6); | |
d62a17ae | 399 | |
400 | if (type == REM) | |
5afa1c6b | 401 | ret = zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api); |
d62a17ae | 402 | else |
5afa1c6b | 403 | ret = zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); |
d62a17ae | 404 | |
8a3f8f2e | 405 | if (ret == ZCLIENT_SEND_FAILURE) |
450971aa | 406 | flog_err(EC_LIB_ZAPI_SOCKET, |
1c50c1c0 QY |
407 | "zclient_route_send() %s failed: %s", |
408 | (type == REM ? "delete" : "add"), | |
409 | safe_strerror(errno)); | |
d62a17ae | 410 | |
d62a17ae | 411 | return; |
718e3744 | 412 | } |
413 | ||
beadc736 | 414 | void ospf6_zebra_route_update_add(struct ospf6_route *request, |
415 | struct ospf6 *ospf6) | |
718e3744 | 416 | { |
beadc736 | 417 | ospf6_zebra_route_update(ADD, request, ospf6); |
718e3744 | 418 | } |
419 | ||
beadc736 | 420 | void ospf6_zebra_route_update_remove(struct ospf6_route *request, |
421 | struct ospf6 *ospf6) | |
718e3744 | 422 | { |
beadc736 | 423 | ospf6_zebra_route_update(REM, request, ospf6); |
718e3744 | 424 | } |
425 | ||
beadc736 | 426 | void ospf6_zebra_add_discard(struct ospf6_route *request, struct ospf6 *ospf6) |
c3c0ac83 | 427 | { |
5afa1c6b | 428 | struct zapi_route api; |
5afa1c6b | 429 | struct prefix *dest = &request->prefix; |
d62a17ae | 430 | |
d00061ea | 431 | if (!CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) { |
5afa1c6b | 432 | memset(&api, 0, sizeof(api)); |
c5d28568 | 433 | api.vrf_id = ospf6->vrf_id; |
d00061ea | 434 | api.type = ZEBRA_ROUTE_OSPF6; |
d00061ea | 435 | api.safi = SAFI_UNICAST; |
5afa1c6b | 436 | api.prefix = *dest; |
09a484dd | 437 | zapi_route_set_blackhole(&api, BLACKHOLE_NULL); |
d00061ea | 438 | |
5afa1c6b | 439 | zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); |
d00061ea RW |
440 | |
441 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
299ce4b3 | 442 | zlog_debug("Zebra: Route add discard %pFX", dest); |
d00061ea RW |
443 | |
444 | SET_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED); | |
445 | } else { | |
d00061ea RW |
446 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) |
447 | zlog_debug( | |
299ce4b3 DS |
448 | "Zebra: Blackhole route present already %pFX", |
449 | dest); | |
c3c0ac83 | 450 | } |
c3c0ac83 DS |
451 | } |
452 | ||
beadc736 | 453 | void ospf6_zebra_delete_discard(struct ospf6_route *request, |
454 | struct ospf6 *ospf6) | |
c3c0ac83 | 455 | { |
5afa1c6b | 456 | struct zapi_route api; |
5afa1c6b | 457 | struct prefix *dest = &request->prefix; |
d62a17ae | 458 | |
d00061ea | 459 | if (CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) { |
5afa1c6b | 460 | memset(&api, 0, sizeof(api)); |
c5d28568 | 461 | api.vrf_id = ospf6->vrf_id; |
d00061ea | 462 | api.type = ZEBRA_ROUTE_OSPF6; |
d00061ea | 463 | api.safi = SAFI_UNICAST; |
5afa1c6b | 464 | api.prefix = *dest; |
09a484dd | 465 | zapi_route_set_blackhole(&api, BLACKHOLE_NULL); |
d00061ea | 466 | |
5afa1c6b | 467 | zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api); |
d00061ea RW |
468 | |
469 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
299ce4b3 | 470 | zlog_debug("Zebra: Route delete discard %pFX", dest); |
d00061ea RW |
471 | |
472 | UNSET_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED); | |
473 | } else { | |
d00061ea RW |
474 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) |
475 | zlog_debug( | |
299ce4b3 DS |
476 | "Zebra: Blackhole route already deleted %pFX", |
477 | dest); | |
c3c0ac83 | 478 | } |
c3c0ac83 DS |
479 | } |
480 | ||
d62a17ae | 481 | static struct ospf6_distance *ospf6_distance_new(void) |
baff583e | 482 | { |
d62a17ae | 483 | return XCALLOC(MTYPE_OSPF6_DISTANCE, sizeof(struct ospf6_distance)); |
baff583e MZ |
484 | } |
485 | ||
d62a17ae | 486 | static void ospf6_distance_free(struct ospf6_distance *odistance) |
baff583e | 487 | { |
d62a17ae | 488 | XFREE(MTYPE_OSPF6_DISTANCE, odistance); |
baff583e MZ |
489 | } |
490 | ||
d62a17ae | 491 | int ospf6_distance_set(struct vty *vty, struct ospf6 *o, |
492 | const char *distance_str, const char *ip_str, | |
493 | const char *access_list_str) | |
baff583e | 494 | { |
d62a17ae | 495 | int ret; |
496 | struct prefix_ipv6 p; | |
d7c0a89a | 497 | uint8_t distance; |
d62a17ae | 498 | struct route_node *rn; |
499 | struct ospf6_distance *odistance; | |
500 | ||
501 | ret = str2prefix_ipv6(ip_str, &p); | |
502 | if (ret == 0) { | |
503 | vty_out(vty, "Malformed prefix\n"); | |
504 | return CMD_WARNING_CONFIG_FAILED; | |
505 | } | |
506 | ||
507 | distance = atoi(distance_str); | |
508 | ||
509 | /* Get OSPF6 distance node. */ | |
510 | rn = route_node_get(o->distance_table, (struct prefix *)&p); | |
511 | if (rn->info) { | |
512 | odistance = rn->info; | |
513 | route_unlock_node(rn); | |
514 | } else { | |
515 | odistance = ospf6_distance_new(); | |
516 | rn->info = odistance; | |
517 | } | |
518 | ||
519 | /* Set distance value. */ | |
520 | odistance->distance = distance; | |
521 | ||
522 | /* Reset access-list configuration. */ | |
523 | if (odistance->access_list) { | |
524 | free(odistance->access_list); | |
525 | odistance->access_list = NULL; | |
526 | } | |
527 | if (access_list_str) | |
528 | odistance->access_list = strdup(access_list_str); | |
529 | ||
530 | return CMD_SUCCESS; | |
baff583e MZ |
531 | } |
532 | ||
d62a17ae | 533 | int ospf6_distance_unset(struct vty *vty, struct ospf6 *o, |
534 | const char *distance_str, const char *ip_str, | |
535 | const char *access_list_str) | |
baff583e | 536 | { |
d62a17ae | 537 | int ret; |
538 | struct prefix_ipv6 p; | |
539 | struct route_node *rn; | |
540 | struct ospf6_distance *odistance; | |
541 | ||
542 | ret = str2prefix_ipv6(ip_str, &p); | |
543 | if (ret == 0) { | |
544 | vty_out(vty, "Malformed prefix\n"); | |
545 | return CMD_WARNING_CONFIG_FAILED; | |
546 | } | |
547 | ||
548 | rn = route_node_lookup(o->distance_table, (struct prefix *)&p); | |
549 | if (!rn) { | |
550 | vty_out(vty, "Cant't find specified prefix\n"); | |
551 | return CMD_WARNING_CONFIG_FAILED; | |
552 | } | |
553 | ||
554 | odistance = rn->info; | |
555 | ||
556 | if (odistance->access_list) | |
557 | free(odistance->access_list); | |
558 | ospf6_distance_free(odistance); | |
559 | ||
560 | rn->info = NULL; | |
561 | route_unlock_node(rn); | |
562 | route_unlock_node(rn); | |
563 | ||
564 | return CMD_SUCCESS; | |
baff583e MZ |
565 | } |
566 | ||
d62a17ae | 567 | void ospf6_distance_reset(struct ospf6 *o) |
baff583e | 568 | { |
d62a17ae | 569 | struct route_node *rn; |
570 | struct ospf6_distance *odistance; | |
571 | ||
572 | for (rn = route_top(o->distance_table); rn; rn = route_next(rn)) | |
573 | if ((odistance = rn->info) != NULL) { | |
574 | if (odistance->access_list) | |
575 | free(odistance->access_list); | |
576 | ospf6_distance_free(odistance); | |
577 | rn->info = NULL; | |
578 | route_unlock_node(rn); | |
579 | } | |
baff583e MZ |
580 | } |
581 | ||
beadc736 | 582 | uint8_t ospf6_distance_apply(struct prefix_ipv6 *p, struct ospf6_route * or, |
583 | struct ospf6 *ospf6) | |
baff583e | 584 | { |
d62a17ae | 585 | struct ospf6 *o; |
baff583e | 586 | |
d62a17ae | 587 | o = ospf6; |
588 | if (o == NULL) | |
589 | return 0; | |
baff583e | 590 | |
d62a17ae | 591 | if (o->distance_intra) |
592 | if (or->path.type == OSPF6_PATH_TYPE_INTRA) | |
593 | return o->distance_intra; | |
baff583e | 594 | |
d62a17ae | 595 | if (o->distance_inter) |
596 | if (or->path.type == OSPF6_PATH_TYPE_INTER) | |
597 | return o->distance_inter; | |
baff583e | 598 | |
d62a17ae | 599 | if (o->distance_external) |
600 | if (or->path.type == OSPF6_PATH_TYPE_EXTERNAL1 || | |
601 | or->path.type == OSPF6_PATH_TYPE_EXTERNAL2) | |
602 | return o->distance_external; | |
baff583e | 603 | |
d62a17ae | 604 | if (o->distance_all) |
605 | return o->distance_all; | |
baff583e | 606 | |
d62a17ae | 607 | return 0; |
baff583e MZ |
608 | } |
609 | ||
d62a17ae | 610 | static void ospf6_zebra_connected(struct zclient *zclient) |
7076bb2f | 611 | { |
d62a17ae | 612 | /* Send the client registration */ |
0945d5ed | 613 | bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER, VRF_DEFAULT); |
2376c3f2 | 614 | |
d62a17ae | 615 | zclient_send_reg_requests(zclient, VRF_DEFAULT); |
7076bb2f FL |
616 | } |
617 | ||
d62a17ae | 618 | void ospf6_zebra_init(struct thread_master *master) |
718e3744 | 619 | { |
d62a17ae | 620 | /* Allocate zebra structure. */ |
26f63a1e | 621 | zclient = zclient_new(master, &zclient_options_default); |
342213ea | 622 | zclient_init(zclient, ZEBRA_ROUTE_OSPF6, 0, &ospf6d_privs); |
d62a17ae | 623 | zclient->zebra_connected = ospf6_zebra_connected; |
624 | zclient->router_id_update = ospf6_router_id_update_zebra; | |
d62a17ae | 625 | zclient->interface_address_add = ospf6_zebra_if_address_update_add; |
626 | zclient->interface_address_delete = | |
627 | ospf6_zebra_if_address_update_delete; | |
74489921 RW |
628 | zclient->redistribute_route_add = ospf6_zebra_read_route; |
629 | zclient->redistribute_route_del = ospf6_zebra_read_route; | |
d62a17ae | 630 | |
d62a17ae | 631 | /* Install command element for zebra node. */ |
632 | install_element(VIEW_NODE, &show_ospf6_zebra_cmd); | |
718e3744 | 633 | } |
634 | ||
508e53e2 | 635 | /* Debug */ |
6b0655a2 | 636 | |
508e53e2 | 637 | DEFUN (debug_ospf6_zebra_sendrecv, |
638 | debug_ospf6_zebra_sendrecv_cmd, | |
1d68dbfe | 639 | "debug ospf6 zebra [<send|recv>]", |
508e53e2 | 640 | DEBUG_STR |
641 | OSPF6_STR | |
642 | "Debug connection between zebra\n" | |
643 | "Debug Sending zebra\n" | |
644 | "Debug Receiving zebra\n" | |
645 | ) | |
646 | { | |
d62a17ae | 647 | int idx_send_recv = 3; |
648 | unsigned char level = 0; | |
649 | ||
650 | if (argc == 4) { | |
651 | if (strmatch(argv[idx_send_recv]->text, "send")) | |
652 | level = OSPF6_DEBUG_ZEBRA_SEND; | |
653 | else if (strmatch(argv[idx_send_recv]->text, "recv")) | |
654 | level = OSPF6_DEBUG_ZEBRA_RECV; | |
655 | } else | |
656 | level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; | |
657 | ||
658 | OSPF6_DEBUG_ZEBRA_ON(level); | |
659 | return CMD_SUCCESS; | |
508e53e2 | 660 | } |
661 | ||
508e53e2 | 662 | DEFUN (no_debug_ospf6_zebra_sendrecv, |
663 | no_debug_ospf6_zebra_sendrecv_cmd, | |
1d68dbfe | 664 | "no debug ospf6 zebra [<send|recv>]", |
508e53e2 | 665 | NO_STR |
666 | DEBUG_STR | |
667 | OSPF6_STR | |
668 | "Debug connection between zebra\n" | |
669 | "Debug Sending zebra\n" | |
670 | "Debug Receiving zebra\n" | |
671 | ) | |
672 | { | |
d62a17ae | 673 | int idx_send_recv = 4; |
674 | unsigned char level = 0; | |
675 | ||
676 | if (argc == 5) { | |
677 | if (strmatch(argv[idx_send_recv]->text, "send")) | |
678 | level = OSPF6_DEBUG_ZEBRA_SEND; | |
679 | else if (strmatch(argv[idx_send_recv]->text, "recv")) | |
680 | level = OSPF6_DEBUG_ZEBRA_RECV; | |
681 | } else | |
682 | level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; | |
683 | ||
684 | OSPF6_DEBUG_ZEBRA_OFF(level); | |
685 | return CMD_SUCCESS; | |
508e53e2 | 686 | } |
687 | ||
508e53e2 | 688 | |
d62a17ae | 689 | int config_write_ospf6_debug_zebra(struct vty *vty) |
508e53e2 | 690 | { |
d62a17ae | 691 | if (IS_OSPF6_DEBUG_ZEBRA(SEND) && IS_OSPF6_DEBUG_ZEBRA(RECV)) |
692 | vty_out(vty, "debug ospf6 zebra\n"); | |
693 | else { | |
694 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
695 | vty_out(vty, "debug ospf6 zebra send\n"); | |
696 | if (IS_OSPF6_DEBUG_ZEBRA(RECV)) | |
697 | vty_out(vty, "debug ospf6 zebra recv\n"); | |
698 | } | |
699 | return 0; | |
508e53e2 | 700 | } |
701 | ||
d62a17ae | 702 | void install_element_ospf6_debug_zebra(void) |
718e3744 | 703 | { |
d62a17ae | 704 | install_element(ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd); |
705 | install_element(ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); | |
706 | install_element(CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd); | |
707 | install_element(CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); | |
718e3744 | 708 | } |