]>
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 | |
ff880b78 | 129 | if_set_index(ifp, IFINDEX_INTERNAL); |
d62a17ae | 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 | |
74489921 RW |
210 | static int ospf6_zebra_read_route(int command, struct zclient *zclient, |
211 | zebra_size_t length, vrf_id_t vrf_id) | |
d62a17ae | 212 | { |
74489921 | 213 | struct zapi_route api; |
d62a17ae | 214 | unsigned long ifindex; |
d62a17ae | 215 | struct in6_addr *nexthop; |
216 | ||
217 | if (ospf6 == NULL) | |
218 | return 0; | |
219 | ||
74489921 RW |
220 | if (zapi_route_decode(zclient->ibuf, &api) < 0) |
221 | return -1; | |
d62a17ae | 222 | |
74489921 RW |
223 | /* we completely ignore srcdest routes for now. */ |
224 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) | |
d62a17ae | 225 | return 0; |
226 | ||
74489921 RW |
227 | ifindex = api.nexthops[0].ifindex; |
228 | nexthop = &api.nexthops[0].gate.ipv6; | |
d62a17ae | 229 | |
230 | if (IS_OSPF6_DEBUG_ZEBRA(RECV)) { | |
231 | char prefixstr[PREFIX2STR_BUFFER], nexthopstr[128]; | |
74489921 RW |
232 | prefix2str((struct prefix *)&api.prefix, prefixstr, |
233 | sizeof(prefixstr)); | |
0af35d90 | 234 | inet_ntop(AF_INET6, nexthop, nexthopstr, sizeof(nexthopstr)); |
d62a17ae | 235 | |
236 | zlog_debug( | |
237 | "Zebra Receive route %s: %s %s nexthop %s ifindex %ld tag %" ROUTE_TAG_PRI, | |
74489921 RW |
238 | (command == ZEBRA_REDISTRIBUTE_ROUTE_ADD ? "add" |
239 | : "delete"), | |
d62a17ae | 240 | zebra_route_string(api.type), prefixstr, nexthopstr, |
241 | ifindex, api.tag); | |
242 | } | |
718e3744 | 243 | |
74489921 RW |
244 | if (command == ZEBRA_REDISTRIBUTE_ROUTE_ADD) |
245 | ospf6_asbr_redistribute_add(api.type, ifindex, &api.prefix, | |
d62a17ae | 246 | api.nexthop_num, nexthop, api.tag); |
247 | else | |
74489921 | 248 | ospf6_asbr_redistribute_remove(api.type, ifindex, &api.prefix); |
718e3744 | 249 | |
d62a17ae | 250 | return 0; |
718e3744 | 251 | } |
252 | ||
718e3744 | 253 | DEFUN (show_zebra, |
eefe02da DS |
254 | show_ospf6_zebra_cmd, |
255 | "show ipv6 ospf6 zebra", | |
718e3744 | 256 | SHOW_STR |
eefe02da DS |
257 | IPV6_STR |
258 | OSPF6_STR | |
41e7fb80 | 259 | ZEBRA_STR) |
718e3744 | 260 | { |
d62a17ae | 261 | int i; |
262 | if (zclient == NULL) { | |
263 | vty_out(vty, "Not connected to zebra\n"); | |
264 | return CMD_SUCCESS; | |
265 | } | |
266 | ||
267 | vty_out(vty, "Zebra Infomation\n"); | |
34b054ba | 268 | vty_out(vty, " fail: %d\n", zclient->fail); |
d62a17ae | 269 | vty_out(vty, " redistribute default: %d\n", |
270 | vrf_bitmap_check(zclient->default_information, VRF_DEFAULT)); | |
271 | vty_out(vty, " redistribute:"); | |
272 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { | |
273 | if (vrf_bitmap_check(zclient->redist[AFI_IP6][i], VRF_DEFAULT)) | |
274 | vty_out(vty, " %s", zebra_route_string(i)); | |
275 | } | |
276 | vty_out(vty, "\n"); | |
277 | return CMD_SUCCESS; | |
718e3744 | 278 | } |
279 | ||
718e3744 | 280 | #define ADD 0 |
508e53e2 | 281 | #define REM 1 |
d62a17ae | 282 | static void ospf6_zebra_route_update(int type, struct ospf6_route *request) |
718e3744 | 283 | { |
5afa1c6b | 284 | struct zapi_route api; |
d62a17ae | 285 | char buf[PREFIX2STR_BUFFER]; |
286 | int nhcount; | |
d62a17ae | 287 | int ret = 0; |
5afa1c6b | 288 | struct prefix *dest; |
d62a17ae | 289 | |
290 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) { | |
291 | prefix2str(&request->prefix, buf, sizeof(buf)); | |
292 | zlog_debug("Send %s route: %s", | |
293 | (type == REM ? "remove" : "add"), buf); | |
294 | } | |
295 | ||
296 | if (zclient->sock < 0) { | |
297 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
298 | zlog_debug(" Not connected to Zebra"); | |
299 | return; | |
300 | } | |
301 | ||
302 | if (request->path.origin.adv_router == ospf6->router_id | |
303 | && (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 | |
304 | || request->path.type == OSPF6_PATH_TYPE_EXTERNAL2)) { | |
305 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
306 | zlog_debug(" Ignore self-originated external route"); | |
307 | return; | |
308 | } | |
309 | ||
310 | /* If removing is the best path and if there's another path, | |
311 | treat this request as add the secondary path */ | |
312 | if (type == REM && ospf6_route_is_best(request) && request->next | |
313 | && ospf6_route_is_same(request, request->next)) { | |
314 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
315 | zlog_debug( | |
316 | " Best-path removal resulted Sencondary addition"); | |
317 | type = ADD; | |
318 | request = request->next; | |
319 | } | |
320 | ||
321 | /* Only the best path will be sent to zebra. */ | |
322 | if (!ospf6_route_is_best(request)) { | |
323 | /* this is not preferred best route, ignore */ | |
324 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
325 | zlog_debug(" Ignore non-best route"); | |
326 | return; | |
327 | } | |
328 | ||
329 | nhcount = ospf6_route_num_nexthops(request); | |
330 | if (nhcount == 0) { | |
331 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
332 | zlog_debug(" No nexthop, ignore"); | |
333 | return; | |
334 | } | |
335 | ||
5afa1c6b | 336 | dest = &request->prefix; |
d62a17ae | 337 | |
5afa1c6b | 338 | memset(&api, 0, sizeof(api)); |
d62a17ae | 339 | api.vrf_id = VRF_DEFAULT; |
340 | api.type = ZEBRA_ROUTE_OSPF6; | |
d62a17ae | 341 | api.safi = SAFI_UNICAST; |
5afa1c6b | 342 | api.prefix = *dest; |
d62a17ae | 343 | SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); |
a74e593b RW |
344 | api.nexthop_num = MIN(nhcount, MULTIPATH_NUM); |
345 | ospf6_route_zebra_copy_nexthops(request, api.nexthops, api.nexthop_num); | |
d62a17ae | 346 | SET_FLAG(api.message, ZAPI_MESSAGE_METRIC); |
347 | api.metric = (request->path.metric_type == 2 ? request->path.u.cost_e2 | |
348 | : request->path.cost); | |
349 | if (request->path.tag) { | |
350 | SET_FLAG(api.message, ZAPI_MESSAGE_TAG); | |
351 | api.tag = request->path.tag; | |
352 | } | |
353 | ||
d62a17ae | 354 | SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE); |
5afa1c6b RW |
355 | api.distance = |
356 | ospf6_distance_apply((struct prefix_ipv6 *)dest, request); | |
d62a17ae | 357 | |
358 | if (type == REM) | |
5afa1c6b | 359 | ret = zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api); |
d62a17ae | 360 | else |
5afa1c6b | 361 | ret = zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); |
d62a17ae | 362 | |
363 | if (ret < 0) | |
5afa1c6b | 364 | zlog_err("zclient_route_send() %s failed: %s", |
d62a17ae | 365 | (type == REM ? "delete" : "add"), |
366 | safe_strerror(errno)); | |
367 | ||
d62a17ae | 368 | return; |
718e3744 | 369 | } |
370 | ||
d62a17ae | 371 | void ospf6_zebra_route_update_add(struct ospf6_route *request) |
718e3744 | 372 | { |
d62a17ae | 373 | ospf6_zebra_route_update(ADD, request); |
718e3744 | 374 | } |
375 | ||
d62a17ae | 376 | void ospf6_zebra_route_update_remove(struct ospf6_route *request) |
718e3744 | 377 | { |
d62a17ae | 378 | ospf6_zebra_route_update(REM, request); |
718e3744 | 379 | } |
380 | ||
d62a17ae | 381 | void ospf6_zebra_add_discard(struct ospf6_route *request) |
c3c0ac83 | 382 | { |
5afa1c6b | 383 | struct zapi_route api; |
d62a17ae | 384 | char buf[INET6_ADDRSTRLEN]; |
5afa1c6b | 385 | struct prefix *dest = &request->prefix; |
d62a17ae | 386 | |
d00061ea | 387 | if (!CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) { |
5afa1c6b | 388 | memset(&api, 0, sizeof(api)); |
d00061ea RW |
389 | api.vrf_id = VRF_DEFAULT; |
390 | api.type = ZEBRA_ROUTE_OSPF6; | |
d00061ea | 391 | api.safi = SAFI_UNICAST; |
5afa1c6b | 392 | api.prefix = *dest; |
09a484dd | 393 | zapi_route_set_blackhole(&api, BLACKHOLE_NULL); |
d00061ea | 394 | |
5afa1c6b | 395 | zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); |
d00061ea RW |
396 | |
397 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
398 | zlog_debug("Zebra: Route add discard %s/%d", | |
5afa1c6b | 399 | inet_ntop(AF_INET6, &dest->u.prefix6, buf, |
d00061ea RW |
400 | INET6_ADDRSTRLEN), |
401 | dest->prefixlen); | |
402 | ||
403 | SET_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED); | |
404 | } else { | |
d00061ea RW |
405 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) |
406 | zlog_debug( | |
407 | "Zebra: Blackhole route present already %s/%d", | |
5afa1c6b | 408 | inet_ntop(AF_INET6, &dest->u.prefix6, buf, |
d00061ea RW |
409 | INET6_ADDRSTRLEN), |
410 | dest->prefixlen); | |
c3c0ac83 | 411 | } |
c3c0ac83 DS |
412 | } |
413 | ||
d62a17ae | 414 | void ospf6_zebra_delete_discard(struct ospf6_route *request) |
c3c0ac83 | 415 | { |
5afa1c6b | 416 | struct zapi_route api; |
d62a17ae | 417 | char buf[INET6_ADDRSTRLEN]; |
5afa1c6b | 418 | struct prefix *dest = &request->prefix; |
d62a17ae | 419 | |
d00061ea | 420 | if (CHECK_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED)) { |
5afa1c6b | 421 | memset(&api, 0, sizeof(api)); |
d00061ea RW |
422 | api.vrf_id = VRF_DEFAULT; |
423 | api.type = ZEBRA_ROUTE_OSPF6; | |
d00061ea | 424 | api.safi = SAFI_UNICAST; |
5afa1c6b | 425 | api.prefix = *dest; |
09a484dd | 426 | zapi_route_set_blackhole(&api, BLACKHOLE_NULL); |
d00061ea | 427 | |
5afa1c6b | 428 | zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api); |
d00061ea RW |
429 | |
430 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
431 | zlog_debug("Zebra: Route delete discard %s/%d", | |
5afa1c6b | 432 | inet_ntop(AF_INET6, &dest->u.prefix6, buf, |
d00061ea RW |
433 | INET6_ADDRSTRLEN), |
434 | dest->prefixlen); | |
435 | ||
436 | UNSET_FLAG(request->flag, OSPF6_ROUTE_BLACKHOLE_ADDED); | |
437 | } else { | |
d00061ea RW |
438 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) |
439 | zlog_debug( | |
440 | "Zebra: Blackhole route already deleted %s/%d", | |
5afa1c6b | 441 | inet_ntop(AF_INET6, &dest->u.prefix6, buf, |
d00061ea RW |
442 | INET6_ADDRSTRLEN), |
443 | dest->prefixlen); | |
c3c0ac83 | 444 | } |
c3c0ac83 DS |
445 | } |
446 | ||
d62a17ae | 447 | static struct ospf6_distance *ospf6_distance_new(void) |
baff583e | 448 | { |
d62a17ae | 449 | return XCALLOC(MTYPE_OSPF6_DISTANCE, sizeof(struct ospf6_distance)); |
baff583e MZ |
450 | } |
451 | ||
d62a17ae | 452 | static void ospf6_distance_free(struct ospf6_distance *odistance) |
baff583e | 453 | { |
d62a17ae | 454 | XFREE(MTYPE_OSPF6_DISTANCE, odistance); |
baff583e MZ |
455 | } |
456 | ||
d62a17ae | 457 | int ospf6_distance_set(struct vty *vty, struct ospf6 *o, |
458 | const char *distance_str, const char *ip_str, | |
459 | const char *access_list_str) | |
baff583e | 460 | { |
d62a17ae | 461 | int ret; |
462 | struct prefix_ipv6 p; | |
463 | u_char distance; | |
464 | struct route_node *rn; | |
465 | struct ospf6_distance *odistance; | |
466 | ||
467 | ret = str2prefix_ipv6(ip_str, &p); | |
468 | if (ret == 0) { | |
469 | vty_out(vty, "Malformed prefix\n"); | |
470 | return CMD_WARNING_CONFIG_FAILED; | |
471 | } | |
472 | ||
473 | distance = atoi(distance_str); | |
474 | ||
475 | /* Get OSPF6 distance node. */ | |
476 | rn = route_node_get(o->distance_table, (struct prefix *)&p); | |
477 | if (rn->info) { | |
478 | odistance = rn->info; | |
479 | route_unlock_node(rn); | |
480 | } else { | |
481 | odistance = ospf6_distance_new(); | |
482 | rn->info = odistance; | |
483 | } | |
484 | ||
485 | /* Set distance value. */ | |
486 | odistance->distance = distance; | |
487 | ||
488 | /* Reset access-list configuration. */ | |
489 | if (odistance->access_list) { | |
490 | free(odistance->access_list); | |
491 | odistance->access_list = NULL; | |
492 | } | |
493 | if (access_list_str) | |
494 | odistance->access_list = strdup(access_list_str); | |
495 | ||
496 | return CMD_SUCCESS; | |
baff583e MZ |
497 | } |
498 | ||
d62a17ae | 499 | int ospf6_distance_unset(struct vty *vty, struct ospf6 *o, |
500 | const char *distance_str, const char *ip_str, | |
501 | const char *access_list_str) | |
baff583e | 502 | { |
d62a17ae | 503 | int ret; |
504 | struct prefix_ipv6 p; | |
505 | struct route_node *rn; | |
506 | struct ospf6_distance *odistance; | |
507 | ||
508 | ret = str2prefix_ipv6(ip_str, &p); | |
509 | if (ret == 0) { | |
510 | vty_out(vty, "Malformed prefix\n"); | |
511 | return CMD_WARNING_CONFIG_FAILED; | |
512 | } | |
513 | ||
514 | rn = route_node_lookup(o->distance_table, (struct prefix *)&p); | |
515 | if (!rn) { | |
516 | vty_out(vty, "Cant't find specified prefix\n"); | |
517 | return CMD_WARNING_CONFIG_FAILED; | |
518 | } | |
519 | ||
520 | odistance = rn->info; | |
521 | ||
522 | if (odistance->access_list) | |
523 | free(odistance->access_list); | |
524 | ospf6_distance_free(odistance); | |
525 | ||
526 | rn->info = NULL; | |
527 | route_unlock_node(rn); | |
528 | route_unlock_node(rn); | |
529 | ||
530 | return CMD_SUCCESS; | |
baff583e MZ |
531 | } |
532 | ||
d62a17ae | 533 | void ospf6_distance_reset(struct ospf6 *o) |
baff583e | 534 | { |
d62a17ae | 535 | struct route_node *rn; |
536 | struct ospf6_distance *odistance; | |
537 | ||
538 | for (rn = route_top(o->distance_table); rn; rn = route_next(rn)) | |
539 | if ((odistance = rn->info) != NULL) { | |
540 | if (odistance->access_list) | |
541 | free(odistance->access_list); | |
542 | ospf6_distance_free(odistance); | |
543 | rn->info = NULL; | |
544 | route_unlock_node(rn); | |
545 | } | |
baff583e MZ |
546 | } |
547 | ||
d62a17ae | 548 | u_char ospf6_distance_apply(struct prefix_ipv6 *p, struct ospf6_route * or) |
baff583e | 549 | { |
d62a17ae | 550 | struct ospf6 *o; |
baff583e | 551 | |
d62a17ae | 552 | o = ospf6; |
553 | if (o == NULL) | |
554 | return 0; | |
baff583e | 555 | |
d62a17ae | 556 | if (o->distance_intra) |
557 | if (or->path.type == OSPF6_PATH_TYPE_INTRA) | |
558 | return o->distance_intra; | |
baff583e | 559 | |
d62a17ae | 560 | if (o->distance_inter) |
561 | if (or->path.type == OSPF6_PATH_TYPE_INTER) | |
562 | return o->distance_inter; | |
baff583e | 563 | |
d62a17ae | 564 | if (o->distance_external) |
565 | if (or->path.type == OSPF6_PATH_TYPE_EXTERNAL1 || | |
566 | or->path.type == OSPF6_PATH_TYPE_EXTERNAL2) | |
567 | return o->distance_external; | |
baff583e | 568 | |
d62a17ae | 569 | if (o->distance_all) |
570 | return o->distance_all; | |
baff583e | 571 | |
d62a17ae | 572 | return 0; |
baff583e MZ |
573 | } |
574 | ||
d62a17ae | 575 | static void ospf6_zebra_connected(struct zclient *zclient) |
7076bb2f | 576 | { |
d62a17ae | 577 | /* Send the client registration */ |
578 | bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER); | |
2376c3f2 | 579 | |
d62a17ae | 580 | zclient_send_reg_requests(zclient, VRF_DEFAULT); |
7076bb2f FL |
581 | } |
582 | ||
d62a17ae | 583 | void ospf6_zebra_init(struct thread_master *master) |
718e3744 | 584 | { |
d62a17ae | 585 | /* Allocate zebra structure. */ |
e1a1880d | 586 | zclient = zclient_new_notify(master, &zclient_options_default); |
342213ea | 587 | zclient_init(zclient, ZEBRA_ROUTE_OSPF6, 0, &ospf6d_privs); |
d62a17ae | 588 | zclient->zebra_connected = ospf6_zebra_connected; |
589 | zclient->router_id_update = ospf6_router_id_update_zebra; | |
590 | zclient->interface_add = ospf6_zebra_if_add; | |
591 | zclient->interface_delete = ospf6_zebra_if_del; | |
592 | zclient->interface_up = ospf6_zebra_if_state_update; | |
593 | zclient->interface_down = ospf6_zebra_if_state_update; | |
594 | zclient->interface_address_add = ospf6_zebra_if_address_update_add; | |
595 | zclient->interface_address_delete = | |
596 | ospf6_zebra_if_address_update_delete; | |
74489921 RW |
597 | zclient->redistribute_route_add = ospf6_zebra_read_route; |
598 | zclient->redistribute_route_del = ospf6_zebra_read_route; | |
d62a17ae | 599 | |
d62a17ae | 600 | /* Install command element for zebra node. */ |
601 | install_element(VIEW_NODE, &show_ospf6_zebra_cmd); | |
718e3744 | 602 | } |
603 | ||
508e53e2 | 604 | /* Debug */ |
6b0655a2 | 605 | |
508e53e2 | 606 | DEFUN (debug_ospf6_zebra_sendrecv, |
607 | debug_ospf6_zebra_sendrecv_cmd, | |
1d68dbfe | 608 | "debug ospf6 zebra [<send|recv>]", |
508e53e2 | 609 | DEBUG_STR |
610 | OSPF6_STR | |
611 | "Debug connection between zebra\n" | |
612 | "Debug Sending zebra\n" | |
613 | "Debug Receiving zebra\n" | |
614 | ) | |
615 | { | |
d62a17ae | 616 | int idx_send_recv = 3; |
617 | unsigned char level = 0; | |
618 | ||
619 | if (argc == 4) { | |
620 | if (strmatch(argv[idx_send_recv]->text, "send")) | |
621 | level = OSPF6_DEBUG_ZEBRA_SEND; | |
622 | else if (strmatch(argv[idx_send_recv]->text, "recv")) | |
623 | level = OSPF6_DEBUG_ZEBRA_RECV; | |
624 | } else | |
625 | level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; | |
626 | ||
627 | OSPF6_DEBUG_ZEBRA_ON(level); | |
628 | return CMD_SUCCESS; | |
508e53e2 | 629 | } |
630 | ||
508e53e2 | 631 | DEFUN (no_debug_ospf6_zebra_sendrecv, |
632 | no_debug_ospf6_zebra_sendrecv_cmd, | |
1d68dbfe | 633 | "no debug ospf6 zebra [<send|recv>]", |
508e53e2 | 634 | NO_STR |
635 | DEBUG_STR | |
636 | OSPF6_STR | |
637 | "Debug connection between zebra\n" | |
638 | "Debug Sending zebra\n" | |
639 | "Debug Receiving zebra\n" | |
640 | ) | |
641 | { | |
d62a17ae | 642 | int idx_send_recv = 4; |
643 | unsigned char level = 0; | |
644 | ||
645 | if (argc == 5) { | |
646 | if (strmatch(argv[idx_send_recv]->text, "send")) | |
647 | level = OSPF6_DEBUG_ZEBRA_SEND; | |
648 | else if (strmatch(argv[idx_send_recv]->text, "recv")) | |
649 | level = OSPF6_DEBUG_ZEBRA_RECV; | |
650 | } else | |
651 | level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV; | |
652 | ||
653 | OSPF6_DEBUG_ZEBRA_OFF(level); | |
654 | return CMD_SUCCESS; | |
508e53e2 | 655 | } |
656 | ||
508e53e2 | 657 | |
d62a17ae | 658 | int config_write_ospf6_debug_zebra(struct vty *vty) |
508e53e2 | 659 | { |
d62a17ae | 660 | if (IS_OSPF6_DEBUG_ZEBRA(SEND) && IS_OSPF6_DEBUG_ZEBRA(RECV)) |
661 | vty_out(vty, "debug ospf6 zebra\n"); | |
662 | else { | |
663 | if (IS_OSPF6_DEBUG_ZEBRA(SEND)) | |
664 | vty_out(vty, "debug ospf6 zebra send\n"); | |
665 | if (IS_OSPF6_DEBUG_ZEBRA(RECV)) | |
666 | vty_out(vty, "debug ospf6 zebra recv\n"); | |
667 | } | |
668 | return 0; | |
508e53e2 | 669 | } |
670 | ||
d62a17ae | 671 | void install_element_ospf6_debug_zebra(void) |
718e3744 | 672 | { |
d62a17ae | 673 | install_element(ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd); |
674 | install_element(ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); | |
675 | install_element(CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd); | |
676 | install_element(CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd); | |
718e3744 | 677 | } |