From: Pablo Neira Ayuso <pablo@netfilter.org>
To: "Jose M. Guisado Gomez" <guigom@riseup.net>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nf-next 1/3] netfilter: nf_tables: add userdata attributes to nft_chain
Date: Tue, 22 Sep 2020 01:49:12 +0200 [thread overview]
Message-ID: <20200921234912.GA6657@salvia> (raw)
In-Reply-To: <20200921132822.55231-2-guigom@riseup.net>
On Mon, Sep 21, 2020 at 03:28:21PM +0200, Jose M. Guisado Gomez wrote:
> Enables storing userdata for nft_chain. Field udata points to user data
> and udlen stores its length.
>
> Adds new attribute flag NFTA_CHAIN_USERDATA.
>
> Signed-off-by: Jose M. Guisado Gomez <guigom@riseup.net>
> ---
> include/net/netfilter/nf_tables.h | 2 ++
> include/uapi/linux/netfilter/nf_tables.h | 2 ++
> net/netfilter/nf_tables_api.c | 19 +++++++++++++++++++
> 3 files changed, 23 insertions(+)
>
> diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
> index 8ceca0e419b3..4686fafbfd8a 100644
> --- a/include/net/netfilter/nf_tables.h
> +++ b/include/net/netfilter/nf_tables.h
> @@ -952,6 +952,8 @@ struct nft_chain {
> bound:1,
> genmask:2;
> char *name;
> + u16 udlen;
> + u8 *udata;
>
> /* Only used during control plane commit phase: */
> struct nft_rule **rules_next;
> diff --git a/include/uapi/linux/netfilter/nf_tables.h b/include/uapi/linux/netfilter/nf_tables.h
> index 3c2469b43742..352ee51707a1 100644
> --- a/include/uapi/linux/netfilter/nf_tables.h
> +++ b/include/uapi/linux/netfilter/nf_tables.h
> @@ -208,6 +208,7 @@ enum nft_chain_flags {
> * @NFTA_CHAIN_COUNTERS: counter specification of the chain (NLA_NESTED: nft_counter_attributes)
> * @NFTA_CHAIN_FLAGS: chain flags
> * @NFTA_CHAIN_ID: uniquely identifies a chain in a transaction (NLA_U32)
> + * @NFTA_CHAIN_USERDATA: user data (NLA_BINARY)
> */
> enum nft_chain_attributes {
> NFTA_CHAIN_UNSPEC,
> @@ -222,6 +223,7 @@ enum nft_chain_attributes {
> NFTA_CHAIN_PAD,
> NFTA_CHAIN_FLAGS,
> NFTA_CHAIN_ID,
> + NFTA_CHAIN_USERDATA,
> __NFTA_CHAIN_MAX
> };
> #define NFTA_CHAIN_MAX (__NFTA_CHAIN_MAX - 1)
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index 84c0c1aaae99..c8065c6eae86 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
[...]
> @@ -2052,6 +2059,18 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
> goto err1;
> }
>
> + if (nla[NFTA_CHAIN_USERDATA]) {
> + udlen = nla_len(nla[NFTA_CHAIN_USERDATA]);
> + chain->udata = kzalloc(udlen, GFP_KERNEL);
> + if (chain->udata == NULL) {
> + err = -ENOMEM;
> + goto err1;
> + }
> +
> + nla_memcpy(chain->udata, nla[NFTA_CHAIN_USERDATA], udlen);
> + chain->udlen = udlen;
> + }
> +
> rules = nf_tables_chain_alloc_rules(chain, 0);
> if (!rules) {
> err = -ENOMEM;
Hm, kfree(chain->udata) from the error path is missing?
While working at this, probably you can rename all those ugly err1;
basic-like goto style in the same patch.
Thanks.
next prev parent reply other threads:[~2020-09-21 23:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-21 13:28 [PATCH 0/3] add userdata and comment support for chains Jose M. Guisado Gomez
2020-09-21 13:28 ` [PATCH nf-next 1/3] netfilter: nf_tables: add userdata attributes to nft_chain Jose M. Guisado Gomez
2020-09-21 23:49 ` Pablo Neira Ayuso [this message]
2020-09-21 13:28 ` [PATCH libnftnl 2/3] chain: add userdata and comment support Jose M. Guisado Gomez
2020-09-21 13:28 ` [PATCH nftables 3/3] src: add comment support for chains Jose M. Guisado Gomez
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=20200921234912.GA6657@salvia \
--to=pablo@netfilter.org \
--cc=guigom@riseup.net \
--cc=netfilter-devel@vger.kernel.org \
/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).