netfilter: nf_tables_offload: support tunnel offload
Subsystems (2)
v5 cover netfilter: nf_tables_offload: support tunnel offload
From: wenxu <[email protected]>
This series add NFT_TUNNEL_IP/6_SRC/DST match and tunnel expr offload. Also add NFTA_TUNNEL_KEY_RELEASE actions adn objref, tunnel obj offload
This version just split from the orignal big seriese without dependency with each other
wenxu (8):
netfilter: nft_tunnel: add nft_tunnel_mode_validate function
netfilter: nft_tunnel: support NFT_TUNNEL_IP_SRC/DST match
netfilter: nft_tunnel: add ipv6 check in nft_tunnel_mode_validate
netfilter: nft_tunnel: support NFT_TUNNEL_IP6_SRC/DST match
netfilter: nft_tunnel: support tunnel meta match offload
netfilter: nft_tunnel: add NFTA_TUNNEL_KEY_RELEASE action
netfilter: nft_objref: add nft_objref_type offload
netfilter: nft_tunnel: support nft_tunnel_obj offload
include/net/netfilter/nf_tables.h | 3 + include/net/netfilter/nf_tables_offload.h | 5 + include/uapi/linux/netfilter/nf_tables.h | 5 + net/netfilter/nft_objref.c | 14 +++ net/netfilter/nft_tunnel.c | 159 +++++++++++++++++++++++++++--- 5 files changed, 173 insertions(+), 13 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v5 1/8 netfilter: nft_tunnel: add nft_tunnel_mode_validate function
From: wenxu <[email protected]>
Move mode validate common code to nft_tunnel_mode_validate function.
---
v5: no chang
net/netfilter/nft_tunnel.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
net/netfilter/nft_tunnel.c +14 -10
@@ -18,6 +18,18 @@ struct nft_tunnel { enum nft_tunnel_mode mode:8; }; +bool nft_tunnel_mode_validate (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,11 +46,7 @@ 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 ))) +if (nft_tunnel_mode_validate (priv->mode, tun_info->mode))nft_reg_store8 (dest, true);else nft_reg_store8 (dest, false);
@@ -48,11 +56,7 @@ static void nft_tunnel_get_eval(const struct nft_expr *expr, 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_validate (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
PATCH v5 2/8 netfilter: nft_tunnel: support NFT_TUNNEL_IP_SRC/DST match
In reply to [email protected]From: wenxu <[email protected]>
Add new two NFT_TUNNEL_IP_SRC/DST match in nft_tunnel
---
v5: no change
include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nft_tunnel.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -1765,6 +1765,8 @@ enum nft_tunnel_key_attributes {enum nft_tunnel_keys {NFT_TUNNEL_PATH ,NFT_TUNNEL_ID , +NFT_TUNNEL_IP_SRC , +NFT_TUNNEL_IP_DST , __NFT_TUNNEL_MAX };#define NFT_TUNNEL_MAX (__NFT_TUNNEL_MAX - 1)
net/netfilter/nft_tunnel.c +22 -0
@@ -61,6 +61,26 @@ static void nft_tunnel_get_eval(const struct nft_expr *expr,else regs->verdict.code =NFT_BREAK ;break ; +case NFT_TUNNEL_IP_SRC : +if (!tun_info) { + regs->verdict.code =NFT_BREAK ; +return ; + } +if (nft_tunnel_mode_validate (priv->mode, tun_info->mode)) + *dest = tun_info->key.u.ipv4.src; +else + regs->verdict.code =NFT_BREAK ; +break ; +case NFT_TUNNEL_IP_DST : +if (!tun_info) { + regs->verdict.code =NFT_BREAK ; +return ; + } +if (nft_tunnel_mode_validate (priv->mode, tun_info->mode)) + *dest = tun_info->key.u.ipv4.dst; +else + regs->verdict.code =NFT_BREAK ; +break ;default :WARN_ON (1 ); regs->verdict.code =NFT_BREAK ;
@@ -90,6 +110,8 @@ static int nft_tunnel_get_init(const struct nft_ctx *ctx, len =sizeof (u8);break ;case NFT_TUNNEL_ID : +case NFT_TUNNEL_IP_SRC : +case NFT_TUNNEL_IP_DST : len =sizeof (u32);break ;default :
Signature · 1 line
1.8.3.1
PATCH v5 3/8 netfilter: nft_tunnel: add ipv6 check in nft_tunnel_mode_validate
In reply to [email protected]From: wenxu <[email protected]>
Add ipv6 tunnel check in nft_tunnel_mode_validate.
---
v5: no change
net/netfilter/nft_tunnel.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
net/netfilter/nft_tunnel.c +9 -5
@@ -18,8 +18,12 @@ struct nft_tunnel { enum nft_tunnel_mode mode:8; }; -bool nft_tunnel_mode_validate (enum nft_tunnel_mode priv_mode,u8 tun_mode) +bool nft_tunnel_mode_validate (enum nft_tunnel_mode priv_mode, +u8 tun_mode,bool ipv6) { +if (ipv6 && !(tun_mode &IP_TUNNEL_INFO_IPV6 )) +return false; + if (priv_mode == NFT_TUNNEL_MODE_NONE || (priv_mode == NFT_TUNNEL_MODE_RX && !(tun_mode & IP_TUNNEL_INFO_TX)) ||
@@ -46,7 +50,7 @@ static void nft_tunnel_get_eval(const struct nft_expr *expr,nft_reg_store8 (dest, false);return ; } -if (nft_tunnel_mode_validate (priv->mode, tun_info->mode)) +if (nft_tunnel_mode_validate (priv->mode, tun_info->mode, false))nft_reg_store8 (dest, true);else nft_reg_store8 (dest, false);
@@ -56,7 +60,7 @@ static void nft_tunnel_get_eval(const struct nft_expr *expr, regs->verdict.code =NFT_BREAK ;return ; } -if (nft_tunnel_mode_validate (priv->mode, tun_info->mode)) +if (nft_tunnel_mode_validate (priv->mode, tun_info->mode, false)) *dest =ntohl (tunnel_id_to_key32 (tun_info->key.tun_id));else regs->verdict.code =NFT_BREAK ;
@@ -66,7 +70,7 @@ static void nft_tunnel_get_eval(const struct nft_expr *expr, regs->verdict.code =NFT_BREAK ;return ; } -if (nft_tunnel_mode_validate (priv->mode, tun_info->mode)) +if (nft_tunnel_mode_validate (priv->mode, tun_info->mode, false)) *dest = tun_info->key.u.ipv4.src;else regs->verdict.code =NFT_BREAK ;
@@ -76,7 +80,7 @@ static void nft_tunnel_get_eval(const struct nft_expr *expr, regs->verdict.code =NFT_BREAK ;return ; } -if (nft_tunnel_mode_validate (priv->mode, tun_info->mode)) +if (nft_tunnel_mode_validate (priv->mode, tun_info->mode, false)) *dest = tun_info->key.u.ipv4.dst;else regs->verdict.code =NFT_BREAK ;
Signature · 1 line
1.8.3.1
PATCH v5 4/8 netfilter: nft_tunnel: support NFT_TUNNEL_IP6_SRC/DST match
In reply to [email protected]From: wenxu <[email protected]>
Add new two NFT_TUNNEL_IP6_SRC/DST match in nft_tunnel
---
v5: no change
include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nft_tunnel.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -1767,6 +1767,8 @@ enum nft_tunnel_keys {NFT_TUNNEL_ID ,NFT_TUNNEL_IP_SRC ,NFT_TUNNEL_IP_DST , +NFT_TUNNEL_IP6_SRC , +NFT_TUNNEL_IP6_DST , __NFT_TUNNEL_MAX };#define NFT_TUNNEL_MAX (__NFT_TUNNEL_MAX - 1)
net/netfilter/nft_tunnel.c +24 -0
@@ -85,6 +85,26 @@ static void nft_tunnel_get_eval(const struct nft_expr *expr,else regs->verdict.code =NFT_BREAK ;break ; +case NFT_TUNNEL_IP6_SRC : +if (!tun_info) { + regs->verdict.code =NFT_BREAK ; +return ; + } +if (nft_tunnel_mode_validate (priv->mode, tun_info->mode, true)) +memcpy (dest, &tun_info->key.u.ipv6.src,sizeof (struct in6_addr )); +else + regs->verdict.code =NFT_BREAK ; +break ; +case NFT_TUNNEL_IP6_DST : +if (!tun_info) { + regs->verdict.code =NFT_BREAK ; +return ; + } +if (nft_tunnel_mode_validate (priv->mode, tun_info->mode, true)) +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 ;
@@ -118,6 +138,10 @@ static int nft_tunnel_get_init(const struct nft_ctx *ctx,case NFT_TUNNEL_IP_DST : len =sizeof (u32);break ; +case NFT_TUNNEL_IP6_SRC : +case NFT_TUNNEL_IP6_DST : + len =sizeof (struct in6_addr ); +break ;default :return -EOPNOTSUPP ; }
Signature · 1 line
1.8.3.1
PATCH v5 5/8 netfilter: nft_tunnel: support tunnel meta match offload
In reply to [email protected]From: wenxu <[email protected]>
Add tunnel meta match offload. Currently support for NFT_TUNNEL_ID NFT_TUNNEL_SRC_IP and NFT_TUNNEL_DST_IP
---
v5: 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
@@ -44,6 +44,11 @@ struct nft_flow_key {struct flow_dissector_key_ip ip;struct flow_dissector_key_vlan vlan;struct flow_dissector_key_eth_addrs eth_addrs; +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
PATCH v5 6/8 netfilter: nft_tunnel: add NFTA_TUNNEL_KEY_RELEASE action
In reply to [email protected]From: wenxu <[email protected]>
Add new NFTA_TUNNEL_KEY_RELEASE action for future offload feature
---
v5: no change
include/uapi/linux/netfilter/nf_tables.h | 1 + net/netfilter/nft_tunnel.c | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +1 -0
@@ -1758,6 +1758,7 @@ enum nft_tunnel_key_attributes {NFTA_TUNNEL_KEY_SPORT ,NFTA_TUNNEL_KEY_DPORT ,NFTA_TUNNEL_KEY_OPTS , +NFTA_TUNNEL_KEY_RELEASE , __NFTA_TUNNEL_KEY_MAX };#define NFTA_TUNNEL_KEY_MAX (__NFTA_TUNNEL_KEY_MAX - 1)
net/netfilter/nft_tunnel.c +21 -3
@@ -247,6 +247,7 @@ struct nft_tunnel_opts {struct nft_tunnel_obj {struct metadata_dst *md;struct nft_tunnel_opts opts; +bool tunnel_key_release; };static const struct nla_policy nft_tunnel_ip_policy[NFTA_TUNNEL_KEY_IP_MAX +1 ] = {
@@ -431,6 +432,7 @@ static int nft_tunnel_obj_opts_init(const struct nft_ctx *ctx, [NFTA_TUNNEL_KEY_TOS] = { .type = NLA_U8, }, [NFTA_TUNNEL_KEY_TTL] = { .type = NLA_U8, }, [NFTA_TUNNEL_KEY_OPTS] = { .type = NLA_NESTED, }, + [NFTA_TUNNEL_KEY_RELEASE] = { .type = NLA_U8, }, }; static int nft_tunnel_obj_init(const struct nft_ctx *ctx,
@@ -442,6 +444,12 @@ static int nft_tunnel_obj_init(const struct nft_ctx *ctx,struct metadata_dst *md;int err; +if (tb[NFTA_TUNNEL_KEY_RELEASE ]) { + priv->tunnel_key_release = !!nla_get_u8 (tb[NFTA_TUNNEL_KEY_RELEASE ]); +if (priv->tunnel_key_release) +return 0 ; + } +if (!tb[NFTA_TUNNEL_KEY_ID ])return -EINVAL ;
@@ -524,8 +532,11 @@ static inline void nft_tunnel_obj_eval(struct nft_object *obj,struct sk_buff *skb = pkt->skb;skb_dst_drop (skb); -dst_hold ((struct dst_entry *) priv->md); -skb_dst_set (skb, (struct dst_entry *) priv->md); + +if (!priv->tunnel_key_release) { +dst_hold ((struct dst_entry *)priv->md); +skb_dst_set (skb, (struct dst_entry *)priv->md); + } }static int nft_tunnel_ip_dump (struct sk_buff *skb,struct ip_tunnel_info *info)
@@ -627,6 +638,12 @@ static int nft_tunnel_obj_dump(struct sk_buff *skb,struct nft_tunnel_obj *priv =nft_obj_data (obj);struct ip_tunnel_info *info = &priv->md->u.tun_info; +if (priv->tunnel_key_release) { +if (nla_put_u8 (skb,NFTA_TUNNEL_KEY_RELEASE ,1 )) + goto nla_put_failure; +return 0 ; + } + if (nla_put_be32(skb, NFTA_TUNNEL_KEY_ID, tunnel_id_to_key32(info->key.tun_id)) || nft_tunnel_ip_dump(skb, info) < 0 ||
@@ -648,7 +665,8 @@ static void nft_tunnel_obj_destroy(const struct nft_ctx *ctx, {struct nft_tunnel_obj *priv =nft_obj_data (obj); -metadata_dst_free (priv->md); +if (!priv->tunnel_key_release) +metadata_dst_free (priv->md); }static struct nft_object_type nft_tunnel_obj_type;
Signature · 1 line
1.8.3.1
PATCH v5 7/8 netfilter: nft_objref: add nft_objref_type offload
In reply to [email protected]From: wenxu <[email protected]>
support offload for nft_objref_type
---
v5: no offload_actions callback
include/net/netfilter/nf_tables.h | 3 +++ net/netfilter/nft_objref.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+)
include/net/netfilter/nf_tables.h +3 -0
@@ -1123,6 +1123,9 @@ struct nft_object_ops {int (*dump)(struct sk_buff *skb,struct nft_object *obj,bool reset); +int (*offload)(struct nft_offload_ctx *ctx, +struct nft_flow_rule *flow, +struct nft_object *obj);const struct nft_object_type *type; };
net/netfilter/nft_objref.c +14 -0
@@ -10,6 +10,7 @@#include <linux/netfilter.h> #include <linux/netfilter/nf_tables.h> #include <net/netfilter/nf_tables.h> +#include <net/netfilter/nf_tables_offload.h> #define nft_objref_priv (expr) *((struct nft_object **)nft_expr_priv(expr))
@@ -82,6 +83,18 @@ static void nft_objref_activate(const struct nft_ctx *ctx, obj->use++; } +static int nft_objref_offload (struct nft_offload_ctx *ctx, +struct nft_flow_rule *flow, +const struct nft_expr *expr) +{ +struct nft_object *obj =nft_objref_priv (expr); + +if (obj->ops->offload) +return obj->ops->offload (ctx, flow, obj); +else +return -EOPNOTSUPP ; +} +static struct nft_expr_type nft_objref_type;static const struct nft_expr_ops nft_objref_ops = { .type = &nft_objref_type,
@@ -91,6 +104,7 @@ static void nft_objref_activate(const struct nft_ctx *ctx, .activate = nft_objref_activate, .deactivate = nft_objref_deactivate, .dump = nft_objref_dump, + .offload = nft_objref_offload, };struct nft_objref_map {
Signature · 1 line
1.8.3.1
PATCH v5 8/8 netfilter: nft_tunnel: support nft_tunnel_obj offload
In reply to [email protected]From: wenxu <[email protected]>
Add nft_tunnel_obj offload for both encap and decap actions
---
v5: no change
net/netfilter/nft_tunnel.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
net/netfilter/nft_tunnel.c +20 -0
@@ -669,6 +669,25 @@ static void nft_tunnel_obj_destroy(const struct nft_ctx *ctx,metadata_dst_free (priv->md); } +static int nft_tunnel_obj_offload (struct nft_offload_ctx *ctx, +struct nft_flow_rule *flow, +struct nft_object *obj) +{ +struct nft_tunnel_obj *priv =nft_obj_data (obj); +struct flow_action_entry *entry; + + entry = &flow->rule->action.entries[ctx->num_actions++]; + +if (!priv->tunnel_key_release) { + entry->id =FLOW_ACTION_TUNNEL_ENCAP ; + entry->tunnel = &priv->md->u.tun_info; + }else { + entry->id =FLOW_ACTION_TUNNEL_DECAP ; + } + +return 0 ; +} +static struct nft_object_type nft_tunnel_obj_type;static const struct nft_object_ops nft_tunnel_obj_ops = { .type = &nft_tunnel_obj_type,
@@ -677,6 +696,7 @@ static void nft_tunnel_obj_destroy(const struct nft_ctx *ctx, .init = nft_tunnel_obj_init, .destroy = nft_tunnel_obj_destroy, .dump = nft_tunnel_obj_dump, + .offload = nft_tunnel_obj_offload, };static struct nft_object_type nft_tunnel_obj_type__read_mostly = {
Signature · 1 line
1.8.3.1
Hi pablo,
Any comments for this series?
BR
wenxu
Quoted 25 lines · On 8/21/2019 1:09 PM, [email protected] wrote:
From: wenxu <[email protected]>
This series add NFT_TUNNEL_IP/6_SRC/DST match and tunnel expr offload. Also add
NFTA_TUNNEL_KEY_RELEASEactions adn objref, tunnel obj offloadThis version just split from the orignal big seriese without dependency with each other
wenxu (8):
netfilter:nft_tunnel: addnft_tunnel_mode_validatefunction
netfilter:nft_tunnel: support NFT_TUNNEL_IP_SRC/DST match
netfilter:nft_tunnel: add ipv6 check innft_tunnel_mode_validate
netfilter:nft_tunnel: support NFT_TUNNEL_IP6_SRC/DST match
netfilter:nft_tunnel: support tunnel meta match offload
netfilter:nft_tunnel: addNFTA_TUNNEL_KEY_RELEASEaction
netfilter:nft_objref: addnft_objref_typeoffload
netfilter:nft_tunnel: supportnft_tunnel_objoffloadinclude/net/netfilter/nf_tables.h | 3 + include/net/netfilter/nf_tables_offload.h | 5 + include/uapi/linux/netfilter/nf_tables.h | 5 + net/netfilter/nft_objref.c | 14 +++ net/netfilter/nft_tunnel.c | 159 +++++++++++++++++++++++++++--- 5 files changed, 173 insertions(+), 13 deletions(-)