]> git.saurik.com Git - apple/network_cmds.git/blobdiff - ifconfig.tproj/ifconfig.c
network_cmds-481.20.1.tar.gz
[apple/network_cmds.git] / ifconfig.tproj / ifconfig.c
index ecc5fd4dbd8f1acbd5586a7234d2f1ff0e98dc12..1a708da087ed54f47bd612e910b3d98d417a8b3a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2013 Apple Inc. All rights reserved.
+ * Copyright (c) 2009-2014 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  *
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
+
 #ifndef lint
-static const char copyright[] =
+__unused static const char copyright[] =
 "@(#) Copyright (c) 1983, 1993\n\
        The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
-#endif
-static const char rcsid[] =
-  "$FreeBSD: src/sbin/ifconfig/ifconfig.c,v 1.134.2.2.2.1 2008/11/25 02:59:29 kensmith Exp $";
-#endif /* not lint */
-
 #include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
@@ -87,6 +81,7 @@ static const char rcsid[] =
 #include <net/if_mib.h>
 #include <net/route.h>
 #include <net/pktsched/pktsched.h>
+#include <net/network_agent.h>
 
 /* IP */
 #include <netinet/in.h>
@@ -257,13 +252,9 @@ main(int argc, char *argv[])
        argc -= optind;
        argv += optind;
 
-       /* -l cannot be used with -a or -q or -r or -m or -b */
+       /* -l cannot be used with -a or -q or -m or -b */
        if (namesonly &&
-#ifdef TARGET_OS_EMBEDDED
-        (all || supmedia || bond_details))
-#else /* TARGET_OS_EMBEDDED */
-           (all || supmedia || showrtref || bond_details))
-#endif /* !TARGET_OS_EMBEDDED */
+           (all || supmedia || bond_details))
                usage();
 
        /* nonsense.. */
@@ -280,7 +271,6 @@ main(int argc, char *argv[])
                        usage();
 
                ifname = NULL;
-               ifindex = 0;
                if (argc == 1) {
                        afp = af_getbyname(*argv);
                        if (afp == NULL)
@@ -971,6 +961,54 @@ setlog(const char *val, int dummy __unused, int s,
                warn("ioctl (set logging parameters)");
 }
 
+void
+setcl2k(const char *vname, int value, int s, const struct afswtch *afp)
+{
+       strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+       ifr.ifr_ifru.ifru_2kcl = value;
+       
+       if (ioctl(s, SIOCSIF2KCL, (caddr_t)&ifr) < 0)
+               Perror(vname);
+}
+
+void
+setexpensive(const char *vname, int value, int s, const struct afswtch *afp)
+{
+       strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+       ifr.ifr_ifru.ifru_expensive = value;
+       
+       if (ioctl(s, SIOCSIFEXPENSIVE, (caddr_t)&ifr) < 0)
+               Perror(vname);
+}
+
+
+void
+setecnmode(const char *val, int dummy __unused, int s,
+    const struct afswtch *afp)
+{
+       char *cp;
+
+       if (strcmp(val, "default") == 0)
+               ifr.ifr_ifru.ifru_ecn_mode = IFRTYPE_ECN_DEFAULT;
+       else if (strcmp(val, "enable") == 0)
+               ifr.ifr_ifru.ifru_ecn_mode = IFRTYPE_ECN_ENABLE;
+       else if (strcmp(val, "disable") == 0)
+               ifr.ifr_ifru.ifru_ecn_mode = IFRTYPE_ECN_DISABLE;
+       else {
+               ifr.ifr_ifru.ifru_ecn_mode = strtold(val, &cp);
+               if (val == cp || errno != 0) {
+                       warn("Invalid ECN mode value '%s'", val);
+                       return;
+               }
+       }
+       
+       strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+       
+       if (ioctl(s, SIOCSECNMODE, (caddr_t)&ifr) < 0)
+               Perror("ioctl(SIOCSECNMODE)");
+}
+
+
 #define        IFFBITS \
 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \
 "\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \
@@ -978,9 +1016,9 @@ setlog(const char *val, int dummy __unused, int s,
 
 #define        IFEFBITS \
 "\020\1AUTOCONFIGURING\6IPV6_DISABLED\7ACCEPT_RTADV\10TXSTART\11RXPOLL" \
-"\12VLAN\13BOND\14ARPLL\15NOWINDOWSCALE\16NOAUTOIPV6LL\20ROUTER4\21ROUTER6" \
-"\22LOCALNET_PRIVATE\23ND6ALT\24RESTRICTED_RECV\25AWDL\26NOACKPRI\35SENDLIST" \
-"\36DIRECTLINK"
+"\12VLAN\13BOND\14ARPLL\15NOWINDOWSCALE\16NOAUTOIPV6LL\17EXPENSIVE\20ROUTER4" \
+"\21ROUTER6\22LOCALNET_PRIVATE\23ND6ALT\24RESTRICTED_RECV\25AWDL\26NOACKPRI" \
+"\27AWDL_RESTRICTED\30CL2K\31ECN_ENABLE\32ECN_DISABLE\35SENDLIST\36DIRECTLINK\40UPDOWNCHANGE"
 
 #define        IFCAPBITS \
 "\020\1RXCSUM\2TXCSUM\3VLAN_MTU\4VLAN_HWTAGGING\5JUMBO_MTU" \
@@ -1107,16 +1145,49 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
                        printf("\ttype: %s\n", c);
        }
 
