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$"; 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 188138593Ssam strncpy(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 "); 257138593Ssam 258243866Shrs if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) 259243866Shrs printf("scopeid 0x%x ", 260243866Shrs ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); 261138593Ssam 262138593Ssam if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { 263138593Ssam printf("pltime "); 264138593Ssam if (lifetime.ia6t_preferred) { 265268367Sume printf("%s ", lifetime.ia6t_preferred < now.tv_sec 266268367Sume ? "0" : sec2str(lifetime.ia6t_preferred - now.tv_sec)); 267138593Ssam } else 268138593Ssam printf("infty "); 269138593Ssam 270138593Ssam printf("vltime "); 271138593Ssam if (lifetime.ia6t_expire) { 272268367Sume printf("%s ", lifetime.ia6t_expire < now.tv_sec 273268367Sume ? "0" : sec2str(lifetime.ia6t_expire - now.tv_sec)); 274138593Ssam } else 275138593Ssam printf("infty "); 276138593Ssam } 277138593Ssam 278228571Sglebius print_vhid(ifa, " "); 279228571Sglebius 280138593Ssam putchar('\n'); 281138593Ssam} 282138593Ssam 283138593Ssam#define SIN6(x) ((struct sockaddr_in6 *) &(x)) 284138593Ssamstatic struct sockaddr_in6 *sin6tab[] = { 285138593Ssam SIN6(in6_ridreq.ifr_addr), SIN6(in6_addreq.ifra_addr), 286138593Ssam SIN6(in6_addreq.ifra_prefixmask), SIN6(in6_addreq.ifra_dstaddr) 287138593Ssam}; 288138593Ssam 289138593Ssamstatic void 290138593Ssamin6_getprefix(const char *plen, int which) 291138593Ssam{ 292138593Ssam struct sockaddr_in6 *sin = sin6tab[which]; 293138593Ssam u_char *cp; 294138593Ssam int len = atoi(plen); 295138593Ssam 296138593Ssam if ((len < 0) || (len > 128)) 297138593Ssam errx(1, "%s: bad value", plen); 298138593Ssam sin->sin6_len = sizeof(*sin); 299138593Ssam if (which != MASK) 300138593Ssam sin->sin6_family = AF_INET6; 301138593Ssam if ((len == 0) || (len == 128)) { 302138593Ssam memset(&sin->sin6_addr, 0xff, sizeof(struct in6_addr)); 303138593Ssam return; 304138593Ssam } 305138593Ssam memset((void *)&sin->sin6_addr, 0x00, sizeof(sin->sin6_addr)); 306138593Ssam for (cp = (u_char *)&sin->sin6_addr; len > 7; len -= 8) 307138593Ssam *cp++ = 0xff; 308138593Ssam *cp = 0xff << (8 - len); 309138593Ssam} 310138593Ssam 311138593Ssamstatic void 312138593Ssamin6_getaddr(const char *s, int which) 313138593Ssam{ 314138593Ssam struct sockaddr_in6 *sin = sin6tab[which]; 315138593Ssam struct addrinfo hints, *res; 316138593Ssam int error = -1; 317138593Ssam 318138593Ssam newaddr &= 1; 319138593Ssam 320138593Ssam sin->sin6_len = sizeof(*sin); 321138593Ssam if (which != MASK) 322138593Ssam sin->sin6_family = AF_INET6; 323138593Ssam 324138593Ssam if (which == ADDR) { 325138593Ssam char *p = NULL; 326138593Ssam if((p = strrchr(s, '/')) != NULL) { 327138593Ssam *p = '\0'; 328138593Ssam in6_getprefix(p + 1, MASK); 329138593Ssam explicit_prefix = 1; 330138593Ssam } 331138593Ssam } 332138593Ssam 333138593Ssam if (sin->sin6_family == AF_INET6) { 334138593Ssam bzero(&hints, sizeof(struct addrinfo)); 335138593Ssam hints.ai_family = AF_INET6; 336138593Ssam error = getaddrinfo(s, NULL, &hints, &res); 337138593Ssam } 338138593Ssam if (error != 0) { 339138593Ssam if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1) 340138593Ssam errx(1, "%s: bad value", s); 341138593Ssam } else 342138593Ssam bcopy(res->ai_addr, sin, res->ai_addrlen); 343138593Ssam} 344138593Ssam 345138593Ssamstatic int 346138593Ssamprefix(void *val, int size) 347138593Ssam{ 348138593Ssam u_char *name = (u_char *)val; 349138593Ssam int byte, bit, plen = 0; 350138593Ssam 351138593Ssam for (byte = 0; byte < size; byte++, plen += 8) 352138593Ssam if (name[byte] != 0xff) 353138593Ssam break; 354138593Ssam if (byte == size) 355138593Ssam return (plen); 356138593Ssam for (bit = 7; bit != 0; bit--, plen++) 357138593Ssam if (!(name[byte] & (1 << bit))) 358138593Ssam break; 359138593Ssam for (; bit != 0; bit--) 360138593Ssam if (name[byte] & (1 << bit)) 361138593Ssam return(0); 362138593Ssam byte++; 363138593Ssam for (; byte < size; byte++) 364138593Ssam if (name[byte]) 365138593Ssam return(0); 366138593Ssam return (plen); 367138593Ssam} 368138593Ssam 369138593Ssamstatic char * 370138593Ssamsec2str(time_t total) 371138593Ssam{ 372138593Ssam static char result[256]; 373138593Ssam int days, hours, mins, secs; 374138593Ssam int first = 1; 375138593Ssam char *p = result; 376138593Ssam 377138593Ssam if (0) { 378138593Ssam days = total / 3600 / 24; 379138593Ssam hours = (total / 3600) % 24; 380138593Ssam mins = (total / 60) % 60; 381138593Ssam secs = total % 60; 382138593Ssam 383138593Ssam if (days) { 384138593Ssam first = 0; 385138593Ssam p += sprintf(p, "%dd", days); 386138593Ssam } 387138593Ssam if (!first || hours) { 388138593Ssam first = 0; 389138593Ssam p += sprintf(p, "%dh", hours); 390138593Ssam } 391138593Ssam if (!first || mins) { 392138593Ssam first = 0; 393138593Ssam p += sprintf(p, "%dm", mins); 394138593Ssam } 395138593Ssam sprintf(p, "%ds", secs); 396138593Ssam } else 397138593Ssam sprintf(result, "%lu", (unsigned long)total); 398138593Ssam 399138593Ssam return(result); 400138593Ssam} 401138593Ssam 402138593Ssamstatic void 403138593Ssamin6_postproc(int s, const struct afswtch *afp) 404138593Ssam{ 405138593Ssam if (explicit_prefix == 0) { 406138593Ssam /* Aggregatable address architecture defines all prefixes 407138593Ssam are 64. So, it is convenient to set prefixlen to 64 if 408138593Ssam it is not specified. */ 409138593Ssam setifprefixlen("64", 0, s, afp); 410138593Ssam /* in6_getprefix("64", MASK) if MASK is available here... */ 411138593Ssam } 412138593Ssam} 413138593Ssam 414138593Ssamstatic void 415138593Ssamin6_status_tunnel(int s) 416138593Ssam{ 417138593Ssam char src[NI_MAXHOST]; 418138593Ssam char dst[NI_MAXHOST]; 419138593Ssam struct in6_ifreq in6_ifr; 420138593Ssam const struct sockaddr *sa = (const struct sockaddr *) &in6_ifr.ifr_addr; 421138593Ssam 422138593Ssam memset(&in6_ifr, 0, sizeof(in6_ifr)); 423138593Ssam strncpy(in6_ifr.ifr_name, name, IFNAMSIZ); 424138593Ssam 425138593Ssam if (ioctl(s, SIOCGIFPSRCADDR_IN6, (caddr_t)&in6_ifr) < 0) 426138593Ssam return; 427147437Sume if (sa->sa_family != AF_INET6) 428147437Sume return; 429146187Sume if (getnameinfo(sa, sa->sa_len, src, sizeof(src), 0, 0, 430146187Sume NI_NUMERICHOST) != 0) 431138593Ssam src[0] = '\0'; 432138593Ssam 433138593Ssam if (ioctl(s, SIOCGIFPDSTADDR_IN6, (caddr_t)&in6_ifr) < 0) 434138593Ssam return; 435147437Sume if (sa->sa_family != AF_INET6) 436147437Sume return; 437146187Sume if (getnameinfo(sa, sa->sa_len, dst, sizeof(dst), 0, 0, 438146187Sume NI_NUMERICHOST) != 0) 439138593Ssam dst[0] = '\0'; 440138593Ssam 441138593Ssam printf("\ttunnel inet6 %s --> %s\n", src, dst); 442138593Ssam} 443138593Ssam 444138593Ssamstatic void 445138593Ssamin6_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres) 446138593Ssam{ 447138593Ssam struct in6_aliasreq in6_addreq; 448138593Ssam 449138593Ssam memset(&in6_addreq, 0, sizeof(in6_addreq)); 450138593Ssam strncpy(in6_addreq.ifra_name, name, IFNAMSIZ); 451138593Ssam memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len); 452138593Ssam memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr, 453138593Ssam dstres->ai_addr->sa_len); 454138593Ssam 455138593Ssam if (ioctl(s, SIOCSIFPHYADDR_IN6, &in6_addreq) < 0) 456138593Ssam warn("SIOCSIFPHYADDR_IN6"); 457138593Ssam} 458138593Ssam 459138593Ssamstatic struct cmd inet6_cmds[] = { 460138593Ssam DEF_CMD_ARG("prefixlen", setifprefixlen), 461138593Ssam DEF_CMD("anycast", IN6_IFF_ANYCAST, setip6flags), 462138593Ssam DEF_CMD("tentative", IN6_IFF_TENTATIVE, setip6flags), 463138593Ssam DEF_CMD("-tentative", -IN6_IFF_TENTATIVE, setip6flags), 464138593Ssam DEF_CMD("deprecated", IN6_IFF_DEPRECATED, setip6flags), 465138593Ssam DEF_CMD("-deprecated", -IN6_IFF_DEPRECATED, setip6flags), 466138593Ssam DEF_CMD("autoconf", IN6_IFF_AUTOCONF, setip6flags), 467138593Ssam DEF_CMD("-autoconf", -IN6_IFF_AUTOCONF, setip6flags), 468197138Shrs DEF_CMD("accept_rtadv", ND6_IFF_ACCEPT_RTADV, setnd6flags), 469197138Shrs DEF_CMD("-accept_rtadv",-ND6_IFF_ACCEPT_RTADV, setnd6flags), 470222728Shrs DEF_CMD("no_radr", ND6_IFF_NO_RADR, setnd6flags), 471222728Shrs DEF_CMD("-no_radr", -ND6_IFF_NO_RADR, setnd6flags), 472197138Shrs DEF_CMD("defaultif", 1, setnd6defif), 473197138Shrs DEF_CMD("-defaultif", -1, setnd6defif), 474197138Shrs DEF_CMD("ifdisabled", ND6_IFF_IFDISABLED, setnd6flags), 475197138Shrs DEF_CMD("-ifdisabled", -ND6_IFF_IFDISABLED, setnd6flags), 476197138Shrs DEF_CMD("nud", ND6_IFF_PERFORMNUD, setnd6flags), 477197138Shrs DEF_CMD("-nud", -ND6_IFF_PERFORMNUD, setnd6flags), 478197138Shrs DEF_CMD("auto_linklocal",ND6_IFF_AUTO_LINKLOCAL,setnd6flags), 479197138Shrs DEF_CMD("-auto_linklocal",-ND6_IFF_AUTO_LINKLOCAL,setnd6flags), 480245230Sume DEF_CMD("no_prefer_iface",ND6_IFF_NO_PREFER_IFACE,setnd6flags), 481245230Sume DEF_CMD("-no_prefer_iface",-ND6_IFF_NO_PREFER_IFACE,setnd6flags), 482138593Ssam DEF_CMD_ARG("pltime", setip6pltime), 483138593Ssam DEF_CMD_ARG("vltime", setip6vltime), 484138593Ssam DEF_CMD("eui64", 0, setip6eui64), 485138593Ssam}; 486138593Ssam 487138593Ssamstatic struct afswtch af_inet6 = { 488138593Ssam .af_name = "inet6", 489138593Ssam .af_af = AF_INET6, 490138593Ssam .af_status = in6_status, 491138593Ssam .af_getaddr = in6_getaddr, 492138593Ssam .af_getprefix = in6_getprefix, 493222711Shrs .af_other_status = nd6_status, 494138593Ssam .af_postproc = in6_postproc, 495138593Ssam .af_status_tunnel = in6_status_tunnel, 496138593Ssam .af_settunnel = in6_set_tunnel, 497138593Ssam .af_difaddr = SIOCDIFADDR_IN6, 498138593Ssam .af_aifaddr = SIOCAIFADDR_IN6, 499166446Sbms .af_ridreq = &in6_addreq, 500138593Ssam .af_addreq = &in6_addreq, 501138593Ssam}; 502138593Ssam 503138593Ssamstatic void 504138593Ssamin6_Lopt_cb(const char *optarg __unused) 505138593Ssam{ 506138593Ssam ip6lifetime++; /* print IPv6 address lifetime */ 507138593Ssam} 508194799Sdelphijstatic struct option in6_Lopt = { .opt = "L", .opt_usage = "[-L]", .cb = in6_Lopt_cb }; 509138593Ssam 510138593Ssamstatic __constructor void 511138593Ssaminet6_ctor(void) 512138593Ssam{ 513138593Ssam#define N(a) (sizeof(a) / sizeof(a[0])) 514194799Sdelphij size_t i; 515138593Ssam 516224179Sbz#ifndef RESCUE 517222527Sbz if (!feature_present("inet6")) 518222527Sbz return; 519224179Sbz#endif 520222527Sbz 521138593Ssam for (i = 0; i < N(inet6_cmds); i++) 522138593Ssam cmd_register(&inet6_cmds[i]); 523138593Ssam af_register(&af_inet6); 524138593Ssam opt_register(&in6_Lopt); 525138593Ssam#undef N 526138593Ssam} 527