From: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
To: Patrick McHardy <kaber@trash.net>, pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 2/3] netfilter: nft_meta: split nft_meta_init() into two functions for get/set
Date: Mon, 31 Mar 2014 15:37:43 +0300 [thread overview]
Message-ID: <53396197.20809@linux.intel.com> (raw)
In-Reply-To: <1396089783-3984-3-git-send-email-kaber@trash.net>
Hi Patrick,
> diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
> index 425cf39..6d0b8cc2 100644
> --- a/net/netfilter/nft_meta.c
> +++ b/net/netfilter/nft_meta.c
> @@ -170,21 +170,15 @@ static const struct nla_policy nft_meta_policy[NFTA_META_MAX + 1] = {
> [NFTA_META_SREG] = { .type = NLA_U32 },
> };
>
> -static int nft_meta_init_validate_set(uint32_t key)
> +static int nft_meta_get_init(const struct nft_ctx *ctx,
> + const struct nft_expr *expr,
> + const struct nlattr * const tb[])
> {
> - switch (key) {
> - case NFT_META_MARK:
> - case NFT_META_PRIORITY:
> - case NFT_META_NFTRACE:
> - return 0;
> - default:
> - return -EOPNOTSUPP;
> - }
> -}
> + struct nft_meta *priv = nft_expr_priv(expr);
> + int err;
>
> -static int nft_meta_init_validate_get(uint32_t key)
> -{
> - switch (key) {
With the disappearance of nft_meta_init_validate_get(), I will need to add
an #ifdef/#endif clause for bridge key support. Or I would copy and adapt
this new nft_meta_get_init() in nft_meta_bridge.c.
Don't you think nft_meta_validate_get() could be kept?
> + priv->key = ntohl(nla_get_be32(tb[NFTA_META_KEY]));
> + switch (priv->key) {
> case NFT_META_LEN:
> case NFT_META_PROTOCOL:
> case NFT_META_NFPROTO:
> @@ -205,39 +199,40 @@ static int nft_meta_init_validate_get(uint32_t key)
> #ifdef CONFIG_NETWORK_SECMARK
> case NFT_META_SECMARK:
> #endif
> - return 0;
> + break;
> default:
> return -EOPNOTSUPP;
> }
>
> + priv->dreg = ntohl(nla_get_be32(tb[NFTA_META_DREG]));
> + err = nft_validate_output_register(priv->dreg);
> + if (err < 0)
> + return err;
> +
> + err = nft_validate_data_load(ctx, priv->dreg, NULL, NFT_DATA_VALUE);
> + if (err < 0)
> + return err;
> +
> + return 0;
> }
>
> -static int nft_meta_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
> - const struct nlattr * const tb[])
> +static int nft_meta_set_init(const struct nft_ctx *ctx,
> + const struct nft_expr *expr,
> + const struct nlattr * const tb[])
> {
> struct nft_meta *priv = nft_expr_priv(expr);
> int err;
>
> priv->key = ntohl(nla_get_be32(tb[NFTA_META_KEY]));
> -
> - if (tb[NFTA_META_DREG]) {
> - err = nft_meta_init_validate_get(priv->key);
> - if (err < 0)
> - return err;
> -
> - priv->dreg = ntohl(nla_get_be32(tb[NFTA_META_DREG]));
> - err = nft_validate_output_register(priv->dreg);
> - if (err < 0)
> - return err;
> -
> - return nft_validate_data_load(ctx, priv->dreg, NULL,
> - NFT_DATA_VALUE);
> + switch (priv->key) {
> + case NFT_META_MARK:
> + case NFT_META_PRIORITY:
> + case NFT_META_NFTRACE:
> + break;
> + default:
> + return -EOPNOTSUPP;
> }
>
> - err = nft_meta_init_validate_set(priv->key);
> - if (err < 0)
> - return err;
> -
> priv->sreg = ntohl(nla_get_be32(tb[NFTA_META_SREG]));
> err = nft_validate_input_register(priv->sreg);
> if (err < 0)
> @@ -282,7 +277,7 @@ static const struct nft_expr_ops nft_meta_get_ops = {
> .type = &nft_meta_type,
> .size = NFT_EXPR_SIZE(sizeof(struct nft_meta)),
> .eval = nft_meta_get_eval,
> - .init = nft_meta_init,
> + .init = nft_meta_get_init,
> .dump = nft_meta_get_dump,
> };
>
> @@ -290,7 +285,7 @@ static const struct nft_expr_ops nft_meta_set_ops = {
> .type = &nft_meta_type,
> .size = NFT_EXPR_SIZE(sizeof(struct nft_meta)),
> .eval = nft_meta_set_eval,
> - .init = nft_meta_init,
> + .init = nft_meta_set_init,
> .dump = nft_meta_set_dump,
> };
>
Rest is fine and indeed it simplifies things on my side (no need to c/p
the old nft_meta_init,
here I can reuse existing nft_meta_set_init)
Tomasz
next prev parent reply other threads:[~2014-03-31 12:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-29 10:43 [PATCH 0/3] netfilter: nf_tables: cleanup and a bugfix Patrick McHardy
2014-03-29 10:43 ` [PATCH 1/3] netfilter: nft_ct: add missing ifdef for NFT_MARK setting Patrick McHardy
2014-03-29 10:43 ` [PATCH 2/3] netfilter: nft_meta: split nft_meta_init() into two functions for get/set Patrick McHardy
2014-03-31 12:37 ` Tomasz Bursztyka [this message]
2014-04-02 11:43 ` Patrick McHardy
2014-03-29 10:43 ` [PATCH 3/3] netfilter: nft_ct: split nft_ct_init() " Patrick McHardy
2014-03-30 11:35 ` [PATCH 0/3] netfilter: nf_tables: cleanup and a bugfix 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=53396197.20809@linux.intel.com \
--to=tomasz.bursztyka@linux.intel.com \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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).