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>,
Ido Schimmel <idosch@nvidia.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v2 5/8] ip6_gre: add drop reasons to the RX path
Date: Sun, 13 Sep 2026 06:49:34 +0300 [thread overview]
Message-ID: <20260913034937.875068-6-littlesmilingcloud@gmail.com> (raw)
In-Reply-To: <20260913034937.875068-1-littlesmilingcloud@gmail.com>
Mirror the previous patch on the IPv6 side: report
SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND when no tunnel matches the packet,
and tell that apart from a header that cannot be pulled
(SKB_DROP_REASON_HDR_TRUNC) or a metadata allocation failure
(SKB_DROP_REASON_NOMEM), which so far all ended up in the same plain
kfree_skb() in gre_rcv().
ip6gre_rcv() and ip6erspan_rcv() get the same output parameter as their
IPv4 counterparts.
Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
net/ipv6/ip6_gre.c | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 78854cc2dac9..047c4f57a828 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -454,7 +454,8 @@ static int ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
return 0;
}
-static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
+static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,
+ enum skb_drop_reason *reason)
{
const struct ipv6hdr *ipv6h;
struct ip6_tnl *tunnel;
@@ -473,8 +474,10 @@ static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
tun_id = key32_to_tunnel_id(tpi->key);
tun_dst = ipv6_tun_rx_dst(skb, flags, tun_id, 0);
- if (!tun_dst)
+ if (!tun_dst) {
+ *reason = SKB_DROP_REASON_NOMEM;
return PACKET_REJECT;
+ }
ip6_tnl_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);
} else {
@@ -484,12 +487,14 @@ static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)
return PACKET_RCVD;
}
+ *reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;
return PACKET_REJECT;
}
static int ip6erspan_rcv(struct sk_buff *skb,
struct tnl_ptk_info *tpi,
- int gre_hdr_len)
+ int gre_hdr_len,
+ enum skb_drop_reason *reason)
{
struct erspan_base_hdr *ershdr;
const struct ipv6hdr *ipv6h;
@@ -497,8 +502,10 @@ static int ip6erspan_rcv(struct sk_buff *skb,
struct ip6_tnl *tunnel;
u8 ver;
- if (unlikely(!pskb_may_pull(skb, sizeof(*ershdr))))
+ if (unlikely(!pskb_may_pull(skb, sizeof(*ershdr)))) {
+ *reason = SKB_DROP_REASON_HDR_TRUNC;
return PACKET_REJECT;
+ }
ipv6h = ipv6_hdr(skb);
ershdr = (struct erspan_base_hdr *)skb->data;
@@ -510,13 +517,17 @@ static int ip6erspan_rcv(struct sk_buff *skb,
if (tunnel) {
int 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,
htons(ETH_P_TEB),
- false, false) < 0)
+ false, false) < 0) {
+ *reason = SKB_DROP_REASON_HDR_TRUNC;
return PACKET_REJECT;
+ }
if (tunnel->parms.collect_md) {
struct erspan_metadata *pkt_md, *md;
@@ -532,8 +543,10 @@ static int ip6erspan_rcv(struct sk_buff *skb,
tun_dst = ipv6_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;
@@ -564,6 +577,7 @@ static int ip6erspan_rcv(struct sk_buff *skb,
return PACKET_RCVD;
}
+ *reason = SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;
return PACKET_REJECT;
}
@@ -577,17 +591,19 @@ static int gre_rcv(struct sk_buff *skb)
if (hdr_len < 0)
goto drop;
- if (iptunnel_pull_header(skb, hdr_len, tpi.proto, false))
+ if (iptunnel_pull_header(skb, hdr_len, tpi.proto, false)) {
+ reason = SKB_DROP_REASON_HDR_TRUNC;
goto drop;
+ }
if (unlikely(tpi.proto == htons(ETH_P_ERSPAN) ||
tpi.proto == htons(ETH_P_ERSPAN2))) {
- if (ip6erspan_rcv(skb, &tpi, hdr_len) == PACKET_RCVD)
+ if (ip6erspan_rcv(skb, &tpi, hdr_len, &reason) == PACKET_RCVD)
return 0;
goto out;
}
- if (ip6gre_rcv(skb, &tpi) == PACKET_RCVD)
+ if (ip6gre_rcv(skb, &tpi, &reason) == PACKET_RCVD)
return 0;
out:
--
2.47.3
next prev parent reply other threads:[~2026-09-13 3:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-13 3:49 [PATCH net-next v2 0/8] tunnels: add core and gre drop reasons Anton Danilov
2026-09-13 3:49 ` [PATCH net-next v2 1/8] ip_tunnel: add drop reasons to the generic RX path Anton Danilov
2026-09-13 3:49 ` [PATCH net-next v2 2/8] ip6_tunnel: " Anton Danilov
2026-09-13 3:49 ` [PATCH net-next v2 3/8] gre: make gre_parse_header() report a drop reason Anton Danilov
2026-09-13 3:49 ` [PATCH net-next v2 4/8] ip_gre: add drop reasons to the RX path Anton Danilov
2026-09-13 3:49 ` Anton Danilov [this message]
2026-09-13 3:49 ` [PATCH net-next v2 6/8] ip_tunnel: add drop reasons to the transmit path Anton Danilov
2026-09-13 3:49 ` [PATCH net-next v2 7/8] ip_gre: " Anton Danilov
2026-09-13 3:49 ` [PATCH net-next v2 8/8] ip6_tunnel: " 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=20260913034937.875068-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=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.