[PATCH net-next v5 08/14] ip6_gre: add drop reasons to the RX path

From: Anton Danilov

Date: Wed Sep 30 2026 - 16:21:52 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_TUNNEL_NOT_FOUND when no tunnel matches,
- what pskb_may_pull_reason() returns when an ERSPAN header cannot be
pulled,
- what iptunnel_pull_header() and __iptunnel_pull_header() return
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: LLM
Signed-off-by: Anton Danilov <littlesmilingcloud@xxxxxxxxx>
---
include/net/ip_tunnels.h | 4 ----
net/ipv6/ip6_gre.c | 49 +++++++++++++++++++++++-----------------
2 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 5cccf4c0e691..792690ae4f26 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 25fd290082c4..3333a0ab180c 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,31 +472,33 @@ 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_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;
+ enum skb_drop_reason reason;
struct erspan_md2 *md2;
struct ip6_tnl *tunnel;
u8 ver;

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

ipv6h = ipv6_hdr(skb);
ershdr = (struct erspan_base_hdr *)skb->data;
@@ -507,13 +510,14 @@ static int ip6erspan_rcv(struct sk_buff *skb,
if (tunnel) {
int len = erspan_hdr_len(ver);

- if (unlikely(!pskb_may_pull(skb, len)))
- return PACKET_REJECT;
+ reason = pskb_may_pull_reason(skb, len);
+ if (unlikely(reason))
+ return reason;

- if (__iptunnel_pull_header(skb, len,
- htons(ETH_P_TEB),
- false, false))
- return PACKET_REJECT;
+ reason = __iptunnel_pull_header(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 +534,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 +562,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_TUNNEL_NOT_FOUND;
}

static int gre_rcv(struct sk_buff *skb)
@@ -573,17 +577,20 @@ static int gre_rcv(struct sk_buff *skb)
if (reason)
goto drop;

- if (iptunnel_pull_header(skb, tpi.hdr_len, tpi.proto, false))
+ reason = iptunnel_pull_header(skb, tpi.hdr_len, tpi.proto, 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