[PATCH net-next v4 06/10] ip6_gre: add drop reasons to the RX path

From: Anton Danilov

Date: Tue Sep 22 2026 - 18:16:43 EST


Mirror the previous patch on the IPv6 side. So far gre_rcv() reported
the drops below as SKB_DROP_REASON_NOT_SPECIFIED, all from the same
kfree_skb_reason() call. Now it reports:

- SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND when no tunnel matches,
- SKB_DROP_REASON_HDR_TRUNC when a header is too short,
- what __iptunnel_pull_header_reason() returns when the pull fails,
- SKB_DROP_REASON_NOMEM when the metadata dst cannot be allocated.

Unlike ip_gre, gre_rcv() calls the helper before the tunnel lookup, so a
packet whose ETH_P_TEB inner Ethernet header or WCCPv2 extra word is cut
short is reported as SKB_DROP_REASON_PKT_TOO_SMALL whether a tunnel
matches or not.

Like their IPv4 counterparts, ip6gre_rcv() and ip6erspan_rcv() now
return SKB_NOT_DROPPED_YET where they returned PACKET_RCVD and a drop
reason where they returned PACKET_REJECT. That leaves PACKET_RCVD,
PACKET_REJECT and PACKET_NEXT without users, so remove them.
PACKET_REJECT has the value of SKB_CONSUMED, and a stray one in a
function that now returns a drop reason would build silently and be
traced as a consumed packet.

Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Anton Danilov <littlesmilingcloud@xxxxxxxxx>
---
include/net/ip_tunnels.h | 4 ----
net/ipv6/ip6_gre.c | 46 +++++++++++++++++++++++-----------------
2 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index c68031d01c39..27a9e097996b 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -207,10 +207,6 @@ struct tnl_ptk_info {
int hdr_len;
};

-#define PACKET_RCVD 0
-#define PACKET_REJECT 1
-#define PACKET_NEXT 2
-
#define IP_TNL_HASH_BITS 7
#define IP_TNL_HASH_SIZE (1 << IP_TNL_HASH_BITS)

diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index d36949cbe9fa..ada48e23ca9d 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -451,7 +451,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 enum skb_drop_reason ip6gre_rcv(struct sk_buff *skb,
+ const struct tnl_ptk_info *tpi)
{
const struct ipv6hdr *ipv6h;
struct ip6_tnl *tunnel;
@@ -471,22 +472,22 @@ static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi)

tun_dst = ipv6_tun_rx_dst(skb, flags, tun_id, 0);
if (!tun_dst)
- return PACKET_REJECT;
+ return SKB_DROP_REASON_NOMEM;

ip6_tnl_rcv(tunnel, skb, tpi, tun_dst, log_ecn_error);
} else {
ip6_tnl_rcv(tunnel, skb, tpi, NULL, log_ecn_error);
}

- return PACKET_RCVD;
+ return SKB_NOT_DROPPED_YET;
}

- return PACKET_REJECT;
+ return SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;
}

-static int ip6erspan_rcv(struct sk_buff *skb,
- struct tnl_ptk_info *tpi,
- int gre_hdr_len)
+static enum skb_drop_reason ip6erspan_rcv(struct sk_buff *skb,
+ struct tnl_ptk_info *tpi,
+ int gre_hdr_len)
{
struct erspan_base_hdr *ershdr;
const struct ipv6hdr *ipv6h;
@@ -495,7 +496,7 @@ static int ip6erspan_rcv(struct sk_buff *skb,
u8 ver;

if (unlikely(!pskb_may_pull(skb, sizeof(*ershdr))))
- return PACKET_REJECT;
+ return SKB_DROP_REASON_HDR_TRUNC;

ipv6h = ipv6_hdr(skb);
ershdr = (struct erspan_base_hdr *)skb->data;
@@ -506,14 +507,16 @@ static int ip6erspan_rcv(struct sk_buff *skb,
tpi->proto);
if (tunnel) {
int len = erspan_hdr_len(ver);
+ enum skb_drop_reason reason;

if (unlikely(!pskb_may_pull(skb, len)))
- return PACKET_REJECT;
+ return SKB_DROP_REASON_HDR_TRUNC;

- if (__iptunnel_pull_header(skb, len,
- htons(ETH_P_TEB),
- false, false) < 0)
- return PACKET_REJECT;
+ reason = __iptunnel_pull_header_reason(skb, len,
+ htons(ETH_P_TEB),
+ false, false);
+ if (reason)
+ return reason;

if (tunnel->parms.collect_md) {
struct erspan_metadata *pkt_md, *md;
@@ -530,7 +533,7 @@ static int ip6erspan_rcv(struct sk_buff *skb,
tun_dst = ipv6_tun_rx_dst(skb, flags, tun_id,
sizeof(*md));
if (!tun_dst)
- return PACKET_REJECT;
+ return SKB_DROP_REASON_NOMEM;

/* MUST set options_len before referencing options */
info = &tun_dst->u.tun_info;
@@ -558,10 +561,10 @@ static int ip6erspan_rcv(struct sk_buff *skb,
ip6_tnl_rcv(tunnel, skb, tpi, NULL, log_ecn_error);
}

- return PACKET_RCVD;
+ return SKB_NOT_DROPPED_YET;
}

- return PACKET_REJECT;
+ return SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND;
}

static int gre_rcv(struct sk_buff *skb)
@@ -572,19 +575,22 @@ static int gre_rcv(struct sk_buff *skb)
reason = gre_parse_header(skb, &tpi, false, htons(ETH_P_IPV6), 0);
if (reason)
goto drop;
- reason = SKB_DROP_REASON_NOT_SPECIFIED;

- if (iptunnel_pull_header(skb, tpi.hdr_len, tpi.proto, false))
+ reason = __iptunnel_pull_header_reason(skb, tpi.hdr_len, tpi.proto,
+ false, false);
+ if (reason)
goto drop;

if (unlikely(tpi.proto == htons(ETH_P_ERSPAN) ||
tpi.proto == htons(ETH_P_ERSPAN2))) {
- if (ip6erspan_rcv(skb, &tpi, tpi.hdr_len) == PACKET_RCVD)
+ reason = ip6erspan_rcv(skb, &tpi, tpi.hdr_len);
+ if (!reason)
return 0;
goto out;
}

- if (ip6gre_rcv(skb, &tpi) == PACKET_RCVD)
+ reason = ip6gre_rcv(skb, &tpi);
+ if (!reason)
return 0;

out:
--
2.47.3