From: Anton Danilov <littlesmilingcloud@gmail.com>
To: netdev@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
David Ahern <dsahern@kernel.org>, Simon Horman <horms@kernel.org>,
Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH net-next 05/11] ip_gre: add drop reasons to the RX path
Date: Tue, 1 Sep 2026 00:51:31 +0300 [thread overview]
Message-ID: <20260831215137.549324-6-littlesmilingcloud@gmail.com> (raw)
In-Reply-To: <20260831215137.549324-1-littlesmilingcloud@gmail.com>
A packet that reaches gre_rcv() and does not belong to any tunnel is
dropped, after an ICMP port unreachable is sent back, with a plain
kfree_skb(). This is the GRE counterpart of a UDP packet hitting no
socket, and by far the most common way a GRE packet is dropped on
receive, yet nothing tells it apart from a malformed one.
Add SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND for it, in the spirit of the
existing SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND, and report it from
erspan_rcv() and __ipgre_rcv() through a new output parameter, so that a
failed lookup is not reported the same way as a header that could not be
pulled or as a metadata allocation failure.
The header pull failures reuse SKB_DROP_REASON_HDR_TRUNC and the
metadata allocation failures reuse SKB_DROP_REASON_NOMEM.
Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
include/net/dropreason-core.h | 6 ++++++
net/ipv4/ip_gre.c | 37 +++++++++++++++++++++++------------
2 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h
index 8efa682601f0..d1fb52c1b0cb 100644
--- a/include/net/dropreason-core.h
+++ b/include/net/dropreason-core.h
@@ -132,6 +132,7 @@
FN(IP_TUNNEL_OLD_SEQ) \
FN(GRE_INVALID_HDR) \
FN(GRE_CSUM) \
+ FN(GRE_TUNNEL_NOT_FOUND) \
FNe(MAX)
/**
@@ -631,6 +632,11 @@ enum skb_drop_reason {
SKB_DROP_REASON_GRE_INVALID_HDR,
/** @SKB_DROP_REASON_GRE_CSUM: GRE checksum error */
SKB_DROP_REASON_GRE_CSUM,
+ /**
+ * @SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND: no GRE tunnel found for the
+ * endpoints and the key the packet carries.
+ */
+ SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND,
/**
* @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/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 1894c5746a73..4d9bb6d186ae 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -265,7 +265,7 @@ static bool is_erspan_type1(int gre_hdr_len)
}
static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
- int gre_hdr_len)
+ int gre_hdr_len, enum skb_drop_reason *reason)
{
struct net *net = dev_net(skb->dev);
struct metadata_dst *tun_dst = NULL;
@@ -289,8 +289,10 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
iph->saddr, iph->daddr, 0);
} else {
if (unlikely(!pskb_may_pull(skb,
- gre_hdr_len + sizeof(*ershdr))))
+ gre_hdr_len + sizeof(*ershdr)))) {
+ *reason = SKB_DROP_REASON_HDR_TRUNC;
return PACKET_REJECT;
+ }
ershdr = (struct erspan_base_hdr *)(skb->data + gre_hdr_len);
ver = ershdr->ver;
@@ -306,8 +308,10 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
else
len = gre_hdr_len + erspan_hdr_len(ver);
- if (unlikely(!pskb_may_pull(skb, len)))
+ if (unlikely(!pskb_may_pull(skb, len))) {
+ *reason = SKB_DROP_REASON_HDR_TRUNC;
return PACKET_REJECT;
+ }
if (__iptunnel_pull_header(skb,
len,
@@ -327,8 +331,10 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
tun_dst = ip_tun_rx_dst(skb, flags,
tun_id, sizeof(*md));
- if (!tun_dst)
+ if (!tun_dst) {
+ *reason = SKB_DROP_REASON_NOMEM;
return PACKET_REJECT;
+ }
/* MUST set options_len before referencing options */
info = &tun_dst->u.tun_info;
@@ -356,15 +362,17 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
ip_tunnel_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);
return PACKET_RCVD;
}
+ *reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;
return PACKET_REJECT;
drop:
- kfree_skb(skb);
+ kfree_skb_reason(skb, SKB_DROP_REASON_HDR_TRUNC);
return PACKET_RCVD;
}
static int __ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
- struct ip_tunnel_net *itn, int hdr_len, bool raw_proto)
+ struct ip_tunnel_net *itn, int hdr_len, bool raw_proto,
+ enum skb_drop_reason *reason)
{
struct metadata_dst *tun_dst = NULL;
const struct iphdr *iph;
@@ -400,22 +408,25 @@ static int __ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
tun_id = key32_to_tunnel_id(tpi->key);
tun_dst = ip_tun_rx_dst(skb, flags, tun_id, 0);
- if (!tun_dst)
+ if (!tun_dst) {
+ *reason = SKB_DROP_REASON_NOMEM;
return PACKET_REJECT;
+ }
}
ip_tunnel_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);
return PACKET_RCVD;
}
+ *reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;
return PACKET_NEXT;
drop:
- kfree_skb(skb);
+ kfree_skb_reason(skb, SKB_DROP_REASON_HDR_TRUNC);
return PACKET_RCVD;
}
static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
- int hdr_len)
+ int hdr_len, enum skb_drop_reason *reason)
{
struct net *net = dev_net(skb->dev);
struct ip_tunnel_net *itn;
@@ -426,13 +437,13 @@ static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
else
itn = net_generic(net, ipgre_net_id);
- res = __ipgre_rcv(skb, tpi, itn, hdr_len, false);
+ res = __ipgre_rcv(skb, tpi, itn, hdr_len, false, reason);
if (res == PACKET_NEXT && tpi->proto == htons(ETH_P_TEB)) {
/* ipgre tunnels in collect metadata mode should receive
* also ETH_P_TEB traffic.
*/
itn = net_generic(net, ipgre_net_id);
- res = __ipgre_rcv(skb, tpi, itn, hdr_len, true);
+ res = __ipgre_rcv(skb, tpi, itn, hdr_len, true, reason);
}
return res;
}
@@ -457,12 +468,12 @@ static int gre_rcv(struct sk_buff *skb)
if (unlikely(tpi.proto == htons(ETH_P_ERSPAN) ||
tpi.proto == htons(ETH_P_ERSPAN2))) {
- if (erspan_rcv(skb, &tpi, hdr_len) == PACKET_RCVD)
+ if (erspan_rcv(skb, &tpi, hdr_len, &reason) == PACKET_RCVD)
return 0;
goto out;
}
- if (ipgre_rcv(skb, &tpi, hdr_len) == PACKET_RCVD)
+ if (ipgre_rcv(skb, &tpi, hdr_len, &reason) == PACKET_RCVD)
return 0;
out:
--
2.47.3
next prev parent reply other threads:[~2026-08-31 21:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 21:51 [PATCH net-next 00/11] tunnels: add core and gre drop reasons Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 01/11] ip_tunnel: add drop reasons to the generic RX path Anton Danilov
2026-09-03 1:47 ` Jakub Kicinski
2026-09-03 1:47 ` Jakub Kicinski
2026-08-31 21:51 ` [PATCH net-next 02/11] ip6_tunnel: " Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 03/11] selftests: net: add a test for the tunnel RX drop reasons Anton Danilov
2026-09-03 1:45 ` Jakub Kicinski
2026-08-31 21:51 ` [PATCH net-next 04/11] gre: make gre_parse_header() report a drop reason Anton Danilov
2026-08-31 21:51 ` Anton Danilov [this message]
2026-08-31 21:51 ` [PATCH net-next 06/11] ip6_gre: add drop reasons to the RX path Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 07/11] selftests: net: cover the GRE specific drop reasons Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 08/11] ip_tunnel: add drop reasons to the transmit path Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 09/11] ip_gre: " Anton Danilov
2026-08-31 21:51 ` [PATCH net-next 10/11] ip6_tunnel: " Anton Danilov
2026-09-03 1:43 ` Jakub Kicinski
2026-08-31 21:51 ` [PATCH net-next 11/11] selftests: net: cover the tunnel transmit drop reasons 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=20260831215137.549324-6-littlesmilingcloud@gmail.com \
--to=littlesmilingcloud@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/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