From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 17/18] bitmap: Split bitmap helper functions into their own module
Date: Fri, 27 Mar 2026 15:34:29 +1100 [thread overview]
Message-ID: <20260327043430.1785787-18-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20260327043430.1785787-1-david@gibson.dropbear.id.au>
Currently bitmap functions are in util.[ch] along with a lot of other
stuff. In preparation for sharing them with a configuration client, move
these out into their own files.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
Makefile | 17 +++++-----
bitmap.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
bitmap.h | 24 ++++++++++++++
conf.c | 1 +
fwd.h | 1 +
util.c | 84 -----------------------------------------------
util.h | 10 ------
7 files changed, 134 insertions(+), 102 deletions(-)
create mode 100644 bitmap.c
create mode 100644 bitmap.h
diff --git a/Makefile b/Makefile
index 5b6891d7..d6ced328 100644
--- a/Makefile
+++ b/Makefile
@@ -37,20 +37,21 @@ FLAGS += -DPAGE_SIZE=$(shell getconf PAGE_SIZE)
FLAGS += -DVERSION=\"$(VERSION)\"
FLAGS += -DDUAL_STACK_SOCKETS=$(DUAL_STACK_SOCKETS)
-PASST_SRCS = arch.c arp.c checksum.c conf.c dhcp.c dhcpv6.c epoll_ctl.c \
- flow.c fwd.c icmp.c igmp.c inany.c iov.c ip.c isolation.c lineread.c \
- log.c mld.c ndp.c netlink.c migrate.c packet.c passt.c pasta.c pcap.c \
- pif.c repair.c serialise.c tap.c tcp.c tcp_buf.c tcp_splice.c tcp_vu.c \
- udp.c udp_flow.c udp_vu.c util.c vhost_user.c virtio.c vu_common.c
+PASST_SRCS = arch.c arp.c bitmap.c checksum.c conf.c dhcp.c dhcpv6.c \
+ epoll_ctl.c flow.c fwd.c icmp.c igmp.c inany.c iov.c ip.c isolation.c \
+ lineread.c log.c mld.c ndp.c netlink.c migrate.c packet.c passt.c \
+ pasta.c pcap.c pif.c repair.c serialise.c tap.c tcp.c tcp_buf.c \
+ tcp_splice.c tcp_vu.c udp.c udp_flow.c udp_vu.c util.c vhost_user.c \
+ virtio.c vu_common.c
QRAP_SRCS = qrap.c
PASST_REPAIR_SRCS = passt-repair.c
SRCS = $(PASST_SRCS) $(QRAP_SRCS) $(PASST_REPAIR_SRCS)
MANPAGES = passt.1 pasta.1 qrap.1 passt-repair.1
-PASST_HEADERS = arch.h arp.h checksum.h conf.h dhcp.h dhcpv6.h epoll_ctl.h \
- flow.h fwd.h flow_table.h icmp.h icmp_flow.h inany.h iov.h ip.h \
- isolation.h lineread.h log.h migrate.h ndp.h netlink.h packet.h \
+PASST_HEADERS = arch.h arp.h bitmap.h checksum.h conf.h dhcp.h dhcpv6.h \
+ epoll_ctl.h flow.h fwd.h flow_table.h icmp.h icmp_flow.h inany.h iov.h \
+ ip.h isolation.h lineread.h log.h migrate.h ndp.h netlink.h packet.h \
passt.h pasta.h pcap.h pif.h repair.h serialise.h siphash.h tap.h tcp.h \
tcp_buf.h tcp_conn.h tcp_internal.h tcp_splice.h tcp_vu.h udp.h \
udp_flow.h udp_internal.h udp_vu.h util.h vhost_user.h virtio.h \
diff --git a/bitmap.c b/bitmap.c
new file mode 100644
index 00000000..b3b204b2
--- /dev/null
+++ b/bitmap.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/* PASST - Plug A Simple Socket Transport
+ * for qemu/UNIX domain socket mode
+ *
+ * PASTA - Pack A Subtle Tap Abstraction
+ * for network namespace/tap device mode
+ *
+ * bitmap.c - bitmap handling
+ *
+ * Copyright Red Hat
+ * Author: Stefano Brivio <sbrivio@redhat.com>
+ */
+
+#include "bitmap.h"
+
+/**
+ * bitmap_set() - Set single bit in bitmap
+ * @map: Pointer to bitmap
+ * @bit: Bit number to set
+ */
+void bitmap_set(uint8_t *map, unsigned bit)
+{
+ unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit);
+
+ *word |= BITMAP_BIT(bit);
+}
+
+/**
+ * bitmap_clear() - Clear single bit in bitmap
+ * @map: Pointer to bitmap
+ * @bit: Bit number to clear
+ */
+/* cppcheck-suppress unusedFunction */
+void bitmap_clear(uint8_t *map, unsigned bit)
+{
+ unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit);
+
+ *word &= ~BITMAP_BIT(bit);
+}
+
+/**
+ * bitmap_isset() - Check for set bit in bitmap
+ * @map: Pointer to bitmap
+ * @bit: Bit number to check
+ *
+ * Return: true if given bit is set, false if it's not
+ */
+bool bitmap_isset(const uint8_t *map, unsigned bit)
+{
+ const unsigned long *word
+ = (const unsigned long *)map + BITMAP_WORD(bit);
+
+ return !!(*word & BITMAP_BIT(bit));
+}
+
+/**
+ * bitmap_or() - Logical disjunction (OR) of two bitmaps
+ * @dst: Pointer to result bitmap
+ * @size: Size of bitmaps, in bytes
+ * @a: First operand
+ * @b: Second operand
+ */
+/* cppcheck-suppress unusedFunction */
+void bitmap_or(uint8_t *dst, size_t size, const uint8_t *a, const uint8_t *b)
+{
+ unsigned long *dw = (unsigned long *)dst;
+ unsigned long *aw = (unsigned long *)a;
+ unsigned long *bw = (unsigned long *)b;
+ size_t i;
+
+ for (i = 0; i < size / sizeof(long); i++, dw++, aw++, bw++)
+ *dw = *aw | *bw;
+
+ for (i = size / sizeof(long) * sizeof(long); i < size; i++)
+ dst[i] = a[i] | b[i];
+}
+
+/**
+ * bitmap_and_not() - Logical conjunction with complement (AND NOT) of bitmap
+ * @dst: Pointer to result bitmap
+ * @size: Size of bitmaps, in bytes
+ * @a: First operand
+ * @b: Second operand
+ */
+void bitmap_and_not(uint8_t *dst, size_t size,
+ const uint8_t *a, const uint8_t *b)
+{
+ unsigned long *dw = (unsigned long *)dst;
+ unsigned long *aw = (unsigned long *)a;
+ unsigned long *bw = (unsigned long *)b;
+ size_t i;
+
+ for (i = 0; i < size / sizeof(long); i++, dw++, aw++, bw++)
+ *dw = *aw & ~*bw;
+
+ for (i = size / sizeof(long) * sizeof(long); i < size; i++)
+ dst[i] = a[i] & ~b[i];
+}
diff --git a/bitmap.h b/bitmap.h
new file mode 100644
index 00000000..b6e91c02
--- /dev/null
+++ b/bitmap.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright Red Hat
+ * Author: Stefano Brivio <sbrivio@redhat.com>
+ */
+
+#ifndef BITMAP_H
+#define BITMAP_H
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#define BIT(n) (1UL << (n))
+#define BITMAP_BIT(n) (BIT((n) % (sizeof(long) * 8)))
+#define BITMAP_WORD(n) (n / (sizeof(long) * 8))
+
+void bitmap_set(uint8_t *map, unsigned bit);
+void bitmap_clear(uint8_t *map, unsigned bit);
+bool bitmap_isset(const uint8_t *map, unsigned bit);
+void bitmap_or(uint8_t *dst, size_t size, const uint8_t *a, const uint8_t *b);
+void bitmap_and_not(uint8_t *dst, size_t size,
+ const uint8_t *a, const uint8_t *b);
+
+#endif /* BITMAP_H */
diff --git a/conf.c b/conf.c
index 5639ef03..ae37bf96 100644
--- a/conf.c
+++ b/conf.c
@@ -36,6 +36,7 @@
#include <netinet/if_ether.h>
#include "util.h"
+#include "bitmap.h"
#include "ip.h"
#include "passt.h"
#include "netlink.h"
diff --git a/fwd.h b/fwd.h
index f111e139..beba0bf5 100644
--- a/fwd.h
+++ b/fwd.h
@@ -14,6 +14,7 @@
#include <netinet/in.h>
+#include "bitmap.h"
#include "inany.h"
struct flowside;
diff --git a/util.c b/util.c
index faa2c6a4..73c9d51d 100644
--- a/util.c
+++ b/util.c
@@ -367,90 +367,6 @@ long timespec_diff_ms(const struct timespec *a, const struct timespec *b)
return timespec_diff_us(a, b) / 1000;
}
-/**
- * bitmap_set() - Set single bit in bitmap
- * @map: Pointer to bitmap
- * @bit: Bit number to set
- */
-void bitmap_set(uint8_t *map, unsigned bit)
-{
- unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit);
-
- *word |= BITMAP_BIT(bit);
-}
-
-/**
- * bitmap_clear() - Clear single bit in bitmap
- * @map: Pointer to bitmap
- * @bit: Bit number to clear
- */
-/* cppcheck-suppress unusedFunction */
-void bitmap_clear(uint8_t *map, unsigned bit)
-{
- unsigned long *word = (unsigned long *)map + BITMAP_WORD(bit);
-
- *word &= ~BITMAP_BIT(bit);
-}
-
-/**
- * bitmap_isset() - Check for set bit in bitmap
- * @map: Pointer to bitmap
- * @bit: Bit number to check
- *
- * Return: true if given bit is set, false if it's not
- */
-bool bitmap_isset(const uint8_t *map, unsigned bit)
-{
- const unsigned long *word
- = (const unsigned long *)map + BITMAP_WORD(bit);
-
- return !!(*word & BITMAP_BIT(bit));
-}
-
-/**
- * bitmap_or() - Logical disjunction (OR) of two bitmaps
- * @dst: Pointer to result bitmap
- * @size: Size of bitmaps, in bytes
- * @a: First operand
- * @b: Second operand
- */
-/* cppcheck-suppress unusedFunction */
-void bitmap_or(uint8_t *dst, size_t size, const uint8_t *a, const uint8_t *b)
-{
- unsigned long *dw = (unsigned long *)dst;
- unsigned long *aw = (unsigned long *)a;
- unsigned long *bw = (unsigned long *)b;
- size_t i;
-
- for (i = 0; i < size / sizeof(long); i++, dw++, aw++, bw++)
- *dw = *aw | *bw;
-
- for (i = size / sizeof(long) * sizeof(long); i < size; i++)
- dst[i] = a[i] | b[i];
-}
-
-/**
- * bitmap_and_not() - Logical conjunction with complement (AND NOT) of bitmap
- * @dst: Pointer to result bitmap
- * @size: Size of bitmaps, in bytes
- * @a: First operand
- * @b: Second operand
- */
-void bitmap_and_not(uint8_t *dst, size_t size,
- const uint8_t *a, const uint8_t *b)
-{
- unsigned long *dw = (unsigned long *)dst;
- unsigned long *aw = (unsigned long *)a;
- unsigned long *bw = (unsigned long *)b;
- size_t i;
-
- for (i = 0; i < size / sizeof(long); i++, dw++, aw++, bw++)
- *dw = *aw & ~*bw;
-
- for (i = size / sizeof(long) * sizeof(long); i < size; i++)
- dst[i] = a[i] & ~b[i];
-}
-
/**
* ns_enter() - Enter configured user (unless already joined) and network ns
* @c: Execution context
diff --git a/util.h b/util.h
index cb669105..92aeabc8 100644
--- a/util.h
+++ b/util.h
@@ -50,10 +50,6 @@
#define MAX_FROM_BITS(n) (((1U << (n)) - 1))
-#define BIT(n) (1UL << (n))
-#define BITMAP_BIT(n) (BIT((n) % (sizeof(long) * 8)))
-#define BITMAP_WORD(n) (n / (sizeof(long) * 8))
-
#define SWAP(a, b) \
do { \
__typeof__(a) __x = (a); (a) = (b); (b) = __x; \
@@ -228,12 +224,6 @@ int sock_unix(char *sock_path);
void sock_probe_features(struct ctx *c);
long timespec_diff_ms(const struct timespec *a, const struct timespec *b);
int64_t timespec_diff_us(const struct timespec *a, const struct timespec *b);
-void bitmap_set(uint8_t *map, unsigned bit);
-void bitmap_clear(uint8_t *map, unsigned bit);
-bool bitmap_isset(const uint8_t *map, unsigned bit);
-void bitmap_or(uint8_t *dst, size_t size, const uint8_t *a, const uint8_t *b);
-void bitmap_and_not(uint8_t *dst, size_t size,
- const uint8_t *a, const uint8_t *b);
char *line_read(char *buf, size_t len, int fd);
void ns_enter(const struct ctx *c);
bool ns_is_init(void);
--
2.53.0
next prev parent reply other threads:[~2026-03-27 4:34 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-27 4:34 [PATCH 00/18] More pesto preliminaries David Gibson
2026-03-27 4:34 ` [PATCH 01/18] conf: runas can be const David Gibson
2026-03-27 4:34 ` [PATCH 02/18] fwd: Comparing rule " David Gibson
2026-03-27 4:34 ` [PATCH 03/18] vhost_user: Fix assorted minor cppcheck warnings David Gibson
2026-03-27 4:34 ` [PATCH 04/18] serialise: Split functions user for serialisation from util.c David Gibson
2026-03-27 4:34 ` [PATCH 05/18] serialise: Add helpers for serialising unsigned integers David Gibson
2026-03-27 4:34 ` [PATCH 06/18] fwd: Move selecting correct scan bitmap into fwd_sync_one() David Gibson
2026-03-27 4:34 ` [PATCH 07/18] fwd: Look up rule index in fwd_sync_one() David Gibson
2026-03-27 4:34 ` [PATCH 08/18] fwd: Store forwarding tables indexed by (origin) pif David Gibson
2026-03-27 4:34 ` [PATCH 09/18] fwd: Allow FWD_DUAL_STACK_ANY flag to be passed directly to fwd_rule_add() David Gibson
2026-03-27 4:34 ` [PATCH 10/18] fwd, conf: Expose ephemeral ports as bitmap rather than function David Gibson
2026-03-27 4:34 ` [PATCH 11/18] conf: Don't bother complaining about overlapping excluded ranges David Gibson
2026-03-27 4:34 ` [PATCH 12/18] conf: Move check for mapping port 0 to caller David Gibson
2026-03-27 4:34 ` [PATCH 13/18] conf: Move check for disabled interfaces earlier David Gibson
2026-03-27 4:34 ` [PATCH 14/18] conf: Remove redundant warning when SO_BINDTODEVICE is unavailable David Gibson
2026-03-27 4:34 ` [PATCH 15/18] pif: Limit pif names to IFNAMSIZ (16) bytes David Gibson
2026-03-29 12:02 ` Stefano Brivio
2026-03-27 4:34 ` [PATCH 16/18] ip: Define a bound for the string returned by ipproto_name() David Gibson
2026-03-27 4:34 ` David Gibson [this message]
2026-03-27 4:34 ` [PATCH 18/18] fwd: Split forwading rule specification from its implementation state David Gibson
2026-03-29 12:02 ` [PATCH 00/18] More pesto preliminaries Stefano Brivio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260327043430.1785787-18-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).