2 * Copyright (c) 2009 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* $FreeBSD: src/sys/netinet6/nd6_nbr.c,v 1.4.2.4 2001/07/06 05:32:25 sumikawa Exp $ */
29 /* $KAME: nd6_nbr.c,v 1.64 2001/05/17 03:48:30 itojun Exp $ */
32 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. Neither the name of the project nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 #include <sys/param.h>
61 #include <sys/systm.h>
62 #include <sys/malloc.h>
64 #include <sys/socket.h>
65 #include <sys/sockio.h>
67 #include <sys/kernel.h>
68 #include <sys/errno.h>
69 #include <sys/syslog.h>
70 #include <kern/queue.h>
73 #include <net/if_types.h>
74 #include <net/if_dl.h>
75 #include <net/route.h>
77 #include <netinet/in.h>
78 #include <netinet/in_var.h>
79 #include <netinet6/in6_var.h>
80 #include <netinet/ip6.h>
81 #include <netinet6/ip6_var.h>
82 #include <netinet6/nd6.h>
83 #include <netinet/icmp6.h>
86 #include <netinet6/ipsec.h>
88 #include <netinet6/ipsec6.h>
90 extern int ipsec_bypass
;
93 #include <net/net_osdep.h>
95 #define SDL(s) ((struct sockaddr_dl *)s)
98 static struct dadq
*nd6_dad_find(struct ifaddr
*);
100 static void nd6_dad_starttimer(struct dadq
*, int);
101 static void nd6_dad_stoptimer(struct dadq
*);
103 void nd6_dad_stoptimer(struct ifaddr
*);
105 static void nd6_dad_timer(struct ifaddr
*);
106 static void nd6_dad_ns_output(struct dadq
*, struct ifaddr
*);
107 static void nd6_dad_ns_input(struct ifaddr
*);
108 static void nd6_dad_na_input(struct ifaddr
*);
110 static int dad_ignore_ns
= 0; /* ignore NS in DAD - specwise incorrect*/
111 static int dad_maxtry
= 15; /* max # of *tries* to transmit DAD packet */
113 extern lck_mtx_t
*dad6_mutex
;
114 extern lck_mtx_t
*nd6_mutex
;
116 * Input an Neighbor Solicitation Message.
119 * Based on RFC 2462 (duplicated address detection)
127 struct ifnet
*ifp
= m
->m_pkthdr
.rcvif
;
128 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
129 struct nd_neighbor_solicit
*nd_ns
;
130 struct in6_addr saddr6
= ip6
->ip6_src
;
131 struct in6_addr daddr6
= ip6
->ip6_dst
;
132 struct in6_addr taddr6
;
133 struct in6_addr myaddr6
;
135 struct ifaddr
*ifa
= NULL
;
137 int anycast
= 0, proxy
= 0, tentative
= 0;
139 union nd_opts ndopts
;
140 struct sockaddr_dl proxydl
;
142 #ifndef PULLDOWN_TEST
143 IP6_EXTHDR_CHECK(m
, off
, icmp6len
, return);
144 nd_ns
= (struct nd_neighbor_solicit
*)((caddr_t
)ip6
+ off
);
146 IP6_EXTHDR_GET(nd_ns
, struct nd_neighbor_solicit
*, m
, off
, icmp6len
);
148 icmp6stat
.icp6s_tooshort
++;
152 ip6
= mtod(m
, struct ip6_hdr
*); /* adjust pointer for safety */
153 taddr6
= nd_ns
->nd_ns_target
;
155 if (ip6
->ip6_hlim
!= 255) {
157 "nd6_ns_input: invalid hlim (%d) from %s to %s on %s\n",
158 ip6
->ip6_hlim
, ip6_sprintf(&ip6
->ip6_src
),
159 ip6_sprintf(&ip6
->ip6_dst
), if_name(ifp
)));
163 if (IN6_IS_ADDR_UNSPECIFIED(&saddr6
)) {
164 /* dst has to be solicited node multicast address. */
165 if (daddr6
.s6_addr16
[0] == IPV6_ADDR_INT16_MLL
166 /* don't check ifindex portion */
167 && daddr6
.s6_addr32
[1] == 0
168 && daddr6
.s6_addr32
[2] == IPV6_ADDR_INT32_ONE
169 && daddr6
.s6_addr8
[12] == 0xff) {
172 nd6log((LOG_INFO
, "nd6_ns_input: bad DAD packet "
173 "(wrong ip6 dst)\n"));
178 if (IN6_IS_ADDR_MULTICAST(&taddr6
)) {
179 nd6log((LOG_INFO
, "nd6_ns_input: bad NS target (multicast)\n"));
183 if (IN6_IS_SCOPE_LINKLOCAL(&taddr6
))
184 taddr6
.s6_addr16
[1] = htons(ifp
->if_index
);
186 icmp6len
-= sizeof(*nd_ns
);
187 nd6_option_init(nd_ns
+ 1, icmp6len
, &ndopts
);
188 if (nd6_options(&ndopts
) < 0) {
190 "nd6_ns_input: invalid ND option, ignored\n"));
191 /* nd6_options have incremented stats */
195 if (ndopts
.nd_opts_src_lladdr
) {
196 lladdr
= (char *)(ndopts
.nd_opts_src_lladdr
+ 1);
197 lladdrlen
= ndopts
.nd_opts_src_lladdr
->nd_opt_len
<< 3;
200 if (IN6_IS_ADDR_UNSPECIFIED(&ip6
->ip6_src
) && lladdr
) {
201 nd6log((LOG_INFO
, "nd6_ns_input: bad DAD packet "
202 "(link-layer address option)\n"));
207 * Attaching target link-layer address to the NA?
210 * NS IP dst is unicast/anycast MUST NOT add
211 * NS IP dst is solicited-node multicast MUST add
213 * In implementation, we add target link-layer address by default.
214 * We do not add one in MUST NOT cases.
216 #if 0 /* too much! */
217 ifa
= (struct ifaddr
*)in6ifa_ifpwithaddr(ifp
, &daddr6
);
218 if (ifa
&& (((struct in6_ifaddr
*)ifa
)->ia6_flags
& IN6_IFF_ANYCAST
))
222 if (!IN6_IS_ADDR_MULTICAST(&daddr6
))
228 * Target address (taddr6) must be either:
229 * (1) Valid unicast/anycast address for my receiving interface,
230 * (2) Unicast address for which I'm offering proxy service, or
231 * (3) "tentative" address on which DAD is being performed.
233 /* (1) and (3) check. */
234 ifa
= (struct ifaddr
*)in6ifa_ifpwithaddr(ifp
, &taddr6
);
239 struct sockaddr_in6 tsin6
;
241 bzero(&tsin6
, sizeof tsin6
);
242 tsin6
.sin6_len
= sizeof(struct sockaddr_in6
);
243 tsin6
.sin6_family
= AF_INET6
;
244 tsin6
.sin6_addr
= taddr6
;
246 rt
= rtalloc1((struct sockaddr
*)&tsin6
, 0, 0);
249 if ((rt
->rt_flags
& RTF_ANNOUNCE
) != 0 &&
250 rt
->rt_gateway
->sa_family
== AF_LINK
) {
252 * proxy NDP for single entry
254 ifa
= (struct ifaddr
*)in6ifa_ifpforlinklocal(
255 ifp
, IN6_IFF_NOTREADY
|IN6_IFF_ANYCAST
);
258 proxydl
= *SDL(rt
->rt_gateway
);
267 * We've got an NS packet, and we don't have that adddress
268 * assigned for us. We MUST silently ignore it.
273 myaddr6
= *IFA_IN6(ifa
);
274 anycast
= ((struct in6_ifaddr
*)ifa
)->ia6_flags
& IN6_IFF_ANYCAST
;
275 tentative
= ((struct in6_ifaddr
*)ifa
)->ia6_flags
& IN6_IFF_TENTATIVE
;
276 if (((struct in6_ifaddr
*)ifa
)->ia6_flags
& IN6_IFF_DUPLICATED
)
279 if (lladdr
&& ((ifp
->if_addrlen
+ 2 + 7) & ~7) != lladdrlen
) {
281 "nd6_ns_input: lladdrlen mismatch for %s "
282 "(if %d, NS packet %d)\n",
283 ip6_sprintf(&taddr6
), ifp
->if_addrlen
, lladdrlen
- 2));
287 if (IN6_ARE_ADDR_EQUAL(&myaddr6
, &saddr6
)) {
289 "nd6_ns_input: duplicate IP6 address %s\n",
290 ip6_sprintf(&saddr6
)));
295 * We have neighbor solicitation packet, with target address equals to
296 * one of my tentative address.
298 * src addr how to process?
300 * multicast of course, invalid (rejected in ip6_input)
301 * unicast somebody is doing address resolution -> ignore
302 * unspec dup address detection
304 * The processing is defined in RFC 2462.
308 * If source address is unspecified address, it is for
309 * duplicated address detection.
311 * If not, the packet is for addess resolution;
312 * silently ignore it.
314 if (IN6_IS_ADDR_UNSPECIFIED(&saddr6
))
315 nd6_dad_ns_input(ifa
);
321 * If the source address is unspecified address, entries must not
322 * be created or updated.
323 * It looks that sender is performing DAD. Output NA toward
324 * all-node multicast address, to tell the sender that I'm using
326 * S bit ("solicited") must be zero.
328 if (IN6_IS_ADDR_UNSPECIFIED(&saddr6
)) {
329 saddr6
= in6addr_linklocal_allnodes
;
330 saddr6
.s6_addr16
[1] = htons(ifp
->if_index
);
331 nd6_na_output(ifp
, &saddr6
, &taddr6
,
332 ((anycast
|| proxy
|| !tlladdr
)
333 ? 0 : ND_NA_FLAG_OVERRIDE
)
334 | (ip6_forwarding
? ND_NA_FLAG_ROUTER
: 0),
335 tlladdr
, proxy
? (struct sockaddr
*)&proxydl
: NULL
);
339 nd6_cache_lladdr(ifp
, &saddr6
, lladdr
, lladdrlen
, ND_NEIGHBOR_SOLICIT
, 0);
341 nd6_na_output(ifp
, &saddr6
, &taddr6
,
342 ((anycast
|| proxy
|| !tlladdr
) ? 0 : ND_NA_FLAG_OVERRIDE
)
343 | (ip6_forwarding
? ND_NA_FLAG_ROUTER
: 0)
344 | ND_NA_FLAG_SOLICITED
,
345 tlladdr
, proxy
? (struct sockaddr
*)&proxydl
: NULL
);
353 nd6log((LOG_ERR
, "nd6_ns_input: src=%s\n", ip6_sprintf(&saddr6
)));
354 nd6log((LOG_ERR
, "nd6_ns_input: dst=%s\n", ip6_sprintf(&daddr6
)));
355 nd6log((LOG_ERR
, "nd6_ns_input: tgt=%s\n", ip6_sprintf(&taddr6
)));
356 icmp6stat
.icp6s_badns
++;
363 * Output an Neighbor Solicitation Message. Caller specifies:
364 * - ICMP6 header source IP6 address
365 * - ND6 header target IP6 address
366 * - ND6 header source datalink address
369 * Based on RFC 2462 (duplicated address detection)
371 * Caller must bump up ln->ln_rt refcnt to make sure 'ln' doesn't go
372 * away if there is a llinfo_nd6 passed in.
377 const struct in6_addr
*daddr6
,
378 const struct in6_addr
*taddr6
,
379 struct llinfo_nd6
*ln
, /* for source address determination */
380 int dad
, /* duplicated address detection */
385 struct nd_neighbor_solicit
*nd_ns
;
386 struct in6_ifaddr
*ia
= NULL
;
387 struct ip6_moptions im6o
;
391 struct ifnet
*outif
= NULL
;
393 if (IN6_IS_ADDR_MULTICAST(taddr6
))
396 /* estimate the size of message */
397 maxlen
= sizeof(*ip6
) + sizeof(*nd_ns
);
398 maxlen
+= (sizeof(struct nd_opt_hdr
) + ifp
->if_addrlen
+ 7) & ~7;
399 if (max_linkhdr
+ maxlen
>= MCLBYTES
) {
401 printf("nd6_ns_output: max_linkhdr + maxlen >= MCLBYTES "
402 "(%d + %d > %d)\n", max_linkhdr
, maxlen
, MCLBYTES
);
407 MGETHDR(m
, M_DONTWAIT
, MT_DATA
); /* XXXMAC: mac_create_mbuf_linklayer() probably */
408 if (m
&& max_linkhdr
+ maxlen
>= MHLEN
) {
409 MCLGET(m
, M_DONTWAIT
);
410 if ((m
->m_flags
& M_EXT
) == 0) {
417 m
->m_pkthdr
.rcvif
= NULL
;
419 if (daddr6
== NULL
|| IN6_IS_ADDR_MULTICAST(daddr6
)) {
420 m
->m_flags
|= M_MCAST
;
421 im6o
.im6o_multicast_ifp
= ifp
;
422 im6o
.im6o_multicast_hlim
= 255;
423 im6o
.im6o_multicast_loop
= 0;
426 icmp6len
= sizeof(*nd_ns
);
427 m
->m_pkthdr
.len
= m
->m_len
= sizeof(*ip6
) + icmp6len
;
428 m
->m_data
+= max_linkhdr
; /* or MH_ALIGN() equivalent? */
430 /* fill neighbor solicitation packet */
431 ip6
= mtod(m
, struct ip6_hdr
*);
433 ip6
->ip6_vfc
&= ~IPV6_VERSION_MASK
;
434 ip6
->ip6_vfc
|= IPV6_VERSION
;
435 /* ip6->ip6_plen will be set later */
436 ip6
->ip6_nxt
= IPPROTO_ICMPV6
;
439 ip6
->ip6_dst
= *daddr6
;
441 ip6
->ip6_dst
.s6_addr16
[0] = IPV6_ADDR_INT16_MLL
;
442 ip6
->ip6_dst
.s6_addr16
[1] = htons(ifp
->if_index
);
443 ip6
->ip6_dst
.s6_addr32
[1] = 0;
444 ip6
->ip6_dst
.s6_addr32
[2] = IPV6_ADDR_INT32_ONE
;
445 ip6
->ip6_dst
.s6_addr32
[3] = taddr6
->s6_addr32
[3];
446 ip6
->ip6_dst
.s6_addr8
[12] = 0xff;
449 #if 0 /* KAME way, exact address scope match */
451 * Select a source whose scope is the same as that of the dest.
452 * Typically, the dest is link-local solicitation multicast
453 * (i.e. neighbor discovery) or link-local/global unicast
454 * (i.e. neighbor un-reachability detection).
456 ia
= in6_ifawithifp(ifp
, &ip6
->ip6_dst
);
461 ip6
->ip6_src
= ia
->ia_addr
.sin6_addr
;
462 #else /* spec-wise correct */
465 * "If the source address of the packet prompting the
466 * solicitation is the same as one of the addresses assigned
467 * to the outgoing interface, that address SHOULD be placed
468 * in the IP Source Address of the outgoing solicitation.
469 * Otherwise, any one of the addresses assigned to the
470 * interface should be used."
472 * We use the source address for the prompting packet
474 * - saddr6 is given from the caller (by giving "ln"), and
475 * - saddr6 belongs to the outgoing interface.
476 * Otherwise, we perform a scope-wise match.
478 struct ip6_hdr
*hip6
= NULL
; /* hold ip6 */
479 struct in6_addr saddr6
;
481 /* Caller holds ref on this route */
484 if (ln
->ln_hold
!= NULL
) {
485 hip6
= mtod(ln
->ln_hold
, struct ip6_hdr
*);
487 if (sizeof (*hip6
) < ln
->ln_hold
->m_len
)
488 saddr6
= hip6
->ip6_src
;
493 * hip6 is used only to indicate whether or
494 * not there is a valid source address from
495 * the held packet in ln_hold. For obvious
496 * reasons we should not dereference it after
497 * releasing the lock though we can simply
498 * test if it's non-NULL.
500 RT_UNLOCK(ln
->ln_rt
);
504 ifafree(&ia
->ia_ifa
);
505 if (hip6
!= NULL
&& (ia
= in6ifa_ifpwithaddr(ifp
, &saddr6
))) {
506 bcopy(&saddr6
, &ip6
->ip6_src
, sizeof (saddr6
));
508 ia
= in6_ifawithifp(ifp
, &ip6
->ip6_dst
);
512 if (ln
->ln_hold
!= NULL
)
513 m_freem(ln
->ln_hold
);
515 RT_UNLOCK(ln
->ln_rt
);
520 ip6
->ip6_src
= ia
->ia_addr
.sin6_addr
;
523 ifafree(&ia
->ia_ifa
);
529 * Source address for DAD packet must always be IPv6
530 * unspecified address. (0::0)
532 bzero(&ip6
->ip6_src
, sizeof(ip6
->ip6_src
));
534 nd_ns
= (struct nd_neighbor_solicit
*)(ip6
+ 1);
535 nd_ns
->nd_ns_type
= ND_NEIGHBOR_SOLICIT
;
536 nd_ns
->nd_ns_code
= 0;
537 nd_ns
->nd_ns_reserved
= 0;
538 nd_ns
->nd_ns_target
= *taddr6
;
540 if (IN6_IS_SCOPE_LINKLOCAL(&nd_ns
->nd_ns_target
))
541 nd_ns
->nd_ns_target
.s6_addr16
[1] = 0;
544 * Add source link-layer address option.
546 * spec implementation
548 * DAD packet MUST NOT do not add the option
549 * there's no link layer address:
550 * impossible do not add the option
551 * there's link layer address:
552 * Multicast NS MUST add one add the option
553 * Unicast NS SHOULD add one add the option
555 if (!dad
&& (mac
= nd6_ifptomac(ifp
))) {
556 int optlen
= sizeof(struct nd_opt_hdr
) + ifp
->if_addrlen
;
557 struct nd_opt_hdr
*nd_opt
= (struct nd_opt_hdr
*)(nd_ns
+ 1);
558 /* 8 byte alignments... */
559 optlen
= (optlen
+ 7) & ~7;
561 m
->m_pkthdr
.len
+= optlen
;
564 bzero((caddr_t
)nd_opt
, optlen
);
565 nd_opt
->nd_opt_type
= ND_OPT_SOURCE_LINKADDR
;
566 nd_opt
->nd_opt_len
= optlen
>> 3;
567 bcopy(mac
, (caddr_t
)(nd_opt
+ 1), ifp
->if_addrlen
);
570 ip6
->ip6_plen
= htons((u_short
)icmp6len
);
571 nd_ns
->nd_ns_cksum
= 0;
573 = in6_cksum(m
, IPPROTO_ICMPV6
, sizeof(*ip6
), icmp6len
);
576 /* Don't lookup socket */
577 if (ipsec_bypass
== 0)
578 (void)ipsec_setsocket(m
, NULL
);
580 ip6_output(m
, NULL
, NULL
, dad
? IPV6_DADOUTPUT
: 0, &im6o
, &outif
, locked
);
582 icmp6_ifstat_inc(outif
, ifs6_out_msg
);
583 icmp6_ifstat_inc(outif
, ifs6_out_neighborsolicit
);
585 icmp6stat
.icp6s_outhist
[ND_NEIGHBOR_SOLICIT
]++;
589 * Neighbor advertisement input handling.
592 * Based on RFC 2462 (duplicated address detection)
594 * the following items are not implemented yet:
595 * - proxy advertisement delay rule (RFC2461 7.2.8, last paragraph, SHOULD)
596 * - anycast advertisement delay rule (RFC2461 7.2.7, SHOULD)
604 struct ifnet
*ifp
= m
->m_pkthdr
.rcvif
;
605 struct ip6_hdr
*ip6
= mtod(m
, struct ip6_hdr
*);
606 struct nd_neighbor_advert
*nd_na
;
608 struct in6_addr saddr6
= ip6
->ip6_src
;
610 struct in6_addr daddr6
= ip6
->ip6_dst
;
611 struct in6_addr taddr6
;
618 struct ifaddr
*ifa
= NULL
;
619 struct llinfo_nd6
*ln
;
621 struct sockaddr_dl
*sdl
;
622 union nd_opts ndopts
;
623 struct timeval timenow
;
625 if (ip6
->ip6_hlim
!= 255) {
627 "nd6_na_input: invalid hlim (%d) from %s to %s on %s\n",
628 ip6
->ip6_hlim
, ip6_sprintf(&ip6
->ip6_src
),
629 ip6_sprintf(&ip6
->ip6_dst
), if_name(ifp
)));
633 #ifndef PULLDOWN_TEST
634 IP6_EXTHDR_CHECK(m
, off
, icmp6len
, return);
635 nd_na
= (struct nd_neighbor_advert
*)((caddr_t
)ip6
+ off
);
637 IP6_EXTHDR_GET(nd_na
, struct nd_neighbor_advert
*, m
, off
, icmp6len
);
639 icmp6stat
.icp6s_tooshort
++;
643 taddr6
= nd_na
->nd_na_target
;
644 flags
= nd_na
->nd_na_flags_reserved
;
645 is_router
= ((flags
& ND_NA_FLAG_ROUTER
) != 0);
646 is_solicited
= ((flags
& ND_NA_FLAG_SOLICITED
) != 0);
647 is_override
= ((flags
& ND_NA_FLAG_OVERRIDE
) != 0);
649 if (IN6_IS_SCOPE_LINKLOCAL(&taddr6
))
650 taddr6
.s6_addr16
[1] = htons(ifp
->if_index
);
652 if (IN6_IS_ADDR_MULTICAST(&taddr6
)) {
654 "nd6_na_input: invalid target address %s\n",
655 ip6_sprintf(&taddr6
)));
658 if (IN6_IS_ADDR_MULTICAST(&daddr6
))
661 "nd6_na_input: a solicited adv is multicasted\n"));
665 icmp6len
-= sizeof(*nd_na
);
666 nd6_option_init(nd_na
+ 1, icmp6len
, &ndopts
);
667 if (nd6_options(&ndopts
) < 0) {
669 "nd6_na_input: invalid ND option, ignored\n"));
670 /* nd6_options have incremented stats */
674 if (ndopts
.nd_opts_tgt_lladdr
) {
675 lladdr
= (char *)(ndopts
.nd_opts_tgt_lladdr
+ 1);
676 lladdrlen
= ndopts
.nd_opts_tgt_lladdr
->nd_opt_len
<< 3;
679 ifa
= (struct ifaddr
*)in6ifa_ifpwithaddr(ifp
, &taddr6
);
682 * Target address matches one of my interface address.
684 * If my address is tentative, this means that there's somebody
685 * already using the same address as mine. This indicates DAD failure.
686 * This is defined in RFC 2462.
688 * Otherwise, process as defined in RFC 2461.
691 && (((struct in6_ifaddr
*)ifa
)->ia6_flags
& IN6_IFF_TENTATIVE
)) {
692 nd6_dad_na_input(ifa
);
696 /* Just for safety, maybe unnecessary. */
699 "nd6_na_input: duplicate IP6 address %s\n",
700 ip6_sprintf(&taddr6
));
704 if (lladdr
&& ((ifp
->if_addrlen
+ 2 + 7) & ~7) != lladdrlen
) {
706 "nd6_na_input: lladdrlen mismatch for %s "
707 "(if %d, NA packet %d)\n",
708 ip6_sprintf(&taddr6
), ifp
->if_addrlen
, lladdrlen
- 2));
713 * If no neighbor cache entry is found, NA SHOULD silently be discarded.
714 * Callee returns a locked route upon success.
716 if ((rt
= nd6_lookup(&taddr6
, 0, ifp
, 0)) == NULL
)
719 RT_LOCK_ASSERT_HELD(rt
);
720 if ((ln
= rt
->rt_llinfo
) == NULL
||
721 (sdl
= SDL(rt
->rt_gateway
)) == NULL
) {
722 RT_REMREF_LOCKED(rt
);
727 getmicrotime(&timenow
);
728 if (ln
->ln_state
== ND6_LLINFO_INCOMPLETE
) {
730 * If the link-layer has address, and no lladdr option came,
731 * discard the packet.
733 if (ifp
->if_addrlen
&& !lladdr
) {
734 RT_REMREF_LOCKED(rt
);
740 * Record link-layer address, and update the state.
742 sdl
->sdl_alen
= ifp
->if_addrlen
;
743 bcopy(lladdr
, LLADDR(sdl
), ifp
->if_addrlen
);
745 ln
->ln_state
= ND6_LLINFO_REACHABLE
;
748 lck_rw_lock_shared(nd_if_rwlock
);
749 ln
->ln_expire
= rt_expiry(rt
, timenow
.tv_sec
,
750 nd_ifinfo
[rt
->rt_ifp
->if_index
].reachable
);
751 lck_rw_done(nd_if_rwlock
);
754 ln
->ln_state
= ND6_LLINFO_STALE
;
755 ln
->ln_expire
= rt_expiry(rt
, timenow
.tv_sec
,
758 if ((ln
->ln_router
= is_router
) != 0) {
760 * This means a router's state has changed from
761 * non-reachable to probably reachable, and might
762 * affect the status of associated prefixes..
765 pfxlist_onlink_check(0);
772 * Check if the link-layer address has changed or not.
778 if (bcmp(lladdr
, LLADDR(sdl
), ifp
->if_addrlen
))
787 * This is VERY complex. Look at it with care.
789 * override solicit lladdr llchange action
794 * 0 0 y y (1) REACHABLE->STALE
795 * 0 1 n -- (2c) *->REACHABLE
796 * 0 1 y n (2b) L *->REACHABLE
797 * 0 1 y y (1) REACHABLE->STALE
800 * 1 0 y y (2a) L *->STALE
801 * 1 1 n -- (2a) *->REACHABLE
802 * 1 1 y n (2a) L *->REACHABLE
803 * 1 1 y y (2a) L *->REACHABLE
805 if (!is_override
&& (lladdr
&& llchange
)) { /* (1) */
807 * If state is REACHABLE, make it STALE.
808 * no other updates should be done.
810 if (ln
->ln_state
== ND6_LLINFO_REACHABLE
) {
811 ln
->ln_state
= ND6_LLINFO_STALE
;
812 ln
->ln_expire
= rt_expiry(rt
, timenow
.tv_sec
,
815 RT_REMREF_LOCKED(rt
);
818 } else if (is_override
/* (2a) */
819 || (!is_override
&& (lladdr
&& !llchange
)) /* (2b) */
820 || !lladdr
) { /* (2c) */
822 * Update link-local address, if any.
825 sdl
->sdl_alen
= ifp
->if_addrlen
;
826 bcopy(lladdr
, LLADDR(sdl
), ifp
->if_addrlen
);
830 * If solicited, make the state REACHABLE.
831 * If not solicited and the link-layer address was
832 * changed, make it STALE.
835 ln
->ln_state
= ND6_LLINFO_REACHABLE
;
838 lck_rw_lock_shared(nd_if_rwlock
);
840 rt_expiry(rt
, timenow
.tv_sec
,
841 nd_ifinfo
[ifp
->if_index
].reachable
);
842 lck_rw_done(nd_if_rwlock
);
845 if (lladdr
&& llchange
) {
846 ln
->ln_state
= ND6_LLINFO_STALE
;
847 ln
->ln_expire
= rt_expiry(rt
,
848 timenow
.tv_sec
, nd6_gctimer
);
853 if (ln
->ln_router
&& !is_router
) {
855 * The peer dropped the router flag.
856 * Remove the sender from the Default Router List and
857 * update the Destination Cache entries.
859 struct nd_defrouter
*dr
;
860 struct in6_addr
*in6
;
861 struct ifnet
*rt_ifp
= rt
->rt_ifp
;
863 in6
= &((struct sockaddr_in6
*)rt_key(rt
))->sin6_addr
;
866 * Lock to protect the default router list.
867 * XXX: this might be unnecessary, since this function
868 * is only called under the network software interrupt
869 * context. However, we keep it just for safety.
872 lck_mtx_lock(nd6_mutex
);
873 dr
= defrouter_lookup(in6
, rt_ifp
);
875 defrtrlist_del(dr
, 1);
876 lck_mtx_unlock(nd6_mutex
);
879 lck_mtx_unlock(nd6_mutex
);
880 if (!ip6_forwarding
&& (ip6_accept_rtadv
|| (rt_ifp
->if_eflags
& IFEF_ACCEPT_RTADVD
))) {
882 * Even if the neighbor is not in the default
883 * router list, the neighbor may be used
884 * as a next hop for some destinations
885 * (e.g. redirect case). So we must
886 * call rt6_flush explicitly.
888 rt6_flush(&ip6
->ip6_src
, rt_ifp
);
893 ln
->ln_router
= is_router
;
895 RT_LOCK_ASSERT_HELD(rt
);
896 rt
->rt_flags
&= ~RTF_REJECT
;
898 if (ln
->ln_hold
!= NULL
) {
899 struct mbuf
*n
= ln
->ln_hold
;
902 * we assume ifp is not a loopback here, so just set the 2nd
903 * argument as the 1st one.
906 nd6_output(ifp
, ifp
, n
, (struct sockaddr_in6
*)rt_key(rt
),
910 RT_REMREF_LOCKED(rt
);
920 icmp6stat
.icp6s_badna
++;
927 * Neighbor advertisement output handling.
931 * the following items are not implemented yet:
932 * - proxy advertisement delay rule (RFC2461 7.2.8, last paragraph, SHOULD)
933 * - anycast advertisement delay rule (RFC2461 7.2.7, SHOULD)
938 const struct in6_addr
*daddr6
,
939 const struct in6_addr
*taddr6
,
941 int tlladdr
, /* 1 if include target link-layer address */
942 struct sockaddr
*sdl0
) /* sockaddr_dl (= proxy NA) or NULL */
946 struct nd_neighbor_advert
*nd_na
;
947 struct in6_ifaddr
*ia
= NULL
;
948 struct ip6_moptions im6o
;
952 struct ifnet
*outif
= NULL
;
954 /* estimate the size of message */
955 maxlen
= sizeof(*ip6
) + sizeof(*nd_na
);
956 maxlen
+= (sizeof(struct nd_opt_hdr
) + ifp
->if_addrlen
+ 7) & ~7;
957 if (max_linkhdr
+ maxlen
>= MCLBYTES
) {
959 printf("nd6_na_output: max_linkhdr + maxlen >= MCLBYTES "
960 "(%d + %d > %d)\n", max_linkhdr
, maxlen
, MCLBYTES
);
965 MGETHDR(m
, M_DONTWAIT
, MT_DATA
); /* XXXMAC: mac_create_mbuf_linklayer() probably */
966 if (m
&& max_linkhdr
+ maxlen
>= MHLEN
) {
967 MCLGET(m
, M_DONTWAIT
);
968 if ((m
->m_flags
& M_EXT
) == 0) {
975 m
->m_pkthdr
.rcvif
= NULL
;
977 if (IN6_IS_ADDR_MULTICAST(daddr6
)) {
978 m
->m_flags
|= M_MCAST
;
979 im6o
.im6o_multicast_ifp
= ifp
;
980 im6o
.im6o_multicast_hlim
= 255;
981 im6o
.im6o_multicast_loop
= 0;
984 icmp6len
= sizeof(*nd_na
);
985 m
->m_pkthdr
.len
= m
->m_len
= sizeof(struct ip6_hdr
) + icmp6len
;
986 m
->m_data
+= max_linkhdr
; /* or MH_ALIGN() equivalent? */
988 /* fill neighbor advertisement packet */
989 ip6
= mtod(m
, struct ip6_hdr
*);
991 ip6
->ip6_vfc
&= ~IPV6_VERSION_MASK
;
992 ip6
->ip6_vfc
|= IPV6_VERSION
;
993 ip6
->ip6_nxt
= IPPROTO_ICMPV6
;
995 if (IN6_IS_ADDR_UNSPECIFIED(daddr6
)) {
997 ip6
->ip6_dst
.s6_addr16
[0] = IPV6_ADDR_INT16_MLL
;
998 ip6
->ip6_dst
.s6_addr16
[1] = htons(ifp
->if_index
);
999 ip6
->ip6_dst
.s6_addr32
[1] = 0;
1000 ip6
->ip6_dst
.s6_addr32
[2] = 0;
1001 ip6
->ip6_dst
.s6_addr32
[3] = IPV6_ADDR_INT32_ONE
;
1002 flags
&= ~ND_NA_FLAG_SOLICITED
;
1004 ip6
->ip6_dst
= *daddr6
;
1007 * Select a source whose scope is the same as that of the dest.
1009 ia
= in6_ifawithifp(ifp
, &ip6
->ip6_dst
);
1014 ip6
->ip6_src
= ia
->ia_addr
.sin6_addr
;
1015 ifafree(&ia
->ia_ifa
);
1018 nd_na
= (struct nd_neighbor_advert
*)(ip6
+ 1);
1019 nd_na
->nd_na_type
= ND_NEIGHBOR_ADVERT
;
1020 nd_na
->nd_na_code
= 0;
1021 nd_na
->nd_na_target
= *taddr6
;
1022 if (IN6_IS_SCOPE_LINKLOCAL(&nd_na
->nd_na_target
))
1023 nd_na
->nd_na_target
.s6_addr16
[1] = 0;
1026 * "tlladdr" indicates NS's condition for adding tlladdr or not.
1027 * see nd6_ns_input() for details.
1028 * Basically, if NS packet is sent to unicast/anycast addr,
1029 * target lladdr option SHOULD NOT be included.
1033 * sdl0 != NULL indicates proxy NA. If we do proxy, use
1034 * lladdr in sdl0. If we are not proxying (sending NA for
1035 * my address) use lladdr configured for the interface.
1038 mac
= nd6_ifptomac(ifp
);
1039 else if (sdl0
->sa_family
== AF_LINK
) {
1040 struct sockaddr_dl
*sdl
;
1041 sdl
= (struct sockaddr_dl
*)sdl0
;
1042 if (sdl
->sdl_alen
== ifp
->if_addrlen
)
1046 if (tlladdr
&& mac
) {
1047 int optlen
= sizeof(struct nd_opt_hdr
) + ifp
->if_addrlen
;
1048 struct nd_opt_hdr
*nd_opt
= (struct nd_opt_hdr
*)(nd_na
+ 1);
1050 /* roundup to 8 bytes alignment! */
1051 optlen
= (optlen
+ 7) & ~7;
1053 m
->m_pkthdr
.len
+= optlen
;
1056 bzero((caddr_t
)nd_opt
, optlen
);
1057 nd_opt
->nd_opt_type
= ND_OPT_TARGET_LINKADDR
;
1058 nd_opt
->nd_opt_len
= optlen
>> 3;
1059 bcopy(mac
, (caddr_t
)(nd_opt
+ 1), ifp
->if_addrlen
);
1061 flags
&= ~ND_NA_FLAG_OVERRIDE
;
1063 ip6
->ip6_plen
= htons((u_short
)icmp6len
);
1064 nd_na
->nd_na_flags_reserved
= flags
;
1065 nd_na
->nd_na_cksum
= 0;
1066 nd_na
->nd_na_cksum
=
1067 in6_cksum(m
, IPPROTO_ICMPV6
, sizeof(struct ip6_hdr
), icmp6len
);
1070 /* Don't lookup socket */
1071 if (ipsec_bypass
== 0)
1072 (void)ipsec_setsocket(m
, NULL
);
1074 ip6_output(m
, NULL
, NULL
, 0, &im6o
, &outif
, 0);
1076 icmp6_ifstat_inc(outif
, ifs6_out_msg
);
1077 icmp6_ifstat_inc(outif
, ifs6_out_neighboradvert
);
1079 icmp6stat
.icp6s_outhist
[ND_NEIGHBOR_ADVERT
]++;
1086 return ((caddr_t
)ifnet_lladdr(ifp
));
1089 TAILQ_HEAD(dadq_head
, dadq
);
1091 TAILQ_ENTRY(dadq
) dad_list
;
1092 struct ifaddr
*dad_ifa
;
1093 int dad_count
; /* max NS to send */
1094 int dad_ns_tcount
; /* # of trials to send NS */
1095 int dad_ns_ocount
; /* NS sent so far */
1100 static struct dadq_head dadq
;
1101 static int dad_init
= 0;
1103 static struct dadq
*
1108 lck_mtx_lock(dad6_mutex
);
1109 for (dp
= dadq
.tqh_first
; dp
; dp
= dp
->dad_list
.tqe_next
) {
1110 if (dp
->dad_ifa
== ifa
) {
1111 lck_mtx_unlock(dad6_mutex
);
1115 lck_mtx_unlock(dad6_mutex
);
1125 untimeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
);
1134 callout_reset(&dp
->dad_timer_ch
, ticks
,
1135 (void (*)(void *))nd6_dad_timer
, (void *)dp
->dad_ifa
);
1143 callout_stop(&dp
->dad_timer_ch
);
1148 * Start Duplicated Address Detection (DAD) for specified interface address.
1153 int *tick_delay
) /* minimum delay ticks for IFF_UP event */
1155 struct in6_ifaddr
*ia
= (struct in6_ifaddr
*)ifa
;
1164 * If we don't need DAD, don't do it.
1165 * There are several cases:
1166 * - DAD is disabled (ip6_dad_count == 0)
1167 * - the interface address is anycast
1169 if (!(ia
->ia6_flags
& IN6_IFF_TENTATIVE
)) {
1171 "nd6_dad_start: called with non-tentative address "
1173 ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1174 ifa
->ifa_ifp
? if_name(ifa
->ifa_ifp
) : "???");
1177 if (ia
->ia6_flags
& IN6_IFF_ANYCAST
) {
1178 ia
->ia6_flags
&= ~IN6_IFF_TENTATIVE
;
1181 if (!ip6_dad_count
) {
1182 ia
->ia6_flags
&= ~IN6_IFF_TENTATIVE
;
1186 panic("nd6_dad_start: ifa->ifa_ifp == NULL");
1187 if (!(ifa
->ifa_ifp
->if_flags
& IFF_UP
))
1189 if (nd6_dad_find(ifa
) != NULL
) {
1190 /* DAD already in progress */
1194 dp
= _MALLOC(sizeof(*dp
), M_IP6NDP
, M_NOWAIT
);
1196 log(LOG_ERR
, "nd6_dad_start: memory allocation failed for "
1198 ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1199 ifa
->ifa_ifp
? if_name(ifa
->ifa_ifp
) : "???");
1202 bzero(dp
, sizeof(*dp
));
1203 lck_mtx_lock(dad6_mutex
);
1204 TAILQ_INSERT_TAIL(&dadq
, (struct dadq
*)dp
, dad_list
);
1205 lck_mtx_unlock(dad6_mutex
);
1207 nd6log((LOG_DEBUG
, "%s: starting DAD for %s\n", if_name(ifa
->ifa_ifp
),
1208 ip6_sprintf(&ia
->ia_addr
.sin6_addr
)));
1211 * Send NS packet for DAD, ip6_dad_count times.
1212 * Note that we must delay the first transmission, if this is the
1213 * first packet to be sent from the interface after interface
1214 * (re)initialization.
1217 ifaref(ifa
); /*just for safety*/
1218 dp
->dad_count
= ip6_dad_count
;
1219 dp
->dad_ns_icount
= dp
->dad_na_icount
= 0;
1220 dp
->dad_ns_ocount
= dp
->dad_ns_tcount
= 0;
1221 if (tick_delay
== NULL
) {
1223 nd6_dad_ns_output(dp
, ifa
);
1224 lck_rw_lock_shared(nd_if_rwlock
);
1225 retrans
= nd_ifinfo
[ifa
->ifa_ifp
->if_index
].retrans
* hz
/ 1000;
1226 lck_rw_done(nd_if_rwlock
);
1227 timeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
, retrans
);
1231 if (*tick_delay
== 0)
1232 ntick
= random() % (MAX_RTR_SOLICITATION_DELAY
* hz
);
1234 ntick
= *tick_delay
+ random() % (hz
/ 2);
1235 *tick_delay
= ntick
;
1236 timeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
,
1242 * terminate DAD unconditionally. used for address removals.
1252 dp
= nd6_dad_find(ifa
);
1254 /* DAD wasn't started yet */
1258 untimeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
);
1260 lck_mtx_lock(dad6_mutex
);
1261 TAILQ_REMOVE(&dadq
, (struct dadq
*)dp
, dad_list
);
1262 lck_mtx_unlock(dad6_mutex
);
1273 struct in6_ifaddr
*ia
= (struct in6_ifaddr
*)ifa
;
1278 log(LOG_ERR
, "nd6_dad_timer: called with null parameter\n");
1281 dp
= nd6_dad_find(ifa
);
1283 log(LOG_ERR
, "nd6_dad_timer: DAD structure not found\n");
1286 if (ia
->ia6_flags
& IN6_IFF_DUPLICATED
) {
1287 log(LOG_ERR
, "nd6_dad_timer: called with duplicated address "
1289 ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1290 ifa
->ifa_ifp
? if_name(ifa
->ifa_ifp
) : "???");
1293 if ((ia
->ia6_flags
& IN6_IFF_TENTATIVE
) == 0) {
1294 log(LOG_ERR
, "nd6_dad_timer: called with non-tentative address "
1296 ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1297 ifa
->ifa_ifp
? if_name(ifa
->ifa_ifp
) : "???");
1301 /* timeouted with IFF_{RUNNING,UP} check */
1302 if (dp
->dad_ns_tcount
> dad_maxtry
) {
1303 nd6log((LOG_INFO
, "%s: could not run DAD, driver problem?\n",
1304 if_name(ifa
->ifa_ifp
)));
1306 lck_mtx_lock(dad6_mutex
);
1307 TAILQ_REMOVE(&dadq
, (struct dadq
*)dp
, dad_list
);
1308 lck_mtx_unlock(dad6_mutex
);
1315 /* Need more checks? */
1316 if (dp
->dad_ns_ocount
< dp
->dad_count
) {
1319 * We have more NS to go. Send NS packet for DAD.
1321 nd6_dad_ns_output(dp
, ifa
);
1322 lck_rw_lock_shared(nd_if_rwlock
);
1323 retrans
= nd_ifinfo
[ifa
->ifa_ifp
->if_index
].retrans
* hz
/ 1000;
1324 lck_rw_done(nd_if_rwlock
);
1325 timeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
, retrans
);
1328 * We have transmitted sufficient number of DAD packets.
1329 * See what we've got.
1335 if (dp
->dad_na_icount
) {
1337 * the check is in nd6_dad_na_input(),
1343 if (dp
->dad_ns_icount
) {
1344 #if 0 /* heuristics */
1347 * - we have sent many(?) DAD NS, and
1348 * - the number of NS we sent equals to the
1349 * number of NS we've got, and
1351 * we may have a faulty network card/driver which
1352 * loops back multicasts to myself.
1354 if (3 < dp
->dad_count
1355 && dp
->dad_ns_icount
== dp
->dad_count
1356 && dp
->dad_na_icount
== 0) {
1357 log(LOG_INFO
, "DAD questionable for %s(%s): "
1358 "network card loops back multicast?\n",
1359 ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1360 if_name(ifa
->ifa_ifp
));
1361 /* XXX consider it a duplicate or not? */
1364 /* We've seen NS, means DAD has failed. */
1368 /* We've seen NS, means DAD has failed. */
1374 /* (*dp) will be freed in nd6_dad_duplicated() */
1376 nd6_dad_duplicated(ifa
);
1379 * We are done with DAD. No NA came, no NS came.
1380 * duplicated address found.
1382 ia
->ia6_flags
&= ~IN6_IFF_TENTATIVE
;
1385 "%s: DAD complete for %s - no duplicates found\n",
1386 if_name(ifa
->ifa_ifp
),
1387 ip6_sprintf(&ia
->ia_addr
.sin6_addr
)));
1389 lck_mtx_lock(dad6_mutex
);
1390 TAILQ_REMOVE(&dadq
, (struct dadq
*)dp
, dad_list
);
1391 lck_mtx_unlock(dad6_mutex
);
1392 in6_post_msg(ia
->ia_ifp
, KEV_INET6_NEW_USER_ADDR
, ia
);
1407 struct in6_ifaddr
*ia
= (struct in6_ifaddr
*)ifa
;
1410 dp
= nd6_dad_find(ifa
);
1412 log(LOG_ERR
, "nd6_dad_duplicated: DAD structure not found\n");
1416 log(LOG_ERR
, "%s: DAD detected duplicate IPv6 address %s: "
1417 "NS in/out=%d/%d, NA in=%d\n",
1418 if_name(ifa
->ifa_ifp
), ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1419 dp
->dad_ns_icount
, dp
->dad_ns_ocount
, dp
->dad_na_icount
);
1421 ia
->ia6_flags
&= ~IN6_IFF_TENTATIVE
;
1422 ia
->ia6_flags
|= IN6_IFF_DUPLICATED
;
1424 /* We are done with DAD, with duplicated address found. (failure) */
1425 untimeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
);
1428 log(LOG_ERR
, "%s: DAD complete for %s - duplicate found\n",
1429 if_name(ifa
->ifa_ifp
), ip6_sprintf(&ia
->ia_addr
.sin6_addr
));
1430 log(LOG_ERR
, "%s: manual intervention required\n",
1431 if_name(ifa
->ifa_ifp
));
1433 lck_mtx_lock(dad6_mutex
);
1434 TAILQ_REMOVE(&dadq
, (struct dadq
*)dp
, dad_list
);
1435 lck_mtx_unlock(dad6_mutex
);
1446 struct in6_ifaddr
*ia
= (struct in6_ifaddr
*)ifa
;
1447 struct ifnet
*ifp
= ifa
->ifa_ifp
;
1449 dp
->dad_ns_tcount
++;
1450 if ((ifp
->if_flags
& IFF_UP
) == 0) {
1452 printf("%s: interface down?\n", if_name(ifp
));
1456 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
1458 printf("%s: interface not running?\n", if_name(ifp
));
1463 dp
->dad_ns_ocount
++;
1464 nd6_ns_output(ifp
, NULL
, &ia
->ia_addr
.sin6_addr
, NULL
, 1, 0);
1471 struct in6_ifaddr
*ia
;
1472 const struct in6_addr
*taddr6
;
1477 panic("ifa == NULL in nd6_dad_ns_input");
1479 ia
= (struct in6_ifaddr
*)ifa
;
1480 taddr6
= &ia
->ia_addr
.sin6_addr
;
1482 dp
= nd6_dad_find(ifa
);
1484 /* Quickhack - completely ignore DAD NS packets */
1485 if (dad_ignore_ns
) {
1487 "nd6_dad_ns_input: ignoring DAD NS packet for "
1488 "address %s(%s)\n", ip6_sprintf(taddr6
),
1489 if_name(ifa
->ifa_ifp
)));
1494 * if I'm yet to start DAD, someone else started using this address
1495 * first. I have a duplicate and you win.
1497 if (!dp
|| dp
->dad_ns_ocount
== 0)
1500 /* XXX more checks for loopback situation - see nd6_dad_timer too */
1503 dp
= NULL
; /* will be freed in nd6_dad_duplicated() */
1504 nd6_dad_duplicated(ifa
);
1507 * not sure if I got a duplicate.
1508 * increment ns count and see what happens.
1511 dp
->dad_ns_icount
++;
1522 panic("ifa == NULL in nd6_dad_na_input");
1524 dp
= nd6_dad_find(ifa
);
1526 dp
->dad_na_icount
++;
1528 /* remove the address. */
1529 nd6_dad_duplicated(ifa
);