netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/4] nf_tables_offload: vlan matching support
@ 2019-11-19 22:05 Pablo Neira Ayuso
  2019-11-19 22:05 ` [PATCH net-next 1/4] netfilter: nf_tables: constify nft_reg_load{8,16,64}() Pablo Neira Ayuso
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2019-11-19 22:05 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Hi David,

The following patchset contains Netfilter support for vlan matching
offloads:

1) Constify nft_reg_load() as a preparation patch.
2) Restrict rule matching to ingress interface type ARPHRD_ETHER.
3) Add new vlan_tci field to flow_dissector_key_vlan structure,
   to allow to set up vlan_id, vlan_dei and vlan_priority in one go.
4) C-VLAN matching support.

Please, directly apply to net-next if you are OK with this batch.

Thank you.

Pablo Neira Ayuso (4):
  netfilter: nf_tables: constify nft_reg_load{8,16,64}()
  netfilter: nf_tables_offload: allow ethernet interface type only
  netfilter: nft_payload: add VLAN offload support
  netfilter: nft_payload: add C-VLAN offload support

 include/net/flow_dissector.h      | 11 ++++++++---
 include/net/netfilter/nf_tables.h |  6 +++---
 net/netfilter/nft_cmp.c           |  6 ++++++
 net/netfilter/nft_meta.c          |  4 ++++
 net/netfilter/nft_payload.c       | 38 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 59 insertions(+), 6 deletions(-)

-- 
2.11.0


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

* [PATCH net-next 1/4] netfilter: nf_tables: constify nft_reg_load{8,16,64}()
  2019-11-19 22:05 [PATCH net-next 0/4] nf_tables_offload: vlan matching support Pablo Neira Ayuso
@ 2019-11-19 22:05 ` Pablo Neira Ayuso
  2019-11-19 22:05 ` [PATCH net-next 2/4] netfilter: nf_tables_offload: allow ethernet interface type only Pablo Neira Ayuso
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2019-11-19 22:05 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

This patch constifies the pointer to source register data that is passed
as an input parameter.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/net/netfilter/nf_tables.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index cae47481e5d6..7dd03b1f0156 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -114,7 +114,7 @@ static inline void nft_reg_store8(u32 *dreg, u8 val)
 	*(u8 *)dreg = val;
 }
 
-static inline u8 nft_reg_load8(u32 *sreg)
+static inline u8 nft_reg_load8(const u32 *sreg)
 {
 	return *(u8 *)sreg;
 }
@@ -125,7 +125,7 @@ static inline void nft_reg_store16(u32 *dreg, u16 val)
 	*(u16 *)dreg = val;
 }
 
-static inline u16 nft_reg_load16(u32 *sreg)
+static inline u16 nft_reg_load16(const u32 *sreg)
 {
 	return *(u16 *)sreg;
 }
@@ -135,7 +135,7 @@ static inline void nft_reg_store64(u32 *dreg, u64 val)
 	put_unaligned(val, (u64 *)dreg);
 }
 
-static inline u64 nft_reg_load64(u32 *sreg)
+static inline u64 nft_reg_load64(const u32 *sreg)
 {
 	return get_unaligned((u64 *)sreg);
 }
-- 
2.11.0


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

* [PATCH net-next 2/4] netfilter: nf_tables_offload: allow ethernet interface type only
  2019-11-19 22:05 [PATCH net-next 0/4] nf_tables_offload: vlan matching support Pablo Neira Ayuso
  2019-11-19 22:05 ` [PATCH net-next 1/4] netfilter: nf_tables: constify nft_reg_load{8,16,64}() Pablo Neira Ayuso
