From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v3 07/14] fwd, tcp, udp: Set up listening sockets based on forward table
Date: Wed, 14 Jan 2026 10:59:20 +1100 [thread overview]
Message-ID: <aWbcWPQhVJ2f7qTE@zatzit> (raw)
In-Reply-To: <20260113231336.0711e84a@elisabeth>
[-- Attachment #1: Type: text/plain, Size: 4152 bytes --]
On Tue, Jan 13, 2026 at 11:13:36PM +0100, Stefano Brivio wrote:
> On Tue, 13 Jan 2026 16:38:58 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
>
> > On Tue, Jan 13, 2026 at 12:26:36AM +0100, Stefano Brivio wrote:
> > > On Thu, 8 Jan 2026 13:29:41 +1100
> > > David Gibson <david@gibson.dropbear.id.au> wrote:
> > >
> > > > Previously we created inbound listening sockets as we parsed the forwarding
> > > > options (-t, -u) whereas outbound listening sockets were created during
> > > > {tcp,udp}_init(). Now that we have a data structure recording the full
> > > > details of the listening options we can move all listening socket creation
> > > > to {tcp,udp}_init(). This means that errors for either direction are
> > > > detected and reported the same way.
> > > >
> > > > Introduce fwd_listen_sync() which synchronizes the state of listening
> > > > sockets to the forwarding rules table, both for fixed and automatic
> > > > forwards.
> > > >
> > > > This does cause a change in semantics for "exclude only" port
> > > > specifications. Previously an option like -t ~6000 wouldn't cause a
> > > > fatal error, as long as we could bind at least one port. Now, it
> > > > requires at least one port for each generated rule; that is for each
> > > > of the contiguous blocks of ports the specification resolves to. With
> > > > typical ephemeral ports settings that's one port each in 1..5999,
> > > > 6001..32767 and 61000..65535.
> > > >
> > > > Preserving the exact behaviour for this case would require a considerably
> > > > more complex data structure, so I'm hoping this is a sufficiently niche
> > > > case for the change to be acceptable.
> > >
> > > I guess so too, I wouldn't really worry.
> > >
> > > Well, I'm not sure if it works, but one relatively simple idea could be
> > > to have a "with_prev" bit in the rule struct representing the fact that
> > > the current rule was derived from the same port specification as the
> > > previous rule, which implies they would need to be deleted all together
> > > (but we can happily enforce that).
> > >
> > > Then, in the fwd_listen_sync_() loop, before reporting failure, you
> > > would check the next entry: if the "with_prev" bit is set, report
> > > failure only if we fail (keeping a local boolean flag) for all the
> > > entries up to the first one with "with_prev" unset.
> >
> > I'll keep that approach in mind if it seems like we need it.
> >
> > > I would be inclined to say it's worth it if it's that simple, but I
> > > haven't tried, so I might be very well missing something.
> >
> > I also considered making WEAK mean we'd always continue on listen
> > failures, even if all of them fail. Maybe that's a bit unexpected?
> > But it would allow an option to "forward single port X, if you can"
> > which seems like it might be useful.
>
> I think that's a different feature, perhaps it would need its own flag.
> But I don't think we should have it on by default with the current
> command-line interface.
>
> Perhaps the client should have a different command/specifier to add a
> set of ranges which can all fail entirely. But I guess it risks being a
> bit too much for the command line.
That's fair.
Hmm... for the client protocol, we could potentially return the number
of sockets we managed to bind(), and the client could decide if it's
good enough. Setting up a listening rule already can't really be
atomic, so I think it's probably ok for the client to have to
explicitly delete/rollback.
Not sure if that's a good idea, but it's a thought.
> By the way, that should make more sense once we add the possibility of
> specifying ports or ranges for automatic port forwarding, or for
> https://bugs.passt.top/show_bug.cgi?id=131, because at that point it
> becomes "when you can"... and we would already have that implemented,
> actually.
Right.
--
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 --]
next prev parent reply other threads:[~2026-01-14 0:42 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-08 2:29 [PATCH v3 00/14] Introduce forwarding table David Gibson
2026-01-08 2:29 ` [PATCH v3 01/14] inany: Extend inany_ntop() to treat NULL as a fully unspecified address David Gibson
2026-01-08 13:16 ` Laurent Vivier
2026-01-08 2:29 ` [PATCH v3 02/14] conf, fwd: Keep a table of our port forwarding configuration David Gibson
2026-01-12 23:26 ` Stefano Brivio
2026-01-13 5:12 ` David Gibson
2026-01-13 22:13 ` Stefano Brivio
2026-01-13 23:53 ` David Gibson
2026-01-08 2:29 ` [PATCH v3 03/14] conf: Accurately record ifname and address for outbound forwards David Gibson
2026-01-08 2:29 ` [PATCH v3 04/14] conf, fwd: Record "auto" port forwards in forwarding table David Gibson
2026-01-12 23:26 ` Stefano Brivio
2026-01-13 5:14 ` David Gibson
2026-01-08 2:29 ` [PATCH v3 05/14] fwd: Make space to store listening sockets in forward table David Gibson
2026-01-12 23:26 ` Stefano Brivio
2026-01-13 5:28 ` David Gibson
2026-01-13 22:13 ` Stefano Brivio
2026-01-13 23:57 ` David Gibson
2026-01-08 2:29 ` [PATCH v3 06/14] ip: Add ipproto_name() function David Gibson
2026-01-08 13:22 ` Laurent Vivier
2026-01-08 23:12 ` David Gibson
2026-01-08 2:29 ` [PATCH v3 07/14] fwd, tcp, udp: Set up listening sockets based on forward table David Gibson
2026-01-12 23:26 ` Stefano Brivio
2026-01-13 5:38 ` David Gibson
2026-01-13 22:13 ` Stefano Brivio
2026-01-13 23:59 ` David Gibson [this message]
2026-01-08 2:29 ` [PATCH v3 08/14] tcp, udp: Remove old auto-forwarding socket arrays David Gibson
2026-01-08 2:29 ` [PATCH v3 09/14] conf, fwd: Check forwarding table for conflicting rules David Gibson
2026-01-12 23:26 ` Stefano Brivio
2026-01-13 5:41 ` David Gibson
2026-01-08 2:29 ` [PATCH v3 10/14] fwd: Generate auto-forward exclusions from socket fd tables David Gibson
2026-01-08 2:29 ` [PATCH v3 11/14] flow, fwd: Consult rules table when forwarding a new flow from socket David Gibson
2026-01-13 22:12 ` Stefano Brivio
2026-01-14 0:09 ` David Gibson
2026-01-08 2:29 ` [PATCH v3 12/14] fwd: Remap ports based directly on forwarding rule David Gibson
2026-01-13 22:12 ` Stefano Brivio
2026-01-14 0:24 ` David Gibson
2026-01-08 2:29 ` [PATCH v3 13/14] fwd, tcp, udp: Add forwarding rule to listening socket epoll references David Gibson
2026-01-13 22:12 ` Stefano Brivio
2026-01-14 0:37 ` David Gibson
2026-01-08 2:29 ` [PATCH v3 14/14] flow, fwd: Optimise forwarding rule lookup using epoll ref when possible David Gibson
2026-01-13 22:13 ` Stefano Brivio
2026-01-14 1:06 ` 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=aWbcWPQhVJ2f7qTE@zatzit \
--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).