1138593Ssam/* 2138593Ssam * Copyright (c) 1983, 1993 3138593Ssam * The Regents of the University of California. All rights reserved. 4138593Ssam * 5138593Ssam * Redistribution and use in source and binary forms, with or without 6138593Ssam * modification, are permitted provided that the following conditions 7138593Ssam * are met: 8138593Ssam * 1. Redistributions of source code must retain the above copyright 9138593Ssam * notice, this list of conditions and the following disclaimer. 10138593Ssam * 2. Redistributions in binary form must reproduce the above copyright 11138593Ssam * notice, this list of conditions and the following disclaimer in the 12138593Ssam * documentation and/or other materials provided with the distribution. 13138593Ssam * 4. Neither the name of the University nor the names of its contributors 14138593Ssam * may be used to endorse or promote products derived from this software 15138593Ssam * without specific prior written permission. 16138593Ssam * 17138593Ssam * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18138593Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19138593Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20138593Ssam * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21138593Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22138593Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23138593Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24138593Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25138593Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26138593Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27138593Ssam * SUCH DAMAGE. 28138593Ssam */ 29138593Ssam 30138593Ssam#ifndef lint 31138593Ssamstatic const char rcsid[] = 32138593Ssam "$FreeBSD: stable/10/sbin/ifconfig/af_inet6.c 319265 2017-05-30 22:45:01Z asomers $"; 33138593Ssam#endif /* not lint */ 34138593Ssam 35138593Ssam#include <sys/param.h> 36138593Ssam#include <sys/ioctl.h> 37138593Ssam#include <sys/socket.h> 38138593Ssam#include <net/if.h> 39138593Ssam 40138593Ssam#include <err.h> 41138593Ssam#include <stdio.h> 42138593Ssam#include <stdlib.h> 43138593Ssam#include <string.h> 44138593Ssam#include <unistd.h> 45268367Sume#include <time.h> 46138593Ssam#include <ifaddrs.h> 47138593Ssam 48138593Ssam#include <arpa/inet.h> 49138593Ssam 50138593Ssam#include <netinet/in.h> 51138593Ssam#include <net/if_var.h> /* for struct ifaddr */ 52138593Ssam#include <netinet/in_var.h> 53138593Ssam#include <arpa/inet.h> 54138593Ssam#include <netdb.h> 55138593Ssam 56138593Ssam#include <netinet6/nd6.h> /* Define ND6_INFINITE_LIFETIME */ 57138593Ssam 58138593Ssam#include "ifconfig.h" 59138593Ssam 60138593Ssamstatic struct in6_ifreq in6_ridreq; 61138593Ssamstatic struct in6_aliasreq in6_addreq = 62194799Sdelphij { .ifra_flags = 0, 63194799Sdelphij .ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } }; 64138593Ssamstatic int ip6lifetime; 65138593Ssam 66138593Ssamstatic int prefix(void *, int); 67138593Ssamstatic char *sec2str(time_t); 68138593Ssamstatic int explicit_prefix = 0; 69138593Ssam 70197138Shrsextern void setnd6flags(const char *, int, int, const struct afswtch *); 71197138Shrsextern void setnd6defif(const char *, int, int, const struct afswtch *); 72222711Shrsextern void nd6_status(int); 73197138Shrs 74138593Ssamstatic char addr_buf[MAXHOSTNAMELEN *2 + 1]; /*for getnameinfo()*/ 75138593Ssam 76138593Ssamstatic void 77138593Ssamsetifprefixlen(const char *addr, int dummy __unused, int s, 78138593Ssam const struct afswtch *afp) 79138593Ssam{ 80138593Ssam if (afp->af_getprefix != NULL) 81138593Ssam afp->af_getprefix(addr, MASK); 82138593Ssam explicit_prefix = 1; 83138593Ssam} 84138593Ssam 85138593Ssamstatic void 86138593Ssamsetip6flags(const char *dummyaddr __unused, int flag, int dummysoc __unused, 87138593Ssam const struct afswtch *afp) 88138593Ssam{ 89138593Ssam if (afp->af_af != AF_INET6) 90138593Ssam err(1, "address flags can be set only for inet6 addresses"); 91138593Ssam 92138593Ssam if (flag < 0) 93138593Ssam in6_addreq.ifra_flags &= ~(-flag); 94138593Ssam else 95138593Ssam in6_addreq.ifra_flags |= flag; 96138593Ssam} 97138593Ssam 98138593Ssamstatic void 99138593Ssamsetip6lifetime(const char *cmd, const char *val, int s, 100138593Ssam const struct afswtch *afp) 101138593Ssam{ 102268367Sume struct timespec now; 103268367Sume time_t newval; 104138593Ssam char *ep; 105138593Ssam 106268367Sume clock_gettime(CLOCK_MONOTONIC_FAST, &now); 107138593Ssam newval = (time_t)strtoul(val, &ep, 0); 108138593Ssam if (val == ep) 109138593Ssam errx(1, "invalid %s", cmd); 110138593Ssam if (afp->af_af != AF_INET6) 111138593Ssam errx(1, "%s not allowed for the AF", cmd); 112138593Ssam if (strcmp(cmd, "vltime") == 0) { 113268367Sume in6_addreq.ifra_lifetime.ia6t_expire = now.tv_sec + newval; 114138593Ssam in6_addreq.ifra_lifetime.ia6t_vltime = newval; 115138593Ssam } else if (strcmp(cmd, "pltime") == 0) { 116268367Sume in6_addreq.ifra_lifetime.ia6t_preferred = now.tv_sec + newval; 117138593Ssam in6_addreq.ifra_lifetime.ia6t_pltime = newval; 118138593Ssam } 119138593Ssam} 120138593Ssam 121138593Ssamstatic void 122138593Ssamsetip6pltime(const char *seconds, int dummy __unused, int s, 123138593Ssam const struct afswtch *afp) 124138593Ssam{ 125138593Ssam setip6lifetime("pltime", seconds, s, afp); 126138593Ssam} 127138593Ssam 128138593Ssamstatic void 129138593Ssamsetip6vltime(const char *seconds, int dummy __unused, int s, 130138593Ssam const struct afswtch *afp) 131138593Ssam{ 132138593Ssam setip6lifetime("vltime", seconds, s, afp); 133138593Ssam} 134138593Ssam 135138593Ssamstatic void 136138593Ssamsetip6eui64(const char *cmd, int dummy __unused, int s, 137138593Ssam const struct afswtch *afp) 138138593Ssam{ 139138593Ssam struct ifaddrs *ifap, *ifa; 140138593Ssam const struct sockaddr_in6 *sin6 = NULL; 141138593Ssam const struct in6_addr *lladdr = NULL; 142138593Ssam struct in6_addr *in6; 143138593Ssam 144138593Ssam if (afp->af_af != AF_INET6) 145138593Ssam errx(EXIT_FAILURE, "%s not allowed for the AF", cmd); 146138593Ssam in6 = (struct in6_addr *)&in6_addreq.ifra_addr.sin6_addr; 147138593Ssam if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0) 148138593Ssam errx(EXIT_FAILURE, "interface index is already filled"); 149138593Ssam if (getifaddrs(&ifap) != 0) 150138593Ssam err(EXIT_FAILURE, "getifaddrs"); 151138593Ssam for (ifa = ifap; ifa; ifa = ifa->ifa_next) { 152138593Ssam if (ifa->ifa_addr->sa_family == AF_INET6 && 153138593Ssam strcmp(ifa->ifa_name, name) == 0) { 154138593Ssam sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr; 155138593Ssam if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 156138593Ssam lladdr = &sin6->sin6_addr; 157138593Ssam break; 158138593Ssam } 159138593Ssam } 160138593Ssam } 161138593Ssam if (!lladdr) 162138593Ssam errx(EXIT_FAILURE, "could not determine link local address"); 163138593Ssam 164138593Ssam memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8); 165138593Ssam 166138593Ssam freeifaddrs(ifap); 167138593Ssam} 168138593Ssam 169138593Ssamstatic void 170166956Ssamin6_status(int s __unused, const struct ifaddrs *ifa) 171138593Ssam{ 172138593Ssam struct sockaddr_in6 *sin, null_sin; 173138593Ssam struct in6_ifreq ifr6; 174138593Ssam int s6; 175138593Ssam u_int32_t flags6; 176138593Ssam struct in6_addrlifetime lifetime; 177268367Sume struct timespec now; 178138593Ssam int error; 179138593Ssam 180268367Sume clock_gettime(CLOCK_MONOTONIC_FAST, &now); 181268367Sume 182138593Ssam memset(&null_sin, 0, sizeof(null_sin)); 183138593Ssam 184166956Ssam sin = (struct sockaddr_in6 *)ifa->ifa_addr; 185138593Ssam if (sin == NULL) 186138593Ssam return; 187138593Ssam 188300285Struckman strlcpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name)); 189138593Ssam if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 190138593Ssam warn("socket(AF_INET6,SOCK_DGRAM)"); 191138593Ssam return; 192138593Ssam } 193138593Ssam ifr6.ifr_addr = *sin; 194138593Ssam if (ioctl(s6, SIOCGIFAFLAG_IN6, &ifr6) < 0) { 195138593Ssam warn("ioctl(SIOCGIFAFLAG_IN6)"); 196138593Ssam close(s6); 197138593Ssam return; 198138593Ssam } 199138593Ssam flags6 = ifr6.ifr_ifru.ifru_flags6; 200138593Ssam memset(&lifetime, 0, sizeof(lifetime)); 201138593Ssam ifr6.ifr_addr = *sin; 202138593Ssam if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) { 203138593Ssam warn("ioctl(SIOCGIFALIFETIME_IN6)"); 204138593Ssam close(s6); 205138593Ssam return; 206138593Ssam } 207138593Ssam lifetime = ifr6.ifr_ifru.ifru_lifetime; 208138593Ssam close(s6); 209138593Ssam 210138593Ssam error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf, 211146187Sume sizeof(addr_buf), NULL, 0, NI_NUMERICHOST); 212138593Ssam if (error != 0) 213138593Ssam inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, 214138593Ssam sizeof(addr_buf)); 215138593Ssam printf("\tinet6 %s ", addr_buf); 216138593Ssam 217166956Ssam if (ifa->ifa_flags & IFF_POINTOPOINT) { 218166956Ssam sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr; 219138593Ssam /* 220138593Ssam * some of the interfaces do not have valid destination 221138593Ssam * address. 222138593Ssam */ 223166956Ssam if (sin != NULL && sin->sin6_family == AF_INET6) { 224138593Ssam int error; 225138593Ssam 226138593Ssam error = getnameinfo((struct sockaddr *)sin, 227138593Ssam sin->sin6_len, addr_buf, 228138593Ssam sizeof(addr_buf), NULL, 0, 229146187Sume NI_NUMERICHOST); 230138593Ssam if (error != 0) 231138593Ssam inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, 232138593Ssam sizeof(addr_buf)); 233138593Ssam printf("--> %s ", addr_buf); 234138593Ssam } 235138593Ssam } 236138593Ssam 237166956Ssam sin = (struct sockaddr_in6 *)ifa->ifa_netmask; 238166956Ssam if (sin == NULL) 239138593Ssam sin = &null_sin; 240138593Ssam printf("prefixlen %d ", prefix(&sin->sin6_addr, 241138593Ssam sizeof(struct in6_addr))); 242138593Ssam 243138593Ssam if ((flags6 & IN6_IFF_ANYCAST) != 0) 244138593Ssam printf("anycast "); 245138593Ssam if ((flags6 & IN6_IFF_TENTATIVE) != 0) 246138593Ssam printf("tentative "); 247138593Ssam if ((flags6 & IN6_IFF_DUPLICATED) != 0) 248138593Ssam printf("duplicated "); 249138593Ssam if ((flags6 & IN6_IFF_DETACHED) != 0) 250138593Ssam printf("detached "); 251138593Ssam if ((flags6 & IN6_IFF_DEPRECATED) != 0) 252138593Ssam printf("deprecated "); 253138593Ssam if ((flags6 & IN6_IFF_AUTOCONF) != 0) 254138593Ssam printf("autoconf "); 255138593Ssam if ((flags6 & IN6_IFF_TEMPORARY) != 0) 256138593Ssam printf("temporary "); 257272790Sae if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0) 258272790Sae printf("prefer_source "); 259138593Ssam 260243866Shrs if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) 261243866Shrs printf("scopeid 0x%x ", 262243866Shrs ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); 263138593Ssam 264138593Ssam if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { 265138593Ssam printf("pltime "); 266138593Ssam if (lifetime.ia6t_preferred) { 267268367Sume printf("%s ", lifetime.ia6t_preferred < now.tv_sec 268268367Sume ? "0" : sec2str(lifetime.ia6t_preferred - now.tv_sec)); 269138593Ssam } else 270138593Ssam printf("infty "); 271138593Ssam 272138593Ssam printf("vltime "); 273138593Ssam if (lifetime.ia6t_expire) { 274268367Sume printf("%s ", lifetime.ia6t_expire < now.tv_sec 275268367Sume ? "0" : sec2str(lifetime.ia6t_expire - now.tv_sec)); 276138593Ssam } else 277138593Ssam printf("infty "); 278138593Ssam } 279138593Ssam 280228571Sglebius print_vhid(ifa, " "); 281228571Sglebius 282138593Ssam putchar('\n'); 283138593Ssam} 284138593Ssam 285138593Ssam#define SIN6(x) ((struct sockaddr_in6 *) &(x)) 286138593Ssamstatic struct sockaddr_in6 *sin6tab[] = { 287138593Ssam SIN6(in6_ridreq.ifr_addr), SIN6(in6_addreq.ifra_addr), 288138593Ssam SIN6(in6_addreq.ifra_prefixmask), SIN6(in6_addreq.ifra_dstaddr) 289138593Ssam}; 290138593Ssam 291138593Ssamstatic void 292138593Ssamin6_getprefix(const char *plen, int which) 293138593Ssam{ 294138593Ssam struct sockaddr_in6 *sin = sin6tab[which]; 295138593Ssam u_char *cp; 296138593Ssam int len = atoi(plen); 297138593Ssam 298138593Ssam if ((len < 0) || (len > 128)) 299138593Ssam errx(1, "%s: bad value", plen); 300138593Ssam sin->sin6_len = sizeof(*sin); 301138593Ssam if (which != MASK) 302138593Ssam sin->sin6_family = AF_INET6; 303138593Ssam if ((len == 0) || (len == 128)) { 304138593Ssam memset(&sin->sin6_addr, 0xff, sizeof(struct in6_addr)); 305138593Ssam return; 306138593Ssam } 307138593Ssam memset((void *)&sin->sin6_addr, 0x00, sizeof(sin->sin6_addr)); 308138593Ssam for (cp = (u_char *)&sin->sin6_addr; len > 7; len -= 8) 309138593Ssam *cp++ = 0xff; 310138593Ssam *cp = 0xff << (8 - len); 311138593Ssam} 312138593Ssam 313138593Ssamstatic void 314138593Ssamin6_getaddr(const char *s, int which) 315138593Ssam{ 316138593Ssam struct sockaddr_in6 *sin = sin6tab[which]; 317138593Ssam struct addrinfo hints, *res; 318138593Ssam int error = -1; 319138593Ssam 320138593Ssam newaddr &= 1; 321138593Ssam 322138593Ssam sin->sin6_len = sizeof(*sin); 323138593Ssam if (which != MASK) 324138593Ssam sin->sin6_family = AF_INET6; 325138593Ssam 326138593Ssam if (which == ADDR) { 327138593Ssam char *p = NULL; 328138593Ssam if((p = strrchr(s, '/')) != NULL) { 329138593Ssam *p = '\0'; 330138593Ssam in6_getprefix(p + 1, MASK); 331138593Ssam explicit_prefix = 1; 332138593Ssam } 333138593Ssam } 334138593Ssam 335138593Ssam if (sin->sin6_family == AF_INET6) { 336138593Ssam bzero(&hints, sizeof(struct addrinfo)); 337138593Ssam hints.ai_family = AF_INET6; 338138593Ssam error = getaddrinfo(s, NULL, &hints, &res); 339319265Sasomers if (error != 0) { 340319265Sasomers if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1) 341319265Sasomers errx(1, "%s: bad value", s); 342319265Sasomers } else { 343319265Sasomers bcopy(res->ai_addr, sin, res->ai_addrlen); 344319265Sasomers freeaddrinfo(res); 345319265Sasomers } 346138593Ssam } 347138593Ssam} 348138593Ssam 349138593Ssamstatic int 350138593Ssamprefix(void *val, int size) 351138593Ssam{ 352138593Ssam u_char *name = (u_char *)val; 353138593Ssam int byte, bit, plen = 0; 354138593Ssam 355138593Ssam for (byte = 0; byte < size; byte++, plen += 8) 356138593Ssam if (name[byte] != 0xff) 357138593Ssam break; 358138593Ssam if (byte == size) 359138593Ssam return (plen); 360138593Ssam for (bit = 7; bit != 0; bit--, plen++) 361138593Ssam if (!(name[byte] & (1 << bit))) 362138593Ssam break; 363138593Ssam for (; bit != 0; bit--) 364138593Ssam if (name[byte] & (1 << bit)) 365138593Ssam return(0); 366138593Ssam byte++; 367138593Ssam for (; byte < size; byte++) 368138593Ssam if (name[byte]) 369138593Ssam return(0); 370138593Ssam return (plen); 371138593Ssam} 372138593Ssam 373138593Ssamstatic char * 374138593Ssamsec2str(time_t total) 375138593Ssam{ 376138593Ssam static char result[256]; 377138593Ssam int days, hours, mins, secs; 378138593Ssam int first = 1; 379138593Ssam char *p = result; 380138593Ssam 381138593Ssam if (0) { 382138593Ssam days = total / 3600 / 24; 383138593Ssam hours = (total / 3600) % 24; 384138593Ssam mins = (total / 60) % 60; 385138593Ssam secs = total % 60; 386138593Ssam 387138593Ssam if (days) { 388138593Ssam first = 0; 389138593Ssam p += sprintf(p, "%dd", days); 390138593Ssam } 391138593Ssam if (!first || hours) { 392138593Ssam first = 0; 393138593Ssam p += sprintf(p, "%dh", hours); 394138593Ssam } 395138593Ssam if (!first || mins) { 396138593Ssam first = 0; 397138593Ssam p += sprintf(p, "%dm", mins); 398138593Ssam } 399138593Ssam sprintf(p, "%ds", secs); 400138593Ssam } else 401138593Ssam sprintf(result, "%lu", (unsigned long)total); 402138593Ssam 403138593Ssam return(result); 404138593Ssam} 405138593Ssam 406138593Ssamstatic void 407138593Ssamin6_postproc(int s, const struct afswtch *afp) 408138593Ssam{ 409138593Ssam if (explicit_prefix == 0) { 410138593Ssam /* Aggregatable address architecture defines all prefixes 411138593Ssam are 64. So, it is convenient to set prefixlen to 64 if 412138593Ssam it is not specified. */ 413138593Ssam setifprefixlen("64", 0, s, afp); 414138593Ssam /* in6_getprefix("64", MASK) if MASK is available here... */ 415138593Ssam } 416138593Ssam} 417138593Ssam 418138593Ssamstatic void 419138593Ssamin6_status_tunnel(int s) 420138593Ssam{ 421138593Ssam char src[NI_MAXHOST]; 422138593Ssam char dst[NI_MAXHOST]; 423138593Ssam struct in6_ifreq in6_ifr; 424138593Ssam const struct sockaddr *sa = (const struct sockaddr *) &in6_ifr.ifr_addr; 425138593Ssam 426138593Ssam memset(&in6_ifr, 0, sizeof(in6_ifr)); 427300285Struckman strlcpy(in6_ifr.ifr_name, name, sizeof(in6_ifr.ifr_name)); 428138593Ssam 429138593Ssam if (ioctl(s, SIOCGIFPSRCADDR_IN6, (caddr_t)&in6_ifr) < 0) 430138593Ssam return; 431147437Sume if (sa->sa_family != AF_INET6) 432147437Sume return; 433146187Sume if (getnameinfo(sa, sa->sa_len, src, sizeof(src), 0, 0, 434146187Sume NI_NUMERICHOST) != 0) 435138593Ssam src[0] = '\0'; 436138593Ssam 437138593Ssam if (ioctl(s, SIOCGIFPDSTADDR_IN6, (caddr_t)&in6_ifr) < 0) 438138593Ssam return; 439147437Sume if (sa->sa_family != AF_INET6) 440147437Sume return; 441146187Sume if (getnameinfo(sa, sa->sa_len, dst, sizeof(dst), 0, 0, 442146187Sume NI_NUMERICHOST) != 0) 443138593Ssam dst[0] = '\0'; 444138593Ssam 445138593Ssam printf("\ttunnel inet6 %s --> %s\n", src, dst); 446138593Ssam} 447138593Ssam 448138593Ssamstatic void 449138593Ssamin6_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres) 450138593Ssam{ 451138593Ssam struct in6_aliasreq in6_addreq; 452138593Ssam 453138593Ssam memset(&in6_addreq, 0, sizeof(in6_addreq)); 454300285Struckman strlcpy(in6_addreq.ifra_name, name, sizeof(in6_addreq.ifra_name)); 455138593Ssam memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len); 456138593Ssam memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr, 457138593Ssam dstres->ai_addr->sa_len); 458138593Ssam 459138593Ssam if (ioctl(s, SIOCSIFPHYADDR_IN6, &in6_addreq) < 0) 460138593Ssam warn("SIOCSIFPHYADDR_IN6"); 461138593Ssam} 462138593Ssam 463138593Ssamstatic struct cmd inet6_cmds[] = { 464138593Ssam DEF_CMD_ARG("prefixlen", setifprefixlen), 465138593Ssam DEF_CMD("anycast", IN6_IFF_ANYCAST, setip6flags), 466138593Ssam DEF_CMD("tentative", IN6_IFF_TENTATIVE, setip6flags), 467138593Ssam DEF_CMD("-tentative", -IN6_IFF_TENTATIVE, setip6flags), 468138593Ssam DEF_CMD("deprecated", IN6_IFF_DEPRECATED, setip6flags), 469138593Ssam DEF_CMD("-deprecated", -IN6_IFF_DEPRECATED, setip6flags), 470138593Ssam DEF_CMD("autoconf", IN6_IFF_AUTOCONF, setip6flags), 471138593Ssam DEF_CMD("-autoconf", -IN6_IFF_AUTOCONF, setip6flags), 472272790Sae DEF_CMD("prefer_source",IN6_IFF_PREFER_SOURCE, setip6flags), 473272790Sae DEF_CMD("-prefer_source",-IN6_IFF_PREFER_SOURCE,setip6flags), 474197138Shrs DEF_CMD("accept_rtadv", ND6_IFF_ACCEPT_RTADV, setnd6flags), 475197138Shrs DEF_CMD("-accept_rtadv",-ND6_IFF_ACCEPT_RTADV, setnd6flags), 476222728Shrs DEF_CMD("no_radr", ND6_IFF_NO_RADR, setnd6flags), 477222728Shrs DEF_CMD("-no_radr", -ND6_IFF_NO_RADR, setnd6flags), 478197138Shrs DEF_CMD("defaultif", 1, setnd6defif), 479197138Shrs DEF_CMD("-defaultif", -1, setnd6defif), 480197138Shrs DEF_CMD("ifdisabled", ND6_IFF_IFDISABLED, setnd6flags), 481197138Shrs DEF_CMD("-ifdisabled", -ND6_IFF_IFDISABLED, setnd6flags), 482197138Shrs DEF_CMD("nud", ND6_IFF_PERFORMNUD, setnd6flags), 483197138Shrs DEF_CMD("-nud", -ND6_IFF_PERFORMNUD, setnd6flags), 484197138Shrs DEF_CMD("auto_linklocal",ND6_IFF_AUTO_LINKLOCAL,setnd6flags), 485197138Shrs DEF_CMD("-auto_linklocal",-ND6_IFF_AUTO_LINKLOCAL,setnd6flags), 486245230Sume DEF_CMD("no_prefer_iface",ND6_IFF_NO_PREFER_IFACE,setnd6flags), 487245230Sume DEF_CMD("-no_prefer_iface",-ND6_IFF_NO_PREFER_IFACE,setnd6flags), 488282622Shiren DEF_CMD("no_dad", ND6_IFF_NO_DAD, setnd6flags), 489282622Shiren DEF_CMD("-no_dad", -ND6_IFF_NO_DAD, setnd6flags), 490138593Ssam DEF_CMD_ARG("pltime", setip6pltime), 491138593Ssam DEF_CMD_ARG("vltime", setip6vltime), 492138593Ssam DEF_CMD("eui64", 0, setip6eui64), 493138593Ssam}; 494138593Ssam 495138593Ssamstatic struct afswtch af_inet6 = { 496138593Ssam .af_name = "inet6", 497138593Ssam .af_af = AF_INET6, 498138593Ssam .af_status = in6_status, 499138593Ssam .af_getaddr = in6_getaddr, 500138593Ssam .af_getprefix = in6_getprefix, 501222711Shrs .af_other_status = nd6_status, 502138593Ssam .af_postproc = in6_postproc, 503138593Ssam .af_status_tunnel = in6_status_tunnel, 504138593Ssam .af_settunnel = in6_set_tunnel, 505138593Ssam .af_difaddr = SIOCDIFADDR_IN6, 506138593Ssam .af_aifaddr = SIOCAIFADDR_IN6, 507166446Sbms .af_ridreq = &in6_addreq, 508138593Ssam .af_addreq = &in6_addreq, 509138593Ssam}; 510138593Ssam 511138593Ssamstatic void 512138593Ssamin6_Lopt_cb(const char *optarg __unused) 513138593Ssam{ 514138593Ssam ip6lifetime++; /* print IPv6 address lifetime */ 515138593Ssam} 516194799Sdelphijstatic struct option in6_Lopt = { .opt = "L", .opt_usage = "[-L]", .cb = in6_Lopt_cb }; 517138593Ssam 518138593Ssamstatic __constructor void 519138593Ssaminet6_ctor(void) 520138593Ssam{ 521194799Sdelphij size_t i; 522138593Ssam 523224179Sbz#ifndef RESCUE 524222527Sbz if (!feature_present("inet6")) 525222527Sbz return; 526224179Sbz#endif 527222527Sbz 528289986Sngie for (i = 0; i < nitems(inet6_cmds); i++) 529138593Ssam cmd_register(&inet6_cmds[i]); 530138593Ssam af_register(&af_inet6); 531138593Ssam opt_register(&in6_Lopt); 532138593Ssam} 533