From nobody Mon Jun 3 15:52:07 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 4VtJBc22Vsz5MkHg; Mon, 03 Jun 2024 15:52:08 +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 4VtJBb6bv5z40X4; Mon, 3 Jun 2024 15:52:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717429927; 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=ca3uAXzlAkBfgpKcl9Nb8XjBleMCU/0dehQWaDXEUoU=; b=LfN7VooIyNd5l+mJ4fzbidUHLVFI7CTzg9hVm+X0zI8vXSajGvoH3wdnxzcTlLx0KRcD0z GvggVPL0bC9SH5HAN35GGR9kFrk2RDFPWVodc9EevpvUzme1weyhvmR5pDx4sryL+dJ+UH eZlJ1W+BaeMuFqVC0kpKQiGkYqh7zaQ+PDDs5I5Nh+2GNISteXNT1LyGtj3mQYI9BHtEe9 5XIoI4alHrK20iL61L7bk7KjU0y6N5XwwORQIFDHRA8rCIYhnoXgeFLMMY8VWN3f7cLffc ZlZMGxS7je40xmeNFptD3zxX3IfYLJPbu4RI0ugy/25n/bYpDAYcNksT16zRIQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717429927; a=rsa-sha256; cv=none; b=NqQr2dLSI154qwnKtU9QmbcTKjEYH6yoWB6iyfTuoT7zkMSElfOslBjLcJ7oS49hEJ7qvO pB9yzlZhD1Z2JcN79fv7FLen0Ljbk1V9RIQb3MmIkIHDziE62l5WVFhRkx2AiVX+iHoetc P7P4JEzbM3w8XZmtRX6ocOZYvYOODwjBi3gGS02rbKTiXcVtR0Hv5Yb/CiVK6I0HwWWeFk a/pW26O+/4uJkZSFBhVogMi29JuESp2DYs1IKURD17hr3ZtcjGarcx6YmqTtemm7UnZYTD 9J2qxYfF+aAz2dMEiC9zI42yXO4umzmekhaxI+0CWrbBohvOFDgLygqsAOabnA== 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=1717429927; 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=ca3uAXzlAkBfgpKcl9Nb8XjBleMCU/0dehQWaDXEUoU=; b=Mu483yT3ry6sU3k+F7+z1W9UM+4VLqNpZ0zjqsLyPZ356busIaJeDsMe82IBOUF9jDrRnO OKAk/I4CPnfQzoaxPqPES5eXU3BvvYvyp1ZKGCv0AVfJK/8LRxlZ5xWU94/a5V4LlcsS6A wIY0a3E7+U2prIpOQTcKhqgKvYeM2PJVxCOtj2YFriYdk5c97Nv0xh7efloilyMt7oVay+ mbZkjsVvnNvpVrGQsLVyVPQ6GBv+x6X9JDqb3dF54iTzkSiViqSQNb8Ymyuw/E6vvEfhkn YfX7Hm83oImPZmQu20fJ18hiadHluMUf9K7694pY4efw1Tr7n9iLoEsed3k31w== 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 4VtJBb6CLSzh9M; Mon, 3 Jun 2024 15:52:07 +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 453Fq71S008846; Mon, 3 Jun 2024 15:52:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 453Fq7MT008843; Mon, 3 Jun 2024 15:52:07 GMT (envelope-from git) Date: Mon, 3 Jun 2024 15:52:07 GMT Message-Id: <202406031552.453Fq7MT008843@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gordon Tetlow Subject: git: a68e4f7a0652 - main - Migrate from printb to print_bits for locally defined bit fields. 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: gordon X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a68e4f7a065218f0bcc5b34ff8d2e73a240b59b2 Auto-Submitted: auto-generated The branch main has been updated by gordon: URL: https://cgit.FreeBSD.org/src/commit/?id=a68e4f7a065218f0bcc5b34ff8d2e73a240b59b2 commit a68e4f7a065218f0bcc5b34ff8d2e73a240b59b2 Author: Gordon Tetlow AuthorDate: 2024-05-31 20:58:52 +0000 Commit: Gordon Tetlow CommitDate: 2024-06-03 15:48:35 +0000 Migrate from printb to print_bits for locally defined bit fields. Reviewed by: emaste Event: Kitchener-Waterloo Hackathon 202406 Differential Revision: https://reviews.freebsd.org/D45441 --- sbin/ifconfig/af_nd6.c | 29 ++++++++++++------- sbin/ifconfig/ifconfig.c | 75 ++++++++++++++++++++++++++++++++++++++---------- sbin/ifconfig/ifgif.c | 7 +++-- sbin/ifconfig/ifgre.c | 9 ++++-- 4 files changed, 90 insertions(+), 30 deletions(-) diff --git a/sbin/ifconfig/af_nd6.c b/sbin/ifconfig/af_nd6.c index 73044e95740a..2899ad6a0778 100644 --- a/sbin/ifconfig/af_nd6.c +++ b/sbin/ifconfig/af_nd6.c @@ -52,17 +52,22 @@ #include "ifconfig.h" #define MAX_SYSCTL_TRY 5 +static const char *ND6BITS[] = { + [0] = "PERFORMNUD", + [1] = "ACCEPT_RTADV", + [2] = "PREFER_SOURCE", + [3] = "IFDISABLED", + [4] = "DONT_SET_IFROUTE", + [5] = "AUTO_LINKLOCAL", + [6] = "NO_RADR", + [7] = "NO_PREFER_IFACE", + [8] = "NO_DAD", #ifdef DRAFT_IETF_6MAN_IPV6ONLY_FLAG -#define ND6BITS "\020\001PERFORMNUD\002ACCEPT_RTADV\003PREFER_SOURCE" \ - "\004IFDISABLED\005DONT_SET_IFROUTE\006AUTO_LINKLOCAL" \ - "\007NO_RADR\010NO_PREFER_IFACE\011NO_DAD" \ - "\012IPV6_ONLY\013IPV6_ONLY_MANUAL" \ - "\020DEFAULTIF" -#else -#define ND6BITS "\020\001PERFORMNUD\002ACCEPT_RTADV\003PREFER_SOURCE" \ - "\004IFDISABLED\005DONT_SET_IFROUTE\006AUTO_LINKLOCAL" \ - "\007NO_RADR\010NO_PREFER_IFACE\011NO_DAD\020DEFAULTIF" + [9] = "IPV6_ONLY", + [10] = "IPV6_ONLY_MANUAL", #endif + [15] = "DEFAULTIF", +}; static int isnd6defif(if_ctx *ctx, int s); void setnd6flags(if_ctx *, const char *, int); @@ -141,6 +146,7 @@ nd6_status(if_ctx *ctx) int s6; int error; int isdefif; + uint32_t bits; strlcpy(nd.ifname, ctx->ifname, sizeof(nd.ifname)); if ((s6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { @@ -159,7 +165,8 @@ nd6_status(if_ctx *ctx) close(s6); if (nd.ndi.flags == 0 && !isdefif) return; - printb("\tnd6 options", - (unsigned int)(nd.ndi.flags | (isdefif << 15)), ND6BITS); + bits = (nd.ndi.flags | (isdefif << 15)); + printf("\tnd6 options=%x", bits); + print_bits("options", &bits, 1, ND6BITS, nitems(ND6BITS)); putchar('\n'); } diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 92543a281959..615de5d4ae14 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1617,17 +1617,60 @@ unsetifdescr(if_ctx *ctx, const char *val __unused, int value __unused) #ifdef WITHOUT_NETLINK -#define IFFBITS \ -"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\7RUNNING" \ -"\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \ -"\20MULTICAST\22PPROMISC\23MONITOR\24STATICARP\25STICKYARP" - -#define IFCAPBITS \ -"\020\1RXCSUM\2TXCSUM\3NETCONS\4VLAN_MTU\5VLAN_HWTAGGING\6JUMBO_MTU\7POLLING" \ -"\10VLAN_HWCSUM\11TSO4\12TSO6\13LRO\14WOL_UCAST\15WOL_MCAST\16WOL_MAGIC" \ -"\17TOE4\20TOE6\21VLAN_HWFILTER\23VLAN_HWTSO\24LINKSTATE\25NETMAP" \ -"\26RXCSUM_IPV6\27TXCSUM_IPV6\31TXRTLMT\32HWRXTSTMP\33NOMAP\34TXTLS4\35TXTLS6" \ -"\36VXLAN_HWCSUM\37VXLAN_HWTSO\40TXTLS_RTLMT" +static const char *IFFBITS[] = { + [0] = "UP", + [1] = "BROADCAST", + [2] = "DEBUG", + [3] = "LOOPBACK", + [4] = "POINTOPOINT", + [6] = "RUNNING", + [7] = "NOARP", + [8] = "PROMISC", + [9] = "ALLMULTI", + [10] = "OACTIVE", + [11] = "SIMPLEX", + [12] = "LINK0", + [13] = "LINK1", + [14] = "LINK2", + [15] = "MULTICAST", + [17] = "PPROMISC", + [18] = "MONITOR", + [19] = "STATICARP", + [20] = "STICKYARP", +}; + +static const char *IFCAPBITS[] = { + [0] = "RXCSUM", + [1] = "TXCSUM", + [2] = "NETCONS", + [3] = "VLAN_MTU", + [4] = "VLAN_HWTAGGING", + [5] = "JUMBO_MTU", + [6] = "POLLING", + [7] = "VLAN_HWCSUM", + [8] = "TSO4", + [9] = "TSO6", + [10] = "LRO", + [11] = "WOL_UCAST", + [12] = "WOL_MCAST", + [13] = "WOL_MAGIC", + [14] = "TOE4", + [15] = "TOE6", + [16] = "VLAN_HWFILTER", + [18] = "VLAN_HWTSO", + [19] = "LINKSTATE", + [20] = "NETMAP", + [21] = "RXCSUM_IPV6", + [22] = "TXCSUM_IPV6", + [24] = "TXRTLMT", + [25] = "HWRXTSTMP", + [26] = "NOMAP", + [27] = "TXTLS4", + [28] = "TXTLS6", + [29] = "VXLAN_HWCSUM", + [30] = "VXLAN_HWTSO", + [31] = "TXTLS_RTLMT", +}; static void print_ifcap_nv(if_ctx *ctx) @@ -1699,10 +1742,12 @@ print_ifcap(if_ctx *ctx) if ((ifr.ifr_curcap & IFCAP_NV) != 0) print_ifcap_nv(ctx); else { - printb("\toptions", ifr.ifr_curcap, IFCAPBITS); + printf("\toptions=%x", ifr.ifr_curcap); + print_bits("options", &ifr.ifr_curcap, 1, IFCAPBITS, nitems(IFCAPBITS)); putchar('\n'); if (ctx->args->supmedia && ifr.ifr_reqcap != 0) { - printb("\tcapabilities", ifr.ifr_reqcap, IFCAPBITS); + printf("\tcapabilities=%x", ifr.ifr_reqcap); + print_bits("capabilities", &ifr.ifr_reqcap, 1, IFCAPBITS, nitems(IFCAPBITS)); putchar('\n'); } } @@ -1790,8 +1835,8 @@ status(if_ctx *ctx, const struct sockaddr_dl *sdl __unused, struct ifaddrs *ifa) old_s = ctx->io_s; ctx->io_s = s; - printf("%s: ", ctx->ifname); - printb("flags", ifa->ifa_flags, IFFBITS); + printf("%s: flags=%x", ctx->ifname, ifa->ifa_flags); + print_bits("flags", &ifa->ifa_flags, 1, IFFBITS, nitems(IFFBITS)); print_metric(ctx); print_mtu(ctx); putchar('\n'); diff --git a/sbin/ifconfig/ifgif.c b/sbin/ifconfig/ifgif.c index 6a4bb8b5a240..991cf110678f 100644 --- a/sbin/ifconfig/ifgif.c +++ b/sbin/ifconfig/ifgif.c @@ -48,7 +48,9 @@ #include "ifconfig.h" -#define GIFBITS "\020\2IGNORE_SOURCE" +static const char *GIFBITS[] = { + [1] = "IGNORE_SOURCE", +}; static void gif_status(if_ctx *ctx) @@ -60,7 +62,8 @@ gif_status(if_ctx *ctx) return; if (opts == 0) return; - printb("\toptions", opts, GIFBITS); + printf("\toptions=%x", opts); + print_bits("options", &opts, 1, GIFBITS, nitems(GIFBITS)); putchar('\n'); } diff --git a/sbin/ifconfig/ifgre.c b/sbin/ifconfig/ifgre.c index 3eeed8f3d200..43c86a546167 100644 --- a/sbin/ifconfig/ifgre.c +++ b/sbin/ifconfig/ifgre.c @@ -41,7 +41,11 @@ #include "ifconfig.h" -#define GREBITS "\020\01ENABLE_CSUM\02ENABLE_SEQ\03UDPENCAP" +static const char *GREBITS[] = { + [0] = "ENABLE_CSUM", + [1] = "ENABLE_SEQ", + [2] = "UDPENCAP", +}; static void gre_status(if_ctx *ctx) @@ -60,7 +64,8 @@ gre_status(if_ctx *ctx) ifr.ifr_data = (caddr_t)&port; if (ioctl_ctx_ifr(ctx, GREGPORT, &ifr) == 0 && port != 0) printf("\tudpport: %u\n", port); - printb("\toptions", opts, GREBITS); + printf("\toptions=%x", opts); + print_bits("options", &opts, 1, GREBITS, nitems(GREBITS)); putchar('\n'); }