public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Jon Maloy <jmaloy@redhat.com>
Cc: sbrivio@redhat.com, passt-dev@passt.top
Subject: Re: [PATCH v8 02/14] passt, pasta: Introduce unified multi-address data structures
Date: Mon, 13 Jul 2026 14:16:47 +1000	[thread overview]
Message-ID: <alRmpPa3-2FDeWJf@zatzit> (raw)
In-Reply-To: <769f4409-c317-4736-98b3-6fe8f6d4078d@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 4142 bytes --]

On Fri, Jul 10, 2026 at 05:31:23PM -0400, Jon Maloy wrote:
> > > -	if (!ip4->prefix_len) {
> > > -		in_addr_t addr = ntohl(ip4->addr.s_addr);
> > > -		if (IN_CLASSA(addr))
> > > -			ip4->prefix_len = (32 - IN_CLASSA_NSHIFT);
> > > -		else if (IN_CLASSB(addr))
> > > -			ip4->prefix_len = (32 - IN_CLASSB_NSHIFT);
> > > -		else if (IN_CLASSC(addr))
> > > -			ip4->prefix_len = (32 - IN_CLASSC_NSHIFT);
> > > -		else
> > > -			ip4->prefix_len = 32;
> > > +		fwd_set_addr(c, &inany_from_v4(addr), CONF_ADDR_HOST,
> > > +			     prefix_len + 96);
> > >   	}
> > > -	ip4->addr_seen = ip4->addr;
> > > -
> > > +	a = fwd_get_addr(c, AF_INET, CONF_ADDR_ANY, 0);
> > 
> > Nit: maybe assert(a), since I doubt static checkers will be able to
> > reason that the fwd_set_addr() above means this fwd_get_addr() can't
> > fail.  Also, I think that go inside the if block, since the other case
> > means we already have a perfectly good a.
> 
> I think my conclusion was that the static checker ignores assert() as a
> conditonal test, but I can try it.

I'm not really sure what you mean by this.  I don't know for certain
with this particular case and each static checker.  I do know that
there are a *heap* of cases where an assert() can fix static checker
warnings because it lets the checker know we can't have reached this
point in the "bad" condition.

