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 v6 6/8] ip_tunnel: make ip_tunnel_encap() return a drop reason
Date: Tue, 10 Nov 2026 23:20:19 +0300 [thread overview]
Message-ID: <20261110202021.821224-7-littlesmilingcloud@gmail.com> (raw)
In-Reply-To: <20261110202021.821224-1-littlesmilingcloud@gmail.com>
ip_tunnel_encap() builds the FOU or GUE header of an IPv4 tunnel and
returns 0 or a negative error, so its callers can tell that the packet
has to be dropped, but not why.
Make it return the drop reason instead, like __iptunnel_pull_header()
and gre_parse_header() do:
- SKB_NOT_DROPPED_YET when no encapsulation is configured or the
header is built,
- SKB_DROP_REASON_NOMEM when the build_header() callback fails with
-ENOMEM, which the FOU and GUE callbacks do when the header of a GSO
packet cannot be uncloned,
- SKB_DROP_REASON_TUNNEL_ENCAP, a new reason, for any other failure,
such as an encapsulation type without a registered callback.
The three callers, two in ip_tunnel.c and one in sit.c, tested the
result with "< 0". With the enum, that test would always be false and
no compiler warns about it, so they test for a non-zero value now. The
next patch reports the reason in the transmit path of ip_tunnel; sit
still frees the packet with a plain kfree_skb().
ip6_tnl_encap() keeps returning an int for now: its only caller,
ip6_tnl_xmit(), returns an int as well, and both belong to the IPv6
transmit path, which is left for a later series.
Suggested-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 2df44745cf3b..fb6f3d8da960 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -131,6 +131,7 @@
FN(TUNNEL_OPT_MISMATCH) \
FN(TUNNEL_OLD_SEQ) \
FN(GRE_CSUM) \
+ FN(TUNNEL_ENCAP) \
FNe(MAX)
/**
@@ -634,6 +635,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_MAX: the maximum of core drop reasons, which
* shouldn't be used as a real 'reason' - only for tracing code gen
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 7d8744ed1664..f3c5d8424925 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;
use_cache = ip_tunnel_dst_cache_usable(skb, tun_info);
@@ -780,7 +780,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;
if (connected && md) {
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-10 20:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 20:20 [PATCH net-next v6 0/8] tunnels: add core and gre drop reasons Anton Danilov
2026-11-10 20:20 ` [PATCH net-next v6 1/8] ip_tunnel: add drop reasons to the generic RX path Anton Danilov
2026-11-10 20:20 ` [PATCH net-next v6 2/8] ip6_tunnel: add drop reasons to the receive path Anton Danilov
2026-11-10 20:20 ` [PATCH net-next v6 3/8] gre: make gre_parse_header() report a drop reason Anton Danilov
2026-11-10 20:20 ` [PATCH net-next v6 4/8] ip_gre: add drop reasons to the RX path Anton Danilov
2026-11-10 20:20 ` [PATCH net-next v6 5/8] ip6_gre: " Anton Danilov
2026-11-10 20:20 ` Anton Danilov [this message]
2026-11-10 20:20 ` [PATCH net-next v6 7/8] ip_tunnel: add drop reasons to the transmit path Anton Danilov
2026-11-10 20:20 ` [PATCH net-next v6 8/8] ip_gre: " Anton Danilov
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=20261110202021.821224-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®