git: 7b676698856e - main - pf: simplify structs with anonymous unions

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Wed, 03 May 2023 09:59:25 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=7b676698856ec4604b2b93f4fa917767bfbfa66e

commit 7b676698856ec4604b2b93f4fa917767bfbfa66e
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2023-05-03 06:02:43 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-05-03 08:24:20 +0000

    pf: simplify structs with anonymous unions
    
    Rather than playing preprocessor hacks use actual anonymous unions.
    No functional change.
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sys/net/pfvar.h           | 24 +++++++++---------------
 sys/netpfil/pf/pf.h       | 20 +++++---------------
 sys/netpfil/pf/pf_table.c | 26 ++++++++++----------------
 3 files changed, 24 insertions(+), 46 deletions(-)

diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h
index c1550f2c30e6..412453f8dd25 100644
--- a/sys/net/pfvar.h
+++ b/sys/net/pfvar.h
@@ -1704,32 +1704,26 @@ struct pfioc_state_kill {
 struct pfioc_states {
 	int	ps_len;
 	union {
-		caddr_t			 psu_buf;
-		struct pfsync_state	*psu_states;
-	} ps_u;
-#define ps_buf		ps_u.psu_buf
-#define ps_states	ps_u.psu_states
+		caddr_t			 ps_buf;
+		struct pfsync_state	*ps_states;
+	};
 };
 
 struct pfioc_states_v2 {
 	int		ps_len;
 	uint64_t	ps_req_version;
 	union {
-		caddr_t			 psu_buf;
-		struct pf_state_export	*psu_states;
-	} ps_u;
-#define ps_buf		ps_u.psu_buf
-#define ps_states	ps_u.psu_states
+		caddr_t			 ps_buf;
+		struct pf_state_export	*ps_states;
+	};
 };
 
 struct pfioc_src_nodes {
 	int	psn_len;
 	union {
-		caddr_t		 psu_buf;
-		struct pf_src_node	*psu_src_nodes;
-	} psn_u;
-#define psn_buf		psn_u.psu_buf
-#define psn_src_nodes	psn_u.psu_src_nodes
+		caddr_t		 psn_buf;
+		struct pf_src_node	*psn_src_nodes;
+	};
 };
 
 struct pfioc_if {
diff --git a/sys/netpfil/pf/pf.h b/sys/netpfil/pf/pf.h
index f226232419f8..fc3ea6c9e1d3 100644
--- a/sys/netpfil/pf/pf.h
+++ b/sys/netpfil/pf/pf.h
@@ -233,11 +233,9 @@ struct pfi_kif_cmp {
 struct pfi_kif {
 	char				 pfik_name[IFNAMSIZ];
 	union {
-		RB_ENTRY(pfi_kif)	 _pfik_tree;
-		LIST_ENTRY(pfi_kif)	 _pfik_list;
-	} _pfik_glue;
-#define	pfik_tree	_pfik_glue._pfik_tree
-#define	pfik_list	_pfik_glue._pfik_list
+		RB_ENTRY(pfi_kif)	 pfik_tree;
+		LIST_ENTRY(pfi_kif)	 pfik_list;
+	};
 	u_int64_t			 pfik_packets[2][2][2];
 	u_int64_t			 pfik_bytes[2][2][2];
 	u_int32_t			 pfik_tzero;
@@ -275,12 +273,7 @@ struct pf_addr {
 		u_int8_t		addr8[16];
 		u_int16_t		addr16[8];
 		u_int32_t		addr32[4];
-	} pfa;		    /* 128-bit address */
-#define v4	pfa.v4
-#define v6	pfa.v6
-#define addr8	pfa.addr8
-#define addr16	pfa.addr16
-#define addr32	pfa.addr32
+	};		    /* 128-bit address */
 };
 
 #define PFI_AFLAG_NETWORK	0x01
@@ -344,10 +337,7 @@ struct pf_poolhashkey {
 		u_int8_t		key8[16];
 		u_int16_t		key16[8];
 		u_int32_t		key32[4];
-	} pfk;		    /* 128-bit hash key */
-#define key8	pfk.key8
-#define key16	pfk.key16
-#define key32	pfk.key32
+	};		    /* 128-bit hash key */
 };
 
 struct pf_mape_portset {
diff --git a/sys/netpfil/pf/pf_table.c b/sys/netpfil/pf/pf_table.c
index ea37b077c651..28d63b54c2d8 100644
--- a/sys/netpfil/pf/pf_table.c
+++ b/sys/netpfil/pf/pf_table.c
@@ -107,21 +107,15 @@ struct pfr_walktree {
 		PFRW_COUNTERS
 	}	 pfrw_op;
 	union {
-		struct pfr_addr		*pfrw1_addr;
-		struct pfr_astats	*pfrw1_astats;
-		struct pfr_kentryworkq	*pfrw1_workq;
-		struct pfr_kentry	*pfrw1_kentry;
-		struct pfi_dynaddr	*pfrw1_dyn;
-	}	 pfrw_1;
+		struct pfr_addr		*pfrw_addr;
+		struct pfr_astats	*pfrw_astats;
+		struct pfr_kentryworkq	*pfrw_workq;
+		struct pfr_kentry	*pfrw_kentry;
+		struct pfi_dynaddr	*pfrw_dyn;
+	};
 	int	 pfrw_free;
 	int	 pfrw_flags;
 };
-#define	pfrw_addr	pfrw_1.pfrw1_addr
-#define	pfrw_astats	pfrw_1.pfrw1_astats
-#define	pfrw_workq	pfrw_1.pfrw1_workq
-#define	pfrw_kentry	pfrw_1.pfrw1_kentry
-#define	pfrw_dyn	pfrw_1.pfrw1_dyn
-#define	pfrw_cnt	pfrw_free
 
 #define	senderr(e)	do { rv = (e); goto _bad; } while (0)
 
@@ -740,7 +734,7 @@ pfr_enqueue_addrs(struct pfr_ktable *kt, struct pfr_kentryworkq *workq,
 		    pfr_walktree, &w))
 			printf("pfr_enqueue_addrs: IPv6 walktree failed.\n");
 	if (naddr != NULL)
-		*naddr = w.pfrw_cnt;
+		*naddr = w.pfrw_free;
 }
 
 static void
@@ -1068,7 +1062,7 @@ pfr_walktree(struct radix_node *rn, void *arg)
 		/* FALLTHROUGH */
 	case PFRW_ENQUEUE:
 		SLIST_INSERT_HEAD(w->pfrw_workq, ke, pfrke_workq);
-		w->pfrw_cnt++;
+		w->pfrw_free++;
 		break;
 	case PFRW_GET_ADDRS:
 		if (w->pfrw_free-- > 0) {
@@ -1089,7 +1083,7 @@ pfr_walktree(struct radix_node *rn, void *arg)
 	case PFRW_POOL_GET:
 		if (ke->pfrke_not)
 			break; /* negative entries are ignored */
-		if (!w->pfrw_cnt--) {
+		if (!w->pfrw_free--) {
 			w->pfrw_kentry = ke;
 			return (1); /* finish search */
 		}
@@ -2347,7 +2341,7 @@ pfr_kentry_byidx(struct pfr_ktable *kt, int idx, int af)
 
 	bzero(&w, sizeof(w));
 	w.pfrw_op = PFRW_POOL_GET;
-	w.pfrw_cnt = idx;
+	w.pfrw_free = idx;
 
 	switch (af) {
 #ifdef INET