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