From: wenxu <wenxu@xxxxxxxxx> Add new NFTA_TUNNEL_KEY_RELEASE action for future offload feature Signed-off-by: wenxu <wenxu@xxxxxxxxx> --- include/uapi/linux/netfilter/nf_tables.h | 1 + net/netfilter/nft_tunnel.c | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/uapi/linux/netfilter/nf_tables.h b/include/uapi/linux/netfilter/nf_tables.h index da9b1d1..0e24c27 100644 --- a/include/uapi/linux/netfilter/nf_tables.h +++ b/include/uapi/linux/netfilter/nf_tables.h @@ -1766,6 +1766,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) diff --git a/net/netfilter/nft_tunnel.c b/net/netfilter/nft_tunnel.c index 68ca894..15d5dc9 100644 --- a/net/netfilter/nft_tunnel.c +++ b/net/netfilter/nft_tunnel.c @@ -262,6 +262,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] = { @@ -446,6 +447,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, @@ -457,6 +459,12 @@ static int nft_tunnel_obj_init(const struct nft_ctx *ctx, struct metadata_dst *md; int err; + if (tb[NFTA_TUNNEL_KEY_RELEASE] && + nla_get_u8(tb[NFTA_TUNNEL_KEY_RELEASE])) { + priv->tunnel_key_release = true; + return 0; + } + if (!tb[NFTA_TUNNEL_KEY_ID]) return -EINVAL; @@ -539,8 +547,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) @@ -642,6 +653,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 || @@ -663,7 +680,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; -- 1.8.3.1