From: Anton Danilov <littlesmilingcloud@gmail.com>
To: netdev@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v8 6/8] ip_tunnel: make ip_tunnel_encap() return a drop reason
Date: Mon, 23 Nov 2026 13:42:08 +0300 [thread overview]
Message-ID: <20261123104210.199916-7-littlesmilingcloud@gmail.com> (raw)
In-Reply-To: <20261123104210.199916-1-littlesmilingcloud@gmail.com>
IPv4 tunnel transmitters need the reason why encapsulation failed.
Make ip_tunnel_encap() return NOMEM when the FOU or GUE build_header()
callback returns -ENOMEM, and TUNNEL_ENCAP for other failures. Success,
including when encapsulation is disabled, still returns zero.
Update both callers in ip_tunnel.c and the one in sit.c to test for a
nonzero result. Their old negative-error test would miss a drop reason.
Suggested-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
include/net/dropreason-core.h | 7 +++++++
include/net/ip_tunnels.h | 16 ++++++++++------
net/ipv4/ip_tunnel.c | 4 ++--
net/ipv6/sit.c | 2 +-
4 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h
index 7150f357c1c6..767f528e099c 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -116,6 +116,7 @@
FN(TUNNEL_OPT_MISMATCH) \
FN(TUNNEL_OLD_SEQ) \
FN(GRE_CSUM) \
+ FN(TUNNEL_ENCAP) \
FN(MAC_INVALID_SOURCE) \
FN(VXLAN_ENTRY_EXISTS) \
FN(NO_TX_TARGET) \
@@ -572,6 +573,12 @@ enum skb_drop_reason {
SKB_DROP_REASON_TUNNEL_OLD_SEQ,
/** @SKB_DROP_REASON_GRE_CSUM: GRE checksum error */
SKB_DROP_REASON_GRE_CSUM,
+ /**
+ * @SKB_DROP_REASON_TUNNEL_ENCAP: failed to build the encapsulation
+ * header of a tunnel, e.g. an unknown or unregistered encapsulation
+ * type.
+ */
+ SKB_DROP_REASON_TUNNEL_ENCAP,
/** @SKB_DROP_REASON_MAC_INVALID_SOURCE: source mac is invalid */
SKB_DROP_REASON_MAC_INVALID_SOURCE,
/**
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 792690ae4f26..87046ba50d45 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -541,18 +541,18 @@ static inline int ip_encap_hlen(struct ip_tunnel_encap *e)
return hlen;
}
-static inline int ip_tunnel_encap(struct sk_buff *skb,
- struct ip_tunnel_encap *e,
- u8 *protocol, struct flowi4 *fl4)
+static inline enum skb_drop_reason
+ip_tunnel_encap(struct sk_buff *skb, struct ip_tunnel_encap *e,
+ u8 *protocol, struct flowi4 *fl4)
{
const struct ip_tunnel_encap_ops *ops;
int ret = -EINVAL;
if (e->type == TUNNEL_ENCAP_NONE)
- return 0;
+ return SKB_NOT_DROPPED_YET;
if (e->type >= MAX_IPTUN_ENCAP_OPS)
- return -EINVAL;
+ return SKB_DROP_REASON_TUNNEL_ENCAP;
rcu_read_lock();
ops = rcu_dereference(iptun_encaps[e->type]);
@@ -560,7 +560,11 @@ static inline int ip_tunnel_encap(struct sk_buff *skb,
ret = ops->build_header(skb, e, protocol, fl4);
rcu_read_unlock();
- return ret;
+ if (!ret)
+ return SKB_NOT_DROPPED_YET;
+ if (ret == -ENOMEM)
+ return SKB_DROP_REASON_NOMEM;
+ return SKB_DROP_REASON_TUNNEL_ENCAP;
}
/* Extract dsfield from inner protocol */
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index 5137c26b9c1d..92e26464f2ee 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -619,7 +619,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
if (!tunnel_hlen)
tunnel_hlen = ip_encap_hlen(&tun_info->encap);
- if (ip_tunnel_encap(skb, &tun_info->encap, &proto, &fl4) < 0)
+ if (ip_tunnel_encap(skb, &tun_info->encap, &proto, &fl4))
goto tx_error;
inner_iph = (const struct iphdr *)skb_inner_network_header(skb);
@@ -783,7 +783,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
tunnel->net, READ_ONCE(tunnel->parms.link),
tunnel->fwmark, skb_get_hash(skb), 0);
- if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0)
+ if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4))
goto tx_error;
inner_iph = (const struct iphdr *)skb_inner_network_header(skb);
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index a7ec800216ad..9576d146c961 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -1096,7 +1096,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
ttl = iph6->hop_limit;
tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6));
- if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4) < 0) {
+ if (ip_tunnel_encap(skb, &tunnel->encap, &protocol, &fl4)) {
ip_rt_put(rt);
goto tx_error;
}
--
2.47.3
next prev parent reply other threads:[~2026-11-23 10:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 10:42 [PATCH net-next v8 0/8] tunnels: add core and gre drop reasons Anton Danilov
2026-11-23 10:42 ` [PATCH net-next v8 1/8] ip_tunnel: add drop reasons to the generic RX path Anton Danilov
2026-11-23 10:42 ` [PATCH net-next v8 2/8] ip6_tunnel: add drop reasons to the receive path Anton Danilov
2026-11-23 10:42 ` [PATCH net-next v8 3/8] gre: make gre_parse_header() report a drop reason Anton Danilov
2026-11-23 10:42 ` [PATCH net-next v8 4/8] ip_gre: add drop reasons to the RX path Anton Danilov
2026-11-23 10:42 ` [PATCH net-next v8 5/8] ip6_gre: " Anton Danilov
2026-11-23 10:42 ` Anton Danilov [this message]
2026-11-23 10:42 ` [PATCH net-next v8 7/8] ip_tunnel: add drop reasons to the transmit path Anton Danilov
2026-11-23 10:42 ` [PATCH net-next v8 8/8] ip_gre: " Anton Danilov
2026-11-29 17:40 ` [PATCH net-next v8 0/8] tunnels: add core and gre drop reasons patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123104210.199916-7-littlesmilingcloud@gmail.com \
--to=littlesmilingcloud@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.