+       if (verbose > 0) {
+               struct if_agentidsreq ifar;
+               memset(&ifar, 0, sizeof(ifar));
+
+               strlcpy(ifar.ifar_name, name, sizeof(ifar.ifar_name));
+
+               if (ioctl(s, SIOCGIFAGENTIDS, &ifar) != -1) {
+                       if (ifar.ifar_count != 0) {
+                               ifar.ifar_uuids = calloc(ifar.ifar_count, sizeof(uuid_t));
+                               if (ifar.ifar_uuids != NULL) {
+                                       if (ioctl(s, SIOCGIFAGENTIDS, &ifar) != 1) {
+                                               for (int agent_i = 0; agent_i < ifar.ifar_count; agent_i++) {
+                                                       struct netagent_req nar;
+                                                       memset(&nar, 0, sizeof(nar));
+
+                                                       uuid_copy(nar.netagent_uuid, ifar.ifar_uuids[agent_i]);
+
+                                                       if (ioctl(s, SIOCGIFAGENTDATA, &nar) != 1) {
+                                                               printf("\tagent domain:%s type:%s flags:0x%x desc:\"%s\"\n",
+                                                                          nar.netagent_domain, nar.netagent_type,
+                                                                          nar.netagent_flags, nar.netagent_desc);
+                                                       }
+                                               }
+                                       }
+                                       free(ifar.ifar_uuids);
+                               }
+                       }
+               }
+       }
+
        if (ioctl(s, SIOCGIFLINKQUALITYMETRIC, &ifr) != -1) {
                int lqm = ifr.ifr_link_quality_metric;
                if (verbose > 1) {
                        printf("\tlink quality: %d ", lqm);
-                       if (lqm == IFNET_LQM_THRESH_OFF) {
+                       if (lqm == IFNET_LQM_THRESH_OFF)
                                printf("(off)");
-                       } else if (lqm == IFNET_LQM_THRESH_UNKNOWN) {
+                       else if (lqm == IFNET_LQM_THRESH_UNKNOWN)
                                printf("(unknown)");
-                       } else if (lqm > IFNET_LQM_THRESH_UNKNOWN &&
-                           lqm <= IFNET_LQM_THRESH_POOR)
+                       else if (lqm > IFNET_LQM_THRESH_UNKNOWN &&
+                                lqm <= IFNET_LQM_THRESH_BAD)
+                               printf("(bad)");
+                       else if (lqm > IFNET_LQM_THRESH_UNKNOWN &&
+                                lqm <= IFNET_LQM_THRESH_POOR)
                                printf("(poor)");
                        else if (lqm > IFNET_LQM_THRESH_POOR &&
                            lqm <= IFNET_LQM_THRESH_GOOD)
@@ -1126,10 +1197,11 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
                        printf("\n");
                } else if (lqm > IFNET_LQM_THRESH_UNKNOWN) {
                        printf("\tlink quality: %d ", lqm);
-                       if (lqm <= IFNET_LQM_THRESH_POOR)
+                       if (lqm <= IFNET_LQM_THRESH_BAD)
+                               printf("(bad)");
+                       else if (lqm <= IFNET_LQM_THRESH_POOR)
                                printf("(poor)");
-                       else if (lqm > IFNET_LQM_THRESH_POOR &&
-                           lqm <= IFNET_LQM_THRESH_GOOD)
+                       else if (lqm <= IFNET_LQM_THRESH_GOOD)
                                printf("(good)");
                        else
                                printf("(?)");
@@ -1137,6 +1209,59 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
                }
        }
 