@ 2019-11-19 22:05 ` Pablo Neira Ayuso
  2019-11-19 22:05 ` [PATCH net-next 3/4] netfilter: nft_payload: add VLAN offload support Pablo Neira Ayuso
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2019-11-19 22:05 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Hardware offload support at this stage assumes an ethernet device in
place. The flow dissector provides the intermediate representation to
express this selector, so extend it to allow to store the interface
type. Flower does not uses this, so skb_flow_dissect_meta() is not
extended to match on this new field.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/net/flow_dissector.h | 2 ++
 net/netfilter/nft_cmp.c      | 6 ++++++
 net/netfilter/nft_meta.c     | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index b1063db63e66..1a0727d1acfa 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -203,9 +203,11 @@ struct flow_dissector_key_ip {
 /**
  * struct flow_dissector_key_meta:
  * @ingress_ifindex: ingress ifindex
+ * @ingress_iftype: ingress interface type
  */
 struct flow_dissector_key_meta {
 	int ingress_ifindex;
+	u16 ingress_iftype;
 };
 
 /**
diff --git a/net/netfilter/nft_cmp.c b/net/netfilter/nft_cmp.c
index 0744b2bb46da..b8092069f868 100644
--- a/net/netfilter/nft_cmp.c
+++ b/net/netfilter/nft_cmp.c
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/netlink.h>
 #include <linux/netfilter.h>
+#include <linux/if_arp.h>
 #include <linux/netfilter/nf_tables.h>
 #include <net/netfilter/nf_tables_core.h>
 #include <net/netfilter/nf_tables_offload.h>
@@ -125,6 +126,11 @@ static int __nft_cmp_offload(struct nft_offload_ctx *ctx,
 	flow->match.dissector.used_keys |= BIT(reg->key);
 	flow->match.dissector.offset[reg->key] = reg->base_offset;
 
+	if (reg->key == FLOW_DISSECTOR_KEY_META &&
+	    reg->offset == offsetof(struct nft_flow_key, meta.ingress_iftype) &&
+	    nft_reg_load16(priv->data.data) != ARPHRD_ETHER)
+		return -EOPNOTSUPP;
+
 	nft_offload_update_dependency(ctx, &priv->data, priv->len);
 
 	return 0;
diff --git a/net/netfilter/nft_meta.c b/net/netfilter/nft_meta.c
index 8fbea031bd4a..9740b554fdb3 100644
--- a/net/netfilter/nft_meta.c
+++ b/net/netfilter/nft_meta.c
@@ -551,6 +551,10 @@ static int nft_meta_get_offload(struct nft_offload_ctx *ctx,
 		NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_META, meta,
 				  ingress_ifindex, sizeof(__u32), reg);
 		break;
+	case NFT_META_IIFTYPE:
+		NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_META, meta,
+				  ingress_iftype, sizeof(__u16), reg);
+		break;
 	default:
 		return -EOPNOTSUPP;
 	}
-- 
2.11.0


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

* [PATCH net-next 3/4] netfilter: nft_payload: add VLAN offload support
  2019-11-19 22:05 [PATCH net-next 0/4] nf_tables_offload: vlan matching support Pablo Neira Ayuso
  2019-11-19 22:05 ` [PATCH net-next 1/4] netfilter: nf_tables: constify nft_reg_load{8,16,64}() Pablo Neira Ayuso
  2019-11-19 22:05 ` [PATCH net-next 2/4] netfilter: nf_tables_offload: allow ethernet interface type only Pablo Neira Ayuso
@ 2019-11-19 22:05 ` Pablo Neira Ayuso
  2019-11-19 22:05 ` [PATCH net-next 4/4] netfilter: nft_payload: add C-VLAN " Pablo Neira Ayuso
  2019-11-20 19:21 ` [PATCH net-next 0/4] nf_tables_offload: vlan matching support David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2019-11-19 22:05 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Match on ethertype and set up protocol dependency. Check for protocol
dependency before accessing the tci field. Allow to match on the
encapsulated ethertype too.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/net/flow_dissector.h |  9 ++++++---
 net/netfilter/nft_payload.c  | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h
index 1a0727d1acfa..f06b0239c32b 100644
--- a/include/net/flow_dissector.h
+++ b/include/net/flow_dissector.h
@@ -48,9 +48,12 @@ struct flow_dissector_key_tags {
 };
 
 struct flow_dissector_key_vlan {
-	u16	vlan_id:12,
-		vlan_dei:1,
-		vlan_priority:3;
+	union {
+		u16	vlan_id:12,
+			vlan_dei:1,
+			vlan_priority:3;
+		__be16	vlan_tci;
+	};
 	__be16	vlan_tpid;
 };
 
diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 0877d46b8605..f17939fbf6c3 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -182,6 +182,28 @@ static int nft_payload_offload_ll(struct nft_offload_ctx *ctx,
 		NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_ETH_ADDRS, eth_addrs,
 				  dst, ETH_ALEN, reg);
 		break;
+	case offsetof(struct ethhdr, h_proto):
+		if (priv->len != sizeof(__be16))
+			return -EOPNOTSUPP;
+
+		NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_BASIC, basic,
+				  n_proto, sizeof(__be16), reg);
+		nft_offload_set_dependency(ctx, NFT_OFFLOAD_DEP_NETWORK);
+		break;
+	case offsetof(struct vlan_ethhdr, h_vlan_TCI):
+		if (priv->len != sizeof(__be16))
+			return -EOPNOTSUPP;
+
+		NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_VLAN, vlan,
+				  vlan_tci, sizeof(__be16), reg);
+		break;
+	case offsetof(struct vlan_ethhdr, h_vlan_encapsulated_proto):
+		if (priv->len != sizeof(__be16))
+			return -EOPNOTSUPP;
+
+		NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_VLAN, vlan,
+				  vlan_tpid, sizeof(__be16), reg);
+		break;
 	default:
 		return -EOPNOTSUPP;
 	}
-- 
2.11.0


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

* [PATCH net-next 4/4] netfilter: nft_payload: add C-VLAN offload support
  2019-11-19 22:05 [PATCH net-next 0/4] nf_tables_offload: vlan matching support Pablo Neira Ayuso
                   ` (2 preceding siblings ...)
  2019-11-19 22:05 ` [PATCH net-next 3/4] netfilter: nft_payload: add VLAN offload support Pablo Neira Ayuso
@ 2019-11-19 22:05 ` Pablo Neira Ayuso
  2019-11-20 19:21 ` [PATCH net-next 0/4] nf_tables_offload: vlan matching support David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2019-11-19 22:05 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, netdev

Match on h_vlan_encapsulated_proto and set up protocol dependency. Check
for protocol dependency before accessing the tci field. Allow to match
on the encapsulated ethertype too.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_payload.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index f17939fbf6c3..1993af3a2979 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -203,6 +203,22 @@ static int nft_payload_offload_ll(struct nft_offload_ctx *ctx,
 
 		NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_VLAN, vlan,
 				  vlan_tpid, sizeof(__be16), reg);
+		nft_offload_set_dependency(ctx, NFT_OFFLOAD_DEP_NETWORK);
+		break;
+	case offsetof(struct vlan_ethhdr, h_vlan_TCI) + sizeof(struct vlan_hdr):
+		if (priv->len != sizeof(__be16))
+			return -EOPNOTSUPP;
+
+		NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_CVLAN, vlan,
+				  vlan_tci, sizeof(__be16), reg);
+		break;
+	case offsetof(struct vlan_ethhdr, h_vlan_encapsulated_proto) +
+							sizeof(struct vlan_hdr):
+		if (priv->len != sizeof(__be16))
+			return -EOPNOTSUPP;
+
+		NFT_OFFLOAD_MATCH(FLOW_DISSECTOR_KEY_CVLAN, vlan,
+				  vlan_tpid, sizeof(__be16), reg);
 		break;
 	default:
 		return -EOPNOTSUPP;
-- 
2.11.0


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

* Re: [PATCH net-next 0/4] nf_tables_offload: vlan matching support
  2019-11-19 22:05 [PATCH net-next 0/4] nf_tables_offload: vlan matching support Pablo Neira Ayuso
                   ` (3 preceding siblings ...)
  2019-11-19 22:05 ` [PATCH net-next 4/4] netfilter: nft_payload: add C-VLAN " Pablo Neira Ayuso
@ 2019-11-20 19:21 ` David Miller
  4 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2019-11-20 19:21 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel, netdev

From: Pablo Neira Ayuso <pablo@netfilter.org>
Date: Tue, 19 Nov 2019 23:05:51 +0100

> The following patchset contains Netfilter support for vlan matching
> offloads:
> 
> 1) Constify nft_reg_load() as a preparation patch.
> 2) Restrict rule matching to ingress interface type ARPHRD_ETHER.
> 3) Add new vlan_tci field to flow_dissector_key_vlan structure,
>    to allow to set up vlan_id, vlan_dei and vlan_priority in one go.
> 4) C-VLAN matching support.
> 
> Please, directly apply to net-next if you are OK with this batch.

Series applied, thanks.

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

end of thread, other threads:[~2019-11-20 19:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-19 22:05 [PATCH net-next 0/4] nf_tables_offload: vlan matching support Pablo Neira Ayuso
2019-11-19 22:05 ` [PATCH net-next 1/4] netfilter: nf_tables: constify nft_reg_load{8,16,64}() Pablo Neira Ayuso
2019-11-19 22:05 ` [PATCH net-next 2/4] netfilter: nf_tables_offload: allow ethernet interface type only Pablo Neira Ayuso
2019-11-19 22:05 ` [PATCH net-next 3/4] netfilter: nft_payload: add VLAN offload support Pablo Neira Ayuso
2019-11-19 22:05 ` [PATCH net-next 4/4] netfilter: nft_payload: add C-VLAN " Pablo Neira Ayuso
2019-11-20 19:21 ` [PATCH net-next 0/4] nf_tables_offload: vlan matching support David Miller

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).