Skip to contentSkip to conversation

netfilter: nft_tunnel: support tunnel match expr offload

PATCH In review [email protected] 2 participants 7 messages Nov 16, 2019 – Feb 11, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover netfilter: nft_tunnel: support tunnel match expr offload

From: wenxu <[email protected]>

This series add NFT_TUNNEL_IPV4/6_SRC/DST match and tunnel expr offload.

wenxu (4):
netfilter: nft_tunnel: add nft_tunnel_mode_match function
netfilter: nft_tunnel: support NFT_TUNNEL_IPV4_SRC/DST match
netfilter: nft_tunnel: support NFT_TUNNEL_IPV6_SRC/DST match
netfilter: nft_tunnel: add nft_tunnel_get_offload support

 include/net/netfilter/nf_tables_offload.h |   5 ++
 include/uapi/linux/netfilter/nf_tables.h  |   4 +
 net/netfilter/nft_tunnel.c                | 138 +++++++++++++++++++++++++++---
 3 files changed, 134 insertions(+), 13 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 1/4 netfilter: nft_tunnel: add nft_tunnel_mode_match function

From: wenxu <[email protected]>

Move mode match common code to nft_tunnel_mode_match function.

---
v2: nft_tunnel_mode_match() returns u8 to store 0 / 1 on the register

 net/netfilter/nft_tunnel.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
net/netfilter/nft_tunnel.c +16 -13
index 3d4c2ae..921555f5 100644
@@ -18,6 +18,19 @@ struct nft_tunnel {
 	enum nft_tunnel_mode	mode:8;
 };
 
+static bool nft_tunnel_mode_match(enum nft_tunnel_mode priv_mode,
+				  u8 tun_mode)
+{
+	if (priv_mode == NFT_TUNNEL_MODE_NONE ||
+	    (priv_mode == NFT_TUNNEL_MODE_RX &&
+	     !(tun_mode & IP_TUNNEL_INFO_TX)) ||
+	    (priv_mode == NFT_TUNNEL_MODE_TX &&
+	     (tun_mode & IP_TUNNEL_INFO_TX)))
+		return true;
+
+	return false;
+}
+
 static void nft_tunnel_get_eval(const struct nft_expr *expr,
 				struct nft_regs *regs,
 				const struct nft_pktinfo *pkt)
@@ -34,25 +47,15 @@ static void nft_tunnel_get_eval(const struct nft_expr *expr,
 			nft_reg_store8(dest, false);
 			return;
 		}
-		if (priv->mode == NFT_TUNNEL_MODE_NONE ||
-		    (priv->mode == NFT_TUNNEL_MODE_RX &&
-		     !(tun_info->mode & IP_TUNNEL_INFO_TX)) ||
-		    (priv->mode == NFT_TUNNEL_MODE_TX &&
-		     (tun_info->mode & IP_TUNNEL_INFO_TX)))
-			nft_reg_store8(dest, true);
-		else
-			nft_reg_store8(dest, false);
+		nft_reg_store8(dest, nft_tunnel_mode_match(priv->mode,
+							   tun_info->mode));
 		break;
 	case NFT_TUNNEL_ID:
 		if (!tun_info) {
 			regs->verdict.code = NFT_BREAK;
 			return;
 		}
-		if (priv->mode == NFT_TUNNEL_MODE_NONE ||
-		    (priv->mode == NFT_TUNNEL_MODE_RX &&
-		     !(tun_info->mode & IP_TUNNEL_INFO_TX)) ||
-		    (priv->mode == NFT_TUNNEL_MODE_TX &&
-		     (tun_info->mode & IP_TUNNEL_INFO_TX)))
+		if (nft_tunnel_mode_match(priv->mode, tun_info->mode))
 			*dest = ntohl(tunnel_id_to_key32(tun_info->key.tun_id));
 		else
 			regs->verdict.code = NFT_BREAK;
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v2 2/4 netfilter: nft_tunnel: support NFT_TUNNEL_IPV4_SRC/DST match

In reply to [email protected]

From: wenxu <[email protected]>

Add new two NFT_TUNNEL_IPV4_SRC/DST match in nft_tunnel

---
v2: add nft_tunnel_mode_match_ip

 include/uapi/linux/netfilter/nf_tables.h |  2 ++
 net/netfilter/nft_tunnel.c               | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
