@@ -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)
@@ -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;