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>,
Simon Horman <horms@kernel.org>, David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v7 5/8] ip6_gre: add drop reasons to the RX path
Date: Wed, 18 Nov 2026 00:18:50 +0300 [thread overview]
Message-ID: <20261117211853.3733250-6-littlesmilingcloud@gmail.com> (raw)
In-Reply-To: <20261117211853.3733250-1-littlesmilingcloud@gmail.com>
Have the IPv6 GRE and ERSPAN receive handlers return the reason for
rejecting an skb. Report TUNNEL_NOT_FOUND for a lookup miss and NOMEM
for a metadata allocation failure. Use TUNNEL_INVALID_HDR for an
unsupported ERSPAN version or ERSPAN type I over IPv6.
Preserve the reason from header pulls. IPv6 GRE pulls the inner header
before tunnel lookup, so a truncated ETH_P_TEB header is reported even
if no tunnel would match.
Remove the now unused PACKET_* return codes. In particular, a leftover
PACKET_REJECT would compile as a drop reason with the value of
SKB_CONSUMED.
Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
v7: Report TUNNEL_INVALID_HDR for the new ERSPAN version and type I checks.
Omit Ido's Reviewed-by pending review of this change.
include/net/ip_tunnels.h | 4 ---
net/ipv6/ip6_gre.c | 55 ++++++++++++++++++++++------------------
2 files changed, 30 insertions(+), 29 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 d91161e7ed78..579df41fa5b4 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,25 +472,26 @@ 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;
@@ -498,10 +500,11 @@ static int ip6erspan_rcv(struct sk_buff *skb,
* IPv6, and such a packet carries no ERSPAN header to look at.
*/
if (unlikely(tpi->proto == htons(ETH_P_ERSPAN) && gre_hdr_len == 4))
- return PACKET_REJECT;
+ return SKB_DROP_REASON_TUNNEL_INVALID_HDR;
- 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;
@@ -514,15 +517,16 @@ static int ip6erspan_rcv(struct sk_buff *skb,
int len = erspan_hdr_len(ver);
if (unlikely(ver != ERSPAN_VERSION && ver != ERSPAN_VERSION2))
- return PACKET_REJECT;
+ return SKB_DROP_REASON_TUNNEL_INVALID_HDR;
- 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;
@@ -539,7 +543,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;
@@ -567,10 +571,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)
@@ -582,19 +586,20 @@ static int gre_rcv(struct sk_buff *skb)
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(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
next prev parent reply other threads:[~2026-11-17 21:19 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 21:18 [PATCH net-next v7 0/8] tunnels: add core and gre drop reasons Anton Danilov
2026-11-17 21:18 ` [PATCH net-next v7 1/8] ip_tunnel: add drop reasons to the generic RX path Anton Danilov
2026-11-17 21:18 ` [PATCH net-next v7 2/8] ip6_tunnel: add drop reasons to the receive path Anton Danilov
2026-11-17 21:18 ` [PATCH net-next v7 3/8] gre: make gre_parse_header() report a drop reason Anton Danilov
2026-11-17 21:18 ` [PATCH net-next v7 4/8] ip_gre: add drop reasons to the RX path Anton Danilov
2026-11-17 21:18 ` Anton Danilov [this message]
2026-11-17 21:18 ` [PATCH net-next v7 6/8] ip_tunnel: make ip_tunnel_encap() return a drop reason Anton Danilov
2026-11-17 21:18 ` [PATCH net-next v7 7/8] ip_tunnel: add drop reasons to the transmit path Anton Danilov
2026-11-17 21:18 ` [PATCH net-next v7 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=20261117211853.3733250-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox