2000-07-04 16:35:15 +00:00
|
|
|
/* $FreeBSD$ */
|
2001-06-11 12:39:29 +00:00
|
|
|
/* $KAME: scope6.c,v 1.10 2000/07/24 13:29:31 itojun Exp $ */
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2000 WIDE Project.
|
|
|
|
* All rights reserved.
|
2003-10-09 16:13:47 +00:00
|
|
|
*
|
2000-07-04 16:35:15 +00: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.
|
2003-10-09 16:13:47 +00:00
|
|
|
*
|
2000-07-04 16:35:15 +00: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/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/systm.h>
|
2001-06-11 12:39:29 +00:00
|
|
|
#include <sys/queue.h>
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <netinet6/in6_var.h>
|
|
|
|
#include <netinet6/scope6_var.h>
|
|
|
|
|
2003-10-22 15:13:36 +00:00
|
|
|
/*
|
2004-11-29 03:10:35 +00:00
|
|
|
* The scope6_lock protects the global sid default stored in
|
|
|
|
* sid_default below.
|
2003-10-22 15:13:36 +00:00
|
|
|
*/
|
|
|
|
static struct mtx scope6_lock;
|
|
|
|
#define SCOPE6_LOCK_INIT() mtx_init(&scope6_lock, "scope6_lock", NULL, MTX_DEF)
|
|
|
|
#define SCOPE6_LOCK() mtx_lock(&scope6_lock)
|
|
|
|
#define SCOPE6_UNLOCK() mtx_unlock(&scope6_lock)
|
|
|
|
#define SCOPE6_LOCK_ASSERT() mtx_assert(&scope6_lock, MA_OWNED)
|
|
|
|
|
2003-10-17 15:46:31 +00:00
|
|
|
static struct scope6_id sid_default;
|
|
|
|
#define SID(ifp) \
|
|
|
|
(((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->scope6_id)
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
void
|
2003-10-17 15:46:31 +00:00
|
|
|
scope6_init()
|
|
|
|
{
|
|
|
|
|
2003-10-22 15:13:36 +00:00
|
|
|
SCOPE6_LOCK_INIT();
|
2003-10-17 15:46:31 +00:00
|
|
|
bzero(&sid_default, sizeof(sid_default));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct scope6_id *
|
2000-07-04 16:35:15 +00:00
|
|
|
scope6_ifattach(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
2003-10-17 15:46:31 +00:00
|
|
|
struct scope6_id *sid;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
2003-10-17 15:46:31 +00:00
|
|
|
sid = (struct scope6_id *)malloc(sizeof(*sid), M_IFADDR, M_WAITOK);
|
|
|
|
bzero(sid, sizeof(*sid));
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: IPV6_ADDR_SCOPE_xxx macros are not standard.
|
|
|
|
* Should we rather hardcode here?
|
|
|
|
*/
|
2003-10-21 20:05:32 +00:00
|
|
|
sid->s6id_list[IPV6_ADDR_SCOPE_INTFACELOCAL] = ifp->if_index;
|
2003-10-17 15:46:31 +00:00
|
|
|
sid->s6id_list[IPV6_ADDR_SCOPE_LINKLOCAL] = ifp->if_index;
|
2000-07-04 16:35:15 +00:00
|
|
|
#ifdef MULTI_SCOPE
|
|
|
|
/* by default, we don't care about scope boundary for these scopes. */
|
2003-10-17 15:46:31 +00:00
|
|
|
sid->s6id_list[IPV6_ADDR_SCOPE_SITELOCAL] = 1;
|
|
|
|
sid->s6id_list[IPV6_ADDR_SCOPE_ORGLOCAL] = 1;
|
2000-07-04 16:35:15 +00:00
|
|
|
#endif
|
|
|
|
|
2003-10-17 15:46:31 +00:00
|
|
|
return sid;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
scope6_ifdetach(sid)
|
|
|
|
struct scope6_id *sid;
|
|
|
|
{
|
|
|
|
|
|
|
|
free(sid, M_IFADDR);
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
scope6_set(ifp, idlist)
|
|
|
|
struct ifnet *ifp;
|
2003-10-17 15:46:31 +00:00
|
|
|
struct scope6_id *idlist;
|
2000-07-04 16:35:15 +00:00
|
|
|
{
|
2004-11-29 03:10:35 +00:00
|
|
|
int i;
|
2000-07-04 16:35:15 +00:00
|
|
|
int error = 0;
|
2004-11-29 03:10:35 +00:00
|
|
|
struct scope6_id *sid = NULL;
|
|
|
|
|
|
|
|
IF_AFDATA_LOCK(ifp);
|
|
|
|
sid = SID(ifp);
|
2000-07-04 16:35:15 +00:00
|
|
|
|
2004-11-29 03:10:35 +00:00
|
|
|
if (!sid) { /* paranoid? */
|
|
|
|
IF_AFDATA_UNLOCK(ifp);
|
2003-10-06 14:02:09 +00:00
|
|
|
return (EINVAL);
|
2004-11-29 03:10:35 +00:00
|
|
|
}
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: We need more consistency checks of the relationship among
|
|
|
|
* scopes (e.g. an organization should be larger than a site).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO(XXX): after setting, we should reflect the changes to
|
2003-10-09 16:13:47 +00:00
|
|
|
* interface addresses, routing table entries, PCB entries...
|
2000-07-04 16:35:15 +00:00
|
|
|
*/
|
|
|
|
|
2003-10-22 15:13:36 +00:00
|
|
|
SCOPE6_LOCK();
|
2000-07-04 16:35:15 +00:00
|
|
|
for (i = 0; i < 16; i++) {
|
2003-10-17 15:46:31 +00:00
|
|
|
if (idlist->s6id_list[i] &&
|
|
|
|
idlist->s6id_list[i] != sid->s6id_list[i]) {
|
2003-10-21 20:05:32 +00:00
|
|
|
/*
|
|
|
|
* An interface zone ID must be the corresponding
|
|
|
|
* interface index by definition.
|
|
|
|
*/
|
|
|
|
if (i == IPV6_ADDR_SCOPE_INTFACELOCAL &&
|
|
|
|
idlist->s6id_list[i] != ifp->if_index) {
|
2004-11-29 03:10:35 +00:00
|
|
|
IF_AFDATA_UNLOCK(ifp);
|
|
|
|
SCOPE6_UNLOCK();
|
2003-10-21 20:05:32 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
2000-07-04 16:35:15 +00:00
|
|
|
if (i == IPV6_ADDR_SCOPE_LINKLOCAL &&
|
2003-10-17 15:46:31 +00:00
|
|
|
idlist->s6id_list[i] > if_index) {
|
2000-07-04 16:35:15 +00:00
|
|
|
/*
|
|
|
|
* XXX: theoretically, there should be no
|
|
|
|
* relationship between link IDs and interface
|
|
|
|
* IDs, but we check the consistency for
|
|
|
|
* safety in later use.
|
|
|
|
*/
|
2004-11-29 03:10:35 +00:00
|
|
|
IF_AFDATA_UNLOCK(ifp);
|
|
|
|
SCOPE6_UNLOCK();
|
2003-10-06 14:02:09 +00:00
|
|
|
return (EINVAL);
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: we must need lots of work in this case,
|
|
|
|
* but we simply set the new value in this initial
|
|
|
|
* implementation.
|
|
|
|
*/
|
2003-10-17 15:46:31 +00:00
|
|
|
sid->s6id_list[i] = idlist->s6id_list[i];
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-22 15:13:36 +00:00
|
|
|
SCOPE6_UNLOCK();
|
2004-11-29 03:10:35 +00:00
|
|
|
IF_AFDATA_UNLOCK(ifp);
|
2000-07-04 16:35:15 +00:00
|
|
|
|
2003-10-06 14:02:09 +00:00
|
|
|
return (error);
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
scope6_get(ifp, idlist)
|
|
|
|
struct ifnet *ifp;
|
2003-10-17 15:46:31 +00:00
|
|
|
struct scope6_id *idlist;
|
2000-07-04 16:35:15 +00:00
|
|
|
{
|
2004-11-29 03:10:35 +00:00
|
|
|
/* We only need to lock the interface's afdata for SID() to work. */
|
|
|
|
IF_AFDATA_LOCK(ifp);
|
2003-10-17 15:46:31 +00:00
|
|
|
struct scope6_id *sid = SID(ifp);
|
|
|
|
|
2004-11-29 03:10:35 +00:00
|
|
|
if (sid == NULL) { /* paranoid? */
|
|
|
|
IF_AFDATA_UNLOCK(ifp);
|
2003-10-06 14:02:09 +00:00
|
|
|
return (EINVAL);
|
2004-11-29 03:10:35 +00:00
|
|
|
}
|
2000-07-04 16:35:15 +00:00
|
|
|
|
2003-10-22 15:13:36 +00:00
|
|
|
SCOPE6_LOCK();
|
2003-10-17 15:46:31 +00:00
|
|
|
*idlist = *sid;
|
2003-10-22 15:13:36 +00:00
|
|
|
SCOPE6_UNLOCK();
|
2000-07-04 16:35:15 +00:00
|
|
|
|
2004-11-29 03:10:35 +00:00
|
|
|
IF_AFDATA_UNLOCK(ifp);
|
2003-10-06 14:02:09 +00:00
|
|
|
return (0);
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a scope of the address. Node-local, link-local, site-local or global.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
in6_addrscope(addr)
|
2003-10-09 16:13:47 +00:00
|
|
|
struct in6_addr *addr;
|
2000-07-04 16:35:15 +00:00
|
|
|
{
|
|
|
|
int scope;
|
|
|
|
|
2003-10-21 20:05:32 +00:00
|
|
|
if (addr->s6_addr[0] == 0xfe) {
|
|
|
|
scope = addr->s6_addr[1] & 0xc0;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
switch (scope) {
|
|
|
|
case 0x80:
|
|
|
|
return IPV6_ADDR_SCOPE_LINKLOCAL;
|
|
|
|
break;
|
|
|
|
case 0xc0:
|
|
|
|
return IPV6_ADDR_SCOPE_SITELOCAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return IPV6_ADDR_SCOPE_GLOBAL; /* just in case */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-21 20:05:32 +00:00
|
|
|
if (addr->s6_addr[0] == 0xff) {
|
|
|
|
scope = addr->s6_addr[1] & 0x0f;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* due to other scope such as reserved,
|
|
|
|
* return scope doesn't work.
|
|
|
|
*/
|
|
|
|
switch (scope) {
|
2003-10-21 20:05:32 +00:00
|
|
|
case IPV6_ADDR_SCOPE_INTFACELOCAL:
|
|
|
|
return IPV6_ADDR_SCOPE_INTFACELOCAL;
|
2000-07-04 16:35:15 +00:00
|
|
|
break;
|
|
|
|
case IPV6_ADDR_SCOPE_LINKLOCAL:
|
|
|
|
return IPV6_ADDR_SCOPE_LINKLOCAL;
|
|
|
|
break;
|
|
|
|
case IPV6_ADDR_SCOPE_SITELOCAL:
|
|
|
|
return IPV6_ADDR_SCOPE_SITELOCAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return IPV6_ADDR_SCOPE_GLOBAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-21 20:05:32 +00:00
|
|
|
/*
|
|
|
|
* Regard loopback and unspecified addresses as global, since
|
|
|
|
* they have no ambiguity.
|
|
|
|
*/
|
2002-03-25 10:12:51 +00:00
|
|
|
if (bcmp(&in6addr_loopback, addr, sizeof(*addr) - 1) == 0) {
|
2003-10-21 20:05:32 +00:00
|
|
|
if (addr->s6_addr[15] == 1) /* loopback */
|
2000-07-04 16:35:15 +00:00
|
|
|
return IPV6_ADDR_SCOPE_LINKLOCAL;
|
2003-10-21 20:05:32 +00:00
|
|
|
if (addr->s6_addr[15] == 0) /* unspecified */
|
|
|
|
return IPV6_ADDR_SCOPE_GLOBAL; /* XXX: correct? */
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return IPV6_ADDR_SCOPE_GLOBAL;
|
|
|
|
}
|
|
|
|
|
2003-10-21 20:05:32 +00:00
|
|
|
/*
|
|
|
|
* When we introduce the "4+28" split semantics in sin6_scope_id,
|
|
|
|
* a 32bit integer is not enough to tell a large ID from an error (-1).
|
|
|
|
* So, we intentionally use a large type as the return value.
|
|
|
|
*/
|
2000-07-04 16:35:15 +00:00
|
|
|
int
|
2003-10-21 20:05:32 +00:00
|
|
|
in6_addr2zoneid(ifp, addr, ret_id)
|
2000-07-04 16:35:15 +00:00
|
|
|
struct ifnet *ifp; /* must not be NULL */
|
|
|
|
struct in6_addr *addr; /* must not be NULL */
|
2003-10-21 20:05:32 +00:00
|
|
|
u_int32_t *ret_id; /* must not be NULL */
|
2000-07-04 16:35:15 +00:00
|
|
|
{
|
2003-10-17 15:46:31 +00:00
|
|
|
int scope;
|
2003-10-21 20:05:32 +00:00
|
|
|
u_int32_t zoneid = 0;
|
2004-11-29 03:10:35 +00:00
|
|
|
struct scope6_id *sid = NULL;
|
|
|
|
|
|
|
|
IF_AFDATA_LOCK(ifp);
|
|
|
|
|
|
|
|
sid = SID(ifp);
|
2003-10-17 15:46:31 +00:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (sid == NULL) { /* should not happen */
|
|
|
|
panic("in6_addr2zoneid: scope array is NULL");
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
2003-10-21 20:05:32 +00:00
|
|
|
if (ret_id == NULL) {
|
|
|
|
panic("in6_addr2zoneid: return ID is null");
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
2003-10-17 15:46:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* special case: the loopback address can only belong to a loopback
|
|
|
|
* interface.
|
|
|
|
*/
|
|
|
|
if (IN6_IS_ADDR_LOOPBACK(addr)) {
|
2004-11-29 03:10:35 +00:00
|
|
|
if (!(ifp->if_flags & IFF_LOOPBACK)) {
|
|
|
|
IF_AFDATA_UNLOCK(ifp);
|
2003-10-17 15:46:31 +00:00
|
|
|
return (-1);
|
2004-11-29 03:10:35 +00:00
|
|
|
} else {
|
2003-10-21 20:05:32 +00:00
|
|
|
*ret_id = 0; /* there's no ambiguity */
|
2004-11-29 03:10:35 +00:00
|
|
|
IF_AFDATA_UNLOCK(ifp);
|
2003-10-21 20:05:32 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2003-10-17 15:46:31 +00:00
|
|
|
}
|
2000-07-04 16:35:15 +00:00
|
|
|
|
2003-10-17 15:46:31 +00:00
|
|
|
scope = in6_addrscope(addr);
|
2000-07-04 16:35:15 +00:00
|
|
|
|
2003-10-22 15:13:36 +00:00
|
|
|
/*
|
|
|
|
* XXX: These are all u_int32_t reads, so may not require locking.
|
|
|
|
*/
|
|
|
|
SCOPE6_LOCK();
|
2003-10-21 20:05:32 +00:00
|
|
|
switch (scope) {
|
|
|
|
case IPV6_ADDR_SCOPE_INTFACELOCAL: /* should be interface index */
|
|
|
|
zoneid = sid->s6id_list[IPV6_ADDR_SCOPE_INTFACELOCAL];
|
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
case IPV6_ADDR_SCOPE_LINKLOCAL:
|
2003-10-21 20:05:32 +00:00
|
|
|
zoneid = sid->s6id_list[IPV6_ADDR_SCOPE_LINKLOCAL];
|
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
case IPV6_ADDR_SCOPE_SITELOCAL:
|
2003-10-21 20:05:32 +00:00
|
|
|
zoneid = sid->s6id_list[IPV6_ADDR_SCOPE_SITELOCAL];
|
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
case IPV6_ADDR_SCOPE_ORGLOCAL:
|
2003-10-21 20:05:32 +00:00
|
|
|
zoneid = sid->s6id_list[IPV6_ADDR_SCOPE_ORGLOCAL];
|
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
|
|
|
|
default:
|
2003-10-21 20:05:32 +00:00
|
|
|
zoneid = 0; /* XXX: treat as global. */
|
|
|
|
break;
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
2003-10-22 15:13:36 +00:00
|
|
|
SCOPE6_UNLOCK();
|
|
|
|
|
2003-10-21 20:05:32 +00:00
|
|
|
*ret_id = zoneid;
|
2004-11-29 03:10:35 +00:00
|
|
|
|
|
|
|
IF_AFDATA_UNLOCK(ifp);
|
|
|
|
|
2003-10-21 20:05:32 +00:00
|
|
|
return (0);
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
scope6_setdefault(ifp)
|
|
|
|
struct ifnet *ifp; /* note that this might be NULL */
|
|
|
|
{
|
|
|
|
/*
|
2004-11-29 03:10:35 +00:00
|
|
|
* Currently, this function just sets the default "interfaces"
|
2003-10-17 15:46:31 +00:00
|
|
|
* and "links" according to the given interface.
|
2000-07-04 16:35:15 +00:00
|
|
|
* We might eventually have to separate the notion of "link" from
|
|
|
|
* "interface" and provide a user interface to set the default.
|
|
|
|
*/
|
2003-10-22 15:13:36 +00:00
|
|
|
SCOPE6_LOCK();
|
2000-07-04 16:35:15 +00:00
|
|
|
if (ifp) {
|
2003-10-21 20:05:32 +00:00
|
|
|
sid_default.s6id_list[IPV6_ADDR_SCOPE_INTFACELOCAL] =
|
2003-10-17 15:46:31 +00:00
|
|
|
ifp->if_index;
|
|
|
|
sid_default.s6id_list[IPV6_ADDR_SCOPE_LINKLOCAL] =
|
2000-07-04 16:35:15 +00:00
|
|
|
ifp->if_index;
|
2003-10-09 16:13:47 +00:00
|
|
|
} else {
|
2003-10-21 20:05:32 +00:00
|
|
|
sid_default.s6id_list[IPV6_ADDR_SCOPE_INTFACELOCAL] = 0;
|
2003-10-17 15:46:31 +00:00
|
|
|
sid_default.s6id_list[IPV6_ADDR_SCOPE_LINKLOCAL] = 0;
|
2003-10-09 16:13:47 +00:00
|
|
|
}
|
2003-10-22 15:13:36 +00:00
|
|
|
SCOPE6_UNLOCK();
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
scope6_get_default(idlist)
|
2003-10-17 15:46:31 +00:00
|
|
|
struct scope6_id *idlist;
|
2000-07-04 16:35:15 +00:00
|
|
|
{
|
2003-10-22 15:13:36 +00:00
|
|
|
|
|
|
|
SCOPE6_LOCK();
|
2003-10-17 15:46:31 +00:00
|
|
|
*idlist = sid_default;
|
2003-10-22 15:13:36 +00:00
|
|
|
SCOPE6_UNLOCK();
|
2000-07-04 16:35:15 +00:00
|
|
|
|
2003-10-06 14:02:09 +00:00
|
|
|
return (0);
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u_int32_t
|
|
|
|
scope6_addr2default(addr)
|
|
|
|
struct in6_addr *addr;
|
|
|
|
{
|
2003-10-22 15:13:36 +00:00
|
|
|
u_int32_t id;
|
|
|
|
|
2003-10-17 15:46:31 +00:00
|
|
|
/*
|
|
|
|
* special case: The loopback address should be considered as
|
|
|
|
* link-local, but there's no ambiguity in the syntax.
|
|
|
|
*/
|
|
|
|
if (IN6_IS_ADDR_LOOPBACK(addr))
|
|
|
|
return (0);
|
|
|
|
|
2003-10-22 15:13:36 +00:00
|
|
|
/*
|
|
|
|
* XXX: 32-bit read is atomic on all our platforms, is it OK
|
|
|
|
* not to lock here?
|
|
|
|
*/
|
|
|
|
SCOPE6_LOCK();
|
|
|
|
id = sid_default.s6id_list[in6_addrscope(addr)];
|
|
|
|
SCOPE6_UNLOCK();
|
|
|
|
return (id);
|
2000-07-04 16:35:15 +00:00
|
|
|
}
|