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: [PATCH nft 3/9] datatype: drop flags field from datatype
Date: Fri, 22 Sep 2023 13:18:08 +0200	[thread overview]
Message-ID: <ZQ138B+q7k7qciAP@calendula> (raw)
In-Reply-To: <b23b4f63e2a5a5296820c66262c16b824ea1b6fe.camel@redhat.com>

On Fri, Sep 22, 2023 at 10:51:29AM +0200, Thomas Haller wrote:
> On Thu, 2023-09-21 at 16:23 +0200, Pablo Neira Ayuso wrote:
> > On Wed, Sep 20, 2023 at 09:23:46PM +0200, Thomas Haller wrote:
> > > On Wed, 2023-09-20 at 20:10 +0200, Pablo Neira Ayuso wrote:
> > > > On Wed, Sep 20, 2023 at 04:26:04PM +0200, Thomas Haller wrote:
> > > > > Flags are not always bad. For example, as a function argument
> > > > > they
> > > > > allow
> > > > > easier extension in the future. But with datatype's "flags"
> > > > > argument and
> > > > > enum datatype_flags there are no advantages of this approach.
> > > > > 
> > > > > - replace DTYPE_F_PREFIX with a "bool f_prefix" field. This
> > > > > could
> > > > > even
> > > > >   be a bool:1 bitfield if we cared to represent the information
> > > > > with
> > > > >   one bit only. For now it's not done because that would not
> > > > > help
> > > > > reducing
> > > > >   the size of the struct, so a bitfield is less preferable.
> > > > > 
> > > > > - instead of DTYPE_F_ALLOC, use the refcnt of zero to represent
> > > > > static
> > > > >   instances. Drop this redundant flag.
> > > > 
> > > > Not sure I want to rely on refcnt to zero to identify dynamic
> > > > datatypes. I think we need to consolidate datatype_set() to be
> > > > used
> > > > not only where this deals with dynamic datatypes, it might help
> > > > improve traceability of datatype assignment.
> > > 
> > > I don't understand. Could you elaborate about datatype_set()?
> > 
> > I wonder if we could use datatype_set() to attach static datatypes
> > too, instead of manually attaching datatypes, such as:
> > 
> >         expr->dtype = &integer_type;
> > 
> > in case of future extensions, using consistently this helper function
> > will help to identify datatype attachments.
> 
> I think `expr->dtype = &integer_type` is fine, if
> 
> - expr->dtype doesn't previously point to a datatype that requires
> datatype_free() (e.g. because it's NULL).
> 
> - the new datatype requires no datatype_get() (e.g. because it's
> static).
> 
> > 
> > > Btw, for dynamically allocated instances the refcnt is always
> > > positive,
> > > and for static ones it's always zero. The DTYPE_F_ALLOC flag is
> > > redundant.
> > 
> > That is a correct observation, but a (hipothetical) subtle bug in
> > refcnt might lead to a dynamic datatype get to refcnt to zero, and
> > that might be harder to track?
> > 
> > Let me have a look if I can come up with some counter proposal to get
> > rid of this flag, I would prefer not to infer the datatype class from
> > reference counter value.
> 
> If the reference counting is messed up, there is either a leak, a use-
> after-free or modification of static data.

I am refering to a hypothetical dynamic datatype object reaching
refcnt == 0.

> These are all bad bugs that needs fixing and are avoided by best
> practices and testing.
> 
> IMO keeping redundant state does not help with that or with
> readability.
> 
> I'd like to replace the "unsigned int flags" field with individual
> boolean fields like "bool f_prefix" or "bool f_alloc".

As for f_prefix, there is probably a way to infer this from context,
I would need to have a look.

> Dropping DTYPE_F_ALLOC/f_alloc flag altogether can be done (or not
> done) independently from that.

  reply	other threads:[~2023-09-22 11:18 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-20 14:26 [PATCH nft 0/9] various cleanups related to enums and struct datatype Thomas Haller
2023-09-20 14:26 ` [PATCH nft 1/9] src: fix indentation/whitespace Thomas Haller
2023-09-20 16:03   ` Pablo Neira Ayuso
2023-09-20 14:26 ` [PATCH nft 2/9] include: fix missing definitions in <cache.h>/<headers.h> Thomas Haller
2023-09-20 14:26 ` [PATCH nft 3/9] datatype: drop flags field from datatype Thomas Haller
2023-09-20 18:10   ` Pablo Neira Ayuso
2023-09-20 19:23     ` Thomas Haller
2023-09-21 14:23       ` Pablo Neira Ayuso
2023-09-22  8:51         ` Thomas Haller
2023-09-22 11:18           ` Pablo Neira Ayuso [this message]
2023-09-20 14:26 ` [PATCH nft 4/9] datatype: use "enum byteorder" instead of int in set_datatype_alloc() Thomas Haller
2023-09-20 16:27   ` Pablo Neira Ayuso
2023-09-20 14:26 ` [PATCH nft 5/9] payload: use enum icmp_hdr_field_type in payload_may_dependency_kill_icmp() Thomas Haller
2023-09-20 16:32   ` Pablo Neira Ayuso
2023-09-20 14:26 ` [PATCH nft 6/9] netlink: handle invalid etype in set_make_key() Thomas Haller
2023-09-20 16:22   ` Pablo Neira Ayuso
2023-09-20 16:24   ` Pablo Neira Ayuso
2023-09-20 14:26 ` [PATCH nft 7/9] expression: cleanup expr_ops_by_type() and handle u32 input Thomas Haller
2023-09-20 18:13   ` Pablo Neira Ayuso
2023-09-20 19:28     ` Thomas Haller
2023-09-21 14:19       ` Pablo Neira Ayuso
2023-09-22  8:54         ` Thomas Haller
2023-09-22  9:56           ` Pablo Neira Ayuso
2023-09-25  8:44           ` Pablo Neira Ayuso
2023-09-20 14:26 ` [PATCH nft 8/9] datatype: use __attribute__((packed)) instead of enum bitfields Thomas Haller
2023-09-20 16:02   ` Pablo Neira Ayuso
2023-09-20 17:48     ` Thomas Haller
2023-09-20 18:07       ` Pablo Neira Ayuso
2023-09-20 16:46   ` Pablo Neira Ayuso
2023-09-20 14:26 ` [PATCH nft 9/9] proto: add missing proto_definitions for PROTO_DESC_GENEVE Thomas Haller
2023-09-20 16:14   ` Pablo Neira Ayuso

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=ZQ138B+q7k7qciAP@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).