From owner-svn-src-head@freebsd.org Thu Jun 2 03:16:04 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 78CEBB66C0F; Thu, 2 Jun 2016 03:16:04 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3A48C1896; Thu, 2 Jun 2016 03:16:04 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u523G3s7071338; Thu, 2 Jun 2016 03:16:03 GMT (envelope-from allanjude@FreeBSD.org) Received: (from allanjude@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u523G2Pg071333; Thu, 2 Jun 2016 03:16:02 GMT (envelope-from allanjude@FreeBSD.org) Message-Id: <201606020316.u523G2Pg071333@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: allanjude set sender to allanjude@FreeBSD.org using -f From: Allan Jude Date: Thu, 2 Jun 2016 03:16:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r301185 - head/sbin/ifconfig X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Jun 2016 03:16:04 -0000 Author: allanjude Date: Thu Jun 2 03:16:02 2016 New Revision: 301185 URL: https://svnweb.freebsd.org/changeset/base/301185 Log: Address feedback from hrs@ re: r301059 (ifconfig subnet mask) - Use NI_MAXHOST to size buffers for getnameinfo() - remove non-standard 'full' inet6 address printing - remove 'no scope' option - use strchr(3) to optimize replacing separator character in lladdrs Reviewed by: gnn, jhb Differential Revision: https://reviews.freebsd.org/D2856 Modified: head/sbin/ifconfig/af_inet.c head/sbin/ifconfig/af_inet6.c head/sbin/ifconfig/af_link.c head/sbin/ifconfig/ifconfig.8 head/sbin/ifconfig/ifconfig.c Modified: head/sbin/ifconfig/af_inet.c ============================================================================== --- head/sbin/ifconfig/af_inet.c Thu Jun 2 02:39:40 2016 (r301184) +++ head/sbin/ifconfig/af_inet.c Thu Jun 2 03:16:02 2016 (r301185) @@ -54,7 +54,7 @@ static const char rcsid[] = static struct in_aliasreq in_addreq; static struct ifreq in_ridreq; -static char addr_buf[MAXHOSTNAMELEN *2 + 1]; /*for getnameinfo()*/ +static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/ extern char *f_inet, *f_addr; static void Modified: head/sbin/ifconfig/af_inet6.c ============================================================================== --- head/sbin/ifconfig/af_inet6.c Thu Jun 2 02:39:40 2016 (r301184) +++ head/sbin/ifconfig/af_inet6.c Thu Jun 2 03:16:02 2016 (r301185) @@ -65,13 +65,13 @@ static int ip6lifetime; static int prefix(void *, int); static char *sec2str(time_t); static int explicit_prefix = 0; -extern char *f_inet6, *f_addr, *f_scope; +extern char *f_inet6, *f_addr; extern void setnd6flags(const char *, int, int, const struct afswtch *); extern void setnd6defif(const char *, int, int, const struct afswtch *); extern void nd6_status(int); -static char addr_buf[MAXHOSTNAMELEN *2 + 1]; /*for getnameinfo()*/ +static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/ static void setifprefixlen(const char *addr, int dummy __unused, int s, @@ -173,10 +173,9 @@ in6_status(int s __unused, const struct struct in6_ifreq ifr6; int s6; u_int32_t flags6; - const u_int16_t *a; struct in6_addrlifetime lifetime; struct timespec now; - int error, n_flags, i; + int error, n_flags; clock_gettime(CLOCK_MONOTONIC_FAST, &now); @@ -208,30 +207,19 @@ in6_status(int s __unused, const struct lifetime = ifr6.ifr_ifru.ifru_lifetime; close(s6); - if (f_addr != NULL && strcmp(f_addr, "full") == 0) { - a = (const u_int16_t *)&sin->sin6_addr; - printf("\tinet6 "); - for (i = 0; i < 8; i++) { - printf("%04hx", ntohs(*(a + i))); - if (i < 7) - printf(":"); - } - } else { - if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0) - n_flags = 0; - else if (f_addr != NULL && strcmp(f_addr, "host") == 0) - n_flags = NI_NOFQDN; - else - n_flags = NI_NUMERICHOST; - error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, - addr_buf, sizeof(addr_buf), NULL, 0, - n_flags); - if (error != 0 || - (f_scope != NULL && strcmp(f_scope, "none") == 0)) - inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, - sizeof(addr_buf)); - printf("\tinet6 %s", addr_buf); - } + if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0) + n_flags = 0; + else if (f_addr != NULL && strcmp(f_addr, "host") == 0) + n_flags = NI_NOFQDN; + else + n_flags = NI_NUMERICHOST; + error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, + addr_buf, sizeof(addr_buf), NULL, 0, + n_flags); + if (error != 0) + inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, + sizeof(addr_buf)); + printf("\tinet6 %s", addr_buf); if (ifa->ifa_flags & IFF_POINTOPOINT) { sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr; @@ -280,8 +268,7 @@ in6_status(int s __unused, const struct if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0) printf("prefer_source "); - if ((f_scope == NULL || strcmp(f_scope, "none") != 0) && - ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) + if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) printf("scopeid 0x%x ", ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); Modified: head/sbin/ifconfig/af_link.c ============================================================================== --- head/sbin/ifconfig/af_link.c Thu Jun 2 02:39:40 2016 (r301184) +++ head/sbin/ifconfig/af_link.c Thu Jun 2 03:16:02 2016 (r301185) @@ -58,25 +58,22 @@ link_status(int s __unused, const struct { /* XXX no const 'cuz LLADDR is defined wrong */ struct sockaddr_dl *sdl = (struct sockaddr_dl *) ifa->ifa_addr; - char *ether_format; - int i; + char *ether_format, *format_char; if (sdl != NULL && sdl->sdl_alen > 0) { if ((sdl->sdl_type == IFT_ETHER || sdl->sdl_type == IFT_L2VLAN || sdl->sdl_type == IFT_BRIDGE) && - sdl->sdl_alen == ETHER_ADDR_LEN) + sdl->sdl_alen == ETHER_ADDR_LEN) { + ether_format = ether_ntoa((struct ether_addr *)LLADDR(sdl)); if (f_ether != NULL && strcmp(f_ether, "dash") == 0) { - ether_format = ether_ntoa((struct ether_addr *)LLADDR(sdl)); - for (i = 0; i < strlen(ether_format); i++) { - if (ether_format[i] == ':') - ether_format[i] = '-'; - } - printf("\tether %s\n", ether_format); - } else - printf("\tether %s\n", - ether_ntoa((struct ether_addr *)LLADDR(sdl))); - else { + for (format_char = strchr(ether_format, ':'); + format_char != NULL; + format_char = strchr(ether_format, ':')) + *format_char = '-'; + } + printf("\tether %s\n", ether_format); + } else { int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0; printf("\tlladdr %s\n", link_ntoa(sdl) + n); Modified: head/sbin/ifconfig/ifconfig.8 ============================================================================== --- head/sbin/ifconfig/ifconfig.8 Thu Jun 2 02:39:40 2016 (r301184) +++ head/sbin/ifconfig/ifconfig.8 Thu Jun 2 03:16:02 2016 (r301185) @@ -213,7 +213,7 @@ The and their associated .Sy format strings are: -.Bl -tag -width scope +.Bl -tag -width ether .It Sy addr Adjust the display of inet and inet6 addresses .Bl -tag -width default @@ -223,9 +223,6 @@ Display inet and inet6 addresses in the .It Sy fqdn Display inet and inet6 addresses as fully qualified domain names .Pq FQDN -.It Sy full -Display inet6 addresses without suppressing zeroes. -Only applicable to inet6 .It Sy host Display inet and inet6 addresses as unqualified hostnames .It Sy numeric @@ -276,19 +273,6 @@ Display subnet prefix in integer format, .br prefixlen 64 .El -.It Sy scope -Controls the display of the interface scope as part of the address. -Only applicable to inet6 addresses. -.Bl -tag -width default -.It Sy default -The interface scope and scopeid are included in the address, for example: -.br -inet6 fe80::1%lo0 prefixlen 64 scopeid 0x7 -.It Sy none -The interface scope and scopeid are not displayed, for example: -.br -inet6 fe80::1 prefixlen 64 -.El .El .Pp The following parameters may be set with Modified: head/sbin/ifconfig/ifconfig.c ============================================================================== --- head/sbin/ifconfig/ifconfig.c Thu Jun 2 02:39:40 2016 (r301184) +++ head/sbin/ifconfig/ifconfig.c Thu Jun 2 03:16:02 2016 (r301185) @@ -99,7 +99,7 @@ int supmedia = 0; int printkeys = 0; /* Print keying material for interfaces. */ /* Formatter Strings */ -char *f_inet, *f_inet6, *f_ether, *f_addr, *f_scope; +char *f_inet, *f_inet6, *f_ether, *f_addr; static int ifconfig(int argc, char *const *argv, int iscreate, const struct afswtch *afp); @@ -257,8 +257,6 @@ static void freeformat(void) free(f_ether); if (f_addr != NULL) free(f_addr); - if (f_scope != NULL) - free(f_scope); } static void setformat(char *input) @@ -286,8 +284,6 @@ static void setformat(char *input) f_inet = strdup(modifier); else if (strcmp(category, "inet6") == 0) f_inet6 = strdup(modifier); - else if (strcmp(category, "scope") == 0) - f_scope = strdup(modifier); } free(formatstr); } @@ -372,7 +368,7 @@ main(int argc, char *argv[]) size_t iflen; all = downonly = uponly = namesonly = noload = verbose = 0; - f_inet = f_inet6 = f_ether = f_addr = f_scope = NULL; + f_inet = f_inet6 = f_ether = f_addr = NULL; envformat = getenv("IFCONFIG_FORMAT"); if (envformat != NULL)