/*
- * Copyright (c) 2009-2012 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>
#include <net/if_mib.h>
#include <net/route.h>
#include <net/pktsched/pktsched.h>
+#include <net/network_agent.h>
/* IP */
#include <netinet/in.h>
const struct afswtch *afp);
static void status(const struct afswtch *afp, const struct sockaddr_dl *sdl,
struct ifaddrs *ifa);
+static char *bytes_to_str(unsigned long long bytes);
static char *bps_to_str(unsigned long long rate);
+static char *ns_to_str(unsigned long long nsec);
static void tunnel_status(int s);
static void usage(void);
static char *sched2str(unsigned int s);
static char *tl2str(unsigned int s);
+static char *ift2str(unsigned int t, unsigned int f, unsigned int sf);
static struct afswtch *af_getbyname(const char *name);
static struct afswtch *af_getbyfamily(int af);
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.. */
usage();
ifname = NULL;
- ifindex = 0;
if (argc == 1) {
afp = af_getbyname(*argv);
if (afp == NULL)
}
}
+static void
+setlog(const char *val, int dummy __unused, int s,
+ const struct afswtch *afp)
+{
+ char *cp;
+
+ errno = 0;
+ strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+
+ ifr.ifr_log.ifl_level = strtold(val, &cp);
+ if (val == cp || errno != 0) {
+ warn("Invalid value '%s'", val);
+ return;
+ }
+ ifr.ifr_log.ifl_flags = (IFRLOGF_DLIL|IFRLOGF_FAMILY|IFRLOGF_DRIVER|
+ IFRLOGF_FIRMWARE);
+
+ if (ioctl(s, SIOCSIFLOG, &ifr) < 0)
+ 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" \
"\20MULTICAST"
#define IFEFBITS \
-"\020\1AUTOCONFIGURING\7ACCEPT_RTADV\10TXSTART\11RXPOLL\12VLAN\13BOND\14ARPLL" \
-"\15NOWINDOWSCALE\16NOAUTOIPV6LL\20ROUTER4\21ROUTER6" \
-"\22LOCALNET_PRIVATE\23ND6ALT\24RESTRICTED_RECV\25AWDL\26NOACKPRI\35SENDLIST"
+"\020\1AUTOCONFIGURING\6IPV6_DISABLED\7ACCEPT_RTADV\10TXSTART\11RXPOLL" \
+"\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" \
-"\6TSO4\7TSO6\10LRO\11AV"
+"\6TSO4\7TSO6\10LRO\11AV\12TXSTATUS"
+
+#define IFRLOGF_BITS \
+"\020\1DLIL\21FAMILY\31DRIVER\35FIRMWARE"
/*
* Print the status of the interface. If an address family was
if (!verbose)
goto done;
+ if (ioctl(s, SIOCGIFTYPE, &ifr) != -1) {
+ char *c = ift2str(ifr.ifr_type.ift_type,
+ ifr.ifr_type.ift_family, ifr.ifr_type.ift_subfamily);
+ if (c != NULL)
+ 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)
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("(?)");
}
}
+ 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) {
u_int64_t obw_eff = iflpr.iflpr_output_bw.eff_bw;
u_int64_t obw_tbr = iflpr.iflpr_output_tbr_rate;
u_int32_t obw_pct = iflpr.iflpr_output_tbr_percent;
+ u_int64_t ilt_max = iflpr.iflpr_input_lt.max_lt;
+ u_int64_t ilt_eff = iflpr.iflpr_input_lt.eff_lt;
+ u_int64_t olt_max = iflpr.iflpr_output_lt.max_lt;
+ u_int64_t olt_eff = iflpr.iflpr_output_lt.eff_lt;
+
if (eflags & IFEF_TXSTART) {
u_int32_t flags = iflpr.iflpr_flags;
printf("\tuplink rate: %s [tbr]\n",
bps_to_str(obw_tbr));
}
+
+ if (ilt_max != 0 || olt_max != 0) {
+ if (ilt_max == olt_max && ilt_eff == olt_eff &&
+ ilt_max == ilt_eff) {
+ printf("\tlink latency: %s\n",
+ ns_to_str(ilt_max));
+ } else {
+ if (olt_max != 0 && olt_eff == olt_max) {
+ printf("\tuplink latency: %s\n",
+ ns_to_str(olt_max));
+ } else if (olt_max != 0) {
+ printf("\tuplink latency: "
+ "%s [eff] / ", ns_to_str(olt_eff));
+ printf("%s [max]\n",
+ ns_to_str(olt_max));
+ }
+ if (ilt_max != 0 && ilt_eff == ilt_max) {
+ printf("\tdownlink latency: %s\n",
+ ns_to_str(ilt_max));
+ } else if (ilt_max != 0) {
+ printf("\tdownlink latency: "
+ "%s [eff] / ", ns_to_str(ilt_eff));
+ printf("%s [max]\n",
+ ns_to_str(ilt_max));
+ }
+ }
+ }
}
/* Common OID prefix */
err(1, "sysctl IFDATA_SUPPLEMENTAL");
if (ifmsupp.ifmd_data_extended.ifi_alignerrs != 0) {
- printf("\tunaligned pkts: %lld\n",
+ printf("\tunaligned pkts: %llu\n",
ifmsupp.ifmd_data_extended.ifi_alignerrs);
}
+ if (ifmsupp.ifmd_data_extended.ifi_dt_bytes != 0) {
+ printf("\tdata milestone interval: %s\n",
+ bytes_to_str(ifmsupp.ifmd_data_extended.ifi_dt_bytes));
+ }
bzero(&ifdr, sizeof (ifdr));
strncpy(ifdr.ifdr_name, name, sizeof (ifdr.ifdr_name));
printf("\tdesc: %s\n", ifdr.ifdr_desc);
}
+ if (ioctl(s, SIOCGIFLOG, &ifr) != -1 && ifr.ifr_log.ifl_level) {
+ printf("\tlogging: level %d ", ifr.ifr_log.ifl_level);
+ printb("facilities", ifr.ifr_log.ifl_flags, IFRLOGF_BITS);
+ putchar('\n');
+ }
+
+ if (ioctl(s, SIOCGIFDELEGATE, &ifr) != -1 && ifr.ifr_delegated) {
+ char delegatedif[IFNAMSIZ+1];
+ if (if_indextoname(ifr.ifr_delegated, delegatedif) != NULL)
+ 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;
}
+#define KILOBYTES 1024
+#define MEGABYTES (KILOBYTES * KILOBYTES)
+#define GIGABYTES (KILOBYTES * KILOBYTES * KILOBYTES)
+
+static char *
+bytes_to_str(unsigned long long bytes)
+{
+ static char buf[32];
+ const char *u;
+ long double n = bytes, t;
+
+ if (bytes >= GIGABYTES) {
+ t = n / GIGABYTES;
+ u = "GB";
+ } else if (n >= MEGABYTES) {
+ t = n / MEGABYTES;
+ u = "MB";
+ } else if (n >= KILOBYTES) {
+ t = n / KILOBYTES;
+ u = "KB";
+ } else {
+ t = n;
+ u = "bytes";
+ }
+
+ snprintf(buf, sizeof (buf), "%-4.2Lf %s", t, u);
+ return (buf);
+}
+
#define GIGABIT_PER_SEC 1000000000 /* gigabit per second */
#define MEGABIT_PER_SEC 1000000 /* megabit per second */
#define KILOBIT_PER_SEC 1000 /* kilobit per second */
return (buf);
}
+#define NSEC_PER_SEC 1000000000 /* nanosecond per second */
+#define USEC_PER_SEC 1000000 /* microsecond per second */
+#define MSEC_PER_SEC 1000 /* millisecond per second */
+
+static char *
+ns_to_str(unsigned long long nsec)
+{
+ static char buf[32];
+ const char *u;
+ long double n = nsec, t;
+
+ if (nsec >= NSEC_PER_SEC) {
+ t = n / NSEC_PER_SEC;
+ u = "sec ";
+ } else if (n >= USEC_PER_SEC) {
+ t = n / USEC_PER_SEC;
+ u = "msec";
+ } else if (n >= MSEC_PER_SEC) {
+ t = n / MSEC_PER_SEC;
+ u = "usec";
+ } else {
+ t = n;
+ u = "nsec";
+ }
+
+ snprintf(buf, sizeof (buf), "%-4.2Lf %4s", t, u);
+ return (buf);
+}
+
static void
tunnel_status(int s)
{
DEF_CMD_ARG("desc", setifdesc),
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
return (c);
}
+
+static char *
+ift2str(unsigned int t, unsigned int f, unsigned int sf)
+{
+ static char buf[256];
+ char *c = NULL;
+
+ switch (t) {
+ case IFT_ETHER:
+ switch (sf) {
+ case IFRTYPE_SUBFAMILY_USB:
+ c = "USB Ethernet";
+ break;
+ case IFRTYPE_SUBFAMILY_BLUETOOTH:
+ c = "Bluetooth PAN";
+ break;
+ case IFRTYPE_SUBFAMILY_WIFI:
+ c = "Wi-Fi";
+ break;
+ case IFRTYPE_SUBFAMILY_THUNDERBOLT:
+ c = "IP over Thunderbolt";
+ break;
+ case IFRTYPE_SUBFAMILY_ANY:
+ default:
+ c = "Ethernet";
+ break;
+ }
+ break;
+
+ case IFT_IEEE1394:
+ c = "IP over FireWire";
+ break;
+
+ case IFT_PKTAP:
+ c = "Packet capture";
+ break;
+
+ case IFT_CELLULAR:
+ c = "Cellular";
+ break;
+
+ case IFT_BRIDGE:
+ case IFT_PFLOG:
+ case IFT_PFSYNC:
+ case IFT_OTHER:
+ case IFT_PPP:
+ case IFT_LOOP:
+ case IFT_GIF:
+ case IFT_STF:
+ case IFT_L2VLAN:
+ case IFT_IEEE8023ADLAG:
+ default:
+ break;
+ }
+
+ if (verbose > 1) {
+ if (c == NULL) {
+ (void) snprintf(buf, sizeof (buf),
+ "0x%x family: %u subfamily: %u",
+ ifr.ifr_type.ift_type, ifr.ifr_type.ift_family,
+ ifr.ifr_type.ift_subfamily);
+ } else {
+ (void) snprintf(buf, sizeof (buf),
+ "%s (0x%x) family: %u subfamily: %u", c,
+ ifr.ifr_type.ift_type, ifr.ifr_type.ift_family,
+ ifr.ifr_type.ift_subfamily);
+ }
+ c = buf;
+ }
+
+ return (c);
+}