git: a68e4f7a0652 - main - Migrate from printb to print_bits for locally defined bit fields.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 03 Jun 2024 15:52:07 UTC
The branch main has been updated by gordon:
URL: https://cgit.FreeBSD.org/src/commit/?id=a68e4f7a065218f0bcc5b34ff8d2e73a240b59b2
commit a68e4f7a065218f0bcc5b34ff8d2e73a240b59b2
Author: Gordon Tetlow <gordon@FreeBSD.org>
AuthorDate: 2024-05-31 20:58:52 +0000
Commit: Gordon Tetlow <gordon@FreeBSD.org>
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');
}