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