diff mbox series

[net-next,v2,1/6] net/tcp: Use static_branch_tcp_{md5,ao} to drop ifdefs

Message ID 20240605-tcp_ao-tracepoints-v2-1-e91e161282ef@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net/tcp: TCP-AO and TCP-MD5 tracepoints | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1804 this patch: 1804
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 923 this patch: 923
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1833 this patch: 1833
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 54 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 2 this patch: 2
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-06-05--06-00 (tests: 1043)

Commit Message

Dmitry Safonov via B4 Relay June 5, 2024, 2:20 a.m. UTC
From: Dmitry Safonov <0x7f454c46@gmail.com>

It's possible to clean-up some ifdefs by hiding that
tcp_{md5,ao}_needed static branch is defined and compiled only
under related configs, since commit 4c8530dc7d7d ("net/tcp: Only produce
AO/MD5 logs if there are any keys").

Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
---
 include/net/tcp.h   | 14 ++++----------
 net/ipv4/tcp_ipv4.c |  8 ++------
 2 files changed, 6 insertions(+), 16 deletions(-)

Comments

Ratheesh Kannoth June 5, 2024, 4:44 a.m. UTC | #1
On 2024-06-05 at 07:50:02, Dmitry Safonov via B4 Relay (devnull+0x7f454c46.gmail.com@kernel.org) wrote:
> From: Dmitry Safonov <0x7f454c46@gmail.com>
>
> It's possible to clean-up some ifdefs by hiding that
> tcp_{md5,ao}_needed static branch is defined and compiled only
> under related configs, since commit 4c8530dc7d7d ("net/tcp: Only produce
> AO/MD5 logs if there are any keys").
>
> Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
> ---
>  include/net/tcp.h   | 14 ++++----------
>  net/ipv4/tcp_ipv4.c |  8 ++------
>  2 files changed, 6 insertions(+), 16 deletions(-)
>
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 08c3b99501cf..f6dd035e0fa9 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -2386,21 +2386,15 @@ static inline void tcp_get_current_key(const struct sock *sk,
>
>  static inline bool tcp_key_is_md5(const struct tcp_key *key)
>  {
> -#ifdef CONFIG_TCP_MD5SIG
> -	if (static_branch_unlikely(&tcp_md5_needed.key) &&
> -	    key->type == TCP_KEY_MD5)
> -		return true;
> -#endif
> +	if (static_branch_tcp_md5())
Seems that we lost unlikely hint. Dont we add that as well-> unlikely()
> +		return key->type == TCP_KEY_MD5;
>  	return false;
>  }
>
>
>
Eric Dumazet June 5, 2024, 7:49 a.m. UTC | #2
On Wed, Jun 5, 2024 at 4:20 AM Dmitry Safonov via B4 Relay
<devnull+0x7f454c46.gmail.com@kernel.org> wrote:
>
> From: Dmitry Safonov <0x7f454c46@gmail.com>
>
> It's possible to clean-up some ifdefs by hiding that
> tcp_{md5,ao}_needed static branch is defined and compiled only
> under related configs, since commit 4c8530dc7d7d ("net/tcp: Only produce
> AO/MD5 logs if there are any keys").
>
> Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>
Dmitry Safonov June 5, 2024, 5:29 p.m. UTC | #3
On Wed, 5 Jun 2024 at 05:50, Ratheesh Kannoth <rkannoth@marvell.com> wrote:
>
> On 2024-06-05 at 07:50:02, Dmitry Safonov via B4 Relay (devnull+0x7f454c46.gmail.com@kernel.org) wrote:
> > From: Dmitry Safonov <0x7f454c46@gmail.com>
> >
> > It's possible to clean-up some ifdefs by hiding that
> > tcp_{md5,ao}_needed static branch is defined and compiled only
> > under related configs, since commit 4c8530dc7d7d ("net/tcp: Only produce
> > AO/MD5 logs if there are any keys").
> >
> > Signed-off-by: Dmitry Safonov <0x7f454c46@gmail.com>
> > ---
> >  include/net/tcp.h   | 14 ++++----------
> >  net/ipv4/tcp_ipv4.c |  8 ++------
> >  2 files changed, 6 insertions(+), 16 deletions(-)
> >
> > diff --git a/include/net/tcp.h b/include/net/tcp.h
> > index 08c3b99501cf..f6dd035e0fa9 100644
> > --- a/include/net/tcp.h
> > +++ b/include/net/tcp.h
> > @@ -2386,21 +2386,15 @@ static inline void tcp_get_current_key(const struct sock *sk,
> >
> >  static inline bool tcp_key_is_md5(const struct tcp_key *key)
> >  {
> > -#ifdef CONFIG_TCP_MD5SIG
> > -     if (static_branch_unlikely(&tcp_md5_needed.key) &&
> > -         key->type == TCP_KEY_MD5)
> > -             return true;
> > -#endif
> > +     if (static_branch_tcp_md5())
> Seems that we lost unlikely hint. Dont we add that as well-> unlikely()

Please, check the definition of static_branch_tcp_md5().
This doesn't have any functional changes but hides ifdefs in
the definition.

Thanks,
             Dmitry
diff mbox series

Patch

diff --git a/include/net/tcp.h b/include/net/tcp.h
index 08c3b99501cf..f6dd035e0fa9 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -2386,21 +2386,15 @@  static inline void tcp_get_current_key(const struct sock *sk,
 
 static inline bool tcp_key_is_md5(const struct tcp_key *key)
 {
-#ifdef CONFIG_TCP_MD5SIG
-	if (static_branch_unlikely(&tcp_md5_needed.key) &&
-	    key->type == TCP_KEY_MD5)
-		return true;
-#endif
+	if (static_branch_tcp_md5())
+		return key->type == TCP_KEY_MD5;
 	return false;
 }
 
 static inline bool tcp_key_is_ao(const struct tcp_key *key)
 {
-#ifdef CONFIG_TCP_AO
-	if (static_branch_unlikely(&tcp_ao_needed.key) &&
-	    key->type == TCP_KEY_AO)
-		return true;
-#endif
+	if (static_branch_tcp_ao())
+		return key->type == TCP_KEY_AO;
 	return false;
 }
 
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 04044605cadf..59c252b90b55 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1052,12 +1052,10 @@  static void tcp_v4_timewait_ack(struct sock *sk, struct sk_buff *skb)
 #else
 	if (0) {
 #endif
-#ifdef CONFIG_TCP_MD5SIG
-	} else if (static_branch_unlikely(&tcp_md5_needed.key)) {
+	} else if (static_branch_tcp_md5()) {
 		key.md5_key = tcp_twsk_md5_key(tcptw);
 		if (key.md5_key)
 			key.type = TCP_KEY_MD5;
-#endif
 	}
 
 	tcp_v4_send_ack(sk, skb,
@@ -1126,8 +1124,7 @@  static void tcp_v4_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
 #else
 	if (0) {
 #endif
-#ifdef CONFIG_TCP_MD5SIG
-	} else if (static_branch_unlikely(&tcp_md5_needed.key)) {
+	} else if (static_branch_tcp_md5()) {
 		const union tcp_md5_addr *addr;
 		int l3index;
 
@@ -1136,7 +1133,6 @@  static void tcp_v4_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
 		key.md5_key = tcp_md5_do_lookup(sk, l3index, addr, AF_INET);
 		if (key.md5_key)
 			key.type = TCP_KEY_MD5;
-#endif
 	}
 
 	tcp_v4_send_ack(sk, skb, seq,