+       if (verbose > 0) {
+               if (ioctl(s, SIOCGIFINTERFACESTATE, &ifr) != -1) {
+                       printf("\tstate");
+                       if (ifr.ifr_interface_state.valid_bitmask &
+                           IF_INTERFACE_STATE_RRC_STATE_VALID) {
+                               uint8_t rrc_state = ifr.ifr_interface_state.rrc_state;
+                               
+                               printf(" rrc: %u ", rrc_state);
+                               if (rrc_state == IF_INTERFACE_STATE_RRC_STATE_CONNECTED)
+                                       printf("(connected)");
+                               else if (rrc_state == IF_INTERFACE_STATE_RRC_STATE_IDLE)
+                                       printf("(idle)");
+                               else
+                                       printf("(?)");
+                       }
+                       if (ifr.ifr_interface_state.valid_bitmask &
+                           IF_INTERFACE_STATE_INTERFACE_AVAILABILITY_VALID) {
+                               uint8_t ifavail = ifr.ifr_interface_state.interface_availability;
+                               
+                               printf(" availability: %u ", ifavail);
+                               if (ifavail == IF_INTERFACE_STATE_INTERFACE_AVAILABLE)
+                                       printf("(true)");
+                               else if (ifavail == IF_INTERFACE_STATE_INTERFACE_UNAVAILABLE)
+                                       printf("(false)");
+                               else
+                                       printf("(?)");
+                       } else {
+                               printf(" availability: (not valid)");
+                       }
+                       if (verbose > 1 &&
+                           ifr.ifr_interface_state.valid_bitmask &
+                           IF_INTERFACE_STATE_LQM_STATE_VALID) {
+                               int8_t lqm = ifr.ifr_interface_state.lqm_state;
+                               
+                               printf(" lqm: %d", lqm);
+                               
+                               if (lqm == IFNET_LQM_THRESH_OFF)
+                                       printf("(off)");
+                               else if (lqm == IFNET_LQM_THRESH_UNKNOWN)
+                                       printf("(unknown)");
+                               else if (lqm == IFNET_LQM_THRESH_BAD)
+                                       printf("(bad)");
+                               else if (lqm == IFNET_LQM_THRESH_POOR)
+                                       printf("(poor)");
+                               else if (lqm == IFNET_LQM_THRESH_GOOD)
+                                       printf("(good)");
+                               else
+                                       printf("(?)");
+                       }
+               }
+               printf("\n");
+       }
+       
        bzero(&iflpr, sizeof (iflpr));
        strncpy(iflpr.iflpr_name, name, sizeof (iflpr.iflpr_name));
        if (ioctl(s, SIOCGIFLINKPARAMS, &iflpr) != -1) {
@@ -1277,6 +1402,16 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
                        printf("\teffective interface: %s\n", delegatedif);
        }
 
+       if(ioctl(s, SIOCGSTARTDELAY, &ifr) != -1) {
+               if (ifr.ifr_start_delay_qlen > 0 &&
+                   ifr.ifr_start_delay_timeout > 0) {
+                       printf("\ttxstart qlen: %u packets "
+                           "timeout: %u microseconds\n",
+                           ifr.ifr_start_delay_qlen,
+                           ifr.ifr_start_delay_timeout/1000);
+               }
+       }
+
 done:
        close(s);
        return;
@@ -1576,6 +1711,11 @@ static struct cmd basic_cmds[] = {
        DEF_CMD_ARG("tbr",                      settbr),
        DEF_CMD_ARG("throttle",                 setthrottle),
        DEF_CMD_ARG("log",                      setlog),
+       DEF_CMD("cl2k", 1,                      setcl2k),
+       DEF_CMD("-cl2k",        0,              setcl2k),
+       DEF_CMD("expensive",    1,              setexpensive),
+       DEF_CMD("-expensive",   0,              setexpensive),
+       DEF_CMD_ARG("ecn",                      setecnmode),
 };
 
 static __constructor void