tcp: return a drop_reason from tcp_add_backlog()
Subsystems (3)
PATCH 1/1 tcp: return a drop_reason from tcp_add_backlog()
Part of a stack canary removal from tcp_v{4,6}_rcv().
Return a drop_reason instead of a boolean, so that we no longer have to pass the address of a local variable.
$ scripts/bloat-o-meter -t vmlinux.old vmlinux.new add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-37 (-37) Function old new delta tcp_v6_rcv 3133 3129 -4 tcp_v4_rcv 3206 3202 -4 tcp_add_backlog 1281 1252 -29 Total: Before=25567186, After=25567149, chg -0.00%
Signed-off-by Eric Dumazet <[email protected]>
--- include/net/tcp.h | 3 +-- net/ipv4/tcp_ipv4.c | 21 +++++++++------------ net/ipv6/tcp_ipv6.c | 3 ++- 3 files changed, 12 insertions(+), 15 deletions(-)
include/net/tcp.h +1 -2
@@ -1680,8 +1680,7 @@ static inline bool tcp_checksum_complete(struct sk_buff *skb)__skb_checksum_complete (skb); } -bool tcp_add_backlog (struct sock *sk,struct sk_buff *skb, -enum skb_drop_reason *reason); +enum skb_drop_reason tcp_add_backlog (struct sock *sk,struct sk_buff *skb);static inline int tcp_filter (struct sock *sk,struct sk_buff *skb,enum skb_drop_reason *reason)
net/ipv4/tcp_ipv4.c +9 -12
@@ -1900,8 +1900,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) }EXPORT_SYMBOL (tcp_v4_do_rcv); -bool tcp_add_backlog (struct sock *sk,struct sk_buff *skb, -enum skb_drop_reason *reason) +enum skb_drop_reason tcp_add_backlog (struct sock *sk,struct sk_buff *skb) {u32 tail_gso_size, tail_gso_segs;struct skb_shared_info *shinfo;
@@ -1929,10 +1928,9 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb,if (unlikely (tcp_checksum_complete (skb))) {bh_unlock_sock (sk);trace_tcp_bad_csum (skb); - *reason =SKB_DROP_REASON_TCP_CSUM ;__TCP_INC_STATS (sock_net (sk),TCP_MIB_CSUMERRORS );__TCP_INC_STATS (sock_net (sk),TCP_MIB_INERRS ); -return true; +return SKB_DROP_REASON_TCP_CSUM ; }/* Attempt coalescing to last skb in backlog, even if we are
@@ -2006,7 +2004,7 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb,__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPBACKLOGCOALESCE );kfree_skb_partial (skb, fragstolen); -return false; +return SKB_NOT_DROPPED_YET ; }__skb_push (skb, hdrlen);
@@ -2031,15 +2029,13 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb,if (unlikely (err)) {bh_unlock_sock (sk);if (err == -ENOMEM ) { - *reason =SKB_DROP_REASON_PFMEMALLOC ;__NET_INC_STATS (sock_net (sk),LINUX_MIB_PFMEMALLOCDROP ); - }else { - *reason =SKB_DROP_REASON_SOCKET_BACKLOG ; -__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPBACKLOGDROP ); +return SKB_DROP_REASON_PFMEMALLOC ; } -return true; +__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPBACKLOGDROP ); +return SKB_DROP_REASON_SOCKET_BACKLOG ; } -return false; +return SKB_NOT_DROPPED_YET ; }static void tcp_v4_restore_cb (struct sk_buff *skb)
@@ -2247,7 +2243,8 @@ int tcp_v4_rcv(struct sk_buff *skb)if (!sock_owned_by_user (sk)) { ret =tcp_v4_do_rcv (sk, skb); }else { -if (tcp_add_backlog (sk, skb, &drop_reason)) + drop_reason =tcp_add_backlog (sk, skb); +if (drop_reason) goto discard_and_relse; }bh_unlock_sock (sk);
net/ipv6/tcp_ipv6.c +2 -1
@@ -1877,7 +1877,8 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)if (!sock_owned_by_user (sk)) { ret =tcp_v6_do_rcv (sk, skb); }else { -if (tcp_add_backlog (sk, skb, &drop_reason)) + drop_reason =tcp_add_backlog (sk, skb); +if (drop_reason) goto discard_and_relse; }bh_unlock_sock (sk);
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
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 13 lines · On Thu, 9 Apr 2026 10:11:47 +0000 you wrote:
Part of a stack canary removal from tcp_v{4,6}_rcv().
Return a
drop_reasoninstead of a boolean, so that we no longer have to pass the address of a local variable.$ scripts/bloat-o-meter -t vmlinux.old vmlinux.new add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-37 (-37) Function old new delta tcp_v6_rcv 3133 3129 -4 tcp_v4_rcv 3206 3202 -4 tcp_add_backlog 1281 1252 -29 Total: Before=25567186, After=25567149, chg -0.00%
Quoted 1 line
[...]
Here is the summary with links:
- [net-next] tcp: return a drop_reason from tcp_add_backlog()
https://git.kernel.org/netdev/net-next/c/f5148298b0fe
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html