2000-07-04 16:35:15 +00:00
|
|
|
/* $FreeBSD$ */
|
2002-04-19 04:46:24 +00:00
|
|
|
/* $KAME: nd6_nbr.c,v 1.86 2002/01/21 02:33:04 jinmei Exp $ */
|
2000-07-04 16:35:15 +00:00
|
|
|
|
2005-01-07 02:30:35 +00:00
|
|
|
/*-
|
1999-11-22 02:45:11 +00:00
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_inet6.h"
|
2005-02-22 13:04:05 +00:00
|
|
|
#include "opt_ipsec.h"
|
|
|
|
#include "opt_carp.h"
|
1999-12-22 19:13:38 +00:00
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/queue.h>
|
2001-06-11 12:39:29 +00:00
|
|
|
#include <sys/callout.h>
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_dl.h>
|
2005-06-12 00:45:24 +00:00
|
|
|
#include <net/if_var.h>
|
1999-11-22 02:45:11 +00:00
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet6/in6_var.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
#include <netinet/ip6.h>
|
1999-11-22 02:45:11 +00:00
|
|
|
#include <netinet6/ip6_var.h>
|
2005-07-25 12:31:43 +00:00
|
|
|
#include <netinet6/scope6_var.h>
|
1999-11-22 02:45:11 +00:00
|
|
|
#include <netinet6/nd6.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
#include <netinet/icmp6.h>
|
|
|
|
|
2005-02-22 13:04:05 +00:00
|
|
|
#ifdef DEV_CARP
|
|
|
|
#include <netinet/ip_carp.h>
|
|
|
|
#endif
|
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
#include <net/net_osdep.h>
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
#define SDL(s) ((struct sockaddr_dl *)s)
|
1999-11-22 02:45:11 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
struct dadq;
|
|
|
|
static struct dadq *nd6_dad_find __P((struct ifaddr *));
|
2001-06-11 12:39:29 +00:00
|
|
|
static void nd6_dad_starttimer __P((struct dadq *, int));
|
|
|
|
static void nd6_dad_stoptimer __P((struct dadq *));
|
2000-07-04 16:35:15 +00:00
|
|
|
static void nd6_dad_timer __P((struct ifaddr *));
|
|
|
|
static void nd6_dad_ns_output __P((struct dadq *, struct ifaddr *));
|
|
|
|
static void nd6_dad_ns_input __P((struct ifaddr *));
|
|
|
|
static void nd6_dad_na_input __P((struct ifaddr *));
|
1999-11-22 02:45:11 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
static int dad_ignore_ns = 0; /* ignore NS in DAD - specwise incorrect*/
|
|
|
|
static int dad_maxtry = 15; /* max # of *tries* to transmit DAD packet */
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/*
|
2002-12-30 21:18:15 +00:00
|
|
|
* Input a Neighbor Solicitation Message.
|
1999-11-22 02:45:11 +00:00
|
|
|
*
|
|
|
|
* Based on RFC 2461
|
2005-08-12 15:27:25 +00:00
|
|
|
* Based on RFC 2462 (duplicate address detection)
|
1999-11-22 02:45:11 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
nd6_ns_input(m, off, icmp6len)
|
|
|
|
struct mbuf *m;
|
|
|
|
int off, icmp6len;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = m->m_pkthdr.rcvif;
|
|
|
|
struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
|
2000-07-04 16:35:15 +00:00
|
|
|
struct nd_neighbor_solicit *nd_ns;
|
1999-11-22 02:45:11 +00:00
|
|
|
struct in6_addr saddr6 = ip6->ip6_src;
|
|
|
|
struct in6_addr daddr6 = ip6->ip6_dst;
|
2000-07-04 16:35:15 +00:00
|
|
|
struct in6_addr taddr6;
|
1999-11-22 02:45:11 +00:00
|
|
|
struct in6_addr myaddr6;
|
|
|
|
char *lladdr = NULL;
|
2005-02-22 13:04:05 +00:00
|
|
|
struct ifaddr *ifa = NULL;
|
1999-11-22 02:45:11 +00:00
|
|
|
int lladdrlen = 0;
|
|
|
|
int anycast = 0, proxy = 0, tentative = 0;
|
|
|
|
int tlladdr;
|
|
|
|
union nd_opts ndopts;
|
2000-07-04 16:35:15 +00:00
|
|
|
struct sockaddr_dl *proxydl = NULL;
|
1999-11-22 02:45:11 +00:00
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifndef PULLDOWN_TEST
|
|
|
|
IP6_EXTHDR_CHECK(m, off, icmp6len,);
|
|
|
|
nd_ns = (struct nd_neighbor_solicit *)((caddr_t)ip6 + off);
|
|
|
|
#else
|
|
|
|
IP6_EXTHDR_GET(nd_ns, struct nd_neighbor_solicit *, m, off, icmp6len);
|
|
|
|
if (nd_ns == NULL) {
|
|
|
|
icmp6stat.icp6s_tooshort++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ip6 = mtod(m, struct ip6_hdr *); /* adjust pointer for safety */
|
|
|
|
taddr6 = nd_ns->nd_ns_target;
|
2005-07-25 12:31:43 +00:00
|
|
|
if (in6_setscope(&taddr6, ifp, NULL) != 0)
|
|
|
|
goto bad;
|
2001-06-11 12:39:29 +00:00
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
if (ip6->ip6_hlim != 255) {
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_ERR,
|
|
|
|
"nd6_ns_input: invalid hlim (%d) from %s to %s on %s\n",
|
|
|
|
ip6->ip6_hlim, ip6_sprintf(&ip6->ip6_src),
|
|
|
|
ip6_sprintf(&ip6->ip6_dst), if_name(ifp)));
|
|
|
|
goto bad;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&saddr6)) {
|
2005-08-12 15:27:25 +00:00
|
|
|
/* dst has to be a solicited node multicast address. */
|
2003-10-09 16:13:47 +00:00
|
|
|
if (daddr6.s6_addr16[0] == IPV6_ADDR_INT16_MLL &&
|
2002-04-19 04:46:24 +00:00
|
|
|
/* don't check ifindex portion */
|
2003-10-09 16:13:47 +00:00
|
|
|
daddr6.s6_addr32[1] == 0 &&
|
|
|
|
daddr6.s6_addr32[2] == IPV6_ADDR_INT32_ONE &&
|
|
|
|
daddr6.s6_addr8[12] == 0xff) {
|
2002-04-19 04:46:24 +00:00
|
|
|
; /* good */
|
1999-11-22 02:45:11 +00:00
|
|
|
} else {
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_INFO, "nd6_ns_input: bad DAD packet "
|
2003-10-09 16:13:47 +00:00
|
|
|
"(wrong ip6 dst)\n"));
|
1999-11-22 02:45:11 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IN6_IS_ADDR_MULTICAST(&taddr6)) {
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_INFO, "nd6_ns_input: bad NS target (multicast)\n"));
|
1999-11-22 02:45:11 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
icmp6len -= sizeof(*nd_ns);
|
|
|
|
nd6_option_init(nd_ns + 1, icmp6len, &ndopts);
|
|
|
|
if (nd6_options(&ndopts) < 0) {
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_INFO,
|
|
|
|
"nd6_ns_input: invalid ND option, ignored\n"));
|
|
|
|
/* nd6_options have incremented stats */
|
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ndopts.nd_opts_src_lladdr) {
|
2002-04-19 04:46:24 +00:00
|
|
|
lladdr = (char *)(ndopts.nd_opts_src_lladdr + 1);
|
1999-11-22 02:45:11 +00:00
|
|
|
lladdrlen = ndopts.nd_opts_src_lladdr->nd_opt_len << 3;
|
|
|
|
}
|
2003-10-09 16:13:47 +00:00
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src) && lladdr) {
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_INFO, "nd6_ns_input: bad DAD packet "
|
|
|
|
"(link-layer address option)\n"));
|
1999-11-22 02:45:11 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attaching target link-layer address to the NA?
|
|
|
|
* (RFC 2461 7.2.4)
|
|
|
|
*
|
|
|
|
* NS IP dst is unicast/anycast MUST NOT add
|
|
|
|
* NS IP dst is solicited-node multicast MUST add
|
|
|
|
*
|
|
|
|
* In implementation, we add target link-layer address by default.
|
|
|
|
* We do not add one in MUST NOT cases.
|
|
|
|
*/
|
2000-07-04 16:35:15 +00:00
|
|
|
#if 0 /* too much! */
|
|
|
|
ifa = (struct ifaddr *)in6ifa_ifpwithaddr(ifp, &daddr6);
|
|
|
|
if (ifa && (((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_ANYCAST))
|
|
|
|
tlladdr = 0;
|
|
|
|
else
|
|
|
|
#endif
|
1999-11-22 02:45:11 +00:00
|
|
|
if (!IN6_IS_ADDR_MULTICAST(&daddr6))
|
|
|
|
tlladdr = 0;
|
|
|
|
else
|
|
|
|
tlladdr = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Target address (taddr6) must be either:
|
|
|
|
* (1) Valid unicast/anycast address for my receiving interface,
|
|
|
|
* (2) Unicast address for which I'm offering proxy service, or
|
|
|
|
* (3) "tentative" address on which DAD is being performed.
|
|
|
|
*/
|
|
|
|
/* (1) and (3) check. */
|
2005-02-22 13:04:05 +00:00
|
|
|
#ifdef DEV_CARP
|
|
|
|
if (ifp->if_carp)
|
|
|
|
ifa = carp_iamatch6(ifp->if_carp, &taddr6);
|
|
|
|
if (!ifa)
|
|
|
|
ifa = (struct ifaddr *)in6ifa_ifpwithaddr(ifp, &taddr6);
|
|
|
|
#else
|
1999-11-22 02:45:11 +00:00
|
|
|
ifa = (struct ifaddr *)in6ifa_ifpwithaddr(ifp, &taddr6);
|
2005-02-22 13:04:05 +00:00
|
|
|
#endif
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/* (2) check. */
|
2000-07-04 16:35:15 +00:00
|
|
|
if (!ifa) {
|
1999-11-22 02:45:11 +00:00
|
|
|
struct rtentry *rt;
|
|
|
|
struct sockaddr_in6 tsin6;
|
2003-10-30 22:56:13 +00:00
|
|
|
int need_proxy;
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
bzero(&tsin6, sizeof tsin6);
|
|
|
|
tsin6.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
tsin6.sin6_family = AF_INET6;
|
|
|
|
tsin6.sin6_addr = taddr6;
|
|
|
|
|
|
|
|
rt = rtalloc1((struct sockaddr *)&tsin6, 0, 0);
|
2003-10-30 22:56:13 +00:00
|
|
|
need_proxy = (rt && (rt->rt_flags & RTF_ANNOUNCE) != 0 &&
|
|
|
|
rt->rt_gateway->sa_family == AF_LINK);
|
|
|
|
if (rt)
|
|
|
|
rtfree(rt);
|
|
|
|
if (need_proxy) {
|
1999-11-22 02:45:11 +00:00
|
|
|
/*
|
2000-07-04 16:35:15 +00:00
|
|
|
* proxy NDP for single entry
|
1999-11-22 02:45:11 +00:00
|
|
|
*/
|
2000-07-04 16:35:15 +00:00
|
|
|
ifa = (struct ifaddr *)in6ifa_ifpforlinklocal(ifp,
|
|
|
|
IN6_IFF_NOTREADY|IN6_IFF_ANYCAST);
|
|
|
|
if (ifa) {
|
1999-11-22 02:45:11 +00:00
|
|
|
proxy = 1;
|
2000-07-04 16:35:15 +00:00
|
|
|
proxydl = SDL(rt->rt_gateway);
|
|
|
|
}
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!ifa) {
|
|
|
|
/*
|
2001-06-11 12:39:29 +00:00
|
|
|
* We've got an NS packet, and we don't have that adddress
|
1999-11-22 02:45:11 +00:00
|
|
|
* assigned for us. We MUST silently ignore it.
|
|
|
|
* See RFC2461 7.2.3.
|
|
|
|
*/
|
2000-07-04 16:35:15 +00:00
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
myaddr6 = *IFA_IN6(ifa);
|
|
|
|
anycast = ((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_ANYCAST;
|
|
|
|
tentative = ((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_TENTATIVE;
|
|
|
|
if (((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_DUPLICATED)
|
2000-07-04 16:35:15 +00:00
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
if (lladdr && ((ifp->if_addrlen + 2 + 7) & ~7) != lladdrlen) {
|
2003-10-09 16:13:47 +00:00
|
|
|
nd6log((LOG_INFO, "nd6_ns_input: lladdrlen mismatch for %s "
|
1999-11-22 02:45:11 +00:00
|
|
|
"(if %d, NS packet %d)\n",
|
2003-10-09 16:13:47 +00:00
|
|
|
ip6_sprintf(&taddr6),
|
|
|
|
ifp->if_addrlen, lladdrlen - 2));
|
2001-06-11 12:39:29 +00:00
|
|
|
goto bad;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IN6_ARE_ADDR_EQUAL(&myaddr6, &saddr6)) {
|
2003-10-09 16:13:47 +00:00
|
|
|
nd6log((LOG_INFO, "nd6_ns_input: duplicate IP6 address %s\n",
|
|
|
|
ip6_sprintf(&saddr6)));
|
2000-07-04 16:35:15 +00:00
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have neighbor solicitation packet, with target address equals to
|
|
|
|
* one of my tentative address.
|
|
|
|
*
|
|
|
|
* src addr how to process?
|
|
|
|
* --- ---
|
|
|
|
* multicast of course, invalid (rejected in ip6_input)
|
|
|
|
* unicast somebody is doing address resolution -> ignore
|
|
|
|
* unspec dup address detection
|
|
|
|
*
|
|
|
|
* The processing is defined in RFC 2462.
|
|
|
|
*/
|
|
|
|
if (tentative) {
|
|
|
|
/*
|
|
|
|
* If source address is unspecified address, it is for
|
2005-08-12 15:27:25 +00:00
|
|
|
* duplicate address detection.
|
1999-11-22 02:45:11 +00:00
|
|
|
*
|
|
|
|
* If not, the packet is for addess resolution;
|
|
|
|
* silently ignore it.
|
|
|
|
*/
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&saddr6))
|
|
|
|
nd6_dad_ns_input(ifa);
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the source address is unspecified address, entries must not
|
|
|
|
* be created or updated.
|
|
|
|
* It looks that sender is performing DAD. Output NA toward
|
|
|
|
* all-node multicast address, to tell the sender that I'm using
|
|
|
|
* the address.
|
|
|
|
* S bit ("solicited") must be zero.
|
|
|
|
*/
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&saddr6)) {
|
2005-07-25 12:31:43 +00:00
|
|
|
struct in6_addr in6_all;
|
|
|
|
|
|
|
|
in6_all = in6addr_linklocal_allnodes;
|
|
|
|
if (in6_setscope(&in6_all, ifp, NULL) != 0)
|
|
|
|
goto bad;
|
|
|
|
nd6_na_output(ifp, &in6_all, &taddr6,
|
2003-10-09 16:13:47 +00:00
|
|
|
((anycast || proxy || !tlladdr) ? 0 : ND_NA_FLAG_OVERRIDE) |
|
|
|
|
(ip6_forwarding ? ND_NA_FLAG_ROUTER : 0),
|
|
|
|
tlladdr, (struct sockaddr *)proxydl);
|
2000-07-04 16:35:15 +00:00
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
2003-10-09 16:13:47 +00:00
|
|
|
nd6_cache_lladdr(ifp, &saddr6, lladdr, lladdrlen,
|
|
|
|
ND_NEIGHBOR_SOLICIT, 0);
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
nd6_na_output(ifp, &saddr6, &taddr6,
|
2003-10-09 16:13:47 +00:00
|
|
|
((anycast || proxy || !tlladdr) ? 0 : ND_NA_FLAG_OVERRIDE) |
|
|
|
|
(ip6_forwarding ? ND_NA_FLAG_ROUTER : 0) | ND_NA_FLAG_SOLICITED,
|
|
|
|
tlladdr, (struct sockaddr *)proxydl);
|
2000-07-04 16:35:15 +00:00
|
|
|
freeit:
|
|
|
|
m_freem(m);
|
1999-11-22 02:45:11 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_ERR, "nd6_ns_input: src=%s\n", ip6_sprintf(&saddr6)));
|
|
|
|
nd6log((LOG_ERR, "nd6_ns_input: dst=%s\n", ip6_sprintf(&daddr6)));
|
|
|
|
nd6log((LOG_ERR, "nd6_ns_input: tgt=%s\n", ip6_sprintf(&taddr6)));
|
|
|
|
icmp6stat.icp6s_badns++;
|
2000-07-04 16:35:15 +00:00
|
|
|
m_freem(m);
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-12-30 21:18:15 +00:00
|
|
|
* Output a Neighbor Solicitation Message. Caller specifies:
|
1999-11-22 02:45:11 +00:00
|
|
|
* - ICMP6 header source IP6 address
|
|
|
|
* - ND6 header target IP6 address
|
|
|
|
* - ND6 header source datalink address
|
|
|
|
*
|
|
|
|
* Based on RFC 2461
|
2005-08-12 15:27:25 +00:00
|
|
|
* Based on RFC 2462 (duplicate address detection)
|
1999-11-22 02:45:11 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
nd6_ns_output(ifp, daddr6, taddr6, ln, dad)
|
|
|
|
struct ifnet *ifp;
|
2001-06-11 12:39:29 +00:00
|
|
|
const struct in6_addr *daddr6, *taddr6;
|
1999-11-22 02:45:11 +00:00
|
|
|
struct llinfo_nd6 *ln; /* for source address determination */
|
2005-08-12 15:27:25 +00:00
|
|
|
int dad; /* duplicate address detection */
|
1999-11-22 02:45:11 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
struct nd_neighbor_solicit *nd_ns;
|
2005-07-25 12:31:43 +00:00
|
|
|
struct in6_addr *src, src_in;
|
1999-11-22 02:45:11 +00:00
|
|
|
struct ip6_moptions im6o;
|
|
|
|
int icmp6len;
|
2000-07-04 16:35:15 +00:00
|
|
|
int maxlen;
|
1999-11-22 02:45:11 +00:00
|
|
|
caddr_t mac;
|
2005-07-25 12:31:43 +00:00
|
|
|
struct route_in6 ro;
|
|
|
|
|
|
|
|
bzero(&ro, sizeof(ro));
|
2003-10-09 16:13:47 +00:00
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
if (IN6_IS_ADDR_MULTICAST(taddr6))
|
|
|
|
return;
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
/* estimate the size of message */
|
|
|
|
maxlen = sizeof(*ip6) + sizeof(*nd_ns);
|
|
|
|
maxlen += (sizeof(struct nd_opt_hdr) + ifp->if_addrlen + 7) & ~7;
|
|
|
|
if (max_linkhdr + maxlen >= MCLBYTES) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("nd6_ns_output: max_linkhdr + maxlen >= MCLBYTES "
|
|
|
|
"(%d + %d > %d)\n", max_linkhdr, maxlen, MCLBYTES);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
2000-07-04 16:35:15 +00:00
|
|
|
if (m && max_linkhdr + maxlen >= MHLEN) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
2000-07-04 16:35:15 +00:00
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
m_free(m);
|
|
|
|
m = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m == NULL)
|
1999-11-22 02:45:11 +00:00
|
|
|
return;
|
2001-06-11 12:39:29 +00:00
|
|
|
m->m_pkthdr.rcvif = NULL;
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
if (daddr6 == NULL || IN6_IS_ADDR_MULTICAST(daddr6)) {
|
|
|
|
m->m_flags |= M_MCAST;
|
|
|
|
im6o.im6o_multicast_ifp = ifp;
|
|
|
|
im6o.im6o_multicast_hlim = 255;
|
|
|
|
im6o.im6o_multicast_loop = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
icmp6len = sizeof(*nd_ns);
|
|
|
|
m->m_pkthdr.len = m->m_len = sizeof(*ip6) + icmp6len;
|
2002-04-19 04:46:24 +00:00
|
|
|
m->m_data += max_linkhdr; /* or MH_ALIGN() equivalent? */
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/* fill neighbor solicitation packet */
|
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
|
|
|
ip6->ip6_flow = 0;
|
2000-07-04 16:35:15 +00:00
|
|
|
ip6->ip6_vfc &= ~IPV6_VERSION_MASK;
|
|
|
|
ip6->ip6_vfc |= IPV6_VERSION;
|
1999-11-22 02:45:11 +00:00
|
|
|
/* ip6->ip6_plen will be set later */
|
|
|
|
ip6->ip6_nxt = IPPROTO_ICMPV6;
|
|
|
|
ip6->ip6_hlim = 255;
|
|
|
|
if (daddr6)
|
|
|
|
ip6->ip6_dst = *daddr6;
|
|
|
|
else {
|
|
|
|
ip6->ip6_dst.s6_addr16[0] = IPV6_ADDR_INT16_MLL;
|
2005-07-25 12:31:43 +00:00
|
|
|
ip6->ip6_dst.s6_addr16[1] = 0;
|
1999-11-22 02:45:11 +00:00
|
|
|
ip6->ip6_dst.s6_addr32[1] = 0;
|
|
|
|
ip6->ip6_dst.s6_addr32[2] = IPV6_ADDR_INT32_ONE;
|
|
|
|
ip6->ip6_dst.s6_addr32[3] = taddr6->s6_addr32[3];
|
|
|
|
ip6->ip6_dst.s6_addr8[12] = 0xff;
|
2005-07-25 12:31:43 +00:00
|
|
|
if (in6_setscope(&ip6->ip6_dst, ifp, NULL) != 0)
|
|
|
|
goto bad;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
if (!dad) {
|
|
|
|
/*
|
|
|
|
* RFC2461 7.2.2:
|
|
|
|
* "If the source address of the packet prompting the
|
|
|
|
* solicitation is the same as one of the addresses assigned
|
|
|
|
* to the outgoing interface, that address SHOULD be placed
|
|
|
|
* in the IP Source Address of the outgoing solicitation.
|
|
|
|
* Otherwise, any one of the addresses assigned to the
|
|
|
|
* interface should be used."
|
|
|
|
*
|
|
|
|
* We use the source address for the prompting packet
|
|
|
|
* (saddr6), if:
|
|
|
|
* - saddr6 is given from the caller (by giving "ln"), and
|
|
|
|
* - saddr6 belongs to the outgoing interface.
|
2005-07-25 12:31:43 +00:00
|
|
|
* Otherwise, we perform the source address selection as usual.
|
1999-11-22 02:45:11 +00:00
|
|
|
*/
|
2002-04-19 04:46:24 +00:00
|
|
|
struct ip6_hdr *hip6; /* hold ip6 */
|
2005-07-25 12:31:43 +00:00
|
|
|
struct in6_addr *hsrc = NULL;
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
if (ln && ln->ln_hold) {
|
2005-08-12 15:27:25 +00:00
|
|
|
/*
|
|
|
|
* assuming every packet in ln_hold has the same IP
|
|
|
|
* header
|
|
|
|
*/
|
1999-11-22 02:45:11 +00:00
|
|
|
hip6 = mtod(ln->ln_hold, struct ip6_hdr *);
|
|
|
|
/* XXX pullup? */
|
|
|
|
if (sizeof(*hip6) < ln->ln_hold->m_len)
|
2005-07-25 12:31:43 +00:00
|
|
|
hsrc = &hip6->ip6_src;
|
1999-11-22 02:45:11 +00:00
|
|
|
else
|
2005-07-25 12:31:43 +00:00
|
|
|
hsrc = NULL;
|
|
|
|
}
|
|
|
|
if (hsrc && in6ifa_ifpwithaddr(ifp, hsrc))
|
|
|
|
src = hsrc;
|
1999-11-22 02:45:11 +00:00
|
|
|
else {
|
2005-07-25 12:31:43 +00:00
|
|
|
int error;
|
|
|
|
struct sockaddr_in6 dst_sa;
|
|
|
|
|
|
|
|
bzero(&dst_sa, sizeof(dst_sa));
|
|
|
|
dst_sa.sin6_family = AF_INET6;
|
|
|
|
dst_sa.sin6_len = sizeof(dst_sa);
|
|
|
|
dst_sa.sin6_addr = ip6->ip6_dst;
|
|
|
|
|
|
|
|
src = in6_selectsrc(&dst_sa, NULL,
|
|
|
|
NULL, &ro, NULL, NULL, &error);
|
|
|
|
if (src == NULL) {
|
|
|
|
nd6log((LOG_DEBUG,
|
|
|
|
"nd6_ns_output: source can't be "
|
|
|
|
"determined: dst=%s, error=%d\n",
|
|
|
|
ip6_sprintf(&dst_sa.sin6_addr), error));
|
|
|
|
goto bad;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Source address for DAD packet must always be IPv6
|
|
|
|
* unspecified address. (0::0)
|
2005-07-25 12:31:43 +00:00
|
|
|
* We actually don't have to 0-clear the address (we did it
|
|
|
|
* above), but we do so here explicitly to make the intention
|
|
|
|
* clearer.
|
1999-11-22 02:45:11 +00:00
|
|
|
*/
|
2005-07-25 12:31:43 +00:00
|
|
|
bzero(&src_in, sizeof(src_in));
|
|
|
|
src = &src_in;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
2005-07-25 12:31:43 +00:00
|
|
|
ip6->ip6_src = *src;
|
1999-11-22 02:45:11 +00:00
|
|
|
nd_ns = (struct nd_neighbor_solicit *)(ip6 + 1);
|
|
|
|
nd_ns->nd_ns_type = ND_NEIGHBOR_SOLICIT;
|
|
|
|
nd_ns->nd_ns_code = 0;
|
|
|
|
nd_ns->nd_ns_reserved = 0;
|
|
|
|
nd_ns->nd_ns_target = *taddr6;
|
2003-10-21 20:05:32 +00:00
|
|
|
in6_clearscope(&nd_ns->nd_ns_target); /* XXX */
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add source link-layer address option.
|
|
|
|
*
|
|
|
|
* spec implementation
|
|
|
|
* --- ---
|
|
|
|
* DAD packet MUST NOT do not add the option
|
|
|
|
* there's no link layer address:
|
|
|
|
* impossible do not add the option
|
|
|
|
* there's link layer address:
|
|
|
|
* Multicast NS MUST add one add the option
|
|
|
|
* Unicast NS SHOULD add one add the option
|
|
|
|
*/
|
|
|
|
if (!dad && (mac = nd6_ifptomac(ifp))) {
|
|
|
|
int optlen = sizeof(struct nd_opt_hdr) + ifp->if_addrlen;
|
|
|
|
struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)(nd_ns + 1);
|
|
|
|
/* 8 byte alignments... */
|
|
|
|
optlen = (optlen + 7) & ~7;
|
2003-10-09 16:13:47 +00:00
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
m->m_pkthdr.len += optlen;
|
|
|
|
m->m_len += optlen;
|
|
|
|
icmp6len += optlen;
|
|
|
|
bzero((caddr_t)nd_opt, optlen);
|
|
|
|
nd_opt->nd_opt_type = ND_OPT_SOURCE_LINKADDR;
|
|
|
|
nd_opt->nd_opt_len = optlen >> 3;
|
|
|
|
bcopy(mac, (caddr_t)(nd_opt + 1), ifp->if_addrlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
ip6->ip6_plen = htons((u_short)icmp6len);
|
|
|
|
nd_ns->nd_ns_cksum = 0;
|
2003-10-09 16:13:47 +00:00
|
|
|
nd_ns->nd_ns_cksum =
|
|
|
|
in6_cksum(m, IPPROTO_ICMPV6, sizeof(*ip6), icmp6len);
|
1999-11-22 02:45:11 +00:00
|
|
|
|
2005-07-25 12:31:43 +00:00
|
|
|
ip6_output(m, NULL, &ro, dad ? IPV6_DADOUTPUT : 0, &im6o, NULL, NULL);
|
|
|
|
icmp6_ifstat_inc(ifp, ifs6_out_msg);
|
|
|
|
icmp6_ifstat_inc(ifp, ifs6_out_neighborsolicit);
|
1999-11-22 02:45:11 +00:00
|
|
|
icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT]++;
|
2005-07-25 12:31:43 +00:00
|
|
|
|
|
|
|
if (ro.ro_rt) { /* we don't cache this route. */
|
|
|
|
RTFREE(ro.ro_rt);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
if (ro.ro_rt) {
|
|
|
|
RTFREE(ro.ro_rt);
|
|
|
|
}
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Neighbor advertisement input handling.
|
|
|
|
*
|
|
|
|
* Based on RFC 2461
|
2005-08-12 15:27:25 +00:00
|
|
|
* Based on RFC 2462 (duplicate address detection)
|
2000-07-04 16:35:15 +00:00
|
|
|
*
|
|
|
|
* the following items are not implemented yet:
|
|
|
|
* - proxy advertisement delay rule (RFC2461 7.2.8, last paragraph, SHOULD)
|
|
|
|
* - anycast advertisement delay rule (RFC2461 7.2.7, SHOULD)
|
1999-11-22 02:45:11 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
nd6_na_input(m, off, icmp6len)
|
|
|
|
struct mbuf *m;
|
|
|
|
int off, icmp6len;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = m->m_pkthdr.rcvif;
|
|
|
|
struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
|
2000-07-04 16:35:15 +00:00
|
|
|
struct nd_neighbor_advert *nd_na;
|
1999-11-22 02:45:11 +00:00
|
|
|
struct in6_addr daddr6 = ip6->ip6_dst;
|
2000-07-04 16:35:15 +00:00
|
|
|
struct in6_addr taddr6;
|
|
|
|
int flags;
|
|
|
|
int is_router;
|
|
|
|
int is_solicited;
|
|
|
|
int is_override;
|
1999-11-22 02:45:11 +00:00
|
|
|
char *lladdr = NULL;
|
|
|
|
int lladdrlen = 0;
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
struct llinfo_nd6 *ln;
|
|
|
|
struct rtentry *rt;
|
|
|
|
struct sockaddr_dl *sdl;
|
|
|
|
union nd_opts ndopts;
|
|
|
|
|
|
|
|
if (ip6->ip6_hlim != 255) {
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_ERR,
|
|
|
|
"nd6_na_input: invalid hlim (%d) from %s to %s on %s\n",
|
|
|
|
ip6->ip6_hlim, ip6_sprintf(&ip6->ip6_src),
|
|
|
|
ip6_sprintf(&ip6->ip6_dst), if_name(ifp)));
|
|
|
|
goto bad;
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef PULLDOWN_TEST
|
|
|
|
IP6_EXTHDR_CHECK(m, off, icmp6len,);
|
|
|
|
nd_na = (struct nd_neighbor_advert *)((caddr_t)ip6 + off);
|
|
|
|
#else
|
|
|
|
IP6_EXTHDR_GET(nd_na, struct nd_neighbor_advert *, m, off, icmp6len);
|
|
|
|
if (nd_na == NULL) {
|
|
|
|
icmp6stat.icp6s_tooshort++;
|
1999-11-22 02:45:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-07-04 16:35:15 +00:00
|
|
|
#endif
|
2005-07-25 12:31:43 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
flags = nd_na->nd_na_flags_reserved;
|
|
|
|
is_router = ((flags & ND_NA_FLAG_ROUTER) != 0);
|
|
|
|
is_solicited = ((flags & ND_NA_FLAG_SOLICITED) != 0);
|
|
|
|
is_override = ((flags & ND_NA_FLAG_OVERRIDE) != 0);
|
1999-11-22 02:45:11 +00:00
|
|
|
|
2005-07-25 12:31:43 +00:00
|
|
|
taddr6 = nd_na->nd_na_target;
|
|
|
|
if (in6_setscope(&taddr6, ifp, NULL))
|
|
|
|
return; /* XXX: impossible */
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
if (IN6_IS_ADDR_MULTICAST(&taddr6)) {
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_ERR,
|
1999-11-22 02:45:11 +00:00
|
|
|
"nd6_na_input: invalid target address %s\n",
|
2001-06-11 12:39:29 +00:00
|
|
|
ip6_sprintf(&taddr6)));
|
|
|
|
goto bad;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
if (IN6_IS_ADDR_MULTICAST(&daddr6))
|
|
|
|
if (is_solicited) {
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_ERR,
|
|
|
|
"nd6_na_input: a solicited adv is multicasted\n"));
|
|
|
|
goto bad;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
icmp6len -= sizeof(*nd_na);
|
|
|
|
nd6_option_init(nd_na + 1, icmp6len, &ndopts);
|
|
|
|
if (nd6_options(&ndopts) < 0) {
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_INFO,
|
|
|
|
"nd6_na_input: invalid ND option, ignored\n"));
|
|
|
|
/* nd6_options have incremented stats */
|
2000-07-04 16:35:15 +00:00
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ndopts.nd_opts_tgt_lladdr) {
|
|
|
|
lladdr = (char *)(ndopts.nd_opts_tgt_lladdr + 1);
|
|
|
|
lladdrlen = ndopts.nd_opts_tgt_lladdr->nd_opt_len << 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifa = (struct ifaddr *)in6ifa_ifpwithaddr(ifp, &taddr6);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Target address matches one of my interface address.
|
|
|
|
*
|
|
|
|
* If my address is tentative, this means that there's somebody
|
|
|
|
* already using the same address as mine. This indicates DAD failure.
|
|
|
|
* This is defined in RFC 2462.
|
|
|
|
*
|
|
|
|
* Otherwise, process as defined in RFC 2461.
|
|
|
|
*/
|
|
|
|
if (ifa
|
|
|
|
&& (((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_TENTATIVE)) {
|
|
|
|
nd6_dad_na_input(ifa);
|
2000-07-04 16:35:15 +00:00
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
2002-04-19 04:46:24 +00:00
|
|
|
/* Just for safety, maybe unnecessary. */
|
1999-11-22 02:45:11 +00:00
|
|
|
if (ifa) {
|
|
|
|
log(LOG_ERR,
|
|
|
|
"nd6_na_input: duplicate IP6 address %s\n",
|
|
|
|
ip6_sprintf(&taddr6));
|
2000-07-04 16:35:15 +00:00
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lladdr && ((ifp->if_addrlen + 2 + 7) & ~7) != lladdrlen) {
|
2003-10-09 16:13:47 +00:00
|
|
|
nd6log((LOG_INFO, "nd6_na_input: lladdrlen mismatch for %s "
|
|
|
|
"(if %d, NA packet %d)\n", ip6_sprintf(&taddr6),
|
|
|
|
ifp->if_addrlen, lladdrlen - 2));
|
2001-06-11 12:39:29 +00:00
|
|
|
goto bad;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-10-09 16:13:47 +00:00
|
|
|
* If no neighbor cache entry is found, NA SHOULD silently be
|
|
|
|
* discarded.
|
1999-11-22 02:45:11 +00:00
|
|
|
*/
|
|
|
|
rt = nd6_lookup(&taddr6, 0, ifp);
|
|
|
|
if ((rt == NULL) ||
|
|
|
|
((ln = (struct llinfo_nd6 *)rt->rt_llinfo) == NULL) ||
|
|
|
|
((sdl = SDL(rt->rt_gateway)) == NULL))
|
2000-07-04 16:35:15 +00:00
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
if (ln->ln_state == ND6_LLINFO_INCOMPLETE) {
|
|
|
|
/*
|
|
|
|
* If the link-layer has address, and no lladdr option came,
|
|
|
|
* discard the packet.
|
|
|
|
*/
|
|
|
|
if (ifp->if_addrlen && !lladdr)
|
2000-07-04 16:35:15 +00:00
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Record link-layer address, and update the state.
|
|
|
|
*/
|
|
|
|
sdl->sdl_alen = ifp->if_addrlen;
|
|
|
|
bcopy(lladdr, LLADDR(sdl), ifp->if_addrlen);
|
|
|
|
if (is_solicited) {
|
|
|
|
ln->ln_state = ND6_LLINFO_REACHABLE;
|
2000-07-04 16:35:15 +00:00
|
|
|
ln->ln_byhint = 0;
|
2003-10-09 16:13:47 +00:00
|
|
|
if (ln->ln_expire) {
|
1999-11-22 02:45:11 +00:00
|
|
|
ln->ln_expire = time_second +
|
2003-10-17 15:46:31 +00:00
|
|
|
ND_IFINFO(rt->rt_ifp)->reachable;
|
2003-10-09 16:13:47 +00:00
|
|
|
}
|
2001-06-11 12:39:29 +00:00
|
|
|
} else {
|
1999-11-22 02:45:11 +00:00
|
|
|
ln->ln_state = ND6_LLINFO_STALE;
|
2001-06-11 12:39:29 +00:00
|
|
|
ln->ln_expire = time_second + nd6_gctimer;
|
|
|
|
}
|
|
|
|
if ((ln->ln_router = is_router) != 0) {
|
|
|
|
/*
|
|
|
|
* This means a router's state has changed from
|
|
|
|
* non-reachable to probably reachable, and might
|
|
|
|
* affect the status of associated prefixes..
|
|
|
|
*/
|
|
|
|
pfxlist_onlink_check();
|
|
|
|
}
|
1999-11-22 02:45:11 +00:00
|
|
|
} else {
|
|
|
|
int llchange;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the link-layer address has changed or not.
|
|
|
|
*/
|
|
|
|
if (!lladdr)
|
|
|
|
llchange = 0;
|
|
|
|
else {
|
|
|
|
if (sdl->sdl_alen) {
|
|
|
|
if (bcmp(lladdr, LLADDR(sdl), ifp->if_addrlen))
|
|
|
|
llchange = 1;
|
|
|
|
else
|
|
|
|
llchange = 0;
|
|
|
|
} else
|
|
|
|
llchange = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is VERY complex. Look at it with care.
|
|
|
|
*
|
|
|
|
* override solicit lladdr llchange action
|
|
|
|
* (L: record lladdr)
|
|
|
|
*
|
|
|
|
* 0 0 n -- (2c)
|
|
|
|
* 0 0 y n (2b) L
|
|
|
|
* 0 0 y y (1) REACHABLE->STALE
|
|
|
|
* 0 1 n -- (2c) *->REACHABLE
|
|
|
|
* 0 1 y n (2b) L *->REACHABLE
|
|
|
|
* 0 1 y y (1) REACHABLE->STALE
|
|
|
|
* 1 0 n -- (2a)
|
|
|
|
* 1 0 y n (2a) L
|
|
|
|
* 1 0 y y (2a) L *->STALE
|
|
|
|
* 1 1 n -- (2a) *->REACHABLE
|
|
|
|
* 1 1 y n (2a) L *->REACHABLE
|
|
|
|
* 1 1 y y (2a) L *->REACHABLE
|
|
|
|
*/
|
|
|
|
if (!is_override && (lladdr && llchange)) { /* (1) */
|
|
|
|
/*
|
|
|
|
* If state is REACHABLE, make it STALE.
|
|
|
|
* no other updates should be done.
|
|
|
|
*/
|
2001-06-11 12:39:29 +00:00
|
|
|
if (ln->ln_state == ND6_LLINFO_REACHABLE) {
|
1999-11-22 02:45:11 +00:00
|
|
|
ln->ln_state = ND6_LLINFO_STALE;
|
2001-06-11 12:39:29 +00:00
|
|
|
ln->ln_expire = time_second + nd6_gctimer;
|
|
|
|
}
|
2000-07-04 16:35:15 +00:00
|
|
|
goto freeit;
|
1999-11-22 02:45:11 +00:00
|
|
|
} else if (is_override /* (2a) */
|
|
|
|
|| (!is_override && (lladdr && !llchange)) /* (2b) */
|
|
|
|
|| !lladdr) { /* (2c) */
|
|
|
|
/*
|
|
|
|
* Update link-local address, if any.
|
|
|
|
*/
|
|
|
|
if (lladdr) {
|
|
|
|
sdl->sdl_alen = ifp->if_addrlen;
|
|
|
|
bcopy(lladdr, LLADDR(sdl), ifp->if_addrlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If solicited, make the state REACHABLE.
|
|
|
|
* If not solicited and the link-layer address was
|
|
|
|
* changed, make it STALE.
|
|
|
|
*/
|
|
|
|
if (is_solicited) {
|
|
|
|
ln->ln_state = ND6_LLINFO_REACHABLE;
|
2000-07-04 16:35:15 +00:00
|
|
|
ln->ln_byhint = 0;
|
1999-11-22 02:45:11 +00:00
|
|
|
if (ln->ln_expire) {
|
|
|
|
ln->ln_expire = time_second +
|
2003-10-17 15:46:31 +00:00
|
|
|
ND_IFINFO(ifp)->reachable;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
2001-06-11 12:39:29 +00:00
|
|
|
if (lladdr && llchange) {
|
1999-11-22 02:45:11 +00:00
|
|
|
ln->ln_state = ND6_LLINFO_STALE;
|
2001-06-11 12:39:29 +00:00
|
|
|
ln->ln_expire = time_second + nd6_gctimer;
|
|
|
|
}
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ln->ln_router && !is_router) {
|
|
|
|
/*
|
|
|
|
* The peer dropped the router flag.
|
|
|
|
* Remove the sender from the Default Router List and
|
|
|
|
* update the Destination Cache entries.
|
|
|
|
*/
|
|
|
|
struct nd_defrouter *dr;
|
|
|
|
struct in6_addr *in6;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
in6 = &((struct sockaddr_in6 *)rt_key(rt))->sin6_addr;
|
2002-04-19 04:46:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Lock to protect the default router list.
|
|
|
|
* XXX: this might be unnecessary, since this function
|
|
|
|
* is only called under the network software interrupt
|
2003-10-09 16:13:47 +00:00
|
|
|
* context. However, we keep it just for safety.
|
2002-04-19 04:46:24 +00:00
|
|
|
*/
|
1999-11-22 02:45:11 +00:00
|
|
|
s = splnet();
|
2004-04-19 08:02:52 +00:00
|
|
|
dr = defrouter_lookup(in6, ifp);
|
1999-11-22 02:45:11 +00:00
|
|
|
if (dr)
|
|
|
|
defrtrlist_del(dr);
|
|
|
|
else if (!ip6_forwarding && ip6_accept_rtadv) {
|
|
|
|
/*
|
|
|
|
* Even if the neighbor is not in the default
|
|
|
|
* router list, the neighbor may be used
|
|
|
|
* as a next hop for some destinations
|
|
|
|
* (e.g. redirect case). So we must
|
|
|
|
* call rt6_flush explicitly.
|
|
|
|
*/
|
2004-04-19 08:02:52 +00:00
|
|
|
rt6_flush(&ip6->ip6_src, ifp);
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
ln->ln_router = is_router;
|
|
|
|
}
|
|
|
|
rt->rt_flags &= ~RTF_REJECT;
|
|
|
|
ln->ln_asked = 0;
|
|
|
|
if (ln->ln_hold) {
|
2000-07-04 16:35:15 +00:00
|
|
|
/*
|
2002-04-19 04:46:24 +00:00
|
|
|
* we assume ifp is not a loopback here, so just set the 2nd
|
2000-07-04 16:35:15 +00:00
|
|
|
* argument as the 1st one.
|
|
|
|
*/
|
|
|
|
nd6_output(ifp, ifp, ln->ln_hold,
|
1999-11-22 02:45:11 +00:00
|
|
|
(struct sockaddr_in6 *)rt_key(rt), rt);
|
2003-10-09 16:13:47 +00:00
|
|
|
ln->ln_hold = NULL;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
freeit:
|
|
|
|
m_freem(m);
|
2001-06-11 12:39:29 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
icmp6stat.icp6s_badna++;
|
|
|
|
m_freem(m);
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Neighbor advertisement output handling.
|
|
|
|
*
|
|
|
|
* Based on RFC 2461
|
|
|
|
*
|
2000-07-04 16:35:15 +00:00
|
|
|
* the following items are not implemented yet:
|
|
|
|
* - proxy advertisement delay rule (RFC2461 7.2.8, last paragraph, SHOULD)
|
|
|
|
* - anycast advertisement delay rule (RFC2461 7.2.7, SHOULD)
|
1999-11-22 02:45:11 +00:00
|
|
|
*/
|
|
|
|
void
|
2005-07-25 12:31:43 +00:00
|
|
|
nd6_na_output(ifp, daddr6_0, taddr6, flags, tlladdr, sdl0)
|
1999-11-22 02:45:11 +00:00
|
|
|
struct ifnet *ifp;
|
2005-07-25 12:31:43 +00:00
|
|
|
const struct in6_addr *daddr6_0, *taddr6;
|
1999-11-22 02:45:11 +00:00
|
|
|
u_long flags;
|
2000-07-04 16:35:15 +00:00
|
|
|
int tlladdr; /* 1 if include target link-layer address */
|
|
|
|
struct sockaddr *sdl0; /* sockaddr_dl (= proxy NA) or NULL */
|
1999-11-22 02:45:11 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
struct nd_neighbor_advert *nd_na;
|
|
|
|
struct ip6_moptions im6o;
|
2005-07-25 12:31:43 +00:00
|
|
|
struct in6_addr *src, daddr6;
|
|
|
|
struct sockaddr_in6 dst_sa;
|
|
|
|
int icmp6len, maxlen, error;
|
2002-03-19 23:26:37 +00:00
|
|
|
caddr_t mac = NULL;
|
2005-07-25 12:31:43 +00:00
|
|
|
struct route_in6 ro;
|
|
|
|
|
|
|
|
bzero(&ro, sizeof(ro));
|
|
|
|
|
|
|
|
daddr6 = *daddr6_0; /* make a local copy for modification */
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
/* estimate the size of message */
|
|
|
|
maxlen = sizeof(*ip6) + sizeof(*nd_na);
|
|
|
|
maxlen += (sizeof(struct nd_opt_hdr) + ifp->if_addrlen + 7) & ~7;
|
|
|
|
if (max_linkhdr + maxlen >= MCLBYTES) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("nd6_na_output: max_linkhdr + maxlen >= MCLBYTES "
|
|
|
|
"(%d + %d > %d)\n", max_linkhdr, maxlen, MCLBYTES);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
2000-07-04 16:35:15 +00:00
|
|
|
if (m && max_linkhdr + maxlen >= MHLEN) {
|
2003-02-19 05:47:46 +00:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
2000-07-04 16:35:15 +00:00
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
m_free(m);
|
|
|
|
m = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m == NULL)
|
1999-11-22 02:45:11 +00:00
|
|
|
return;
|
2001-06-11 12:39:29 +00:00
|
|
|
m->m_pkthdr.rcvif = NULL;
|
1999-11-22 02:45:11 +00:00
|
|
|
|
2005-07-25 12:31:43 +00:00
|
|
|
if (IN6_IS_ADDR_MULTICAST(&daddr6)) {
|
1999-11-22 02:45:11 +00:00
|
|
|
m->m_flags |= M_MCAST;
|
|
|
|
im6o.im6o_multicast_ifp = ifp;
|
|
|
|
im6o.im6o_multicast_hlim = 255;
|
|
|
|
im6o.im6o_multicast_loop = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
icmp6len = sizeof(*nd_na);
|
|
|
|
m->m_pkthdr.len = m->m_len = sizeof(struct ip6_hdr) + icmp6len;
|
2002-04-19 04:46:24 +00:00
|
|
|
m->m_data += max_linkhdr; /* or MH_ALIGN() equivalent? */
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/* fill neighbor advertisement packet */
|
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
|
|
|
ip6->ip6_flow = 0;
|
2000-07-04 16:35:15 +00:00
|
|
|
ip6->ip6_vfc &= ~IPV6_VERSION_MASK;
|
|
|
|
ip6->ip6_vfc |= IPV6_VERSION;
|
1999-11-22 02:45:11 +00:00
|
|
|
ip6->ip6_nxt = IPPROTO_ICMPV6;
|
|
|
|
ip6->ip6_hlim = 255;
|
2005-07-25 12:31:43 +00:00
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&daddr6)) {
|
1999-11-22 02:45:11 +00:00
|
|
|
/* reply to DAD */
|
|
|
|
ip6->ip6_dst.s6_addr16[0] = IPV6_ADDR_INT16_MLL;
|
2005-07-25 12:31:43 +00:00
|
|
|
ip6->ip6_dst.s6_addr16[1] = 0;
|
1999-11-22 02:45:11 +00:00
|
|
|
ip6->ip6_dst.s6_addr32[1] = 0;
|
|
|
|
ip6->ip6_dst.s6_addr32[2] = 0;
|
|
|
|
ip6->ip6_dst.s6_addr32[3] = IPV6_ADDR_INT32_ONE;
|
2005-07-25 12:31:43 +00:00
|
|
|
if (in6_setscope(&daddr6, ifp, NULL))
|
|
|
|
goto bad;
|
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
flags &= ~ND_NA_FLAG_SOLICITED;
|
2005-07-25 12:31:43 +00:00
|
|
|
}
|
|
|
|
ip6->ip6_dst = daddr6;
|
|
|
|
bzero(&dst_sa, sizeof(struct sockaddr_in6));
|
|
|
|
dst_sa.sin6_family = AF_INET6;
|
|
|
|
dst_sa.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
dst_sa.sin6_addr = daddr6;
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Select a source whose scope is the same as that of the dest.
|
|
|
|
*/
|
2005-07-25 12:31:43 +00:00
|
|
|
bcopy(&dst_sa, &ro.ro_dst, sizeof(dst_sa));
|
|
|
|
src = in6_selectsrc(&dst_sa, NULL, NULL, &ro, NULL, NULL, &error);
|
|
|
|
if (src == NULL) {
|
|
|
|
nd6log((LOG_DEBUG, "nd6_na_output: source can't be "
|
|
|
|
"determined: dst=%s, error=%d\n",
|
|
|
|
ip6_sprintf(&dst_sa.sin6_addr), error));
|
|
|
|
goto bad;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
2005-07-25 12:31:43 +00:00
|
|
|
ip6->ip6_src = *src;
|
1999-11-22 02:45:11 +00:00
|
|
|
nd_na = (struct nd_neighbor_advert *)(ip6 + 1);
|
|
|
|
nd_na->nd_na_type = ND_NEIGHBOR_ADVERT;
|
|
|
|
nd_na->nd_na_code = 0;
|
|
|
|
nd_na->nd_na_target = *taddr6;
|
2003-10-21 20:05:32 +00:00
|
|
|
in6_clearscope(&nd_na->nd_na_target); /* XXX */
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* "tlladdr" indicates NS's condition for adding tlladdr or not.
|
|
|
|
* see nd6_ns_input() for details.
|
|
|
|
* Basically, if NS packet is sent to unicast/anycast addr,
|
|
|
|
* target lladdr option SHOULD NOT be included.
|
|
|
|
*/
|
2000-07-04 16:35:15 +00:00
|
|
|
if (tlladdr) {
|
|
|
|
/*
|
|
|
|
* sdl0 != NULL indicates proxy NA. If we do proxy, use
|
|
|
|
* lladdr in sdl0. If we are not proxying (sending NA for
|
|
|
|
* my address) use lladdr configured for the interface.
|
|
|
|
*/
|
2005-02-22 13:04:05 +00:00
|
|
|
if (sdl0 == NULL) {
|
|
|
|
#ifdef DEV_CARP
|
|
|
|
if (ifp->if_carp)
|
|
|
|
mac = carp_macmatch6(ifp->if_carp, m, taddr6);
|
|
|
|
if (mac == NULL)
|
|
|
|
mac = nd6_ifptomac(ifp);
|
|
|
|
#else
|
2000-07-04 16:35:15 +00:00
|
|
|
mac = nd6_ifptomac(ifp);
|
2005-02-22 13:04:05 +00:00
|
|
|
#endif
|
|
|
|
} else if (sdl0->sa_family == AF_LINK) {
|
2000-07-04 16:35:15 +00:00
|
|
|
struct sockaddr_dl *sdl;
|
|
|
|
sdl = (struct sockaddr_dl *)sdl0;
|
|
|
|
if (sdl->sdl_alen == ifp->if_addrlen)
|
|
|
|
mac = LLADDR(sdl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tlladdr && mac) {
|
1999-11-22 02:45:11 +00:00
|
|
|
int optlen = sizeof(struct nd_opt_hdr) + ifp->if_addrlen;
|
|
|
|
struct nd_opt_hdr *nd_opt = (struct nd_opt_hdr *)(nd_na + 1);
|
2003-10-09 16:13:47 +00:00
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
/* roundup to 8 bytes alignment! */
|
|
|
|
optlen = (optlen + 7) & ~7;
|
|
|
|
|
|
|
|
m->m_pkthdr.len += optlen;
|
|
|
|
m->m_len += optlen;
|
|
|
|
icmp6len += optlen;
|
|
|
|
bzero((caddr_t)nd_opt, optlen);
|
|
|
|
nd_opt->nd_opt_type = ND_OPT_TARGET_LINKADDR;
|
|
|
|
nd_opt->nd_opt_len = optlen >> 3;
|
|
|
|
bcopy(mac, (caddr_t)(nd_opt + 1), ifp->if_addrlen);
|
|
|
|
} else
|
|
|
|
flags &= ~ND_NA_FLAG_OVERRIDE;
|
|
|
|
|
|
|
|
ip6->ip6_plen = htons((u_short)icmp6len);
|
|
|
|
nd_na->nd_na_flags_reserved = flags;
|
|
|
|
nd_na->nd_na_cksum = 0;
|
|
|
|
nd_na->nd_na_cksum =
|
2003-10-09 16:13:47 +00:00
|
|
|
in6_cksum(m, IPPROTO_ICMPV6, sizeof(struct ip6_hdr), icmp6len);
|
1999-11-22 02:45:11 +00:00
|
|
|
|
2005-07-25 12:31:43 +00:00
|
|
|
ip6_output(m, NULL, &ro, 0, &im6o, NULL, NULL);
|
|
|
|
icmp6_ifstat_inc(ifp, ifs6_out_msg);
|
|
|
|
icmp6_ifstat_inc(ifp, ifs6_out_neighboradvert);
|
1999-11-22 02:45:11 +00:00
|
|
|
icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]++;
|
2005-07-25 12:31:43 +00:00
|
|
|
|
|
|
|
if (ro.ro_rt) { /* we don't cache this route. */
|
|
|
|
RTFREE(ro.ro_rt);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
if (ro.ro_rt) {
|
|
|
|
RTFREE(ro.ro_rt);
|
|
|
|
}
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
caddr_t
|
|
|
|
nd6_ifptomac(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
switch (ifp->if_type) {
|
|
|
|
case IFT_ARCNET:
|
|
|
|
case IFT_ETHER:
|
|
|
|
case IFT_FDDI:
|
2001-06-11 12:39:29 +00:00
|
|
|
case IFT_IEEE1394:
|
2001-06-19 14:48:02 +00:00
|
|
|
#ifdef IFT_L2VLAN
|
|
|
|
case IFT_L2VLAN:
|
|
|
|
#endif
|
2001-06-11 12:39:29 +00:00
|
|
|
#ifdef IFT_IEEE80211
|
|
|
|
case IFT_IEEE80211:
|
2005-02-22 13:04:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef IFT_CARP
|
|
|
|
case IFT_CARP:
|
2001-06-11 12:39:29 +00:00
|
|
|
#endif
|
2003-09-14 02:32:31 +00:00
|
|
|
case IFT_ISO88025:
|
2005-06-12 00:45:24 +00:00
|
|
|
return IF_LLADDR(ifp);
|
1999-11-22 02:45:11 +00:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_HEAD(dadq_head, dadq);
|
1999-11-22 02:45:11 +00:00
|
|
|
struct dadq {
|
2000-05-26 02:09:24 +00:00
|
|
|
TAILQ_ENTRY(dadq) dad_list;
|
1999-11-22 02:45:11 +00:00
|
|
|
struct ifaddr *dad_ifa;
|
|
|
|
int dad_count; /* max NS to send */
|
2000-07-04 16:35:15 +00:00
|
|
|
int dad_ns_tcount; /* # of trials to send NS */
|
1999-11-22 02:45:11 +00:00
|
|
|
int dad_ns_ocount; /* NS sent so far */
|
|
|
|
int dad_ns_icount;
|
|
|
|
int dad_na_icount;
|
2001-06-11 12:39:29 +00:00
|
|
|
struct callout dad_timer_ch;
|
1999-11-22 02:45:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct dadq_head dadq;
|
2001-06-11 12:39:29 +00:00
|
|
|
static int dad_init = 0;
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
static struct dadq *
|
|
|
|
nd6_dad_find(ifa)
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
{
|
|
|
|
struct dadq *dp;
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
for (dp = dadq.tqh_first; dp; dp = dp->dad_list.tqe_next) {
|
1999-11-22 02:45:11 +00:00
|
|
|
if (dp->dad_ifa == ifa)
|
|
|
|
return dp;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
static void
|
|
|
|
nd6_dad_starttimer(dp, ticks)
|
|
|
|
struct dadq *dp;
|
|
|
|
int ticks;
|
|
|
|
{
|
|
|
|
|
|
|
|
callout_reset(&dp->dad_timer_ch, ticks,
|
|
|
|
(void (*) __P((void *)))nd6_dad_timer, (void *)dp->dad_ifa);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nd6_dad_stoptimer(dp)
|
|
|
|
struct dadq *dp;
|
|
|
|
{
|
|
|
|
|
|
|
|
callout_stop(&dp->dad_timer_ch);
|
|
|
|
}
|
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
/*
|
2005-08-12 15:27:25 +00:00
|
|
|
* Start Duplicate Address Detection (DAD) for specified interface address.
|
1999-11-22 02:45:11 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
nd6_dad_start(ifa, tick)
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
int *tick; /* minimum delay ticks for IFF_UP event */
|
|
|
|
{
|
|
|
|
struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa;
|
|
|
|
struct dadq *dp;
|
|
|
|
|
|
|
|
if (!dad_init) {
|
|
|
|
TAILQ_INIT(&dadq);
|
|
|
|
dad_init++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we don't need DAD, don't do it.
|
|
|
|
* There are several cases:
|
|
|
|
* - DAD is disabled (ip6_dad_count == 0)
|
|
|
|
* - the interface address is anycast
|
|
|
|
*/
|
|
|
|
if (!(ia->ia6_flags & IN6_IFF_TENTATIVE)) {
|
2000-07-04 16:35:15 +00:00
|
|
|
log(LOG_DEBUG,
|
|
|
|
"nd6_dad_start: called with non-tentative address "
|
1999-11-22 02:45:11 +00:00
|
|
|
"%s(%s)\n",
|
|
|
|
ip6_sprintf(&ia->ia_addr.sin6_addr),
|
|
|
|
ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ia->ia6_flags & IN6_IFF_ANYCAST) {
|
|
|
|
ia->ia6_flags &= ~IN6_IFF_TENTATIVE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!ip6_dad_count) {
|
|
|
|
ia->ia6_flags &= ~IN6_IFF_TENTATIVE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!ifa->ifa_ifp)
|
|
|
|
panic("nd6_dad_start: ifa->ifa_ifp == NULL");
|
2003-10-09 16:13:47 +00:00
|
|
|
if (!(ifa->ifa_ifp->if_flags & IFF_UP)) {
|
1999-11-22 02:45:11 +00:00
|
|
|
return;
|
2003-10-09 16:13:47 +00:00
|
|
|
}
|
1999-11-22 02:45:11 +00:00
|
|
|
if (nd6_dad_find(ifa) != NULL) {
|
|
|
|
/* DAD already in progress */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dp = malloc(sizeof(*dp), M_IP6NDP, M_NOWAIT);
|
|
|
|
if (dp == NULL) {
|
2000-07-04 16:35:15 +00:00
|
|
|
log(LOG_ERR, "nd6_dad_start: memory allocation failed for "
|
1999-11-22 02:45:11 +00:00
|
|
|
"%s(%s)\n",
|
|
|
|
ip6_sprintf(&ia->ia_addr.sin6_addr),
|
|
|
|
ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bzero(dp, sizeof(*dp));
|
2001-06-11 12:39:29 +00:00
|
|
|
callout_init(&dp->dad_timer_ch, 0);
|
1999-11-22 02:45:11 +00:00
|
|
|
TAILQ_INSERT_TAIL(&dadq, (struct dadq *)dp, dad_list);
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_DEBUG, "%s: starting DAD for %s\n", if_name(ifa->ifa_ifp),
|
|
|
|
ip6_sprintf(&ia->ia_addr.sin6_addr)));
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send NS packet for DAD, ip6_dad_count times.
|
|
|
|
* Note that we must delay the first transmission, if this is the
|
|
|
|
* first packet to be sent from the interface after interface
|
|
|
|
* (re)initialization.
|
|
|
|
*/
|
|
|
|
dp->dad_ifa = ifa;
|
2002-04-19 04:46:24 +00:00
|
|
|
IFAREF(ifa); /* just for safety */
|
1999-11-22 02:45:11 +00:00
|
|
|
dp->dad_count = ip6_dad_count;
|
|
|
|
dp->dad_ns_icount = dp->dad_na_icount = 0;
|
2000-07-04 16:35:15 +00:00
|
|
|
dp->dad_ns_ocount = dp->dad_ns_tcount = 0;
|
2002-04-19 04:46:24 +00:00
|
|
|
if (tick == NULL) {
|
2000-07-04 16:35:15 +00:00
|
|
|
nd6_dad_ns_output(dp, ifa);
|
2003-10-17 15:46:31 +00:00
|
|
|
nd6_dad_starttimer(dp,
|
|
|
|
ND_IFINFO(ifa->ifa_ifp)->retrans * hz / 1000);
|
1999-11-22 02:45:11 +00:00
|
|
|
} else {
|
|
|
|
int ntick;
|
|
|
|
|
|
|
|
if (*tick == 0)
|
2003-10-31 16:06:05 +00:00
|
|
|
ntick = arc4random() % (MAX_RTR_SOLICITATION_DELAY * hz);
|
1999-11-22 02:45:11 +00:00
|
|
|
else
|
2003-10-31 16:06:05 +00:00
|
|
|
ntick = *tick + arc4random() % (hz / 2);
|
1999-11-22 02:45:11 +00:00
|
|
|
*tick = ntick;
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6_dad_starttimer(dp, ntick);
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
/*
|
|
|
|
* terminate DAD unconditionally. used for address removals.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nd6_dad_stop(ifa)
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
{
|
|
|
|
struct dadq *dp;
|
|
|
|
|
|
|
|
if (!dad_init)
|
|
|
|
return;
|
|
|
|
dp = nd6_dad_find(ifa);
|
|
|
|
if (!dp) {
|
|
|
|
/* DAD wasn't started yet */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nd6_dad_stoptimer(dp);
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&dadq, (struct dadq *)dp, dad_list);
|
|
|
|
free(dp, M_IP6NDP);
|
|
|
|
dp = NULL;
|
|
|
|
IFAFREE(ifa);
|
|
|
|
}
|
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
static void
|
|
|
|
nd6_dad_timer(ifa)
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa;
|
|
|
|
struct dadq *dp;
|
|
|
|
|
2002-04-19 04:46:24 +00:00
|
|
|
s = splnet(); /* XXX */
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (ia == NULL) {
|
2000-07-04 16:35:15 +00:00
|
|
|
log(LOG_ERR, "nd6_dad_timer: called with null parameter\n");
|
1999-11-22 02:45:11 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
dp = nd6_dad_find(ifa);
|
|
|
|
if (dp == NULL) {
|
2000-07-04 16:35:15 +00:00
|
|
|
log(LOG_ERR, "nd6_dad_timer: DAD structure not found\n");
|
1999-11-22 02:45:11 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (ia->ia6_flags & IN6_IFF_DUPLICATED) {
|
2000-07-04 16:35:15 +00:00
|
|
|
log(LOG_ERR, "nd6_dad_timer: called with duplicated address "
|
1999-11-22 02:45:11 +00:00
|
|
|
"%s(%s)\n",
|
|
|
|
ip6_sprintf(&ia->ia_addr.sin6_addr),
|
|
|
|
ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if ((ia->ia6_flags & IN6_IFF_TENTATIVE) == 0) {
|
2000-07-04 16:35:15 +00:00
|
|
|
log(LOG_ERR, "nd6_dad_timer: called with non-tentative address "
|
1999-11-22 02:45:11 +00:00
|
|
|
"%s(%s)\n",
|
|
|
|
ip6_sprintf(&ia->ia_addr.sin6_addr),
|
|
|
|
ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
/* timeouted with IFF_{RUNNING,UP} check */
|
|
|
|
if (dp->dad_ns_tcount > dad_maxtry) {
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_INFO, "%s: could not run DAD, driver problem?\n",
|
2003-10-09 16:13:47 +00:00
|
|
|
if_name(ifa->ifa_ifp)));
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
TAILQ_REMOVE(&dadq, (struct dadq *)dp, dad_list);
|
|
|
|
free(dp, M_IP6NDP);
|
|
|
|
dp = NULL;
|
|
|
|
IFAFREE(ifa);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1999-11-22 02:45:11 +00:00
|
|
|
/* Need more checks? */
|
|
|
|
if (dp->dad_ns_ocount < dp->dad_count) {
|
|
|
|
/*
|
|
|
|
* We have more NS to go. Send NS packet for DAD.
|
|
|
|
*/
|
2000-07-04 16:35:15 +00:00
|
|
|
nd6_dad_ns_output(dp, ifa);
|
2003-10-09 16:13:47 +00:00
|
|
|
nd6_dad_starttimer(dp,
|
2003-10-17 15:46:31 +00:00
|
|
|
ND_IFINFO(ifa->ifa_ifp)->retrans * hz / 1000);
|
1999-11-22 02:45:11 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We have transmitted sufficient number of DAD packets.
|
|
|
|
* See what we've got.
|
|
|
|
*/
|
|
|
|
int duplicate;
|
|
|
|
|
|
|
|
duplicate = 0;
|
|
|
|
|
|
|
|
if (dp->dad_na_icount) {
|
|
|
|
/*
|
|
|
|
* the check is in nd6_dad_na_input(),
|
|
|
|
* but just in case
|
|
|
|
*/
|
|
|
|
duplicate++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dp->dad_ns_icount) {
|
|
|
|
/* We've seen NS, means DAD has failed. */
|
|
|
|
duplicate++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (duplicate) {
|
|
|
|
/* (*dp) will be freed in nd6_dad_duplicated() */
|
|
|
|
dp = NULL;
|
|
|
|
nd6_dad_duplicated(ifa);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We are done with DAD. No NA came, no NS came.
|
2005-08-12 15:27:25 +00:00
|
|
|
* No duplicate address found.
|
1999-11-22 02:45:11 +00:00
|
|
|
*/
|
|
|
|
ia->ia6_flags &= ~IN6_IFF_TENTATIVE;
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_DEBUG,
|
2000-07-04 16:35:15 +00:00
|
|
|
"%s: DAD complete for %s - no duplicates found\n",
|
|
|
|
if_name(ifa->ifa_ifp),
|
2001-06-11 12:39:29 +00:00
|
|
|
ip6_sprintf(&ia->ia_addr.sin6_addr)));
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
TAILQ_REMOVE(&dadq, (struct dadq *)dp, dad_list);
|
|
|
|
free(dp, M_IP6NDP);
|
|
|
|
dp = NULL;
|
2000-07-04 16:35:15 +00:00
|
|
|
IFAFREE(ifa);
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nd6_dad_duplicated(ifa)
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
{
|
|
|
|
struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa;
|
|
|
|
struct dadq *dp;
|
|
|
|
|
|
|
|
dp = nd6_dad_find(ifa);
|
|
|
|
if (dp == NULL) {
|
2000-07-04 16:35:15 +00:00
|
|
|
log(LOG_ERR, "nd6_dad_duplicated: DAD structure not found\n");
|
1999-11-22 02:45:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-06-11 12:39:29 +00:00
|
|
|
log(LOG_ERR, "%s: DAD detected duplicate IPv6 address %s: "
|
|
|
|
"NS in/out=%d/%d, NA in=%d\n",
|
|
|
|
if_name(ifa->ifa_ifp), ip6_sprintf(&ia->ia_addr.sin6_addr),
|
|
|
|
dp->dad_ns_icount, dp->dad_ns_ocount, dp->dad_na_icount);
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
ia->ia6_flags &= ~IN6_IFF_TENTATIVE;
|
|
|
|
ia->ia6_flags |= IN6_IFF_DUPLICATED;
|
|
|
|
|
2005-08-12 15:27:25 +00:00
|
|
|
/* We are done with DAD, with duplicate address found. (failure) */
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6_dad_stoptimer(dp);
|
1999-11-22 02:45:11 +00:00
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
log(LOG_ERR, "%s: DAD complete for %s - duplicate found\n",
|
1999-11-22 02:45:11 +00:00
|
|
|
if_name(ifa->ifa_ifp), ip6_sprintf(&ia->ia_addr.sin6_addr));
|
2000-07-04 16:35:15 +00:00
|
|
|
log(LOG_ERR, "%s: manual intervention required\n",
|
|
|
|
if_name(ifa->ifa_ifp));
|
1999-11-22 02:45:11 +00:00
|
|
|
|
|
|
|
TAILQ_REMOVE(&dadq, (struct dadq *)dp, dad_list);
|
|
|
|
free(dp, M_IP6NDP);
|
|
|
|
dp = NULL;
|
2000-07-04 16:35:15 +00:00
|
|
|
IFAFREE(ifa);
|
1999-11-22 02:45:11 +00:00
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
static void
|
|
|
|
nd6_dad_ns_output(dp, ifa)
|
|
|
|
struct dadq *dp;
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
{
|
|
|
|
struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa;
|
|
|
|
struct ifnet *ifp = ifa->ifa_ifp;
|
|
|
|
|
|
|
|
dp->dad_ns_tcount++;
|
|
|
|
if ((ifp->if_flags & IFF_UP) == 0) {
|
|
|
|
#if 0
|
|
|
|
printf("%s: interface down?\n", if_name(ifp));
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2005-08-09 10:20:02 +00:00
|
|
|
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
|
2000-07-04 16:35:15 +00:00
|
|
|
#if 0
|
|
|
|
printf("%s: interface not running?\n", if_name(ifp));
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dp->dad_ns_ocount++;
|
|
|
|
nd6_ns_output(ifp, NULL, &ia->ia_addr.sin6_addr, NULL, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-11-22 02:45:11 +00:00
|
|
|
nd6_dad_ns_input(ifa)
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
{
|
|
|
|
struct in6_ifaddr *ia;
|
|
|
|
struct ifnet *ifp;
|
2001-06-11 12:39:29 +00:00
|
|
|
const struct in6_addr *taddr6;
|
1999-11-22 02:45:11 +00:00
|
|
|
struct dadq *dp;
|
|
|
|
int duplicate;
|
|
|
|
|
|
|
|
if (!ifa)
|
|
|
|
panic("ifa == NULL in nd6_dad_ns_input");
|
|
|
|
|
|
|
|
ia = (struct in6_ifaddr *)ifa;
|
|
|
|
ifp = ifa->ifa_ifp;
|
|
|
|
taddr6 = &ia->ia_addr.sin6_addr;
|
|
|
|
duplicate = 0;
|
|
|
|
dp = nd6_dad_find(ifa);
|
|
|
|
|
|
|
|
/* Quickhack - completely ignore DAD NS packets */
|
|
|
|
if (dad_ignore_ns) {
|
2001-06-11 12:39:29 +00:00
|
|
|
nd6log((LOG_INFO,
|
|
|
|
"nd6_dad_ns_input: ignoring DAD NS packet for "
|
1999-11-22 02:45:11 +00:00
|
|
|
"address %s(%s)\n", ip6_sprintf(taddr6),
|
2001-06-11 12:39:29 +00:00
|
|
|
if_name(ifa->ifa_ifp)));
|
1999-11-22 02:45:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if I'm yet to start DAD, someone else started using this address
|
|
|
|
* first. I have a duplicate and you win.
|
|
|
|
*/
|
|
|
|
if (!dp || dp->dad_ns_ocount == 0)
|
|
|
|
duplicate++;
|
|
|
|
|
|
|
|
/* XXX more checks for loopback situation - see nd6_dad_timer too */
|
|
|
|
|
|
|
|
if (duplicate) {
|
|
|
|
dp = NULL; /* will be freed in nd6_dad_duplicated() */
|
|
|
|
nd6_dad_duplicated(ifa);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* not sure if I got a duplicate.
|
|
|
|
* increment ns count and see what happens.
|
|
|
|
*/
|
|
|
|
if (dp)
|
|
|
|
dp->dad_ns_icount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
static void
|
1999-11-22 02:45:11 +00:00
|
|
|
nd6_dad_na_input(ifa)
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
{
|
|
|
|
struct dadq *dp;
|
|
|
|
|
|
|
|
if (!ifa)
|
|
|
|
panic("ifa == NULL in nd6_dad_na_input");
|
|
|
|
|
|
|
|
dp = nd6_dad_find(ifa);
|
|
|
|
if (dp)
|
|
|
|
dp->dad_na_icount++;
|
|
|
|
|
|
|
|
/* remove the address. */
|
|
|
|
nd6_dad_duplicated(ifa);
|
|
|
|
}
|