]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tcp: change tcp_filter() to return the reason by value
authorEric Dumazet <edumazet@google.com>
Thu, 9 Apr 2026 14:56:23 +0000 (14:56 +0000)
committerJakub Kicinski <kuba@kernel.org>
Sun, 12 Apr 2026 21:30:25 +0000 (14:30 -0700)
sk_filter_trim_cap() will soon return the reason by value,
do the same for tcp_filter().

Note:

tcp_filter() is no longer inlined. Following patch will inline it again.

$ scripts/bloat-o-meter -t vmlinux.4 vmlinux.5
add/remove: 2/0 grow/shrink: 0/2 up/down: 186/-43 (143)
Function                                     old     new   delta
tcp_filter                                     -     154    +154
__pfx_tcp_filter                               -      32     +32
tcp_v4_rcv                                  3152    3143      -9
tcp_v6_rcv                                  3169    3135     -34
Total: Before=29722640, After=29722783, chg +0.00%

Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260409145625.2306224-5-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/tcp.h
net/ipv4/tcp_ipv4.c
net/ipv6/tcp_ipv6.c

index 6156d1d068e142f696ec9dfff63e3aaebb0171bc..098e52269a04cb8938812a8f43caf11f9d5c68a3 100644 (file)
@@ -1683,12 +1683,14 @@ static inline bool tcp_checksum_complete(struct sk_buff *skb)
 bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb,
                     enum skb_drop_reason *reason);
 
-static inline int tcp_filter(struct sock *sk, struct sk_buff *skb,
-                            enum skb_drop_reason *reason)
+static inline enum skb_drop_reason
+tcp_filter(struct sock *sk, struct sk_buff *skb)
 {
        const struct tcphdr *th = (const struct tcphdr *)skb->data;
+       enum skb_drop_reason reason;
 
-       return sk_filter_trim_cap(sk, skb, __tcp_hdrlen(th), reason);
+       sk_filter_trim_cap(sk, skb, __tcp_hdrlen(th), &reason);
+       return reason;
 }
 
 void tcp_set_state(struct sock *sk, int state);
index 69ab236072e7142d5ca9d0703d99f02c1e17c738..e2da3246a641e24328985cf558c322211df02b84 100644 (file)
@@ -2164,7 +2164,8 @@ lookup:
                }
                refcounted = true;
                nsk = NULL;
-               if (!tcp_filter(sk, skb, &drop_reason)) {
+               drop_reason = tcp_filter(sk, skb);
+               if (!drop_reason) {
                        th = (const struct tcphdr *)skb->data;
                        iph = ip_hdr(skb);
                        tcp_v4_fill_cb(skb, iph, th);
@@ -2225,7 +2226,8 @@ process:
 
        nf_reset_ct(skb);
 
-       if (tcp_filter(sk, skb, &drop_reason))
+       drop_reason = tcp_filter(sk, skb);
+       if (drop_reason)
                goto discard_and_relse;
 
        th = (const struct tcphdr *)skb->data;
index 8dc3874e8b9252da60f21ad77a5ca834532e650a..d64d28e9842f7db69389034ac2ecdc76f405d379 100644 (file)
@@ -1794,7 +1794,8 @@ lookup:
                }
                refcounted = true;
                nsk = NULL;
-               if (!tcp_filter(sk, skb, &drop_reason)) {
+               drop_reason = tcp_filter(sk, skb);
+               if (!drop_reason) {
                        th = (const struct tcphdr *)skb->data;
                        hdr = ipv6_hdr(skb);
                        tcp_v6_fill_cb(skb, hdr, th);
@@ -1855,7 +1856,8 @@ process:
 
        nf_reset_ct(skb);
 
-       if (tcp_filter(sk, skb, &drop_reason))
+       drop_reason = tcp_filter(sk, skb);
+       if (drop_reason)
                goto discard_and_relse;
 
        th = (const struct tcphdr *)skb->data;