[snip]
> > > +/**
> > > + * struct guest_addr - Unified IPv4/IPv6 address entry
> > > + * @addr:	IPv4 (as mapped) or IPv6 address
> > > + * @prefix_len:	Prefix length in IPv6/IPv4-mapped [0,128]/[96,128] format
> > > + * @flags:	CONF_ADDR_* flags
> > > + */
> > > +struct guest_addr {
> > > +	union inany_addr addr;
> > > +	uint8_t prefix_len;
> > > +	uint8_t flags;
> > > +#define CONF_ADDR_USER		BIT(0)		/* User set via -a */
> > > +#define CONF_ADDR_HOST		BIT(1)		/* From host interface */
> > > +#define CONF_ADDR_GENERATED	BIT(2)		/* Generated by PASST/PASTA */
> > > +#define CONF_ADDR_LINKLOCAL	BIT(3)		/* Link-local address */
> > > +#define CONF_ADDR_ANY		0xff		/* Match any flag */
> > 
> > In general I like CONF_ADDR_ANY instead of 0 being special-cased.  But
> > with LINKLOCAL in the mix it doesn't quite work.  ANY meaning "USER or
> > HOST or GENERATED" makes sense.  ANY meaning "USER or HOST or
> > GENERATED or LINKLOCAL" is nonsense.  I suggest you move LINKLOCAL
> > into a different field, as Stefano has suggested to handle this (maybe
> > "provenance" for USER/HOST/GENERATED and "flags" for LINKLOCAL?).  Or
> > you could remove the LINKLOCAL flag from the structure entirely: the
> > information is already present in the address itself.
> 
> I was hoping to postpone this to a commit after this series, but I see your
> point. I can try with a 'scope' field, as suggested earlier, or just skip it
> altogheter and using an is_link_local() function.

Sorry, I thought there was already an inany_is_linklocal() function,
but I see that there's only inany_is_linklocal6().  So that will need
to be extended to handle IPv4 as well.

[snip]
> > > diff --git a/pasta.c b/pasta.c
> > > index 4e7ee542..9ef3ac00 100644
> > > --- a/pasta.c
> > > +++ b/pasta.c
> > > @@ -330,6 +330,8 @@ void pasta_ns_conf(struct ctx *c)
> > >   	if (c->pasta_conf_ns) {
> > >   		unsigned int flags = IFF_UP;
> > > +		const struct guest_addr *a;
> > > +		int plen = 0;
> > >   		if (c->mtu)
> > >   			nl_link_set_mtu(nl_sock_ns, c->pasta_ifi, c->mtu);
> > > @@ -341,10 +343,17 @@ void pasta_ns_conf(struct ctx *c)
> > >   		if (c->ifi4) {
> > 
> > Nit: I think you can reduce the very deep nesting here, by moving the
> > fwd_get_addr() and changing the if below to..
> 
> This is already done in a later patch, by introducing two subfuntions.
> However, this has caused lot of trouble at each rebase, so I think I will
> move it to a separate, standalone patch before this series.

Sounds like a good idea.

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2026-07-13  5:39 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26  2:45 [PATCH v8 00/14] Introduce multiple addresses Jon Maloy
2026-06-26  2:45 ` [PATCH v8 01/14] dhcpv6: Fix reply destination to match client's source address Jon Maloy
2026-07-09  3:01   ` David Gibson
2026-06-26  2:45 ` [PATCH v8 02/14] passt, pasta: Introduce unified multi-address data structures Jon Maloy
2026-07-09  4:05   ` David Gibson
2026-07-09  5:56     ` David Gibson
2026-07-09  5:59       ` David Gibson
2026-07-10 21:40       ` Jon Maloy
2026-07-10 21:31     ` Jon Maloy
2026-07-13  4:16       ` David Gibson [this message]
2026-06-26  2:45 ` [PATCH v8 03/14] tap, conf: Replace addr_fixed with CONF_ADDR_USER flag check Jon Maloy
2026-06-26  2:45 ` [PATCH v8 04/14] fwd: Unify guest accessibility checks with unified address array Jon Maloy
2026-06-26  2:45 ` [PATCH v8 05/14] arp: Check all configured addresses in ARP filtering Jon Maloy
2026-06-26  2:45 ` [PATCH v8 06/14] conf: Allow multiple -a/--address options per address family Jon Maloy
2026-06-26  2:45 ` [PATCH v8 07/14] netlink, conf: Read all addresses from template interface at startup Jon Maloy
2026-06-26  2:45 ` [PATCH v8 08/14] netlink, pasta: refactor function pasta_ns_conf() Jon Maloy
2026-06-26  2:45 ` [PATCH v8 09/14] conf, pasta: Track observed guest IPv4 addresses in unified address array Jon Maloy
2026-06-26  2:45 ` [PATCH v8 10/14] conf, pasta: Track observed guest IPv6 " Jon Maloy
2026-06-26  2:45 ` [PATCH v8 11/14] dhcp: Select address for DHCP distribution Jon Maloy
2026-06-26  2:45 ` [PATCH v8 12/14] dhcpv6: Select addresses for DHCPv6 distribution Jon Maloy
2026-06-26  2:45 ` [PATCH v8 13/14] ndp: Support advertising multiple prefixes in Router Advertisements Jon Maloy
2026-06-26  2:45 ` [PATCH v8 14/14] migrate: Update protocol to v3 for multi-address support Jon Maloy

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=alRmpPa3-2FDeWJf@zatzit \
    --to=david@gibson.dropbear.id.au \
    --cc=jmaloy@redhat.com \
    --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).