xref: /freebsd/sbin/ifconfig/af_inet6.c (revision 2c0a6d0e7b82fbe6657fe90d990aa2e812f49b44)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1983, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 #ifndef lint
33 static const char rcsid[] =
34   "$FreeBSD$";
35 #endif /* not lint */
36 
37 #include <sys/param.h>
38 #include <sys/ioctl.h>
39 #include <sys/socket.h>
40 #include <net/if.h>
41 
42 #include <err.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <unistd.h>
47 #include <time.h>
48 #include <ifaddrs.h>
49 
50 #include <arpa/inet.h>
51 
52 #include <netinet/in.h>
53 #include <netinet/in_var.h>
54 #include <arpa/inet.h>
55 #include <netdb.h>
56 
57 #include <netinet6/nd6.h>	/* Define ND6_INFINITE_LIFETIME */
58 
59 #include "ifconfig.h"
60 #include "ifconfig_netlink.h"
61 
62 static	struct in6_ifreq in6_ridreq;
63 static	struct in6_aliasreq in6_addreq =
64   { .ifra_flags = 0,
65     .ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } };
66 static	int ip6lifetime;
67 
68 #ifdef WITHOUT_NETLINK
69 static	int prefix(void *, int);
70 #endif
71 static	char *sec2str(time_t);
72 static	int explicit_prefix = 0;
73 extern	char *f_inet6, *f_addr;
74 
75 extern void setnd6flags(if_ctx *, const char *, int);
76 extern void setnd6defif(if_ctx *,const char *, int);
77 extern void nd6_status(if_ctx *);
78 
79 static	char addr_buf[NI_MAXHOST];	/*for getnameinfo()*/
80 
81 static void
82 setifprefixlen(if_ctx *ctx, const char *addr, int dummy __unused)
83 {
84 	const struct afswtch *afp = ctx->afp;
85 
86         if (afp->af_getprefix != NULL)
87                 afp->af_getprefix(addr, MASK);
88 	explicit_prefix = 1;
89 }
90 
91 static void
92 setip6flags(if_ctx *ctx, const char *dummyaddr __unused, int flag)
93 {
94 	const struct afswtch *afp = ctx->afp;
95 
96 	if (afp->af_af != AF_INET6)
97 		err(1, "address flags can be set only for inet6 addresses");
98 
99 	if (flag < 0)
100 		in6_addreq.ifra_flags &= ~(-flag);
101 	else
102 		in6_addreq.ifra_flags |= flag;
103 }
104 
105 static void
106 setip6lifetime(if_ctx *ctx, const char *cmd, const char *val)
107 {
108 	const struct afswtch *afp = ctx->afp;
109 	struct timespec now;
110 	time_t newval;
111 	char *ep;
112 
113 	clock_gettime(CLOCK_MONOTONIC_FAST, &now);
114 	newval = (time_t)strtoul(val, &ep, 0);
115 	if (val == ep)
116 		errx(1, "invalid %s", cmd);
117 	if (afp->af_af != AF_INET6)
118 		errx(1, "%s not allowed for the AF", cmd);
119 	if (strcmp(cmd, "vltime") == 0) {
120 		in6_addreq.ifra_lifetime.ia6t_expire = now.tv_sec + newval;
121 		in6_addreq.ifra_lifetime.ia6t_vltime = newval;
122 	} else if (strcmp(cmd, "pltime") == 0) {
123 		in6_addreq.ifra_lifetime.ia6t_preferred = now.tv_sec + newval;
124 		in6_addreq.ifra_lifetime.ia6t_pltime = newval;
125 	}
126 }
127 
128 static void
129 setip6pltime(if_ctx *ctx, const char *seconds, int dummy __unused)
130 {
131 	setip6lifetime(ctx, "pltime", seconds);
132 }
133 
134 static void
135 setip6vltime(if_ctx *ctx, const char *seconds, int dummy __unused)
136 {
137 	setip6lifetime(ctx, "vltime", seconds);
138 }
139 
140 static void
141 setip6eui64(if_ctx *ctx, const char *cmd, int dummy __unused)
142 {
143 	const struct afswtch *afp = ctx->afp;
144 	struct ifaddrs *ifap, *ifa;
145 	const struct sockaddr_in6 *sin6 = NULL;
146 	const struct in6_addr *lladdr = NULL;
147 	struct in6_addr *in6;
148 
149 	if (afp->af_af != AF_INET6)
150 		errx(EXIT_FAILURE, "%s not allowed for the AF", cmd);
151  	in6 = (struct in6_addr *)&in6_addreq.ifra_addr.sin6_addr;
152 	if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0)
153 		errx(EXIT_FAILURE, "interface index is already filled");
154 	if (getifaddrs(&ifap) != 0)
155 		err(EXIT_FAILURE, "getifaddrs");
156 	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
157 		if (ifa->ifa_addr->sa_family == AF_INET6 &&
158 		    strcmp(ifa->ifa_name, name) == 0) {
159 			sin6 = (const struct sockaddr_in6 *)satosin6(ifa->ifa_addr);
160 			if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
161 				lladdr = &sin6->sin6_addr;
162 				break;
163 			}
164 		}
165 	}
166 	if (!lladdr)
167 		errx(EXIT_FAILURE, "could not determine link local address");
168 
169  	memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8);
170 
171 	freeifaddrs(ifap);
172 }
173 
174 static void
175 print_addr(struct sockaddr_in6 *sin)
176 {
177 	int error, n_flags;
178 
179 	if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0)
180 		n_flags = 0;
181 	else if (f_addr != NULL && strcmp(f_addr, "host") == 0)
182 		n_flags = NI_NOFQDN;
183 	else
184 		n_flags = NI_NUMERICHOST;
185 	error = getnameinfo((struct sockaddr *)sin, sin->sin6_len,
186 			    addr_buf, sizeof(addr_buf), NULL, 0,
187 			    n_flags);
188 	if (error != 0)
189 		inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
190 			  sizeof(addr_buf));
191 	printf("\tinet6 %s", addr_buf);
192 }
193 
194 static void
195 print_p2p(struct sockaddr_in6 *sin)
196 {
197 	int error;
198 
199 	error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf,
200 	    sizeof(addr_buf), NULL, 0, NI_NUMERICHOST);
201 
202 	if (error != 0)
203 		inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, sizeof(addr_buf));
204 	printf(" --> %s", addr_buf);
205 }
206 
207 static void
208 print_mask(int plen)
209 {
210 	if (f_inet6 != NULL && strcmp(f_inet6, "cidr") == 0)
211 		printf("/%d", plen);
212 	else
213 		printf(" prefixlen %d", plen);
214 }
215 
216 static void
217 print_flags(int flags6)
218 {
219 	if ((flags6 & IN6_IFF_ANYCAST) != 0)
220 		printf(" anycast");
221 	if ((flags6 & IN6_IFF_TENTATIVE) != 0)
222 		printf(" tentative");
223 	if ((flags6 & IN6_IFF_DUPLICATED) != 0)
224 		printf(" duplicated");
225 	if ((flags6 & IN6_IFF_DETACHED) != 0)
226 		printf(" detached");
227 	if ((flags6 & IN6_IFF_DEPRECATED) != 0)
228 		printf(" deprecated");
229 	if ((flags6 & IN6_IFF_AUTOCONF) != 0)
230 		printf(" autoconf");
231 	if ((flags6 & IN6_IFF_TEMPORARY) != 0)
232 		printf(" temporary");
233 	if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0)
234 		printf(" prefer_source");
235 
236 }
237 
238 static void
239 print_lifetime(const char *prepend, time_t px_time, struct timespec *now)
240 {
241 	printf(" %s", prepend);
242 	if (px_time == 0)
243 		printf(" infty");
244 
245 	printf(" %s", px_time < now->tv_sec ? "0" : sec2str(px_time - now->tv_sec));
246 }
247 
248 #ifdef WITHOUT_NETLINK
249 static void
250 in6_status(if_ctx *ctx __unused, const struct ifaddrs *ifa)
251 {
252 	struct sockaddr_in6 *sin, null_sin = {};
253 	struct in6_ifreq ifr6;
254 	int s6;
255 	u_int32_t flags6;
256 	struct in6_addrlifetime lifetime;
257 
258 	sin = (struct sockaddr_in6 *)ifa->ifa_addr;
259 	if (sin == NULL)
260 		return;
261 
262 	strlcpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name));
263 	if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
264 		warn("socket(AF_INET6,SOCK_DGRAM)");
265 		return;
266 	}
267 	ifr6.ifr_addr = *sin;
268 	if (ioctl(s6, SIOCGIFAFLAG_IN6, &ifr6) < 0) {
269 		warn("ioctl(SIOCGIFAFLAG_IN6)");
270 		close(s6);
271 		return;
272 	}
273 	flags6 = ifr6.ifr_ifru.ifru_flags6;
274 	memset(&lifetime, 0, sizeof(lifetime));
275 	ifr6.ifr_addr = *sin;
276 	if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) {
277 		warn("ioctl(SIOCGIFALIFETIME_IN6)");
278 		close(s6);
279 		return;
280 	}
281 	lifetime = ifr6.ifr_ifru.ifru_lifetime;
282 	close(s6);
283 
284 	print_addr(sin);
285 
286 	if (ifa->ifa_flags & IFF_POINTOPOINT) {
287 		sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
288 		/*
289 		 * some of the interfaces do not have valid destination
290 		 * address.
291 		 */
292 		if (sin != NULL && sin->sin6_family == AF_INET6)
293 			print_p2p(sin);
294 	}
295 
296 	sin = (struct sockaddr_in6 *)ifa->ifa_netmask;
297 	if (sin == NULL)
298 		sin = &null_sin;
299 	print_mask(prefix(&sin->sin6_addr, sizeof(struct in6_addr)));
300 
301 	print_flags(flags6);
302 
303 	if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id)
304 		printf(" scopeid 0x%x",
305 		    ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id);
306 
307 	if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) {
308 		struct timespec now;
309 
310 		clock_gettime(CLOCK_MONOTONIC_FAST, &now);
311 		print_lifetime("pltime", lifetime.ia6t_preferred, &now);
312 		print_lifetime("vltime", lifetime.ia6t_expire, &now);
313 	}
314 
315 	print_vhid(ifa, " ");
316 
317 	putchar('\n');
318 }
319 
320 #else
321 static void
322 show_lifetime(struct ifa_cacheinfo *ci)
323 {
324 	struct timespec now;
325 	uint32_t pl, vl;
326 
327 	if (ci == NULL)
328 		return;
329 
330 	int count = ci->ifa_prefered != ND6_INFINITE_LIFETIME;
331 	count += ci->ifa_valid != ND6_INFINITE_LIFETIME;
332 	if (count == 0)
333 		return;
334 
335 	pl = (ci->ifa_prefered == ND6_INFINITE_LIFETIME) ? 0 : ci->ifa_prefered;
336 	vl = (ci->ifa_valid == ND6_INFINITE_LIFETIME) ? 0 : ci->ifa_valid;
337 
338 	clock_gettime(CLOCK_MONOTONIC_FAST, &now);
339 	print_lifetime("pltime", pl + now.tv_sec, &now);
340 	print_lifetime("vltime", vl + now.tv_sec, &now);
341 }
342 
343 static void
344 in6_status_nl(if_ctx *ctx __unused, if_link_t *link, if_addr_t *ifa)
345 {
346 	int plen = ifa->ifa_prefixlen;
347 	uint32_t scopeid;
348 
349 	if (ifa->ifa_local == NULL) {
350 		/* Non-P2P address */
351 		scopeid = satosin6(ifa->ifa_address)->sin6_scope_id;
352 		print_addr(satosin6(ifa->ifa_address));
353 	} else {
354 		scopeid = satosin6(ifa->ifa_local)->sin6_scope_id;
355 		print_addr(satosin6(ifa->ifa_local));
356 		print_p2p(satosin6(ifa->ifa_address));
357 	}
358 
359 	print_mask(plen);
360 	print_flags(ifa->ifaf_flags);
361 
362 	if (scopeid != 0)
363 		printf(" scopeid 0x%x", scopeid);
364 
365 	show_lifetime(ifa->ifa_cacheinfo);
366 
367 	if (ifa->ifaf_vhid != 0)
368 		printf(" vhid %d", ifa->ifaf_vhid);
369 
370 	putchar('\n');
371 }
372 #endif
373 
374 static struct	sockaddr_in6 *sin6tab[] = {
375 	&in6_ridreq.ifr_addr, &in6_addreq.ifra_addr,
376 	&in6_addreq.ifra_prefixmask, &in6_addreq.ifra_dstaddr
377 };
378 
379 static void
380 in6_getprefix(const char *plen, int which)
381 {
382 	struct sockaddr_in6 *sin = sin6tab[which];
383 	u_char *cp;
384 	int len = atoi(plen);
385 
386 	if ((len < 0) || (len > 128))
387 		errx(1, "%s: bad value", plen);
388 	sin->sin6_len = sizeof(*sin);
389 	if (which != MASK)
390 		sin->sin6_family = AF_INET6;
391 	if ((len == 0) || (len == 128)) {
392 		memset(&sin->sin6_addr, 0xff, sizeof(struct in6_addr));
393 		return;
394 	}
395 	memset((void *)&sin->sin6_addr, 0x00, sizeof(sin->sin6_addr));
396 	for (cp = (u_char *)&sin->sin6_addr; len > 7; len -= 8)
397 		*cp++ = 0xff;
398 	*cp = 0xff << (8 - len);
399 }
400 
401 static void
402 in6_getaddr(const char *s, int which)
403 {
404 	struct sockaddr_in6 *sin = sin6tab[which];
405 	struct addrinfo hints, *res;
406 	int error = -1;
407 
408 	newaddr &= 1;
409 
410 	sin->sin6_len = sizeof(*sin);
411 	if (which != MASK)
412 		sin->sin6_family = AF_INET6;
413 
414 	if (which == ADDR) {
415 		char *p = NULL;
416 		if((p = strrchr(s, '/')) != NULL) {
417 			*p = '\0';
418 			in6_getprefix(p + 1, MASK);
419 			explicit_prefix = 1;
420 		}
421 	}
422 
423 	if (sin->sin6_family == AF_INET6) {
424 		bzero(&hints, sizeof(struct addrinfo));
425 		hints.ai_family = AF_INET6;
426 		error = getaddrinfo(s, NULL, &hints, &res);
427 		if (error != 0) {
428 			if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1)
429 				errx(1, "%s: bad value", s);
430 		} else {
431 			bcopy(res->ai_addr, sin, res->ai_addrlen);
432 			freeaddrinfo(res);
433 		}
434 	}
435 }
436 
437 #ifdef WITHOUT_NETLINK
438 static int
439 prefix(void *val, int size)
440 {
441 	u_char *name = (u_char *)val;
442 	int byte, bit, plen = 0;
443 
444 	for (byte = 0; byte < size; byte++, plen += 8)
445 		if (name[byte] != 0xff)
446 			break;
447 	if (byte == size)
448 		return (plen);
449 	for (bit = 7; bit != 0; bit--, plen++)
450 		if (!(name[byte] & (1 << bit)))
451 			break;
452 	for (; bit != 0; bit--)
453 		if (name[byte] & (1 << bit))
454 			return(0);
455 	byte++;
456 	for (; byte < size; byte++)
457 		if (name[byte])
458 			return(0);
459 	return (plen);
460 }
461 #endif
462 
463 static char *
464 sec2str(time_t total)
465 {
466 	static char result[256];
467 	int days, hours, mins, secs;
468 	int first = 1;
469 	char *p = result;
470 
471 	if (0) {
472 		days = total / 3600 / 24;
473 		hours = (total / 3600) % 24;
474 		mins = (total / 60) % 60;
475 		secs = total % 60;
476 
477 		if (days) {
478 			first = 0;
479 			p += sprintf(p, "%dd", days);
480 		}
481 		if (!first || hours) {
482 			first = 0;
483 			p += sprintf(p, "%dh", hours);
484 		}
485 		if (!first || mins) {
486 			first = 0;
487 			p += sprintf(p, "%dm", mins);
488 		}
489 		sprintf(p, "%ds", secs);
490 	} else
491 		sprintf(result, "%lu", (unsigned long)total);
492 
493 	return(result);
494 }
495 
496 static void
497 in6_postproc(if_ctx *ctx, int newaddr __unused,
498     int ifflags __unused)
499 {
500 	if (explicit_prefix == 0) {
501 		/* Aggregatable address architecture defines all prefixes
502 		   are 64. So, it is convenient to set prefixlen to 64 if
503 		   it is not specified. */
504 		setifprefixlen(ctx, "64", 0);
505 		/* in6_getprefix("64", MASK) if MASK is available here... */
506 	}
507 }
508 
509 static void
510 in6_status_tunnel(int s)
511 {
512 	char src[NI_MAXHOST];
513 	char dst[NI_MAXHOST];
514 	struct in6_ifreq in6_ifr;
515 	const struct sockaddr *sa = (const struct sockaddr *) &in6_ifr.ifr_addr;
516 
517 	memset(&in6_ifr, 0, sizeof(in6_ifr));
518 	strlcpy(in6_ifr.ifr_name, name, sizeof(in6_ifr.ifr_name));
519 
520 	if (ioctl(s, SIOCGIFPSRCADDR_IN6, (caddr_t)&in6_ifr) < 0)
521 		return;
522 	if (sa->sa_family != AF_INET6)
523 		return;
524 	if (getnameinfo(sa, sa->sa_len, src, sizeof(src), 0, 0,
525 	    NI_NUMERICHOST) != 0)
526 		src[0] = '\0';
527 
528 	if (ioctl(s, SIOCGIFPDSTADDR_IN6, (caddr_t)&in6_ifr) < 0)
529 		return;
530 	if (sa->sa_family != AF_INET6)
531 		return;
532 	if (getnameinfo(sa, sa->sa_len, dst, sizeof(dst), 0, 0,
533 	    NI_NUMERICHOST) != 0)
534 		dst[0] = '\0';
535 
536 	printf("\ttunnel inet6 %s --> %s\n", src, dst);
537 }
538 
539 static void
540 in6_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres)
541 {
542 	struct in6_aliasreq in6_addreq;
543 
544 	memset(&in6_addreq, 0, sizeof(in6_addreq));
545 	strlcpy(in6_addreq.ifra_name, name, sizeof(in6_addreq.ifra_name));
546 	memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len);
547 	memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr,
548 	    dstres->ai_addr->sa_len);
549 
550 	if (ioctl(s, SIOCSIFPHYADDR_IN6, &in6_addreq) < 0)
551 		warn("SIOCSIFPHYADDR_IN6");
552 }
553 
554 static void
555 in6_set_vhid(int vhid)
556 {
557 	in6_addreq.ifra_vhid = vhid;
558 }
559 
560 static struct cmd inet6_cmds[] = {
561 	DEF_CMD_ARG("prefixlen",			setifprefixlen),
562 	DEF_CMD("anycast",	IN6_IFF_ANYCAST,	setip6flags),
563 	DEF_CMD("tentative",	IN6_IFF_TENTATIVE,	setip6flags),
564 	DEF_CMD("-tentative",	-IN6_IFF_TENTATIVE,	setip6flags),
565 	DEF_CMD("deprecated",	IN6_IFF_DEPRECATED,	setip6flags),
566 	DEF_CMD("-deprecated", -IN6_IFF_DEPRECATED,	setip6flags),
567 	DEF_CMD("autoconf",	IN6_IFF_AUTOCONF,	setip6flags),
568 	DEF_CMD("-autoconf",	-IN6_IFF_AUTOCONF,	setip6flags),
569 	DEF_CMD("prefer_source",IN6_IFF_PREFER_SOURCE,	setip6flags),
570 	DEF_CMD("-prefer_source",-IN6_IFF_PREFER_SOURCE,setip6flags),
571 	DEF_CMD("accept_rtadv",	ND6_IFF_ACCEPT_RTADV,	setnd6flags),
572 	DEF_CMD("-accept_rtadv",-ND6_IFF_ACCEPT_RTADV,	setnd6flags),
573 	DEF_CMD("no_radr",	ND6_IFF_NO_RADR,	setnd6flags),
574 	DEF_CMD("-no_radr",	-ND6_IFF_NO_RADR,	setnd6flags),
575 	DEF_CMD("defaultif",	1,			setnd6defif),
576 	DEF_CMD("-defaultif",	-1,			setnd6defif),
577 	DEF_CMD("ifdisabled",	ND6_IFF_IFDISABLED,	setnd6flags),
578 	DEF_CMD("-ifdisabled",	-ND6_IFF_IFDISABLED,	setnd6flags),
579 	DEF_CMD("nud",		ND6_IFF_PERFORMNUD,	setnd6flags),
580 	DEF_CMD("-nud",		-ND6_IFF_PERFORMNUD,	setnd6flags),
581 	DEF_CMD("auto_linklocal",ND6_IFF_AUTO_LINKLOCAL,setnd6flags),
582 	DEF_CMD("-auto_linklocal",-ND6_IFF_AUTO_LINKLOCAL,setnd6flags),
583 	DEF_CMD("no_prefer_iface",ND6_IFF_NO_PREFER_IFACE,setnd6flags),
584 	DEF_CMD("-no_prefer_iface",-ND6_IFF_NO_PREFER_IFACE,setnd6flags),
585 	DEF_CMD("no_dad",	ND6_IFF_NO_DAD,		setnd6flags),
586 	DEF_CMD("-no_dad",	-ND6_IFF_NO_DAD,	setnd6flags),
587 	DEF_CMD_ARG("pltime",        			setip6pltime),
588 	DEF_CMD_ARG("vltime",        			setip6vltime),
589 	DEF_CMD("eui64",	0,			setip6eui64),
590 #ifdef EXPERIMENTAL
591 	DEF_CMD("ipv6_only",	ND6_IFF_IPV6_ONLY_MANUAL,setnd6flags),
592 	DEF_CMD("-ipv6_only",	-ND6_IFF_IPV6_ONLY_MANUAL,setnd6flags),
593 #endif
594 };
595 
596 static struct afswtch af_inet6 = {
597 	.af_name	= "inet6",
598 	.af_af		= AF_INET6,
599 #ifdef WITHOUT_NETLINK
600 	.af_status	= in6_status,
601 #else
602 	.af_status	= in6_status_nl,
603 #endif
604 	.af_getaddr	= in6_getaddr,
605 	.af_getprefix	= in6_getprefix,
606 	.af_other_status = nd6_status,
607 	.af_postproc	= in6_postproc,
608 	.af_status_tunnel = in6_status_tunnel,
609 	.af_settunnel	= in6_set_tunnel,
610 	.af_setvhid	= in6_set_vhid,
611 	.af_difaddr	= SIOCDIFADDR_IN6,
612 	.af_aifaddr	= SIOCAIFADDR_IN6,
613 	.af_ridreq	= &in6_addreq,
614 	.af_addreq	= &in6_addreq,
615 };
616 
617 static void
618 in6_Lopt_cb(const char *optarg __unused)
619 {
620 	ip6lifetime++;	/* print IPv6 address lifetime */
621 }
622 static struct option in6_Lopt = {
623 	.opt = "L",
624 	.opt_usage = "[-L]",
625 	.cb = in6_Lopt_cb
626 };
627 
628 static __constructor void
629 inet6_ctor(void)
630 {
631 	size_t i;
632 
633 #ifndef RESCUE
634 	if (!feature_present("inet6"))
635 		return;
636 #endif
637 
638 	for (i = 0; i < nitems(inet6_cmds);  i++)
639 		cmd_register(&inet6_cmds[i]);
640 	af_register(&af_inet6);
641 	opt_register(&in6_Lopt);
642 }
643