From nobody Mon May 20 09:35:04 2024 X-Original-To: dev-commits-src-all@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 4VjXV05QXGz5KZVw; Mon, 20 May 2024 09:35:04 +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 4VjXV04lcyz4t4M; Mon, 20 May 2024 09:35:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716197704; 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=0Uz7lnOXG481NMh4ETQqmgh930TDZkoYSbUlZyWnf50=; b=r4Fofp+WCnJbHl/YLR5S233vI5dVYMhqjIzZmlIQl8fx1onl8r6QXSNtzPm7K+hGZ75PJj tfQ0b7DX/cuNrXslgJsaQYkwk93US3iG2Omaw5p/DhtVr+r2qK3JtcCrfpC+FKBH0aAzqq 4Z8fTVpxhEBu81HgFrLI4z6LQgf23RMXmbcf/7jEVtCjcI9YBf092EsUFbtXLAq08g2I44 5ZZA7ze/sW8SIxjOwCvBlnVWJlZ9nZEJvgQ9US8nBlJXqgcjz6U/XIQy2AMOTmQa+kVsDU u8AjCfcMMzZwbXAwA5apWnd7z2eg1tWnszTjpoDP+3Cu+08vumzmH+XNEhUrUw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716197704; a=rsa-sha256; cv=none; b=MKfDDkERFrmyOYgk/tgPRmepEmmubuhwfTpWooVpi9ER4ozfCmnuu0Q9LQle6g9huTMczB UMQOjNzekqUNBSqtB7XxHLqheaXqWMw/cCB/A3seqXw2DJviYMvnwuLtyNtTEGr3dy6kpQ HmXLhuF+Rd3rUek9VyvJKZv25ZA0A/fuDnwxHvX4Q2DBpH6jStZBAosMfHyKV6ibf0/xry Xl9ZLXJMSy6bl8AR/vRNEqvOEdlFk6FOtXYn+w3ibYNIo0rvCUfDdAxMHYRyjeNQRVRcMJ 4YealxbGlPj8y/UBkJy9bhIoViJchaz/P/RevLcT7dRUhrAzAdjTuia/x7T0RQ== 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=1716197704; 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=0Uz7lnOXG481NMh4ETQqmgh930TDZkoYSbUlZyWnf50=; b=UfxuTZjXPNudRa2luDLy3NGeqKaeP6AnI+GiAREXUzslOGvGgKdPXwTfInaoR1owZMKty8 trxhnnPmFyVKNDs82yTAbHwIvV64DPcvccsndTgwXdOGYo+NTxosO+hDm88dalUWeXONwL AnNT5W/Fhl1hQNUpU9xu8SSXE+XGolzg0uB4KTl6TIk01ON7lCwqdXD2drNk5MLExrwpI8 OalB7QSv7N08ZEtxXLVTOgVlIEcdf7Htw1DFjZV1Kaj3dpHJooQj06+q1rEVUzYd6uAALV 6Q37iwaZ1+MBJNrFBF6vId6MaT1uC9elqQMlIdmAIpoQM6eNOkYoxtPY8CkYLQ== 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 4VjXV04M3lzYHx; Mon, 20 May 2024 09:35:04 +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 44K9Z4Pf039691; Mon, 20 May 2024 09:35:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44K9Z4O3039688; Mon, 20 May 2024 09:35:04 GMT (envelope-from git) Date: Mon, 20 May 2024 09:35:04 GMT Message-Id: <202405200935.44K9Z4O3039688@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 54290c48db65 - stable/13 - ifconfig: Add format shortcuts. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 54290c48db65986b9953e27420c86a18c3bb21f7 Auto-Submitted: auto-generated The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=54290c48db65986b9953e27420c86a18c3bb21f7 commit 54290c48db65986b9953e27420c86a18c3bb21f7 Author: Dag-Erling Smørgrav AuthorDate: 2024-05-14 06:51:42 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-05-20 09:04:58 +0000 ifconfig: Add format shortcuts. MFC after: 1 week Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D45166 (cherry picked from commit 847ef59d4b5eab234bd1f8eb947ad74bdab5614e) --- sbin/ifconfig/ifconfig.8 | 14 ++++++++++++-- sbin/ifconfig/ifconfig.c | 41 +++++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index f280a263cb51..28b6f2dfb72e 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -27,7 +27,7 @@ .\" .\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94 .\" -.Dd February 1, 2023 +.Dd May 12, 2024 .Dt IFCONFIG 8 .Os .Sh NAME @@ -131,7 +131,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 @@ -193,6 +193,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 1537edfc5ea2..74dfb73f565f 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -303,14 +303,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) @@ -320,9 +316,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; } @@ -330,14 +335,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); } @@ -427,7 +437,6 @@ main(int argc, char *argv[]) #endif all = downonly = uponly = namesonly = noload = verbose = 0; - f_inet = f_inet6 = f_ether = f_addr = NULL; matchgroup = nogroup = NULL; lifh = ifconfig_open();