af_inet6.c revision 238273
1260684Skaiw/*
2260684Skaiw * Copyright (c) 1983, 1993
3260684Skaiw *	The Regents of the University of California.  All rights reserved.
4260684Skaiw *
5260684Skaiw * Redistribution and use in source and binary forms, with or without
6260684Skaiw * modification, are permitted provided that the following conditions
7260684Skaiw * are met:
8260684Skaiw * 1. Redistributions of source code must retain the above copyright
9260684Skaiw *    notice, this list of conditions and the following disclaimer.
10260684Skaiw * 2. Redistributions in binary form must reproduce the above copyright
11260684Skaiw *    notice, this list of conditions and the following disclaimer in the
12260684Skaiw *    documentation and/or other materials provided with the distribution.
13260684Skaiw * 4. Neither the name of the University nor the names of its contributors
14260684Skaiw *    may be used to endorse or promote products derived from this software
15260684Skaiw *    without specific prior written permission.
16260684Skaiw *
17260684Skaiw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18260684Skaiw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19260684Skaiw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20260684Skaiw * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21260684Skaiw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22260684Skaiw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23260684Skaiw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24260684Skaiw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25260684Skaiw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26260684Skaiw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27260684Skaiw * SUCH DAMAGE.
28260684Skaiw */
29260684Skaiw
30260684Skaiw#ifndef lint
31260684Skaiwstatic const char rcsid[] =
32260684Skaiw  "$FreeBSD: head/sbin/ifconfig/af_inet6.c 238273 2012-07-09 06:21:46Z hrs $";
33260684Skaiw#endif /* not lint */
34260684Skaiw
35260684Skaiw#include <sys/param.h>
36260684Skaiw#include <sys/ioctl.h>
37260684Skaiw#include <sys/socket.h>
38260684Skaiw#include <net/if.h>
39260684Skaiw
40260684Skaiw#include <err.h>
41260684Skaiw#include <stdio.h>
42260684Skaiw#include <stdlib.h>
43260684Skaiw#include <string.h>
44260684Skaiw#include <unistd.h>
45260684Skaiw#include <ifaddrs.h>
46260684Skaiw
47260684Skaiw#include <arpa/inet.h>
48260684Skaiw
49260684Skaiw#include <netinet/in.h>
50260684Skaiw#include <net/if_var.h>		/* for struct ifaddr */
51260684Skaiw#include <netinet/in_var.h>
52260684Skaiw#include <arpa/inet.h>
53260684Skaiw#include <netdb.h>
54260684Skaiw
55260684Skaiw#include <netinet6/nd6.h>	/* Define ND6_INFINITE_LIFETIME */
56260684Skaiw
57260684Skaiw#include "ifconfig.h"
58260684Skaiw
59260684Skaiwstatic	struct in6_ifreq in6_ridreq;
60260684Skaiwstatic	struct in6_aliasreq in6_addreq =
61260684Skaiw  { .ifra_flags = 0,
62260684Skaiw    .ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } };
63260684Skaiwstatic	int ip6lifetime;
64260684Skaiw
65260684Skaiwstatic	void in6_fillscopeid(struct sockaddr_in6 *sin6);
66260684Skaiwstatic	int prefix(void *, int);
67260684Skaiwstatic	char *sec2str(time_t);
68260684Skaiwstatic	int explicit_prefix = 0;
69260684Skaiw
70260684Skaiwextern void setnd6flags(const char *, int, int, const struct afswtch *);
71260684Skaiwextern void setnd6defif(const char *, int, int, const struct afswtch *);
72260684Skaiwextern void nd6_status(int);
73260684Skaiw
74260684Skaiwstatic	char addr_buf[MAXHOSTNAMELEN *2 + 1];	/*for getnameinfo()*/
75260684Skaiw
76260684Skaiwstatic void
77260684Skaiwsetifprefixlen(const char *addr, int dummy __unused, int s,
78260684Skaiw    const struct afswtch *afp)
79260684Skaiw{
80260684Skaiw        if (afp->af_getprefix != NULL)
81260684Skaiw                afp->af_getprefix(addr, MASK);
82260684Skaiw	explicit_prefix = 1;
83260684Skaiw}
84260684Skaiw
85260684Skaiwstatic void
86260684Skaiwsetip6flags(const char *dummyaddr __unused, int flag, int dummysoc __unused,
87260684Skaiw    const struct afswtch *afp)
88260684Skaiw{
89260684Skaiw	if (afp->af_af != AF_INET6)
90260684Skaiw		err(1, "address flags can be set only for inet6 addresses");
91260684Skaiw
92260684Skaiw	if (flag < 0)
93260684Skaiw		in6_addreq.ifra_flags &= ~(-flag);
94260684Skaiw	else
95260684Skaiw		in6_addreq.ifra_flags |= flag;
96260684Skaiw}
97260684Skaiw
98260684Skaiwstatic void
99260684Skaiwsetip6lifetime(const char *cmd, const char *val, int s,
100260684Skaiw    const struct afswtch *afp)
101260684Skaiw{
102260684Skaiw	time_t newval, t;
103260684Skaiw	char *ep;
104260684Skaiw
105260684Skaiw	t = time(NULL);
106260684Skaiw	newval = (time_t)strtoul(val, &ep, 0);
107260684Skaiw	if (val == ep)
108260684Skaiw		errx(1, "invalid %s", cmd);
109260684Skaiw	if (afp->af_af != AF_INET6)
110260684Skaiw		errx(1, "%s not allowed for the AF", cmd);
111260684Skaiw	if (strcmp(cmd, "vltime") == 0) {
112260684Skaiw		in6_addreq.ifra_lifetime.ia6t_expire = t + newval;
113260684Skaiw		in6_addreq.ifra_lifetime.ia6t_vltime = newval;
114260684Skaiw	} else if (strcmp(cmd, "pltime") == 0) {
115260684Skaiw		in6_addreq.ifra_lifetime.ia6t_preferred = t + newval;
116260684Skaiw		in6_addreq.ifra_lifetime.ia6t_pltime = newval;
117260684Skaiw	}
118260684Skaiw}
119260684Skaiw
120260684Skaiwstatic void
121260684Skaiwsetip6pltime(const char *seconds, int dummy __unused, int s,
122260684Skaiw    const struct afswtch *afp)
123260684Skaiw{
124260684Skaiw	setip6lifetime("pltime", seconds, s, afp);
125260684Skaiw}
126260684Skaiw
127260684Skaiwstatic void
128260684Skaiwsetip6vltime(const char *seconds, int dummy __unused, int s,
129260684Skaiw    const struct afswtch *afp)
130260684Skaiw{
131260684Skaiw	setip6lifetime("vltime", seconds, s, afp);
132260684Skaiw}
133260684Skaiw
134260684Skaiwstatic void
135260684Skaiwsetip6eui64(const char *cmd, int dummy __unused, int s,
136260684Skaiw    const struct afswtch *afp)
137260684Skaiw{
138260684Skaiw	struct ifaddrs *ifap, *ifa;
139260684Skaiw	const struct sockaddr_in6 *sin6 = NULL;
140260684Skaiw	const struct in6_addr *lladdr = NULL;
141260684Skaiw	struct in6_addr *in6;
142260684Skaiw
143260684Skaiw	if (afp->af_af != AF_INET6)
144260684Skaiw		errx(EXIT_FAILURE, "%s not allowed for the AF", cmd);
145260684Skaiw 	in6 = (struct in6_addr *)&in6_addreq.ifra_addr.sin6_addr;
146260684Skaiw	if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0)
147260684Skaiw		errx(EXIT_FAILURE, "interface index is already filled");
148260684Skaiw	if (getifaddrs(&ifap) != 0)
149260684Skaiw		err(EXIT_FAILURE, "getifaddrs");
150260684Skaiw	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
151260684Skaiw		if (ifa->ifa_addr->sa_family == AF_INET6 &&
152260684Skaiw		    strcmp(ifa->ifa_name, name) == 0) {
153260684Skaiw			sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr;
154260684Skaiw			if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
155260684Skaiw				lladdr = &sin6->sin6_addr;
156260684Skaiw				break;
157260684Skaiw			}
158260684Skaiw		}
159260684Skaiw	}
160260684Skaiw	if (!lladdr)
161260684Skaiw		errx(EXIT_FAILURE, "could not determine link local address");
162260684Skaiw
163260684Skaiw 	memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8);
164260684Skaiw
165	freeifaddrs(ifap);
166}
167
168static void
169in6_fillscopeid(struct sockaddr_in6 *sin6)
170{
171#if defined(__KAME__) && defined(KAME_SCOPEID)
172	if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
173		sin6->sin6_scope_id =
174			ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]);
175		sin6->sin6_addr.s6_addr[2] = sin6->sin6_addr.s6_addr[3] = 0;
176	}
177#endif
178}
179
180static void
181in6_status(int s __unused, const struct ifaddrs *ifa)
182{
183	struct sockaddr_in6 *sin, null_sin;
184	struct in6_ifreq ifr6;
185	int s6;
186	u_int32_t flags6;
187	struct in6_addrlifetime lifetime;
188	time_t t = time(NULL);
189	int error;
190	u_int32_t scopeid;
191
192	memset(&null_sin, 0, sizeof(null_sin));
193
194	sin = (struct sockaddr_in6 *)ifa->ifa_addr;
195	if (sin == NULL)
196		return;
197
198	strncpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name));
199	if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
200		warn("socket(AF_INET6,SOCK_DGRAM)");
201		return;
202	}
203	ifr6.ifr_addr = *sin;
204	if (ioctl(s6, SIOCGIFAFLAG_IN6, &ifr6) < 0) {
205		warn("ioctl(SIOCGIFAFLAG_IN6)");
206		close(s6);
207		return;
208	}
209	flags6 = ifr6.ifr_ifru.ifru_flags6;
210	memset(&lifetime, 0, sizeof(lifetime));
211	ifr6.ifr_addr = *sin;
212	if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) {
213		warn("ioctl(SIOCGIFALIFETIME_IN6)");
214		close(s6);
215		return;
216	}
217	lifetime = ifr6.ifr_ifru.ifru_lifetime;
218	close(s6);
219
220	/* XXX: embedded link local addr check */
221	if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) &&
222	    *(u_short *)&sin->sin6_addr.s6_addr[2] != 0) {
223		u_short index;
224
225		index = *(u_short *)&sin->sin6_addr.s6_addr[2];
226		*(u_short *)&sin->sin6_addr.s6_addr[2] = 0;
227		if (sin->sin6_scope_id == 0)
228			sin->sin6_scope_id = ntohs(index);
229	}
230	scopeid = sin->sin6_scope_id;
231
232	error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf,
233			    sizeof(addr_buf), NULL, 0, NI_NUMERICHOST);
234	if (error != 0)
235		inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
236			  sizeof(addr_buf));
237	printf("\tinet6 %s ", addr_buf);
238
239	if (ifa->ifa_flags & IFF_POINTOPOINT) {
240		sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
241		/*
242		 * some of the interfaces do not have valid destination
243		 * address.
244		 */
245		if (sin != NULL && sin->sin6_family == AF_INET6) {
246			int error;
247
248			/* XXX: embedded link local addr check */
249			if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) &&
250			    *(u_short *)&sin->sin6_addr.s6_addr[2] != 0) {
251				u_short index;
252
253				index = *(u_short *)&sin->sin6_addr.s6_addr[2];
254				*(u_short *)&sin->sin6_addr.s6_addr[2] = 0;
255				if (sin->sin6_scope_id == 0)
256					sin->sin6_scope_id = ntohs(index);
257			}
258
259			error = getnameinfo((struct sockaddr *)sin,
260					    sin->sin6_len, addr_buf,
261					    sizeof(addr_buf), NULL, 0,
262					    NI_NUMERICHOST);
263			if (error != 0)
264				inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
265					  sizeof(addr_buf));
266			printf("--> %s ", addr_buf);
267		}
268	}
269
270	sin = (struct sockaddr_in6 *)ifa->ifa_netmask;
271	if (sin == NULL)
272		sin = &null_sin;
273	printf("prefixlen %d ", prefix(&sin->sin6_addr,
274		sizeof(struct in6_addr)));
275
276	if ((flags6 & IN6_IFF_ANYCAST) != 0)
277		printf("anycast ");
278	if ((flags6 & IN6_IFF_TENTATIVE) != 0)
279		printf("tentative ");
280	if ((flags6 & IN6_IFF_DUPLICATED) != 0)
281		printf("duplicated ");
282	if ((flags6 & IN6_IFF_DETACHED) != 0)
283		printf("detached ");
284	if ((flags6 & IN6_IFF_DEPRECATED) != 0)
285		printf("deprecated ");
286	if ((flags6 & IN6_IFF_AUTOCONF) != 0)
287		printf("autoconf ");
288	if ((flags6 & IN6_IFF_TEMPORARY) != 0)
289		printf("temporary ");
290
291        if (scopeid)
292		printf("scopeid 0x%x ", scopeid);
293
294	if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) {
295		printf("pltime ");
296		if (lifetime.ia6t_preferred) {
297			printf("%s ", lifetime.ia6t_preferred < t
298				? "0" : sec2str(lifetime.ia6t_preferred - t));
299		} else
300			printf("infty ");
301
302		printf("vltime ");
303		if (lifetime.ia6t_expire) {
304			printf("%s ", lifetime.ia6t_expire < t
305				? "0" : sec2str(lifetime.ia6t_expire - t));
306		} else
307			printf("infty ");
308	}
309
310	print_vhid(ifa, " ");
311
312	putchar('\n');
313}
314
315#define	SIN6(x) ((struct sockaddr_in6 *) &(x))
316static struct	sockaddr_in6 *sin6tab[] = {
317	SIN6(in6_ridreq.ifr_addr), SIN6(in6_addreq.ifra_addr),
318	SIN6(in6_addreq.ifra_prefixmask), SIN6(in6_addreq.ifra_dstaddr)
319};
320
321static void
322in6_getprefix(const char *plen, int which)
323{
324	struct sockaddr_in6 *sin = sin6tab[which];
325	u_char *cp;
326	int len = atoi(plen);
327
328	if ((len < 0) || (len > 128))
329		errx(1, "%s: bad value", plen);
330	sin->sin6_len = sizeof(*sin);
331	if (which != MASK)
332		sin->sin6_family = AF_INET6;
333	if ((len == 0) || (len == 128)) {
334		memset(&sin->sin6_addr, 0xff, sizeof(struct in6_addr));
335		return;
336	}
337	memset((void *)&sin->sin6_addr, 0x00, sizeof(sin->sin6_addr));
338	for (cp = (u_char *)&sin->sin6_addr; len > 7; len -= 8)
339		*cp++ = 0xff;
340	*cp = 0xff << (8 - len);
341}
342
343static void
344in6_getaddr(const char *s, int which)
345{
346	struct sockaddr_in6 *sin = sin6tab[which];
347	struct addrinfo hints, *res;
348	int error = -1;
349
350	newaddr &= 1;
351
352	sin->sin6_len = sizeof(*sin);
353	if (which != MASK)
354		sin->sin6_family = AF_INET6;
355
356	if (which == ADDR) {
357		char *p = NULL;
358		if((p = strrchr(s, '/')) != NULL) {
359			*p = '\0';
360			in6_getprefix(p + 1, MASK);
361			explicit_prefix = 1;
362		}
363	}
364
365	if (sin->sin6_family == AF_INET6) {
366		bzero(&hints, sizeof(struct addrinfo));
367		hints.ai_family = AF_INET6;
368		error = getaddrinfo(s, NULL, &hints, &res);
369	}
370	if (error != 0) {
371		if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1)
372			errx(1, "%s: bad value", s);
373	} else
374		bcopy(res->ai_addr, sin, res->ai_addrlen);
375}
376
377static int
378prefix(void *val, int size)
379{
380        u_char *name = (u_char *)val;
381        int byte, bit, plen = 0;
382
383        for (byte = 0; byte < size; byte++, plen += 8)
384                if (name[byte] != 0xff)
385                        break;
386	if (byte == size)
387		return (plen);
388	for (bit = 7; bit != 0; bit--, plen++)
389                if (!(name[byte] & (1 << bit)))
390                        break;
391        for (; bit != 0; bit--)
392                if (name[byte] & (1 << bit))
393                        return(0);
394        byte++;
395        for (; byte < size; byte++)
396                if (name[byte])
397                        return(0);
398        return (plen);
399}
400
401static char *
402sec2str(time_t total)
403{
404	static char result[256];
405	int days, hours, mins, secs;
406	int first = 1;
407	char *p = result;
408
409	if (0) {
410		days = total / 3600 / 24;
411		hours = (total / 3600) % 24;
412		mins = (total / 60) % 60;
413		secs = total % 60;
414
415		if (days) {
416			first = 0;
417			p += sprintf(p, "%dd", days);
418		}
419		if (!first || hours) {
420			first = 0;
421			p += sprintf(p, "%dh", hours);
422		}
423		if (!first || mins) {
424			first = 0;
425			p += sprintf(p, "%dm", mins);
426		}
427		sprintf(p, "%ds", secs);
428	} else
429		sprintf(result, "%lu", (unsigned long)total);
430
431	return(result);
432}
433
434static void
435in6_postproc(int s, const struct afswtch *afp)
436{
437	if (explicit_prefix == 0) {
438		/* Aggregatable address architecture defines all prefixes
439		   are 64. So, it is convenient to set prefixlen to 64 if
440		   it is not specified. */
441		setifprefixlen("64", 0, s, afp);
442		/* in6_getprefix("64", MASK) if MASK is available here... */
443	}
444}
445
446static void
447in6_status_tunnel(int s)
448{
449	char src[NI_MAXHOST];
450	char dst[NI_MAXHOST];
451	struct in6_ifreq in6_ifr;
452	const struct sockaddr *sa = (const struct sockaddr *) &in6_ifr.ifr_addr;
453
454	memset(&in6_ifr, 0, sizeof(in6_ifr));
455	strncpy(in6_ifr.ifr_name, name, IFNAMSIZ);
456
457	if (ioctl(s, SIOCGIFPSRCADDR_IN6, (caddr_t)&in6_ifr) < 0)
458		return;
459	if (sa->sa_family != AF_INET6)
460		return;
461	in6_fillscopeid(&in6_ifr.ifr_addr);
462	if (getnameinfo(sa, sa->sa_len, src, sizeof(src), 0, 0,
463	    NI_NUMERICHOST) != 0)
464		src[0] = '\0';
465
466	if (ioctl(s, SIOCGIFPDSTADDR_IN6, (caddr_t)&in6_ifr) < 0)
467		return;
468	if (sa->sa_family != AF_INET6)
469		return;
470	in6_fillscopeid(&in6_ifr.ifr_addr);
471	if (getnameinfo(sa, sa->sa_len, dst, sizeof(dst), 0, 0,
472	    NI_NUMERICHOST) != 0)
473		dst[0] = '\0';
474
475	printf("\ttunnel inet6 %s --> %s\n", src, dst);
476}
477
478static void
479in6_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres)
480{
481	struct in6_aliasreq in6_addreq;
482
483	memset(&in6_addreq, 0, sizeof(in6_addreq));
484	strncpy(in6_addreq.ifra_name, name, IFNAMSIZ);
485	memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len);
486	memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr,
487	    dstres->ai_addr->sa_len);
488
489	if (ioctl(s, SIOCSIFPHYADDR_IN6, &in6_addreq) < 0)
490		warn("SIOCSIFPHYADDR_IN6");
491}
492
493static struct cmd inet6_cmds[] = {
494	DEF_CMD_ARG("prefixlen",			setifprefixlen),
495	DEF_CMD("anycast",	IN6_IFF_ANYCAST,	setip6flags),
496	DEF_CMD("tentative",	IN6_IFF_TENTATIVE,	setip6flags),
497	DEF_CMD("-tentative",	-IN6_IFF_TENTATIVE,	setip6flags),
498	DEF_CMD("deprecated",	IN6_IFF_DEPRECATED,	setip6flags),
499	DEF_CMD("-deprecated", -IN6_IFF_DEPRECATED,	setip6flags),
500	DEF_CMD("autoconf",	IN6_IFF_AUTOCONF,	setip6flags),
501	DEF_CMD("-autoconf",	-IN6_IFF_AUTOCONF,	setip6flags),
502	DEF_CMD("accept_rtadv",	ND6_IFF_ACCEPT_RTADV,	setnd6flags),
503	DEF_CMD("-accept_rtadv",-ND6_IFF_ACCEPT_RTADV,	setnd6flags),
504	DEF_CMD("no_radr",	ND6_IFF_NO_RADR,	setnd6flags),
505	DEF_CMD("-no_radr",	-ND6_IFF_NO_RADR,	setnd6flags),
506	DEF_CMD("defaultif",	1,			setnd6defif),
507	DEF_CMD("-defaultif",	-1,			setnd6defif),
508	DEF_CMD("ifdisabled",	ND6_IFF_IFDISABLED,	setnd6flags),
509	DEF_CMD("-ifdisabled",	-ND6_IFF_IFDISABLED,	setnd6flags),
510	DEF_CMD("nud",		ND6_IFF_PERFORMNUD,	setnd6flags),
511	DEF_CMD("-nud",		-ND6_IFF_PERFORMNUD,	setnd6flags),
512	DEF_CMD("auto_linklocal",ND6_IFF_AUTO_LINKLOCAL,setnd6flags),
513	DEF_CMD("-auto_linklocal",-ND6_IFF_AUTO_LINKLOCAL,setnd6flags),
514	DEF_CMD_ARG("pltime",        			setip6pltime),
515	DEF_CMD_ARG("vltime",        			setip6vltime),
516	DEF_CMD("eui64",	0,			setip6eui64),
517};
518
519static struct afswtch af_inet6 = {
520	.af_name	= "inet6",
521	.af_af		= AF_INET6,
522	.af_status	= in6_status,
523	.af_getaddr	= in6_getaddr,
524	.af_getprefix	= in6_getprefix,
525	.af_other_status = nd6_status,
526	.af_postproc	= in6_postproc,
527	.af_status_tunnel = in6_status_tunnel,
528	.af_settunnel	= in6_set_tunnel,
529	.af_difaddr	= SIOCDIFADDR_IN6,
530	.af_aifaddr	= SIOCAIFADDR_IN6,
531	.af_ridreq	= &in6_addreq,
532	.af_addreq	= &in6_addreq,
533};
534
535static void
536in6_Lopt_cb(const char *optarg __unused)
537{
538	ip6lifetime++;	/* print IPv6 address lifetime */
539}
540static struct option in6_Lopt = { .opt = "L", .opt_usage = "[-L]", .cb = in6_Lopt_cb };
541
542static __constructor void
543inet6_ctor(void)
544{
545#define	N(a)	(sizeof(a) / sizeof(a[0]))
546	size_t i;
547
548#ifndef RESCUE
549	if (!feature_present("inet6"))
550		return;
551#endif
552
553	for (i = 0; i < N(inet6_cmds);  i++)
554		cmd_register(&inet6_cmds[i]);
555	af_register(&af_inet6);
556	opt_register(&in6_Lopt);
557#undef N
558}
559