All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] netfilter: meta: add support for setting skb->pkttype
@ 2015-12-03 15:56 Florian Westphal
  2015-12-09 22:54 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Westphal @ 2015-12-03 15:56 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

This allows to redirect bridged packets to local machine.

ether type ip ether daddr set aa:53:08:12:34:56 meta pkttype set unicast

Without 'set unicast', ip stack discards PACKET_OTHERHOST skbs.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 Hi Patrick,

 as discussed this adds meta set support for pkttype.

 I'm not sure how restricted it should be; this only allows
 changing PACKET_OTHERHOST to something else, but I'm not sure
 if this should do more checks on value (e.g. only allow
 PACKET_HOST?) or even less (e.g. also allow mangling
 mcast and the like?).

 It only allows NETDEV and BRIDGE families but thats mainly
 because the other ones make no sense (PACKET_OTHERHOST
 cannot happen w. IPV4, 6, INET since stack already drops them earlier).

diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
index 9dfaf4d..3d64742 100644
--- a/net/netfilter/nft_meta.c
+++ b/net/netfilter/nft_meta.c
@@ -24,6 +24,8 @@
 #include <net/netfilter/nf_tables.h>
 #include <net/netfilter/nft_meta.h>
 
+#include <uapi/linux/netfilter_bridge.h> /* NF_BR_PRE_ROUTING */
+
 void nft_meta_get_eval(const struct nft_expr *expr,
 		       struct nft_regs *regs,
 		       const struct nft_pktinfo *pkt)
@@ -203,6 +205,10 @@ void nft_meta_set_eval(const struct nft_expr *expr,
 	case NFT_META_PRIORITY:
 		skb->priority = value;
 		break;
+	case NFT_META_PKTTYPE:
+		if (skb->pkt_type == PACKET_OTHERHOST)
+			skb->pkt_type = value;
+		break;
 	case NFT_META_NFTRACE:
 		skb->nf_trace = 1;
 		break;
@@ -271,6 +277,24 @@ 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)
+{
+	unsigned int hooks;
+
+	switch (ctx->afi->family) {
+	case NFPROTO_BRIDGE:
+		hooks = 1 << NF_BR_PRE_ROUTING;
+		break;
+	case NFPROTO_NETDEV:
+		hooks = 1 << NF_NETDEV_INGRESS;
+		break;
+	default:
+		return -EOPNOTSUPP;
+	}
+
+	return nft_chain_validate_hooks(ctx->chain, hooks);
+}
+
 int nft_meta_set_init(const struct nft_ctx *ctx,
 		      const struct nft_expr *expr,
 		      const struct nlattr * const tb[])
@@ -288,6 +312,12 @@ int nft_meta_set_init(const struct nft_ctx *ctx,
 	case NFT_META_NFTRACE:
 		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;
 	}
-- 
2.4.10


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

* Re: [PATCH -next] netfilter: meta: add support for setting skb->pkttype
  2015-12-03 15:56 [PATCH -next] netfilter: meta: add support for setting skb->pkttype Florian Westphal
@ 2015-12-09 22:54 ` Pablo Neira Ayuso
  2015-12-10  1:41   ` Florian Westphal
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2015-12-09 22:54 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

On Thu, Dec 03, 2015 at 04:56:41PM +0100, Florian Westphal wrote:
> This allows to redirect bridged packets to local machine.
> 
> ether type ip ether daddr set aa:53:08:12:34:56 meta pkttype set unicast
> 
> Without 'set unicast', ip stack discards PACKET_OTHERHOST skbs.
> 
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
>  Hi Patrick,
> 
>  as discussed this adds meta set support for pkttype.
> 
>  I'm not sure how restricted it should be; this only allows
>  changing PACKET_OTHERHOST to something else, but I'm not sure
>  if this should do more checks on value (e.g. only allow
>  PACKET_HOST?) or even less (e.g. also allow mangling
>  mcast and the like?).
>
>  It only allows NETDEV and BRIDGE families but thats mainly
>  because the other ones make no sense (PACKET_OTHERHOST
>  cannot happen w. IPV4, 6, INET since stack already drops them earlier).

With a 'hash' expression and this mangling, we can emulate the cluster
match (hence its CLUSTERIP target predecesor too).

If mangling doesn't crash the kernel, ie. nonsense configuration just
results in a drop, then I would make no restrictions.

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

* Re: [PATCH -next] netfilter: meta: add support for setting skb->pkttype
  2015-12-09 22:54 ` Pablo Neira Ayuso
@ 2015-12-10  1:41   ` Florian Westphal
  0 siblings, 0 replies; 3+ messages in thread
From: Florian Westphal @ 2015-12-10  1:41 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Florian Westphal, netfilter-devel

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Thu, Dec 03, 2015 at 04:56:41PM +0100, Florian Westphal wrote:
> > This allows to redirect bridged packets to local machine.
> > 
> > ether type ip ether daddr set aa:53:08:12:34:56 meta pkttype set unicast
> > 
> > Without 'set unicast', ip stack discards PACKET_OTHERHOST skbs.
> > 
> > Signed-off-by: Florian Westphal <fw@strlen.de>
> > ---
> >  Hi Patrick,
> > 
> >  as discussed this adds meta set support for pkttype.
> > 
> >  I'm not sure how restricted it should be; this only allows
> >  changing PACKET_OTHERHOST to something else, but I'm not sure
> >  if this should do more checks on value (e.g. only allow
> >  PACKET_HOST?) or even less (e.g. also allow mangling
> >  mcast and the like?).
> >
> >  It only allows NETDEV and BRIDGE families but thats mainly
> >  because the other ones make no sense (PACKET_OTHERHOST
> >  cannot happen w. IPV4, 6, INET since stack already drops them earlier).
> 
> With a 'hash' expression and this mangling, we can emulate the cluster
> match (hence its CLUSTERIP target predecesor too).

I forgot about -m cluster, so we definitely want to be able to change
MULTICAST to HOST.

So the only question is wheter we should allow setting it to arbitrary
value (e.g. PACKET_LOOPBACK).  I'm reasonably sure HOST/BROAD/MULTICAST
are okay.

I'll dig if that might cause any problems (esp. when considering
mangling happens in a netns).

> If mangling doesn't crash the kernel, ie. nonsense configuration just
> results in a drop, then I would make no restrictions.

Makes sense.

An updated patch to also permit MCAST will arrive in any case,
moved patchwork state to 'changes requested'.

Thanks!

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

end of thread, other threads:[~2015-12-10  1:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-03 15:56 [PATCH -next] netfilter: meta: add support for setting skb->pkttype Florian Westphal
2015-12-09 22:54 ` Pablo Neira Ayuso
2015-12-10  1:41   ` Florian Westphal

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.