All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org, richard@nod.at, fw@strlen.de
Subject: Re: [PATCH nf-next,RFC 1/3] netfilter: nf_conntrack: add 64-bit conntrack ID extension
Date: Tue, 28 Nov 2017 13:16:52 +0100	[thread overview]
Message-ID: <20171128121652.GH23412@breakpoint.cc> (raw)
In-Reply-To: <20171128021309.11277-1-pablo@netfilter.org>

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> This patch adds a 64-bit conntrack ID extension that allows userspace to
> uniquely identify a conntrack object.
> 
> The existing 32-bit ID is not good to uniquely identify a conntrack
> object. Long time ago, this used to be an incremental number that could
> quickly wrap around. Someone suggested to use 64-bits, back then this
> was considered to be too much memory for just an ID. So we usually
> suggested to users that they should combine it with the conntrack tuple
> to achieve a way to uniquely conntrack objects. This has always
> generated a bit of controversy since userspace applications needed to
> deal with extra work.
> 
> At some point, someone remove the explicit ct->id field that we used to
> have to save memory space. This ID was modified to part of its memory
> address. Howeover, this is a problem because objects can be quickly
> recycled with the slab-by-rcu approach that we use these days. So even
> combining this 32-bit ID with the tuple doesn't ensure that this is
> unique. Moreover, this is leaking the pointer to userspace in 32-bit
> arches, which is not good.
> 
> So let's introduce a 64-bit unique ID that ensures no overlaps. This is
> only allocated once in the first packet, and never ever again from the
> hot path, so let's keep this in a separated extension not to grab more
> cachelines.
> 
> ID assignment is lockless: this patch divides the 64-bit space between
> the existing CPUs, so they can freely allocate IDs in their space.
> 
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
>  include/net/netfilter/nf_conntrack_extend.h |  2 ++
>  include/net/netfilter/nf_conntrack_id.h     | 51 +++++++++++++++++++++++++++++
>  include/net/netns/conntrack.h               |  1 +
>  net/netfilter/Makefile                      |  2 +-
>  net/netfilter/nf_conntrack_core.c           | 18 +++++++++-
>  net/netfilter/nf_conntrack_id.c             | 48 +++++++++++++++++++++++++++
>  net/netfilter/nf_conntrack_netlink.c        |  2 ++
>  7 files changed, 122 insertions(+), 2 deletions(-)
>  create mode 100644 include/net/netfilter/nf_conntrack_id.h
>  create mode 100644 net/netfilter/nf_conntrack_id.c
> 
> diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
> index 21f887c5058c..274f9370c56a 100644
> --- a/include/net/netfilter/nf_conntrack_extend.h
> +++ b/include/net/netfilter/nf_conntrack_extend.h
> @@ -28,6 +28,7 @@ enum nf_ct_ext_id {
>  #if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY)
>  	NF_CT_EXT_SYNPROXY,
>  #endif
> +	NF_CT_EXT_ID,

I think, if we decide that this new id is needed,
we might as well place this directly in the extension
struct itself rather than an id.

AFAIU this id is always active/set so we never have a
conntrack without this.

> +static inline u64 nf_ct_id(const struct nf_conn *ct)
> +{
> +	struct nf_conn_id *conn;
> +
> +	conn = nf_ct_ext_find(ct, NF_CT_EXT_ID);
> +	if (!conn)
> +		return 0;

so this could just return ct->ext->id.

  parent reply	other threads:[~2017-11-28 12:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-28  2:13 [PATCH nf-next,RFC 1/3] netfilter: nf_conntrack: add 64-bit conntrack ID extension Pablo Neira Ayuso
2017-11-28  2:13 ` [PATCH nf-next,RFC 2/3] netfilter: ctnetlink: use 64-bit conntrack ID Pablo Neira Ayuso
2017-11-28 12:12   ` Florian Westphal
2017-11-28 15:45     ` Pablo Neira Ayuso
2017-11-28 20:27       ` Florian Westphal
2017-11-28  2:13 ` [PATCH nf-next,RFC 3/3] netfilter: ctnetlink: randomize 32-bit ID Pablo Neira Ayuso
2017-11-28 12:18   ` Florian Westphal
2017-11-28 15:46     ` Pablo Neira Ayuso
2017-11-28 10:54 ` [PATCH nf-next,RFC 1/3] netfilter: nf_conntrack: add 64-bit conntrack ID extension Florian Westphal
2017-11-28 15:44   ` Pablo Neira Ayuso
2017-11-28 20:43     ` Florian Westphal
2017-11-28 12:16 ` Florian Westphal [this message]
2017-11-28 15:57   ` Pablo Neira Ayuso
2017-11-28 20:44     ` Florian Westphal

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=20171128121652.GH23412@breakpoint.cc \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=richard@nod.at \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.