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