All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nf] netfilter: nft_meta: improve the validity check of pkttype set expr
@ 2016-08-22 14:57 Liping Zhang
  2016-08-25 11:10 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Liping Zhang @ 2016-08-22 14:57 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel, Liping Zhang

From: Liping Zhang <liping.zhang@spreadtrum.com>

"meta pkttype set" is only supported on prerouting chain with bridge
family and ingress chain with netdev family.

But the validate check is incomplete, and the user can add the nft
rules on input chain with bridge family, for example:
  # nft add table bridge filter
  # nft add chain bridge filter input {type filter hook input \
    priority 0 \;}
  # nft add chain bridge filter test
  # nft add rule bridge filter test meta pkttype set unicast
  # nft add rule bridge filter input jump test

This patch fixes the problem.

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
---
 include/net/netfilter/nft_meta.h       |  4 ++++
 net/bridge/netfilter/nft_meta_bridge.c |  1 +
 net/netfilter/nft_meta.c               | 17 +++++++++++++----
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/include/net/netfilter/nft_meta.h b/include/net/netfilter/nft_meta.h
index d27588c..1139cde 100644
--- a/include/net/netfilter/nft_meta.h
+++ b/include/net/netfilter/nft_meta.h
@@ -36,4 +36,8 @@ void nft_meta_set_eval(const struct nft_expr *expr,
 void nft_meta_set_destroy(const struct nft_ctx *ctx,
 			  const struct nft_expr *expr);
 
+int nft_meta_set_validate(const struct nft_ctx *ctx,
+			  const struct nft_expr *expr,
+			  const struct nft_data **data);
+
 #endif
diff --git a/net/bridge/netfilter/nft_meta_bridge.c b/net/bridge/netfilter/nft_meta_bridge.c
index 4b901d9..ad47a92 100644
--- a/net/bridge/netfilter/nft_meta_bridge.c
+++ b/net/bridge/netfilter/nft_meta_bridge.c
@@ -86,6 +86,7 @@ static const struct nft_expr_ops nft_meta_bridge_set_ops = {
 	.init		= nft_meta_set_init,
 	.destroy	= nft_meta_set_destroy,
 	.dump		= nft_meta_set_dump,
+	.validate	= nft_meta_set_validate,
 };
 
 static const struct nft_expr_ops *
diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
index 2863f34..8a6bc76 100644
--- a/net/netfilter/nft_meta.c
+++ b/net/netfilter/nft_meta.c
@@ -291,10 +291,16 @@ int nft_meta_get_init(const struct nft_ctx *ctx,
 }
 EXPORT_SYMBOL_GPL(nft_meta_get_init);
 
-static int nft_meta_set_init_pkttype(const struct nft_ctx *ctx)
+int nft_meta_set_validate(const struct nft_ctx *ctx,
+			  const struct nft_expr *expr,
+			  const struct nft_data **data)
 {
+	struct nft_meta *priv = nft_expr_priv(expr);
 	unsigned int hooks;
 
+	if (priv->key != NFT_META_PKTTYPE)
+		return 0;
+
 	switch (ctx->afi->family) {
 	case NFPROTO_BRIDGE:
 		hooks = 1 << NF_BR_PRE_ROUTING;
@@ -308,6 +314,7 @@ static int nft_meta_set_init_pkttype(const struct nft_ctx *ctx)
 
 	return nft_chain_validate_hooks(ctx->chain, hooks);
 }
+EXPORT_SYMBOL_GPL(nft_meta_set_validate);
 
 int nft_meta_set_init(const struct nft_ctx *ctx,
 		      const struct nft_expr *expr,
@@ -327,15 +334,16 @@ int nft_meta_set_init(const struct nft_ctx *ctx,
 		len = sizeof(u8);
 		break;
 	case NFT_META_PKTTYPE:
-		err = nft_meta_set_init_pkttype(ctx);
-		if (err)
-			return err;
 		len = sizeof(u8);
 		break;
 	default:
 		return -EOPNOTSUPP;
 	}
 
+	err = nft_meta_set_validate(ctx, expr, NULL);
+	if (err < 0)
+		return err;
+
 	priv->sreg = nft_parse_register(tb[NFTA_META_SREG]);
 	err = nft_validate_register_load(priv->sreg, len);
 	if (err < 0)
@@ -407,6 +415,7 @@ static const struct nft_expr_ops nft_meta_set_ops = {
 	.init		= nft_meta_set_init,
 	.destroy	= nft_meta_set_destroy,
 	.dump		= nft_meta_set_dump,
+	.validate	= nft_meta_set_validate,
 };
 
 static const struct nft_expr_ops *
-- 
2.5.5



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH nf] netfilter: nft_meta: improve the validity check of pkttype set expr
  2016-08-22 14:57 [PATCH nf] netfilter: nft_meta: improve the validity check of pkttype set expr Liping Zhang
@ 2016-08-25 11:10 ` Pablo Neira Ayuso
  2016-08-26  0:24   ` Liping Zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2016-08-25 11:10 UTC (permalink / raw)
  To: Liping Zhang; +Cc: netfilter-devel, Liping Zhang

On Mon, Aug 22, 2016 at 10:57:56PM +0800, Liping Zhang wrote:
> From: Liping Zhang <liping.zhang@spreadtrum.com>
> 
> "meta pkttype set" is only supported on prerouting chain with bridge
> family and ingress chain with netdev family.
> 
> But the validate check is incomplete, and the user can add the nft
> rules on input chain with bridge family, for example:
>   # nft add table bridge filter
>   # nft add chain bridge filter input {type filter hook input \
>     priority 0 \;}
>   # nft add chain bridge filter test
>   # nft add rule bridge filter test meta pkttype set unicast
>   # nft add rule bridge filter input jump test
> 
> This patch fixes the problem.

Good catch, applied, thanks!

Actually, it would be good to allow mangling this pkttype from
prerouting ip and ip6 too, so we can emulate the 'cluster match' very
easily.

Now we have a hash expression in place, which is what was missing to
support this.

So, once your fix shows up in the nf-next tree, I'd appreciate if you
can follow up with a patch to allow the use of this from there.
Thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH nf] netfilter: nft_meta: improve the validity check of pkttype set expr
  2016-08-25 11:10 ` Pablo Neira Ayuso
@ 2016-08-26  0:24   ` Liping Zhang
  0 siblings, 0 replies; 3+ messages in thread
From: Liping Zhang @ 2016-08-26  0:24 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Liping Zhang, netfilter-devel, Liping Zhang

2016-08-25 19:10 GMT+08:00 Pablo Neira Ayuso <pablo@netfilter.org>:
> Actually, it would be good to allow mangling this pkttype from
> prerouting ip and ip6 too, so we can emulate the 'cluster match' very
> easily.
>
> Now we have a hash expression in place, which is what was missing to
> support this.
>
> So, once your fix shows up in the nf-next tree, I'd appreciate if you
> can follow up with a patch to allow the use of this from there.

OK. I will follow up on this.
Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-08-26  0:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-22 14:57 [PATCH nf] netfilter: nft_meta: improve the validity check of pkttype set expr Liping Zhang
2016-08-25 11:10 ` Pablo Neira Ayuso
2016-08-26  0:24   ` Liping Zhang

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.