Skip to contentSkip to conversation

gre: Count GRE packet drops

PATCH Applied Gal Pressman 2 participants 3 messages Apr 9 – Apr 12

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gre: Count GRE packet drops

GRE is silently dropping packets without updating statistics.

In case of drop, increment rx_dropped counter to provide visibility into packet loss. For the case where no GRE protocol handler is registered, use rx_nohandler.

---
 net/ipv4/gre_demux.c | 8 ++++++--
 net/ipv4/ip_gre.c    | 1 +
 net/ipv6/ip6_gre.c   | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)
net/ipv4/gre_demux.c +6 -2
index dafd68f3436a..96fd7dc6d82d 100644
@@ -159,14 +159,18 @@ static int gre_rcv(struct sk_buff *skb)
 	rcu_read_lock();
 	proto = rcu_dereference(gre_proto[ver]);
 	if (!proto || !proto->handler)
-		goto drop_unlock;
+		goto drop_nohandler;
 	ret = proto->handler(skb);
 	rcu_read_unlock();
 	return ret;
 
-drop_unlock:
+drop_nohandler:
 	rcu_read_unlock();
+	dev_core_stats_rx_nohandler_inc(skb->dev);
+	kfree_skb(skb);
+	return NET_RX_DROP;
 drop:
+	dev_core_stats_rx_dropped_inc(skb->dev);
 	kfree_skb(skb);
 	return NET_RX_DROP;
 }
net/ipv4/ip_gre.c +1 -0
index 35f0baa99d40..169e2921a851 100644
@@ -468,6 +468,7 @@ static int gre_rcv(struct sk_buff *skb)
 out:
 	icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
 drop:
+	dev_core_stats_rx_dropped_inc(skb->dev);
 	kfree_skb(skb);
 	return 0;
 }
net/ipv6/ip6_gre.c +1 -0
index dafcc0dcd77a..63fc8556b475 100644
@@ -593,6 +593,7 @@ static int gre_rcv(struct sk_buff *skb)
 out:
 	icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
 drop:
+	dev_core_stats_rx_dropped_inc(skb->dev);
 	kfree_skb(skb);
 	return 0;
 }
Signature · 1 line
2.52.0
#1 lore raw

Addressing Sashiko's comments:
https://sashiko.dev/#/patchset/[email protected]

Quoted 27 lines · Gal Pressman

GRE is silently dropping packets without updating statistics.

In case of drop, increment rx_dropped counter to provide visibility into packet loss. For the case where no GRE protocol handler is registered, use rx_nohandler.

---
 net/ipv4/gre_demux.c | 8 ++++++--
 net/ipv4/ip_gre.c    | 1 +
 net/ipv6/ip6_gre.c   | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)
net/ipv4/gre_demux.c +1 -1
index dafd68f3436a..96fd7dc6d82d 100644
@@ -159,14 +159,18 @@ static int gre_rcv(struct sk_buff *skb)
 	rcu_read_lock();
 	proto = rcu_dereference(gre_proto[ver]);
 	if (!proto || !proto->handler)
-		goto drop_unlock;
+		goto drop_nohandler;
 	ret = proto->handler(skb);
 	rcu_read_unlock();

net/ipv4/gre_demux.c static int gre_rcv(struct sk_buff *skb) · line 173

Quoted 10 lines
net/ipv4/gre_demux.c +5 -1
 	return ret;
 
-drop_unlock:
+drop_nohandler:
 	rcu_read_unlock();
+	dev_core_stats_rx_nohandler_inc(skb->dev);
+	kfree_skb(skb);
+	return NET_RX_DROP;
 drop:
+	dev_core_stats_rx_dropped_inc(skb->dev);

---
At this point in gre_rcv(), does skb->dev point to the underlying ingress physical interface (e.g., eth0) rather than a GRE tunnel device? If so, does incrementing the L2 physical device counters for an L4 protocol error case pollute the physical interface metrics? Unconfigured GRE traffic from the network might cause physical device drop counters to spike, which could be misdiagnosed as hardware issues.
Would it be better to expose these via protocol-specific MIB counters or by passing a specific drop reason to kfree_skb_reason()?
---

Yes, it points to the underlying device, and that makes sense IMO.

At this point, the packets are still not associated with any tunnel (it might not even exist).

Quoted 8 lines
net/ipv4/gre_demux.c +0 -0
 	kfree_skb(skb);
 	return NET_RX_DROP;
 }
net/ipv6/ip6_gre.c +0 -0
index dafcc0dcd77a..63fc8556b475 100644

net/ipv6/ip6_gre.c static int gre_rcv(struct sk_buff *skb) · line 599

Quoted 7 lines
net/ipv6/ip6_gre.c +1 -0
@@ -593,6 +593,7 @@ static int gre_rcv(struct sk_buff *skb)
 out:
 	icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
 drop:
+	dev_core_stats_rx_dropped_inc(skb->dev);
 	kfree_skb(skb);
 	return 0;
 }

---
Does this fully account for silent packet drops during decapsulation?

Looking at erspan_rcv() and ipgre_rcv() which are called earlier in this function, if they fail internally (for example, if __iptunnel_pull_header() fails), they free the skb and return PACKET_RCVD:
net/ipv4/ip_gre.c:erspan_rcv() {
...
if (__iptunnel_pull_header(skb, len, htons(ETH_P_TEB), false, false)
< 0)

        goto drop;
    ...
drop:
    kfree_skb(skb);
    return PACKET_RCVD;
}
Since gre_rcv() checks for PACKET_RCVD and returns 0:
    if (erspan_rcv(skb, &tpi, hdr_len) == PACKET_RCVD)
        return 0;

Does this bypass the newly added dev_core_stats_rx_dropped_inc() call under the drop label entirely, leaving these packets silently dropped?
---

These are also silent drops, but these should be counted towards the tunnel device, maybe as a separate patch.

#2 lore raw
In reply to Gal Pressman
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Thu, 9 Apr 2026 12:09:45 +0300 you wrote:

GRE is silently dropping packets without updating statistics.

In case of drop, increment rx_dropped counter to provide visibility into packet loss. For the case where no GRE protocol handler is registered, use rx_nohandler.

[...]

Here is the summary with links:
- [net-next] gre: Count GRE packet drops

    https://git.kernel.org/netdev/net-next/c/8632175ccb0c

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html