]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
2 | * Address linked list routine. | |
3 | * Copyright (C) 1997, 98 Kunihiro Ishiguro | |
4 | * | |
5 | * This file is part of GNU Zebra. | |
6 | * | |
7 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2, or (at your option) any | |
10 | * later version. | |
11 | * | |
12 | * GNU Zebra is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
896014f4 DL |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 20 | */ |
21 | ||
22 | #include <zebra.h> | |
23 | ||
24 | #include "prefix.h" | |
25 | #include "linklist.h" | |
26 | #include "if.h" | |
27 | #include "table.h" | |
28 | #include "rib.h" | |
29 | #include "table.h" | |
30 | #include "log.h" | |
0752ef0b | 31 | #include "memory.h" |
4a1ab8e4 | 32 | #include "zebra_memory.h" |
718e3744 | 33 | |
82f97584 | 34 | #include "vty.h" |
b84c7253 | 35 | #include "zebra/debug.h" |
718e3744 | 36 | #include "zebra/zserv.h" |
37 | #include "zebra/redistribute.h" | |
eef1fe11 | 38 | #include "zebra/interface.h" |
a1ac18c4 | 39 | #include "zebra/connected.h" |
b6120505 | 40 | #include "zebra/rtadv.h" |
40c7bdb0 | 41 | #include "zebra/zebra_mpls.h" |
939fba27 | 42 | #include "zebra/debug.h" |
9df414fe | 43 | #include "zebra/zebra_errors.h" |
6b0655a2 | 44 | |
02b4805f | 45 | /* communicate the withdrawal of a connected address */ |
d62a17ae | 46 | static void connected_withdraw(struct connected *ifc) |
ca16218d | 47 | { |
d62a17ae | 48 | if (!ifc) |
49 | return; | |
ca16218d | 50 | |
d62a17ae | 51 | /* Update interface address information to protocol daemon. */ |
52 | if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) { | |
53 | zebra_interface_address_delete_update(ifc->ifp, ifc); | |
ca16218d | 54 | |
d62a17ae | 55 | if (ifc->address->family == AF_INET) |
56 | if_subnet_delete(ifc->ifp, ifc); | |
9db047fc | 57 | |
11461c63 | 58 | connected_down(ifc->ifp, ifc); |
ca16218d | 59 | |
d62a17ae | 60 | UNSET_FLAG(ifc->conf, ZEBRA_IFC_REAL); |
61 | } | |
ca16218d | 62 | |
d62a17ae | 63 | /* The address is not in the kernel anymore, so clear the flag */ |
64 | UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED); | |
f7f740fe | 65 | |
d62a17ae | 66 | if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) { |
67 | listnode_delete(ifc->ifp->connected, ifc); | |
68 | connected_free(ifc); | |
69 | } | |
ca16218d | 70 | } |
71 | ||
d62a17ae | 72 | static void connected_announce(struct interface *ifp, struct connected *ifc) |
ca16218d | 73 | { |
d62a17ae | 74 | if (!ifc) |
75 | return; | |
76 | ||
b0fa6f6a CS |
77 | if (!if_is_loopback(ifp) && ifc->address->family == AF_INET && |
78 | !IS_ZEBRA_IF_VRF(ifp)) { | |
d62a17ae | 79 | if (ifc->address->prefixlen == 32) |
80 | SET_FLAG(ifc->flags, ZEBRA_IFA_UNNUMBERED); | |
81 | else | |
82 | UNSET_FLAG(ifc->flags, ZEBRA_IFA_UNNUMBERED); | |
83 | } | |
84 | ||
85 | listnode_add(ifp->connected, ifc); | |
86 | ||
87 | /* Update interface address information to protocol daemon. */ | |
88 | if (ifc->address->family == AF_INET) | |
89 | if_subnet_add(ifp, ifc); | |
90 | ||
91 | zebra_interface_address_add_update(ifp, ifc); | |
92 | ||
93 | if (if_is_operative(ifp)) { | |
ae87977c | 94 | connected_up(ifp, ifc); |
d62a17ae | 95 | } |
ca16218d | 96 | } |
6b0655a2 | 97 | |
718e3744 | 98 | /* If same interface address is already exist... */ |
abffde07 DL |
99 | struct connected *connected_check(struct interface *ifp, |
100 | union prefixconstptr pu) | |
718e3744 | 101 | { |
abffde07 | 102 | const struct prefix *p = pu.p; |
d62a17ae | 103 | struct connected *ifc; |
104 | struct listnode *node; | |
718e3744 | 105 | |
d62a17ae | 106 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) |
107 | if (prefix_same(ifc->address, p)) | |
108 | return ifc; | |
718e3744 | 109 | |
d62a17ae | 110 | return NULL; |
718e3744 | 111 | } |
112 | ||
abffde07 DL |
113 | /* same, but with peer address */ |
114 | struct connected *connected_check_ptp(struct interface *ifp, | |
115 | union prefixconstptr pu, | |
116 | union prefixconstptr du) | |
117 | { | |
118 | const struct prefix *p = pu.p; | |
119 | const struct prefix *d = du.p; | |
120 | struct connected *ifc; | |
121 | struct listnode *node; | |
122 | ||
123 | /* ignore broadcast addresses */ | |
124 | if (p->prefixlen != IPV4_MAX_PREFIXLEN) | |
125 | d = NULL; | |
126 | ||
127 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) { | |
128 | if (!prefix_same(ifc->address, p)) | |
129 | continue; | |
130 | if (!CONNECTED_PEER(ifc) && !d) | |
131 | return ifc; | |
132 | if (CONNECTED_PEER(ifc) && d | |
133 | && prefix_same(ifc->destination, d)) | |
134 | return ifc; | |
135 | } | |
136 | ||
137 | return NULL; | |
138 | } | |
139 | ||
02b4805f | 140 | /* Check if two ifc's describe the same address in the same state */ |
d62a17ae | 141 | static int connected_same(struct connected *ifc1, struct connected *ifc2) |
74ecdc9e | 142 | { |
d62a17ae | 143 | if (ifc1->ifp != ifc2->ifp) |
144 | return 0; | |
145 | ||
146 | if (ifc1->destination) | |
147 | if (!ifc2->destination) | |
148 | return 0; | |
149 | if (ifc2->destination) | |
150 | if (!ifc1->destination) | |
151 | return 0; | |
152 | ||
153 | if (ifc1->destination && ifc2->destination) | |
154 | if (!prefix_same(ifc1->destination, ifc2->destination)) | |
155 | return 0; | |
156 | ||
157 | if (ifc1->flags != ifc2->flags) | |
158 | return 0; | |
159 | ||
160 | if (ifc1->conf != ifc2->conf) | |
161 | return 0; | |
162 | ||
163 | return 1; | |
74ecdc9e PJ |
164 | } |
165 | ||
d7f5dad6 CF |
166 | /* Handle changes to addresses and send the neccesary announcements |
167 | * to clients. */ | |
d62a17ae | 168 | static void connected_update(struct interface *ifp, struct connected *ifc) |
74ecdc9e | 169 | { |
d62a17ae | 170 | struct connected *current; |
171 | ||
172 | /* Check same connected route. */ | |
abffde07 DL |
173 | current = connected_check_ptp(ifp, ifc->address, ifc->destination); |
174 | if (current) { | |
d62a17ae | 175 | if (CHECK_FLAG(current->conf, ZEBRA_IFC_CONFIGURED)) |
176 | SET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED); | |
177 | ||
178 | /* Avoid spurious withdraws, this might be just the kernel | |
179 | * 'reflecting' | |
180 | * back an address we have already added. | |
181 | */ | |
182 | if (connected_same(current, ifc)) { | |
183 | /* nothing to do */ | |
184 | connected_free(ifc); | |
185 | return; | |
186 | } | |
187 | ||
188 | /* Clear the configured flag on the old ifc, so it will be freed | |
189 | * by | |
190 | * connected withdraw. */ | |
191 | UNSET_FLAG(current->conf, ZEBRA_IFC_CONFIGURED); | |
192 | connected_withdraw( | |
193 | current); /* implicit withdraw - freebsd does this */ | |
194 | } | |
195 | ||
196 | /* If the connected is new or has changed, announce it, if it is usable | |
197 | */ | |
198 | if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) | |
199 | connected_announce(ifp, ifc); | |
74ecdc9e PJ |
200 | } |
201 | ||
718e3744 | 202 | /* Called from if_up(). */ |
ae87977c | 203 | void connected_up(struct interface *ifp, struct connected *ifc) |
718e3744 | 204 | { |
ae87977c | 205 | afi_t afi; |
d62a17ae | 206 | struct prefix p; |
fd36be7e | 207 | struct nexthop nh = { |
4a7371e9 DS |
208 | .type = NEXTHOP_TYPE_IFINDEX, |
209 | .ifindex = ifp->ifindex, | |
210 | .vrf_id = ifp->vrf_id, | |
fd36be7e | 211 | }; |
d62a17ae | 212 | |
213 | if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) | |
214 | return; | |
215 | ||
ae87977c | 216 | PREFIX_COPY(&p, CONNECTED_PREFIX(ifc)); |
d62a17ae | 217 | |
218 | /* Apply mask to the network. */ | |
219 | apply_mask(&p); | |
220 | ||
ae87977c DS |
221 | afi = family2afi(p.family); |
222 | ||
223 | switch (afi) { | |
224 | case AFI_IP: | |
225 | /* | |
226 | * In case of connected address is 0.0.0.0/0 we treat it tunnel | |
227 | * address. | |
228 | */ | |
229 | if (prefix_ipv4_any((struct prefix_ipv4 *)&p)) | |
230 | return; | |
231 | break; | |
232 | case AFI_IP6: | |
233 | #ifndef LINUX | |
234 | /* XXX: It is already done by rib_bogus_ipv6 within rib_add */ | |
235 | if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6)) | |
236 | return; | |
237 | #endif | |
238 | break; | |
239 | default: | |
e914ccbe | 240 | flog_warn(EC_ZEBRA_CONNECTED_AFI_UNKNOWN, |
9df414fe | 241 | "Received unknown AFI: %s", afi2str(afi)); |
d62a17ae | 242 | return; |
ae87977c DS |
243 | break; |
244 | } | |
d62a17ae | 245 | |
4a7371e9 DS |
246 | rib_add(afi, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0, &p, |
247 | NULL, &nh, RT_TABLE_MAIN, ifp->metric, 0, 0, 0); | |
d62a17ae | 248 | |
4a7371e9 DS |
249 | rib_add(afi, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0, &p, |
250 | NULL, &nh, RT_TABLE_MAIN, ifp->metric, 0, 0, 0); | |
d62a17ae | 251 | |
ae87977c DS |
252 | if (IS_ZEBRA_DEBUG_RIB_DETAILED) { |
253 | char buf[PREFIX_STRLEN]; | |
254 | ||
996c9314 LB |
255 | zlog_debug( |
256 | "%u: IF %s address %s add/up, scheduling RIB processing", | |
257 | ifp->vrf_id, ifp->name, | |
258 | prefix2str(&p, buf, sizeof(buf))); | |
ae87977c | 259 | } |
d62a17ae | 260 | rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); |
261 | ||
262 | /* Schedule LSP forwarding entries for processing, if appropriate. */ | |
263 | if (ifp->vrf_id == VRF_DEFAULT) { | |
ae87977c DS |
264 | if (IS_ZEBRA_DEBUG_MPLS) { |
265 | char buf[PREFIX_STRLEN]; | |
266 | ||
996c9314 LB |
267 | zlog_debug( |
268 | "%u: IF %s IP %s address add/up, scheduling MPLS processing", | |
269 | ifp->vrf_id, ifp->name, | |
270 | prefix2str(&p, buf, sizeof(buf))); | |
ae87977c | 271 | } |
d62a17ae | 272 | mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id)); |
273 | } | |
718e3744 | 274 | } |
275 | ||
276 | /* Add connected IPv4 route to the interface. */ | |
d62a17ae | 277 | void connected_add_ipv4(struct interface *ifp, int flags, struct in_addr *addr, |
d7c0a89a | 278 | uint8_t prefixlen, struct in_addr *broad, |
d62a17ae | 279 | const char *label) |
718e3744 | 280 | { |
d62a17ae | 281 | struct prefix_ipv4 *p; |
282 | struct connected *ifc; | |
283 | ||
284 | if (ipv4_martian(addr)) | |
285 | return; | |
286 | ||
287 | /* Make connected structure. */ | |
288 | ifc = connected_new(); | |
289 | ifc->ifp = ifp; | |
290 | ifc->flags = flags; | |
291 | /* If we get a notification from the kernel, | |
292 | * we can safely assume the address is known to the kernel */ | |
293 | SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED); | |
294 | ||
295 | /* Allocate new connected address. */ | |
296 | p = prefix_ipv4_new(); | |
297 | p->family = AF_INET; | |
298 | p->prefix = *addr; | |
abffde07 DL |
299 | p->prefixlen = CHECK_FLAG(flags, ZEBRA_IFA_PEER) ? IPV4_MAX_PREFIXLEN |
300 | : prefixlen; | |
d62a17ae | 301 | ifc->address = (struct prefix *)p; |
302 | ||
303 | /* If there is broadcast or peer address. */ | |
304 | if (broad) { | |
305 | p = prefix_ipv4_new(); | |
306 | p->family = AF_INET; | |
307 | p->prefix = *broad; | |
308 | p->prefixlen = prefixlen; | |
309 | ifc->destination = (struct prefix *)p; | |
310 | ||
311 | /* validate the destination address */ | |
312 | if (CONNECTED_PEER(ifc)) { | |
313 | if (IPV4_ADDR_SAME(addr, broad)) | |
9df414fe | 314 | flog_warn( |
e914ccbe | 315 | EC_ZEBRA_IFACE_SAME_LOCAL_AS_PEER, |
d62a17ae | 316 | "warning: interface %s has same local and peer " |
317 | "address %s, routing protocols may malfunction", | |
318 | ifp->name, inet_ntoa(*addr)); | |
319 | } else { | |
320 | if (broad->s_addr | |
321 | != ipv4_broadcast_addr(addr->s_addr, prefixlen)) { | |
322 | char buf[2][INET_ADDRSTRLEN]; | |
323 | struct in_addr bcalc; | |
324 | bcalc.s_addr = ipv4_broadcast_addr(addr->s_addr, | |
325 | prefixlen); | |
9df414fe | 326 | flog_warn( |
e914ccbe | 327 | EC_ZEBRA_BCAST_ADDR_MISMATCH, |
d62a17ae | 328 | "warning: interface %s broadcast addr %s/%d != " |
329 | "calculated %s, routing protocols may malfunction", | |
330 | ifp->name, | |
331 | inet_ntop(AF_INET, broad, buf[0], | |
332 | sizeof(buf[0])), | |
333 | prefixlen, | |
334 | inet_ntop(AF_INET, &bcalc, buf[1], | |
335 | sizeof(buf[1]))); | |
336 | } | |
337 | } | |
338 | ||
339 | } else { | |
340 | if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER)) { | |
9df414fe | 341 | zlog_debug( |
d62a17ae | 342 | "warning: %s called for interface %s " |
343 | "with peer flag set, but no peer address supplied", | |
344 | __func__, ifp->name); | |
345 | UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER); | |
346 | } | |
347 | ||
348 | /* no broadcast or destination address was supplied */ | |
349 | if ((prefixlen == IPV4_MAX_PREFIXLEN) && if_is_pointopoint(ifp)) | |
9df414fe | 350 | zlog_debug( |
d62a17ae | 351 | "warning: PtP interface %s with addr %s/%d needs a " |
352 | "peer address", | |
353 | ifp->name, inet_ntoa(*addr), prefixlen); | |
e4529636 AS |
354 | } |
355 | ||
d62a17ae | 356 | /* Label of this address. */ |
357 | if (label) | |
358 | ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label); | |
718e3744 | 359 | |
d62a17ae | 360 | /* For all that I know an IPv4 address is always ready when we receive |
361 | * the notification. So it should be safe to set the REAL flag here. */ | |
362 | SET_FLAG(ifc->conf, ZEBRA_IFC_REAL); | |
718e3744 | 363 | |
d62a17ae | 364 | connected_update(ifp, ifc); |
718e3744 | 365 | } |
366 | ||
11461c63 | 367 | void connected_down(struct interface *ifp, struct connected *ifc) |
718e3744 | 368 | { |
11461c63 | 369 | afi_t afi; |
d62a17ae | 370 | struct prefix p; |
fd36be7e | 371 | struct nexthop nh = { |
4a7371e9 DS |
372 | .type = NEXTHOP_TYPE_IFINDEX, |
373 | .ifindex = ifp->ifindex, | |
374 | .vrf_id = ifp->vrf_id, | |
fd36be7e | 375 | }; |
718e3744 | 376 | |
d62a17ae | 377 | if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) |
378 | return; | |
718e3744 | 379 | |
11461c63 | 380 | PREFIX_COPY(&p, CONNECTED_PREFIX(ifc)); |
718e3744 | 381 | |
d62a17ae | 382 | /* Apply mask to the network. */ |
383 | apply_mask(&p); | |
718e3744 | 384 | |
11461c63 DS |
385 | afi = family2afi(p.family); |
386 | ||
387 | switch (afi) { | |
388 | case AFI_IP: | |
389 | /* | |
390 | * In case of connected address is 0.0.0.0/0 we treat it tunnel | |
391 | * address. | |
392 | */ | |
393 | if (prefix_ipv4_any((struct prefix_ipv4 *)&p)) | |
394 | return; | |
395 | break; | |
396 | case AFI_IP6: | |
397 | if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6)) | |
398 | return; | |
399 | break; | |
400 | default: | |
401 | zlog_info("Unknown AFI: %s", afi2str(afi)); | |
402 | break; | |
403 | } | |
718e3744 | 404 | |
11461c63 DS |
405 | /* |
406 | * Same logic as for connected_up(): push the changes into the | |
407 | * head. | |
408 | */ | |
409 | rib_delete(afi, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0, | |
40ecd8e4 | 410 | &p, NULL, &nh, 0, 0, 0, false); |
718e3744 | 411 | |
996c9314 | 412 | rib_delete(afi, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0, |
40ecd8e4 | 413 | &p, NULL, &nh, 0, 0, 0, false); |
42cb6b66 | 414 | |
11461c63 DS |
415 | if (IS_ZEBRA_DEBUG_RIB_DETAILED) { |
416 | char buf[PREFIX_STRLEN]; | |
417 | ||
996c9314 LB |
418 | zlog_debug( |
419 | "%u: IF %s IP %s address down, scheduling RIB processing", | |
420 | ifp->vrf_id, ifp->name, | |
421 | prefix2str(&p, buf, sizeof(buf))); | |
11461c63 | 422 | } |
b84c7253 | 423 | |
d62a17ae | 424 | rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); |
40c7bdb0 | 425 | |
d62a17ae | 426 | /* Schedule LSP forwarding entries for processing, if appropriate. */ |
427 | if (ifp->vrf_id == VRF_DEFAULT) { | |
11461c63 DS |
428 | if (IS_ZEBRA_DEBUG_MPLS) { |
429 | char buf[PREFIX_STRLEN]; | |
430 | ||
996c9314 LB |
431 | zlog_debug( |
432 | "%u: IF %s IP %s address down, scheduling MPLS processing", | |
433 | ifp->vrf_id, ifp->name, | |
434 | prefix2str(&p, buf, sizeof(buf))); | |
11461c63 | 435 | } |
d62a17ae | 436 | mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id)); |
437 | } | |
718e3744 | 438 | } |
439 | ||
dc7cd304 DS |
440 | static void connected_delete_helper(struct connected *ifc, struct prefix *p) |
441 | { | |
442 | struct interface *ifp; | |
443 | ||
444 | if (!ifc) | |
445 | return; | |
446 | ifp = ifc->ifp; | |
447 | ||
448 | connected_withdraw(ifc); | |
449 | ||
450 | if (IS_ZEBRA_DEBUG_RIB_DETAILED) { | |
451 | char buf[PREFIX_STRLEN]; | |
452 | ||
996c9314 LB |
453 | zlog_debug( |
454 | "%u: IF %s IP %s address del, scheduling RIB processing", | |
455 | ifp->vrf_id, ifp->name, | |
456 | prefix2str(p, buf, sizeof(buf))); | |
dc7cd304 DS |
457 | } |
458 | rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); | |
459 | ||
460 | /* Schedule LSP forwarding entries for processing, if appropriate. */ | |
461 | if (ifp->vrf_id == VRF_DEFAULT) { | |
462 | if (IS_ZEBRA_DEBUG_MPLS) { | |
463 | char buf[PREFIX_STRLEN]; | |
464 | ||
996c9314 LB |
465 | zlog_debug( |
466 | "%u: IF %s IP %s address delete, scheduling MPLS processing", | |
467 | ifp->vrf_id, ifp->name, | |
468 | prefix2str(p, buf, sizeof(buf))); | |
dc7cd304 DS |
469 | } |
470 | mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id)); | |
471 | } | |
472 | } | |
473 | ||
718e3744 | 474 | /* Delete connected IPv4 route to the interface. */ |
d62a17ae | 475 | void connected_delete_ipv4(struct interface *ifp, int flags, |
d7c0a89a | 476 | struct in_addr *addr, uint8_t prefixlen, |
d62a17ae | 477 | struct in_addr *broad) |
718e3744 | 478 | { |
dc7cd304 | 479 | struct prefix p, d; |
d62a17ae | 480 | struct connected *ifc; |
481 | ||
dc7cd304 | 482 | memset(&p, 0, sizeof(struct prefix)); |
d62a17ae | 483 | p.family = AF_INET; |
dc7cd304 | 484 | p.u.prefix4 = *addr; |
abffde07 DL |
485 | p.prefixlen = CHECK_FLAG(flags, ZEBRA_IFA_PEER) ? IPV4_MAX_PREFIXLEN |
486 | : prefixlen; | |
487 | ||
488 | if (broad) { | |
dc7cd304 | 489 | memset(&d, 0, sizeof(struct prefix)); |
abffde07 | 490 | d.family = AF_INET; |
dc7cd304 | 491 | d.u.prefix4 = *broad; |
abffde07 | 492 | d.prefixlen = prefixlen; |
dc7cd304 | 493 | ifc = connected_check_ptp(ifp, &p, &d); |
abffde07 | 494 | } else |
dc7cd304 | 495 | ifc = connected_check_ptp(ifp, &p, NULL); |
d62a17ae | 496 | |
dc7cd304 | 497 | connected_delete_helper(ifc, &p); |
718e3744 | 498 | } |
499 | ||
718e3744 | 500 | /* Add connected IPv6 route to the interface. */ |
d62a17ae | 501 | void connected_add_ipv6(struct interface *ifp, int flags, struct in6_addr *addr, |
60c0687a DS |
502 | struct in6_addr *broad, uint8_t prefixlen, |
503 | const char *label) | |
718e3744 | 504 | { |
d62a17ae | 505 | struct prefix_ipv6 *p; |
506 | struct connected *ifc; | |
507 | ||
508 | if (ipv6_martian(addr)) | |
509 | return; | |
510 | ||
511 | /* Make connected structure. */ | |
512 | ifc = connected_new(); | |
513 | ifc->ifp = ifp; | |
514 | ifc->flags = flags; | |
515 | /* If we get a notification from the kernel, | |
516 | * we can safely assume the address is known to the kernel */ | |
517 | SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED); | |
518 | ||
519 | /* Allocate new connected address. */ | |
520 | p = prefix_ipv6_new(); | |
521 | p->family = AF_INET6; | |
522 | IPV6_ADDR_COPY(&p->prefix, addr); | |
523 | p->prefixlen = prefixlen; | |
524 | ifc->address = (struct prefix *)p; | |
525 | ||
f52d0a1a | 526 | if (broad) { |
60c0687a DS |
527 | p = prefix_ipv6_new(); |
528 | p->family = AF_INET6; | |
529 | IPV6_ADDR_COPY(&p->prefix, broad); | |
530 | p->prefixlen = prefixlen; | |
531 | ifc->destination = (struct prefix *)p; | |
f52d0a1a DS |
532 | } else { |
533 | if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER)) { | |
9df414fe QY |
534 | zlog_debug( |
535 | "warning: %s called for interface %s with peer flag set, but no peer address supplied", | |
536 | __func__, ifp->name); | |
f52d0a1a DS |
537 | UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER); |
538 | } | |
60c0687a DS |
539 | } |
540 | ||
d62a17ae | 541 | /* Label of this address. */ |
542 | if (label) | |
543 | ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label); | |
544 | ||
545 | /* On Linux, we only get here when DAD is complete, therefore we can set | |
546 | * ZEBRA_IFC_REAL. | |
547 | * | |
548 | * On BSD, there currently doesn't seem to be a way to check for | |
549 | * completion of | |
550 | * DAD, so we replicate the old behaviour and set ZEBRA_IFC_REAL, | |
551 | * although DAD | |
552 | * might still be running. | |
553 | */ | |
554 | SET_FLAG(ifc->conf, ZEBRA_IFC_REAL); | |
555 | connected_update(ifp, ifc); | |
718e3744 | 556 | } |
557 | ||
d62a17ae | 558 | void connected_delete_ipv6(struct interface *ifp, struct in6_addr *address, |
60c0687a | 559 | struct in6_addr *broad, uint8_t prefixlen) |
718e3744 | 560 | { |
60c0687a | 561 | struct prefix p, d; |
d62a17ae | 562 | struct connected *ifc; |
563 | ||
dc7cd304 | 564 | memset(&p, 0, sizeof(struct prefix)); |
d62a17ae | 565 | p.family = AF_INET6; |
dc7cd304 | 566 | memcpy(&p.u.prefix6, address, sizeof(struct in6_addr)); |
d62a17ae | 567 | p.prefixlen = prefixlen; |
568 | ||
60c0687a DS |
569 | if (broad) { |
570 | memset(&d, 0, sizeof(struct prefix)); | |
571 | d.family = AF_INET6; | |
a85297a7 | 572 | IPV6_ADDR_COPY(&d.u.prefix6, broad); |
60c0687a DS |
573 | d.prefixlen = prefixlen; |
574 | ifc = connected_check_ptp(ifp, &p, &d); | |
575 | } else | |
576 | ifc = connected_check_ptp(ifp, &p, NULL); | |
d62a17ae | 577 | |
dc7cd304 | 578 | connected_delete_helper(ifc, &p); |
718e3744 | 579 | } |
d44ca835 | 580 | |
d62a17ae | 581 | int connected_is_unnumbered(struct interface *ifp) |
d44ca835 | 582 | { |
d62a17ae | 583 | struct connected *connected; |
584 | struct listnode *node; | |
585 | ||
586 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { | |
587 | if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL) | |
588 | && connected->address->family == AF_INET) | |
589 | return CHECK_FLAG(connected->flags, | |
590 | ZEBRA_IFA_UNNUMBERED); | |
591 | } | |
592 | return 0; | |
d44ca835 | 593 | } |