X-Git-Url: https://git.saurik.com/apple/network_cmds.git/blobdiff_plain/fdfd5971fdda9c24d576337643161018a5281167..342c141ecf761e55ea0f23a89d835a8544df5f2e:/ifconfig.tproj/af_inet6.c diff --git a/ifconfig.tproj/af_inet6.c b/ifconfig.tproj/af_inet6.c index cd5e34a..6462597 100644 --- a/ifconfig.tproj/af_inet6.c +++ b/ifconfig.tproj/af_inet6.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Apple Inc. All rights reserved. + * Copyright (c) 2009-2013 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -55,10 +55,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD: src/sbin/ifconfig/af_inet6.c,v 1.6.6.1 2008/11/25 02:59:29 kensmith Exp $"; -#endif /* not lint */ #include #include @@ -66,6 +62,7 @@ static const char rcsid[] = #include #include +#include #include #include #include @@ -84,6 +81,10 @@ static const char rcsid[] = #include "ifconfig.h" +#define ND6BITS "\020\001PERFORMNUD\002ACCEPT_RTADV\003PREFER_SOURCE" \ + "\004IFDISABLED\005DONT_SET_IFROUTE\006PROXY_PREFIXES" \ + "\007IGNORE_NA\010INSECURE" + static struct in6_ifreq in6_ridreq; static struct in6_aliasreq in6_addreq = { { 0 }, @@ -110,6 +111,29 @@ setifprefixlen(const char *addr, int dummy __unused, int s, explicit_prefix = 1; } +static void +setnd6flags(const char *dummyaddr __unused, int d, int s, + const struct afswtch *afp) +{ + struct in6_ndireq nd; + int error; + + memset(&nd, 0, sizeof(nd)); + strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname)); + error = ioctl(s, SIOCGIFINFO_IN6, &nd); + if (error) { + warn("ioctl(SIOCGIFINFO_IN6)"); + return; + } + if (d < 0) + nd.ndi.flags &= ~(-d); + else + nd.ndi.flags |= d; + error = ioctl(s, SIOCSIFINFO_FLAGS, (caddr_t)&nd); + if (error) + warn("ioctl(SIOCSIFINFO_FLAGS)"); +} + static void setip6flags(const char *dummyaddr __unused, int flag, int dummysoc __unused, const struct afswtch *afp) @@ -305,6 +329,8 @@ in6_status(int s __unused, const struct ifaddrs *ifa) printf("anycast "); if ((flags6 & IN6_IFF_TENTATIVE) != 0) printf("tentative "); + if ((flags6 & IN6_IFF_OPTIMISTIC) != 0) + printf("optimistic "); if ((flags6 & IN6_IFF_DUPLICATED) != 0) printf("duplicated "); if ((flags6 & IN6_IFF_DETACHED) != 0) @@ -315,6 +341,10 @@ in6_status(int s __unused, const struct ifaddrs *ifa) printf("autoconf "); if ((flags6 & IN6_IFF_TEMPORARY) != 0) printf("temporary "); + if ((flags6 & IN6_IFF_DYNAMIC) != 0) + printf("dynamic "); + if ((flags6 & IN6_IFF_SECURED) != 0) + printf("secured "); if (scopeid) printf("scopeid 0x%x ", scopeid); @@ -501,6 +531,34 @@ in6_status_tunnel(int s) printf("\ttunnel inet6 %s --> %s\n", src, dst); } +static void +nd6_status(int s) +{ + struct in6_ndireq nd; + int s6; + int error; + + memset(&nd, 0, sizeof(nd)); + strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname)); + if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { + if (errno != EPROTONOSUPPORT) + warn("socket(AF_INET6, SOCK_DGRAM)"); + return; + } + error = ioctl(s6, SIOCGIFINFO_IN6, &nd); + if (error) { + if (errno != EPFNOSUPPORT && errno != EINVAL) + warn("ioctl(SIOCGIFINFO_IN6)"); + close(s6); + return; + } + close(s6); + if (nd.ndi.flags == 0) + return; + printb("\tnd6 options", (unsigned int)nd.ndi.flags, ND6BITS); + putchar('\n'); +} + static void in6_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres) { @@ -516,18 +574,50 @@ in6_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres) warn("SIOCSIFPHYADDR_IN6"); } +static void +in6_set_router(int s, int enable) +{ + struct ifreq ifr; + + bzero(&ifr, sizeof (ifr)); + strncpy(ifr.ifr_name, name, IFNAMSIZ); + ifr.ifr_intval = enable; + + if (ioctl(s, SIOCSETROUTERMODE_IN6, &ifr) < 0) + warn("SIOCSETROUTERMODE_IN6"); +} + static struct cmd inet6_cmds[] = { DEF_CMD_ARG("prefixlen", setifprefixlen), DEF_CMD("anycast", IN6_IFF_ANYCAST, setip6flags), DEF_CMD("tentative", IN6_IFF_TENTATIVE, setip6flags), DEF_CMD("-tentative", -IN6_IFF_TENTATIVE, setip6flags), + /* RFC 4429, section 3.1, says: + * "Optimistic DAD SHOULD NOT be used for manually entered + * addresses." + * + * DEF_CMD("optimistic", IN6_IFF_OPTIMISTIC, setip6flags), + * DEF_CMD("-optimistic", -IN6_IFF_OPTIMISTIC, setip6flags), + */ DEF_CMD("deprecated", IN6_IFF_DEPRECATED, setip6flags), DEF_CMD("-deprecated", -IN6_IFF_DEPRECATED, setip6flags), DEF_CMD("autoconf", IN6_IFF_AUTOCONF, setip6flags), DEF_CMD("-autoconf", -IN6_IFF_AUTOCONF, setip6flags), + DEF_CMD("nud", ND6_IFF_PERFORMNUD, setnd6flags), + DEF_CMD("-nud", -ND6_IFF_PERFORMNUD, setnd6flags), + DEF_CMD("ifdisabled", ND6_IFF_IFDISABLED, setnd6flags), + DEF_CMD("-ifdisabled", -ND6_IFF_IFDISABLED, setnd6flags), + DEF_CMD("ignore_na", ND6_IFF_IGNORE_NA, setnd6flags), + DEF_CMD("-ignore_na", -ND6_IFF_IGNORE_NA, setnd6flags), + DEF_CMD("proxy_prefixes", ND6_IFF_PROXY_PREFIXES, setnd6flags), + DEF_CMD("-proxy_prefixes", -ND6_IFF_PROXY_PREFIXES, setnd6flags), + DEF_CMD("insecure", ND6_IFF_INSECURE, setnd6flags), + DEF_CMD("-insecure", -ND6_IFF_INSECURE, setnd6flags), DEF_CMD_ARG("pltime", setip6pltime), DEF_CMD_ARG("vltime", setip6vltime), DEF_CMD("eui64", 0, setip6eui64), + DEF_CMD("secured", IN6_IFF_SECURED, setip6flags), + DEF_CMD("-secured", -IN6_IFF_SECURED, setip6flags), }; static struct afswtch af_inet6 = { @@ -536,12 +626,14 @@ static struct afswtch af_inet6 = { .af_status = in6_status, .af_getaddr = in6_getaddr, .af_getprefix = in6_getprefix, + .af_other_status = nd6_status, .af_postproc = in6_postproc, .af_status_tunnel = in6_status_tunnel, .af_settunnel = in6_set_tunnel, + .af_setrouter = in6_set_router, .af_difaddr = SIOCDIFADDR_IN6, .af_aifaddr = SIOCAIFADDR_IN6, - .af_ridreq = &in6_addreq, + .af_ridreq = &in6_ridreq, .af_addreq = &in6_addreq, };