From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>, passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH v5 14/18] inany: Prepare inany.[ch] for sharing with pesto tool
Date: Tue, 21 Apr 2026 16:25:12 +1000 [thread overview]
Message-ID: <20260421062516.2601204-15-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20260421062516.2601204-1-david@gibson.dropbear.id.au>
inany contains a number of helpful functions for dealing with addresses
which might be IPv4 or IPv6. We're going to want to use that in pesto.
For the most part inany doesn't depend on other passt/pasta internals,
however it does depend on siphash.h, which pesto doesn't need.
Move the single dependent function, inany_siphash_feed() to siphash.h,
renaming to match. Use that include inany.[ch] into pesto as well as
passt/pasta. While we're there reformat pesto.c's header comment to match
the convention used in most other files.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
common.h | 20 ++++++++++++++++++--
flow.c | 4 ++--
fwd.c | 2 +-
fwd.h | 1 +
fwd_rule.h | 1 +
inany.c | 19 ++++++++++++++-----
inany.h | 17 ++---------------
pif.h | 1 +
siphash.h | 13 +++++++++++++
util.h | 16 ----------------
10 files changed, 53 insertions(+), 41 deletions(-)
diff --git a/common.h b/common.h
index 4a167ae0..370cfa16 100644
--- a/common.h
+++ b/common.h
@@ -18,9 +18,27 @@
"This is free software: you are free to change and redistribute it.\n" \
"There is NO WARRANTY, to the extent permitted by law.\n\n"
+#ifndef MIN
+#define MIN(x, y) (((x) < (y)) ? (x) : (y))
+#endif
+#ifndef MAX
+#define MAX(x, y) (((x) > (y)) ? (x) : (y))
+#endif
+
+#define MAX_FROM_BITS(n) (((1U << (n)) - 1))
+
/* FPRINTF() intentionally silences cert-err33-c clang-tidy warnings */
#define FPRINTF(f, ...) (void)fprintf(f, __VA_ARGS__)
+#define ARRAY_SIZE(a) ((int)(sizeof(a) / sizeof((a)[0])))
+
+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+#define DIV_ROUND_CLOSEST(n, d) (((n) + (d) / 2) / (d))
+#define ROUND_DOWN(x, y) ((x) & ~((y) - 1))
+#define ROUND_UP(x, y) (((x) + (y) - 1) & ~((y) - 1))
+
+#define UINT16_STRLEN (sizeof("65535"))
+
/*
* Starting from glibc 2.40.9000 and commit 25a5eb4010df ("string: strerror,
* strsignal cannot use buffer after dlmopen (bug 32026)"), strerror() needs
@@ -53,8 +71,6 @@ static inline const char *strerror_(int errnum)
#define strerror(x) @ "Don't call strerror() directly, use strerror_() instead"
-#define ARRAY_SIZE(a) ((int)(sizeof(a) / sizeof((a)[0])))
-
#ifndef __bswap_constant_16
#define __bswap_constant_16(x) \
((uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
diff --git a/flow.c b/flow.c
index 56a6c6d3..91f2b81f 100644
--- a/flow.c
+++ b/flow.c
@@ -680,8 +680,8 @@ static uint64_t flow_hash(const struct ctx *c, uint8_t proto, uint8_t pif,
{
struct siphash_state state = SIPHASH_INIT(c->hash_secret);
- inany_siphash_feed(&state, &side->oaddr);
- inany_siphash_feed(&state, &side->eaddr);
+ siphash_feed_inany(&state, &side->oaddr);
+ siphash_feed_inany(&state, &side->eaddr);
return siphash_final(&state, 38, (uint64_t)proto << 40 |
(uint64_t)pif << 32 |
diff --git a/fwd.c b/fwd.c
index 728a783c..8849cfcd 100644
--- a/fwd.c
+++ b/fwd.c
@@ -80,7 +80,7 @@ static size_t neigh_table_slot(const struct ctx *c,
struct siphash_state st = SIPHASH_INIT(c->hash_secret);
uint32_t i;
- inany_siphash_feed(&st, key);
+ siphash_feed_inany(&st, key);
i = siphash_final(&st, sizeof(*key), 0);
return ((size_t)i) & (NEIGH_TABLE_SIZE - 1);
diff --git a/fwd.h b/fwd.h
index 8f845d09..ac247826 100644
--- a/fwd.h
+++ b/fwd.h
@@ -19,6 +19,7 @@
#include "fwd_rule.h"
struct flowside;
+struct ctx;
#define FWD_NO_HINT (-1)
diff --git a/fwd_rule.h b/fwd_rule.h
index 58551382..f51f1b4b 100644
--- a/fwd_rule.h
+++ b/fwd_rule.h
@@ -13,6 +13,7 @@
#include <net/if.h>
#include <netinet/in.h>
+#include "common.h"
#include "ip.h"
#include "inany.h"
#include "bitmap.h"
diff --git a/inany.c b/inany.c
index 2a586ed1..23faf3ff 100644
--- a/inany.c
+++ b/inany.c
@@ -1,9 +1,19 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later
- * Copyright Red Hat
- * Author: David Gibson <david@gibson.dropbear.id.au>
+// 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
+ *
+ * PESTO - Programmable Extensible Socket Translation Orchestrator
+ * front-end for passt(1) and pasta(1) forwarding configuration
*
* inany.c - Types and helpers for handling addresses which could be
* IPv6 or IPv4 (encoded as IPv4-mapped IPv6 addresses)
+ *
+ * Copyright Red Hat
+ * Author: David Gibson <david@gibson.dropbear.id.au>
*/
#include <stdlib.h>
@@ -13,9 +23,8 @@
#include <arpa/inet.h>
#include <errno.h>
-#include "util.h"
+#include "common.h"
#include "ip.h"
-#include "siphash.h"
#include "inany.h"
#include "fwd.h"
diff --git a/inany.h b/inany.h
index 1f7741d1..73385b91 100644
--- a/inany.h
+++ b/inany.h
@@ -11,13 +11,11 @@
#include <assert.h>
#include <stdbool.h>
+#include <stddef.h>
#include <string.h>
-#include "util.h"
+#include "common.h"
#include "ip.h"
-#include "siphash.h"
-
-struct siphash_state;
/** union inany_addr - Represents either an IPv4 or IPv6 address
* @a6: Address as an IPv6 address, may be IPv4-mapped
@@ -301,17 +299,6 @@ static inline int inany_from_sockaddr(union inany_addr *dst, in_port_t *port,
return -1;
}
-/** inany_siphash_feed- Fold IPv[46] address into an in-progress siphash
- * @state: siphash state
- * @aa: inany to hash
- */
-static inline void inany_siphash_feed(struct siphash_state *state,
- const union inany_addr *aa)
-{
- siphash_feed(state, (uint64_t)aa->u32[0] << 32 | aa->u32[1]);
- siphash_feed(state, (uint64_t)aa->u32[2] << 32 | aa->u32[3]);
-}
-
#define INANY_ADDRSTRLEN MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)
bool inany_matches(const union inany_addr *a, const union inany_addr *b);
diff --git a/pif.h b/pif.h
index d7708603..37409d57 100644
--- a/pif.h
+++ b/pif.h
@@ -16,6 +16,7 @@
union inany_addr;
union sockaddr_inany;
+struct ctx;
/**
* enum pif_type - Type of passt/pasta interface ("pif")
diff --git a/siphash.h b/siphash.h
index bbddcac0..313b8947 100644
--- a/siphash.h
+++ b/siphash.h
@@ -47,6 +47,8 @@
#include <stddef.h>
#include <stdint.h>
+#include "inany.h"
+
/**
* struct siphash_state - Internal state of siphash calculation
*/
@@ -101,6 +103,17 @@ static inline void siphash_feed(struct siphash_state *state, uint64_t in)
state->v[0] ^= in;
}
+/** siphash_feed_inany() - Fold IPv[46] address into an in-progress siphash
+ * @state: siphash state
+ * @aa: inany to hash
+ */
+static inline void siphash_feed_inany(struct siphash_state *state,
+ const union inany_addr *aa)
+{
+ siphash_feed(state, (uint64_t)aa->u32[0] << 32 | aa->u32[1]);
+ siphash_feed(state, (uint64_t)aa->u32[2] << 32 | aa->u32[3]);
+}
+
/**
* siphash_final() - Finalize SipHash calculations
* @v: siphash state (4 x 64-bit integers)
diff --git a/util.h b/util.h
index dc14c78c..70aadeba 100644
--- a/util.h
+++ b/util.h
@@ -29,20 +29,6 @@
#define IP_MAX_MTU USHRT_MAX
#endif
-#ifndef MIN
-#define MIN(x, y) (((x) < (y)) ? (x) : (y))
-#endif
-#ifndef MAX
-#define MAX(x, y) (((x) > (y)) ? (x) : (y))
-#endif
-
-#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
-#define DIV_ROUND_CLOSEST(n, d) (((n) + (d) / 2) / (d))
-#define ROUND_DOWN(x, y) ((x) & ~((y) - 1))
-#define ROUND_UP(x, y) (((x) + (y) - 1) & ~((y) - 1))
-
-#define MAX_FROM_BITS(n) (((1U << (n)) - 1))
-
#define SWAP(a, b) \
do { \
__typeof__(a) __x = (a); (a) = (b); (b) = __x; \
@@ -202,8 +188,6 @@ static inline const char *af_name(sa_family_t af)
}
}
-#define UINT16_STRLEN (sizeof("65535"))
-
/* inet address (- '\0') + port (u16) (- '\0') + ':' + '\0' */
#define SOCKADDR_INET_STRLEN \
(INET_ADDRSTRLEN-1 + UINT16_STRLEN-1 + sizeof(":"))
--
2.53.0
next prev parent reply other threads:[~2026-04-21 6:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 6:24 [PATCH v5 00/18] RFC: Dynamic configuration update implementation David Gibson
2026-04-21 6:24 ` [PATCH v5 01/18] conf, fwd: Stricter rule checking in fwd_rule_add() David Gibson
2026-04-21 6:25 ` [PATCH v5 02/18] fwd_rule: Move ephemeral port probing to fwd_rule.c David Gibson
2026-04-21 6:25 ` [PATCH v5 03/18] fwd, conf: Move rule parsing code to fwd_rule.[ch] David Gibson
2026-04-21 6:25 ` [PATCH v5 04/18] fwd_rule: Move conflict checking back within fwd_rule_add() David Gibson
2026-04-21 6:25 ` [PATCH v5 05/18] fwd: Generalise fwd_rules_info() David Gibson
2026-04-21 6:25 ` [PATCH v5 06/18] pif: Limit pif names to 128 bytes David Gibson
2026-04-21 6:25 ` [PATCH v5 07/18] fwd_rule: Fix some format specifiers David Gibson
2026-04-21 6:25 ` [PATCH v5 08/18] tap, repair: Use SOCK_NONBLOCK and SOCK_CLOEXEC on Unix sockets David Gibson
2026-04-21 6:25 ` [PATCH v5 09/18] pesto: Introduce stub configuration tool David Gibson
2026-04-21 6:25 ` [PATCH v5 10/18] pesto, log: Share log.h (but not log.c) with pesto tool David Gibson
2026-04-21 6:25 ` [PATCH v5 11/18] pesto, conf: Have pesto connect to passt and check versions David Gibson
2026-04-21 6:25 ` [PATCH v5 12/18] pesto: Expose list of pifs to pesto and optionally display David Gibson
2026-04-21 6:25 ` [PATCH v5 13/18] ip: Prepare ip.[ch] for sharing with pesto tool David Gibson
2026-04-21 6:25 ` David Gibson [this message]
2026-04-21 6:25 ` [PATCH v5 15/18] pesto: Read current ruleset from passt/pasta and optionally display it David Gibson
2026-04-21 6:25 ` [PATCH v5 16/18] pesto: Parse and add new rules from command line David Gibson
2026-04-21 6:25 ` [PATCH v5 17/18] pesto, conf: Send updated rules from pesto back to passt/pasta David Gibson
2026-04-21 6:25 ` [PATCH v5 18/18] conf, fwd: Allow switching to new rules received from pesto David Gibson
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=20260421062516.2601204-15-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).