public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Subject: Re: [PATCH 1/8] Improve types and names for port forwarding configuration
Date: Sat, 24 Sep 2022 08:28:32 +0200	[thread overview]
Message-ID: <20220924082832.6314f9ec@elisabeth> (raw)
In-Reply-To: <Yy5yFVvyQD0QkvtT@yekko>

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

On Sat, 24 Sep 2022 12:57:25 +1000
David Gibson <david(a)gibson.dropbear.id.au> wrote:

> On Sat, Sep 24, 2022 at 12:52:57AM +0200, Stefano Brivio wrote:
> > On Fri, 23 Sep 2022 14:57:59 +1000
> > David Gibson <david(a)gibson.dropbear.id.au> wrote:
> >   
> > > [...]
> > > 
> > > --- /dev/null
> > > +++ b/port_fwd.h
> > > @@ -0,0 +1,19 @@
> > > +/* SPDX-License-Identifier: AGPL-3.0-or-later
> > > + * Copyright Red Hat
> > > + * Author: Stefano Brivio <sbrivio(a)redhat.com>
> > > + * Author: David Gibson <david(a)gibson.dropbear.id.au>
> > > + */
> > > +
> > > +#ifndef PORT_FWD_H
> > > +#define PORT_FWD_H
> > > +
> > > +enum port_fwd_mode {
> > > +	FWD_SPEC = 1,
> > > +	FWD_NONE,
> > > +	FWD_AUTO,
> > > +	FWD_ALL,
> > > +};
> > > +
> > > +typedef uint8_t port_fwd_map[DIV_ROUND_UP(USHRT_MAX, 8)];  
> > 
> > Given that this gets conveniently embedded in a struct in 2/8, could we
> > avoid the typedef (or perhaps drop it after 2/8)? It makes the actual
> > type less obvious to figure out, and in general I agree with most
> > points from this slide deck:
> > 
> >   http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/mgp00025.html  
> 
> As do I, in fact especially for array types, due to their
> idiosyncratic handling in C.
> 
> > :) ...well, unless there's some resulting complexity I'm missing.  
> 
> Well, maybe.  I added the typedef because of two things: 1) the fact
> that in one place we use a bitmap of this format separately from the
> rest for the 'exclude' map in conf_ports().  2) the fact that we need
> the size of this map in get_bound_ports().  Having the typedef lets us
> handle both without duplicating the calculation of the size, which
> would mean more opportunities to get it wrong.

I see, but at the same time:

- forgetting to use the new type should be as easy as forgetting to use
  a define representing the size

- the risk of doing stupid things (such as trying to pass this by
  value), despite the clear name of the typedef, looks to me slightly
  bigger than with "uint8_t ports[SIZE_PORTS]"

> I feel the advantages outweigh the disadvantages of a typedef in this
> case, but I won't be offended if you disagree.  We could use a #define
> or const of the bitmap size instead.

Well, I see now, and I don't have such a strong preference anymore...
even though I would still prefer the define (perhaps SIZE_PORTS, based
on NUM_PORTS from 7/8?).

Also introducing the first typedef in the whole project for something
we can implement almost equivalently, hmm.

I don't know, if you still think it's clearly better than the
alternative, let's go with it, I just have a slight preference against
it at this point.

-- 
Stefano


  reply	other threads:[~2022-09-24  6:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23  4:57 [PATCH 0/8] Clean up and fix bugs in port forwarding data structures David Gibson
2022-09-23  4:57 ` [PATCH 1/8] Improve types and names for port forwarding configuration David Gibson
2022-09-23 22:52   ` Stefano Brivio
2022-09-24  2:57     ` David Gibson
2022-09-24  6:28       ` Stefano Brivio [this message]
2022-09-24  9:06         ` David Gibson
2022-09-23  4:58 ` [PATCH 2/8] Consolidate port forwarding configuration into a common structure David Gibson
2022-09-23  4:58 ` [PATCH 3/8] udp: Delay initialization of UDP reversed port mapping table David Gibson
2022-09-23  4:58 ` [PATCH 4/8] Don't use indirect remap functions for conf_ports() David Gibson
2022-09-23  4:58 ` [PATCH 5/8] Pass entire port forwarding configuration substructure to conf_ports() David Gibson
2022-09-23  4:58 ` [PATCH 6/8] Treat port numbers as unsigned David Gibson
2022-09-23  4:58 ` [PATCH 7/8] Fix widespread off-by-one error dealing with port numbers David Gibson
2022-09-23  4:58 ` [PATCH 8/8] icmp: Correct off by one errors dealing with number of echo request ids 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=20220924082832.6314f9ec@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=passt-dev@passt.top \
    /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).