git: edf5608bfef3 - main - netlink: use bitset(9)

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Tue, 03 Dec 2024 20:04:55 UTC
The branch main has been updated by glebius:

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

commit edf5608bfef3840718bf31b453efb714ef290f31
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-12-03 20:04:14 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2024-12-03 20:04:14 +0000

    netlink: use bitset(9)
    
    Reviewed by:            melifaro
    Differential Revision:  https://reviews.freebsd.org/D47548
---
 sys/netlink/netlink_domain.c | 6 +++---
 sys/netlink/netlink_var.h    | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/sys/netlink/netlink_domain.c b/sys/netlink/netlink_domain.c
index 7bd58e63b65a..67ca16d59009 100644
--- a/sys/netlink/netlink_domain.c
+++ b/sys/netlink/netlink_domain.c
@@ -145,7 +145,7 @@ nl_add_group_locked(struct nlpcb *nlp, unsigned int group_id)
 	if (!nlp_unconstrained_vnet(nlp))
 		return;
 
-	nlp->nl_groups[group_id / 64] |= (uint64_t)1 << (group_id % 64);
+	BIT_SET(NLP_MAX_GROUPS, group_id, &nlp->nl_groups);
 }
 
 static void
@@ -154,7 +154,7 @@ nl_del_group_locked(struct nlpcb *nlp, unsigned int group_id)
 	MPASS(group_id <= NLP_MAX_GROUPS);
 	--group_id;
 
-	nlp->nl_groups[group_id / 64] &= ~((uint64_t)1 << (group_id % 64));
+	BIT_CLR(NLP_MAX_GROUPS, group_id, &nlp->nl_groups);
 }
 
 static bool
@@ -163,7 +163,7 @@ nl_isset_group_locked(struct nlpcb *nlp, unsigned int group_id)
 	MPASS(group_id <= NLP_MAX_GROUPS);
 	--group_id;
 
-	return (nlp->nl_groups[group_id / 64] & ((uint64_t)1 << (group_id % 64)));
+	return (BIT_ISSET(NLP_MAX_GROUPS, group_id, &nlp->nl_groups));
 }
 
 static uint32_t
diff --git a/sys/netlink/netlink_var.h b/sys/netlink/netlink_var.h
index 51b0045b1430..7557bd2c06a5 100644
--- a/sys/netlink/netlink_var.h
+++ b/sys/netlink/netlink_var.h
@@ -53,9 +53,10 @@ struct nl_buf {
 
 #define	NLP_MAX_GROUPS		128
 
+BITSET_DEFINE(nl_groups, NLP_MAX_GROUPS);
 struct nlpcb {
         struct socket           *nl_socket;
-	uint64_t	        nl_groups[NLP_MAX_GROUPS / 64];
+	struct nl_groups	nl_groups;
 	uint32_t                nl_port;
 	uint32_t	        nl_flags;
 	uint32_t	        nl_process_id;