netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Thomas Haller <thaller@redhat.com>
Cc: NetFilter <netfilter-devel@vger.kernel.org>
Subject: Re: [nft PATCH v2] src: use reentrant getprotobyname_r()/getprotobynumber_r()/getservbyport_r()
Date: Fri, 18 Aug 2023 18:10:23 +0200	[thread overview]
Message-ID: <ZN+X76/KObT2EOrg@calendula> (raw)
In-Reply-To: <5541fc793b4346e2f00eaf3e7f18c754053d8d00.camel@redhat.com>

On Fri, Aug 18, 2023 at 04:14:01PM +0200, Thomas Haller wrote:
> Hi Pablo,
> 
> On Fri, 2023-08-18 at 11:57 +0200, Pablo Neira Ayuso wrote:
> > 
> > > -       struct protoent *p;
> > > -
> > >         if (!nft_output_numeric_proto(octx)) {
> > > -               p = getprotobynumber(mpz_get_uint8(expr->value));
> > > -               if (p != NULL) {
> > > -                       nft_print(octx, "%s", p->p_name);
> > > +               char name[1024];
> > 
> > Is there any definition that could be used instead of 1024. Same
> > comment for all other hardcoded buffers. Or maybe add a definition
> > for
> > this?
> 
> Added defines instead. See v3.
> 
> [...]
> 
> > >  #include <nftables.h>
> > >  #include <utils.h>
> > > @@ -105,3 +106,90 @@ int round_pow_2(unsigned int n)
> > >  {
> > >         return 1UL << fls(n - 1);
> > >  }
> > > +
> > 
> > Could you move this new code to a new file instead of utils.c? We are
> > slowing moving towards GPLv2 or any later for new code. Probably
> > netdb.c or pick a better name that you like.
> 
> This request leaves me with a lot of choices. I made them, but I guess
> you will have something to say about it. See v3.
> 
> > 
> > > +bool nft_getprotobynumber(int proto, char *out_name, size_t
> > > name_len)
> > > +{
> > > +       const struct protoent *result;
> > > +
> > > +#if HAVE_DECL_GETPROTOBYNUMBER_R
> > > +       struct protoent result_buf;
> > > +       char buf[2048];
> > > +       int r;
> > > +
> > > +       r = getprotobynumber_r(proto,
> > > +                              &result_buf,
> > > +                              buf,
> > > +                              sizeof(buf),
> > > +                              (struct protoent **) &result);
> > > +       if (r != 0 || result != &result_buf)
> > > +               result = NULL;
> > > +#else
> > > +       result = getprotobynumber(proto);
> > > +#endif
> > 
> > I'd suggest wrap this code with #ifdef's in a helper function.
> 
> I don't understand. nft_getprotobynumber() *is* that helper function to
> wrap the #if. This point is not addressed by v3 (??).

I mean, something like a smaller function:

static struct __nft_getprotobynumber(...)

that is wraps this code above and it returns const struct protoent.
This helper function is called from nft_getprotobynumber().

But it is fine as it is, this is just a bit of bike shedding.

  reply	other threads:[~2023-08-18 16:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-10 12:30 [nft PATCH] src: use reentrant getprotobyname_r()/getprotobynumber_r()/getservbyport_r() Thomas Haller
2023-08-10 21:48 ` Jan Engelhardt
2023-08-11 11:28   ` Thomas Haller
2023-08-11 12:20 ` Pablo Neira Ayuso
2023-08-11 12:58   ` Thomas Haller
2023-08-16 16:16     ` Pablo Neira Ayuso
2023-08-18  9:18 ` [nft PATCH v2] " Thomas Haller
2023-08-18  9:57   ` Pablo Neira Ayuso
2023-08-18 14:14     ` Thomas Haller
2023-08-18 16:10       ` Pablo Neira Ayuso [this message]
2023-08-18 16:23         ` Pablo Neira Ayuso
2023-08-18 17:38         ` Thomas Haller

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=ZN+X76/KObT2EOrg@calendula \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=thaller@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.
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 NNTP newsgroup(s).