From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UzHFhll5; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id C58A15A0619 for ; Mon, 04 May 2026 17:37:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777909067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=LWRa6jgXdszbnGXJytCIRyldcpt7mm/wAen2JBogy84=; b=UzHFhll5AFiMFvCNGCr0j1oS2CtH5H4a91FcOY1GNG8VAenHH7rObZDQ1miE7xFEMwLDDO QdLHkDccTRtNOaO+nSZSU8Fj01D63Pr8ND9zDSCE3ulCvLBQQlUPI/I/D+CT2yDP4hnC44 uS247X4JLMOdRZit92LTtGYGH94WP9g= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-100-IsWNQE0sOMakTg9ufPNOMw-1; Mon, 04 May 2026 11:37:46 -0400 X-MC-Unique: IsWNQE0sOMakTg9ufPNOMw-1 X-Mimecast-MFC-AGG-ID: IsWNQE0sOMakTg9ufPNOMw_1777909065 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-43d721a4858so2344098f8f.1 for ; Mon, 04 May 2026 08:37:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777909065; x=1778513865; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LWRa6jgXdszbnGXJytCIRyldcpt7mm/wAen2JBogy84=; b=ZT5NA6scTnVUBMsS69imYWRiEUPYPMRf6xb4oCtq24JoEN8Fz04FEXRYEZEA3LEgkK EA8mSZAr1t+i3UGcz/GxqdmLe1JIH9J/QMd9/f33gLrAXDeyfO2aw6UdgZaCpvsIAeGy hLFFKLkudcPnMPI15beGU0MHqj4dtBZg1htLpLA3vECtYj/J6YVmrsWapXcpwM2/+ina 9F9/u/fisQl3wZBoFDHlAqXQ/pfslesIsG/x42CnYsPKJ/J6KEcvC7MmNO5Gp8Ps+Ft/ bHXgzGAtTzPo3tR8KIYbR5HHk0YMdtzBFF9sNwDbg4JjGGHvB5jEI+JHJa9ZYwPuRrQM HGpg== X-Forwarded-Encrypted: i=1; AFNElJ+huIkx9olAbp8loqgwcdWtpkPzaN1jZ04cKg64HeR/35KBeJgx6z2TaFNvBX6SYLHU7gBwGkCoOmc=@passt.top X-Gm-Message-State: AOJu0YzszR12STTL/XQy7d2elpWVBLLCwgxYPV+Pmt7W6qvM3yklalbx nrBLB/NzkTW7eUEuFxKh/Je3rIOB2Nqj0WrCBhjaqbRjo4wCpFngZoBn2ccqiF5vvkRH8b0hZfv HnOHeaR2lA3aoJb1PzXJuxYkImsKqEPgeXOAY6bisU2CHDaHNdeeg0K1nhbhZkQ== X-Gm-Gg: AeBDieuA/okuq451QH5IvtC9FBRO/A8r12S1mg8rjWcpb2KjmLBS+vQkNkUtNbVQHce YJcjoJd0ZmCZ7TyBmST8Sfp9VqIshe4hNYgRvTsXa0QikfBJpb4aS6QqwHeooAIH2IvoBkX/hoK V+YmLfr2IPaiXRGYF0SuDnbgK6ivh6idqSM+o+b+KHIvlJ5blLf1mf6BT5QZiyLG0gNPiLq4JzG BcOpJvtcZRbgCzRJqZzNhxoxWL5K/adaBz/h0+W4DYDT/OLH+2Oi16vpuevcVYIlnGR3ci2OSAa hA9p7pRdIjEqXXLGwCmrWZ+xE37ALXsGH/nkF3ZWEHY3DgOnmbV7tegqxMoQ9lrrqbvh02Hrqoq TYYsq1sVdT36lqhV/G+39We+5Ghsf9NwF4QqXE6qtF+9hGMpi+n1sxk//xRHdLPTqfg== X-Received: by 2002:a5d:5d81:0:b0:43d:7783:c684 with SMTP id ffacd0b85a97d-44bb66d5c0fmr17346927f8f.43.1777909065001; Mon, 04 May 2026 08:37:45 -0700 (PDT) X-Received: by 2002:a5d:5d81:0:b0:43d:7783:c684 with SMTP id ffacd0b85a97d-44bb66d5c0fmr17346852f8f.43.1777909064456; Mon, 04 May 2026 08:37:44 -0700 (PDT) Received: from [192.168.100.100] (82-64-211-94.subs.proxad.net. [82.64.211.94]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-44b638ac434sm23066551f8f.36.2026.05.04.08.37.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 May 2026 08:37:43 -0700 (PDT) Message-ID: Date: Mon, 4 May 2026 17:37:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 13/18] inany: Prepare inany.[ch] for sharing with pesto tool To: Stefano Brivio , passt-dev@passt.top References: <20260503215601.823029-1-sbrivio@redhat.com> <20260503215601.823029-14-sbrivio@redhat.com> From: Laurent Vivier Autocrypt: addr=lvivier@redhat.com; keydata= xsFNBFYFJhkBEAC2me7w2+RizYOKZM+vZCx69GTewOwqzHrrHSG07MUAxJ6AY29/+HYf6EY2 WoeuLWDmXE7A3oJoIsRecD6BXHTb0OYS20lS608anr3B0xn5g0BX7es9Mw+hV/pL+63EOCVm SUVTEQwbGQN62guOKnJJJfphbbv82glIC/Ei4Ky8BwZkUuXd7d5NFJKC9/GDrbWdj75cDNQx UZ9XXbXEKY9MHX83Uy7JFoiFDMOVHn55HnncflUncO0zDzY7CxFeQFwYRbsC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j4XjVpL8+2x OhXKrM1fzzb8JtAuSbuzZSQPDwQEI5CKKxp7zf76J21YeRrEW4WDznPyVcDTa+tz++q2S/Bp P4W98bXCBIuQgs2m+OflERv5c3Ojldp04/S4NEjXEYRWdiCxN7ca5iPml5gLtuvhJMSy36gl U6IW9kn30IWuSoBpTkgV7rLUEhh9Ms82VWW/h2TxL8enfx40PrfbDtWwqRID3WY8jLrjKfTd R3LW8BnUDNkG+c4FzvvGUs8AvuqxxyHbXAfDx9o/jXfPHVRmJVhSmd+hC3mcQ+4iX5bBPBPM oDqSoLt5w9GoQQ6gDVP2ZjTWqwSRMLzNr37rJjZ1pt0DCMMTbiYIUcrhX8eveCJtY7NGWNyx FCRkhxRuGcpwPmRVDwOl39MB3iTsRighiMnijkbLXiKoJ5CDVvX5yicNqYJPKh5MFXN1bvsB kmYiStMRbrD0HoY1kx5/VozBtc70OU0EB8Wrv9hZD+Ofp0T3KOr1RUHvCZoLURfFhSQ= In-Reply-To: <20260503215601.823029-14-sbrivio@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: wMbZBJA5uVS2Arzb-sHUV3U4pviZkn9iHoKTiexcyhI_1777909065 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: 6UWNOJJ45U46JLQ236GYJHC2ORGTDWDX X-Message-ID-Hash: 6UWNOJJ45U46JLQ236GYJHC2ORGTDWDX X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Jon Maloy , David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 5/3/26 23:55, Stefano Brivio wrote: > From: David Gibson > > 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 > Signed-off-by: Stefano Brivio Reviewed-by: Laurent Vivier > --- > 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 4a167ae..370cfa1 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 56a6c6d..91f2b81 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 728a783..8849cfc 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 8f845d0..ac24782 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 5855138..f51f1b4 100644 > --- a/fwd_rule.h > +++ b/fwd_rule.h > @@ -13,6 +13,7 @@ > #include > #include > > +#include "common.h" > #include "ip.h" > #include "inany.h" > #include "bitmap.h" > diff --git a/inany.c b/inany.c > index 2a586ed..23faf3f 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 > +// 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 > */ > > #include > @@ -13,9 +23,8 @@ > #include > #include > > -#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 1f7741d..73385b9 100644 > --- a/inany.h > +++ b/inany.h > @@ -11,13 +11,11 @@ > > #include > #include > +#include > #include > > -#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 d770860..37409d5 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 bbddcac..313b894 100644 > --- a/siphash.h > +++ b/siphash.h > @@ -47,6 +47,8 @@ > #include > #include > > +#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 dc14c78..70aadeb 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(":"))