2000-11-05 20:17:12 +03:00
|
|
|
/* $NetBSD: in6_ifattach.c,v 1.32 2000/11/05 17:17:16 onoe Exp $ */
|
2000-10-01 14:56:02 +04:00
|
|
|
/* $KAME: in6_ifattach.c,v 1.67 2000/10/01 10:51:54 itojun Exp $ */
|
1999-07-04 01:24:45 +04:00
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
2000-04-10 19:45:24 +04:00
|
|
|
*
|
1999-06-28 10:36:47 +04:00
|
|
|
* 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.
|
2000-04-10 19:45:24 +04:00
|
|
|
*
|
1999-06-28 10:36:47 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
1999-12-13 18:17:17 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/md5.h>
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
|
2000-02-06 15:49:37 +03:00
|
|
|
#include <netinet/ip6.h>
|
1999-06-28 10:36:47 +04:00
|
|
|
#include <netinet6/ip6_var.h>
|
|
|
|
#include <netinet6/in6_ifattach.h>
|
|
|
|
#include <netinet6/ip6_var.h>
|
|
|
|
#include <netinet6/nd6.h>
|
|
|
|
|
1999-12-13 18:17:17 +03:00
|
|
|
#include <net/net_osdep.h>
|
|
|
|
|
|
|
|
struct in6_ifstat **in6_ifstat = NULL;
|
|
|
|
struct icmp6_ifstat **icmp6_ifstat = NULL;
|
|
|
|
size_t in6_ifstatmax = 0;
|
|
|
|
size_t icmp6_ifstatmax = 0;
|
1999-06-28 10:36:47 +04:00
|
|
|
unsigned long in6_maxmtu = 0;
|
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
static int get_rand_ifid __P((struct ifnet *, struct in6_addr *));
|
|
|
|
static int get_hw_ifid __P((struct ifnet *, struct in6_addr *));
|
|
|
|
static int get_ifid __P((struct ifnet *, struct ifnet *, struct in6_addr *));
|
|
|
|
static int in6_ifattach_addaddr __P((struct ifnet *, struct in6_ifaddr *));
|
|
|
|
static int in6_ifattach_linklocal __P((struct ifnet *, struct ifnet *));
|
|
|
|
static int in6_ifattach_loopback __P((struct ifnet *));
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
#define EUI64_GBIT 0x01
|
|
|
|
#define EUI64_UBIT 0x02
|
|
|
|
#define EUI64_TO_IFID(in6) do {(in6)->s6_addr[8] ^= EUI64_UBIT; } while (0)
|
|
|
|
#define EUI64_GROUP(in6) ((in6)->s6_addr[8] & EUI64_GBIT)
|
|
|
|
#define EUI64_INDIVIDUAL(in6) (!EUI64_GROUP(in6))
|
|
|
|
#define EUI64_LOCAL(in6) ((in6)->s6_addr[8] & EUI64_UBIT)
|
|
|
|
#define EUI64_UNIVERSAL(in6) (!EUI64_LOCAL(in6))
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
#define IFID_LOCAL(in6) (!EUI64_LOCAL(in6))
|
|
|
|
#define IFID_UNIVERSAL(in6) (!EUI64_UNIVERSAL(in6))
|
1999-06-28 10:36:47 +04:00
|
|
|
|
1999-12-13 18:17:17 +03:00
|
|
|
/*
|
|
|
|
* Generate a last-resort interface identifier, when the machine has no
|
|
|
|
* IEEE802/EUI64 address sources.
|
2000-04-12 14:36:38 +04:00
|
|
|
* The goal here is to get an interface identifier that is
|
|
|
|
* (1) random enough and (2) does not change across reboot.
|
|
|
|
* We currently use MD5(hostname) for it.
|
1999-12-13 18:17:17 +03:00
|
|
|
*/
|
|
|
|
static int
|
2000-04-12 14:36:38 +04:00
|
|
|
get_rand_ifid(ifp, in6)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct in6_addr *in6; /*upper 64bits are preserved */
|
1999-12-13 18:17:17 +03:00
|
|
|
{
|
|
|
|
MD5_CTX ctxt;
|
|
|
|
u_int8_t digest[16];
|
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
#if 0
|
|
|
|
/* we need at least several letters as seed for ifid */
|
|
|
|
if (hostnamelen < 3)
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* generate 8 bytes of pseudo-random value. */
|
1999-12-13 18:17:17 +03:00
|
|
|
bzero(&ctxt, sizeof(ctxt));
|
|
|
|
MD5Init(&ctxt);
|
|
|
|
MD5Update(&ctxt, hostname, hostnamelen);
|
|
|
|
MD5Final(digest, &ctxt);
|
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
/* assumes sizeof(digest) > sizeof(ifid) */
|
|
|
|
bcopy(digest, &in6->s6_addr[8], 8);
|
1999-12-13 18:17:17 +03:00
|
|
|
|
|
|
|
/* make sure to set "u" bit to local, and "g" bit to individual. */
|
2000-04-12 14:36:38 +04:00
|
|
|
in6->s6_addr[8] &= ~EUI64_GBIT; /* g bit to "individual" */
|
|
|
|
in6->s6_addr[8] |= EUI64_UBIT; /* u bit to "local" */
|
|
|
|
|
|
|
|
/* convert EUI64 into IPv6 interface identifier */
|
|
|
|
EUI64_TO_IFID(in6);
|
1999-12-13 18:17:17 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
2000-04-12 14:36:38 +04:00
|
|
|
* Get interface identifier for the specified interface.
|
|
|
|
* XXX assumes single sockaddr_dl (AF_LINK address) per an interface
|
1999-06-28 10:36:47 +04:00
|
|
|
*/
|
2000-04-12 14:36:38 +04:00
|
|
|
static int
|
|
|
|
get_hw_ifid(ifp, in6)
|
1999-06-28 10:36:47 +04:00
|
|
|
struct ifnet *ifp;
|
2000-04-12 14:36:38 +04:00
|
|
|
struct in6_addr *in6; /*upper 64bits are preserved */
|
|
|
|
{
|
1999-06-28 10:36:47 +04:00
|
|
|
struct ifaddr *ifa;
|
|
|
|
struct sockaddr_dl *sdl;
|
2000-04-12 14:36:38 +04:00
|
|
|
u_int8_t *addr;
|
|
|
|
size_t addrlen;
|
|
|
|
static u_int8_t allzero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
|
static u_int8_t allone[8] =
|
|
|
|
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
|
|
|
|
|
|
|
for (ifa = ifp->if_addrlist.tqh_first;
|
|
|
|
ifa;
|
|
|
|
ifa = ifa->ifa_list.tqe_next)
|
|
|
|
{
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
|
|
|
sdl = (struct sockaddr_dl *)ifa->ifa_addr;
|
|
|
|
if (sdl == NULL)
|
|
|
|
continue;
|
|
|
|
if (sdl->sdl_alen == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
found:
|
|
|
|
addr = LLADDR(sdl);
|
|
|
|
addrlen = sdl->sdl_alen;
|
|
|
|
|
|
|
|
/* get EUI64 */
|
|
|
|
switch (ifp->if_type) {
|
|
|
|
case IFT_ETHER:
|
|
|
|
case IFT_FDDI:
|
|
|
|
case IFT_ATM:
|
2000-11-05 20:17:12 +03:00
|
|
|
case IFT_IEEE1394:
|
2000-04-12 14:36:38 +04:00
|
|
|
/* IEEE802/EUI64 cases - what others? */
|
2000-11-05 20:17:12 +03:00
|
|
|
/* IEEE1394 uses 16byte length address starting with EUI64 */
|
|
|
|
if (addrlen > 8)
|
|
|
|
addrlen = 8;
|
2000-04-12 14:36:38 +04:00
|
|
|
|
|
|
|
/* look at IEEE802/EUI64 only */
|
|
|
|
if (addrlen != 8 && addrlen != 6)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check for invalid MAC address - on bsdi, we see it a lot
|
|
|
|
* since wildboar configures all-zero MAC on pccard before
|
|
|
|
* card insertion.
|
|
|
|
*/
|
|
|
|
if (bcmp(addr, allzero, addrlen) == 0)
|
|
|
|
return -1;
|
|
|
|
if (bcmp(addr, allone, addrlen) == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* make EUI64 address */
|
|
|
|
if (addrlen == 8)
|
|
|
|
bcopy(addr, &in6->s6_addr[8], 8);
|
|
|
|
else if (addrlen == 6) {
|
|
|
|
in6->s6_addr[8] = addr[0];
|
|
|
|
in6->s6_addr[9] = addr[1];
|
|
|
|
in6->s6_addr[10] = addr[2];
|
|
|
|
in6->s6_addr[11] = 0xff;
|
2000-04-13 20:21:25 +04:00
|
|
|
in6->s6_addr[12] = 0xfe;
|
2000-04-12 14:36:38 +04:00
|
|
|
in6->s6_addr[13] = addr[3];
|
|
|
|
in6->s6_addr[14] = addr[4];
|
|
|
|
in6->s6_addr[15] = addr[5];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IFT_ARCNET:
|
|
|
|
if (addrlen != 1)
|
|
|
|
return -1;
|
|
|
|
if (!addr[0])
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
bzero(&in6->s6_addr[8], 8);
|
|
|
|
in6->s6_addr[15] = addr[0];
|
|
|
|
|
2000-04-16 19:00:56 +04:00
|
|
|
/*
|
|
|
|
* due to insufficient bitwidth, we mark it local.
|
|
|
|
*/
|
2000-04-12 14:36:38 +04:00
|
|
|
in6->s6_addr[8] &= ~EUI64_GBIT; /* g bit to "individual" */
|
|
|
|
in6->s6_addr[8] |= EUI64_UBIT; /* u bit to "local" */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IFT_GIF:
|
|
|
|
#ifdef IFT_STF
|
|
|
|
case IFT_STF:
|
|
|
|
#endif
|
|
|
|
/*
|
2000-04-16 19:00:56 +04:00
|
|
|
* mech-06 says: "SHOULD use IPv4 address as ifid source".
|
|
|
|
* however, IPv4 address is not very suitable as unique
|
|
|
|
* identifier source (can be renumbered).
|
|
|
|
* we don't do this.
|
2000-04-12 14:36:38 +04:00
|
|
|
*/
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sanity check: g bit must not indicate "group" */
|
|
|
|
if (EUI64_GROUP(in6))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* convert EUI64 into IPv6 interface identifier */
|
|
|
|
EUI64_TO_IFID(in6);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sanity check: ifid must not be all zero, avoid conflict with
|
|
|
|
* subnet router anycast
|
|
|
|
*/
|
|
|
|
if ((in6->s6_addr[8] & ~(EUI64_GBIT | EUI64_UBIT)) == 0x00 &&
|
|
|
|
bcmp(&in6->s6_addr[9], allzero, 7) == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get interface identifier for the specified interface. If it is not
|
|
|
|
* available on ifp0, borrow interface identifier from other information
|
|
|
|
* sources.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
get_ifid(ifp0, altifp, in6)
|
|
|
|
struct ifnet *ifp0;
|
|
|
|
struct ifnet *altifp; /*secondary EUI64 source*/
|
|
|
|
struct in6_addr *in6;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
/* first, try to get it from the interface itself */
|
|
|
|
if (get_hw_ifid(ifp0, in6) == 0) {
|
|
|
|
#ifdef ND6_DEBUG
|
|
|
|
printf("%s: got interface identifier from itself\n",
|
|
|
|
if_name(ifp0));
|
|
|
|
#endif
|
|
|
|
goto success;
|
|
|
|
}
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
/* try secondary EUI64 source. this basically is for ATM PVC */
|
|
|
|
if (altifp && get_hw_ifid(altifp, in6) == 0) {
|
|
|
|
#ifdef ND6_DEBUG
|
|
|
|
printf("%s: got interface identifier from %s\n",
|
2000-10-01 14:56:02 +04:00
|
|
|
if_name(ifp0), if_name(altifp));
|
2000-04-12 14:36:38 +04:00
|
|
|
#endif
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* next, try to get it from some other hardware interface */
|
1999-12-13 18:17:17 +03:00
|
|
|
for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_list.tqe_next)
|
|
|
|
{
|
2000-04-12 14:36:38 +04:00
|
|
|
if (ifp == ifp0)
|
1999-06-28 10:36:47 +04:00
|
|
|
continue;
|
2000-04-12 14:36:38 +04:00
|
|
|
if (get_hw_ifid(ifp, in6) != 0)
|
|
|
|
continue;
|
2000-04-16 19:00:56 +04:00
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
/*
|
|
|
|
* to borrow ifid from other interface, ifid needs to be
|
|
|
|
* globally unique
|
|
|
|
*/
|
|
|
|
if (IFID_UNIVERSAL(in6)) {
|
|
|
|
|
|
|
|
#ifdef ND6_DEBUG
|
|
|
|
printf("%s: borrow interface identifier from %s\n",
|
|
|
|
if_name(ifp0), if_name(ifp));
|
|
|
|
#endif
|
|
|
|
goto success;
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|
|
|
|
}
|
2000-04-12 14:36:38 +04:00
|
|
|
|
|
|
|
/* last resort: get from random number source */
|
|
|
|
if (get_rand_ifid(ifp, in6) == 0) {
|
|
|
|
#ifdef ND6_DEBUG
|
|
|
|
printf("%s: interface identifier generated by random number\n",
|
|
|
|
if_name(ifp0));
|
1999-07-10 23:46:10 +04:00
|
|
|
#endif
|
2000-04-12 14:36:38 +04:00
|
|
|
goto success;
|
|
|
|
}
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2000-10-01 14:56:02 +04:00
|
|
|
printf("%s: failed to get interface identifier\n", if_name(ifp0));
|
2000-04-12 14:36:38 +04:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
success:
|
|
|
|
#ifdef ND6_DEBUG
|
|
|
|
printf("%s: ifid: "
|
|
|
|
"%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
|
if_name(ifp0),
|
|
|
|
in6->s6_addr[8], in6->s6_addr[9],
|
|
|
|
in6->s6_addr[10], in6->s6_addr[11],
|
|
|
|
in6->s6_addr[12], in6->s6_addr[13],
|
|
|
|
in6->s6_addr[14], in6->s6_addr[15]);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* configure IPv6 interface address. XXX code duplicated with in.c
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
in6_ifattach_addaddr(ifp, ia)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct in6_ifaddr *ia;
|
|
|
|
{
|
|
|
|
struct in6_ifaddr *oia;
|
|
|
|
struct ifaddr *ifa;
|
|
|
|
int error;
|
|
|
|
int rtflag;
|
|
|
|
struct in6_addr llsol;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize if_addrlist, if we are the very first one
|
|
|
|
*/
|
|
|
|
ifa = TAILQ_FIRST(&ifp->if_addrlist);
|
|
|
|
if (ifa == NULL) {
|
|
|
|
TAILQ_INIT(&ifp->if_addrlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* link the interface address to global list
|
|
|
|
*/
|
|
|
|
TAILQ_INSERT_TAIL(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
|
2000-04-16 19:00:56 +04:00
|
|
|
IFAREF(&ia->ia_ifa);
|
2000-04-12 14:36:38 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Also link into the IPv6 address chain beginning with in6_ifaddr.
|
|
|
|
* kazu opposed it, but itojun & jinmei wanted.
|
|
|
|
*/
|
|
|
|
if ((oia = in6_ifaddr) != NULL) {
|
|
|
|
for (; oia->ia_next; oia = oia->ia_next)
|
|
|
|
continue;
|
|
|
|
oia->ia_next = ia;
|
|
|
|
} else
|
|
|
|
in6_ifaddr = ia;
|
2000-04-16 19:00:56 +04:00
|
|
|
IFAREF(&ia->ia_ifa);
|
2000-04-12 14:36:38 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* give the interface a chance to initialize, in case this
|
|
|
|
* is the first address to be added.
|
|
|
|
*/
|
|
|
|
if (ifp->if_ioctl != NULL) {
|
|
|
|
int s;
|
|
|
|
s = splimp();
|
|
|
|
error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia);
|
|
|
|
splx(s);
|
|
|
|
} else
|
|
|
|
error = 0;
|
|
|
|
if (error) {
|
|
|
|
switch (error) {
|
|
|
|
case EAFNOSUPPORT:
|
|
|
|
printf("%s: IPv6 not supported\n", if_name(ifp));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%s: SIOCSIFADDR error %d\n", if_name(ifp),
|
|
|
|
error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* undo changes */
|
|
|
|
TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
|
|
|
|
IFAFREE(&ia->ia_ifa);
|
|
|
|
if (oia)
|
|
|
|
oia->ia_next = ia->ia_next;
|
|
|
|
else
|
|
|
|
in6_ifaddr = ia->ia_next;
|
|
|
|
IFAFREE(&ia->ia_ifa);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* configure link-layer address resolution */
|
2000-04-16 19:00:56 +04:00
|
|
|
rtflag = 0;
|
2000-04-12 14:36:38 +04:00
|
|
|
if (IN6_ARE_ADDR_EQUAL(&ia->ia_prefixmask.sin6_addr, &in6mask128))
|
|
|
|
rtflag = RTF_HOST;
|
|
|
|
else {
|
|
|
|
switch (ifp->if_type) {
|
|
|
|
case IFT_LOOP:
|
|
|
|
#ifdef IFT_STF
|
|
|
|
case IFT_STF:
|
|
|
|
#endif
|
|
|
|
rtflag = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ia->ia_ifa.ifa_rtrequest = nd6_rtrequest;
|
|
|
|
ia->ia_ifa.ifa_flags |= RTF_CLONING;
|
|
|
|
rtflag = RTF_CLONING;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add route to the interface. */
|
|
|
|
rtrequest(RTM_ADD,
|
|
|
|
(struct sockaddr *)&ia->ia_addr,
|
|
|
|
(struct sockaddr *)&ia->ia_addr,
|
|
|
|
(struct sockaddr *)&ia->ia_prefixmask,
|
|
|
|
RTF_UP | rtflag,
|
|
|
|
(struct rtentry **)0);
|
|
|
|
ia->ia_flags |= IFA_ROUTE;
|
|
|
|
|
|
|
|
if ((rtflag & RTF_CLONING) != 0 &&
|
|
|
|
(ifp->if_flags & IFF_MULTICAST) != 0) {
|
|
|
|
/* Restore saved multicast addresses (if any). */
|
|
|
|
in6_restoremkludge(ia, ifp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* join solicited multicast address
|
|
|
|
*/
|
|
|
|
bzero(&llsol, sizeof(llsol));
|
|
|
|
llsol.s6_addr16[0] = htons(0xff02);
|
|
|
|
llsol.s6_addr16[1] = htons(ifp->if_index);
|
|
|
|
llsol.s6_addr32[1] = 0;
|
|
|
|
llsol.s6_addr32[2] = htonl(1);
|
|
|
|
llsol.s6_addr32[3] = ia->ia_addr.sin6_addr.s6_addr32[3];
|
|
|
|
llsol.s6_addr8[12] = 0xff;
|
|
|
|
(void)in6_addmulti(&llsol, ifp, &error);
|
|
|
|
|
|
|
|
/* XXX should we run DAD on other interface types? */
|
|
|
|
switch (ifp->if_type) {
|
|
|
|
#if 1
|
|
|
|
case IFT_ARCNET:
|
|
|
|
case IFT_ETHER:
|
|
|
|
case IFT_FDDI:
|
2000-11-05 20:17:12 +03:00
|
|
|
case IFT_IEEE1394:
|
2000-04-12 14:36:38 +04:00
|
|
|
#else
|
|
|
|
default:
|
|
|
|
#endif
|
|
|
|
/* mark the address TENTATIVE, if needed. */
|
|
|
|
ia->ia6_flags |= IN6_IFF_TENTATIVE;
|
|
|
|
/* nd6_dad_start() will be called in in6_if_up */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
in6_ifattach_linklocal(ifp, altifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifnet *altifp; /*secondary EUI64 source*/
|
|
|
|
{
|
|
|
|
struct in6_ifaddr *ia;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* configure link-local address
|
|
|
|
*/
|
|
|
|
ia = (struct in6_ifaddr *)malloc(sizeof(*ia), M_IFADDR, M_WAITOK);
|
|
|
|
bzero((caddr_t)ia, sizeof(*ia));
|
|
|
|
ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
|
|
|
|
if (ifp->if_flags & IFF_POINTOPOINT)
|
|
|
|
ia->ia_ifa.ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr;
|
|
|
|
else
|
|
|
|
ia->ia_ifa.ifa_dstaddr = NULL;
|
|
|
|
ia->ia_ifa.ifa_netmask = (struct sockaddr *)&ia->ia_prefixmask;
|
|
|
|
ia->ia_ifp = ifp;
|
|
|
|
|
|
|
|
bzero(&ia->ia_prefixmask, sizeof(ia->ia_prefixmask));
|
|
|
|
ia->ia_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
ia->ia_prefixmask.sin6_family = AF_INET6;
|
|
|
|
ia->ia_prefixmask.sin6_addr = in6mask64;
|
|
|
|
|
|
|
|
/* just in case */
|
|
|
|
bzero(&ia->ia_dstaddr, sizeof(ia->ia_dstaddr));
|
|
|
|
ia->ia_dstaddr.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
ia->ia_dstaddr.sin6_family = AF_INET6;
|
|
|
|
|
|
|
|
bzero(&ia->ia_addr, sizeof(ia->ia_addr));
|
|
|
|
ia->ia_addr.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
ia->ia_addr.sin6_family = AF_INET6;
|
|
|
|
ia->ia_addr.sin6_addr.s6_addr16[0] = htons(0xfe80);
|
|
|
|
ia->ia_addr.sin6_addr.s6_addr16[1] = htons(ifp->if_index);
|
|
|
|
ia->ia_addr.sin6_addr.s6_addr32[1] = 0;
|
|
|
|
if (ifp->if_flags & IFF_LOOPBACK) {
|
|
|
|
ia->ia_addr.sin6_addr.s6_addr32[2] = 0;
|
|
|
|
ia->ia_addr.sin6_addr.s6_addr32[3] = htonl(1);
|
1999-06-28 10:36:47 +04:00
|
|
|
} else {
|
2000-04-12 14:36:38 +04:00
|
|
|
if (get_ifid(ifp, altifp, &ia->ia_addr.sin6_addr) != 0) {
|
|
|
|
#ifdef ND6_DEBUG
|
|
|
|
printf("%s: no ifid available\n", if_name(ifp));
|
1999-07-10 23:46:10 +04:00
|
|
|
#endif
|
2000-04-12 14:36:38 +04:00
|
|
|
free(ia, M_IFADDR);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ia->ia_ifa.ifa_metric = ifp->if_metric;
|
|
|
|
|
|
|
|
if (in6_ifattach_addaddr(ifp, ia) != 0) {
|
|
|
|
/* ia will be freed on failure */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
in6_ifattach_loopback(ifp)
|
|
|
|
struct ifnet *ifp; /* must be IFT_LOOP */
|
|
|
|
{
|
|
|
|
struct in6_ifaddr *ia;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* configure link-local address
|
|
|
|
*/
|
|
|
|
ia = (struct in6_ifaddr *)malloc(sizeof(*ia), M_IFADDR, M_WAITOK);
|
|
|
|
bzero((caddr_t)ia, sizeof(*ia));
|
|
|
|
ia->ia_ifa.ifa_addr = (struct sockaddr *)&ia->ia_addr;
|
|
|
|
ia->ia_ifa.ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr;
|
|
|
|
ia->ia_ifa.ifa_netmask = (struct sockaddr *)&ia->ia_prefixmask;
|
|
|
|
ia->ia_ifp = ifp;
|
|
|
|
|
|
|
|
bzero(&ia->ia_prefixmask, sizeof(ia->ia_prefixmask));
|
|
|
|
ia->ia_prefixmask.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
ia->ia_prefixmask.sin6_family = AF_INET6;
|
|
|
|
ia->ia_prefixmask.sin6_addr = in6mask128;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Always initialize ia_dstaddr (= broadcast address) to loopback
|
|
|
|
* address, to make getifaddr happier.
|
|
|
|
*
|
|
|
|
* For BSDI, it is mandatory. The BSDI version of
|
|
|
|
* ifa_ifwithroute() rejects to add a route to the loopback
|
|
|
|
* interface. Even for other systems, loopback looks somewhat
|
|
|
|
* special.
|
|
|
|
*/
|
|
|
|
bzero(&ia->ia_dstaddr, sizeof(ia->ia_dstaddr));
|
|
|
|
ia->ia_dstaddr.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
ia->ia_dstaddr.sin6_family = AF_INET6;
|
|
|
|
ia->ia_dstaddr.sin6_addr = in6addr_loopback;
|
|
|
|
|
|
|
|
bzero(&ia->ia_addr, sizeof(ia->ia_addr));
|
|
|
|
ia->ia_addr.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
ia->ia_addr.sin6_family = AF_INET6;
|
|
|
|
ia->ia_addr.sin6_addr = in6addr_loopback;
|
|
|
|
|
|
|
|
ia->ia_ifa.ifa_metric = ifp->if_metric;
|
|
|
|
|
|
|
|
if (in6_ifattach_addaddr(ifp, ia) != 0) {
|
|
|
|
/* ia will be freed on failure */
|
|
|
|
return -1;
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|
2000-04-12 14:36:38 +04:00
|
|
|
|
|
|
|
return 0;
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|
|
|
|
|
2000-02-02 19:58:10 +03:00
|
|
|
/*
|
|
|
|
* XXX multiple loopback interface needs more care. for instance,
|
|
|
|
* nodelocal address needs to be configured onto only one of them.
|
2000-04-12 14:36:38 +04:00
|
|
|
* XXX multiple link-local address case
|
2000-02-02 19:58:10 +03:00
|
|
|
*/
|
1999-06-28 10:36:47 +04:00
|
|
|
void
|
2000-04-12 14:36:38 +04:00
|
|
|
in6_ifattach(ifp, altifp)
|
1999-06-28 10:36:47 +04:00
|
|
|
struct ifnet *ifp;
|
2000-04-12 14:36:38 +04:00
|
|
|
struct ifnet *altifp; /* secondary EUI64 source */
|
1999-06-28 10:36:47 +04:00
|
|
|
{
|
|
|
|
static size_t if_indexlim = 8;
|
|
|
|
struct sockaddr_in6 mltaddr;
|
|
|
|
struct sockaddr_in6 mltmask;
|
|
|
|
struct sockaddr_in6 gate;
|
|
|
|
struct sockaddr_in6 mask;
|
2000-04-12 14:36:38 +04:00
|
|
|
struct in6_ifaddr *ia;
|
|
|
|
struct in6_addr in6;
|
1999-12-13 18:17:17 +03:00
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
|
|
|
* We have some arrays that should be indexed by if_index.
|
|
|
|
* since if_index will grow dynamically, they should grow too.
|
1999-12-13 18:17:17 +03:00
|
|
|
* struct in6_ifstat **in6_ifstat
|
|
|
|
* struct icmp6_ifstat **icmp6_ifstat
|
1999-06-28 10:36:47 +04:00
|
|
|
*/
|
2000-04-12 14:36:38 +04:00
|
|
|
if (in6_ifstat == NULL || icmp6_ifstat == NULL ||
|
|
|
|
if_index >= if_indexlim) {
|
1999-06-28 10:36:47 +04:00
|
|
|
size_t n;
|
|
|
|
caddr_t q;
|
1999-09-13 16:15:54 +04:00
|
|
|
size_t olim;
|
1999-06-28 10:36:47 +04:00
|
|
|
|
1999-09-13 16:15:54 +04:00
|
|
|
olim = if_indexlim;
|
|
|
|
while (if_index >= if_indexlim)
|
1999-06-28 10:36:47 +04:00
|
|
|
if_indexlim <<= 1;
|
|
|
|
|
1999-12-13 18:17:17 +03:00
|
|
|
/* grow in6_ifstat */
|
|
|
|
n = if_indexlim * sizeof(struct in6_ifstat *);
|
|
|
|
q = (caddr_t)malloc(n, M_IFADDR, M_WAITOK);
|
|
|
|
bzero(q, n);
|
|
|
|
if (in6_ifstat) {
|
|
|
|
bcopy((caddr_t)in6_ifstat, q,
|
|
|
|
olim * sizeof(struct in6_ifstat *));
|
|
|
|
free((caddr_t)in6_ifstat, M_IFADDR);
|
|
|
|
}
|
|
|
|
in6_ifstat = (struct in6_ifstat **)q;
|
|
|
|
in6_ifstatmax = if_indexlim;
|
|
|
|
|
|
|
|
/* grow icmp6_ifstat */
|
|
|
|
n = if_indexlim * sizeof(struct icmp6_ifstat *);
|
1999-06-28 10:36:47 +04:00
|
|
|
q = (caddr_t)malloc(n, M_IFADDR, M_WAITOK);
|
|
|
|
bzero(q, n);
|
1999-12-13 18:17:17 +03:00
|
|
|
if (icmp6_ifstat) {
|
|
|
|
bcopy((caddr_t)icmp6_ifstat, q,
|
|
|
|
olim * sizeof(struct icmp6_ifstat *));
|
|
|
|
free((caddr_t)icmp6_ifstat, M_IFADDR);
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|
1999-12-13 18:17:17 +03:00
|
|
|
icmp6_ifstat = (struct icmp6_ifstat **)q;
|
|
|
|
icmp6_ifstatmax = if_indexlim;
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-04-12 14:36:38 +04:00
|
|
|
* quirks based on interface type
|
1999-06-28 10:36:47 +04:00
|
|
|
*/
|
2000-04-12 14:36:38 +04:00
|
|
|
switch (ifp->if_type) {
|
|
|
|
#ifdef IFT_STF
|
|
|
|
case IFT_STF:
|
|
|
|
/*
|
|
|
|
* 6to4 interface is a very speical kind of beast.
|
|
|
|
* no multicast, no linklocal (based on 03 draft).
|
|
|
|
*/
|
|
|
|
goto statinit;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
1999-09-13 16:15:54 +04:00
|
|
|
}
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
2000-04-12 14:36:38 +04:00
|
|
|
* usually, we require multicast capability to the interface
|
1999-06-28 10:36:47 +04:00
|
|
|
*/
|
2000-04-12 14:36:38 +04:00
|
|
|
if ((ifp->if_flags & IFF_MULTICAST) == 0) {
|
|
|
|
printf("%s: not multicast capable, IPv6 not enabled\n",
|
|
|
|
if_name(ifp));
|
|
|
|
return;
|
|
|
|
}
|
2000-02-02 01:52:04 +03:00
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
2000-04-12 14:36:38 +04:00
|
|
|
* assign link-local address, if there's none
|
1999-06-28 10:36:47 +04:00
|
|
|
*/
|
2000-04-12 14:36:38 +04:00
|
|
|
ia = in6ifa_ifpforlinklocal(ifp, 0);
|
|
|
|
if (ia == NULL) {
|
|
|
|
if (in6_ifattach_linklocal(ifp, altifp) != 0)
|
|
|
|
return;
|
|
|
|
ia = in6ifa_ifpforlinklocal(ifp, 0);
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
if (ia == NULL) {
|
2000-10-01 14:56:02 +04:00
|
|
|
printf("%s: failed to add link-local address\n",
|
2000-04-12 14:36:38 +04:00
|
|
|
if_name(ifp));
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
/* we can't initialize multicasts without link-local */
|
|
|
|
goto statinit;
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
if (ifp->if_flags & IFF_POINTOPOINT) {
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
|
|
|
* route local address to loopback
|
|
|
|
*/
|
|
|
|
bzero(&gate, sizeof(gate));
|
|
|
|
gate.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
gate.sin6_family = AF_INET6;
|
|
|
|
gate.sin6_addr = in6addr_loopback;
|
|
|
|
bzero(&mask, sizeof(mask));
|
|
|
|
mask.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
mask.sin6_family = AF_INET6;
|
|
|
|
mask.sin6_addr = in6mask64;
|
|
|
|
rtrequest(RTM_ADD,
|
|
|
|
(struct sockaddr *)&ia->ia_addr,
|
|
|
|
(struct sockaddr *)&gate,
|
|
|
|
(struct sockaddr *)&mask,
|
|
|
|
RTF_UP|RTF_HOST,
|
|
|
|
(struct rtentry **)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-04-12 14:36:38 +04:00
|
|
|
* assign loopback address for loopback interface
|
|
|
|
* XXX multiple loopback interface case
|
1999-06-28 10:36:47 +04:00
|
|
|
*/
|
2000-04-12 14:36:38 +04:00
|
|
|
in6 = in6addr_loopback;
|
|
|
|
if (ifp->if_flags & IFF_LOOPBACK) {
|
|
|
|
if (in6ifa_ifpwithaddr(ifp, &in6) == NULL) {
|
|
|
|
if (in6_ifattach_loopback(ifp) != 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (!ia) {
|
|
|
|
panic("ia == NULL in in6_ifattach");
|
|
|
|
/*NOTREACHED*/
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|
2000-04-12 14:36:38 +04:00
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* join multicast
|
|
|
|
*/
|
|
|
|
if (ifp->if_flags & IFF_MULTICAST) {
|
|
|
|
int error; /* not used */
|
2000-04-12 14:36:38 +04:00
|
|
|
struct in6_multi *in6m;
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
/* Restore saved multicast addresses (if any). */
|
1999-06-28 10:36:47 +04:00
|
|
|
in6_restoremkludge(ia, ifp);
|
|
|
|
|
|
|
|
bzero(&mltmask, sizeof(mltmask));
|
|
|
|
mltmask.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
mltmask.sin6_family = AF_INET6;
|
|
|
|
mltmask.sin6_addr = in6mask32;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* join link-local all-nodes address
|
|
|
|
*/
|
|
|
|
bzero(&mltaddr, sizeof(mltaddr));
|
|
|
|
mltaddr.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
mltaddr.sin6_family = AF_INET6;
|
|
|
|
mltaddr.sin6_addr = in6addr_linklocal_allnodes;
|
|
|
|
mltaddr.sin6_addr.s6_addr16[1] = htons(ifp->if_index);
|
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
IN6_LOOKUP_MULTI(mltaddr.sin6_addr, ifp, in6m);
|
|
|
|
if (in6m == NULL) {
|
1999-06-28 10:36:47 +04:00
|
|
|
rtrequest(RTM_ADD,
|
|
|
|
(struct sockaddr *)&mltaddr,
|
2000-04-12 14:36:38 +04:00
|
|
|
(struct sockaddr *)&ia->ia_addr,
|
1999-06-28 10:36:47 +04:00
|
|
|
(struct sockaddr *)&mltmask,
|
2000-04-12 14:36:38 +04:00
|
|
|
RTF_UP|RTF_CLONING, /* xxx */
|
1999-06-28 10:36:47 +04:00
|
|
|
(struct rtentry **)0);
|
|
|
|
(void)in6_addmulti(&mltaddr.sin6_addr, ifp, &error);
|
2000-04-12 14:36:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_LOOPBACK) {
|
|
|
|
in6 = in6addr_loopback;
|
|
|
|
ia = in6ifa_ifpwithaddr(ifp, &in6);
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
2000-04-12 14:36:38 +04:00
|
|
|
* join node-local all-nodes address, on loopback
|
1999-06-28 10:36:47 +04:00
|
|
|
*/
|
2000-04-12 14:36:38 +04:00
|
|
|
mltaddr.sin6_addr = in6addr_nodelocal_allnodes;
|
|
|
|
|
|
|
|
IN6_LOOKUP_MULTI(mltaddr.sin6_addr, ifp, in6m);
|
|
|
|
if (in6m == NULL && ia != NULL) {
|
|
|
|
rtrequest(RTM_ADD,
|
|
|
|
(struct sockaddr *)&mltaddr,
|
|
|
|
(struct sockaddr *)&ia->ia_addr,
|
|
|
|
(struct sockaddr *)&mltmask,
|
|
|
|
RTF_UP,
|
|
|
|
(struct rtentry **)0);
|
|
|
|
(void)in6_addmulti(&mltaddr.sin6_addr, ifp, &error);
|
|
|
|
}
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-12 14:36:38 +04:00
|
|
|
statinit:;
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/* update dynamically. */
|
|
|
|
if (in6_maxmtu < ifp->if_mtu)
|
|
|
|
in6_maxmtu = ifp->if_mtu;
|
|
|
|
|
1999-12-13 18:17:17 +03:00
|
|
|
if (in6_ifstat[ifp->if_index] == NULL) {
|
|
|
|
in6_ifstat[ifp->if_index] = (struct in6_ifstat *)
|
|
|
|
malloc(sizeof(struct in6_ifstat), M_IFADDR, M_WAITOK);
|
|
|
|
bzero(in6_ifstat[ifp->if_index], sizeof(struct in6_ifstat));
|
|
|
|
}
|
|
|
|
if (icmp6_ifstat[ifp->if_index] == NULL) {
|
|
|
|
icmp6_ifstat[ifp->if_index] = (struct icmp6_ifstat *)
|
|
|
|
malloc(sizeof(struct icmp6_ifstat), M_IFADDR, M_WAITOK);
|
|
|
|
bzero(icmp6_ifstat[ifp->if_index], sizeof(struct icmp6_ifstat));
|
|
|
|
}
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/* initialize NDP variables */
|
|
|
|
nd6_ifattach(ifp);
|
|
|
|
}
|
|
|
|
|
2000-02-02 19:58:10 +03:00
|
|
|
/*
|
|
|
|
* NOTE: in6_ifdetach() does not support loopback if at this moment.
|
|
|
|
*/
|
1999-06-28 10:36:47 +04:00
|
|
|
void
|
|
|
|
in6_ifdetach(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct in6_ifaddr *ia, *oia;
|
2000-05-05 12:03:12 +04:00
|
|
|
struct ifaddr *ifa, *next;
|
1999-06-28 10:36:47 +04:00
|
|
|
struct rtentry *rt;
|
|
|
|
short rtflags;
|
2000-02-02 16:44:05 +03:00
|
|
|
struct sockaddr_in6 sin6;
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2000-02-04 17:34:22 +03:00
|
|
|
/* nuke prefix list. this may try to remove some of ifaddrs as well */
|
|
|
|
in6_purgeprefix(ifp);
|
|
|
|
|
|
|
|
/* remove neighbor management table */
|
|
|
|
nd6_purge(ifp);
|
|
|
|
|
2000-05-05 12:03:12 +04:00
|
|
|
/* nuke any of IPv6 addresses we have */
|
|
|
|
for (ifa = ifp->if_addrlist.tqh_first; ifa; ifa = next)
|
|
|
|
{
|
|
|
|
next = ifa->ifa_list.tqe_next;
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_INET6)
|
|
|
|
continue;
|
|
|
|
in6_purgeaddr(ifa, ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* undo everything done by in6_ifattach(), just in case */
|
|
|
|
for (ifa = ifp->if_addrlist.tqh_first; ifa; ifa = next)
|
1999-12-13 18:17:17 +03:00
|
|
|
{
|
2000-05-05 12:03:12 +04:00
|
|
|
next = ifa->ifa_list.tqe_next;
|
|
|
|
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
if (ifa->ifa_addr->sa_family != AF_INET6
|
|
|
|
|| !IN6_IS_ADDR_LINKLOCAL(&satosin6(&ifa->ifa_addr)->sin6_addr)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ia = (struct in6_ifaddr *)ifa;
|
|
|
|
|
|
|
|
/* remove from the routing table */
|
|
|
|
if ((ia->ia_flags & IFA_ROUTE)
|
2000-01-06 18:46:07 +03:00
|
|
|
&& (rt = rtalloc1((struct sockaddr *)&ia->ia_addr, 0))) {
|
1999-06-28 10:36:47 +04:00
|
|
|
rtflags = rt->rt_flags;
|
|
|
|
rtfree(rt);
|
|
|
|
rtrequest(RTM_DELETE,
|
|
|
|
(struct sockaddr *)&ia->ia_addr,
|
2000-04-10 19:45:24 +04:00
|
|
|
(struct sockaddr *)&ia->ia_addr,
|
1999-06-28 10:36:47 +04:00
|
|
|
(struct sockaddr *)&ia->ia_prefixmask,
|
|
|
|
rtflags, (struct rtentry **)0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove from the linked list */
|
|
|
|
TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
|
2000-05-05 12:03:12 +04:00
|
|
|
IFAFREE(&ia->ia_ifa);
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/* also remove from the IPv6 address chain(itojun&jinmei) */
|
|
|
|
oia = ia;
|
|
|
|
if (oia == (ia = in6_ifaddr))
|
|
|
|
in6_ifaddr = ia->ia_next;
|
|
|
|
else {
|
|
|
|
while (ia->ia_next && (ia->ia_next != oia))
|
|
|
|
ia = ia->ia_next;
|
|
|
|
if (ia->ia_next)
|
|
|
|
ia->ia_next = oia->ia_next;
|
2000-04-12 14:36:38 +04:00
|
|
|
#ifdef ND6_DEBUG
|
1999-06-28 10:36:47 +04:00
|
|
|
else
|
1999-07-10 23:46:10 +04:00
|
|
|
printf("%s: didn't unlink in6ifaddr from "
|
1999-12-13 18:17:17 +03:00
|
|
|
"list\n", if_name(ifp));
|
1999-07-10 23:46:10 +04:00
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|
|
|
|
|
2000-05-05 12:03:12 +04:00
|
|
|
IFAFREE(&oia->ia_ifa);
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|
2000-02-02 16:44:05 +03:00
|
|
|
|
2000-02-02 19:58:10 +03:00
|
|
|
/* cleanup multicast address kludge table, if there is any */
|
|
|
|
in6_purgemkludge(ifp);
|
2000-02-04 17:34:22 +03:00
|
|
|
|
2000-05-05 12:03:12 +04:00
|
|
|
/* remove neighbor management table */
|
|
|
|
nd6_purge(ifp);
|
|
|
|
|
2000-02-02 16:44:05 +03:00
|
|
|
/* remove route to link-local allnodes multicast (ff02::1) */
|
|
|
|
bzero(&sin6, sizeof(sin6));
|
|
|
|
sin6.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
sin6.sin6_family = AF_INET6;
|
|
|
|
sin6.sin6_addr = in6addr_linklocal_allnodes;
|
|
|
|
sin6.sin6_addr.s6_addr16[1] = htons(ifp->if_index);
|
|
|
|
if ((rt = rtalloc1((struct sockaddr *)&sin6, 0)) != NULL) {
|
|
|
|
rtrequest(RTM_DELETE, (struct sockaddr *)rt_key(rt),
|
|
|
|
rt->rt_gateway, rt_mask(rt), rt->rt_flags, 0);
|
|
|
|
rtfree(rt);
|
|
|
|
}
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|