]> git.proxmox.com Git - mirror_frr.git/blame - zebra/connected.c
tests: clean up all_proto_startup a bit
[mirror_frr.git] / zebra / connected.c
CommitLineData
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"
718e3744 32
82f97584 33#include "vty.h"
b84c7253 34#include "zebra/debug.h"
718e3744 35#include "zebra/zserv.h"
36#include "zebra/redistribute.h"
eef1fe11 37#include "zebra/interface.h"
a1ac18c4 38#include "zebra/connected.h"
b6120505 39#include "zebra/rtadv.h"
40c7bdb0 40#include "zebra/zebra_mpls.h"
9df414fe 41#include "zebra/zebra_errors.h"
e4876266 42#include "zebra/zebra_router.h"
6b0655a2 43
02b4805f 44/* communicate the withdrawal of a connected address */
d62a17ae 45static void connected_withdraw(struct connected *ifc)
ca16218d 46{
d62a17ae 47 if (!ifc)
48 return;
ca16218d 49
d62a17ae 50 /* Update interface address information to protocol daemon. */
51 if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) {
52 zebra_interface_address_delete_update(ifc->ifp, ifc);
ca16218d 53
d62a17ae 54 if (ifc->address->family == AF_INET)
55 if_subnet_delete(ifc->ifp, ifc);
9db047fc 56
11461c63 57 connected_down(ifc->ifp, ifc);
ca16218d 58
d62a17ae 59 UNSET_FLAG(ifc->conf, ZEBRA_IFC_REAL);
60 }
ca16218d 61
d62a17ae 62 /* The address is not in the kernel anymore, so clear the flag */
63 UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
f7f740fe 64
d62a17ae 65 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) {
66 listnode_delete(ifc->ifp->connected, ifc);
721c0857 67 connected_free(&ifc);
d62a17ae 68 }
ca16218d 69}
70
d62a17ae 71static void connected_announce(struct interface *ifp, struct connected *ifc)
ca16218d 72{
d62a17ae 73 if (!ifc)
74 return;
75
b0fa6f6a
CS
76 if (!if_is_loopback(ifp) && ifc->address->family == AF_INET &&
77 !IS_ZEBRA_IF_VRF(ifp)) {
12256b84 78 if (ifc->address->prefixlen == IPV4_MAX_BITLEN)
d62a17ae 79 SET_FLAG(ifc->flags, ZEBRA_IFA_UNNUMBERED);
80 else
81 UNSET_FLAG(ifc->flags, ZEBRA_IFA_UNNUMBERED);
82 }
83
84 listnode_add(ifp->connected, ifc);
85
86 /* Update interface address information to protocol daemon. */
87 if (ifc->address->family == AF_INET)
88 if_subnet_add(ifp, ifc);
89
90 zebra_interface_address_add_update(ifp, ifc);
91
92 if (if_is_operative(ifp)) {
ae87977c 93 connected_up(ifp, ifc);
d62a17ae 94 }
ca16218d 95}
6b0655a2 96
718e3744 97/* If same interface address is already exist... */
abffde07
DL
98struct connected *connected_check(struct interface *ifp,
99 union prefixconstptr pu)
718e3744 100{
abffde07 101 const struct prefix *p = pu.p;
d62a17ae 102 struct connected *ifc;
103 struct listnode *node;
718e3744 104
d62a17ae 105 for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc))
106 if (prefix_same(ifc->address, p))
107 return ifc;
718e3744 108
d62a17ae 109 return NULL;
718e3744 110}
111
abffde07
DL
112/* same, but with peer address */
113struct connected *connected_check_ptp(struct interface *ifp,
114 union prefixconstptr pu,
115 union prefixconstptr du)
116{
117 const struct prefix *p = pu.p;
118 const struct prefix *d = du.p;
119 struct connected *ifc;
120 struct listnode *node;
121
abffde07
DL
122 for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
123 if (!prefix_same(ifc->address, p))
124 continue;
125 if (!CONNECTED_PEER(ifc) && !d)
126 return ifc;
127 if (CONNECTED_PEER(ifc) && d
128 && prefix_same(ifc->destination, d))
129 return ifc;
130 }
131
132 return NULL;
133}
134
02b4805f 135/* Check if two ifc's describe the same address in the same state */
d62a17ae 136static int connected_same(struct connected *ifc1, struct connected *ifc2)
74ecdc9e 137{
d62a17ae 138 if (ifc1->ifp != ifc2->ifp)
139 return 0;
140
0f3af738
JW
141 if (ifc1->flags != ifc2->flags)
142 return 0;
143
144 if (ifc1->conf != ifc2->conf)
145 return 0;
146
d62a17ae 147 if (ifc1->destination)
148 if (!ifc2->destination)
149 return 0;
150 if (ifc2->destination)
151 if (!ifc1->destination)
152 return 0;
153
154 if (ifc1->destination && ifc2->destination)
155 if (!prefix_same(ifc1->destination, ifc2->destination))
156 return 0;
157
d62a17ae 158 return 1;
74ecdc9e
PJ
159}
160
d7f5dad6
CF
161/* Handle changes to addresses and send the neccesary announcements
162 * to clients. */
d62a17ae 163static void connected_update(struct interface *ifp, struct connected *ifc)
74ecdc9e 164{
d62a17ae 165 struct connected *current;
166
167 /* Check same connected route. */
abffde07
DL
168 current = connected_check_ptp(ifp, ifc->address, ifc->destination);
169 if (current) {
d62a17ae 170 if (CHECK_FLAG(current->conf, ZEBRA_IFC_CONFIGURED))
171 SET_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED);
172
173 /* Avoid spurious withdraws, this might be just the kernel
174 * 'reflecting'
175 * back an address we have already added.
176 */
177 if (connected_same(current, ifc)) {
178 /* nothing to do */
721c0857 179 connected_free(&ifc);
d62a17ae 180 return;
181 }
182
183 /* Clear the configured flag on the old ifc, so it will be freed
184 * by
185 * connected withdraw. */
186 UNSET_FLAG(current->conf, ZEBRA_IFC_CONFIGURED);
187 connected_withdraw(
188 current); /* implicit withdraw - freebsd does this */
189 }
190
191 /* If the connected is new or has changed, announce it, if it is usable
192 */
193 if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
194 connected_announce(ifp, ifc);
74ecdc9e
PJ
195}
196
718e3744 197/* Called from if_up(). */
ae87977c 198void connected_up(struct interface *ifp, struct connected *ifc)
718e3744 199{
ae87977c 200 afi_t afi;
b08dcc3f 201 struct prefix p;
fd36be7e 202 struct nexthop nh = {
4a7371e9
DS
203 .type = NEXTHOP_TYPE_IFINDEX,
204 .ifindex = ifp->ifindex,
a36898e7 205 .vrf_id = ifp->vrf_id,
fd36be7e 206 };
56e78254 207 struct zebra_vrf *zvrf;
cde1af84 208 uint32_t metric;
e4876266 209 uint32_t flags = 0;
92980561
DS
210 uint32_t count = 0;
211 struct listnode *cnode;
212 struct connected *c;
d62a17ae 213
a36898e7 214 zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
56e78254 215 if (!zvrf) {
15569c58
DA
216 flog_err(
217 EC_ZEBRA_VRF_NOT_FOUND,
218 "%s: Received Up for interface but no associated zvrf: %d",
219 __func__, ifp->vrf_id);
56e78254
DS
220 return;
221 }
d62a17ae 222 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
223 return;
224
e3d901f8
MS
225 /* Ensure 'down' flag is cleared */
226 UNSET_FLAG(ifc->conf, ZEBRA_IFC_DOWN);
227
b08dcc3f 228 prefix_copy(&p, CONNECTED_PREFIX(ifc));
d62a17ae 229
230 /* Apply mask to the network. */
231 apply_mask(&p);
232
ae87977c
DS
233 afi = family2afi(p.family);
234
235 switch (afi) {
236 case AFI_IP:
237 /*
238 * In case of connected address is 0.0.0.0/0 we treat it tunnel
239 * address.
240 */
241 if (prefix_ipv4_any((struct prefix_ipv4 *)&p))
242 return;
243 break;
244 case AFI_IP6:
70bc8385 245#ifndef GNU_LINUX
ae87977c
DS
246 /* XXX: It is already done by rib_bogus_ipv6 within rib_add */
247 if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6))
248 return;
249#endif
250 break;
251 default:
e914ccbe 252 flog_warn(EC_ZEBRA_CONNECTED_AFI_UNKNOWN,
9df414fe 253 "Received unknown AFI: %s", afi2str(afi));
d62a17ae 254 return;
ae87977c
DS
255 break;
256 }
d62a17ae 257
cde1af84
AK
258 metric = (ifc->metric < (uint32_t)METRIC_MAX) ?
259 ifc->metric : ifp->metric;
d62a17ae 260
e4876266
DS
261 /*
262 * Since we are hand creating the connected routes
263 * in our main routing table, *if* we are working
264 * in an offloaded environment then we need to
265 * pretend like the route is offloaded so everything
266 * else will work
267 */
268 if (zrouter.asic_offloaded)
269 flags |= ZEBRA_FLAG_OFFLOADED;
270
92980561
DS
271 /*
272 * It's possible to add the same network and mask
273 * to an interface over and over. This would
274 * result in an equivalent number of connected
275 * routes. Just add one connected route in
276 * for all the addresses on an interface that
277 * resolve to the same network and mask
278 */
279 for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
b08dcc3f 280 struct prefix cp;
92980561 281
b08dcc3f 282 prefix_copy(&cp, CONNECTED_PREFIX(c));
92980561
DS
283 apply_mask(&cp);
284
e3d901f8
MS
285 if (prefix_same(&cp, &p) &&
286 !CHECK_FLAG(c->conf, ZEBRA_IFC_DOWN))
92980561
DS
287 count++;
288
289 if (count >= 2)
290 return;
291 }
292
e4876266
DS
293 rib_add(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0,
294 flags, &p, NULL, &nh, 0, zvrf->table_id, metric, 0, 0, 0);
295
296 rib_add(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0,
297 flags, &p, NULL, &nh, 0, zvrf->table_id, metric, 0, 0, 0);
d62a17ae 298
d62a17ae 299 /* Schedule LSP forwarding entries for processing, if appropriate. */
56e78254 300 if (zvrf->vrf->vrf_id == VRF_DEFAULT) {
2dbe669b 301 if (IS_ZEBRA_DEBUG_MPLS)
996c9314 302 zlog_debug(
2dbe669b
DA
303 "%u: IF %s IP %pFX address add/up, scheduling MPLS processing",
304 zvrf->vrf->vrf_id, ifp->name, &p);
56e78254 305 mpls_mark_lsps_for_processing(zvrf, &p);
d62a17ae 306 }
718e3744 307}
308
309/* Add connected IPv4 route to the interface. */
9c86ee1e
MS
310void connected_add_ipv4(struct interface *ifp, int flags,
311 const struct in_addr *addr, uint16_t prefixlen,
312 const struct in_addr *dest, const char *label,
313 uint32_t metric)
718e3744 314{
d62a17ae 315 struct prefix_ipv4 *p;
316 struct connected *ifc;
317
318 if (ipv4_martian(addr))
319 return;
320
321 /* Make connected structure. */
322 ifc = connected_new();
323 ifc->ifp = ifp;
324 ifc->flags = flags;
cde1af84 325 ifc->metric = metric;
d62a17ae 326 /* If we get a notification from the kernel,
327 * we can safely assume the address is known to the kernel */
328 SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
329
330 /* Allocate new connected address. */
331 p = prefix_ipv4_new();
332 p->family = AF_INET;
333 p->prefix = *addr;
936fbaef
DA
334 p->prefixlen =
335 CHECK_FLAG(flags, ZEBRA_IFA_PEER) ? IPV4_MAX_BITLEN : prefixlen;
d62a17ae 336 ifc->address = (struct prefix *)p;
337
0f3af738
JW
338 /* If there is a peer address. */
339 if (CONNECTED_PEER(ifc)) {
d62a17ae 340 /* validate the destination address */
0f3af738
JW
341 if (dest) {
342 p = prefix_ipv4_new();
343 p->family = AF_INET;
344 p->prefix = *dest;
345 p->prefixlen = prefixlen;
346 ifc->destination = (struct prefix *)p;
347
348 if (IPV4_ADDR_SAME(addr, dest))
9df414fe 349 flog_warn(
e914ccbe 350 EC_ZEBRA_IFACE_SAME_LOCAL_AS_PEER,
ad6f7449 351 "interface %s has same local and peer address %pI4, routing protocols may malfunction",
9bcef951 352 ifp->name, addr);
d62a17ae 353 } else {
9df414fe 354 zlog_debug(
ad6f7449 355 "%s called for interface %s with peer flag set, but no peer address supplied",
d62a17ae 356 __func__, ifp->name);
357 UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
358 }
e4529636
AS
359 }
360
0f3af738 361 /* no destination address was supplied */
936fbaef 362 if (!dest && (prefixlen == IPV4_MAX_BITLEN) && if_is_pointopoint(ifp))
0f3af738 363 zlog_debug(
ad6f7449 364 "PtP interface %s with addr %pI4/%d needs a peer address",
9bcef951 365 ifp->name, addr, prefixlen);
0f3af738 366
d62a17ae 367 /* Label of this address. */
368 if (label)
369 ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label);
718e3744 370
d62a17ae 371 /* For all that I know an IPv4 address is always ready when we receive
372 * the notification. So it should be safe to set the REAL flag here. */
373 SET_FLAG(ifc->conf, ZEBRA_IFC_REAL);
718e3744 374
d62a17ae 375 connected_update(ifp, ifc);
718e3744 376}
377
11461c63 378void connected_down(struct interface *ifp, struct connected *ifc)
718e3744 379{
11461c63 380 afi_t afi;
d62a17ae 381 struct prefix p;
fd36be7e 382 struct nexthop nh = {
4a7371e9
DS
383 .type = NEXTHOP_TYPE_IFINDEX,
384 .ifindex = ifp->ifindex,
a36898e7 385 .vrf_id = ifp->vrf_id,
fd36be7e 386 };
56e78254 387 struct zebra_vrf *zvrf;
92980561
DS
388 uint32_t count = 0;
389 struct listnode *cnode;
390 struct connected *c;
56e78254 391
a36898e7 392 zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
56e78254 393 if (!zvrf) {
15569c58
DA
394 flog_err(
395 EC_ZEBRA_VRF_NOT_FOUND,
e3d901f8 396 "%s: Received Down for interface but no associated zvrf: %d",
15569c58 397 __func__, ifp->vrf_id);
56e78254
DS
398 return;
399 }
718e3744 400
d62a17ae 401 if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
402 return;
718e3744 403
e3d901f8
MS
404 /* Skip if we've already done this; this can happen if we have a
405 * config change that takes an interface down, then we receive kernel
406 * notifications about the downed interface and its addresses.
407 */
408 if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_DOWN)) {
409 if (IS_ZEBRA_DEBUG_RIB)
410 zlog_debug("%s: ifc %p, %pFX already DOWN",
411 __func__, ifc, ifc->address);
412 return;
413 }
414
b08dcc3f 415 prefix_copy(&p, CONNECTED_PREFIX(ifc));
718e3744 416
d62a17ae 417 /* Apply mask to the network. */
418 apply_mask(&p);
718e3744 419
11461c63
DS
420 afi = family2afi(p.family);
421
422 switch (afi) {
423 case AFI_IP:
424 /*
425 * In case of connected address is 0.0.0.0/0 we treat it tunnel
426 * address.
427 */
428 if (prefix_ipv4_any((struct prefix_ipv4 *)&p))
429 return;
430 break;
431 case AFI_IP6:
432 if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6))
433 return;
434 break;
435 default:
14a4d9d0 436 zlog_warn("Unknown AFI: %s", afi2str(afi));
11461c63
DS
437 break;
438 }
718e3744 439
e3d901f8
MS
440 /* Mark the address as 'down' */
441 SET_FLAG(ifc->conf, ZEBRA_IFC_DOWN);
442
92980561
DS
443 /*
444 * It's possible to have X number of addresses
445 * on a interface that all resolve to the same
446 * network and mask. Find them and just
447 * allow the deletion when are removing the last
448 * one.
449 */
450 for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
451 struct prefix cp;
452
b08dcc3f 453 prefix_copy(&cp, CONNECTED_PREFIX(c));
92980561
DS
454 apply_mask(&cp);
455
e3d901f8
MS
456 if (prefix_same(&p, &cp) &&
457 !CHECK_FLAG(c->conf, ZEBRA_IFC_DOWN))
92980561
DS
458 count++;
459
e3d901f8 460 if (count >= 1)
92980561
DS
461 return;
462 }
463
11461c63
DS
464 /*
465 * Same logic as for connected_up(): push the changes into the
466 * head.
467 */
bc541126 468 rib_delete(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0,
3ceae22b 469 0, &p, NULL, &nh, 0, zvrf->table_id, 0, 0, false);
718e3744 470
56e78254 471 rib_delete(afi, SAFI_MULTICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT,
3ceae22b 472 0, 0, &p, NULL, &nh, 0, zvrf->table_id, 0, 0, false);
42cb6b66 473
d62a17ae 474 /* Schedule LSP forwarding entries for processing, if appropriate. */
56e78254 475 if (zvrf->vrf->vrf_id == VRF_DEFAULT) {
2dbe669b 476 if (IS_ZEBRA_DEBUG_MPLS)
996c9314 477 zlog_debug(
2dbe669b
DA
478 "%u: IF %s IP %pFX address down, scheduling MPLS processing",
479 zvrf->vrf->vrf_id, ifp->name, &p);
56e78254 480 mpls_mark_lsps_for_processing(zvrf, &p);
d62a17ae 481 }
718e3744 482}
483
dc7cd304
DS
484static void connected_delete_helper(struct connected *ifc, struct prefix *p)
485{
486 struct interface *ifp;
487
488 if (!ifc)
489 return;
490 ifp = ifc->ifp;
491
492 connected_withdraw(ifc);
493
dc7cd304 494 /* Schedule LSP forwarding entries for processing, if appropriate. */
a36898e7 495 if (ifp->vrf_id == VRF_DEFAULT) {
2dbe669b 496 if (IS_ZEBRA_DEBUG_MPLS)
996c9314 497 zlog_debug(
2dbe669b
DA
498 "%u: IF %s IP %pFX address delete, scheduling MPLS processing",
499 ifp->vrf_id, ifp->name, p);
a36898e7 500 mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id), p);
dc7cd304
DS
501 }
502}
503
718e3744 504/* Delete connected IPv4 route to the interface. */
d62a17ae 505void connected_delete_ipv4(struct interface *ifp, int flags,
9c86ee1e
MS
506 const struct in_addr *addr, uint16_t prefixlen,
507 const struct in_addr *dest)
718e3744 508{
dc7cd304 509 struct prefix p, d;
d62a17ae 510 struct connected *ifc;
511
dc7cd304 512 memset(&p, 0, sizeof(struct prefix));
d62a17ae 513 p.family = AF_INET;
dc7cd304 514 p.u.prefix4 = *addr;
936fbaef
DA
515 p.prefixlen =
516 CHECK_FLAG(flags, ZEBRA_IFA_PEER) ? IPV4_MAX_BITLEN : prefixlen;
abffde07 517
0f3af738 518 if (dest) {
dc7cd304 519 memset(&d, 0, sizeof(struct prefix));
abffde07 520 d.family = AF_INET;
0f3af738 521 d.u.prefix4 = *dest;
abffde07 522 d.prefixlen = prefixlen;
dc7cd304 523 ifc = connected_check_ptp(ifp, &p, &d);
abffde07 524 } else
dc7cd304 525 ifc = connected_check_ptp(ifp, &p, NULL);
d62a17ae 526
dc7cd304 527 connected_delete_helper(ifc, &p);
718e3744 528}
529
718e3744 530/* Add connected IPv6 route to the interface. */
9c86ee1e
MS
531void connected_add_ipv6(struct interface *ifp, int flags,
532 const struct in6_addr *addr,
533 const struct in6_addr *dest, uint16_t prefixlen,
cde1af84 534 const char *label, uint32_t metric)
718e3744 535{
d62a17ae 536 struct prefix_ipv6 *p;
537 struct connected *ifc;
538
539 if (ipv6_martian(addr))
540 return;
541
542 /* Make connected structure. */
543 ifc = connected_new();
544 ifc->ifp = ifp;
545 ifc->flags = flags;
cde1af84 546 ifc->metric = metric;
d62a17ae 547 /* If we get a notification from the kernel,
548 * we can safely assume the address is known to the kernel */
549 SET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
550
551 /* Allocate new connected address. */
552 p = prefix_ipv6_new();
553 p->family = AF_INET6;
554 IPV6_ADDR_COPY(&p->prefix, addr);
555 p->prefixlen = prefixlen;
556 ifc->address = (struct prefix *)p;
557
2a855763
DS
558 /* Add global ipv6 address to the RA prefix list */
559 if (!IN6_IS_ADDR_LINKLOCAL(&p->prefix))
560 rtadv_add_prefix(ifp->info, p);
561
0f3af738 562 if (dest) {
60c0687a
DS
563 p = prefix_ipv6_new();
564 p->family = AF_INET6;
0f3af738 565 IPV6_ADDR_COPY(&p->prefix, dest);
60c0687a
DS
566 p->prefixlen = prefixlen;
567 ifc->destination = (struct prefix *)p;
f52d0a1a
DS
568 } else {
569 if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER)) {
9df414fe 570 zlog_debug(
ad6f7449 571 "%s called for interface %s with peer flag set, but no peer address supplied",
9df414fe 572 __func__, ifp->name);
f52d0a1a
DS
573 UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
574 }
60c0687a
DS
575 }
576
d62a17ae 577 /* Label of this address. */
578 if (label)
579 ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label);
580
581 /* On Linux, we only get here when DAD is complete, therefore we can set
582 * ZEBRA_IFC_REAL.
583 *
584 * On BSD, there currently doesn't seem to be a way to check for
585 * completion of
586 * DAD, so we replicate the old behaviour and set ZEBRA_IFC_REAL,
587 * although DAD
588 * might still be running.
589 */
590 SET_FLAG(ifc->conf, ZEBRA_IFC_REAL);
591 connected_update(ifp, ifc);
718e3744 592}
593
9c86ee1e
MS
594void connected_delete_ipv6(struct interface *ifp,
595 const struct in6_addr *address,
596 const struct in6_addr *dest, uint16_t prefixlen)
718e3744 597{
60c0687a 598 struct prefix p, d;
d62a17ae 599 struct connected *ifc;
600
dc7cd304 601 memset(&p, 0, sizeof(struct prefix));
d62a17ae 602 p.family = AF_INET6;
dc7cd304 603 memcpy(&p.u.prefix6, address, sizeof(struct in6_addr));
d62a17ae 604 p.prefixlen = prefixlen;
605
2a855763
DS
606 /* Delete global ipv6 address from RA prefix list */
607 if (!IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6))
608 rtadv_delete_prefix(ifp->info, &p);
609
0f3af738 610 if (dest) {
60c0687a
DS
611 memset(&d, 0, sizeof(struct prefix));
612 d.family = AF_INET6;
0f3af738 613 IPV6_ADDR_COPY(&d.u.prefix6, dest);
60c0687a
DS
614 d.prefixlen = prefixlen;
615 ifc = connected_check_ptp(ifp, &p, &d);
616 } else
617 ifc = connected_check_ptp(ifp, &p, NULL);
d62a17ae 618
dc7cd304 619 connected_delete_helper(ifc, &p);
718e3744 620}
d44ca835 621
d62a17ae 622int connected_is_unnumbered(struct interface *ifp)
d44ca835 623{
d62a17ae 624 struct connected *connected;
625 struct listnode *node;
626
627 for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
628 if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
629 && connected->address->family == AF_INET)
630 return CHECK_FLAG(connected->flags,
631 ZEBRA_IFA_UNNUMBERED);
632 }
a79fdd65 633 return 0;
d44ca835 634}