From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH v4 02/14] conf, fwd: Keep a table of our port forwarding configuration
Date: Fri, 16 Jan 2026 11:48:04 +1100 [thread overview]
Message-ID: <aWmKxDQm2A7MOa5x@zatzit> (raw)
In-Reply-To: <20260116012554.549c4cd3@elisabeth>
[-- Attachment #1: Type: text/plain, Size: 3545 bytes --]
On Fri, Jan 16, 2026 at 01:25:54AM +0100, Stefano Brivio wrote:
> On Fri, 16 Jan 2026 11:20:43 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
>
> > On Fri, Jan 16, 2026 at 12:01:27AM +0100, Stefano Brivio wrote:
> > > On Thu, 15 Jan 2026 19:50:33 +1100
> > > David Gibson <david@gibson.dropbear.id.au> wrote:
> > >
> > > > @@ -313,6 +330,90 @@ bool fwd_port_is_ephemeral(in_port_t port)
> > > > return (port >= fwd_ephemeral_min) && (port <= fwd_ephemeral_max);
> > > > }
> > > >
> > > > +/**
> > > > + * fwd_rule_add() - Add a rule to a forwarding table
> > > > + * @fwd: Table to add to
> > > > + * @flags: Flags for this entry
> > > > + * @addr: Our address to forward (NULL for both 0.0.0.0 and ::)
> > > > + * @ifname: Only forward from this interface name, if non-empty
> > > > + * @first: First port number to forward
> > > > + * @last: Last port number to forward
> > > > + * @to: First port of target port range to map to
> > > > + */
> > > > +void fwd_rule_add(struct fwd_ports *fwd, uint8_t flags,
> > > > + const union inany_addr *addr, const char *ifname,
> > > > + in_port_t first, in_port_t last, in_port_t to)
> > > > +{
> > > > + /* Flags which can be set from the caller */
> > > > + const uint8_t allowed_flags = FWD_WEAK;
> > > > + struct fwd_rule *new;
> > > > + unsigned port;
> > > > +
> > > > + ASSERT(!(flags & ~allowed_flags));
> > > > +
> > > > + if (fwd->count >= ARRAY_SIZE(fwd->rules))
> > > > + die("Too many port forwarding ranges");
> > > > +
> > > > + new = &fwd->rules[fwd->count++];
> > > > + new->flags = flags;
> > > > +
> > > > + if (addr) {
> > > > + new->addr = *addr;
> > > > + } else {
> > > > + new->addr = inany_any6;
> > > > + new->flags |= FWD_DUAL_STACK_ANY;
> > > > + }
> > > > +
> > > > + memset(new->ifname, 0, sizeof(new->ifname));
> > > > + if (ifname) {
> > > > + if (strlen(ifname) + 1 > sizeof(new->ifname))
> > > > + die("Interface name %s is too long", ifname);
> > > > + strncpy(new->ifname, ifname, sizeof(new->ifname));
> > > > + }
> > >
> > > This looks safe to me now, but:
> > >
> > > /home/sbrivio/passt/fwd.c:394:3:
> > > Type: Buffer not null terminated (BUFFER_SIZE)
> > [snip]
> > > ...perhaps worth switching to the usual snprintf() approach with return
> > > check (see handling of c->ip4.ifname_out in conf()) and be done with it?
> >
> > Good idea, not sure why it didn't occur to me earlier.
> >
> > I've done that, and verified it fixes the coverity error (thanks for
> > resending the instructions for that).
> >
> > > I'd be slightly more confident if Coverity Scan didn't complain at all
> > > (and happier without the noise, too).
> > >
> > > Other than that, this version looks good to me. I would make a new
> > > release just before merging it (with this "fixed") so that we can debug
> > > things a bit more conveniently should something go wrong with it.
> >
> > That sounds wise. Do you want a new spin with the coverity fix? Just
> > this patch? Something else?
>
> Yes, thanks, a respin would be nice, so that we have a reasonable
> "permalink" to it, given it's a quite fundamental feature you're adding
> and we might want to refer to the series as posted / applied.
Ok. Will do that as soon as this test run completes.
--
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-16 0:48 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-15 8:50 [PATCH v4 00/14] Introduce forwarding table David Gibson
2026-01-15 8:50 ` [PATCH v4 01/14] inany: Extend inany_ntop() to treat NULL as a fully unspecified address David Gibson
2026-01-15 8:50 ` [PATCH v4 02/14] conf, fwd: Keep a table of our port forwarding configuration David Gibson
2026-01-15 23:01 ` Stefano Brivio
2026-01-16 0:20 ` David Gibson
2026-01-16 0:25 ` Stefano Brivio
2026-01-16 0:48 ` David Gibson [this message]
2026-01-15 8:50 ` [PATCH v4 03/14] conf: Accurately record ifname and address for outbound forwards David Gibson
2026-01-15 8:50 ` [PATCH v4 04/14] conf, fwd: Record "auto" port forwards in forwarding table David Gibson
2026-01-15 8:50 ` [PATCH v4 05/14] fwd: Make space to store listening sockets in forward table David Gibson
2026-01-15 8:50 ` [PATCH v4 06/14] ip: Add ipproto_name() function David Gibson
2026-01-15 8:50 ` [PATCH v4 07/14] fwd, tcp, udp: Set up listening sockets based on forward table David Gibson
2026-01-15 8:50 ` [PATCH v4 08/14] tcp, udp: Remove old auto-forwarding socket arrays David Gibson
2026-01-15 8:50 ` [PATCH v4 09/14] conf, fwd: Check forwarding table for conflicting rules David Gibson
2026-01-15 8:50 ` [PATCH v4 10/14] fwd: Generate auto-forward exclusions from socket fd tables David Gibson
2026-01-15 8:50 ` [PATCH v4 11/14] flow, fwd: Consult rules table when forwarding a new flow from socket David Gibson
2026-01-15 8:50 ` [PATCH v4 12/14] fwd: Remap ports based directly on forwarding rule David Gibson
2026-01-15 8:50 ` [PATCH v4 13/14] fwd, tcp, udp: Add forwarding rule to listening socket epoll references David Gibson
2026-01-15 8:50 ` [PATCH v4 14/14] flow, fwd: Optimise forwarding rule lookup using epoll ref when possible 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=aWmKxDQm2A7MOa5x@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).