From nobody Tue May 14 06:52:20 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Vdn9108plz5KYBs; Tue, 14 May 2024 06:52:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vdn904qhCz4nRL; Tue, 14 May 2024 06:52:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715669540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Ulg/yX1ptCor4pJIsMAXU/6b/sER5hiEJWdqFM8Ym8E=; b=Sg/SMsBwGxJSW0iCe6NJYb+42lM4h/cScTUEBFkBbZGPPZf6GK9l4BrZVnbBibawyXQCnq fLigcnBDRwClDu62jONvbWPie3bMs969yUo1ZbCDotdcpf4zXcKwnZDAILJNuXy/C0OzMu pVglFjkVhrWlDDpKtS38g4NI1pvNoXq4WbLTECsX5Z0z2EC8ETHDewj0W+v4qyoPM2Mh27 vApF7hzeVn3ROh3MIJ7N3R+OYP0eishV4S6z1g3Avf5C/tF9TuK4x8krn/5KwgUebO44RF 835a5K1UfvxrZf4S4soVBnxGW35lpg1Ibwr49pdH/+ur89cK931Q27Nc+uw0/A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715669540; a=rsa-sha256; cv=none; b=jJ3ZGH5gAy8124Oo6IYl4sbMh3irno5NKhio3Dwsyjo+4AjoZRvcOpj8/xWs/WFkv9YZby F8JXsarr2DJDrD5XFRfjfF9Kbl0mj0yKnMHLsra8PzMB1sHQj7AC230X8yYQM/BrFnzvfB TBhTYr+VUtmY1gTnjrt+0Cj87U24DD0XbwcLUSllvQihftj/86y5KcVjRgW3n6t6zqM5s0 tyiIxLcfNcobMBTT8jtV94Pmb+U9G/k1i/LmtXCaw3w8pPLIvN3tFFKfk1qfV5wYIVcFIa M0qf21dH/Ybp+gCM8UpJB3XEdl/y7V9Nl7UHK6xhynaRRwj0a/cRQp9p4vHVEg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715669540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Ulg/yX1ptCor4pJIsMAXU/6b/sER5hiEJWdqFM8Ym8E=; b=qjluY5RqdS9OvMfEB2kfcCOkEAcjmaaghYwGuNiFb/2A4di8pDrtLfx4mNxYOZjeo9xoOo jbON2DV6x/5YqZChMKNb7gTR1qObQzBOi5cGZK6Ke8a6+XUEs16KVCn/nW9YBkerSpAjMX LpcQDR/WwSVj5/Gc+bWt6TnOm0X7QQ4xrrimI7zi5+zxP0pl0ZWr+Jivp5kg7AElDwZ05G 7Mdc077D5MjG0M626Mqg3lyZMQl4B7RkClbpLMeEJtJCGk9UnEbxcAItpaQVTaYLR1XBNx bhPW99XqMM8NMl8bNk6k5wWNnW0KXjDOfmk0a1Q3FKeKBm3nxg0+ZLSBfx5m+w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Vdn904PrLzMGs; Tue, 14 May 2024 06:52:20 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44E6qKXG002573; Tue, 14 May 2024 06:52:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44E6qK5I002569; Tue, 14 May 2024 06:52:20 GMT (envelope-from git) Date: Tue, 14 May 2024 06:52:20 GMT Message-Id: <202405140652.44E6qK5I002569@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 847ef59d4b5e - main - ifconfig: Add format shortcuts. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 847ef59d4b5eab234bd1f8eb947ad74bdab5614e Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=847ef59d4b5eab234bd1f8eb947ad74bdab5614e commit 847ef59d4b5eab234bd1f8eb947ad74bdab5614e Author: Dag-Erling Smørgrav AuthorDate: 2024-05-14 06:51:42 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-05-14 06:51:50 +0000 ifconfig: Add format shortcuts. MFC after: 1 week Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D45166 --- sbin/ifconfig/ifconfig.8 | 14 ++++++++++++-- sbin/ifconfig/ifconfig.c | 42 +++++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index 99a4cf8c9751..72f4883a9e26 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -25,7 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd May 1, 2024 +.Dd May 12, 2024 .Dt IFCONFIG 8 .Os .Sh NAME @@ -135,7 +135,7 @@ and their associated .Ar format strings are: .Pp -.Bl -tag -width ether +.Bl -tag -width default .It Cm addr Adjust the display of inet and inet6 addresses: .Pp @@ -200,6 +200,16 @@ Integer format, for example: .Ql prefixlen 64 .El .El +.Pp +In addition, the following shortcuts are accepted: +.Bl -tag -width default +.It Cm default +Resets all formats to their default values. +.It Cm cidr +Shortcut notation for +.Cm inet:cidr,inet6:cidr . +.El +.Pp .It Fl G Ar groupname Exclude members of the specified .Ar groupname diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 2cbe7a881bd0..a8bd5a0c89db 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -313,14 +313,10 @@ cmpifaddrs(struct ifaddrs *a, struct ifaddrs *b, struct ifa_queue *q) static void freeformat(void) { - if (f_inet != NULL) - free(f_inet); - if (f_inet6 != NULL) - free(f_inet6); - if (f_ether != NULL) - free(f_ether); - if (f_addr != NULL) - free(f_addr); + free(f_inet); + free(f_inet6); + free(f_ether); + free(f_addr); } static void setformat(char *input) @@ -330,9 +326,18 @@ static void setformat(char *input) formatstr = strdup(input); while ((category = strsep(&formatstr, ",")) != NULL) { modifier = strchr(category, ':'); - if (modifier == NULL || modifier[1] == '\0') { - warnx("Skipping invalid format specification: %s\n", - category); + if (modifier == NULL) { + if (strcmp(category, "default") == 0) { + freeformat(); + } else if (strcmp(category, "cidr") == 0) { + free(f_inet); + f_inet = strdup(category); + free(f_inet6); + f_inet6 = strdup(category); + } else { + warnx("Skipping invalid format: %s\n", + category); + } continue; } @@ -340,14 +345,19 @@ static void setformat(char *input) modifier[0] = '\0'; modifier++; - if (strcmp(category, "addr") == 0) + if (strcmp(category, "addr") == 0) { + free(f_addr); f_addr = strdup(modifier); - else if (strcmp(category, "ether") == 0) + } else if (strcmp(category, "ether") == 0) { + free(f_ether); f_ether = strdup(modifier); - else if (strcmp(category, "inet") == 0) + } else if (strcmp(category, "inet") == 0) { + free(f_inet); f_inet = strdup(modifier); - else if (strcmp(category, "inet6") == 0) + } else if (strcmp(category, "inet6") == 0) { + free(f_inet6); f_inet6 = strdup(modifier); + } } free(formatstr); } @@ -612,8 +622,6 @@ main(int ac, char *av[]) .io_s = -1, }; - f_inet = f_inet6 = f_ether = f_addr = NULL; - lifh = ifconfig_open(); if (lifh == NULL) err(EXIT_FAILURE, "ifconfig_open");