net: dropreason: add SKB_DROP_REASON_IP_TTL_EXCEEDED
Subsystems (3)
PATCH v4 1/1 net: dropreason: add SKB_DROP_REASON_IP_TTL_EXCEEDED
The forwarding paths report an expired TTL or hop limit as SKB_DROP_REASON_IP_INHDR, the reason otherwise used for a header that is malformed (ip_input.c, exthdrs.c, br_netfilter). Nothing else in the drop path separates the two: IPSTATS_MIB_INHDRERRORS covers both, and the TTL check runs before NF_INET_FORWARD, so netfilter tracing stops at PREROUTING and never sees the drop.
The Fedora bug linked below shows how that reads in practice. The reporter took kfree_skb(reason=IP_INHDR, loc=ip_forward) to mean the software header checksum check had failed, and worked through RX checksum offload, tc csum actions and both libvirt firewall backends before the drops turned out to be replies arriving with TTL 1. ip_forward() never verifies the header checksum; that runs earlier, in ip_rcv_core(), and reports IP_CSUM.
TTL expiry is not a corner case -- every traceroute through a Linux router goes through too_many_hops.
The three loopback hop limit checks in exthdrs.c drop with no reason at all; give them the new one.
IPSTATS_MIB_INHDRERRORS stays as it is: RFC 1213 counts time-to-live exceeded under ipInHdrErrors. The drop reason has no such constraint.
---
v4: kernel-doc says "<= 1" instead of "hit zero" (Jiayuan Chen)
v3: https://lore.kernel.org/netdev/[email protected]/
v2: https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/
include/net/dropreason-core.h | 6 ++++++ net/ipv4/ip_forward.c | 2 +- net/ipv6/exthdrs.c | 6 +++--- net/ipv6/ip6_output.c | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-)
include/net/dropreason-core.h +6 -0
@@ -128,6 +128,7 @@ FN(PSP_INPUT) \ FN(PSP_OUTPUT) \ FN(RECURSION_LIMIT) \ + FN(IP_TTL_EXCEEDED) \ FNe(MAX)/**
@@ -606,6 +607,11 @@ enum skb_drop_reason {SKB_DROP_REASON_PSP_OUTPUT ,/** @SKB_DROP_REASON_RECURSION_LIMIT: Dead loop on virtual device. */ SKB_DROP_REASON_RECURSION_LIMIT , +/** +* @SKB_DROP_REASON_IP_TTL_EXCEEDED: IPv4 TTL or IPv6 hop limit <= 1 +* (see IPSTATS_MIB_INHDRERRORS) +*/ + SKB_DROP_REASON_IP_TTL_EXCEEDED,/** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen
net/ipv4/ip_forward.c +1 -1
@@ -174,7 +174,7 @@ int ip_forward(struct sk_buff *skb)/* Tell the sender its packet died... */ __IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS );icmp_send (skb,ICMP_TIME_EXCEEDED ,ICMP_EXC_TTL ,0 ); -SKB_DR_SET (reason,IP_INHDR ); +SKB_DR_SET (reason,IP_TTL_EXCEEDED ); drop:kfree_skb_reason (skb, reason);return NET_RX_DROP ;
net/ipv6/exthdrs.c +3 -3
@@ -464,7 +464,7 @@ static int ipv6_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)__IP6_INC_STATS (net, idev,IPSTATS_MIB_INHDRERRORS );icmpv6_send (skb,ICMPV6_TIME_EXCEED ,ICMPV6_EXC_HOPLIMIT ,0 ); -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_IP_TTL_EXCEEDED );return -1 ; }ipv6_hdr (skb)->hop_limit--;
@@ -623,7 +623,7 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)__IP6_INC_STATS (net, idev,IPSTATS_MIB_INHDRERRORS );icmpv6_send (skb,ICMPV6_TIME_EXCEED ,ICMPV6_EXC_HOPLIMIT ,0 ); -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_IP_TTL_EXCEEDED );return -1 ; }ipv6_hdr (skb)->hop_limit--;
@@ -815,7 +815,7 @@ static int ipv6_rthdr_rcv(struct sk_buff *skb)__IP6_INC_STATS (net, idev,IPSTATS_MIB_INHDRERRORS );icmpv6_send (skb,ICMPV6_TIME_EXCEED ,ICMPV6_EXC_HOPLIMIT ,0 ); -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_IP_TTL_EXCEEDED );return -1 ; }ipv6_hdr (skb)->hop_limit--;
net/ipv6/ip6_output.c +1 -1
@@ -577,7 +577,7 @@ int ip6_forward(struct sk_buff *skb)icmpv6_send (skb,ICMPV6_TIME_EXCEED ,ICMPV6_EXC_HOPLIMIT ,0 );__IP6_INC_STATS (net, idev,IPSTATS_MIB_INHDRERRORS ); -kfree_skb_reason (skb,SKB_DROP_REASON_IP_INHDR ); +kfree_skb_reason (skb,SKB_DROP_REASON_IP_TTL_EXCEEDED );return -ETIMEDOUT ; }
Signature · 1 line
2.43.0
Hi Junjie,
Quoted 68 lines · Junjie Cao
The forwarding paths report an expired TTL or hop limit as
SKB_DROP_REASON_IP_INHDR, the reason otherwise used for a header that is malformed (ip_input.c,exthdrs.c,br_netfilter). Nothing else in the drop path separates the two:IPSTATS_MIB_INHDRERRORScovers both, and the TTL check runs beforeNF_INET_FORWARD, so netfilter tracing stops at PREROUTING and never sees the drop.The Fedora bug linked below shows how that reads in practice. The reporter took
kfree_skb(reason=IP_INHDR, loc=ip_forward)to mean the software header checksum check had failed, and worked through RX checksum offload, tc csum actions and both libvirt firewall backends before the drops turned out to be replies arriving with TTL 1.ip_forward()never verifies the header checksum; that runs earlier, inip_rcv_core(), and reportsIP_CSUM.TTL expiry is not a corner case -- every traceroute through a Linux router goes through
too_many_hops.The three loopback hop limit checks in
exthdrs.cdrop with no reason at all; give them the new one.
IPSTATS_MIB_INHDRERRORSstays as it is: RFC 1213 counts time-to-live exceeded under ipInHdrErrors. The drop reason has no such constraint.Signed-off-by Junjie Cao <[email protected]>Reviewed-by Jiayuan Chen <[email protected]>Reviewed-by Fernando Fernandez Mancera <[email protected]>---
v4: kernel-doc says "<= 1" instead of "hit zero" (Jiayuan Chen)
v3: https://lore.kernel.org/netdev/[email protected]/
v2: https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/include/net/dropreason-core.h | 6 ++++++ net/ipv4/ip_forward.c | 2 +- net/ipv6/exthdrs.c | 6 +++--- net/ipv6/ip6_output.c | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-)include/net/dropreason-core.h +6
-0@@ -128,6 +128,7 @@ FN(PSP_INPUT) \ FN(PSP_OUTPUT) \ FN(RECURSION_LIMIT) \ + FN(IP_TTL_EXCEEDED) \ FNe(MAX)/** @@ -606,6 +607,11 @@ enum skb_drop_reason {SKB_DROP_REASON_PSP_OUTPUT ,/** @SKB_DROP_REASON_RECURSION_LIMIT: Dead loop on virtual device. */ SKB_DROP_REASON_RECURSION_LIMIT , +/** +* @SKB_DROP_REASON_IP_TTL_EXCEEDED: IPv4 TTL or IPv6 hop limit <= 1 +* (see IPSTATS_MIB_INHDRERRORS) +*/ + SKB_DROP_REASON_IP_TTL_EXCEEDED,/** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen net/ipv4/ip_forward.c +0
-0
net/ipv4/ip_forward.c int ip_forward(struct sk_buff *skb) · line 180
Quoted 8 lines
net/ipv4/ip_forward.c +1
-1@@ -174,7 +174,7 @@ int ip_forward(struct sk_buff *skb)/* Tell the sender its packet died... */ __IP_INC_STATS (net,IPSTATS_MIB_INHDRERRORS );icmp_send (skb,ICMP_TIME_EXCEEDED ,ICMP_EXC_TTL ,0 ); -SKB_DR_SET (reason,IP_INHDR ); +SKB_DR_SET (reason,IP_TTL_EXCEEDED ); drop:kfree_skb_reason (skb, reason);return NET_RX_DROP ;
I saw
ip_vs_forward_icmp()
- ip_vs_in_icmp_v6
- ip_vs_icmp_xmit_v6()
- __ip_vs_get_out_rt_v6()
- decrement_ttl()
Also sends ICMP_EXC_TTL/ICMPV6_EXC_HOPLIMIT messages, But not changed in this patch. Should we also update them? Or there is no plan to change the ipvs code yet?
Thanks
Hangbin
Jakub Kicinski
maintainerinclude/net/dropreason-core.h line 132
Quoted 8 lines · On Mon, 7 Sep 2026 11:01:33 +0800 Junjie Cao wrote:
include/net/dropreason-core.h +1
-0@@ -128,6 +128,7 @@ FN(PSP_INPUT) \ FN(PSP_OUTPUT) \ FN(RECURSION_LIMIT) \ + FN(IP_TTL_EXCEEDED) \ FNe(MAX)
These entries are not strict uAPI, let's not append at the end cause it gets messy. Please add the new field after IP_INVALID_DEST
Signature · 1 line
pw-bot: cr