Message ID | d1ecf500f07e063d4e8e34f4045ddca55416c686.1668507036.git.geert+renesas@glider.be |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2627227wru; Tue, 15 Nov 2022 02:14:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ip2QQ1PUloy2eWZ5+ojQanPtDXTG8eb5FL0ZapnpPFvLT1PVrIjWfwEoxECkRdYtEb5Cs X-Received: by 2002:a17:90a:4f81:b0:213:1fcb:3ce1 with SMTP id q1-20020a17090a4f8100b002131fcb3ce1mr1492258pjh.58.1668507253272; Tue, 15 Nov 2022 02:14:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668507253; cv=none; d=google.com; s=arc-20160816; b=yWd5OirNbq3JQvT+EBitoVRcCQEtxouYH7o3G4k4Ag+wRRJsGMGkwx4pXcAQ/O2QIj 2UsaOxf+VfGuTRcgLOCZ5z3DW8mq9nX+PL6SJ8vxMRqVXYm87yc7I++ULbkVZy2y//lW MskfMhEMm3wB1G0olW8u6iCIZnU+zViSLpgan/CdsUiixcOyB/96b0k+MZ9MzlN2xM/Q aJb9+uEgxCRLINbMNUTj2yFf2TwLd2OtLW/VfY/1cuApbEd6cis6Sosf88IP0w3X39wy WkjH9MMwHmfRNLXKAo/7qTeC2jUYu2JnBL4biwCtBzqTP/znZLk95nX/8f3a7jKyAQBS TT/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=OLY5vsYaseHs5dsWYEBKr66v8ZTEUvv4FHZuzVimlE8=; b=yFHBh0HfKyoVqerUAxpVT/BnZJSh3XWYoLPalZYIaXzXekSGQ+uPdUktPfXbJrw3lB qOf78Ounaif0T27j1ZEEGh4Pf7XUEgA24j2VZ4eq9ThBBNPxYIUE4i/dn0qgiOGaqn64 l1FjUK/pr4M8PWv0WBqIqjrvv5JsfoVUOXTKOLhiGdnGR2G0Q8GiciA6f6ZsUc/NL/OI MX2EcF3LsbLL06KNxLdz8nVxwEfVLzltzH7hmJbEvk1pRWVbEfRGqG2pLD0MFc5lOEvV 2B5hSonmgoRNhO3rR9wW91qzjFaEyRVTLcOF2rML90nqt4YxdRe33AjxWfKsEpggOyF0 0bzQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 73-20020a63004c000000b004403ddda6e6si11564768pga.847.2022.11.15.02.13.59; Tue, 15 Nov 2022 02:14:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238442AbiKOKNa (ORCPT <rfc822;lkml4gm@gmail.com> + 99 others); Tue, 15 Nov 2022 05:13:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238384AbiKOKMj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 15 Nov 2022 05:12:39 -0500 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2251025E81 for <linux-kernel@vger.kernel.org>; Tue, 15 Nov 2022 02:12:22 -0800 (PST) Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed10:8c33:62a1:bd29:7c58]) by xavier.telenet-ops.be with bizsmtp id kaCJ280030JF8f801aCJRV; Tue, 15 Nov 2022 11:12:21 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from <geert@linux-m68k.org>) id 1ousvR-000Xyg-IX; Tue, 15 Nov 2022 11:12:17 +0100 Received: from geert by rox.of.borg with local (Exim 4.93) (envelope-from <geert@linux-m68k.org>) id 1ousvQ-005B9T-VS; Tue, 15 Nov 2022 11:12:16 +0100 From: Geert Uytterhoeven <geert+renesas@glider.be> To: Jamie Bainbridge <jamie.bainbridge@gmail.com>, Eric Dumazet <edumazet@google.com>, "David S . Miller" <davem@davemloft.net>, Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>, David Ahern <dsahern@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Chris Down <chris@chrisdown.name>, Stephen Hemminger <stephen@networkplumber.org> Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven <geert+renesas@glider.be> Subject: [PATCH net-next] tcp: Fix tcp_syn_flood_action() if CONFIG_IPV6=n Date: Tue, 15 Nov 2022 11:12:16 +0100 Message-Id: <d1ecf500f07e063d4e8e34f4045ddca55416c686.1668507036.git.geert+renesas@glider.be> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749556661952155429?= X-GMAIL-MSGID: =?utf-8?q?1749556661952155429?= |
Series |
[net-next] tcp: Fix tcp_syn_flood_action() if CONFIG_IPV6=n
|
|
Commit Message
Geert Uytterhoeven
Nov. 15, 2022, 10:12 a.m. UTC
If CONFIG_IPV6=n:
net/ipv4/tcp_input.c: In function ‘tcp_syn_flood_action’:
include/net/sock.h:387:37: error: ‘const struct sock_common’ has no member named ‘skc_v6_rcv_saddr’; did you mean ‘skc_rcv_saddr’?
387 | #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
| ^~~~~~~~~~~~~~~~
include/linux/printk.h:429:19: note: in definition of macro ‘printk_index_wrap’
429 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~~~~~~~~
include/linux/printk.h:530:2: note: in expansion of macro ‘printk’
530 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/net.h:272:3: note: in expansion of macro ‘pr_info’
272 | function(__VA_ARGS__); \
| ^~~~~~~~
include/linux/net.h:288:2: note: in expansion of macro ‘net_ratelimited_function’
288 | net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/net.h:288:43: note: in expansion of macro ‘sk_v6_rcv_saddr’
288 | net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)
| ^~~~~~~~~~~
net/ipv4/tcp_input.c:6847:4: note: in expansion of macro ‘net_info_ratelimited’
6847 | net_info_ratelimited("%s: Possible SYN flooding on port [%pI6c]:%u. %s.\n",
| ^~~~~~~~~~~~~~~~~~~~
Fix this by using "#if" instead of "if", like is done for all other
checks for CONFIG_IPV6.
Fixes: d9282e48c6088105 ("tcp: Add listening address to SYN flood message")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
net/ipv4/tcp_input.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
Comments
Hi Geert, On 15/11/2022 11:12, Geert Uytterhoeven wrote: > If CONFIG_IPV6=n: > > net/ipv4/tcp_input.c: In function ‘tcp_syn_flood_action’: > include/net/sock.h:387:37: error: ‘const struct sock_common’ has no member named ‘skc_v6_rcv_saddr’; did you mean ‘skc_rcv_saddr’? > 387 | #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr > | ^~~~~~~~~~~~~~~~ > include/linux/printk.h:429:19: note: in definition of macro ‘printk_index_wrap’ > 429 | _p_func(_fmt, ##__VA_ARGS__); \ > | ^~~~~~~~~~~ > include/linux/printk.h:530:2: note: in expansion of macro ‘printk’ > 530 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) > | ^~~~~~ > include/linux/net.h:272:3: note: in expansion of macro ‘pr_info’ > 272 | function(__VA_ARGS__); \ > | ^~~~~~~~ > include/linux/net.h:288:2: note: in expansion of macro ‘net_ratelimited_function’ > 288 | net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) > | ^~~~~~~~~~~~~~~~~~~~~~~~ > include/linux/net.h:288:43: note: in expansion of macro ‘sk_v6_rcv_saddr’ > 288 | net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) > | ^~~~~~~~~~~ > net/ipv4/tcp_input.c:6847:4: note: in expansion of macro ‘net_info_ratelimited’ > 6847 | net_info_ratelimited("%s: Possible SYN flooding on port [%pI6c]:%u. %s.\n", > | ^~~~~~~~~~~~~~~~~~~~ > > Fix this by using "#if" instead of "if", like is done for all other > checks for CONFIG_IPV6. Thank you for the patch! Our CI validating MPTCP also found the issue. I was going to suggest a similar one before I saw yours :) Everything is fixed on my side after having applied the patch! Tested-by: Matthieu Baerts <matthieu.baerts@tessares.net> > Fixes: d9282e48c6088105 ("tcp: Add listening address to SYN flood message") > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> > --- > net/ipv4/tcp_input.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c > index 94024fdc2da1b28a..e5d7a33fac6666bb 100644 > --- a/net/ipv4/tcp_input.c > +++ b/net/ipv4/tcp_input.c > @@ -6843,11 +6843,14 @@ static bool tcp_syn_flood_action(const struct sock *sk, const char *proto) > > if (!queue->synflood_warned && syncookies != 2 && > xchg(&queue->synflood_warned, 1) == 0) { > - if (IS_ENABLED(CONFIG_IPV6) && sk->sk_family == AF_INET6) { > +#if IS_ENABLED(CONFIG_IPV6) > + if (sk->sk_family == AF_INET6) { > net_info_ratelimited("%s: Possible SYN flooding on port [%pI6c]:%u. %s.\n", > proto, &sk->sk_v6_rcv_saddr, > sk->sk_num, msg); > - } else { > + } else > +#endif > + { I was going to suggest to remove the unneeded braces here and just before + eventually fix the indentation under net_info_ratelimited() while at it but that's just some details not directly linked to the fix here. Cheers, Matt
On Tue, 15 Nov 2022 11:12:16 +0100 Geert Uytterhoeven wrote: > If CONFIG_IPV6=n: > > net/ipv4/tcp_input.c: In function ‘tcp_syn_flood_action’: > include/net/sock.h:387:37: error: ‘const struct sock_common’ has no member named ‘skc_v6_rcv_saddr’; did you mean ‘skc_rcv_saddr’? > 387 | #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr > | ^~~~~~~~~~~~~~~~ > include/linux/printk.h:429:19: note: in definition of macro ‘printk_index_wrap’ > 429 | _p_func(_fmt, ##__VA_ARGS__); \ > | ^~~~~~~~~~~ > include/linux/printk.h:530:2: note: in expansion of macro ‘printk’ > 530 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) > | ^~~~~~ > include/linux/net.h:272:3: note: in expansion of macro ‘pr_info’ > 272 | function(__VA_ARGS__); \ > | ^~~~~~~~ > include/linux/net.h:288:2: note: in expansion of macro ‘net_ratelimited_function’ > 288 | net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) > | ^~~~~~~~~~~~~~~~~~~~~~~~ > include/linux/net.h:288:43: note: in expansion of macro ‘sk_v6_rcv_saddr’ > 288 | net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) > | ^~~~~~~~~~~ > net/ipv4/tcp_input.c:6847:4: note: in expansion of macro ‘net_info_ratelimited’ > 6847 | net_info_ratelimited("%s: Possible SYN flooding on port [%pI6c]:%u. %s.\n", > | ^~~~~~~~~~~~~~~~~~~~ > > Fix this by using "#if" instead of "if", like is done for all other > checks for CONFIG_IPV6. > > Fixes: d9282e48c6088105 ("tcp: Add listening address to SYN flood message") > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Sorry for the late reaction, this now conflicts with bf36267e3ad3df8 I was gonna hand edit but perhaps we can do better with the ifdef formation. Instead of #ifdef v6 if (v6) { expensive_call6(); } else // d k #endif // o i { // o e expensive_call4(); } Can we go with: #ifdef v6 if (v6) expensive_call6(); else #endif expensive_call4(); or if (v4) { expensive_call4(); #ifdef v6 } else { expensive_call6(); #endif } or if (v6) { #ifdef v6 expensive_call6(); #endif } else { expensive_call6(); } I know you're just going with the most obviously correct / smallest diff way, but the broken up else bracket gives me flashbacks of looking at vendor code :S
On Thu, 17 Nov 2022 at 07:31, Jakub Kicinski <kuba@kernel.org> wrote: > > On Tue, 15 Nov 2022 11:12:16 +0100 Geert Uytterhoeven wrote: > > If CONFIG_IPV6=n: > > > > net/ipv4/tcp_input.c: In function ‘tcp_syn_flood_action’: > > include/net/sock.h:387:37: error: ‘const struct sock_common’ has no member named ‘skc_v6_rcv_saddr’; did you mean ‘skc_rcv_saddr’? > > 387 | #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr > > | ^~~~~~~~~~~~~~~~ > > include/linux/printk.h:429:19: note: in definition of macro ‘printk_index_wrap’ > > 429 | _p_func(_fmt, ##__VA_ARGS__); \ > > | ^~~~~~~~~~~ > > include/linux/printk.h:530:2: note: in expansion of macro ‘printk’ > > 530 | printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) > > | ^~~~~~ > > include/linux/net.h:272:3: note: in expansion of macro ‘pr_info’ > > 272 | function(__VA_ARGS__); \ > > | ^~~~~~~~ > > include/linux/net.h:288:2: note: in expansion of macro ‘net_ratelimited_function’ > > 288 | net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) > > | ^~~~~~~~~~~~~~~~~~~~~~~~ > > include/linux/net.h:288:43: note: in expansion of macro ‘sk_v6_rcv_saddr’ > > 288 | net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) > > | ^~~~~~~~~~~ > > net/ipv4/tcp_input.c:6847:4: note: in expansion of macro ‘net_info_ratelimited’ > > 6847 | net_info_ratelimited("%s: Possible SYN flooding on port [%pI6c]:%u. %s.\n", > > | ^~~~~~~~~~~~~~~~~~~~ > > > > Fix this by using "#if" instead of "if", like is done for all other > > checks for CONFIG_IPV6. > > > > Fixes: d9282e48c6088105 ("tcp: Add listening address to SYN flood message") > > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> > > Sorry for the late reaction, this now conflicts with bf36267e3ad3df8 > > I was gonna hand edit but perhaps we can do better with the ifdef > formation. > > Instead of > > #ifdef v6 > if (v6) { > expensive_call6(); > } else // d k > #endif // o i > { // o e > expensive_call4(); > } I actually started off using this way in my v1. I did that intentionally because that pattern already exists in other places, discussed at: https://lore.kernel.org/netdev/CAAvyFNg1F8ixrgy0YeL-TT5xLmk8N7dD=ZMLQ6VxsjHb_PU9bg@mail.gmail.com/ or just see: grep -C1 -ERHn "IS_ENABLED\(CONFIG_IPV6\)" net | grep -C1 "family == AF_INET6" Geert's patch adheres to existing style, which seems the better option? > Can we go with: > > #ifdef v6 > if (v6) > expensive_call6(); > else > #endif > expensive_call4(); This is a nested if, so it really should have braces to prevent dangling else, both now and in the future. > or > > if (v4) { > expensive_call4(); > #ifdef v6 > } else { > expensive_call6(); > #endif > } > or > > if (v6) { > #ifdef v6 > expensive_call6(); > #endif > } else { > expensive_call6(); > } These should work, but I expect they cause a comparison which can't be optimised out at compile time. This is probably why the first style exists. In this SYN flood codepath optimisation doesn't matter because we're doing ratelimited logging anyway. But if we're breaking with existing style, then wouldn't the others also have to change to this style? I haven't reviewed all the other usage to tell if they're in an oft-used fastpath where such a thing might matter. It seems Geert's patch style is the best way. Jamie
On Thu, 17 Nov 2022 08:39:43 +1100 Jamie Bainbridge wrote: > > if (v6) { > > #ifdef v6 > > expensive_call6(); > > #endif > > } else { > > expensive_call6(); > > } > > These should work, but I expect they cause a comparison which can't be > optimised out at compile time. This is probably why the first style > exists. > > In this SYN flood codepath optimisation doesn't matter because we're > doing ratelimited logging anyway. But if we're breaking with existing > style, then wouldn't the others also have to change to this style? I > haven't reviewed all the other usage to tell if they're in an oft-used > fastpath where such a thing might matter. I think the word style already implies subjectivity.
On Thu, 17 Nov 2022 at 08:15, Jakub Kicinski <kuba@kernel.org> wrote: > > On Thu, 17 Nov 2022 08:39:43 +1100 Jamie Bainbridge wrote: > > > if (v6) { > > > #ifdef v6 > > > expensive_call6(); > > > #endif > > > } else { > > > expensive_call6(); > > > } > > > > These should work, but I expect they cause a comparison which can't be > > optimised out at compile time. This is probably why the first style > > exists. > > > > In this SYN flood codepath optimisation doesn't matter because we're > > doing ratelimited logging anyway. But if we're breaking with existing > > style, then wouldn't the others also have to change to this style? I > > haven't reviewed all the other usage to tell if they're in an oft-used > > fastpath where such a thing might matter. > > I think the word style already implies subjectivity. You are right. Looking further, there are many other ways IF_ENABLED(CONFIG_IPV6) is used, including similar to the ways you have suggested. I don't mind Geert's original patch, but if you want a different style, I like your suggestion with v4 first: if (v4) { expensive_call4(); #ifdef v6 } else { expensive_call6(); #endif } Jamie
Hi Jamie, On Fri, Nov 18, 2022 at 2:50 AM Jamie Bainbridge <jamie.bainbridge@gmail.com> wrote: > On Thu, 17 Nov 2022 at 08:15, Jakub Kicinski <kuba@kernel.org> wrote: > > On Thu, 17 Nov 2022 08:39:43 +1100 Jamie Bainbridge wrote: > > > > if (v6) { > > > > #ifdef v6 > > > > expensive_call6(); > > > > #endif > > > > } else { > > > > expensive_call6(); > > > > } > > > > > > These should work, but I expect they cause a comparison which can't be > > > optimised out at compile time. This is probably why the first style > > > exists. > > > > > > In this SYN flood codepath optimisation doesn't matter because we're > > > doing ratelimited logging anyway. But if we're breaking with existing > > > style, then wouldn't the others also have to change to this style? I > > > haven't reviewed all the other usage to tell if they're in an oft-used > > > fastpath where such a thing might matter. > > > > I think the word style already implies subjectivity. > > You are right. Looking further, there are many other ways > IF_ENABLED(CONFIG_IPV6) is used, including similar to the ways you > have suggested. > > I don't mind Geert's original patch, but if you want a different > style, I like your suggestion with v4 first: > > if (v4) { > expensive_call4(); > #ifdef v6 > } else { > expensive_call6(); > #endif > } IMHO this is worse, as the #ifdef/#endif is spread across the two branches of an if-conditional. Hence this is usually written as: if (cond1) { expensive_call1(); } #ifdef cond2_enabled else { expensive_call1(); } #endif Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
On Fri, 18 Nov 2022 09:29:13 +0100 Geert Uytterhoeven wrote: > IMHO this is worse, as the #ifdef/#endif is spread across the two branches > of an if-conditional. > > Hence this is usually written as: > > if (cond1) { > expensive_call1(); > } > #ifdef cond2_enabled > else { > expensive_call1(); > } > #endif Alright, good enough for me.
On 18 Nov 09:29, Geert Uytterhoeven wrote: >Hi Jamie, > >On Fri, Nov 18, 2022 at 2:50 AM Jamie Bainbridge ><jamie.bainbridge@gmail.com> wrote: >> On Thu, 17 Nov 2022 at 08:15, Jakub Kicinski <kuba@kernel.org> wrote: >> > On Thu, 17 Nov 2022 08:39:43 +1100 Jamie Bainbridge wrote: >> > > > if (v6) { >> > > > #ifdef v6 >> > > > expensive_call6(); >> > > > #endif >> > > > } else { >> > > > expensive_call6(); >> > > > } >> > > >> > > These should work, but I expect they cause a comparison which can't be >> > > optimised out at compile time. This is probably why the first style >> > > exists. >> > > >> > > In this SYN flood codepath optimisation doesn't matter because we're >> > > doing ratelimited logging anyway. But if we're breaking with existing >> > > style, then wouldn't the others also have to change to this style? I >> > > haven't reviewed all the other usage to tell if they're in an oft-used >> > > fastpath where such a thing might matter. >> > >> > I think the word style already implies subjectivity. >> >> You are right. Looking further, there are many other ways >> IF_ENABLED(CONFIG_IPV6) is used, including similar to the ways you >> have suggested. >> >> I don't mind Geert's original patch, but if you want a different >> style, I like your suggestion with v4 first: >> >> if (v4) { >> expensive_call4(); >> #ifdef v6 >> } else { >> expensive_call6(); >> #endif >> } > >IMHO this is worse, as the #ifdef/#endif is spread across the two branches >of an if-conditional. > >Hence this is usually written as: > > if (cond1) { > expensive_call1(); > } > #ifdef cond2_enabled > else { > expensive_call1(); > } > #endif > I don't think any of this complication is needed, there's a macro inet6_rcv_saddr(sk), we can use it instead of directly referencing &sk->sk_v6_rcv_saddr, it already handles the case where CONFIG_IPV6=n --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6845,7 +6845,7 @@ static bool tcp_syn_flood_action(const struct sock *sk, const char *proto) xchg(&queue->synflood_warned, 1) == 0) { if (IS_ENABLED(CONFIG_IPV6) && sk->sk_family == AF_INET6) { net_info_ratelimited("%s: Possible SYN flooding on port [%pI6c]:%u. %s.\n", - proto, &sk->sk_v6_rcv_saddr, + proto, inet6_rcv_saddr(sk),
On Mon, 21 Nov 2022 14:44:19 -0800 Saeed Mahameed wrote: > there's a macro inet6_rcv_saddr(sk), we can use it instead of directly > referencing &sk->sk_v6_rcv_saddr, it already handles the case where > CONFIG_IPV6=n > > --- a/net/ipv4/tcp_input.c > +++ b/net/ipv4/tcp_input.c > @@ -6845,7 +6845,7 @@ static bool tcp_syn_flood_action(const struct sock *sk, const char *proto) > xchg(&queue->synflood_warned, 1) == 0) { > if (IS_ENABLED(CONFIG_IPV6) && sk->sk_family == AF_INET6) { > net_info_ratelimited("%s: Possible SYN flooding on port [%pI6c]:%u. %s.\n", > - proto, &sk->sk_v6_rcv_saddr, > + proto, inet6_rcv_saddr(sk), Great, could you post a full patch? I haven't seen v2, now it's almost Thanksgiving..
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 94024fdc2da1b28a..e5d7a33fac6666bb 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -6843,11 +6843,14 @@ static bool tcp_syn_flood_action(const struct sock *sk, const char *proto) if (!queue->synflood_warned && syncookies != 2 && xchg(&queue->synflood_warned, 1) == 0) { - if (IS_ENABLED(CONFIG_IPV6) && sk->sk_family == AF_INET6) { +#if IS_ENABLED(CONFIG_IPV6) + if (sk->sk_family == AF_INET6) { net_info_ratelimited("%s: Possible SYN flooding on port [%pI6c]:%u. %s.\n", proto, &sk->sk_v6_rcv_saddr, sk->sk_num, msg); - } else { + } else +#endif + { net_info_ratelimited("%s: Possible SYN flooding on port %pI4:%u. %s.\n", proto, &sk->sk_rcv_saddr, sk->sk_num, msg);