use new scopeid functions

This commit is contained in:
christos 2013-10-19 17:16:25 +00:00
parent a18b60aecf
commit 94a96ec4ae
5 changed files with 24 additions and 91 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: faithd.c,v 1.35 2011/09/16 15:39:37 joerg Exp $ */
/* $NetBSD: faithd.c,v 1.36 2013/10/19 17:16:25 christos Exp $ */
/* $KAME: faithd.c,v 1.62 2003/08/19 21:20:33 itojun Exp $ */
/*
@ -751,7 +751,6 @@ grab_myaddrs(void)
{
struct ifaddrs *ifap, *ifa;
struct myaddrs *p;
struct sockaddr_in6 *sin6;
if (getifaddrs(&ifap) != 0) {
exit_failure("getifaddrs");
@ -776,19 +775,11 @@ grab_myaddrs(void)
memcpy(p + 1, ifa->ifa_addr, ifa->ifa_addr->sa_len);
p->next = myaddrs;
p->addr = (void *)(p + 1);
#ifdef __KAME__
if (ifa->ifa_addr->sa_family == AF_INET6) {
sin6 = (void *)p->addr;
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)
|| IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
sin6->sin6_scope_id =
ntohs(*(uint16_t *)(void *)
&sin6->sin6_addr.s6_addr[3]);
sin6->sin6_addr.s6_addr[2] = 0;
sin6->sin6_addr.s6_addr[3] = 0;
}
struct sockaddr_in6 *sin6 = (void *)p->addr;
inet6_getscopeid(sin6, INET6_IS_ADDR_LINKLOCAL|
INET6_IS_ADDR_SITELOCAL);
}
#endif
myaddrs = p;
if (dflag) {
char hbuf[NI_MAXHOST];

View File

@ -1,4 +1,4 @@
/* $NetBSD: ifmcstat.c,v 1.11 2012/10/26 16:52:52 seanb Exp $ */
/* $NetBSD: ifmcstat.c,v 1.12 2013/10/19 17:16:25 christos Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -110,21 +110,14 @@ const char *inet6_n2a(p)
{
static char buf[NI_MAXHOST];
struct sockaddr_in6 sin6;
u_int32_t scopeid;
const int niflags = NI_NUMERICHOST;
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_family = AF_INET6;
sin6.sin6_len = sizeof(struct sockaddr_in6);
sin6.sin6_addr = *p;
if (IN6_IS_ADDR_LINKLOCAL(p) || IN6_IS_ADDR_MC_LINKLOCAL(p)) {
scopeid = ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]);
if (scopeid) {
sin6.sin6_scope_id = scopeid;
sin6.sin6_addr.s6_addr[2] = 0;
sin6.sin6_addr.s6_addr[3] = 0;
}
}
inet6_getscopeid(&sin6, INET6_IS_ADDR_LINKLOCAL|
INET6_IS_ADDR_MC_LINKLOCAL);
if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len,
buf, sizeof(buf), NULL, 0, niflags) == 0)
return buf;

View File

@ -1,4 +1,4 @@
/* $NetBSD: common.c,v 1.40 2009/07/13 19:05:41 roy Exp $ */
/* $NetBSD: common.c,v 1.41 2013/10/19 17:16:25 christos Exp $ */
/*
* Copyright (c) 1983, 1993
@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)common.c 8.5 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: common.c,v 1.40 2009/07/13 19:05:41 roy Exp $");
__RCSID("$NetBSD: common.c,v 1.41 2013/10/19 17:16:25 christos Exp $");
#endif
#endif /* not lint */
@ -396,27 +396,15 @@ checkremote(void)
rname, sizeof(rname), NULL, 0, niflags) != 0)
continue;
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
#ifdef __KAME__
sin6p = (struct sockaddr_in6 *)ifa->ifa_addr;
if (ifa->ifa_addr->sa_family == AF_INET6 &&
ifa->ifa_addr->sa_len == sizeof(sin6) &&
IN6_IS_ADDR_LINKLOCAL(&sin6p->sin6_addr) &&
*(u_int16_t *)&sin6p->sin6_addr.s6_addr[2]) {
/* kame scopeid hack */
memcpy(&sin6, ifa->ifa_addr, sizeof(sin6));
sin6.sin6_scope_id =
ntohs(*(u_int16_t *)&sin6p->sin6_addr.s6_addr[2]);
sin6.sin6_addr.s6_addr[2] = 0;
sin6.sin6_addr.s6_addr[3] = 0;
ifa->ifa_addr->sa_len == sizeof(sin6)) {
inet6_getscopeid(sin6p, 3);
if (getnameinfo((struct sockaddr *)&sin6,
sin6.sin6_len, lname, sizeof(lname),
NULL, 0, niflags) != 0)
continue;
} else
#endif
if (getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len,
lname, sizeof(lname), NULL, 0, niflags) != 0)
continue;
}
if (strcmp(rname, lname) == 0) {
remote = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ndp.c,v 1.40 2011/08/31 13:32:38 joerg Exp $ */
/* $NetBSD: ndp.c,v 1.41 2013/10/19 17:16:25 christos Exp $ */
/* $KAME: ndp.c,v 1.121 2005/07/13 11:30:13 keiichi Exp $ */
/*
@ -357,12 +357,7 @@ set(int argc, char **argv)
return 1;
}
mysin->sin6_addr = ((struct sockaddr_in6 *)(void *)res->ai_addr)->sin6_addr;
#ifdef __KAME__
if (IN6_IS_ADDR_LINKLOCAL(&mysin->sin6_addr)) {
*(u_int16_t *)(void *)&mysin->sin6_addr.s6_addr[2] =
htons(((struct sockaddr_in6 *)(void *)res->ai_addr)->sin6_scope_id);
}
#endif
inet6_putscopeid(mysin, INET6_IS_ADDR_LINKLOCAL);
ea = (u_char *)LLADDR(&sdl_m);
if (ndp_ether_aton(eaddr, ea) == 0)
sdl_m.sdl_alen = 6;
@ -429,12 +424,7 @@ get(char *host)
return;
}
mysin->sin6_addr = ((struct sockaddr_in6 *)(void *)res->ai_addr)->sin6_addr;
#ifdef __KAME__
if (IN6_IS_ADDR_LINKLOCAL(&mysin->sin6_addr)) {
*(u_int16_t *)(void *)&mysin->sin6_addr.s6_addr[2] =
htons(((struct sockaddr_in6 *)(void *)res->ai_addr)->sin6_scope_id);
}
#endif
inet6_putscopeid(mysin, INET6_IS_ADDR_LINKLOCAL);
dump(&mysin->sin6_addr, 0);
if (found_entry == 0) {
(void)getnameinfo((struct sockaddr *)(void *)mysin,
@ -468,12 +458,7 @@ delete(char *host)
return 1;
}
mysin->sin6_addr = ((struct sockaddr_in6 *)(void *)res->ai_addr)->sin6_addr;
#ifdef __KAME__
if (IN6_IS_ADDR_LINKLOCAL(&mysin->sin6_addr)) {
*(u_int16_t *)(void *)&mysin->sin6_addr.s6_addr[2] =
htons(((struct sockaddr_in6 *)(void *)res->ai_addr)->sin6_scope_id);
}
#endif
inet6_putscopeid(mysin, INET6_IS_ADDR_LINKLOCAL);
if (rtmsg(RTM_GET) < 0)
errx(1, "RTM_GET(%s) failed", host);
mysin = (struct sockaddr_in6 *)(void *)(rtm + 1);
@ -500,12 +485,8 @@ delete:
if (rtmsg(RTM_DELETE) == 0) {
struct sockaddr_in6 s6 = *mysin; /* XXX: for safety */
#ifdef __KAME__
if (IN6_IS_ADDR_LINKLOCAL(&s6.sin6_addr)) {
s6.sin6_scope_id = ntohs(*(u_int16_t *)(void *)&s6.sin6_addr.s6_addr[2]);
*(u_int16_t *)(void *)&s6.sin6_addr.s6_addr[2] = 0;
}
#endif
mysin->sin6_scope_id = 0;
inet6_putscopeid(mysin, INET6_IS_ADDR_LINKLOCAL);
(void)getnameinfo((struct sockaddr *)(void *)&s6,
(socklen_t)s6.sin6_len, host_buf,
sizeof(host_buf), NULL, 0,
@ -598,13 +579,11 @@ again:;
continue;
if (IN6_IS_ADDR_LINKLOCAL(&mysin->sin6_addr) ||
IN6_IS_ADDR_MC_LINKLOCAL(&mysin->sin6_addr)) {
/* XXX: should scope id be filled in the kernel? */
if (mysin->sin6_scope_id == 0)
uint16_t scopeid = mysin->sin6_scope_id;
inet6_getscopeid(mysin, INET6_IS_ADDR_LINKLOCAL|
INET6_IS_ADDR_MC_LINKLOCAL);
if (scopeid == 0)
mysin->sin6_scope_id = sdl->sdl_index;
#ifdef __KAME__
/* KAME specific hack; removed the embedded id */
*(u_int16_t *)(void *)&mysin->sin6_addr.s6_addr[2] = 0;
#endif
}
(void)getnameinfo((struct sockaddr *)(void *)mysin,
(socklen_t)mysin->sin6_len,

View File

@ -1,4 +1,4 @@
/* $NetBSD: util.c,v 1.16 2009/01/18 10:17:38 lukem Exp $ */
/* $NetBSD: util.c,v 1.17 2013/10/19 17:16:25 christos Exp $ */
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@ -55,9 +55,6 @@ static struct sockaddr_in6 *local_in6;
#endif
static int bitmaskcmp(void *, void *, void *, int);
#ifdef INET6
static void in6_fillscopeid(struct sockaddr_in6 *);
#endif
/*
* For all bits set in "mask", compare the corresponding bits in
@ -83,21 +80,6 @@ bitmaskcmp(void *dst, void *src, void *mask, int bytelen)
return 0;
}
/*
* Taken from ifconfig.c
*/
#ifdef INET6
static void
in6_fillscopeid(struct sockaddr_in6 *sin6)
{
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
sin6->sin6_scope_id =
ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]);
sin6->sin6_addr.s6_addr[2] = sin6->sin6_addr.s6_addr[3] = 0;
}
}
#endif
char *
addrmerge(struct netbuf *caller, char *serv_uaddr, char *clnt_uaddr,
char *netid)
@ -218,7 +200,7 @@ addrmerge(struct netbuf *caller, char *serv_uaddr, char *clnt_uaddr,
*/
realsin6 = (struct sockaddr_in6 *)clnt;
ifsin6 = (struct sockaddr_in6 *)ifap->ifa_addr;
in6_fillscopeid(ifsin6);
inet6_getscopeid(ifsin6, 1);
clntsin6 = (struct sockaddr_in6 *)clnt_sa;
servsin6 = (struct sockaddr_in6 *)serv_sa;
sin6mask = (struct sockaddr_in6 *)ifap->ifa_netmask;