2009-08-07 22:53:37 +04:00
|
|
|
/* $NetBSD: af_inet6.c,v 1.24 2009/08/07 18:53:37 dyoung Exp $ */
|
2005-03-20 04:09:16 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. 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 University 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 REGENTS 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 REGENTS 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/cdefs.h>
|
|
|
|
#ifndef lint
|
2009-08-07 22:53:37 +04:00
|
|
|
__RCSID("$NetBSD: af_inet6.c,v 1.24 2009/08/07 18:53:37 dyoung Exp $");
|
2005-03-20 04:09:16 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet6/nd6.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2006-08-26 22:14:28 +04:00
|
|
|
#include <util.h>
|
2005-03-20 04:09:16 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
#include "env.h"
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
#include "extern.h"
|
2008-05-06 08:33:42 +04:00
|
|
|
#include "parse.h"
|
2005-03-20 04:09:16 +03:00
|
|
|
#include "extern.h"
|
2008-05-08 11:13:20 +04:00
|
|
|
#include "af_inetany.h"
|
2005-03-20 04:09:16 +03:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static void in6_constructor(void) __attribute__((constructor));
|
|
|
|
static void in6_alias(const char *, prop_dictionary_t, prop_dictionary_t,
|
|
|
|
struct in6_ifreq *);
|
|
|
|
static void in6_commit_address(prop_dictionary_t, prop_dictionary_t);
|
|
|
|
|
|
|
|
static int setia6eui64_impl(prop_dictionary_t, struct in6_aliasreq *);
|
|
|
|
static int setia6flags_impl(prop_dictionary_t, struct in6_aliasreq *);
|
|
|
|
static int setia6pltime_impl(prop_dictionary_t, struct in6_aliasreq *);
|
|
|
|
static int setia6vltime_impl(prop_dictionary_t, struct in6_aliasreq *);
|
|
|
|
|
|
|
|
static int setia6lifetime(prop_dictionary_t, int64_t, time_t *, uint32_t *);
|
|
|
|
|
|
|
|
static void in6_delscopeid(struct sockaddr_in6 *sin6);
|
|
|
|
static void in6_status(prop_dictionary_t, prop_dictionary_t, bool);
|
|
|
|
|
2008-07-16 00:56:13 +04:00
|
|
|
static struct usage_func usage;
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static cmdloop_branch_t branch[2];
|
|
|
|
|
2008-05-08 01:29:27 +04:00
|
|
|
static const struct kwinst ia6flagskw[] = {
|
|
|
|
IFKW("anycast", IN6_IFF_ANYCAST)
|
|
|
|
, IFKW("tentative", IN6_IFF_TENTATIVE)
|
|
|
|
, IFKW("deprecated", IN6_IFF_DEPRECATED)
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pinteger parse_pltime = PINTEGER_INITIALIZER(&parse_pltime,
|
2008-05-12 02:12:04 +04:00
|
|
|
"pltime", 0, NULL, "pltime", &command_root.pb_parser);
|
2008-05-08 01:29:27 +04:00
|
|
|
|
|
|
|
static struct pinteger parse_vltime = PINTEGER_INITIALIZER(&parse_vltime,
|
2008-05-12 02:12:04 +04:00
|
|
|
"vltime", 0, NULL, "vltime", &command_root.pb_parser);
|
2008-05-08 01:29:27 +04:00
|
|
|
|
|
|
|
static const struct kwinst inet6kw[] = {
|
|
|
|
{.k_word = "pltime", .k_nextparser = &parse_pltime.pi_parser}
|
|
|
|
, {.k_word = "vltime", .k_nextparser = &parse_vltime.pi_parser}
|
2008-05-12 02:07:23 +04:00
|
|
|
, {.k_word = "eui64", .k_key = "eui64", .k_type = KW_T_BOOL,
|
2008-05-12 02:12:04 +04:00
|
|
|
.k_bool = true, .k_nextparser = &command_root.pb_parser}
|
2008-05-08 01:29:27 +04:00
|
|
|
};
|
|
|
|
|
2008-05-12 02:12:04 +04:00
|
|
|
struct pkw ia6flags = PKW_INITIALIZER(&ia6flags, "ia6flags", NULL,
|
2008-05-08 01:29:27 +04:00
|
|
|
"ia6flag", ia6flagskw, __arraycount(ia6flagskw), &command_root.pb_parser);
|
|
|
|
struct pkw inet6 = PKW_INITIALIZER(&inet6, "IPv6 keywords", NULL,
|
|
|
|
NULL, inet6kw, __arraycount(inet6kw), NULL);
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static struct afswtch in6af = {
|
|
|
|
.af_name = "inet6", .af_af = AF_INET6, .af_status = in6_status,
|
|
|
|
.af_addr_commit = in6_commit_address
|
|
|
|
};
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2005-03-20 04:09:16 +03:00
|
|
|
static int
|
|
|
|
prefix(void *val, int size)
|
|
|
|
{
|
|
|
|
u_char *pname = (u_char *)val;
|
|
|
|
int byte, bit, plen = 0;
|
|
|
|
|
|
|
|
for (byte = 0; byte < size; byte++, plen += 8)
|
|
|
|
if (pname[byte] != 0xff)
|
|
|
|
break;
|
|
|
|
if (byte == size)
|
|
|
|
return (plen);
|
|
|
|
for (bit = 7; bit != 0; bit--, plen++)
|
|
|
|
if (!(pname[byte] & (1 << bit)))
|
|
|
|
break;
|
|
|
|
for (; bit != 0; bit--)
|
|
|
|
if (pname[byte] & (1 << bit))
|
|
|
|
return(0);
|
|
|
|
byte++;
|
|
|
|
for (; byte < size; byte++)
|
|
|
|
if (pname[byte])
|
|
|
|
return(0);
|
|
|
|
return (plen);
|
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
int
|
|
|
|
setia6flags_impl(prop_dictionary_t env, struct in6_aliasreq *ifra)
|
2005-03-20 04:09:16 +03:00
|
|
|
{
|
2008-05-07 01:13:20 +04:00
|
|
|
int64_t ia6flag;
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-07 01:13:20 +04:00
|
|
|
if (!prop_dictionary_get_int64(env, "ia6flag", &ia6flag)) {
|
2008-05-06 08:33:42 +04:00
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
2005-03-20 04:09:16 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if (ia6flag < 0) {
|
|
|
|
ia6flag = -ia6flag;
|
|
|
|
ifra->ifra_flags &= ~ia6flag;
|
2005-03-20 04:09:16 +03:00
|
|
|
} else
|
2008-05-06 08:33:42 +04:00
|
|
|
ifra->ifra_flags |= ia6flag;
|
|
|
|
return 0;
|
2005-03-20 04:09:16 +03:00
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
int
|
|
|
|
setia6pltime_impl(prop_dictionary_t env, struct in6_aliasreq *ifra)
|
2005-03-20 04:09:16 +03:00
|
|
|
{
|
2008-05-07 01:13:20 +04:00
|
|
|
int64_t pltime;
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-07 01:13:20 +04:00
|
|
|
if (!prop_dictionary_get_int64(env, "pltime", &pltime)) {
|
2008-05-06 08:33:42 +04:00
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
2005-03-20 04:09:16 +03:00
|
|
|
|
2008-05-07 01:13:20 +04:00
|
|
|
return setia6lifetime(env, pltime,
|
2008-05-06 08:33:42 +04:00
|
|
|
&ifra->ifra_lifetime.ia6t_preferred,
|
|
|
|
&ifra->ifra_lifetime.ia6t_pltime);
|
2005-03-20 04:09:16 +03:00
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
int
|
|
|
|
setia6vltime_impl(prop_dictionary_t env, struct in6_aliasreq *ifra)
|
2005-03-20 04:09:16 +03:00
|
|
|
{
|
2008-05-07 01:13:20 +04:00
|
|
|
int64_t vltime;
|
2008-05-06 08:33:42 +04:00
|
|
|
|
2008-05-07 01:13:20 +04:00
|
|
|
if (!prop_dictionary_get_int64(env, "vltime", &vltime)) {
|
2008-05-06 08:33:42 +04:00
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
2005-03-20 04:09:16 +03:00
|
|
|
|
2008-05-07 01:13:20 +04:00
|
|
|
return setia6lifetime(env, vltime,
|
2008-05-06 08:33:42 +04:00
|
|
|
&ifra->ifra_lifetime.ia6t_expire,
|
|
|
|
&ifra->ifra_lifetime.ia6t_vltime);
|
2005-03-20 04:09:16 +03:00
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
static int
|
|
|
|
setia6lifetime(prop_dictionary_t env, int64_t val, time_t *timep,
|
|
|
|
uint32_t *ivalp)
|
2005-03-20 04:09:16 +03:00
|
|
|
{
|
2008-05-06 08:33:42 +04:00
|
|
|
time_t t;
|
|
|
|
int af;
|
2005-03-20 04:09:16 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if ((af = getaf(env)) == -1 || af != AF_INET6) {
|
|
|
|
errx(EXIT_FAILURE,
|
|
|
|
"inet6 address lifetime not allowed for the AF");
|
2005-03-20 04:09:16 +03:00
|
|
|
}
|
2008-05-06 08:33:42 +04:00
|
|
|
|
|
|
|
t = time(NULL);
|
|
|
|
*timep = t + val;
|
|
|
|
*ivalp = val;
|
|
|
|
return 0;
|
2005-03-20 04:09:16 +03:00
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
int
|
|
|
|
setia6eui64_impl(prop_dictionary_t env, struct in6_aliasreq *ifra)
|
2005-03-20 04:09:16 +03:00
|
|
|
{
|
2008-05-12 02:07:23 +04:00
|
|
|
char buf[2][80];
|
2005-03-20 04:09:16 +03:00
|
|
|
struct ifaddrs *ifap, *ifa;
|
|
|
|
const struct sockaddr_in6 *sin6 = NULL;
|
|
|
|
const struct in6_addr *lladdr = NULL;
|
|
|
|
struct in6_addr *in6;
|
2008-05-06 08:33:42 +04:00
|
|
|
const char *ifname;
|
2008-05-12 02:07:23 +04:00
|
|
|
bool doit = false;
|
2008-05-06 08:33:42 +04:00
|
|
|
int af;
|
|
|
|
|
2008-05-12 02:07:23 +04:00
|
|
|
if (!prop_dictionary_get_bool(env, "eui64", &doit) || !doit) {
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if ((ifname = getifname(env)) == NULL)
|
|
|
|
return -1;
|
2005-03-20 04:09:16 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
af = getaf(env);
|
|
|
|
if (af != AF_INET6) {
|
|
|
|
errx(EXIT_FAILURE,
|
|
|
|
"eui64 address modifier not allowed for the AF");
|
|
|
|
}
|
|
|
|
in6 = &ifra->ifra_addr.sin6_addr;
|
2008-05-12 02:07:23 +04:00
|
|
|
if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0) {
|
|
|
|
union {
|
|
|
|
struct sockaddr_in6 sin6;
|
|
|
|
struct sockaddr sa;
|
|
|
|
} any = {.sin6 = {.sin6_family = AF_INET6}};
|
|
|
|
memcpy(&any.sin6.sin6_addr, &in6addr_any,
|
|
|
|
sizeof(any.sin6.sin6_addr));
|
|
|
|
(void)sockaddr_snprintf(buf[0], sizeof(buf[0]), "%a%%S",
|
|
|
|
&any.sa);
|
|
|
|
(void)sockaddr_snprintf(buf[1], sizeof(buf[1]), "%a%%S",
|
|
|
|
(const struct sockaddr *)&ifra->ifra_addr);
|
|
|
|
errx(EXIT_FAILURE, "interface index is already filled, %s | %s",
|
|
|
|
buf[0], buf[1]);
|
|
|
|
}
|
2005-03-20 04:09:16 +03:00
|
|
|
if (getifaddrs(&ifap) != 0)
|
|
|
|
err(EXIT_FAILURE, "getifaddrs");
|
|
|
|
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
|
|
|
if (ifa->ifa_addr->sa_family == AF_INET6 &&
|
2008-05-06 08:33:42 +04:00
|
|
|
strcmp(ifa->ifa_name, ifname) == 0) {
|
2005-03-20 04:09:16 +03:00
|
|
|
sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr;
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
|
|
|
lladdr = &sin6->sin6_addr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!lladdr)
|
|
|
|
errx(EXIT_FAILURE, "could not determine link local address");
|
|
|
|
|
|
|
|
memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8);
|
|
|
|
|
|
|
|
freeifaddrs(ifap);
|
2008-05-06 08:33:42 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-12 02:07:23 +04:00
|
|
|
/* KAME idiosyncrasy */
|
|
|
|
static void
|
|
|
|
in6_delscopeid(struct sockaddr_in6 *sin6)
|
|
|
|
{
|
|
|
|
if (!IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) ||
|
|
|
|
sin6->sin6_scope_id == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*(u_int16_t *)&sin6->sin6_addr.s6_addr[2] = htons(sin6->sin6_scope_id);
|
|
|
|
sin6->sin6_scope_id = 0;
|
|
|
|
}
|
|
|
|
|
2005-03-20 04:09:16 +03:00
|
|
|
/* XXX not really an alias */
|
|
|
|
void
|
2008-05-06 08:33:42 +04:00
|
|
|
in6_alias(const char *ifname, prop_dictionary_t env, prop_dictionary_t oenv,
|
|
|
|
struct in6_ifreq *creq)
|
2005-03-20 04:09:16 +03:00
|
|
|
{
|
2008-05-06 08:33:42 +04:00
|
|
|
struct in6_ifreq ifr6;
|
2005-03-20 04:09:16 +03:00
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
char hbuf[NI_MAXHOST];
|
|
|
|
u_int32_t scopeid;
|
2008-05-06 08:33:42 +04:00
|
|
|
int s;
|
2009-08-07 22:53:37 +04:00
|
|
|
const int niflag = Nflag ? 0 : NI_NUMERICHOST;
|
2008-05-06 08:33:42 +04:00
|
|
|
unsigned short flags;
|
2005-03-20 04:09:16 +03:00
|
|
|
|
|
|
|
/* Get the non-alias address for this interface. */
|
2008-05-06 08:33:42 +04:00
|
|
|
if ((s = getsock(AF_INET6)) == -1) {
|
2006-06-14 15:05:42 +04:00
|
|
|
if (errno == EAFNOSUPPORT)
|
2005-03-20 04:09:16 +03:00
|
|
|
return;
|
|
|
|
err(EXIT_FAILURE, "socket");
|
|
|
|
}
|
|
|
|
|
2008-05-12 02:18:20 +04:00
|
|
|
sin6 = &creq->ifr_addr;
|
2005-03-20 04:09:16 +03:00
|
|
|
|
|
|
|
in6_fillscopeid(sin6);
|
|
|
|
scopeid = sin6->sin6_scope_id;
|
2008-05-12 02:30:07 +04:00
|
|
|
if (getnameinfo((const struct sockaddr *)sin6, sin6->sin6_len,
|
2005-03-20 04:09:16 +03:00
|
|
|
hbuf, sizeof(hbuf), NULL, 0, niflag))
|
|
|
|
strlcpy(hbuf, "", sizeof(hbuf)); /* some message? */
|
|
|
|
printf("\tinet6 %s", hbuf);
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if (getifflags(env, oenv, &flags) == -1)
|
|
|
|
err(EXIT_FAILURE, "%s: getifflags", __func__);
|
|
|
|
|
2005-03-20 04:09:16 +03:00
|
|
|
if (flags & IFF_POINTOPOINT) {
|
2008-05-12 02:30:07 +04:00
|
|
|
ifr6 = *creq;
|
2005-03-20 04:09:16 +03:00
|
|
|
if (ioctl(s, SIOCGIFDSTADDR_IN6, &ifr6) == -1) {
|
|
|
|
if (errno != EADDRNOTAVAIL)
|
|
|
|
warn("SIOCGIFDSTADDR_IN6");
|
2008-04-24 09:29:40 +04:00
|
|
|
memset(&ifr6.ifr_addr, 0, sizeof(ifr6.ifr_addr));
|
2005-03-20 04:09:16 +03:00
|
|
|
ifr6.ifr_addr.sin6_family = AF_INET6;
|
|
|
|
ifr6.ifr_addr.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
}
|
2008-05-12 02:18:20 +04:00
|
|
|
sin6 = &ifr6.ifr_addr;
|
2005-03-20 04:09:16 +03:00
|
|
|
in6_fillscopeid(sin6);
|
|
|
|
hbuf[0] = '\0';
|
|
|
|
if (getnameinfo((struct sockaddr *)sin6, sin6->sin6_len,
|
|
|
|
hbuf, sizeof(hbuf), NULL, 0, niflag))
|
|
|
|
strlcpy(hbuf, "", sizeof(hbuf)); /* some message? */
|
|
|
|
printf(" -> %s", hbuf);
|
|
|
|
}
|
|
|
|
|
2008-05-12 02:30:07 +04:00
|
|
|
ifr6 = *creq;
|
2005-03-20 04:09:16 +03:00
|
|
|
if (ioctl(s, SIOCGIFNETMASK_IN6, &ifr6) == -1) {
|
|
|
|
if (errno != EADDRNOTAVAIL)
|
|
|
|
warn("SIOCGIFNETMASK_IN6");
|
|
|
|
} else {
|
2008-05-12 02:18:20 +04:00
|
|
|
sin6 = &ifr6.ifr_addr;
|
2005-03-20 04:09:16 +03:00
|
|
|
printf(" prefixlen %d", prefix(&sin6->sin6_addr,
|
|
|
|
sizeof(struct in6_addr)));
|
|
|
|
}
|
|
|
|
|
2008-05-12 02:30:07 +04:00
|
|
|
ifr6 = *creq;
|
2005-03-20 04:09:16 +03:00
|
|
|
if (ioctl(s, SIOCGIFAFLAG_IN6, &ifr6) == -1) {
|
|
|
|
if (errno != EADDRNOTAVAIL)
|
|
|
|
warn("SIOCGIFAFLAG_IN6");
|
|
|
|
} else {
|
|
|
|
if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_ANYCAST)
|
|
|
|
printf(" anycast");
|
|
|
|
if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_TENTATIVE)
|
|
|
|
printf(" tentative");
|
|
|
|
if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_DUPLICATED)
|
|
|
|
printf(" duplicated");
|
|
|
|
if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_DETACHED)
|
|
|
|
printf(" detached");
|
|
|
|
if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_DEPRECATED)
|
|
|
|
printf(" deprecated");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scopeid)
|
|
|
|
printf(" scopeid 0x%x", scopeid);
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
if (get_flag('L')) {
|
2005-03-20 04:09:16 +03:00
|
|
|
struct in6_addrlifetime *lifetime;
|
2008-05-12 02:30:07 +04:00
|
|
|
ifr6 = *creq;
|
2005-03-20 04:09:16 +03:00
|
|
|
lifetime = &ifr6.ifr_ifru.ifru_lifetime;
|
|
|
|
if (ioctl(s, SIOCGIFALIFETIME_IN6, &ifr6) == -1) {
|
|
|
|
if (errno != EADDRNOTAVAIL)
|
|
|
|
warn("SIOCGIFALIFETIME_IN6");
|
|
|
|
} else if (lifetime->ia6t_preferred || lifetime->ia6t_expire) {
|
|
|
|
time_t t = time(NULL);
|
|
|
|
printf(" pltime ");
|
|
|
|
if (lifetime->ia6t_preferred) {
|
2008-05-12 03:27:32 +04:00
|
|
|
printf("%lu",
|
|
|
|
(unsigned long)(lifetime->ia6t_preferred -
|
|
|
|
MIN(t, lifetime->ia6t_preferred)));
|
2005-03-20 04:09:16 +03:00
|
|
|
} else
|
|
|
|
printf("infty");
|
|
|
|
|
|
|
|
printf(" vltime ");
|
|
|
|
if (lifetime->ia6t_expire) {
|
2008-05-12 03:27:32 +04:00
|
|
|
printf("%lu",
|
|
|
|
(unsigned long)(lifetime->ia6t_expire -
|
|
|
|
MIN(t, lifetime->ia6t_expire)));
|
2005-03-20 04:09:16 +03:00
|
|
|
} else
|
|
|
|
printf("infty");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static void
|
2008-05-06 20:15:17 +04:00
|
|
|
in6_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force)
|
2005-03-20 04:09:16 +03:00
|
|
|
{
|
|
|
|
struct ifaddrs *ifap, *ifa;
|
2008-05-06 08:33:42 +04:00
|
|
|
struct in6_ifreq ifr;
|
|
|
|
const char *ifname;
|
|
|
|
|
|
|
|
if ((ifname = getifname(env)) == NULL)
|
|
|
|
err(EXIT_FAILURE, "%s: getifname", __func__);
|
2005-03-20 04:09:16 +03:00
|
|
|
|
|
|
|
if (getifaddrs(&ifap) != 0)
|
|
|
|
err(EXIT_FAILURE, "getifaddrs");
|
|
|
|
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
2008-05-06 08:33:42 +04:00
|
|
|
if (strcmp(ifname, ifa->ifa_name) != 0)
|
2005-03-20 04:09:16 +03:00
|
|
|
continue;
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_INET6)
|
|
|
|
continue;
|
2008-05-06 08:33:42 +04:00
|
|
|
if (sizeof(ifr.ifr_addr) < ifa->ifa_addr->sa_len)
|
2005-03-20 04:09:16 +03:00
|
|
|
continue;
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
estrlcpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name));
|
|
|
|
memcpy(&ifr.ifr_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len);
|
|
|
|
in6_alias(ifname, env, oenv, &ifr);
|
2005-03-20 04:09:16 +03:00
|
|
|
}
|
|
|
|
freeifaddrs(ifap);
|
|
|
|
}
|
|
|
|
|
2008-05-08 11:13:20 +04:00
|
|
|
static int
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
in6_pre_aifaddr(prop_dictionary_t env, const struct afparam *param)
|
2008-05-08 11:13:20 +04:00
|
|
|
{
|
2008-05-12 02:07:23 +04:00
|
|
|
struct in6_aliasreq *ifra = param->req.buf;
|
2008-05-08 11:13:20 +04:00
|
|
|
|
|
|
|
setia6eui64_impl(env, ifra);
|
|
|
|
setia6vltime_impl(env, ifra);
|
|
|
|
setia6pltime_impl(env, ifra);
|
|
|
|
setia6flags_impl(env, ifra);
|
2008-05-12 02:07:23 +04:00
|
|
|
in6_delscopeid(&ifra->ifra_addr);
|
|
|
|
in6_delscopeid(&ifra->ifra_dstaddr);
|
2008-05-08 11:13:20 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static void
|
2008-05-08 11:13:20 +04:00
|
|
|
in6_commit_address(prop_dictionary_t env, prop_dictionary_t oenv)
|
|
|
|
{
|
2008-05-12 02:07:23 +04:00
|
|
|
struct in6_ifreq in6_ifr = {
|
2008-05-08 11:13:20 +04:00
|
|
|
.ifr_addr = {
|
|
|
|
.sin6_family = AF_INET6,
|
2008-05-12 19:35:50 +04:00
|
|
|
.sin6_len = sizeof(in6_ifr.ifr_addr),
|
2008-05-08 11:13:20 +04:00
|
|
|
.sin6_addr = {
|
|
|
|
.s6_addr =
|
|
|
|
{0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static struct sockaddr_in6 in6_defmask = {
|
2008-05-12 19:35:50 +04:00
|
|
|
.sin6_family = AF_INET6,
|
|
|
|
.sin6_len = sizeof(in6_defmask),
|
2008-05-08 11:13:20 +04:00
|
|
|
.sin6_addr = {
|
|
|
|
.s6_addr = {0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-12 02:07:23 +04:00
|
|
|
struct in6_aliasreq in6_ifra = {
|
2008-05-08 11:13:20 +04:00
|
|
|
.ifra_prefixmask = {
|
2008-05-12 19:35:50 +04:00
|
|
|
.sin6_family = AF_INET6,
|
|
|
|
.sin6_len = sizeof(in6_ifra.ifra_prefixmask),
|
2008-05-08 11:13:20 +04:00
|
|
|
.sin6_addr = {
|
|
|
|
.s6_addr =
|
|
|
|
{0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff}}},
|
|
|
|
.ifra_lifetime = {
|
|
|
|
.ia6t_pltime = ND6_INFINITE_LIFETIME
|
|
|
|
, .ia6t_vltime = ND6_INFINITE_LIFETIME
|
|
|
|
}
|
|
|
|
};
|
|
|
|
struct afparam in6param = {
|
|
|
|
.req = BUFPARAM(in6_ifra)
|
|
|
|
, .dgreq = BUFPARAM(in6_ifr)
|
|
|
|
, .name = {
|
|
|
|
{.buf = in6_ifr.ifr_name,
|
|
|
|
.buflen = sizeof(in6_ifr.ifr_name)},
|
|
|
|
{.buf = in6_ifra.ifra_name,
|
|
|
|
.buflen = sizeof(in6_ifra.ifra_name)}
|
|
|
|
}
|
|
|
|
, .dgaddr = BUFPARAM(in6_ifr.ifr_addr)
|
|
|
|
, .addr = BUFPARAM(in6_ifra.ifra_addr)
|
|
|
|
, .dst = BUFPARAM(in6_ifra.ifra_dstaddr)
|
|
|
|
, .brd = BUFPARAM(in6_ifra.ifra_broadaddr)
|
|
|
|
, .mask = BUFPARAM(in6_ifra.ifra_prefixmask)
|
|
|
|
, .aifaddr = IFADDR_PARAM(SIOCAIFADDR_IN6)
|
|
|
|
, .difaddr = IFADDR_PARAM(SIOCDIFADDR_IN6)
|
|
|
|
, .gifaddr = IFADDR_PARAM(SIOCGIFADDR_IN6)
|
|
|
|
, .defmask = BUFPARAM(in6_defmask)
|
|
|
|
, .pre_aifaddr = in6_pre_aifaddr
|
|
|
|
};
|
|
|
|
commit_address(env, oenv, &in6param);
|
|
|
|
}
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
|
2008-07-16 00:56:13 +04:00
|
|
|
static void
|
|
|
|
in6_usage(prop_dictionary_t env)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"\t[ anycast | -anycast ] [ deprecated | -deprecated ]\n"
|
|
|
|
"\t[ tentative | -tentative ] [ pltime n ] [ vltime n ] "
|
|
|
|
"[ eui64 ]\n");
|
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static void
|
|
|
|
in6_constructor(void)
|
|
|
|
{
|
|
|
|
if (register_flag('L') != 0)
|
|
|
|
err(EXIT_FAILURE, __func__);
|
|
|
|
register_family(&in6af);
|
2008-07-16 00:56:13 +04:00
|
|
|
usage_func_init(&usage, in6_usage);
|
|
|
|
register_usage(&usage);
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
cmdloop_branch_init(&branch[0], &ia6flags.pk_parser);
|
|
|
|
cmdloop_branch_init(&branch[1], &inet6.pk_parser);
|
|
|
|
register_cmdloop_branch(&branch[0]);
|
|
|
|
register_cmdloop_branch(&branch[1]);
|
|
|
|
}
|