1/* 2 * Copyright (c) 2009-2013 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29/* 30 * Copyright (c) 1983, 1993 31 * The Regents of the University of California. All rights reserved. 32 * 33 * Redistribution and use in source and binary forms, with or without 34 * modification, are permitted provided that the following conditions 35 * are met: 36 * 1. Redistributions of source code must retain the above copyright 37 * notice, this list of conditions and the following disclaimer. 38 * 2. Redistributions in binary form must reproduce the above copyright 39 * notice, this list of conditions and the following disclaimer in the 40 * documentation and/or other materials provided with the distribution. 41 * 4. Neither the name of the University nor the names of its contributors 42 * may be used to endorse or promote products derived from this software 43 * without specific prior written permission. 44 * 45 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 48 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 55 * SUCH DAMAGE. 56 */ 57 58#ifndef lint 59static const char rcsid[] = 60 "$FreeBSD: src/sbin/ifconfig/af_inet6.c,v 1.6.6.1 2008/11/25 02:59:29 kensmith Exp $"; 61#endif /* not lint */ 62 63#include <sys/param.h> 64#include <sys/ioctl.h> 65#include <sys/socket.h> 66#include <net/if.h> 67 68#include <err.h> 69#include <errno.h> 70#include <stdio.h> 71#include <stdlib.h> 72#include <string.h> 73#include <unistd.h> 74#include <ifaddrs.h> 75 76#include <arpa/inet.h> 77 78#include <netinet/in.h> 79#include <net/if_var.h> /* for struct ifaddr */ 80#include <netinet/in_var.h> 81#include <arpa/inet.h> 82#include <netdb.h> 83 84#include <netinet6/nd6.h> /* Define ND6_INFINITE_LIFETIME */ 85 86#include "ifconfig.h" 87 88#define ND6BITS "\020\001PERFORMNUD\002ACCEPT_RTADV\003PREFER_SOURCE" \ 89 "\004IFDISABLED\005DONT_SET_IFROUTE\006PROXY_PREFIXES" \ 90 "\007IGNORE_NA\010INSECURE" 91 92static struct in6_ifreq in6_ridreq; 93static struct in6_aliasreq in6_addreq = 94 { { 0 }, 95 { 0 }, 96 { 0 }, 97 { 0 }, 98 0, 99 { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } }; 100static int ip6lifetime; 101 102static void in6_fillscopeid(struct sockaddr_in6 *sin6); 103static int prefix(void *, int); 104static char *sec2str(time_t); 105static int explicit_prefix = 0; 106 107static char addr_buf[MAXHOSTNAMELEN *2 + 1]; /*for getnameinfo()*/ 108 109static void 110setifprefixlen(const char *addr, int dummy __unused, int s, 111 const struct afswtch *afp) 112{ 113 if (afp->af_getprefix != NULL) 114 afp->af_getprefix(addr, MASK); 115 explicit_prefix = 1; 116} 117 118static void 119setnd6flags(const char *dummyaddr __unused, int d, int s, 120 const struct afswtch *afp) 121{ 122 struct in6_ndireq nd; 123 int error; 124 125 memset(&nd, 0, sizeof(nd)); 126 strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname)); 127 error = ioctl(s, SIOCGIFINFO_IN6, &nd); 128 if (error) { 129 warn("ioctl(SIOCGIFINFO_IN6)"); 130 return; 131 } 132 if (d < 0) 133 nd.ndi.flags &= ~(-d); 134 else 135 nd.ndi.flags |= d; 136 error = ioctl(s, SIOCSIFINFO_FLAGS, (caddr_t)&nd); 137 if (error) 138 warn("ioctl(SIOCSIFINFO_FLAGS)"); 139} 140 141static void 142setip6flags(const char *dummyaddr __unused, int flag, int dummysoc __unused, 143 const struct afswtch *afp) 144{ 145 if (afp->af_af != AF_INET6) 146 err(1, "address flags can be set only for inet6 addresses"); 147 148 if (flag < 0) 149 in6_addreq.ifra_flags &= ~(-flag); 150 else 151 in6_addreq.ifra_flags |= flag; 152} 153 154static void 155setip6lifetime(const char *cmd, const char *val, int s, 156 const struct afswtch *afp) 157{ 158 time_t newval, t; 159 char *ep; 160 161 t = time(NULL); 162 newval = (time_t)strtoul(val, &ep, 0); 163 if (val == ep) 164 errx(1, "invalid %s", cmd); 165 if (afp->af_af != AF_INET6) 166 errx(1, "%s not allowed for the AF", cmd); 167 if (strcmp(cmd, "vltime") == 0) { 168 in6_addreq.ifra_lifetime.ia6t_expire = t + newval; 169 in6_addreq.ifra_lifetime.ia6t_vltime = newval; 170 } else if (strcmp(cmd, "pltime") == 0) { 171 in6_addreq.ifra_lifetime.ia6t_preferred = t + newval; 172 in6_addreq.ifra_lifetime.ia6t_pltime = newval; 173 } 174} 175 176static void 177setip6pltime(const char *seconds, int dummy __unused, int s, 178 const struct afswtch *afp) 179{ 180 setip6lifetime("pltime", seconds, s, afp); 181} 182 183static void 184setip6vltime(const char *seconds, int dummy __unused, int s, 185 const struct afswtch *afp) 186{ 187 setip6lifetime("vltime", seconds, s, afp); 188} 189 190static void 191setip6eui64(const char *cmd, int dummy __unused, int s, 192 const struct afswtch *afp) 193{ 194 struct ifaddrs *ifap, *ifa; 195 const struct sockaddr_in6 *sin6 = NULL; 196 const struct in6_addr *lladdr = NULL; 197 struct in6_addr *in6; 198 199 if (afp->af_af != AF_INET6) 200 errx(EXIT_FAILURE, "%s not allowed for the AF", cmd); 201 in6 = (struct in6_addr *)&in6_addreq.ifra_addr.sin6_addr; 202 if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0) 203 errx(EXIT_FAILURE, "interface index is already filled"); 204 if (getifaddrs(&ifap) != 0) 205 err(EXIT_FAILURE, "getifaddrs"); 206 for (ifa = ifap; ifa; ifa = ifa->ifa_next) { 207 if (ifa->ifa_addr->sa_family == AF_INET6 && 208 strcmp(ifa->ifa_name, name) == 0) { 209 sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr; 210 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 211 lladdr = &sin6->sin6_addr; 212 break; 213 } 214 } 215 } 216 if (!lladdr) 217 errx(EXIT_FAILURE, "could not determine link local address"); 218 219 memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8); 220 221 freeifaddrs(ifap); 222} 223 224static void 225in6_fillscopeid(struct sockaddr_in6 *sin6) 226{ 227#if defined(__KAME__) && defined(KAME_SCOPEID) 228 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 229 sin6->sin6_scope_id = 230 ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]); 231 sin6->sin6_addr.s6_addr[2] = sin6->sin6_addr.s6_addr[3] = 0; 232 } 233#endif 234} 235 236static void 237in6_status(int s __unused, const struct ifaddrs *ifa) 238{ 239 struct sockaddr_in6 *sin, null_sin; 240 struct in6_ifreq ifr6; 241 int s6; 242 u_int32_t flags6; 243 struct in6_addrlifetime lifetime; 244 time_t t = time(NULL); 245 int error; 246 u_int32_t scopeid; 247 248 memset(&null_sin, 0, sizeof(null_sin)); 249 250 sin = (struct sockaddr_in6 *)ifa->ifa_addr; 251 if (sin == NULL) 252 return; 253 254 strncpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name)); 255 if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 256 warn("socket(AF_INET6,SOCK_DGRAM)"); 257 return; 258 } 259 ifr6.ifr_addr = *sin; 260 if (ioctl(s6, SIOCGIFAFLAG_IN6, &ifr6) < 0) { 261 warn("ioctl(SIOCGIFAFLAG_IN6)"); 262 close(s6); 263 return; 264 } 265 flags6 = ifr6.ifr_ifru.ifru_flags6; 266 memset(&lifetime, 0, sizeof(lifetime)); 267 ifr6.ifr_addr = *sin; 268 if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) { 269 warn("ioctl(SIOCGIFALIFETIME_IN6)"); 270 close(s6); 271 return; 272 } 273 lifetime = ifr6.ifr_ifru.ifru_lifetime; 274 close(s6); 275 276 /* XXX: embedded link local addr check */ 277 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) && 278 *(u_short *)&sin->sin6_addr.s6_addr[2] != 0) { 279 u_short index; 280 281 index = *(u_short *)&sin->sin6_addr.s6_addr[2]; 282 *(u_short *)&sin->sin6_addr.s6_addr[2] = 0; 283 if (sin->sin6_scope_id == 0) 284 sin->sin6_scope_id = ntohs(index); 285 } 286 scopeid = sin->sin6_scope_id; 287 288 error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, addr_buf, 289 sizeof(addr_buf), NULL, 0, NI_NUMERICHOST); 290 if (error != 0) 291 inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, 292 sizeof(addr_buf)); 293 printf("\tinet6 %s ", addr_buf); 294 295 if (ifa->ifa_flags & IFF_POINTOPOINT) { 296 sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr; 297 /* 298 * some of the interfaces do not have valid destination 299 * address. 300 */ 301 if (sin != NULL && sin->sin6_family == AF_INET6) { 302 int error; 303 304 /* XXX: embedded link local addr check */ 305 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) && 306 *(u_short *)&sin->sin6_addr.s6_addr[2] != 0) { 307 u_short index; 308 309 index = *(u_short *)&sin->sin6_addr.s6_addr[2]; 310 *(u_short *)&sin->sin6_addr.s6_addr[2] = 0; 311 if (sin->sin6_scope_id == 0) 312 sin->sin6_scope_id = ntohs(index); 313 } 314 315 error = getnameinfo((struct sockaddr *)sin, 316 sin->sin6_len, addr_buf, 317 sizeof(addr_buf), NULL, 0, 318 NI_NUMERICHOST); 319 if (error != 0) 320 inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, 321 sizeof(addr_buf)); 322 printf("--> %s ", addr_buf); 323 } 324 } 325 326 sin = (struct sockaddr_in6 *)ifa->ifa_netmask; 327 if (sin == NULL) 328 sin = &null_sin; 329 printf("prefixlen %d ", prefix(&sin->sin6_addr, 330 sizeof(struct in6_addr))); 331 332 if ((flags6 & IN6_IFF_ANYCAST) != 0) 333 printf("anycast "); 334 if ((flags6 & IN6_IFF_TENTATIVE) != 0) 335 printf("tentative "); 336 if ((flags6 & IN6_IFF_OPTIMISTIC) != 0) 337 printf("optimistic "); 338 if ((flags6 & IN6_IFF_DUPLICATED) != 0) 339 printf("duplicated "); 340 if ((flags6 & IN6_IFF_DETACHED) != 0) 341 printf("detached "); 342 if ((flags6 & IN6_IFF_DEPRECATED) != 0) 343 printf("deprecated "); 344 if ((flags6 & IN6_IFF_AUTOCONF) != 0) 345 printf("autoconf "); 346 if ((flags6 & IN6_IFF_TEMPORARY) != 0) 347 printf("temporary "); 348 if ((flags6 & IN6_IFF_SECURED) != 0) 349 printf("secured "); 350 351 if (scopeid) 352 printf("scopeid 0x%x ", scopeid); 353 354 if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { 355 printf("pltime "); 356 if (lifetime.ia6t_preferred) { 357 printf("%s ", lifetime.ia6t_preferred < t 358 ? "0" : sec2str(lifetime.ia6t_preferred - t)); 359 } else 360 printf("infty "); 361 362 printf("vltime "); 363 if (lifetime.ia6t_expire) { 364 printf("%s ", lifetime.ia6t_expire < t 365 ? "0" : sec2str(lifetime.ia6t_expire - t)); 366 } else 367 printf("infty "); 368 } 369 370 putchar('\n'); 371} 372 373#define SIN6(x) ((struct sockaddr_in6 *) &(x)) 374static struct sockaddr_in6 *sin6tab[] = { 375 SIN6(in6_ridreq.ifr_addr), SIN6(in6_addreq.ifra_addr), 376 SIN6(in6_addreq.ifra_prefixmask), SIN6(in6_addreq.ifra_dstaddr) 377}; 378 379static void 380in6_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 401static void 402in6_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 } 428 if (error != 0) { 429 if (inet_pton(AF_INET6, s, &sin->sin6_addr) != 1) 430 errx(1, "%s: bad value", s); 431 } else 432 bcopy(res->ai_addr, sin, res->ai_addrlen); 433} 434 435static int 436prefix(void *val, int size) 437{ 438 u_char *name = (u_char *)val; 439 int byte, bit, plen = 0; 440 441 for (byte = 0; byte < size; byte++, plen += 8) 442 if (name[byte] != 0xff) 443 break; 444 if (byte == size) 445 return (plen); 446 for (bit = 7; bit != 0; bit--, plen++) 447 if (!(name[byte] & (1 << bit))) 448 break; 449 for (; bit != 0; bit--) 450 if (name[byte] & (1 << bit)) 451 return(0); 452 byte++; 453 for (; byte < size; byte++) 454 if (name[byte]) 455 return(0); 456 return (plen); 457} 458 459static char * 460sec2str(time_t total) 461{ 462 static char result[256]; 463 int days, hours, mins, secs; 464 int first = 1; 465 char *p = result; 466 467 if (0) { 468 days = total / 3600 / 24; 469 hours = (total / 3600) % 24; 470 mins = (total / 60) % 60; 471 secs = total % 60; 472 473 if (days) { 474 first = 0; 475 p += snprintf(p, sizeof(result) - (p - result), "%dd", days); 476 } 477 if (!first || hours) { 478 first = 0; 479 p += snprintf(p, sizeof(result) - (p - result), "%dh", hours); 480 } 481 if (!first || mins) { 482 first = 0; 483 p += snprintf(p, sizeof(result) - (p - result), "%dm", mins); 484 } 485 snprintf(p, sizeof(result) - (p - result), "%ds", secs); 486 } else 487 snprintf(result, sizeof(result), "%lu", (unsigned long)total); 488 489 return(result); 490} 491 492static void 493in6_postproc(int s, const struct afswtch *afp) 494{ 495 if (explicit_prefix == 0) { 496 /* Aggregatable address architecture defines all prefixes 497 are 64. So, it is convenient to set prefixlen to 64 if 498 it is not specified. */ 499 setifprefixlen("64", 0, s, afp); 500 /* in6_getprefix("64", MASK) if MASK is available here... */ 501 } 502} 503 504static void 505in6_status_tunnel(int s) 506{ 507 char src[NI_MAXHOST]; 508 char dst[NI_MAXHOST]; 509 struct in6_ifreq in6_ifr; 510 const struct sockaddr *sa = (const struct sockaddr *) &in6_ifr.ifr_addr; 511 512 memset(&in6_ifr, 0, sizeof(in6_ifr)); 513 strncpy(in6_ifr.ifr_name, name, IFNAMSIZ); 514 515 if (ioctl(s, SIOCGIFPSRCADDR_IN6, (caddr_t)&in6_ifr) < 0) 516 return; 517 if (sa->sa_family != AF_INET6) 518 return; 519 in6_fillscopeid(&in6_ifr.ifr_addr); 520 if (getnameinfo(sa, sa->sa_len, src, sizeof(src), 0, 0, 521 NI_NUMERICHOST) != 0) 522 src[0] = '\0'; 523 524 if (ioctl(s, SIOCGIFPDSTADDR_IN6, (caddr_t)&in6_ifr) < 0) 525 return; 526 if (sa->sa_family != AF_INET6) 527 return; 528 in6_fillscopeid(&in6_ifr.ifr_addr); 529 if (getnameinfo(sa, sa->sa_len, dst, sizeof(dst), 0, 0, 530 NI_NUMERICHOST) != 0) 531 dst[0] = '\0'; 532 533 printf("\ttunnel inet6 %s --> %s\n", src, dst); 534} 535 536static void 537nd6_status(int s) 538{ 539 struct in6_ndireq nd; 540 int s6; 541 int error; 542 543 memset(&nd, 0, sizeof(nd)); 544 strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname)); 545 if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 546 if (errno != EPROTONOSUPPORT) 547 warn("socket(AF_INET6, SOCK_DGRAM)"); 548 return; 549 } 550 error = ioctl(s6, SIOCGIFINFO_IN6, &nd); 551 if (error) { 552 if (errno != EPFNOSUPPORT && errno != EINVAL) 553 warn("ioctl(SIOCGIFINFO_IN6)"); 554 close(s6); 555 return; 556 } 557 close(s6); 558 if (nd.ndi.flags == 0) 559 return; 560 printb("\tnd6 options", (unsigned int)nd.ndi.flags, ND6BITS); 561 putchar('\n'); 562} 563 564static void 565in6_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres) 566{ 567 struct in6_aliasreq in6_addreq; 568 569 memset(&in6_addreq, 0, sizeof(in6_addreq)); 570 strncpy(in6_addreq.ifra_name, name, IFNAMSIZ); 571 memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len); 572 memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr, 573 dstres->ai_addr->sa_len); 574 575 if (ioctl(s, SIOCSIFPHYADDR_IN6, &in6_addreq) < 0) 576 warn("SIOCSIFPHYADDR_IN6"); 577} 578 579static void 580in6_set_router(int s, int enable) 581{ 582 struct ifreq ifr; 583 584 bzero(&ifr, sizeof (ifr)); 585 strncpy(ifr.ifr_name, name, IFNAMSIZ); 586 ifr.ifr_intval = enable; 587 588 if (ioctl(s, SIOCSETROUTERMODE_IN6, &ifr) < 0) 589 warn("SIOCSETROUTERMODE_IN6"); 590} 591 592static struct cmd inet6_cmds[] = { 593 DEF_CMD_ARG("prefixlen", setifprefixlen), 594 DEF_CMD("anycast", IN6_IFF_ANYCAST, setip6flags), 595 DEF_CMD("tentative", IN6_IFF_TENTATIVE, setip6flags), 596 DEF_CMD("-tentative", -IN6_IFF_TENTATIVE, setip6flags), 597 /* RFC 4429, section 3.1, says: 598 * "Optimistic DAD SHOULD NOT be used for manually entered 599 * addresses." 600 * 601 * DEF_CMD("optimistic", IN6_IFF_OPTIMISTIC, setip6flags), 602 * DEF_CMD("-optimistic", -IN6_IFF_OPTIMISTIC, setip6flags), 603 */ 604 DEF_CMD("deprecated", IN6_IFF_DEPRECATED, setip6flags), 605 DEF_CMD("-deprecated", -IN6_IFF_DEPRECATED, setip6flags), 606 DEF_CMD("autoconf", IN6_IFF_AUTOCONF, setip6flags), 607 DEF_CMD("-autoconf", -IN6_IFF_AUTOCONF, setip6flags), 608 DEF_CMD("nud", ND6_IFF_PERFORMNUD, setnd6flags), 609 DEF_CMD("-nud", -ND6_IFF_PERFORMNUD, setnd6flags), 610 DEF_CMD("ifdisabled", ND6_IFF_IFDISABLED, setnd6flags), 611 DEF_CMD("-ifdisabled", -ND6_IFF_IFDISABLED, setnd6flags), 612 DEF_CMD("ignore_na", ND6_IFF_IGNORE_NA, setnd6flags), 613 DEF_CMD("-ignore_na", -ND6_IFF_IGNORE_NA, setnd6flags), 614 DEF_CMD("proxy_prefixes", ND6_IFF_PROXY_PREFIXES, setnd6flags), 615 DEF_CMD("-proxy_prefixes", -ND6_IFF_PROXY_PREFIXES, setnd6flags), 616 DEF_CMD("insecure", ND6_IFF_INSECURE, setnd6flags), 617 DEF_CMD("-insecure", -ND6_IFF_INSECURE, setnd6flags), 618 DEF_CMD_ARG("pltime", setip6pltime), 619 DEF_CMD_ARG("vltime", setip6vltime), 620 DEF_CMD("eui64", 0, setip6eui64), 621 DEF_CMD("secured", IN6_IFF_SECURED, setip6flags), 622 DEF_CMD("-secured", -IN6_IFF_SECURED, setip6flags), 623}; 624 625static struct afswtch af_inet6 = { 626 .af_name = "inet6", 627 .af_af = AF_INET6, 628 .af_status = in6_status, 629 .af_getaddr = in6_getaddr, 630 .af_getprefix = in6_getprefix, 631 .af_other_status = nd6_status, 632 .af_postproc = in6_postproc, 633 .af_status_tunnel = in6_status_tunnel, 634 .af_settunnel = in6_set_tunnel, 635 .af_setrouter = in6_set_router, 636 .af_difaddr = SIOCDIFADDR_IN6, 637 .af_aifaddr = SIOCAIFADDR_IN6, 638 .af_ridreq = &in6_ridreq, 639 .af_addreq = &in6_addreq, 640}; 641 642static void 643in6_Lopt_cb(const char *optarg __unused) 644{ 645 ip6lifetime++; /* print IPv6 address lifetime */ 646} 647static struct option in6_Lopt = { "L", "[-L]", in6_Lopt_cb }; 648 649static __constructor void 650inet6_ctor(void) 651{ 652#define N(a) (sizeof(a) / sizeof(a[0])) 653 int i; 654 655 for (i = 0; i < N(inet6_cmds); i++) 656 cmd_register(&inet6_cmds[i]); 657 af_register(&af_inet6); 658 opt_register(&in6_Lopt); 659#undef N 660} 661