index bb9b049..1621d72 100644
@@ -1777,6 +1777,8 @@ enum nft_tunnel_key_attributes {
 enum nft_tunnel_keys {
 	NFT_TUNNEL_PATH,
 	NFT_TUNNEL_ID,
+	NFT_TUNNEL_IPV4_SRC,
+	NFT_TUNNEL_IPV4_DST,
 	__NFT_TUNNEL_MAX
 };
 #define NFT_TUNNEL_MAX	(__NFT_TUNNEL_MAX - 1)
net/netfilter/nft_tunnel.c +32 -0
index 921555f5..67f7718 100644
@@ -31,6 +31,16 @@ static bool nft_tunnel_mode_match(enum nft_tunnel_mode priv_mode,
 	return false;
 }
 
+static bool nft_tunnel_mode_match_ip(enum nft_tunnel_mode priv_mode,
+				     struct ip_tunnel_info *tun_info)
+{
+	if (nft_tunnel_mode_match(priv_mode, tun_info->mode) &&
+	    ip_tunnel_info_af(tun_info) == AF_INET)
+		return true;
+
+	return false;
+}
+
 static void nft_tunnel_get_eval(const struct nft_expr *expr,
 				struct nft_regs *regs,
 				const struct nft_pktinfo *pkt)
@@ -60,6 +70,26 @@ static void nft_tunnel_get_eval(const struct nft_expr *expr,
 		else
 			regs->verdict.code = NFT_BREAK;
 		break;
+	case NFT_TUNNEL_IPV4_SRC:
+		if (!tun_info) {
+			regs->verdict.code = NFT_BREAK;
+			return;
+		}
+		if (nft_tunnel_mode_match_ip(priv->mode, tun_info))
+			*dest = tun_info->key.u.ipv4.src;
+		else
+			regs->verdict.code = NFT_BREAK;
+		break;
+	case NFT_TUNNEL_IPV4_DST:
+		if (!tun_info) {
+			regs->verdict.code = NFT_BREAK;
+			return;
+		}
+		if (nft_tunnel_mode_match_ip(priv->mode, tun_info))
+			*dest = tun_info->key.u.ipv4.dst;
+		else
+			regs->verdict.code = NFT_BREAK;
+		break;
 	default:
 		WARN_ON(1);
 		regs->verdict.code = NFT_BREAK;
@@ -89,6 +119,8 @@ static int nft_tunnel_get_init(const struct nft_ctx *ctx,
 		len = sizeof(u8);
 		break;
 	case NFT_TUNNEL_ID:
+	case NFT_TUNNEL_IPV4_SRC:
+	case NFT_TUNNEL_IPV4_DST:
 		len = sizeof(u32);
 		break;
 	default:
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v2 3/4 netfilter: nft_tunnel: support NFT_TUNNEL_IPV6_SRC/DST match

In reply to [email protected]

From: wenxu <[email protected]>

Add new two NFT_TUNNEL_IPV6_SRC/DST match in nft_tunnel

---
v2: add nft_tunnel_mode_match_ip6

 include/uapi/linux/netfilter/nf_tables.h |  2 ++
 net/netfilter/nft_tunnel.c               | 36 ++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
index 1621d72..d067ee7 100644
@@ -1779,6 +1779,8 @@ enum nft_tunnel_keys {
 	NFT_TUNNEL_ID,
 	NFT_TUNNEL_IPV4_SRC,
 	NFT_TUNNEL_IPV4_DST,
+	NFT_TUNNEL_IPV6_SRC,
+	NFT_TUNNEL_IPV6_DST,
 	__NFT_TUNNEL_MAX
 };
 #define NFT_TUNNEL_MAX	(__NFT_TUNNEL_MAX - 1)
net/netfilter/nft_tunnel.c +36 -0
index 67f7718..943a704 100644
@@ -41,6 +41,16 @@ static bool nft_tunnel_mode_match_ip(enum nft_tunnel_mode priv_mode,
 	return false;
 }
 
+static bool nft_tunnel_mode_match_ip6(enum nft_tunnel_mode priv_mode,
+				       struct ip_tunnel_info *tun_info)
+{
+	if (nft_tunnel_mode_match(priv_mode, tun_info->mode) &&
+	    ip_tunnel_info_af(tun_info) == AF_INET6)
+		return true;
+
+	return false;
+}
+
 static void nft_tunnel_get_eval(const struct nft_expr *expr,
 				struct nft_regs *regs,
 				const struct nft_pktinfo *pkt)
@@ -90,6 +100,28 @@ static void nft_tunnel_get_eval(const struct nft_expr *expr,
 		else
 			regs->verdict.code = NFT_BREAK;
 		break;
+	case NFT_TUNNEL_IPV6_SRC:
+		if (!tun_info) {
+			regs->verdict.code = NFT_BREAK;
+			return;
+		}
+		if (nft_tunnel_mode_match_ip6(priv->mode, tun_info))
+			memcpy(dest, &tun_info->key.u.ipv6.src,
+			       sizeof(struct in6_addr));
+		else
+			regs->verdict.code = NFT_BREAK;
+		break;
+	case NFT_TUNNEL_IPV6_DST:
+		if (!tun_info) {
+			regs->verdict.code = NFT_BREAK;
+			return;
+		}
+		if (nft_tunnel_mode_match_ip6(priv->mode, tun_info))
+			memcpy(dest, &tun_info->key.u.ipv6.dst,
+			       sizeof(struct in6_addr));
+		else
+			regs->verdict.code = NFT_BREAK;
+		break;
 	default:
 		WARN_ON(1);
 		regs->verdict.code = NFT_BREAK;
@@ -123,6 +155,10 @@ static int nft_tunnel_get_init(const struct nft_ctx *ctx,
 	case NFT_TUNNEL_IPV4_DST:
 		len = sizeof(u32);
 		break;
+	case NFT_TUNNEL_IPV6_SRC:
+	case NFT_TUNNEL_IPV6_DST:
+		len = sizeof(struct in6_addr);
+		break;
 	default:
 		return -EOPNOTSUPP;
 	}
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH v2 4/4 netfilter: nft_tunnel: add nft_tunnel_get_offload support

In reply to [email protected]

From: wenxu <[email protected]>

Add tunnel meta match offload. Currently support for NFT_TUNNEL_ID NFT_TUNNEL_IPV4_SRC/DST and NFT_TUNNEL_IPV6_SRC/DST

---
v2: no change

 include/net/netfilter/nf_tables_offload.h |  5 ++++
 net/netfilter/nft_tunnel.c                | 41 +++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
include/net/netfilter/nf_tables_offload.h +5 -0
index ea7d1d7..58ac20c 100644
@@ -46,6 +46,11 @@ struct nft_flow_key {
 	struct flow_dissector_key_vlan			vlan;
 	struct flow_dissector_key_eth_addrs		eth_addrs;
 	struct flow_dissector_key_meta			meta;
+	struct flow_dissector_key_keyid			enc_key_id;
+	union {
+		struct flow_dissector_key_ipv4_addrs	enc_ipv4;
+		struct flow_dissector_key_ipv6_addrs	enc_ipv6;
+	};
 } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
 
 struct nft_flow_match {
net/netfilter/nft_tunnel.c +41 -0

59 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#5 lore raw
In reply to [email protected]
Quoted 3 lines · On Sat, Nov 16, 2019 at 03:49:20PM +0800, [email protected] wrote:

From: wenxu <[email protected]>

This series add NFT_TUNNEL_IPV4/6_SRC/DST match and tunnel expr offload.

Thanks. Please, let me revamp a new patch series for the encapsulation/decapsulation support to make sure those are mixing well with your tunnel matching support.

Quoted 14 lines

wenxu (4):
netfilter: nft_tunnel: add nft_tunnel_mode_match function
netfilter: nft_tunnel: support NFT_TUNNEL_IPV4_SRC/DST match
netfilter: nft_tunnel: support NFT_TUNNEL_IPV6_SRC/DST match
netfilter: nft_tunnel: add nft_tunnel_get_offload support

 include/net/netfilter/nf_tables_offload.h |   5 ++
 include/uapi/linux/netfilter/nf_tables.h  |   4 +
 net/netfilter/nft_tunnel.c                | 138 +++++++++++++++++++++++++++---
 3 files changed, 134 insertions(+), 13 deletions(-)
Signature · 1 line
1.8.3.1
author
#6 lore raw
Quoted 7 lines · Pablo Neira Ayuso
Quoted 3 lines · On Sat, Nov 16, 2019 at 03:49:20PM +0800, [email protected] wrote:

From: wenxu <[email protected]>

This series add NFT_TUNNEL_IPV4/6_SRC/DST match and tunnel expr offload.

Thanks. Please, let me revamp a new patch series for the encapsulation/decapsulation support to make sure those are mixing well with your tunnel matching support.

Pablo, any update for this series?

Quoted 15 lines
Quoted 15 lines

wenxu (4):
netfilter: nft_tunnel: add nft_tunnel_mode_match function
netfilter: nft_tunnel: support NFT_TUNNEL_IPV4_SRC/DST match
netfilter: nft_tunnel: support NFT_TUNNEL_IPV6_SRC/DST match
netfilter: nft_tunnel: add nft_tunnel_get_offload support

 include/net/netfilter/nf_tables_offload.h |   5 ++
 include/uapi/linux/netfilter/nf_tables.h  |   4 +
 net/netfilter/nft_tunnel.c                | 138 +++++++++++++++++++++++++++---
 3 files changed, 134 insertions(+), 13 deletions(-)
Signature · 1 line
1.8.3.1