Skip to content

Commit 2798e36

Browse files
edumazetkuba-moo
authored andcommitted
tcp: add TCP_MINTTL drop reason
In the unlikely case incoming packets are dropped because of IP_MINTTL / IPV6_MINHOPCOUNT constraints... Signed-off-by: Eric Dumazet <edumazet@google.com> Link: https://lore.kernel.org/r/20230201174345.2708943-1-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 0719bc3 commit 2798e36

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

include/net/dropreason.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
FN(DUP_FRAG) \
7272
FN(FRAG_REASM_TIMEOUT) \
7373
FN(FRAG_TOO_FAR) \
74+
FN(TCP_MINTTL) \
7475
FNe(MAX)
7576

7677
/**
@@ -312,6 +313,11 @@ enum skb_drop_reason {
312313
* (/proc/sys/net/ipv4/ipfrag_max_dist)
313314
*/
314315
SKB_DROP_REASON_FRAG_TOO_FAR,
316+
/**
317+
* @SKB_DROP_REASON_TCP_MINTTL: ipv4 ttl or ipv6 hoplimit below
318+
* the threshold (IP_MINTTL or IPV6_MINHOPCOUNT).
319+
*/
320+
SKB_DROP_REASON_TCP_MINTTL,
315321
/**
316322
* @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be
317323
* used as a real 'reason'

net/ipv4/tcp_ipv4.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
21022102
/* min_ttl can be changed concurrently from do_ip_setsockopt() */
21032103
if (unlikely(iph->ttl < READ_ONCE(inet_sk(sk)->min_ttl))) {
21042104
__NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP);
2105+
drop_reason = SKB_DROP_REASON_TCP_MINTTL;
21052106
goto discard_and_relse;
21062107
}
21072108
}

net/ipv6/tcp_ipv6.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1708,8 +1708,9 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
17081708

17091709
if (static_branch_unlikely(&ip6_min_hopcount)) {
17101710
/* min_hopcount can be changed concurrently from do_ipv6_setsockopt() */
1711-
if (hdr->hop_limit < READ_ONCE(tcp_inet6_sk(sk)->min_hopcount)) {
1711+
if (unlikely(hdr->hop_limit < READ_ONCE(tcp_inet6_sk(sk)->min_hopcount))) {
17121712
__NET_INC_STATS(net, LINUX_MIB_TCPMINTTLDROP);
1713+
drop_reason = SKB_DROP_REASON_TCP_MINTTL;
17131714
goto discard_and_relse;
17141715
}
17151716
}

0 commit comments

Comments
 (0)