From e0b07f2d5ba2222268f5d1293221b413eb7c2655 Mon Sep 17 00:00:00 2001 From: Apple Date: Tue, 14 May 2019 06:10:09 +0000 Subject: [PATCH] network_cmds-596.tar.gz --- arp.tproj/arp.c | 2 +- dnctl/dnctl.c | 4 +- ecnprobe/capture.c | 4 +- ecnprobe/ecn_probe.c | 42 +- ifconfig.tproj/af_inet.c | 6 +- ifconfig.tproj/af_inet6.c | 12 +- ifconfig.tproj/if6lowpan.c | 178 ++++++++ ifconfig.tproj/ifclone.c | 2 +- ifconfig.tproj/ifconfig.c | 595 +++++++++++++++++++++++-- ifconfig.tproj/ifconfig.h | 6 +- ifconfig.tproj/ifmedia.c | 13 +- ifconfig.tproj/nexus.c | 8 +- mnc.tproj/README | 2 +- mptcp_client/mptcp_client.c | 4 +- mtest.tproj/mtest.c | 2 +- ndp.tproj/ndp.c | 27 +- netstat.tproj/if.c | 73 ++- netstat.tproj/inet.c | 26 +- netstat.tproj/main.c | 2 +- netstat.tproj/mcast.c | 4 +- netstat.tproj/netstat.h | 2 - netstat.tproj/route.c | 74 +-- netstat.tproj/systm.c | 2 +- netstat.tproj/unix.c | 26 +- network_cmds.xcodeproj/project.pbxproj | 20 +- ping.tproj/ping.c | 8 +- ping6.tproj/ping6.c | 6 +- pktmnglr/packet_mangler.c | 2 +- rarpd.tproj/rarpd.c | 4 +- route.tproj/route.c | 9 +- rtadvd.tproj/advcap.c | 4 +- rtadvd.tproj/config.c | 4 +- rtadvd.tproj/if.c | 2 +- rtsol.tproj/if.c | 6 +- rtsol.tproj/rtsold.c | 5 +- traceroute.tproj/ifaddrlist.c | 5 +- traceroute.tproj/traceroute.c | 6 +- unbound/util/tube.c | 1 + unbound/winrc/gen_msg.bin | Bin 116 -> 0 bytes 39 files changed, 951 insertions(+), 247 deletions(-) create mode 100644 ifconfig.tproj/if6lowpan.c delete mode 100644 unbound/winrc/gen_msg.bin diff --git a/arp.tproj/arp.c b/arp.tproj/arp.c index 85796eb..eeca003 100644 --- a/arp.tproj/arp.c +++ b/arp.tproj/arp.c @@ -913,7 +913,7 @@ get_ether_addr(in_addr_t ipaddr, struct ether_addr *hwaddr) for (ifr = ifc.ifc_req; ifr < ifend; ifr = NEXTIFR(ifr) ) { if (ifr->ifr_addr.sa_family != AF_INET) continue; - strncpy(ifreq.ifr_name, ifr->ifr_name, + strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name)); ifreq.ifr_addr = ifr->ifr_addr; /* diff --git a/dnctl/dnctl.c b/dnctl/dnctl.c index 119a839..38cffe8 100644 --- a/dnctl/dnctl.c +++ b/dnctl/dnctl.c @@ -800,10 +800,8 @@ end_mask: * set clocking interface or bandwidth value */ if (av[0][0] >= 'a' && av[0][0] <= 'z') { - int l = sizeof(p.if_name)-1; /* interface name */ - strncpy(p.if_name, av[0], l); - p.if_name[l] = '\0'; + strlcpy(p.if_name, av[0], sizeof(p.if_name)); p.bandwidth = 0; } else { p.if_name[0] = '\0'; diff --git a/ecnprobe/capture.c b/ecnprobe/capture.c index ff6b6d5..83cbf78 100644 --- a/ecnprobe/capture.c +++ b/ecnprobe/capture.c @@ -131,8 +131,8 @@ void CaptureInit(u_int32_t sourceIP, u_int16_t sourcePort, exit(-1); } - strncpy(source, InetAddress(sourceIP), sizeof(source) - 1); - strncpy(target, InetAddress(targetIP), sizeof(target) - 1); + strlcpy(source, InetAddress(sourceIP), sizeof(source)); + strlcpy(target, InetAddress(targetIP), sizeof(target)); /* Setup initial filter */ sprintf(filtercmds, diff --git a/ecnprobe/ecn_probe.c b/ecnprobe/ecn_probe.c index ae00f4a..362ff4f 100644 --- a/ecnprobe/ecn_probe.c +++ b/ecnprobe/ecn_probe.c @@ -64,7 +64,7 @@ extern struct TcpSession session; void usage (char *name); -int GetCannonicalInfo(char *string, u_int32_t *address); +int GetCannonicalInfo(char *string, size_t str_size, u_int32_t *address); int BindTcpPort(int sockfd) ; void usage(char *name) @@ -179,7 +179,7 @@ void SigHandle(int signo) exit(-1); } -int GetCannonicalInfo(char *string, u_int32_t *address) +int GetCannonicalInfo(char *string, size_t str_size, u_int32_t *address) { struct hostent *hp; /* Is string in dotted decimal format? */ @@ -191,7 +191,7 @@ int GetCannonicalInfo(char *string, u_int32_t *address) "RETURN CODE: %d\n", string, FAIL); return(-1); } else { - strncpy(string, hp->h_name, MAXHOSTNAMELEN-1); + strlcpy(string, hp->h_name, str_size); memcpy((void *)address, (void *)hp->h_addr, hp->h_length); } @@ -207,9 +207,9 @@ int GetCannonicalInfo(char *string, u_int32_t *address) " name for %s\nRETURN CODE: %d", string, NO_SRC_CANON_INFO); } - /* strncpy(name, string, MAXHOSTNAMELEN - 1);*/ + /* strlcpy(name, string, MAXHOSTNAMELEN);*/ } else { - /* strncpy(name, hp->h_name, MAXHOSTNAMELEN - 1);*/ + /* strlcpy(name, hp->h_name, MAXHOSTNAMELEN);*/ } } return(0); @@ -288,10 +288,10 @@ int main(int argc, char **argv) printf("Target host name too long, max %u chars\n", MAXHOSTNAMELEN); Quit(FAIL); } - strncpy(session.targetHostName, optarg, - MAXHOSTNAMELEN); - strncpy(session.targetName, session.targetHostName, - MAXHOSTNAMELEN); + strlcpy(session.targetHostName, optarg, + sizeof(session.targetHostName)); + strlcpy(session.targetName, session.targetHostName, + sizeof(session.targetName)); break; case 'p': targetPort = atoi(optarg); @@ -310,7 +310,7 @@ int main(int argc, char **argv) printf("Source host name too long, max %u chars\n", MAXHOSTNAMELEN); Quit(FAIL); } - strncpy(session.sourceHostName, optarg, + strlcpy(session.sourceHostName, optarg, MAXHOSTNAMELEN); break; case 'd': @@ -319,7 +319,7 @@ int main(int argc, char **argv) Quit(FAIL); } bzero(dev, sizeof(dev)); - strncpy(dev, optarg, (sizeof(dev) - 1)); + strlcpy(dev, optarg, sizeof(dev)); usedev = 1; break; case 'f': @@ -367,18 +367,12 @@ int main(int argc, char **argv) signal(SIGINT, SigHandle); signal(SIGHUP, SigHandle); - if (GetCannonicalInfo(session.targetHostName, &targetIpAddress) < 0) + if (GetCannonicalInfo(session.targetHostName, sizeof(session.targetHostName), + &targetIpAddress) < 0) { printf("Failed to convert targetIP address\n"); Quit(NO_TARGET_CANON_INFO); } - /* - if (GetCannonicalInfo(session.sourceHostName, &sourceIpAddress) < 0) - { - printf("Failed to convert source IP address\n"); - Quit(NO_TARGET_CANON_INFO); - } - */ rc = getifaddrs(&ifap); if (rc != 0 || ifap == NULL) { printf("Failed to get source addresswith getifaddrs: %d\n", rc); @@ -398,9 +392,9 @@ int main(int argc, char **argv) if (strcmp(dev, tmp->ifa_name) == 0) { sin = (struct sockaddr_in *)tmp->ifa_addr; sourceIpAddress = sin->sin_addr.s_addr; - strncpy(session.sourceHostName, + strlcpy(session.sourceHostName, inet_ntoa(sin->sin_addr), - MAXHOSTNAMELEN); + sizeof(session.sourceHostName)); } else { continue; } @@ -409,10 +403,10 @@ int main(int argc, char **argv) bzero(dev, sizeof(dev)); sin = (struct sockaddr_in *)tmp->ifa_addr; sourceIpAddress = sin->sin_addr.s_addr; - strncpy(session.sourceHostName, + strlcpy(session.sourceHostName, inet_ntoa(sin->sin_addr), - MAXHOSTNAMELEN); - strncpy(dev, tmp->ifa_name, sizeof(dev)); + sizeof(session.sourceHostName)); + strlcpy(dev, tmp->ifa_name, sizeof(dev)); } } freeifaddrs(ifap); diff --git a/ifconfig.tproj/af_inet.c b/ifconfig.tproj/af_inet.c index ae05970..1b98d77 100644 --- a/ifconfig.tproj/af_inet.c +++ b/ifconfig.tproj/af_inet.c @@ -172,7 +172,7 @@ in_status_tunnel(int s) const struct sockaddr *sa = (const struct sockaddr *) &ifr.ifr_addr; memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, name, IFNAMSIZ); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCGIFPSRCADDR, (caddr_t)&ifr) < 0) return; @@ -197,7 +197,7 @@ in_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres) struct ifaliasreq addreq; memset(&addreq, 0, sizeof(addreq)); - strncpy(addreq.ifra_name, name, IFNAMSIZ); + strlcpy(addreq.ifra_name, name, sizeof(addreq.ifra_name)); memcpy(&addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len); memcpy(&addreq.ifra_dstaddr, dstres->ai_addr, dstres->ai_addr->sa_len); @@ -211,7 +211,7 @@ in_set_router(int s, int enable) struct ifreq ifr; bzero(&ifr, sizeof (ifr)); - strncpy(ifr.ifr_name, name, IFNAMSIZ); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_intval = enable; if (ioctl(s, SIOCSETROUTERMODE, &ifr) < 0) diff --git a/ifconfig.tproj/af_inet6.c b/ifconfig.tproj/af_inet6.c index 2fedbb3..59f8b06 100644 --- a/ifconfig.tproj/af_inet6.c +++ b/ifconfig.tproj/af_inet6.c @@ -119,7 +119,7 @@ setnd6flags(const char *dummyaddr __unused, int d, int s, int error; memset(&nd, 0, sizeof(nd)); - strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname)); + strlcpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname)); error = ioctl(s, SIOCGIFINFO_IN6, &nd); if (error) { warn("ioctl(SIOCGIFINFO_IN6)"); @@ -247,7 +247,7 @@ in6_status(int s __unused, const struct ifaddrs *ifa) if (sin == NULL) return; - strncpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name)); + strlcpy(ifr6.ifr_name, ifr.ifr_name, sizeof(ifr.ifr_name)); if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { warn("socket(AF_INET6,SOCK_DGRAM)"); return; @@ -510,7 +510,7 @@ in6_status_tunnel(int s) const struct sockaddr *sa = (const struct sockaddr *) &in6_ifr.ifr_addr; memset(&in6_ifr, 0, sizeof(in6_ifr)); - strncpy(in6_ifr.ifr_name, name, IFNAMSIZ); + strlcpy(in6_ifr.ifr_name, name, sizeof(in6_ifr.ifr_name)); if (ioctl(s, SIOCGIFPSRCADDR_IN6, (caddr_t)&in6_ifr) < 0) return; @@ -541,7 +541,7 @@ nd6_status(int s) int error; memset(&nd, 0, sizeof(nd)); - strncpy(nd.ifname, ifr.ifr_name, sizeof(nd.ifname)); + strlcpy(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)"); @@ -567,7 +567,7 @@ in6_set_tunnel(int s, struct addrinfo *srcres, struct addrinfo *dstres) struct in6_aliasreq in6_addreq; memset(&in6_addreq, 0, sizeof(in6_addreq)); - strncpy(in6_addreq.ifra_name, name, IFNAMSIZ); + strlcpy(in6_addreq.ifra_name, name, sizeof(in6_addreq.ifra_name)); memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len); memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr, dstres->ai_addr->sa_len); @@ -582,7 +582,7 @@ in6_set_router(int s, int enable) struct ifreq ifr; bzero(&ifr, sizeof (ifr)); - strncpy(ifr.ifr_name, name, IFNAMSIZ); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_intval = enable; if (ioctl(s, SIOCSETROUTERMODE_IN6, &ifr) < 0) diff --git a/ifconfig.tproj/if6lowpan.c b/ifconfig.tproj/if6lowpan.c new file mode 100644 index 0000000..f0f4b2e --- /dev/null +++ b/ifconfig.tproj/if6lowpan.c @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2017-2018 Apple Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ + */ + +/* + * Copyright (c) 1999 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "ifconfig.h" + +#include + + +static boolean_t is_sixlowpan_inited = FALSE; +static struct sixlowpanreq params; + +static int +get6lowpan(int s, struct ifreq *ifr, struct sixlowpanreq *req) +{ + bzero((char *)req, sizeof(*req)); + ifr->ifr_data = (caddr_t)req; + return ioctl(s, SIOCGIF6LOWPAN, (caddr_t)ifr); +} + +static void +sixlowpan_status(int s) +{ + struct sixlowpanreq req; + + if (get6lowpan(s, &ifr, &req) != -1) + printf("\t6lowpan: parent interface: %s\n", + req.parent[0] == '\0' ? + "" : req.parent); +} + + +static void +set6lowpandev(const char *val, int d, int s, const struct afswtch *afp) +{ + struct sixlowpanreq req; + + strlcpy(params.parent, val, sizeof(params.parent)); + is_sixlowpan_inited = TRUE; + fprintf(stderr, "val %s\n", val); + + strlcpy(req.parent, val, sizeof(req.parent)); + ifr.ifr_data = (caddr_t) &req; + if (ioctl(s, SIOCSIF6LOWPAN, (caddr_t)&ifr) == -1) + err(1, "SIOCSIF6LOWPAN"); +} + +static void +unset6lowpandev(const char *val, int d, int s, const struct afswtch *afp) +{ + struct sixlowpanreq req; + + bzero((char *)&req, sizeof(req)); + ifr.ifr_data = (caddr_t)&req; + + if (ioctl(s, SIOCGIF6LOWPAN, (caddr_t)&ifr) == -1) + err(1, "SIOCGIF6LOWPAN"); + + bzero((char *)&req, sizeof(req)); + if (ioctl(s, SIOCSIF6LOWPAN, (caddr_t)&ifr) == -1) + err(1, "SIOCSIF6LOWPAN"); +} + +static void +sixlowpan_create(const char *val, int d, int s, const struct afswtch *afp) +{ + strlcpy(params.parent, val, sizeof(params.parent)); + is_sixlowpan_inited = TRUE; +} + +static void +sixlowpan_clone_cb(int s, void *arg) +{ + if (is_sixlowpan_inited == TRUE && params.parent[0] == '\0') + errx(1, "6lowpandev must be specified"); +} + +static struct cmd sixlowpan_cmds[] = { + DEF_CLONE_CMD_ARG("6lowpandev", sixlowpan_create), + DEF_CMD_OPTARG("6lowpansetdev", set6lowpandev), + DEF_CMD_OPTARG("6lowpanunsetdev", unset6lowpandev), +}; +static struct afswtch af_6lowpan = { + .af_name = "af_6lowpan", + .af_af = AF_UNSPEC, + .af_other_status = sixlowpan_status, +}; + +static __constructor void +sixlowpan_ctor(void) +{ +#define N(a) (sizeof(a) / sizeof(a[0])) + int i; + + for (i = 0; i < N(sixlowpan_cmds); i++) + cmd_register(&sixlowpan_cmds[i]); + af_register(&af_6lowpan); + callback_register(sixlowpan_clone_cb, NULL); +#undef N +} diff --git a/ifconfig.tproj/ifclone.c b/ifconfig.tproj/ifclone.c index f6b8c07..127d10b 100644 --- a/ifconfig.tproj/ifclone.c +++ b/ifconfig.tproj/ifclone.c @@ -137,7 +137,7 @@ DECL_CMD_FUNC(clone_create, arg, d) static DECL_CMD_FUNC(clone_destroy, arg, d) { - (void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + (void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCIFDESTROY, &ifr) < 0) err(1, "SIOCIFDESTROY"); } diff --git a/ifconfig.tproj/ifconfig.c b/ifconfig.tproj/ifconfig.c index cb6a239..187f0f1 100644 --- a/ifconfig.tproj/ifconfig.c +++ b/ifconfig.tproj/ifconfig.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2018 Apple Inc. All rights reserved. + * Copyright (c) 2009-2019 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -94,15 +94,21 @@ __unused static const char copyright[] = #include #include #include +#include #include #include #include +#include #include #include #include #include "ifconfig.h" +#ifdef __APPLE__ +#include +#endif + /* * Since "struct ifreq" is composed of various union members, callers * should pay special attention to interprete the value. @@ -121,13 +127,13 @@ int all; int bond_details = 0; int supmedia = 0; -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) int verbose = 1; int showrtref = 1; -#else /* !TARGET_OS_EMBEDDED */ +#else /* (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */ int verbose = 0; int showrtref = 0; -#endif /* !TARGET_OS_EMBEDDED */ +#endif /* (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */ int printkeys = 0; /* Print keying material for interfaces. */ static int ifconfig(int argc, char *const *argv, int iscreate, @@ -144,6 +150,7 @@ 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 char *iffunct2str(u_int32_t functional_type); static struct afswtch *af_getbyname(const char *name); static struct afswtch *af_getbyfamily(int af); @@ -328,7 +335,7 @@ main(int argc, char *argv[]) ifindex = 0; for (ifa = ifap; ifa; ifa = ifa->ifa_next) { memset(&paifr, 0, sizeof(paifr)); - strncpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name)); + strlcpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name)); if (sizeof(paifr.ifr_addr) >= ifa->ifa_addr->sa_len) { memcpy(&paifr.ifr_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len); @@ -498,9 +505,9 @@ ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *afp) { const struct afswtch *nafp; struct callback *cb; - int s; + int ret, s; - strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); + strlcpy(ifr.ifr_name, name, sizeof ifr.ifr_name); top: if (afp == NULL) afp = af_getbyname("inet"); @@ -566,8 +573,15 @@ top: p->c_name); p->c_u.c_func2(argv[1], argv[2], s, afp); argc -= 2, argv += 2; - } else + } else if (p->c_parameter == VAARGS) { + ret = p->c_u.c_funcv(argc - 1, argv + 1, s, afp); + if (ret < 0) + errx(1, "'%s' command error", + p->c_name); + argc -= ret, argv += ret; + } else { p->c_u.c_func(*argv, p->c_parameter, s, afp); + } } argc--, argv++; } @@ -594,8 +608,7 @@ top: } } if (clearaddr) { - int ret; - strncpy(afp->af_ridreq, name, sizeof ifr.ifr_name); + strlcpy(afp->af_ridreq, name, sizeof ifr.ifr_name); ret = ioctl(s, afp->af_difaddr, afp->af_ridreq); if (ret < 0) { if (errno == EADDRNOTAVAIL && (doalias >= 0)) { @@ -612,7 +625,7 @@ top: } } if (newaddr && (setaddr || setmask)) { - strncpy(afp->af_addreq, name, sizeof ifr.ifr_name); + strlcpy(afp->af_addreq, name, sizeof ifr.ifr_name); if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0) Perror("ioctl (SIOCAIFADDR)"); } @@ -753,7 +766,7 @@ setifflags(const char *vname, int value, int s, const struct afswtch *afp) Perror("ioctl (SIOCGIFFLAGS)"); exit(1); } - strncpy(my_ifr.ifr_name, name, sizeof (my_ifr.ifr_name)); + strlcpy(my_ifr.ifr_name, name, sizeof (my_ifr.ifr_name)); flags = my_ifr.ifr_flags; if (value < 0) { @@ -791,7 +804,7 @@ static void setifmetric(const char *val, int dummy __unused, int s, const struct afswtch *afp) { - strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); ifr.ifr_metric = atoi(val); if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0) warn("ioctl (set metric)"); @@ -801,7 +814,7 @@ static void setifmtu(const char *val, int dummy __unused, int s, const struct afswtch *afp) { - strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); ifr.ifr_mtu = atoi(val); if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0) warn("ioctl (set mtu)"); @@ -848,9 +861,9 @@ setifdesc(const char *val, int dummy __unused, int s, const struct afswtch *afp) struct if_descreq ifdr; bzero(&ifdr, sizeof (ifdr)); - strncpy(ifdr.ifdr_name, name, sizeof (ifdr.ifdr_name)); + strlcpy(ifdr.ifdr_name, name, sizeof (ifdr.ifdr_name)); ifdr.ifdr_len = strlen(val); - strncpy((char *)ifdr.ifdr_desc, val, sizeof (ifdr.ifdr_desc)); + strlcpy((char *)ifdr.ifdr_desc, val, sizeof (ifdr.ifdr_desc)); if (ioctl(s, SIOCSIFDESC, (caddr_t)&ifdr) < 0) { warn("ioctl (set desc)"); @@ -868,7 +881,7 @@ settbr(const char *val, int dummy __unused, int s, const struct afswtch *afp) errno = 0; bzero(&iflpr, sizeof (iflpr)); - strncpy(iflpr.iflpr_name, name, sizeof (iflpr.iflpr_name)); + strlcpy(iflpr.iflpr_name, name, sizeof (iflpr.iflpr_name)); bps = strtold(val, &cp); if (val == cp || errno != 0) { @@ -903,7 +916,7 @@ settbr(const char *val, int dummy __unused, int s, const struct afswtch *afp) warn("ioctl (set link params)"); } else if (errno == ENXIO) { printf("TBR cannot be set on %s\n", name); - } else if (errno == ENOENT || rate == 0) { + } else if (errno == 0 && rate == 0) { printf("%s: TBR is now disabled\n", name); } else if (errno == ENODEV) { printf("%s: requires absolute TBR rate\n", name); @@ -915,6 +928,327 @@ settbr(const char *val, int dummy __unused, int s, const struct afswtch *afp) } } +static int +get_int64(uint64_t *i, char const *s) +{ + char *cp; + *i = strtol(s, &cp, 10); + if (cp == s || errno != 0) { + return (-1); + } + return (0); +} + +static int +get_int32(uint32_t *i, char const *s) +{ + char *cp; + *i = strtol(s, &cp, 10); + if (cp == s || errno != 0) { + return (-1); + } + return (0); +} + +static int +get_percent(double *d, const char *s) +{ + char *cp; + *d = strtod(s, &cp) / (double)100; + if (*d == HUGE_VALF || *d == HUGE_VALL) { + return (-1); + } + if (*d == 0.0 || (*cp != '\0' && strcmp(cp, "%") != 0)) { + return (-1); + } + return (0); +} + +static int +get_percent_fixed_point(uint32_t *i, const char *s) +{ + double p; + + if (get_percent(&p, s) != 0){ + return (-1); + } + + *i = p * IF_NETEM_PARAMS_PSCALE; + return (0); +} + +static int +netem_parse_args(struct if_netem_params *p, int argc, char *const *argv) +{ + int argc_saved = argc; + uint64_t bandwitdh = 0; + uint32_t latency = 0, jitter = 0; + uint32_t corruption = 0; + uint32_t duplication = 0; + uint32_t loss_p_gr_gl = 0, loss_p_gr_bl = 0, loss_p_bl_br = 0, + loss_p_bl_gr = 0, loss_p_br_bl = 0; + uint32_t reordering = 0; + + bzero(p, sizeof (*p)); + + /* take out "input"/"output" */ + argc--, argv++; + + for ( ; argc > 0; ) { + if (strcmp(*argv, "bandwidth") == 0) { + argc--, argv++; + if (argc <= 0 || get_int64(&bandwitdh, *argv) != 0) { + err(1, "Invalid value '%s'", *argv); + } + argc--, argv++; + } else if (strcmp(*argv, "corruption") == 0) { + argc--, argv++; + if (argc <= 0 || + get_percent_fixed_point(&corruption, *argv) != 0) { + err(1, "Invalid value '%s'", *argv); + } + argc--, argv++; + } else if (strcmp(*argv, "delay") == 0) { + argc--, argv++; + if (argc <= 0 || get_int32(&latency, *argv) != 0) { + err(1, "Invalid value '%s'", *argv); + } + argc--, argv++; + if (argc > 0 && get_int32(&jitter, *argv) == 0) { + argc--, argv++; + } + } else if (strcmp(*argv, "duplication") == 0) { + argc--, argv++; + if (argc <= 0 || + get_percent_fixed_point(&duplication, *argv) != 0) { + err(1, "Invalid value '%s'", *argv); + return (-1); + } + argc--, argv++; + } else if (strcmp(*argv, "loss") == 0) { + argc--, argv++; + if (argc <= 0 || get_percent_fixed_point(&loss_p_gr_gl, *argv) != 0) { + err(1, "Invalid value '%s'", *argv); + } + /* we may have all 5 probs, use naive model if not */ + argc--, argv++; + if (argc <= 0 || get_percent_fixed_point(&loss_p_gr_bl, *argv) != 0) { + continue; + } + /* if more than p_gr_gl, then should have all probs */ + argc--, argv++; + if (argc <= 0 || get_percent_fixed_point(&loss_p_bl_br, *argv) != 0) { + err(1, "Invalid value '%s' for p_bl_br", *argv); + } + argc--, argv++; + if (argc <= 0 || get_percent_fixed_point(&loss_p_bl_gr, *argv) != 0) { + err(1, "Invalid value '%s' for p_bl_gr", *argv); + } + argc--, argv++; + if (argc <= 0 || get_percent_fixed_point(&loss_p_br_bl, *argv) != 0) { + err(1, "Invalid value '%s' for p_br_bl", *argv); + } + argc--, argv++; + } else if (strcmp(*argv, "reordering") == 0) { + argc--, argv++; + if (argc <= 0 || get_percent_fixed_point(&reordering, *argv) != 0) { + err(1, "Invalid value '%s'", *argv); + } + argc--, argv++; + } else { + return (-1); + } + } + + if (corruption > IF_NETEM_PARAMS_PSCALE) { + err(1, "corruption percentage > 100%%"); + } + + if (duplication > IF_NETEM_PARAMS_PSCALE) { + err(1, "duplication percentage > 100%%"); + } + + if (duplication > 0 && latency == 0) { + /* we need to insert dup'ed packet with latency */ + err(1, "duplication needs latency param"); + } + + if (latency > 1000) { + err(1, "latency %dms too big (> 1 sec)", latency); + } + + if (jitter * 3 > latency) { + err(1, "jitter %dms too big (latency %dms)", jitter, latency); + } + + /* if gr_gl == 0 (no loss), other prob should all be zero */ + if (loss_p_gr_gl == 0 && + (loss_p_gr_bl != 0 || loss_p_bl_br != 0 || loss_p_bl_gr != 0 || + loss_p_br_bl != 0)) { + err(1, "loss params not all zero when gr_gl is zero"); + } + + /* check state machine transition prob integrity */ + if (loss_p_gr_gl > IF_NETEM_PARAMS_PSCALE || + /* gr_gl = IF_NETEM_PARAMS_PSCALE for total loss */ + loss_p_gr_bl > IF_NETEM_PARAMS_PSCALE || + loss_p_bl_br > IF_NETEM_PARAMS_PSCALE || + loss_p_bl_gr > IF_NETEM_PARAMS_PSCALE || + loss_p_br_bl > IF_NETEM_PARAMS_PSCALE || + loss_p_gr_gl + loss_p_gr_bl > IF_NETEM_PARAMS_PSCALE || + loss_p_bl_br + loss_p_bl_gr > IF_NETEM_PARAMS_PSCALE) { + err(1, "loss params too big"); + } + + if (reordering > IF_NETEM_PARAMS_PSCALE) { + err(1, "reordering percentage > 100%%"); + } + + p->ifnetem_bandwidth_bps = bandwitdh; + p->ifnetem_latency_ms = latency; + p->ifnetem_jitter_ms = jitter; + p->ifnetem_corruption_p = corruption; + p->ifnetem_duplication_p = duplication; + p->ifnetem_loss_p_gr_gl = loss_p_gr_gl; + p->ifnetem_loss_p_gr_bl = loss_p_gr_bl; + p->ifnetem_loss_p_bl_br = loss_p_bl_br; + p->ifnetem_loss_p_bl_gr = loss_p_bl_gr; + p->ifnetem_loss_p_br_bl = loss_p_br_bl; + p->ifnetem_reordering_p = reordering; + + return (argc_saved - argc); +} + +void +print_netem_params(struct if_netem_params *p, const char *desc) +{ + struct if_netem_params zero_params; + double pscale = IF_NETEM_PARAMS_PSCALE / 100; + bzero(&zero_params, sizeof (zero_params)); + + if (memcmp(p, &zero_params, sizeof (zero_params)) == 0) { + printf("%s NetEm Disabled\n\n", desc); + } else { + printf( + "%s NetEm Parameters\n" + "\tbandwidth rate %llubps\n" + "\tdelay latency %dms\n" + "\t jitter %dms\n", + desc, p->ifnetem_bandwidth_bps, + p->ifnetem_latency_ms, p->ifnetem_jitter_ms); + if (p->ifnetem_loss_p_gr_bl == 0 && + p->ifnetem_loss_p_bl_br == 0 && + p->ifnetem_loss_p_bl_gr == 0 && + p->ifnetem_loss_p_br_bl == 0) { + printf( + "\tloss %.3f%%\n", + (double) p->ifnetem_loss_p_gr_gl / pscale); + } else { + printf( + "\tloss GAP_RECV -> GAP_LOSS %.3f%%\n" + "\t GAP_RECV -> BURST_LOSS %.3f%%\n" + "\t BURST_LOSS -> BURST_RECV %.3f%%\n" + "\t BURST_LOSS -> GAP_RECV %.3f%%\n" + "\t BURST_RECV -> BURST_LOSS %.3f%%\n", + (double) p->ifnetem_loss_p_gr_gl / pscale, + (double) p->ifnetem_loss_p_gr_bl / pscale, + (double) p->ifnetem_loss_p_bl_br / pscale, + (double) p->ifnetem_loss_p_bl_gr / pscale, + (double) p->ifnetem_loss_p_br_bl / pscale); + } + printf( + "\tcorruption %.3f%%\n" + "\treordering %.3f%%\n\n", + (double) p->ifnetem_corruption_p / pscale, + (double) p->ifnetem_reordering_p / pscale); + } +} + +static int +setnetem(int argc, char *const *argv, int s, const struct afswtch *afp) +{ + struct if_linkparamsreq iflpr; + struct if_netem_params input_params, output_params; + int ret = 0, error = 0; + + bzero(&iflpr, sizeof (iflpr)); + bzero(&input_params, sizeof (input_params)); + bzero(&output_params, sizeof (output_params)); + + if (argc > 1) { + if (strcmp(argv[0], "input") == 0) { + ret = netem_parse_args(&input_params, argc, argv); + } else if (strcmp(argv[0], "output") == 0) { + ret = netem_parse_args(&output_params, argc, argv); + } else if (strcmp(argv[0], "-h") == 0 || strcmp(argv[0], "--help") == 0) { + goto bad_args; + } else { + fprintf(stderr, "uknown option %s\n", argv[0]); + goto bad_args; + } + if (ret < 0) { + goto bad_args; + } + } + + errno = 0; + strlcpy(iflpr.iflpr_name, name, sizeof (iflpr.iflpr_name)); + error = ioctl(s, SIOCGIFLINKPARAMS, &iflpr); + if (error < 0) { + warn("ioctl (get link params)"); + } + + if (argc == 0) { + print_netem_params(&iflpr.iflpr_input_netem, "Input"); + print_netem_params(&iflpr.iflpr_output_netem, "Output"); + return (0); + } else if (argc == 1) { + if (strcmp(argv[0], "input") == 0) { + bzero(&iflpr.iflpr_input_netem, + sizeof (iflpr.iflpr_input_netem)); + } else if (strcmp(argv[0], "output") == 0) { + bzero(&iflpr.iflpr_output_netem, + sizeof (iflpr.iflpr_output_netem)); + } else { + fprintf(stderr, "uknown option %s\n", argv[0]); + goto bad_args; + } + printf("%s: netem is now disabled for %s\n", name, argv[0]); + ret = 1; + } else { + if (strcmp(argv[0], "input") == 0) { + iflpr.iflpr_input_netem = input_params; + } else if (strcmp(argv[0], "output") == 0) { + iflpr.iflpr_output_netem = output_params; + } + } + + error = ioctl(s, SIOCSIFLINKPARAMS, &iflpr); + if (error < 0 && errno != ENOENT && errno != ENXIO && errno != ENODEV) { + warn("ioctl (set link params)"); + } else if (errno == ENXIO) { + printf("netem cannot be set on %s\n", name); + } else { + printf("%s: netem configured\n", name); + } + + return (ret); +bad_args: + fprintf(stderr, "Usage:\n" + "\tTo enable/set netem params\n" + "\t\tnetem \n" + "\t\t [ bandwidth BIT_PER_SEC ]\n" + "\t\t [ delay DELAY_MSEC [ JITTER_MSEC ] ]\n" + "\t\t [ loss PERCENTAGE ]\n" + "\t\t [ duplication PERCENTAGE ]\n" + "\t\t [ reordering PERCENTAGE ]\n\n" + "\tTo disable netem\n" + "\t\tnetem \n\n" + "\tTo show current settings\n" + "\t\tnetem\n\n"); + return (-1); +} + static void setthrottle(const char *val, int dummy __unused, int s, const struct afswtch *afp) @@ -924,7 +1258,7 @@ setthrottle(const char *val, int dummy __unused, int s, errno = 0; bzero(&iftr, sizeof (iftr)); - strncpy(iftr.ifthr_name, name, sizeof (iftr.ifthr_name)); + strlcpy(iftr.ifthr_name, name, sizeof (iftr.ifthr_name)); iftr.ifthr_level = strtold(val, &cp); if (val == cp || errno != 0) { @@ -950,7 +1284,7 @@ setdisableoutput(const char *val, int dummy __unused, int s, char *cp; errno = 0; bzero(&ifr, sizeof (ifr)); - strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); ifr.ifr_ifru.ifru_disable_output = strtold(val, &cp); if (val == cp || errno != 0) { @@ -976,7 +1310,7 @@ setlog(const char *val, int dummy __unused, int s, char *cp; errno = 0; - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_log.ifl_level = strtold(val, &cp); if (val == cp || errno != 0) { @@ -993,7 +1327,7 @@ setlog(const char *val, int dummy __unused, int s, void setcl2k(const char *vname, int value, int s, const struct afswtch *afp) { - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_ifru.ifru_2kcl = value; if (ioctl(s, SIOCSIF2KCL, (caddr_t)&ifr) < 0) @@ -1003,17 +1337,39 @@ setcl2k(const char *vname, int value, int s, const struct afswtch *afp) void setexpensive(const char *vname, int value, int s, const struct afswtch *afp) { - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_ifru.ifru_expensive = value; if (ioctl(s, SIOCSIFEXPENSIVE, (caddr_t)&ifr) < 0) Perror(vname); } +#ifdef SIOCSIFCONSTRAINED +void +setconstrained(const char *vname, int value, int s, const struct afswtch *afp) +{ + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + ifr.ifr_ifru.ifru_constrained = value; + + if (ioctl(s, SIOCSIFCONSTRAINED, (caddr_t)&ifr) < 0) + Perror(vname); +} +#endif + +static void +setifmpklog(const char *vname, int value, int s, const struct afswtch *afp) +{ + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + ifr.ifr_ifru.ifru_mpk_log = value; + + if (ioctl(s, SIOCSIFMPKLOG, (caddr_t)&ifr) < 0) + Perror(vname); +} + void settimestamp(const char *vname, int value, int s, const struct afswtch *afp) { - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); if (value == 0) { if (ioctl(s, SIOCSIFTIMESTAMPDISABLE, (caddr_t)&ifr) < 0) @@ -1044,7 +1400,7 @@ setecnmode(const char *val, int dummy __unused, int s, } } - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCSECNMODE, (caddr_t)&ifr) < 0) Perror("ioctl(SIOCSECNMODE)"); @@ -1071,13 +1427,15 @@ setqosmarking(const char *cmd, const char *arg, int s, const struct afswtch *afp printf("%s(%s, %s)\n", __func__, cmd, arg); #endif /* (DEBUG | DEVELOPMENT) */ - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); if (strcmp(cmd, "mode") == 0) { ioc = SIOCSQOSMARKINGMODE; if (strcmp(arg, "fastlane") == 0) ifr.ifr_qosmarking_mode = IFRTYPE_QOSMARKING_FASTLANE; + else if (strcmp(arg, "rfc4594") == 0) + ifr.ifr_qosmarking_mode = IFRTYPE_QOSMARKING_RFC4594; else if (strcasecmp(arg, "none") == 0 || strcasecmp(arg, "off") == 0) ifr.ifr_qosmarking_mode = IFRTYPE_QOSMARKING_MODE_NONE; else @@ -1103,7 +1461,7 @@ setqosmarking(const char *cmd, const char *arg, int s, const struct afswtch *afp void setfastlane(const char *cmd, const char *arg, int s, const struct afswtch *afp) { - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); warnx("### fastlane is obsolete, use qosmarking ###"); @@ -1138,7 +1496,7 @@ setfastlane(const char *cmd, const char *arg, int s, const struct afswtch *afp) int value; u_long ioc; - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); if (strcmp(cmd, "capable") == 0) ioc = SIOCSFASTLANECAPABLE; @@ -1202,6 +1560,74 @@ setlowpowermode(const char *vname, int value, int s, const struct afswtch *afp) Perror(vname); } +struct str2num { + const char *str; + uint32_t num; +}; + +static struct str2num subfamily_str2num[] = { + { .str = "any", .num = IFRTYPE_SUBFAMILY_ANY }, + { .str = "USB", .num = IFRTYPE_SUBFAMILY_USB }, + { .str = "Bluetooth", .num = IFRTYPE_SUBFAMILY_BLUETOOTH }, + { .str = "Wi-Fi", .num = IFRTYPE_SUBFAMILY_WIFI }, + { .str = "wifi", .num = IFRTYPE_SUBFAMILY_WIFI }, + { .str = "Thunderbolt", .num = IFRTYPE_SUBFAMILY_THUNDERBOLT }, + { .str = "reserverd", .num = IFRTYPE_SUBFAMILY_RESERVED }, + { .str = "intcoproc", .num = IFRTYPE_SUBFAMILY_INTCOPROC }, + { .str = "QuickRelay", .num = IFRTYPE_SUBFAMILY_QUICKRELAY }, + { .str = "Default", .num = IFRTYPE_SUBFAMILY_DEFAULT }, + { .str = NULL, .num = 0 }, +}; + +static uint32_t +get_num_from_str(struct str2num* str2nums, const char *str) +{ + struct str2num *str2num = str2nums; + + while (str2num != NULL && str2num->str != NULL) { + if (strcasecmp(str2num->str, str) == 0) { + return str2num->num; + } + str2num++; + } + return 0; +} + +static void +setifsubfamily(const char *val, int dummy __unused, int s, + const struct afswtch *afp) +{ + strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + + char *endptr; + uint32_t subfamily = strtoul(val, &endptr, 0); + if (*endptr != 0) { + subfamily = get_num_from_str(subfamily_str2num, val); + if (subfamily == 0) { + return; + } + } + + ifr.ifr_type.ift_subfamily = subfamily; + if (ioctl(s, SIOCSIFSUBFAMILY, (caddr_t)&ifr) < 0) + warn("ioctl(SIOCSIFSUBFAMILY)"); +} + +void +setifavailability(const char *vname, int value, int s, const struct afswtch *afp) +{ + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + ifr.ifr_interface_state.valid_bitmask = IF_INTERFACE_STATE_INTERFACE_AVAILABILITY_VALID; + if (value == 0) { + ifr.ifr_interface_state.interface_availability = IF_INTERFACE_STATE_INTERFACE_UNAVAILABLE; + } else { + ifr.ifr_interface_state.interface_availability = IF_INTERFACE_STATE_INTERFACE_AVAILABLE; + } + if (ioctl(s, SIOCSIFINTERFACESTATE, (caddr_t)&ifr) < 0) + warn("ioctl(SIOCSIFINTERFACESTATE)"); +} + + #define IFFBITS \ "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \ "\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \ @@ -1214,6 +1640,10 @@ setlowpowermode(const char *vname, int value, int s, const struct afswtch *afp) "\27AWDL_RESTRICTED\30CL2K\31ECN_ENABLE\32ECN_DISABLE\33CHANNEL_DRV\34CA" \ "\35SENDLIST\36DIRECTLINK\37FASTLN_ON\40UPDOWNCHANGE" +#define IFXFBITS \ +"\020\1WOL\2TIMESTAMP\3NOAUTONX\4LEGACY\5TXLOWINET\6RXLOWINET\7ALLOCKPI" \ +"\10LOWPOWER\11MPKLOG\12CONSTRAINED" + #define IFCAPBITS \ "\020\1RXCSUM\2TXCSUM\3VLAN_MTU\4VLAN_HWTAGGING\5JUMBO_MTU" \ "\6TSO4\7TSO6\10LRO\11AV\12TXSTATUS\13CHANNEL_IO\14HW_TIMESTAMP\15SW_TIMESTAMP" \ @@ -1239,6 +1669,7 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, struct ifmibdata_supplemental ifmsupp; size_t miblen = sizeof(struct ifmibdata_supplemental); u_int64_t eflags = 0; + u_int64_t xflags = 0; int curcap = 0; if (afp == NULL) { @@ -1248,7 +1679,7 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, allfamilies = 0; ifr.ifr_addr.sa_family = afp->af_af == AF_LINK ? AF_INET : afp->af_af; - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0); if (s < 0) @@ -1268,6 +1699,13 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, if (ifindex != 0) printf(" index %u", ifindex); } +#ifdef SIOCGIFCONSTRAINED + // Constrained is stored in if_xflags which isn't exposed directly + if (ioctl(s, SIOCGIFCONSTRAINED, (caddr_t)&ifr) == 0 && + ifr.ifr_constrained != 0) { + printf(" constrained"); + } +#endif putchar('\n'); if (verbose && ioctl(s, SIOCGIFEFLAGS, (caddr_t)&ifr) != -1 && @@ -1276,6 +1714,12 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, putchar('\n'); } + if (verbose && ioctl(s, SIOCGIFXFLAGS, (caddr_t)&ifr) != -1 && + (xflags = ifr.ifr_xflags) != 0) { + printb("\txflags", xflags, IFXFBITS); + putchar('\n'); + } + if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) { if (ifr.ifr_curcap != 0) { curcap = ifr.ifr_curcap; @@ -1287,7 +1731,7 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, putchar('\n'); } } - + tunnel_status(s); for (ift = ifa; ift != NULL; ift = ift->ifa_next) { @@ -1332,7 +1776,7 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, else if (afp->af_other_status != NULL) afp->af_other_status(s); - strncpy(ifs.ifs_name, name, sizeof ifs.ifs_name); + strlcpy(ifs.ifs_name, name, sizeof ifs.ifs_name); if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0) printf("%s", ifs.ascii); @@ -1347,6 +1791,14 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, printf("\ttype: %s\n", c); } + if (verbose > 1) { + if (ioctl(s, SIOCGIFFUNCTIONALTYPE, &ifr) != -1) { + char *c = iffunct2str(ifr.ifr_functional_type); + if (c != NULL) + printf("\tfunctional type: %s\n", c); + } + } + if (verbose > 0) { struct if_agentidsreq ifar; memset(&ifar, 0, sizeof(ifar)); @@ -1465,7 +1917,7 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, } bzero(&iflpr, sizeof (iflpr)); - strncpy(iflpr.iflpr_name, name, sizeof (iflpr.iflpr_name)); + strlcpy(iflpr.iflpr_name, name, sizeof (iflpr.iflpr_name)); if (ioctl(s, SIOCGIFLINKPARAMS, &iflpr) != -1) { u_int64_t ibw_max = iflpr.iflpr_input_bw.max_bw; u_int64_t ibw_eff = iflpr.iflpr_input_bw.eff_bw; @@ -1492,7 +1944,7 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, printf("\n"); bzero(&iftr, sizeof (iftr)); - strncpy(iftr.ifthr_name, name, + strlcpy(iftr.ifthr_name, name, sizeof (iftr.ifthr_name)); if (ioctl(s, SIOCGIFTHROTTLE, &iftr) != -1 && iftr.ifthr_level != IFNET_THROTTLE_OFF) @@ -1587,7 +2039,7 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, } bzero(&ifdr, sizeof (ifdr)); - strncpy(ifdr.ifdr_name, name, sizeof (ifdr.ifdr_name)); + strlcpy(ifdr.ifdr_name, name, sizeof (ifdr.ifdr_name)); if (ioctl(s, SIOCGIFDESC, &ifdr) != -1 && ifdr.ifdr_len) { printf("\tdesc: %s\n", ifdr.ifdr_desc); } @@ -1629,6 +2081,9 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, case IFRTYPE_QOSMARKING_FASTLANE: printf("fastlane\n"); break; + case IFRTYPE_QOSMARKING_RFC4594: + printf("RFC4594\n"); + break; case IFRTYPE_QOSMARKING_MODE_NONE: printf("none\n"); break; @@ -1644,6 +2099,10 @@ status(const struct afswtch *afp, const struct sockaddr_dl *sdl, printf("\tlow power mode: %s\n", (ifr.ifr_low_power_mode != 0) ? "enabled" : "disabled"); } + if (verbose > 0 && ioctl(s, SIOCGIFMPKLOG, &ifr) != -1) { + printf("\tmulti layer packet logging (mpklog): %s\n", + (ifr.ifr_mpk_log != 0) ? "enabled" : "disabled"); + } done: close(s); return; @@ -1927,6 +2386,8 @@ static struct cmd basic_cmds[] = { DEF_CMD("monitor", IFF_MONITOR:, setifflags), DEF_CMD("-monitor", -IFF_MONITOR, setifflags), #endif /* IFF_MONITOR */ + DEF_CMD("mpklog", 1, setifmpklog), + DEF_CMD("-mpklog", 0, setifmpklog), #ifdef IFF_STATICARP DEF_CMD("staticarp", IFF_STATICARP, setifflags), DEF_CMD("-staticarp", -IFF_STATICARP, setifflags), @@ -1986,12 +2447,17 @@ static struct cmd basic_cmds[] = { DEF_CMD("-router", 0, setrouter), DEF_CMD_ARG("desc", setifdesc), DEF_CMD_ARG("tbr", settbr), + DEF_CMD_VA("netem", setnetem), 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), +#ifdef SIOCSIFCONSTRAINED + DEF_CMD("constrained", 1, setconstrained), + DEF_CMD("-constrained", 0, setconstrained), +#endif DEF_CMD("timestamp", 1, settimestamp), DEF_CMD("-timestamp", 0, settimestamp), DEF_CMD_ARG("ecn", setecnmode), @@ -2002,6 +2468,10 @@ static struct cmd basic_cmds[] = { DEF_CMD("-probe_connectivity", 0, setprobeconnectivity), DEF_CMD("lowpowermode", 1, setlowpowermode), DEF_CMD("-lowpowermode", 0, setlowpowermode), + DEF_CMD_ARG("subfamily", setifsubfamily), + DEF_CMD("available", 1, setifavailability), + DEF_CMD("-available", 0, setifavailability), + DEF_CMD("unavailable", 0, setifavailability), }; static __constructor void @@ -2101,10 +2571,23 @@ ift2str(unsigned int t, unsigned int f, unsigned int sf) c = "Cellular"; break; + case IFT_OTHER: + if (ifr.ifr_type.ift_family == APPLE_IF_FAM_IPSEC) { + if (ifr.ifr_type.ift_subfamily == IFRTYPE_SUBFAMILY_BLUETOOTH) { + c = "Companion Link Bluetooth"; + } else if (ifr.ifr_type.ift_subfamily == IFRTYPE_SUBFAMILY_QUICKRELAY) { + c = "Companion Link QuickRelay"; + } else if (ifr.ifr_type.ift_subfamily == IFRTYPE_SUBFAMILY_WIFI) { + c = "Companion Link Wi-Fi"; + } else if (ifr.ifr_type.ift_subfamily == IFRTYPE_SUBFAMILY_DEFAULT) { + c = "Companion Link Default"; + } + } + break; + case IFT_BRIDGE: case IFT_PFLOG: case IFT_PFSYNC: - case IFT_OTHER: case IFT_PPP: case IFT_LOOP: case IFT_GIF: @@ -2132,3 +2615,45 @@ ift2str(unsigned int t, unsigned int f, unsigned int sf) return (c); } + +static char * +iffunct2str(u_int32_t functional_type) +{ + char *str = NULL; + + switch (functional_type) { + case IFRTYPE_FUNCTIONAL_UNKNOWN: + break; + + case IFRTYPE_FUNCTIONAL_LOOPBACK: + str = "loopback"; + break; + + case IFRTYPE_FUNCTIONAL_WIRED: + str = "wired"; + break; + + case IFRTYPE_FUNCTIONAL_WIFI_INFRA: + str = "wifi"; + break; + + case IFRTYPE_FUNCTIONAL_WIFI_AWDL: + str = "awdl"; + break; + + case IFRTYPE_FUNCTIONAL_CELLULAR: + str = "cellular"; + break; + + case IFRTYPE_FUNCTIONAL_INTCOPROC: + break; + + case IFRTYPE_FUNCTIONAL_COMPANIONLINK: + str = "companionlink"; + break; + + default: + break; + } + return str; +} diff --git a/ifconfig.tproj/ifconfig.h b/ifconfig.tproj/ifconfig.h index 1a89a33..ef1a362 100644 --- a/ifconfig.tproj/ifconfig.h +++ b/ifconfig.tproj/ifconfig.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2011 Apple Inc. All rights reserved. + * Copyright (c) 2009-2018 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -69,6 +69,7 @@ struct cmd; typedef void c_func(const char *cmd, int arg, int s, const struct afswtch *afp); typedef void c_func2(const char *arg1, const char *arg2, int s, const struct afswtch *afp); +typedef int c_funcv(int argc, char *const *argv, int s, const struct afswtch *afp); struct cmd { const char *c_name; @@ -76,9 +77,11 @@ struct cmd { #define NEXTARG 0xffffff /* has following arg */ #define NEXTARG2 0xfffffe /* has 2 following args */ #define OPTARG 0xfffffd /* has optional following arg */ +#define VAARGS 0xfffffc /* has variable following args */ union { c_func *c_func; c_func2 *c_func2; + c_funcv *c_funcv; } c_u; int c_iscloneop; struct cmd *c_next; @@ -100,6 +103,7 @@ void callback_register(callback_func *, void *); #define DEF_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func } } #define DEF_CMD_OPTARG(name, func) { name, OPTARG, { .c_func = func } } #define DEF_CMD_ARG2(name, func) { name, NEXTARG2, { .c_func2 = func } } +#define DEF_CMD_VA(name, func) { name, VAARGS, { .c_funcv = func } } #define DEF_CLONE_CMD(name, param, func) { name, param, { .c_func = func }, 1 } #define DEF_CLONE_CMD_ARG(name, func) { name, NEXTARG, { .c_func = func }, 1 } diff --git a/ifconfig.tproj/ifmedia.c b/ifconfig.tproj/ifmedia.c index f03e995..713c136 100644 --- a/ifconfig.tproj/ifmedia.c +++ b/ifconfig.tproj/ifmedia.c @@ -111,7 +111,7 @@ media_status(int s) int *media_list, i; (void) memset(&ifmr, 0, sizeof(ifmr)); - (void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); + (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0) { /* @@ -132,6 +132,7 @@ media_status(int s) if (ioctl(s, SIOCGIFXMEDIA, (caddr_t)&ifmr) < 0) err(1, "SIOCGIFXMEDIA"); + printf("\tmedia: "); print_media_word(ifmr.ifm_current, 1); if (ifmr.ifm_active != ifmr.ifm_current) { @@ -204,7 +205,7 @@ ifmedia_getstate(int s) err(1, "malloc"); (void) memset(ifmr, 0, sizeof(struct ifmediareq)); - (void) strncpy(ifmr->ifm_name, name, + (void) strlcpy(ifmr->ifm_name, name, sizeof(ifmr->ifm_name)); ifmr->ifm_count = 0; @@ -270,7 +271,7 @@ setmedia(const char *val, int d, int s, const struct afswtch *afp) */ subtype = get_media_subtype(IFM_TYPE(ifmr->ifm_ulist[0]), val); - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_media = (ifmr->ifm_current & ~(IFM_NMASK|IFM_TMASK)) | IFM_TYPE(ifmr->ifm_ulist[0]) | subtype; @@ -306,7 +307,7 @@ domediaopt(const char *val, int clear, int s) options = get_media_options(IFM_TYPE(ifmr->ifm_ulist[0]), val); - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_media = ifmr->ifm_current; if (clear) ifr.ifr_media &= ~options; @@ -333,7 +334,7 @@ setmediainst(const char *val, int d, int s, const struct afswtch *afp) if (inst < 0 || inst > IFM_INST_MAX) errx(1, "invalid media instance: %s", val); - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_media = (ifmr->ifm_current & ~IFM_IMASK) | inst << IFM_ISHIFT; ifmr->ifm_current = ifr.ifr_media; @@ -351,7 +352,7 @@ setmediamode(const char *val, int d, int s, const struct afswtch *afp) mode = get_media_mode(IFM_TYPE(ifmr->ifm_ulist[0]), val); - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_media = (ifmr->ifm_current & ~IFM_MMASK) | mode; ifmr->ifm_current = ifr.ifr_media; diff --git a/ifconfig.tproj/nexus.c b/ifconfig.tproj/nexus.c index 692e211..3df9842 100644 --- a/ifconfig.tproj/nexus.c +++ b/ifconfig.tproj/nexus.c @@ -60,7 +60,7 @@ static void nexus_status(int s) { struct if_nexusreq ifnr; - uuid_string_t multistack; + uuid_string_t flowswitch; uuid_string_t netif; if (!verbose) { @@ -77,9 +77,9 @@ nexus_status(int s) } uuid_unparse_upper(ifnr.ifnr_netif, netif); printf("\tnetif: %s\n", netif); - if (uuid_is_null(ifnr.ifnr_multistack) == 0) { - uuid_unparse_upper(ifnr.ifnr_multistack, multistack); - printf("\tmultistack: %s\n", multistack); + if (uuid_is_null(ifnr.ifnr_flowswitch) == 0) { + uuid_unparse_upper(ifnr.ifnr_flowswitch, flowswitch); + printf("\tflowswitch: %s\n", flowswitch); } return; } diff --git a/mnc.tproj/README b/mnc.tproj/README index 291ce1a..77cbaa8 100644 --- a/mnc.tproj/README +++ b/mnc.tproj/README @@ -1,4 +1,4 @@ - MNC - Multicast NetCat +1 MNC - Multicast NetCat ------------------------ 1. Introduction diff --git a/mptcp_client/mptcp_client.c b/mptcp_client/mptcp_client.c index 37a43ec..770aabc 100644 --- a/mptcp_client/mptcp_client.c +++ b/mptcp_client/mptcp_client.c @@ -89,7 +89,7 @@ char *setup_buffer1(int bufsz) return NULL; bzero(buf, bufsz); - strlcpy(buf, MSG_HDR, sizeof(MSG_HDR)); + strlcpy(buf, MSG_HDR, bufsz); for (i = sizeof(MSG_HDR); i < bufsz; i++) { buf[i] = j; @@ -111,7 +111,7 @@ char *setup_buffer2(int bufsz) return NULL; bzero(buf, bufsz); - strlcpy(buf, MSG_HDR, sizeof(MSG_HDR)); + strlcpy(buf, MSG_HDR, bufsz); for (i = sizeof(MSG_HDR); i < bufsz; i++) { buf[i] = j; diff --git a/mtest.tproj/mtest.c b/mtest.tproj/mtest.c index e5a7442..9c1614e 100644 --- a/mtest.tproj/mtest.c +++ b/mtest.tproj/mtest.c @@ -744,7 +744,7 @@ process_cmd(char *cmd, int s, int s6 __unused, FILE *fp __unused) warnc(EINVAL, "ether_aton"); break; } - strlcpy(ifr.ifr_name, str1, IF_NAMESIZE); + strlcpy(ifr.ifr_name, str1, sizeof(ifr.ifr_name)); memcpy(LLADDR(dlp), ep, ETHER_ADDR_LEN); if (ioctl(s, (*cmd == 'a') ? SIOCADDMULTI : SIOCDELMULTI, &ifr) == -1) { diff --git a/ndp.tproj/ndp.c b/ndp.tproj/ndp.c index 01d64aa..b485fa1 100644 --- a/ndp.tproj/ndp.c +++ b/ndp.tproj/ndp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2013 Apple Inc. All rights reserved. + * Copyright (c) 2009-2017 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -393,6 +393,7 @@ set(int argc, char **argv) int gai_error; u_char *ea; char *host = argv[0], *eaddr = argv[1]; + int ealen; getsocket(); argc -= 2; @@ -416,8 +417,10 @@ set(int argc, char **argv) } #endif ea = (u_char *)LLADDR(&sdl_m); - if (ndp_ether_aton(eaddr, ea) == 0) - sdl_m.sdl_alen = 6; + + ealen = ndp_ether_aton(eaddr, ea); + if (ealen != -1) + sdl_m.sdl_alen = ealen; flags = expire_time = 0; while (argc-- > 0) { if (strncmp(argv[0], "temp", 4) == 0) { @@ -439,7 +442,8 @@ set(int argc, char **argv) (rtm->rtm_flags & RTF_LLINFO) && !(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) { case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023: - case IFT_ISO88024: case IFT_ISO88025: + case IFT_ISO88024: case IFT_ISO88025: + case IFT_6LOWPAN: goto overwrite; } /* @@ -1066,17 +1070,18 @@ ether_str(struct sockaddr_dl *sdl) static int ndp_ether_aton(char *a, u_char *n) { - int i, o[6]; + int i, o[8]; + int len; - i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o[0], &o[1], &o[2], &o[3], &o[4], - &o[5]); - if (i != 6) { + len = sscanf(a, "%x:%x:%x:%x:%x:%x:%x:%x", &o[0], &o[1], &o[2], &o[3], &o[4], + &o[5], &o[6], &o[7]); + if (len != 6 && len != 8) { fprintf(stderr, "ndp: invalid Ethernet address '%s'\n", a); - return (1); + return (-1); } - for (i = 0; i < 6; i++) + for (i = 0; i < len; i++) n[i] = o[i]; - return (0); + return (len); } static void diff --git a/netstat.tproj/if.c b/netstat.tproj/if.c index 5d82d82..0704c32 100644 --- a/netstat.tproj/if.c +++ b/netstat.tproj/if.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008-2015 Apple Inc. All rights reserved. + * Copyright (c) 2008-2019 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -93,6 +93,8 @@ #include #include +#include + #include "netstat.h" #define YES 1 @@ -307,8 +309,13 @@ intpr(void (*pfunc)(char *)) } if (!pfunc) { - printf("%-5.5s %-5.5s %-13.13s %-15.15s %8.8s %5.5s", - "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs"); + if (lflag) { + printf("%-10.10s %-5.5s %-39.39s %-39.39s %8.8s %5.5s", + "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs"); + } else { + printf("%-10.10s %-5.5s %-13.13s %-15.15s %8.8s %5.5s", + "Name", "Mtu", "Network", "Address", "Ipkts", "Ierrs"); + } if (prioflag >= 0) printf(" %8.8s %8.8s", "Itcpkts", "Ipvpkts"); if (bflag) { @@ -364,17 +371,19 @@ intpr(void (*pfunc)(char *)) int mibname[6]; size_t miblen = sizeof(struct ifmibdata_supplemental); - strncpy(name, sdl->sdl_data, sdl->sdl_nlen); - name[sdl->sdl_nlen] = 0; if (interface != 0 && if2m->ifm_index != ifindex) continue; - cp = index(name, '\0'); + + /* The interface name is not a zero-ended string */ + memcpy(name, sdl->sdl_data, MIN(sizeof(name) - 1, sdl->sdl_nlen)); + name[MIN(sizeof(name) - 1, sdl->sdl_nlen)] = 0; if (pfunc) { (*pfunc)(name); continue; } + cp = index(name, '\0'); if ((if2m->ifm_flags & IFF_UP) == 0) *cp++ = '*'; *cp = '\0'; @@ -464,16 +473,20 @@ intpr(void (*pfunc)(char *)) } else { continue; } - printf("%-5.5s %-5u ", name, mtu); + if (lflag) { + printf("%-10.10s %-5u ", name, mtu); + } else { + printf("%-5.5s %-5u ", name, mtu); + } if (sa == 0) { - printf("%-13.13s ", "none"); - printf("%-15.15s ", "none"); + printf(lflag ? "%-39.39s " : "%-13.13s ", "none"); + printf(lflag ? "%-39.39s " : "%-15.15s ", "none"); } else { switch (sa->sa_family) { case AF_UNSPEC: - printf("%-13.13s ", "none"); - printf("%-15.15s ", "none"); + printf(lflag ? "%-39.39s " : "%-13.13s ", "none"); + printf(lflag ? "%-39.39s " : "%-15.15s ", "none"); break; case AF_INET: { @@ -486,12 +499,12 @@ intpr(void (*pfunc)(char *)) ((struct sockaddr_in *) rti_info[RTAX_NETMASK])->sin_len); - printf("%-13.13s ", + printf(lflag ? "%-39.39s " : "%-13.13s ", netname(sin->sin_addr.s_addr & mask.sin_addr.s_addr, ntohl(mask.sin_addr.s_addr))); - printf("%-15.15s ", + printf(lflag ? "%-39.39s " : "%-15.15s ", routename(sin->sin_addr.s_addr)); network_layer = 1; @@ -504,8 +517,8 @@ intpr(void (*pfunc)(char *)) struct sockaddr *mask = (struct sockaddr *)rti_info[RTAX_NETMASK]; - printf("%-11.11s ", netname6(sin6, mask)); - printf("%-17.17s ", (char *)inet_ntop(AF_INET6, + printf(lflag ? "%-39.39s " : "%-11.11s ", netname6(sin6, mask)); + printf(lflag ? "%-39.39s " : "%-17.17s ", (char *)inet_ntop(AF_INET6, &sin6->sin6_addr, ntop_buf, sizeof(ntop_buf))); @@ -521,7 +534,7 @@ intpr(void (*pfunc)(char *)) n = sdl->sdl_alen; snprintf(linknum, sizeof(linknum), "", sdl->sdl_index); - m = printf("%-11.11s ", linknum); + m = printf(lflag ? "%-39.39s " : "%-11.11s ", linknum); goto hexprint; } @@ -535,7 +548,7 @@ intpr(void (*pfunc)(char *)) while (--n >= 0) m += printf("%02x%c", *cp++ & 0xff, n > 0 ? ':' : ' '); - m = 30 - m; + m = (lflag ? 80 : 30) - m; while (m-- > 0) putchar(' '); @@ -1998,6 +2011,7 @@ rxpollstatpr(void) size_t miblen = sizeof (ifmsupp); struct itimerval timer_interval; struct if_rxpoll_stats *sp; + struct if_netif_stats *np; sigset_t sigset, oldsigset; unsigned int ifindex; int name[6]; @@ -2038,8 +2052,11 @@ loop: interface, sp->ifi_poll_on_req, sp->ifi_poll_on_err); printf(" [ poll off requests: %15u errors: %27u ]\n", sp->ifi_poll_off_req, sp->ifi_poll_off_err); - printf(" [ polled packets: %18llu polled bytes: %21llu ]\n", - sp->ifi_poll_packets, sp->ifi_poll_bytes); + printf(" [ polled packets: %18llu per poll limit: %19lu ]\n", + sp->ifi_poll_packets, sp->ifi_poll_packets_limit); + printf(" [ polled bytes: %20llu ]\n", sp->ifi_poll_bytes); + printf(" [ poll interval: %14llu nsec ]\n", + sp->ifi_poll_interval_time); printf(" [ sampled packets avg/min/max: %12u / %12u / %12u ]\n", sp->ifi_poll_packets_avg, sp->ifi_poll_packets_min, sp->ifi_poll_packets_max); @@ -2055,6 +2072,24 @@ loop: printf(" [ wakeups lowat/hiwat threshold: %10u / %10u ]\n", sp->ifi_poll_wakeups_lowat, sp->ifi_poll_wakeups_hiwat); + np = &ifmsupp.ifmd_netif_stats; + printf(" [ mit mode: %24U cfg idx: %26u ]\n", + np->ifn_rx_mit_mode, np->ifn_rx_mit_cfg_idx); + printf(" [ cfg packets lo/hi threshold: %12u / %12u ]\n", + np->ifn_rx_mit_cfg_packets_lowat, np->ifn_rx_mit_cfg_packets_hiwat); + printf(" [ cfg bytes lo/hi threshold: %12u / %12u ]\n", + np->ifn_rx_mit_cfg_bytes_lowat, np->ifn_rx_mit_cfg_bytes_hiwat); + printf(" [ cfg interval: %15llu nsec ]\n", + np->ifn_rx_mit_cfg_interval); + printf(" [ mit interval: %15llu nsec ]\n", + np->ifn_rx_mit_interval); + printf(" [ mit packets avg/min/max: %12u / %12u / %12u ]\n", + np->ifn_rx_mit_packets_avg, np->ifn_rx_mit_packets_min, + np->ifn_rx_mit_packets_max); + printf(" [ mit bytes avg/min/max: %12u / %12u / %12u ]\n", + np->ifn_rx_mit_bytes_avg, np->ifn_rx_mit_bytes_min, + np->ifn_rx_mit_bytes_max); + fflush(stdout); if (interval > 0) { diff --git a/netstat.tproj/inet.c b/netstat.tproj/inet.c index d962a80..7f015fd 100644 --- a/netstat.tproj/inet.c +++ b/netstat.tproj/inet.c @@ -354,11 +354,7 @@ protopr(uint32_t proto, /* for sysctl version we pass proto # */ "Current listen queue sizes (qlen/incqlen/maxqlen)"); putchar('\n'); if (Aflag) { -#if !TARGET_OS_EMBEDDED printf("%-16.16s ", "Socket"); -#else - printf("%-8.8s ", "Socket"); -#endif printf("%-9.9s", "Flowhash"); } if (Lflag) @@ -384,18 +380,9 @@ protopr(uint32_t proto, /* for sysctl version we pass proto # */ } if (Aflag) { if (istcp) -#if !TARGET_OS_EMBEDDED printf("%16lx ", (u_long)inp->inp_ppcb); -#else - printf("%8lx ", (u_long)inp->inp_ppcb); - -#endif else -#if !TARGET_OS_EMBEDDED printf("%16lx ", (u_long)so->so_pcb); -#else - printf("%8lx ", (u_long)so->so_pcb); -#endif printf("%8x ", inp->inp_flowhash); } if (Lflag) { @@ -482,11 +469,6 @@ protopr(uint32_t proto, /* for sysctl version we pass proto # */ printf("%-11d", tp->t_state); else { printf("%-11s", tcpstates[tp->t_state]); -#if defined(TF_NEEDSYN) && defined(TF_NEEDFIN) - /* Show T/TCP `hidden state' */ - if (tp->t_flags & (TF_NEEDSYN|TF_NEEDFIN)) - putchar('*'); -#endif /* defined(TF_NEEDSYN) && defined(TF_NEEDFIN) */ } } if (!istcp) @@ -661,6 +643,7 @@ tcp_stats(uint32_t off , char *name, int af) p(tcps_keeptimeo, "\t%u keepalive timeout%s\n"); p(tcps_keepprobe, "\t\t%u keepalive probe%s sent\n"); p(tcps_keepdrops, "\t\t%u connection%s dropped by keepalive\n"); + p(tcps_ka_offload_drops, "\t\t%u connection%s dropped by keepalive offload\n"); p(tcps_predack, "\t%u correct ACK header prediction%s\n"); p(tcps_preddat, "\t%u correct data packet header prediction%s\n"); #ifdef TCP_MAX_SACK @@ -959,12 +942,12 @@ ip_stats(uint32_t off , char *name, int af ) if (sysctlbyname("net.inet.ip.output_perf_data", &out_net_perf, &out_net_perf_len, 0, 0) < 0) { warn("sysctl: net.inet.ip.output_perf_data"); - return; + bzero(&out_net_perf, out_net_perf_len); } if (sysctlbyname("net.inet.ip.input_perf_data", &in_net_perf, &in_net_perf_len, 0, 0) < 0) { warn("sysctl: net.inet.ip.input_perf_data"); - return; + bzero(&in_net_perf, in_net_perf_len); } if (interval && vflag > 0) @@ -1370,8 +1353,7 @@ inetname(struct in_addr *inp) if (inp->s_addr == INADDR_ANY) strlcpy(line, "*", sizeof(line)); else if (cp) { - strncpy(line, cp, sizeof(line) - 1); - line[sizeof(line) - 1] = '\0'; + strlcpy(line, cp, sizeof(line)); } else { inp->s_addr = ntohl(inp->s_addr); #define C(x) ((u_int)((x) & 0xff)) diff --git a/netstat.tproj/main.c b/netstat.tproj/main.c index 7a9d7d7..294e97f 100644 --- a/netstat.tproj/main.c +++ b/netstat.tproj/main.c @@ -204,7 +204,7 @@ int Fflag; /* show i/f forwarded packets */ int gflag; /* show group (multicast) routing or stats */ #endif int iflag; /* show interfaces */ -int lflag; /* show routing table with use and ref */ +int lflag; /* show routing table with more information */ int Lflag; /* show size of listen queues */ int mflag; /* show memory stats */ int nflag; /* show addresses numerically */ diff --git a/netstat.tproj/mcast.c b/netstat.tproj/mcast.c index 6ea18bf..3637f4d 100644 --- a/netstat.tproj/mcast.c +++ b/netstat.tproj/mcast.c @@ -251,7 +251,7 @@ ether_ntoa((struct ether_addr *)&psa->sdl.sdl_data); /* Interface upon which the membership exists */ psa = (sockunion_t *)ifma->ifma_name; if (psa != NULL && psa->sa.sa_family == AF_LINK) { - strlcpy(myifname, link_ntoa(&psa->sdl), IFNAMSIZ); + strlcpy(myifname, link_ntoa(&psa->sdl), sizeof(myifname)); pcolon = strchr(myifname, ':'); if (pcolon) *pcolon = '\0'; @@ -339,7 +339,7 @@ ifmalist_dump_mcstat(struct ifmaddrs *ifmap) if (af != 0 && pgsa->sa.sa_family != af) continue; - strlcpy(thisifname, link_ntoa(&psa->sdl), IFNAMSIZ); + strlcpy(thisifname, link_ntoa(&psa->sdl), sizeof(thisifname)); pcolon = strchr(thisifname, ':'); if (pcolon) *pcolon = '\0'; diff --git a/netstat.tproj/netstat.h b/netstat.tproj/netstat.h index c1641ac..0b9e6c3 100644 --- a/netstat.tproj/netstat.h +++ b/netstat.tproj/netstat.h @@ -72,9 +72,7 @@ extern int bflag; /* show i/f total bytes in/out */ extern int cflag; /* show specific classq */ extern int dflag; /* show i/f dropped packets */ extern int Fflag; /* show i/f forwarded packets */ -#if defined(__APPLE__) && !TARGET_OS_EMBEDDED extern int gflag; /* show group (multicast) routing or stats */ -#endif extern int iflag; /* show interfaces */ extern int lflag; /* show routing table with use and ref */ extern int Lflag; /* show size of listen queues */ diff --git a/netstat.tproj/route.c b/netstat.tproj/route.c index fceabf0..6f727ad 100644 --- a/netstat.tproj/route.c +++ b/netstat.tproj/route.c @@ -168,12 +168,15 @@ pr_family(int af) #ifndef INET6 #define WID_DST(af) 18 /* width of destination column */ #define WID_GW(af) 18 /* width of gateway column */ +#define WID_RT_IFA(af) 18 /* width of source column */ #define WID_IF(af) 7 /* width of netif column */ #else #define WID_DST(af) \ ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 39: 18)) : 18) #define WID_GW(af) \ ((af) == AF_INET6 ? (lflag ? 31 : (nflag ? 31 : 18)) : 18) +#define WID_RT_IFA(af) \ + ((af) == AF_INET6 ? (lflag ? 39 : (nflag ? 39 : 18)) : 18) #define WID_IF(af) ((af) == AF_INET6 ? 8 : 7) #endif /*INET6*/ @@ -183,44 +186,38 @@ pr_family(int af) void pr_rthdr(int af) { - - if (Aflag) - printf("%-8.8s ","Address"); - if (af == AF_INET || lflag) { + if (lflag) { if (lflag > 2) - printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s " - "%10s %10s %8s %8s %8s\n", - WID_DST(af), WID_DST(af), "Destination", - WID_GW(af), WID_GW(af), "Gateway", - "Flags", "Refs", "Use", "Mtu", - WID_IF(af), WID_IF(af), "Netif", "Expire", - "rtt(ns)", "rttvar(ns)", "recvpipe", "sendpipe", "ssthresh"); + printf("%-*.*s %-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s " + "%10s %10s %8s %8s %8s\n", + WID_DST(af), WID_DST(af), "Destination", + WID_GW(af), WID_GW(af), "Gateway", + WID_RT_IFA(af), WID_RT_IFA(af), "RT_IFA", + "Flags", "Refs", "Use", "Mtu", + WID_IF(af), WID_IF(af), "Netif", "Expire", + "rtt(ms)", "rttvar(ms)", "recvpipe", "sendpipe", "ssthresh"); else if (lflag > 1) - printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s " - "%10s %10s\n", - WID_DST(af), WID_DST(af), "Destination", - WID_GW(af), WID_GW(af), "Gateway", - "Flags", "Refs", "Use", "Mtu", - WID_IF(af), WID_IF(af), "Netif", "Expire", - "rtt(ns)", "rttvar(ns)"); - else if (lflag == 1) - printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s\n", + printf("%-*.*s %-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s " + "%10s %10s\n", WID_DST(af), WID_DST(af), "Destination", WID_GW(af), WID_GW(af), "Gateway", + WID_RT_IFA(af), WID_RT_IFA(af), "RT_IFA", "Flags", "Refs", "Use", "Mtu", - WID_IF(af), WID_IF(af), "Netif", "Expire"); + WID_IF(af), WID_IF(af), "Netif", "Expire", + "rtt(ms)", "rttvar(ms)"); else - printf("%-*.*s %-*.*s %-10.10s %6.6s %8.8s %*.*s %6s\n", + printf("%-*.*s %-*.*s %-*.*s %-10.10s %6.6s %8.8s %6.6s %*.*s %6s\n", WID_DST(af), WID_DST(af), "Destination", WID_GW(af), WID_GW(af), "Gateway", - "Flags", "Refs", "Use", + WID_RT_IFA(af), WID_RT_IFA(af), "RT_IFA", + "Flags", "Refs", "Use", "Mtu", WID_IF(af), WID_IF(af), "Netif", "Expire"); - } else { - printf("%-*.*s %-*.*s %-10.10s %8.8s %6s\n", + } else { + printf("%-*.*s %-*.*s %-10.10s %*.*s %6s\n", WID_DST(af), WID_DST(af), "Destination", WID_GW(af), WID_GW(af), "Gateway", - "Flags", "Netif", "Expire"); -} + "Flags", WID_IF(af), WID_IF(af), "Netif", "Expire"); + } } /* @@ -316,18 +313,22 @@ np_rtentry(struct rt_msghdr2 *rtm) p_sockaddr(rti_info[RTAX_GATEWAY], NULL, RTF_HOST, WID_GW(addr.u_sa.sa_family)); + + if (lflag && (rtm->rtm_addrs & RTA_IFA)) { + p_sockaddr(rti_info[RTAX_IFA], NULL, RTF_HOST, + WID_RT_IFA(addr.u_sa.sa_family)); + } p_flags(rtm->rtm_flags, "%-10.10s "); - if (addr.u_sa.sa_family == AF_INET || lflag) { + if (lflag) { printf("%6u %8u ", rtm->rtm_refcnt, (unsigned int)rtm->rtm_use); - if (lflag) { - if (rtm->rtm_rmx.rmx_mtu != 0) - printf("%6u ", rtm->rtm_rmx.rmx_mtu); - else - printf("%6s ", ""); - } + if (rtm->rtm_rmx.rmx_mtu != 0) + printf("%6u ", rtm->rtm_rmx.rmx_mtu); + else + printf("%6s ", ""); } + if (rtm->rtm_index != lastindex) { if_indextoname(rtm->rtm_index, ifname); lastindex = rtm->rtm_index; @@ -512,8 +513,7 @@ routename(uint32_t in) } } if (cp) { - strncpy(line, cp, sizeof(line) - 1); - line[sizeof(line) - 1] = '\0'; + strlcpy(line, cp, sizeof(line)); } else { #define C(x) ((x) & 0xff) in = ntohl(in); @@ -591,7 +591,7 @@ netname(uint32_t in, uint32_t mask) } } if (cp) - strncpy(line, cp, sizeof(line) - 1); + strlcpy(line, cp, sizeof(line)); else { switch (dmask) { case IN_CLASSA_NET: diff --git a/netstat.tproj/systm.c b/netstat.tproj/systm.c index dbb228f..3e076ca 100644 --- a/netstat.tproj/systm.c +++ b/netstat.tproj/systm.c @@ -367,7 +367,7 @@ kctl_stats(uint32_t off __unused, char *name, int af __unused) p(kcs_tbl_size_too_big, "\t%llu register failure%s because of too many kern_ctl_ref\n"); p(kcs_enqdata_mb_alloc_fail, "\t%llu enqueuedata failure%s because could not allocate a packet\n"); p(kcs_enqdata_sbappend_fail, "\t%llu enqueuedata failure%s due to full socket buffers\n"); - + #undef STATDIFF #undef p #undef p1a diff --git a/netstat.tproj/unix.c b/netstat.tproj/unix.c index 2c7b2ef..eece65a 100644 --- a/netstat.tproj/unix.c +++ b/netstat.tproj/unix.c @@ -79,7 +79,11 @@ #include #include "netstat.h" -#if !TARGET_OS_EMBEDDED +#ifdef __APPLE__ +#include +#endif + +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) static void unixdomainpr __P((struct xunpcb64 *, struct xsocket64 *)); #else static void unixdomainpr __P((struct xunpcb *, struct xsocket *)); @@ -95,7 +99,7 @@ unixpr() int type; size_t len; struct xunpgen *xug, *oxug; -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) struct xsocket64 *so; struct xunpcb64 *xunp; char mibvar[sizeof "net.local.seqpacket.pcblist64"]; @@ -106,7 +110,7 @@ unixpr() #endif for (type = SOCK_STREAM; type <= SOCK_RAW; type++) { -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) snprintf(mibvar, sizeof(mibvar), "net.local.%s.pcblist64", socktype[type]); #else snprintf(mibvar, sizeof(mibvar), "net.local.%s.pcblist", socktype[type]); @@ -131,7 +135,7 @@ unixpr() for (xug = (struct xunpgen *)((char *)xug + xug->xug_len); xug->xug_len > sizeof(struct xunpgen); xug = (struct xunpgen *)((char *)xug + xug->xug_len)) { -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) xunp = (struct xunpcb64 *)xug; #else xunp = (struct xunpcb *)xug; @@ -139,7 +143,7 @@ unixpr() so = &xunp->xu_socket; /* Ignore PCBs which were freed during copyout. */ -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (xunp->xunp_gencnt > oxug->xug_gen) #else if (xunp->xu_unp.unp_gencnt > oxug->xug_gen) @@ -165,7 +169,7 @@ unixpr() static void unixdomainpr(xunp, so) -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) struct xunpcb64 *xunp; struct xsocket64 *so; #else @@ -173,13 +177,13 @@ unixdomainpr(xunp, so) struct xsocket *so; #endif { -#if TARGET_OS_EMBEDDED +#if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) struct unpcb *unp; #endif struct sockaddr_un *sa; static int first = 1; -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) sa = &xunp->xu_addr; #else unp = &xunp->xu_unp; @@ -192,7 +196,7 @@ unixdomainpr(xunp, so) if (first) { printf("Active LOCAL (UNIX) domain sockets\n"); printf( -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) "%-16.16s %-6.6s %-6.6s %-6.6s %16.16s %16.16s %16.16s %16.16s Addr\n", #else "%-8.8s %-6.6s %-6.6s %-6.6s %8.8s %8.8s %8.8s %8.8s Addr\n", @@ -201,7 +205,7 @@ unixdomainpr(xunp, so) "Inode", "Conn", "Refs", "Nextref"); first = 0; } -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) printf("%16lx %-6.6s %6u %6u %16lx %16lx %16lx %16lx", (long)xunp->xu_unpp, socktype[so->so_type], so->so_rcv.sb_cc, so->so_snd.sb_cc, @@ -215,7 +219,7 @@ unixdomainpr(xunp, so) (long)unp->unp_refs.lh_first, (long)unp->unp_reflink.le_next); #endif -#if !TARGET_OS_EMBEDDED +#if !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) if (sa->sun_len) #else if (sa) diff --git a/network_cmds.xcodeproj/project.pbxproj b/network_cmds.xcodeproj/project.pbxproj index 710cd11..17a6ae5 100755 --- a/network_cmds.xcodeproj/project.pbxproj +++ b/network_cmds.xcodeproj/project.pbxproj @@ -286,6 +286,7 @@ 72B732DF1899B0380060E6D4 /* cfilutil.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 72B732DE1899B0380060E6D4 /* cfilutil.1 */; }; 72B732EF1899B23A0060E6D4 /* cfilutil.c in Sources */ = {isa = PBXBuildFile; fileRef = 72B732EE1899B23A0060E6D4 /* cfilutil.c */; }; 72B732F11899B2430060E6D4 /* cfilstat.c in Sources */ = {isa = PBXBuildFile; fileRef = 72B732F01899B2430060E6D4 /* cfilstat.c */; }; + 72B7F36B1BA69352003A9AA2 /* if6lowpan.c in Sources */ = {isa = PBXBuildFile; fileRef = 72B7F36A1BA69281003A9AA2 /* if6lowpan.c */; }; 72B894EC0EEDB17C00C218D6 /* libipsec.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72CD1DB50EE8C619005F825D /* libipsec.dylib */; }; 72D000C4142BB11100151981 /* dnctl.c in Sources */ = {isa = PBXBuildFile; fileRef = 72D000C3142BB11100151981 /* dnctl.c */; }; 72D33F572271319400EF5B5E /* rtadvd_logging.c in Sources */ = {isa = PBXBuildFile; fileRef = 72D33F562271220100EF5B5E /* rtadvd_logging.c */; }; @@ -1390,6 +1391,7 @@ 72B732DE1899B0380060E6D4 /* cfilutil.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = cfilutil.1; sourceTree = ""; }; 72B732EE1899B23A0060E6D4 /* cfilutil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cfilutil.c; sourceTree = ""; }; 72B732F01899B2430060E6D4 /* cfilstat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cfilstat.c; sourceTree = ""; }; + 72B7F36A1BA69281003A9AA2 /* if6lowpan.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = if6lowpan.c; sourceTree = ""; }; 72CD1DB50EE8C619005F825D /* libipsec.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libipsec.dylib; path = /usr/lib/libipsec.dylib; sourceTree = ""; }; 72D000C3142BB11100151981 /* dnctl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dnctl.c; sourceTree = ""; }; 72D33F552271220100EF5B5E /* rtadvd_logging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rtadvd_logging.h; sourceTree = ""; }; @@ -1971,6 +1973,7 @@ 726120540EE86F0900AFED1B /* ifconfig.tproj */ = { isa = PBXGroup; children = ( + 72B7F36A1BA69281003A9AA2 /* if6lowpan.c */, 72E650A2107BF2F000AAF325 /* af_inet.c */, 72E650A3107BF2F000AAF325 /* af_inet6.c */, 72E650A4107BF2F000AAF325 /* af_link.c */, @@ -3244,6 +3247,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 72B7F36B1BA69352003A9AA2 /* if6lowpan.c in Sources */, 7261215A0EE8883900AFED1B /* ifbond.c in Sources */, 7261215B0EE8883900AFED1B /* ifconfig.c in Sources */, 7261215C0EE8883900AFED1B /* ifmedia.c in Sources */, @@ -3651,10 +3655,6 @@ "__APPLE_USE_RFC_3542=1", "__APPLE_API_OBSOLETE=1", ); - "GCC_PREPROCESSOR_DEFINITIONS[sdk=iphoneos*][arch=*]" = ( - "$(inherited)", - "TARGET_OS_EMBEDDED=1", - ); GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; PREBINDING = NO; @@ -4682,10 +4682,6 @@ "__APPLE_USE_RFC_3542=1", "__APPLE_API_OBSOLETE=1", ); - "GCC_PREPROCESSOR_DEFINITIONS[sdk=iphoneos*][arch=*]" = ( - "$(inherited)", - "TARGET_OS_EMBEDDED=1", - ); GCC_TREAT_WARNINGS_AS_ERRORS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; PREBINDING = NO; @@ -4711,10 +4707,6 @@ "__APPLE_USE_RFC_3542=1", "__APPLE_API_OBSOLETE=1", ); - "GCC_PREPROCESSOR_DEFINITIONS[sdk=iphoneos*][arch=*]" = ( - "$(inherited)", - "TARGET_OS_EMBEDDED=1", - ); GCC_TREAT_WARNINGS_AS_ERRORS = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = NO; PREBINDING = NO; @@ -5169,10 +5161,6 @@ COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; - "GCC_PREPROCESSOR_DEFINITIONS[sdk=yola4.0.internal][arch=*]" = ( - "$(inherited)", - "TARGET_OS_EMBEDDED=1", - ); PRODUCT_NAME = "All-EmbeddedOther"; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; diff --git a/ping.tproj/ping.c b/ping.tproj/ping.c index ad5ea7a..58e7f80 100644 --- a/ping.tproj/ping.c +++ b/ping.tproj/ping.c @@ -654,9 +654,8 @@ main(int argc, char *const *argv) errx(1, "gethostbyname2: illegal address"); memcpy(&sock_in.sin_addr, hp->h_addr_list[0], sizeof(sock_in.sin_addr)); - (void)strncpy(snamebuf, hp->h_name, - sizeof(snamebuf) - 1); - snamebuf[sizeof(snamebuf) - 1] = '\0'; + (void)strlcpy(snamebuf, hp->h_name, + sizeof(snamebuf)); shostname = snamebuf; } if (bind(s, (struct sockaddr *)&sock_in, sizeof sock_in) == -1) @@ -682,8 +681,7 @@ main(int argc, char *const *argv) if ((unsigned)hp->h_length > sizeof(to->sin_addr)) errx(1, "gethostbyname2 returned an illegal address"); memcpy(&to->sin_addr, hp->h_addr_list[0], sizeof to->sin_addr); - (void)strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1); - hnamebuf[sizeof(hnamebuf) - 1] = '\0'; + (void)strlcpy(hnamebuf, hp->h_name, sizeof(hnamebuf)); hostname = hnamebuf; } diff --git a/ping6.tproj/ping6.c b/ping6.tproj/ping6.c index f4d2411..7890e66 100644 --- a/ping6.tproj/ping6.c +++ b/ping6.tproj/ping6.c @@ -230,7 +230,6 @@ static const struct option longopts[] = { { NULL, 0, NULL, 0 } }; - #define IN6LEN sizeof(struct in6_addr) #define SA6LEN sizeof(struct sockaddr_in6) #define DUMMY_PORT 10101 @@ -575,7 +574,7 @@ main(int argc, char *argv[]) t = strtod(optarg, &e); if (*optarg == '\0' || *e != '\0') errx(1, "illegal timing interval %s", optarg); - if (t < 1 && getuid()) { + if (t < 0.1 && getuid()) { errx(1, "%s: only root may use interval < 1s", strerror(EPERM)); } @@ -2673,7 +2672,6 @@ static const char *nircode[] = { "Success", "Refused", "Unknown", }; - /* * pr_icmph -- * Print a descriptive string about an ICMP header. @@ -3108,7 +3106,7 @@ nigroup(char *name, int nig_oldmcprefix) l = p - name; if (l > 63 || l > sizeof(hbuf) - 1) return NULL; /*label too long*/ - strncpy(hbuf, name, l); + strlcpy(hbuf, name, l); hbuf[(int)l] = '\0'; for (q = name; *q; q++) { diff --git a/pktmnglr/packet_mangler.c b/pktmnglr/packet_mangler.c index 8a5b0f1..cf94cd4 100644 --- a/pktmnglr/packet_mangler.c +++ b/pktmnglr/packet_mangler.c @@ -248,7 +248,7 @@ doit() { struct ctl_info info; memset(&info, 0, sizeof(info)); - strncpy(info.ctl_name, PACKET_MANGLER_CONTROL_NAME, sizeof(info.ctl_name)); + strlcpy(info.ctl_name, PACKET_MANGLER_CONTROL_NAME, sizeof(info.ctl_name)); if (ioctl(sf, CTLIOCGINFO, &info)) { perror("Could not get ID for kernel control.\n"); exit(-1); diff --git a/rarpd.tproj/rarpd.c b/rarpd.tproj/rarpd.c index 6c42b6c..1a3ae51 100644 --- a/rarpd.tproj/rarpd.c +++ b/rarpd.tproj/rarpd.c @@ -328,7 +328,7 @@ rarp_open(device) err(FATAL, "BIOCIMMEDIATE: %s", strerror(errno)); /* NOTREACHED */ } - (void) strncpy(ifr.ifr_name, device, sizeof ifr.ifr_name); + (void) strlcpy(ifr.ifr_name, device, sizeof ifr.ifr_name); if (ioctl(fd, BIOCSETIF, (caddr_t) & ifr) < 0) { err(FATAL, "BIOCSETIF: %s", strerror(errno)); /* NOTREACHED */ @@ -632,7 +632,7 @@ lookup_ipaddr(ifname, addrp, netmaskp) err(FATAL, "socket: %s", strerror(errno)); /* NOTREACHED */ } - (void) strncpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name); + (void) strlcpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name); if (ioctl(fd, SIOCGIFADDR, (char *) &ifr) < 0) { err(FATAL, "SIOCGIFADDR: %s", strerror(errno)); /* NOTREACHED */ diff --git a/route.tproj/route.c b/route.tproj/route.c index 69ee7e1..9f7f4bd 100644 --- a/route.tproj/route.c +++ b/route.tproj/route.c @@ -352,8 +352,7 @@ routename(sa) } } if (cp) { - strncpy(line, cp, sizeof(line) - 1); - line[sizeof(line) - 1] = '\0'; + strlcpy(line, cp, sizeof(line)); } else { /* XXX - why not inet_ntoa()? */ #define C(x) (unsigned)((x) & 0xff) @@ -393,7 +392,7 @@ routename(sa) niflags |= NI_NUMERICHOST; if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, line, sizeof(line), NULL, 0, niflags) != 0) - strncpy(line, "invalid", sizeof(line)); + strlcpy(line, "invalid", sizeof(line)); return(line); } @@ -445,7 +444,7 @@ netname(sa) } #define C(x) (unsigned)((x) & 0xff) if (cp != NULL) - strncpy(line, cp, sizeof(line)); + strlcpy(line, cp, sizeof(line)); else if ((in.s_addr & 0xffffff) == 0) (void) sprintf(line, "%u", C(in.s_addr >> 24)); else if ((in.s_addr & 0xffff) == 0) @@ -490,7 +489,7 @@ netname(sa) niflags |= NI_NUMERICHOST; if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, line, sizeof(line), NULL, 0, niflags) != 0) - strncpy(line, "invalid", sizeof(line)); + strlcpy(line, "invalid", sizeof(line)); return(line); } diff --git a/rtadvd.tproj/advcap.c b/rtadvd.tproj/advcap.c index 061230c..33b6fae 100644 --- a/rtadvd.tproj/advcap.c +++ b/rtadvd.tproj/advcap.c @@ -187,9 +187,9 @@ getent(bp, name, cp) } break; } - if (cp >= bp + BUFSIZ) { + if (cp >= bp + BUFSIZ - 1) { write(STDERR_FILENO, "Remcap entry too long\n", - 23); + 22); break; } else *cp++ = c; diff --git a/rtadvd.tproj/config.c b/rtadvd.tproj/config.c index 8ad5cf0..42c50ac 100644 --- a/rtadvd.tproj/config.c +++ b/rtadvd.tproj/config.c @@ -424,7 +424,7 @@ getconfig(intface) exit(1); } memset(&ndi, 0, sizeof(ndi)); - strncpy(ndi.ifname, intface, IFNAMSIZ); + strlcpy(ndi.ifname, intface, sizeof(ndi.ifname)); if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&ndi) < 0) { infolog("<%s> ioctl:SIOCGIFINFO_IN6 at %s: %s", __func__, intface, strerror(errno)); @@ -840,9 +840,9 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr) prefix->onlinkflg = ipr->ipr_raf_onlink; prefix->autoconfflg = ipr->ipr_raf_auto; prefix->origin = PREFIX_FROM_DYNAMIC; + prefix->rainfo = rai; insque(prefix, &rai->prefix); - prefix->rainfo = rai; debuglog("<%s> new prefix %s/%d was added on %s", __func__, inet_ntop(AF_INET6, &ipr->ipr_prefix.sin6_addr, diff --git a/rtadvd.tproj/if.c b/rtadvd.tproj/if.c index 082714c..9862af2 100644 --- a/rtadvd.tproj/if.c +++ b/rtadvd.tproj/if.c @@ -163,7 +163,7 @@ if_getmtu(char *name) return(0); ifr.ifr_addr.sa_family = AF_INET6; - strncpy(ifr.ifr_name, name, + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCGIFMTU, (caddr_t)&ifr) < 0) { close(s); diff --git a/rtsol.tproj/if.c b/rtsol.tproj/if.c index 79da223..b46c781 100644 --- a/rtsol.tproj/if.c +++ b/rtsol.tproj/if.c @@ -126,7 +126,7 @@ interface_up(char *name) struct ifreq ifr; int llflag; - strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); if (ioctl(ifsock, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) { warnmsg(LOG_WARNING, __FUNCTION__, "ioctl(SIOCGIFFLAGS): %s", @@ -182,7 +182,7 @@ interface_status(struct ifinfo *ifinfo) /* get interface flags */ memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) { warnmsg(LOG_ERR, __FUNCTION__, "ioctl(SIOCGIFFLAGS) on %s: %s", ifname, strerror(errno)); @@ -200,7 +200,7 @@ interface_status(struct ifinfo *ifinfo) if (!ifinfo->mediareqok) goto active; memset(&ifmr, 0, sizeof(ifmr)); - strncpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name)); + strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name)); if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) { if (errno != EINVAL) { diff --git a/rtsol.tproj/rtsold.c b/rtsol.tproj/rtsold.c index 6ccc84d..68923ec 100644 --- a/rtsol.tproj/rtsold.c +++ b/rtsol.tproj/rtsold.c @@ -344,7 +344,7 @@ ifconfig(char *ifname) memset(ifinfo, 0, sizeof(*ifinfo)); ifinfo->sdl = sdl; - strncpy(ifinfo->ifname, ifname, sizeof(ifinfo->ifname)); + strlcpy(ifinfo->ifname, ifname, sizeof(ifinfo->ifname)); /* construct a router solicitation message */ if (make_packet(ifinfo)) @@ -775,8 +775,7 @@ autoifprobe() } if (target) { - strncpy(ifname, target->ifa_name, sizeof(ifname) - 1); - ifname[sizeof(ifname) - 1] = '\0'; + strlcpy(ifname, target->ifa_name, sizeof(ifname)); argv[0] = ifname; argv[1] = NULL; diff --git a/traceroute.tproj/ifaddrlist.c b/traceroute.tproj/ifaddrlist.c index 2d19c78..17b1026 100644 --- a/traceroute.tproj/ifaddrlist.c +++ b/traceroute.tproj/ifaddrlist.c @@ -154,7 +154,7 @@ ifaddrlist(register struct ifaddrlist **ipaddrp, register char *errbuf, size_t e * SIOCGIFFLAGS stomps over it because the requests * are returned in a union.) */ - strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr) < 0) { if (errno == ENXIO) continue; @@ -170,8 +170,7 @@ ifaddrlist(register struct ifaddrlist **ipaddrp, register char *errbuf, size_t e continue; - (void)strncpy(device, ifr.ifr_name, sizeof(ifr.ifr_name)); - device[sizeof(device) - 1] = '\0'; + (void)strlcpy(device, ifr.ifr_name, sizeof(device)); #ifdef sun /* Ignore sun virtual interfaces */ if (strchr(device, ':') != NULL) diff --git a/traceroute.tproj/traceroute.c b/traceroute.tproj/traceroute.c index eff6cec..a411d0a 100644 --- a/traceroute.tproj/traceroute.c +++ b/traceroute.tproj/traceroute.c @@ -1621,8 +1621,7 @@ inetname(struct in_addr in) domain[0] = '\0'; else { ++cp; - (void)strncpy(domain, cp, sizeof(domain) - 1); - domain[sizeof(domain) - 1] = '\0'; + memmove(domain, cp, strlen(cp) + 1); } } } @@ -1632,8 +1631,7 @@ inetname(struct in_addr in) if ((cp = strchr(hp->h_name, '.')) != NULL && strcmp(cp + 1, domain) == 0) *cp = '\0'; - (void)strncpy(line, hp->h_name, sizeof(line) - 1); - line[sizeof(line) - 1] = '\0'; + (void)strlcpy(line, hp->h_name, sizeof(line)); return (line); } } diff --git a/unbound/util/tube.c b/unbound/util/tube.c index 2106a07..b048be0 100644 --- a/unbound/util/tube.c +++ b/unbound/util/tube.c @@ -38,6 +38,7 @@ * * This file contains pipe service functions. */ +#include #include "config.h" #include "util/tube.h" #include "util/log.h" diff --git a/unbound/winrc/gen_msg.bin b/unbound/winrc/gen_msg.bin deleted file mode 100644 index 6e560057c26813430527e8906f6388206e0c7e82..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 116 zcmZQ!U|?WmU{nBM6Cj(3fiVGuU4U$62F3*-90FvsFfcv<;S?ZS0H{Ni!H|KMfeXkZ Goeu!`+XqPi -- 2.45.2