Home | History | Annotate | Line # | Download | only in ifconfig
af_inet6.c revision 1.5.18.1
      1  1.5.18.1       mjf /*	$NetBSD: af_inet6.c,v 1.5.18.1 2008/06/02 13:21:22 mjf Exp $	*/
      2       1.1   thorpej 
      3       1.1   thorpej /*
      4       1.1   thorpej  * Copyright (c) 1983, 1993
      5       1.1   thorpej  *      The Regents of the University of California.  All rights reserved.
      6       1.1   thorpej  *
      7       1.1   thorpej  * Redistribution and use in source and binary forms, with or without
      8       1.1   thorpej  * modification, are permitted provided that the following conditions
      9       1.1   thorpej  * are met:
     10       1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     11       1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     12       1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     14       1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     15       1.1   thorpej  * 3. Neither the name of the University nor the names of its contributors
     16       1.1   thorpej  *    may be used to endorse or promote products derived from this software
     17       1.1   thorpej  *    without specific prior written permission.
     18       1.1   thorpej  *
     19       1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20       1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23       1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.1   thorpej  * SUCH DAMAGE.
     30       1.1   thorpej  */
     31       1.1   thorpej 
     32       1.1   thorpej #include <sys/cdefs.h>
     33       1.1   thorpej #ifndef lint
     34  1.5.18.1       mjf __RCSID("$NetBSD: af_inet6.c,v 1.5.18.1 2008/06/02 13:21:22 mjf Exp $");
     35       1.1   thorpej #endif /* not lint */
     36       1.1   thorpej 
     37       1.1   thorpej #include <sys/param.h>
     38       1.1   thorpej #include <sys/ioctl.h>
     39       1.1   thorpej #include <sys/socket.h>
     40       1.1   thorpej 
     41       1.1   thorpej #include <net/if.h>
     42       1.1   thorpej #include <netinet/in.h>
     43       1.1   thorpej #include <netinet/in_var.h>
     44       1.1   thorpej #include <netinet6/nd6.h>
     45       1.1   thorpej 
     46       1.1   thorpej #include <err.h>
     47       1.1   thorpej #include <errno.h>
     48       1.1   thorpej #include <ifaddrs.h>
     49       1.1   thorpej #include <netdb.h>
     50       1.1   thorpej #include <string.h>
     51       1.1   thorpej #include <stdlib.h>
     52       1.1   thorpej #include <stdio.h>
     53       1.5  christos #include <util.h>
     54       1.1   thorpej 
     55  1.5.18.1       mjf #include "env.h"
     56  1.5.18.1       mjf #include "parse.h"
     57       1.1   thorpej #include "extern.h"
     58       1.1   thorpej #include "af_inet6.h"
     59  1.5.18.1       mjf #include "af_inetany.h"
     60       1.1   thorpej 
     61  1.5.18.1       mjf static const struct kwinst ia6flagskw[] = {
     62  1.5.18.1       mjf 	  IFKW("anycast",	IN6_IFF_ANYCAST)
     63  1.5.18.1       mjf 	, IFKW("tentative",	IN6_IFF_TENTATIVE)
     64  1.5.18.1       mjf 	, IFKW("deprecated",	IN6_IFF_DEPRECATED)
     65  1.5.18.1       mjf };
     66  1.5.18.1       mjf 
     67  1.5.18.1       mjf static struct pinteger parse_pltime = PINTEGER_INITIALIZER(&parse_pltime,
     68  1.5.18.1       mjf     "pltime", 0, NULL, "pltime", &command_root.pb_parser);
     69  1.5.18.1       mjf 
     70  1.5.18.1       mjf static struct pinteger parse_vltime = PINTEGER_INITIALIZER(&parse_vltime,
     71  1.5.18.1       mjf     "vltime", 0, NULL, "vltime", &command_root.pb_parser);
     72  1.5.18.1       mjf 
     73  1.5.18.1       mjf static const struct kwinst inet6kw[] = {
     74  1.5.18.1       mjf 	  {.k_word = "pltime", .k_nextparser = &parse_pltime.pi_parser}
     75  1.5.18.1       mjf 	, {.k_word = "vltime", .k_nextparser = &parse_vltime.pi_parser}
     76  1.5.18.1       mjf 	, {.k_word = "eui64", .k_key = "eui64", .k_type = KW_T_BOOL,
     77  1.5.18.1       mjf 	   .k_bool = true, .k_nextparser = &command_root.pb_parser}
     78  1.5.18.1       mjf };
     79  1.5.18.1       mjf 
     80  1.5.18.1       mjf struct pkw ia6flags = PKW_INITIALIZER(&ia6flags, "ia6flags", NULL,
     81  1.5.18.1       mjf     "ia6flag", ia6flagskw, __arraycount(ia6flagskw), &command_root.pb_parser);
     82  1.5.18.1       mjf struct pkw inet6 = PKW_INITIALIZER(&inet6, "IPv6 keywords", NULL,
     83  1.5.18.1       mjf     NULL, inet6kw, __arraycount(inet6kw), NULL);
     84  1.5.18.1       mjf 
     85  1.5.18.1       mjf static void in6_delscopeid(struct sockaddr_in6 *sin6);
     86  1.5.18.1       mjf static int setia6lifetime(prop_dictionary_t, int64_t, time_t *, uint32_t *);
     87  1.5.18.1       mjf static void in6_alias(const char *, prop_dictionary_t, prop_dictionary_t,
     88  1.5.18.1       mjf     struct in6_ifreq *);
     89       1.1   thorpej 
     90       1.1   thorpej static int
     91       1.1   thorpej prefix(void *val, int size)
     92       1.1   thorpej {
     93       1.1   thorpej 	u_char *pname = (u_char *)val;
     94       1.1   thorpej 	int byte, bit, plen = 0;
     95       1.1   thorpej 
     96       1.1   thorpej 	for (byte = 0; byte < size; byte++, plen += 8)
     97       1.1   thorpej 		if (pname[byte] != 0xff)
     98       1.1   thorpej 			break;
     99       1.1   thorpej 	if (byte == size)
    100       1.1   thorpej 		return (plen);
    101       1.1   thorpej 	for (bit = 7; bit != 0; bit--, plen++)
    102       1.1   thorpej 		if (!(pname[byte] & (1 << bit)))
    103       1.1   thorpej 			break;
    104       1.1   thorpej 	for (; bit != 0; bit--)
    105       1.1   thorpej 		if (pname[byte] & (1 << bit))
    106       1.1   thorpej 			return(0);
    107       1.1   thorpej 	byte++;
    108       1.1   thorpej 	for (; byte < size; byte++)
    109       1.1   thorpej 		if (pname[byte])
    110       1.1   thorpej 			return(0);
    111       1.1   thorpej 	return (plen);
    112       1.1   thorpej }
    113       1.1   thorpej 
    114  1.5.18.1       mjf int
    115  1.5.18.1       mjf setia6flags_impl(prop_dictionary_t env, struct in6_aliasreq *ifra)
    116       1.1   thorpej {
    117  1.5.18.1       mjf 	int64_t ia6flag;
    118  1.5.18.1       mjf 
    119  1.5.18.1       mjf 	if (!prop_dictionary_get_int64(env, "ia6flag", &ia6flag)) {
    120  1.5.18.1       mjf 		errno = ENOENT;
    121  1.5.18.1       mjf 		return -1;
    122  1.5.18.1       mjf 	}
    123       1.1   thorpej 
    124  1.5.18.1       mjf 	if (ia6flag < 0) {
    125  1.5.18.1       mjf 		ia6flag = -ia6flag;
    126  1.5.18.1       mjf 		ifra->ifra_flags &= ~ia6flag;
    127       1.1   thorpej 	} else
    128  1.5.18.1       mjf 		ifra->ifra_flags |= ia6flag;
    129  1.5.18.1       mjf 	return 0;
    130       1.1   thorpej }
    131       1.1   thorpej 
    132  1.5.18.1       mjf int
    133  1.5.18.1       mjf setia6pltime_impl(prop_dictionary_t env, struct in6_aliasreq *ifra)
    134       1.1   thorpej {
    135  1.5.18.1       mjf 	int64_t pltime;
    136  1.5.18.1       mjf 
    137  1.5.18.1       mjf 	if (!prop_dictionary_get_int64(env, "pltime", &pltime)) {
    138  1.5.18.1       mjf 		errno = ENOENT;
    139  1.5.18.1       mjf 		return -1;
    140  1.5.18.1       mjf 	}
    141       1.1   thorpej 
    142  1.5.18.1       mjf 	return setia6lifetime(env, pltime,
    143  1.5.18.1       mjf 	    &ifra->ifra_lifetime.ia6t_preferred,
    144  1.5.18.1       mjf 	    &ifra->ifra_lifetime.ia6t_pltime);
    145       1.1   thorpej }
    146       1.1   thorpej 
    147  1.5.18.1       mjf int
    148  1.5.18.1       mjf setia6vltime_impl(prop_dictionary_t env, struct in6_aliasreq *ifra)
    149       1.1   thorpej {
    150  1.5.18.1       mjf 	int64_t vltime;
    151  1.5.18.1       mjf 
    152  1.5.18.1       mjf 	if (!prop_dictionary_get_int64(env, "vltime", &vltime)) {
    153  1.5.18.1       mjf 		errno = ENOENT;
    154  1.5.18.1       mjf 		return -1;
    155  1.5.18.1       mjf 	}
    156       1.1   thorpej 
    157  1.5.18.1       mjf 	return setia6lifetime(env, vltime,
    158  1.5.18.1       mjf 		&ifra->ifra_lifetime.ia6t_expire,
    159  1.5.18.1       mjf 		&ifra->ifra_lifetime.ia6t_vltime);
    160       1.1   thorpej }
    161       1.1   thorpej 
    162  1.5.18.1       mjf static int
    163  1.5.18.1       mjf setia6lifetime(prop_dictionary_t env, int64_t val, time_t *timep,
    164  1.5.18.1       mjf     uint32_t *ivalp)
    165       1.1   thorpej {
    166  1.5.18.1       mjf 	time_t t;
    167  1.5.18.1       mjf 	int af;
    168       1.1   thorpej 
    169  1.5.18.1       mjf 	if ((af = getaf(env)) == -1 || af != AF_INET6) {
    170  1.5.18.1       mjf 		errx(EXIT_FAILURE,
    171  1.5.18.1       mjf 		    "inet6 address lifetime not allowed for the AF");
    172       1.1   thorpej 	}
    173  1.5.18.1       mjf 
    174  1.5.18.1       mjf 	t = time(NULL);
    175  1.5.18.1       mjf 	*timep = t + val;
    176  1.5.18.1       mjf 	*ivalp = val;
    177  1.5.18.1       mjf 	return 0;
    178       1.1   thorpej }
    179       1.1   thorpej 
    180  1.5.18.1       mjf int
    181  1.5.18.1       mjf setia6eui64_impl(prop_dictionary_t env, struct in6_aliasreq *ifra)
    182       1.1   thorpej {
    183  1.5.18.1       mjf 	char buf[2][80];
    184       1.1   thorpej 	struct ifaddrs *ifap, *ifa;
    185       1.1   thorpej 	const struct sockaddr_in6 *sin6 = NULL;
    186       1.1   thorpej 	const struct in6_addr *lladdr = NULL;
    187       1.1   thorpej 	struct in6_addr *in6;
    188  1.5.18.1       mjf 	const char *ifname;
    189  1.5.18.1       mjf 	bool doit = false;
    190  1.5.18.1       mjf 	int af;
    191  1.5.18.1       mjf 
    192  1.5.18.1       mjf 	if (!prop_dictionary_get_bool(env, "eui64", &doit) || !doit) {
    193  1.5.18.1       mjf 		errno = ENOENT;
    194  1.5.18.1       mjf 		return -1;
    195  1.5.18.1       mjf 	}
    196  1.5.18.1       mjf 
    197  1.5.18.1       mjf 	if ((ifname = getifname(env)) == NULL)
    198  1.5.18.1       mjf 		return -1;
    199  1.5.18.1       mjf 
    200  1.5.18.1       mjf 	af = getaf(env);
    201  1.5.18.1       mjf 	if (af != AF_INET6) {
    202  1.5.18.1       mjf 		errx(EXIT_FAILURE,
    203  1.5.18.1       mjf 		    "eui64 address modifier not allowed for the AF");
    204  1.5.18.1       mjf 	}
    205  1.5.18.1       mjf  	in6 = &ifra->ifra_addr.sin6_addr;
    206  1.5.18.1       mjf 	if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0) {
    207  1.5.18.1       mjf 		union {
    208  1.5.18.1       mjf 			struct sockaddr_in6 sin6;
    209  1.5.18.1       mjf 			struct sockaddr sa;
    210  1.5.18.1       mjf 		} any = {.sin6 = {.sin6_family = AF_INET6}};
    211  1.5.18.1       mjf 		memcpy(&any.sin6.sin6_addr, &in6addr_any,
    212  1.5.18.1       mjf 		    sizeof(any.sin6.sin6_addr));
    213  1.5.18.1       mjf 		(void)sockaddr_snprintf(buf[0], sizeof(buf[0]), "%a%%S",
    214  1.5.18.1       mjf 		    &any.sa);
    215  1.5.18.1       mjf 		(void)sockaddr_snprintf(buf[1], sizeof(buf[1]), "%a%%S",
    216  1.5.18.1       mjf 		    (const struct sockaddr *)&ifra->ifra_addr);
    217  1.5.18.1       mjf 		errx(EXIT_FAILURE, "interface index is already filled, %s | %s",
    218  1.5.18.1       mjf 		    buf[0], buf[1]);
    219  1.5.18.1       mjf 	}
    220       1.1   thorpej 	if (getifaddrs(&ifap) != 0)
    221       1.1   thorpej 		err(EXIT_FAILURE, "getifaddrs");
    222       1.1   thorpej 	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
    223       1.1   thorpej 		if (ifa->ifa_addr->sa_family == AF_INET6 &&
    224  1.5.18.1       mjf 		    strcmp(ifa->ifa_name, ifname) == 0) {
    225       1.1   thorpej 			sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr;
    226       1.1   thorpej 			if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
    227       1.1   thorpej 				lladdr = &sin6->sin6_addr;
    228       1.1   thorpej 				break;
    229       1.1   thorpej 			}
    230       1.1   thorpej 		}
    231       1.1   thorpej 	}
    232       1.1   thorpej 	if (!lladdr)
    233       1.1   thorpej 		errx(EXIT_FAILURE, "could not determine link local address");
    234       1.1   thorpej 
    235       1.1   thorpej  	memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8);
    236       1.1   thorpej 
    237       1.1   thorpej 	freeifaddrs(ifap);
    238  1.5.18.1       mjf 	return 0;
    239  1.5.18.1       mjf }
    240  1.5.18.1       mjf 
    241  1.5.18.1       mjf /* KAME idiosyncrasy */
    242  1.5.18.1       mjf static void
    243  1.5.18.1       mjf in6_delscopeid(struct sockaddr_in6 *sin6)
    244  1.5.18.1       mjf {
    245  1.5.18.1       mjf 	if (!IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) ||
    246  1.5.18.1       mjf 	    sin6->sin6_scope_id == 0)
    247  1.5.18.1       mjf 		return;
    248  1.5.18.1       mjf 
    249  1.5.18.1       mjf 	*(u_int16_t *)&sin6->sin6_addr.s6_addr[2] = htons(sin6->sin6_scope_id);
    250  1.5.18.1       mjf 	sin6->sin6_scope_id = 0;
    251       1.1   thorpej }
    252       1.1   thorpej 
    253  1.5.18.1       mjf /* KAME idiosyncrasy */
    254       1.1   thorpej void
    255       1.1   thorpej in6_fillscopeid(struct sockaddr_in6 *sin6)
    256       1.1   thorpej {
    257       1.1   thorpej 	if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
    258       1.1   thorpej 		sin6->sin6_scope_id =
    259       1.1   thorpej 			ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]);
    260       1.1   thorpej 		sin6->sin6_addr.s6_addr[2] = sin6->sin6_addr.s6_addr[3] = 0;
    261       1.1   thorpej 	}
    262       1.1   thorpej }
    263       1.1   thorpej 
    264       1.1   thorpej /* XXX not really an alias */
    265       1.1   thorpej void
    266  1.5.18.1       mjf in6_alias(const char *ifname, prop_dictionary_t env, prop_dictionary_t oenv,
    267  1.5.18.1       mjf     struct in6_ifreq *creq)
    268       1.1   thorpej {
    269  1.5.18.1       mjf 	struct in6_ifreq ifr6;
    270       1.1   thorpej 	struct sockaddr_in6 *sin6;
    271       1.1   thorpej 	char hbuf[NI_MAXHOST];
    272       1.1   thorpej 	u_int32_t scopeid;
    273  1.5.18.1       mjf 	int s;
    274       1.1   thorpej 	const int niflag = NI_NUMERICHOST;
    275  1.5.18.1       mjf 	unsigned short flags;
    276       1.1   thorpej 
    277       1.1   thorpej 	/* Get the non-alias address for this interface. */
    278  1.5.18.1       mjf 	if ((s = getsock(AF_INET6)) == -1) {
    279       1.3      tron 		if (errno == EAFNOSUPPORT)
    280       1.1   thorpej 			return;
    281       1.1   thorpej 		err(EXIT_FAILURE, "socket");
    282       1.1   thorpej 	}
    283       1.1   thorpej 
    284  1.5.18.1       mjf 	sin6 = &creq->ifr_addr;
    285       1.1   thorpej 
    286       1.1   thorpej 	in6_fillscopeid(sin6);
    287       1.1   thorpej 	scopeid = sin6->sin6_scope_id;
    288  1.5.18.1       mjf 	if (getnameinfo((const struct sockaddr *)sin6, sin6->sin6_len,
    289       1.1   thorpej 			hbuf, sizeof(hbuf), NULL, 0, niflag))
    290       1.1   thorpej 		strlcpy(hbuf, "", sizeof(hbuf));	/* some message? */
    291       1.1   thorpej 	printf("\tinet6 %s", hbuf);
    292       1.1   thorpej 
    293  1.5.18.1       mjf 	if (getifflags(env, oenv, &flags) == -1)
    294  1.5.18.1       mjf 		err(EXIT_FAILURE, "%s: getifflags", __func__);
    295  1.5.18.1       mjf 
    296       1.1   thorpej 	if (flags & IFF_POINTOPOINT) {
    297  1.5.18.1       mjf 		ifr6 = *creq;
    298       1.1   thorpej 		if (ioctl(s, SIOCGIFDSTADDR_IN6, &ifr6) == -1) {
    299       1.1   thorpej 			if (errno != EADDRNOTAVAIL)
    300       1.1   thorpej 				warn("SIOCGIFDSTADDR_IN6");
    301  1.5.18.1       mjf 			memset(&ifr6.ifr_addr, 0, sizeof(ifr6.ifr_addr));
    302       1.1   thorpej 			ifr6.ifr_addr.sin6_family = AF_INET6;
    303       1.1   thorpej 			ifr6.ifr_addr.sin6_len = sizeof(struct sockaddr_in6);
    304       1.1   thorpej 		}
    305  1.5.18.1       mjf 		sin6 = &ifr6.ifr_addr;
    306       1.1   thorpej 		in6_fillscopeid(sin6);
    307       1.1   thorpej 		hbuf[0] = '\0';
    308       1.1   thorpej 		if (getnameinfo((struct sockaddr *)sin6, sin6->sin6_len,
    309       1.1   thorpej 				hbuf, sizeof(hbuf), NULL, 0, niflag))
    310       1.1   thorpej 			strlcpy(hbuf, "", sizeof(hbuf)); /* some message? */
    311       1.1   thorpej 		printf(" -> %s", hbuf);
    312       1.1   thorpej 	}
    313       1.1   thorpej 
    314  1.5.18.1       mjf 	ifr6 = *creq;
    315       1.1   thorpej 	if (ioctl(s, SIOCGIFNETMASK_IN6, &ifr6) == -1) {
    316       1.1   thorpej 		if (errno != EADDRNOTAVAIL)
    317       1.1   thorpej 			warn("SIOCGIFNETMASK_IN6");
    318       1.1   thorpej 	} else {
    319  1.5.18.1       mjf 		sin6 = &ifr6.ifr_addr;
    320       1.1   thorpej 		printf(" prefixlen %d", prefix(&sin6->sin6_addr,
    321       1.1   thorpej 					       sizeof(struct in6_addr)));
    322       1.1   thorpej 	}
    323       1.1   thorpej 
    324  1.5.18.1       mjf 	ifr6 = *creq;
    325       1.1   thorpej 	if (ioctl(s, SIOCGIFAFLAG_IN6, &ifr6) == -1) {
    326       1.1   thorpej 		if (errno != EADDRNOTAVAIL)
    327       1.1   thorpej 			warn("SIOCGIFAFLAG_IN6");
    328       1.1   thorpej 	} else {
    329       1.1   thorpej 		if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_ANYCAST)
    330       1.1   thorpej 			printf(" anycast");
    331       1.1   thorpej 		if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_TENTATIVE)
    332       1.1   thorpej 			printf(" tentative");
    333       1.1   thorpej 		if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_DUPLICATED)
    334       1.1   thorpej 			printf(" duplicated");
    335       1.1   thorpej 		if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_DETACHED)
    336       1.1   thorpej 			printf(" detached");
    337       1.1   thorpej 		if (ifr6.ifr_ifru.ifru_flags6 & IN6_IFF_DEPRECATED)
    338       1.1   thorpej 			printf(" deprecated");
    339       1.1   thorpej 	}
    340       1.1   thorpej 
    341       1.1   thorpej 	if (scopeid)
    342       1.1   thorpej 		printf(" scopeid 0x%x", scopeid);
    343       1.1   thorpej 
    344       1.1   thorpej 	if (Lflag) {
    345       1.1   thorpej 		struct in6_addrlifetime *lifetime;
    346  1.5.18.1       mjf 		ifr6 = *creq;
    347       1.1   thorpej 		lifetime = &ifr6.ifr_ifru.ifru_lifetime;
    348       1.1   thorpej 		if (ioctl(s, SIOCGIFALIFETIME_IN6, &ifr6) == -1) {
    349       1.1   thorpej 			if (errno != EADDRNOTAVAIL)
    350       1.1   thorpej 				warn("SIOCGIFALIFETIME_IN6");
    351       1.1   thorpej 		} else if (lifetime->ia6t_preferred || lifetime->ia6t_expire) {
    352       1.1   thorpej 			time_t t = time(NULL);
    353       1.1   thorpej 			printf(" pltime ");
    354       1.1   thorpej 			if (lifetime->ia6t_preferred) {
    355  1.5.18.1       mjf 				printf("%lu",
    356  1.5.18.1       mjf 				    (unsigned long)(lifetime->ia6t_preferred -
    357  1.5.18.1       mjf 				        MIN(t, lifetime->ia6t_preferred)));
    358       1.1   thorpej 			} else
    359       1.1   thorpej 				printf("infty");
    360       1.1   thorpej 
    361       1.1   thorpej 			printf(" vltime ");
    362       1.1   thorpej 			if (lifetime->ia6t_expire) {
    363  1.5.18.1       mjf 				printf("%lu",
    364  1.5.18.1       mjf 				    (unsigned long)(lifetime->ia6t_expire -
    365  1.5.18.1       mjf 				        MIN(t, lifetime->ia6t_expire)));
    366       1.1   thorpej 			} else
    367       1.1   thorpej 				printf("infty");
    368       1.1   thorpej 		}
    369       1.1   thorpej 	}
    370       1.1   thorpej 
    371       1.1   thorpej 	printf("\n");
    372       1.1   thorpej }
    373       1.1   thorpej 
    374       1.1   thorpej void
    375  1.5.18.1       mjf in6_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force)
    376       1.1   thorpej {
    377       1.1   thorpej 	struct ifaddrs *ifap, *ifa;
    378  1.5.18.1       mjf 	struct in6_ifreq ifr;
    379  1.5.18.1       mjf 	const char *ifname;
    380  1.5.18.1       mjf 
    381  1.5.18.1       mjf 	if ((ifname = getifname(env)) == NULL)
    382  1.5.18.1       mjf 		err(EXIT_FAILURE, "%s: getifname", __func__);
    383       1.1   thorpej 
    384       1.1   thorpej 	if (getifaddrs(&ifap) != 0)
    385       1.1   thorpej 		err(EXIT_FAILURE, "getifaddrs");
    386       1.1   thorpej 	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
    387  1.5.18.1       mjf 		if (strcmp(ifname, ifa->ifa_name) != 0)
    388       1.1   thorpej 			continue;
    389       1.1   thorpej 		if (ifa->ifa_addr->sa_family != AF_INET6)
    390       1.1   thorpej 			continue;
    391  1.5.18.1       mjf 		if (sizeof(ifr.ifr_addr) < ifa->ifa_addr->sa_len)
    392       1.1   thorpej 			continue;
    393       1.1   thorpej 
    394  1.5.18.1       mjf 		memset(&ifr, 0, sizeof(ifr));
    395  1.5.18.1       mjf 		estrlcpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name));
    396  1.5.18.1       mjf 		memcpy(&ifr.ifr_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len);
    397  1.5.18.1       mjf 		in6_alias(ifname, env, oenv, &ifr);
    398       1.1   thorpej 	}
    399       1.1   thorpej 	freeifaddrs(ifap);
    400       1.1   thorpej }
    401       1.1   thorpej 
    402  1.5.18.1       mjf static int
    403  1.5.18.1       mjf in6_pre_aifaddr(prop_dictionary_t env, struct afparam *param)
    404       1.1   thorpej {
    405  1.5.18.1       mjf 	struct in6_aliasreq *ifra = param->req.buf;
    406       1.1   thorpej 
    407  1.5.18.1       mjf 	setia6eui64_impl(env, ifra);
    408  1.5.18.1       mjf 	setia6vltime_impl(env, ifra);
    409  1.5.18.1       mjf 	setia6pltime_impl(env, ifra);
    410  1.5.18.1       mjf 	setia6flags_impl(env, ifra);
    411  1.5.18.1       mjf 	in6_delscopeid(&ifra->ifra_addr);
    412  1.5.18.1       mjf 	in6_delscopeid(&ifra->ifra_dstaddr);
    413       1.1   thorpej 
    414  1.5.18.1       mjf 	return 0;
    415       1.1   thorpej }
    416       1.1   thorpej 
    417       1.1   thorpej void
    418  1.5.18.1       mjf in6_commit_address(prop_dictionary_t env, prop_dictionary_t oenv)
    419       1.1   thorpej {
    420  1.5.18.1       mjf 	struct in6_ifreq in6_ifr = {
    421  1.5.18.1       mjf 		.ifr_addr = {
    422  1.5.18.1       mjf 			.sin6_family = AF_INET6,
    423  1.5.18.1       mjf 			.sin6_len = sizeof(in6_ifr.ifr_addr),
    424  1.5.18.1       mjf 			.sin6_addr = {
    425  1.5.18.1       mjf 				.s6_addr =
    426  1.5.18.1       mjf 				    {0xff, 0xff, 0xff, 0xff,
    427  1.5.18.1       mjf 				     0xff, 0xff, 0xff, 0xff}
    428  1.5.18.1       mjf 			}
    429  1.5.18.1       mjf 		}
    430  1.5.18.1       mjf 	};
    431  1.5.18.1       mjf 	static struct sockaddr_in6 in6_defmask = {
    432  1.5.18.1       mjf 		.sin6_family = AF_INET6,
    433  1.5.18.1       mjf 		.sin6_len = sizeof(in6_defmask),
    434  1.5.18.1       mjf 		.sin6_addr = {
    435  1.5.18.1       mjf 			.s6_addr = {0xff, 0xff, 0xff, 0xff,
    436  1.5.18.1       mjf 			            0xff, 0xff, 0xff, 0xff}
    437  1.5.18.1       mjf 		}
    438  1.5.18.1       mjf 	};
    439       1.1   thorpej 
    440  1.5.18.1       mjf 	struct in6_aliasreq in6_ifra = {
    441  1.5.18.1       mjf 		.ifra_prefixmask = {
    442  1.5.18.1       mjf 			.sin6_family = AF_INET6,
    443  1.5.18.1       mjf 			.sin6_len = sizeof(in6_ifra.ifra_prefixmask),
    444  1.5.18.1       mjf 			.sin6_addr = {
    445  1.5.18.1       mjf 				.s6_addr =
    446  1.5.18.1       mjf 				    {0xff, 0xff, 0xff, 0xff,
    447  1.5.18.1       mjf 				     0xff, 0xff, 0xff, 0xff}}},
    448  1.5.18.1       mjf 		.ifra_lifetime = {
    449  1.5.18.1       mjf 			  .ia6t_pltime = ND6_INFINITE_LIFETIME
    450  1.5.18.1       mjf 			, .ia6t_vltime = ND6_INFINITE_LIFETIME
    451  1.5.18.1       mjf 		}
    452  1.5.18.1       mjf 	};
    453  1.5.18.1       mjf 	struct afparam in6param = {
    454  1.5.18.1       mjf 		  .req = BUFPARAM(in6_ifra)
    455  1.5.18.1       mjf 		, .dgreq = BUFPARAM(in6_ifr)
    456  1.5.18.1       mjf 		, .name = {
    457  1.5.18.1       mjf 			{.buf = in6_ifr.ifr_name,
    458  1.5.18.1       mjf 			 .buflen = sizeof(in6_ifr.ifr_name)},
    459  1.5.18.1       mjf 			{.buf = in6_ifra.ifra_name,
    460  1.5.18.1       mjf 			 .buflen = sizeof(in6_ifra.ifra_name)}
    461  1.5.18.1       mjf 		  }
    462  1.5.18.1       mjf 		, .dgaddr = BUFPARAM(in6_ifr.ifr_addr)
    463  1.5.18.1       mjf 		, .addr = BUFPARAM(in6_ifra.ifra_addr)
    464  1.5.18.1       mjf 		, .dst = BUFPARAM(in6_ifra.ifra_dstaddr)
    465  1.5.18.1       mjf 		, .brd = BUFPARAM(in6_ifra.ifra_broadaddr)
    466  1.5.18.1       mjf 		, .mask = BUFPARAM(in6_ifra.ifra_prefixmask)
    467  1.5.18.1       mjf 		, .aifaddr = IFADDR_PARAM(SIOCAIFADDR_IN6)
    468  1.5.18.1       mjf 		, .difaddr = IFADDR_PARAM(SIOCDIFADDR_IN6)
    469  1.5.18.1       mjf 		, .gifaddr = IFADDR_PARAM(SIOCGIFADDR_IN6)
    470  1.5.18.1       mjf 		, .defmask = BUFPARAM(in6_defmask)
    471  1.5.18.1       mjf 		, .pre_aifaddr = in6_pre_aifaddr
    472  1.5.18.1       mjf 	};
    473  1.5.18.1       mjf 	commit_address(env, oenv, &in6param);
    474       1.1   thorpej }
    475