2 * Copyright (c) 2008 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
= 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
= timenow
.tv_sec
+ nd6_gctimer
;
757 if ((ln
->ln_router
= is_router
) != 0) {
759 * This means a router's state has changed from
760 * non-reachable to probably reachable, and might
761 * affect the status of associated prefixes..
764 pfxlist_onlink_check(0);
771 * Check if the link-layer address has changed or not.
777 if (bcmp(lladdr
, LLADDR(sdl
), ifp
->if_addrlen
))
786 * This is VERY complex. Look at it with care.
788 * override solicit lladdr llchange action
793 * 0 0 y y (1) REACHABLE->STALE
794 * 0 1 n -- (2c) *->REACHABLE
795 * 0 1 y n (2b) L *->REACHABLE
796 * 0 1 y y (1) REACHABLE->STALE
799 * 1 0 y y (2a) L *->STALE
800 * 1 1 n -- (2a) *->REACHABLE
801 * 1 1 y n (2a) L *->REACHABLE
802 * 1 1 y y (2a) L *->REACHABLE
804 if (!is_override
&& (lladdr
&& llchange
)) { /* (1) */
806 * If state is REACHABLE, make it STALE.
807 * no other updates should be done.
809 if (ln
->ln_state
== ND6_LLINFO_REACHABLE
) {
810 ln
->ln_state
= ND6_LLINFO_STALE
;
811 ln
->ln_expire
= timenow
.tv_sec
+ nd6_gctimer
;
813 RT_REMREF_LOCKED(rt
);
816 } else if (is_override
/* (2a) */
817 || (!is_override
&& (lladdr
&& !llchange
)) /* (2b) */
818 || !lladdr
) { /* (2c) */
820 * Update link-local address, if any.
823 sdl
->sdl_alen
= ifp
->if_addrlen
;
824 bcopy(lladdr
, LLADDR(sdl
), ifp
->if_addrlen
);
828 * If solicited, make the state REACHABLE.
829 * If not solicited and the link-layer address was
830 * changed, make it STALE.
833 ln
->ln_state
= ND6_LLINFO_REACHABLE
;
836 lck_rw_lock_shared(nd_if_rwlock
);
837 ln
->ln_expire
= timenow
.tv_sec
+
838 nd_ifinfo
[ifp
->if_index
].reachable
;
839 lck_rw_done(nd_if_rwlock
);
842 if (lladdr
&& llchange
) {
843 ln
->ln_state
= ND6_LLINFO_STALE
;
844 ln
->ln_expire
= timenow
.tv_sec
+ nd6_gctimer
;
849 if (ln
->ln_router
&& !is_router
) {
851 * The peer dropped the router flag.
852 * Remove the sender from the Default Router List and
853 * update the Destination Cache entries.
855 struct nd_defrouter
*dr
;
856 struct in6_addr
*in6
;
857 struct ifnet
*rt_ifp
= rt
->rt_ifp
;
859 in6
= &((struct sockaddr_in6
*)rt_key(rt
))->sin6_addr
;
862 * Lock to protect the default router list.
863 * XXX: this might be unnecessary, since this function
864 * is only called under the network software interrupt
865 * context. However, we keep it just for safety.
868 lck_mtx_lock(nd6_mutex
);
869 dr
= defrouter_lookup(in6
, rt_ifp
);
871 defrtrlist_del(dr
, 1);
872 lck_mtx_unlock(nd6_mutex
);
875 lck_mtx_unlock(nd6_mutex
);
876 if (!ip6_forwarding
&& (ip6_accept_rtadv
|| (rt_ifp
->if_eflags
& IFEF_ACCEPT_RTADVD
))) {
878 * Even if the neighbor is not in the default
879 * router list, the neighbor may be used
880 * as a next hop for some destinations
881 * (e.g. redirect case). So we must
882 * call rt6_flush explicitly.
884 rt6_flush(&ip6
->ip6_src
, rt_ifp
);
889 ln
->ln_router
= is_router
;
891 RT_LOCK_ASSERT_HELD(rt
);
892 rt
->rt_flags
&= ~RTF_REJECT
;
894 if (ln
->ln_hold
!= NULL
) {
895 struct mbuf
*n
= ln
->ln_hold
;
898 * we assume ifp is not a loopback here, so just set the 2nd
899 * argument as the 1st one.
902 nd6_output(ifp
, ifp
, n
, (struct sockaddr_in6
*)rt_key(rt
),
906 RT_REMREF_LOCKED(rt
);
916 icmp6stat
.icp6s_badna
++;
923 * Neighbor advertisement output handling.
927 * the following items are not implemented yet:
928 * - proxy advertisement delay rule (RFC2461 7.2.8, last paragraph, SHOULD)
929 * - anycast advertisement delay rule (RFC2461 7.2.7, SHOULD)
934 const struct in6_addr
*daddr6
,
935 const struct in6_addr
*taddr6
,
937 int tlladdr
, /* 1 if include target link-layer address */
938 struct sockaddr
*sdl0
) /* sockaddr_dl (= proxy NA) or NULL */
942 struct nd_neighbor_advert
*nd_na
;
943 struct in6_ifaddr
*ia
= NULL
;
944 struct ip6_moptions im6o
;
948 struct ifnet
*outif
= NULL
;
950 /* estimate the size of message */
951 maxlen
= sizeof(*ip6
) + sizeof(*nd_na
);
952 maxlen
+= (sizeof(struct nd_opt_hdr
) + ifp
->if_addrlen
+ 7) & ~7;
953 if (max_linkhdr
+ maxlen
>= MCLBYTES
) {
955 printf("nd6_na_output: max_linkhdr + maxlen >= MCLBYTES "
956 "(%d + %d > %d)\n", max_linkhdr
, maxlen
, MCLBYTES
);
961 MGETHDR(m
, M_DONTWAIT
, MT_DATA
); /* XXXMAC: mac_create_mbuf_linklayer() probably */
962 if (m
&& max_linkhdr
+ maxlen
>= MHLEN
) {
963 MCLGET(m
, M_DONTWAIT
);
964 if ((m
->m_flags
& M_EXT
) == 0) {
971 m
->m_pkthdr
.rcvif
= NULL
;
973 if (IN6_IS_ADDR_MULTICAST(daddr6
)) {
974 m
->m_flags
|= M_MCAST
;
975 im6o
.im6o_multicast_ifp
= ifp
;
976 im6o
.im6o_multicast_hlim
= 255;
977 im6o
.im6o_multicast_loop
= 0;
980 icmp6len
= sizeof(*nd_na
);
981 m
->m_pkthdr
.len
= m
->m_len
= sizeof(struct ip6_hdr
) + icmp6len
;
982 m
->m_data
+= max_linkhdr
; /* or MH_ALIGN() equivalent? */
984 /* fill neighbor advertisement packet */
985 ip6
= mtod(m
, struct ip6_hdr
*);
987 ip6
->ip6_vfc
&= ~IPV6_VERSION_MASK
;
988 ip6
->ip6_vfc
|= IPV6_VERSION
;
989 ip6
->ip6_nxt
= IPPROTO_ICMPV6
;
991 if (IN6_IS_ADDR_UNSPECIFIED(daddr6
)) {
993 ip6
->ip6_dst
.s6_addr16
[0] = IPV6_ADDR_INT16_MLL
;
994 ip6
->ip6_dst
.s6_addr16
[1] = htons(ifp
->if_index
);
995 ip6
->ip6_dst
.s6_addr32
[1] = 0;
996 ip6
->ip6_dst
.s6_addr32
[2] = 0;
997 ip6
->ip6_dst
.s6_addr32
[3] = IPV6_ADDR_INT32_ONE
;
998 flags
&= ~ND_NA_FLAG_SOLICITED
;
1000 ip6
->ip6_dst
= *daddr6
;
1003 * Select a source whose scope is the same as that of the dest.
1005 ia
= in6_ifawithifp(ifp
, &ip6
->ip6_dst
);
1010 ip6
->ip6_src
= ia
->ia_addr
.sin6_addr
;
1011 ifafree(&ia
->ia_ifa
);
1014 nd_na
= (struct nd_neighbor_advert
*)(ip6
+ 1);
1015 nd_na
->nd_na_type
= ND_NEIGHBOR_ADVERT
;
1016 nd_na
->nd_na_code
= 0;
1017 nd_na
->nd_na_target
= *taddr6
;
1018 if (IN6_IS_SCOPE_LINKLOCAL(&nd_na
->nd_na_target
))
1019 nd_na
->nd_na_target
.s6_addr16
[1] = 0;
1022 * "tlladdr" indicates NS's condition for adding tlladdr or not.
1023 * see nd6_ns_input() for details.
1024 * Basically, if NS packet is sent to unicast/anycast addr,
1025 * target lladdr option SHOULD NOT be included.
1029 * sdl0 != NULL indicates proxy NA. If we do proxy, use
1030 * lladdr in sdl0. If we are not proxying (sending NA for
1031 * my address) use lladdr configured for the interface.
1034 mac
= nd6_ifptomac(ifp
);
1035 else if (sdl0
->sa_family
== AF_LINK
) {
1036 struct sockaddr_dl
*sdl
;
1037 sdl
= (struct sockaddr_dl
*)sdl0
;
1038 if (sdl
->sdl_alen
== ifp
->if_addrlen
)
1042 if (tlladdr
&& mac
) {
1043 int optlen
= sizeof(struct nd_opt_hdr
) + ifp
->if_addrlen
;
1044 struct nd_opt_hdr
*nd_opt
= (struct nd_opt_hdr
*)(nd_na
+ 1);
1046 /* roundup to 8 bytes alignment! */
1047 optlen
= (optlen
+ 7) & ~7;
1049 m
->m_pkthdr
.len
+= optlen
;
1052 bzero((caddr_t
)nd_opt
, optlen
);
1053 nd_opt
->nd_opt_type
= ND_OPT_TARGET_LINKADDR
;
1054 nd_opt
->nd_opt_len
= optlen
>> 3;
1055 bcopy(mac
, (caddr_t
)(nd_opt
+ 1), ifp
->if_addrlen
);
1057 flags
&= ~ND_NA_FLAG_OVERRIDE
;
1059 ip6
->ip6_plen
= htons((u_short
)icmp6len
);
1060 nd_na
->nd_na_flags_reserved
= flags
;
1061 nd_na
->nd_na_cksum
= 0;
1062 nd_na
->nd_na_cksum
=
1063 in6_cksum(m
, IPPROTO_ICMPV6
, sizeof(struct ip6_hdr
), icmp6len
);
1066 /* Don't lookup socket */
1067 if (ipsec_bypass
== 0)
1068 (void)ipsec_setsocket(m
, NULL
);
1070 ip6_output(m
, NULL
, NULL
, 0, &im6o
, &outif
, 0);
1072 icmp6_ifstat_inc(outif
, ifs6_out_msg
);
1073 icmp6_ifstat_inc(outif
, ifs6_out_neighboradvert
);
1075 icmp6stat
.icp6s_outhist
[ND_NEIGHBOR_ADVERT
]++;
1082 return ((caddr_t
)ifnet_lladdr(ifp
));
1085 TAILQ_HEAD(dadq_head
, dadq
);
1087 TAILQ_ENTRY(dadq
) dad_list
;
1088 struct ifaddr
*dad_ifa
;
1089 int dad_count
; /* max NS to send */
1090 int dad_ns_tcount
; /* # of trials to send NS */
1091 int dad_ns_ocount
; /* NS sent so far */
1096 static struct dadq_head dadq
;
1097 static int dad_init
= 0;
1099 static struct dadq
*
1104 lck_mtx_lock(dad6_mutex
);
1105 for (dp
= dadq
.tqh_first
; dp
; dp
= dp
->dad_list
.tqe_next
) {
1106 if (dp
->dad_ifa
== ifa
) {
1107 lck_mtx_unlock(dad6_mutex
);
1111 lck_mtx_unlock(dad6_mutex
);
1121 untimeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
);
1130 callout_reset(&dp
->dad_timer_ch
, ticks
,
1131 (void (*)(void *))nd6_dad_timer
, (void *)dp
->dad_ifa
);
1139 callout_stop(&dp
->dad_timer_ch
);
1144 * Start Duplicated Address Detection (DAD) for specified interface address.
1149 int *tick_delay
) /* minimum delay ticks for IFF_UP event */
1151 struct in6_ifaddr
*ia
= (struct in6_ifaddr
*)ifa
;
1160 * If we don't need DAD, don't do it.
1161 * There are several cases:
1162 * - DAD is disabled (ip6_dad_count == 0)
1163 * - the interface address is anycast
1165 if (!(ia
->ia6_flags
& IN6_IFF_TENTATIVE
)) {
1167 "nd6_dad_start: called with non-tentative address "
1169 ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1170 ifa
->ifa_ifp
? if_name(ifa
->ifa_ifp
) : "???");
1173 if (ia
->ia6_flags
& IN6_IFF_ANYCAST
) {
1174 ia
->ia6_flags
&= ~IN6_IFF_TENTATIVE
;
1177 if (!ip6_dad_count
) {
1178 ia
->ia6_flags
&= ~IN6_IFF_TENTATIVE
;
1182 panic("nd6_dad_start: ifa->ifa_ifp == NULL");
1183 if (!(ifa
->ifa_ifp
->if_flags
& IFF_UP
))
1185 if (nd6_dad_find(ifa
) != NULL
) {
1186 /* DAD already in progress */
1190 dp
= _MALLOC(sizeof(*dp
), M_IP6NDP
, M_NOWAIT
);
1192 log(LOG_ERR
, "nd6_dad_start: memory allocation failed for "
1194 ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1195 ifa
->ifa_ifp
? if_name(ifa
->ifa_ifp
) : "???");
1198 bzero(dp
, sizeof(*dp
));
1199 lck_mtx_lock(dad6_mutex
);
1200 TAILQ_INSERT_TAIL(&dadq
, (struct dadq
*)dp
, dad_list
);
1201 lck_mtx_unlock(dad6_mutex
);
1203 nd6log((LOG_DEBUG
, "%s: starting DAD for %s\n", if_name(ifa
->ifa_ifp
),
1204 ip6_sprintf(&ia
->ia_addr
.sin6_addr
)));
1207 * Send NS packet for DAD, ip6_dad_count times.
1208 * Note that we must delay the first transmission, if this is the
1209 * first packet to be sent from the interface after interface
1210 * (re)initialization.
1213 ifaref(ifa
); /*just for safety*/
1214 dp
->dad_count
= ip6_dad_count
;
1215 dp
->dad_ns_icount
= dp
->dad_na_icount
= 0;
1216 dp
->dad_ns_ocount
= dp
->dad_ns_tcount
= 0;
1217 if (tick_delay
== NULL
) {
1219 nd6_dad_ns_output(dp
, ifa
);
1220 lck_rw_lock_shared(nd_if_rwlock
);
1221 retrans
= nd_ifinfo
[ifa
->ifa_ifp
->if_index
].retrans
* hz
/ 1000;
1222 lck_rw_done(nd_if_rwlock
);
1223 timeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
, retrans
);
1227 if (*tick_delay
== 0)
1228 ntick
= random() % (MAX_RTR_SOLICITATION_DELAY
* hz
);
1230 ntick
= *tick_delay
+ random() % (hz
/ 2);
1231 *tick_delay
= ntick
;
1232 timeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
,
1238 * terminate DAD unconditionally. used for address removals.
1248 dp
= nd6_dad_find(ifa
);
1250 /* DAD wasn't started yet */
1254 untimeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
);
1256 lck_mtx_lock(dad6_mutex
);
1257 TAILQ_REMOVE(&dadq
, (struct dadq
*)dp
, dad_list
);
1258 lck_mtx_unlock(dad6_mutex
);
1269 struct in6_ifaddr
*ia
= (struct in6_ifaddr
*)ifa
;
1274 log(LOG_ERR
, "nd6_dad_timer: called with null parameter\n");
1277 dp
= nd6_dad_find(ifa
);
1279 log(LOG_ERR
, "nd6_dad_timer: DAD structure not found\n");
1282 if (ia
->ia6_flags
& IN6_IFF_DUPLICATED
) {
1283 log(LOG_ERR
, "nd6_dad_timer: called with duplicated address "
1285 ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1286 ifa
->ifa_ifp
? if_name(ifa
->ifa_ifp
) : "???");
1289 if ((ia
->ia6_flags
& IN6_IFF_TENTATIVE
) == 0) {
1290 log(LOG_ERR
, "nd6_dad_timer: called with non-tentative address "
1292 ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1293 ifa
->ifa_ifp
? if_name(ifa
->ifa_ifp
) : "???");
1297 /* timeouted with IFF_{RUNNING,UP} check */
1298 if (dp
->dad_ns_tcount
> dad_maxtry
) {
1299 nd6log((LOG_INFO
, "%s: could not run DAD, driver problem?\n",
1300 if_name(ifa
->ifa_ifp
)));
1302 lck_mtx_lock(dad6_mutex
);
1303 TAILQ_REMOVE(&dadq
, (struct dadq
*)dp
, dad_list
);
1304 lck_mtx_unlock(dad6_mutex
);
1311 /* Need more checks? */
1312 if (dp
->dad_ns_ocount
< dp
->dad_count
) {
1315 * We have more NS to go. Send NS packet for DAD.
1317 nd6_dad_ns_output(dp
, ifa
);
1318 lck_rw_lock_shared(nd_if_rwlock
);
1319 retrans
= nd_ifinfo
[ifa
->ifa_ifp
->if_index
].retrans
* hz
/ 1000;
1320 lck_rw_done(nd_if_rwlock
);
1321 timeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
, retrans
);
1324 * We have transmitted sufficient number of DAD packets.
1325 * See what we've got.
1331 if (dp
->dad_na_icount
) {
1333 * the check is in nd6_dad_na_input(),
1339 if (dp
->dad_ns_icount
) {
1340 #if 0 /* heuristics */
1343 * - we have sent many(?) DAD NS, and
1344 * - the number of NS we sent equals to the
1345 * number of NS we've got, and
1347 * we may have a faulty network card/driver which
1348 * loops back multicasts to myself.
1350 if (3 < dp
->dad_count
1351 && dp
->dad_ns_icount
== dp
->dad_count
1352 && dp
->dad_na_icount
== 0) {
1353 log(LOG_INFO
, "DAD questionable for %s(%s): "
1354 "network card loops back multicast?\n",
1355 ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1356 if_name(ifa
->ifa_ifp
));
1357 /* XXX consider it a duplicate or not? */
1360 /* We've seen NS, means DAD has failed. */
1364 /* We've seen NS, means DAD has failed. */
1370 /* (*dp) will be freed in nd6_dad_duplicated() */
1372 nd6_dad_duplicated(ifa
);
1375 * We are done with DAD. No NA came, no NS came.
1376 * duplicated address found.
1378 ia
->ia6_flags
&= ~IN6_IFF_TENTATIVE
;
1381 "%s: DAD complete for %s - no duplicates found\n",
1382 if_name(ifa
->ifa_ifp
),
1383 ip6_sprintf(&ia
->ia_addr
.sin6_addr
)));
1385 lck_mtx_lock(dad6_mutex
);
1386 TAILQ_REMOVE(&dadq
, (struct dadq
*)dp
, dad_list
);
1387 lck_mtx_unlock(dad6_mutex
);
1388 in6_post_msg(ia
->ia_ifp
, KEV_INET6_NEW_USER_ADDR
, ia
);
1403 struct in6_ifaddr
*ia
= (struct in6_ifaddr
*)ifa
;
1406 dp
= nd6_dad_find(ifa
);
1408 log(LOG_ERR
, "nd6_dad_duplicated: DAD structure not found\n");
1412 log(LOG_ERR
, "%s: DAD detected duplicate IPv6 address %s: "
1413 "NS in/out=%d/%d, NA in=%d\n",
1414 if_name(ifa
->ifa_ifp
), ip6_sprintf(&ia
->ia_addr
.sin6_addr
),
1415 dp
->dad_ns_icount
, dp
->dad_ns_ocount
, dp
->dad_na_icount
);
1417 ia
->ia6_flags
&= ~IN6_IFF_TENTATIVE
;
1418 ia
->ia6_flags
|= IN6_IFF_DUPLICATED
;
1420 /* We are done with DAD, with duplicated address found. (failure) */
1421 untimeout((void (*)(void *))nd6_dad_timer
, (void *)ifa
);
1424 log(LOG_ERR
, "%s: DAD complete for %s - duplicate found\n",
1425 if_name(ifa
->ifa_ifp
), ip6_sprintf(&ia
->ia_addr
.sin6_addr
));
1426 log(LOG_ERR
, "%s: manual intervention required\n",
1427 if_name(ifa
->ifa_ifp
));
1429 lck_mtx_lock(dad6_mutex
);
1430 TAILQ_REMOVE(&dadq
, (struct dadq
*)dp
, dad_list
);
1431 lck_mtx_unlock(dad6_mutex
);
1442 struct in6_ifaddr
*ia
= (struct in6_ifaddr
*)ifa
;
1443 struct ifnet
*ifp
= ifa
->ifa_ifp
;
1445 dp
->dad_ns_tcount
++;
1446 if ((ifp
->if_flags
& IFF_UP
) == 0) {
1448 printf("%s: interface down?\n", if_name(ifp
));
1452 if ((ifp
->if_flags
& IFF_RUNNING
) == 0) {
1454 printf("%s: interface not running?\n", if_name(ifp
));
1459 dp
->dad_ns_ocount
++;
1460 nd6_ns_output(ifp
, NULL
, &ia
->ia_addr
.sin6_addr
, NULL
, 1, 0);
1467 struct in6_ifaddr
*ia
;
1468 const struct in6_addr
*taddr6
;
1473 panic("ifa == NULL in nd6_dad_ns_input");
1475 ia
= (struct in6_ifaddr
*)ifa
;
1476 taddr6
= &ia
->ia_addr
.sin6_addr
;
1478 dp
= nd6_dad_find(ifa
);
1480 /* Quickhack - completely ignore DAD NS packets */
1481 if (dad_ignore_ns
) {
1483 "nd6_dad_ns_input: ignoring DAD NS packet for "
1484 "address %s(%s)\n", ip6_sprintf(taddr6
),
1485 if_name(ifa
->ifa_ifp
)));
1490 * if I'm yet to start DAD, someone else started using this address
1491 * first. I have a duplicate and you win.
1493 if (!dp
|| dp
->dad_ns_ocount
== 0)
1496 /* XXX more checks for loopback situation - see nd6_dad_timer too */
1499 dp
= NULL
; /* will be freed in nd6_dad_duplicated() */
1500 nd6_dad_duplicated(ifa
);
1503 * not sure if I got a duplicate.
1504 * increment ns count and see what happens.
1507 dp
->dad_ns_icount
++;
1518 panic("ifa == NULL in nd6_dad_na_input");
1520 dp
= nd6_dad_find(ifa
);
1522 dp
->dad_na_icount
++;
1524 /* remove the address. */
1525 nd6_dad_duplicated(ifa
);