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