* [PATCH net-next v3] inet_ecn: Use csum16_add() helper for IP_ECN_set_* helpers
@ 2020-12-11 14:26 Toke Høiland-Jørgensen
2020-12-15 3:10 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-11 14:26 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski
Cc: netdev, Toke Høiland-Jørgensen, Jonathan Morton,
Pete Heist
Jakub pointed out that the IP_ECN_set* helpers basically open-code
csum16_add(), so let's switch them over to using the helper instead.
v2:
- Use __be16 for check_add stack variable in IP_ECN_set_ce() (kbot)
v3:
- Turns out we need __force casts to do arithmetic on __be16 types
Reported-by: Jakub Kicinski <kuba@kernel.org>
Tested-by: Jonathan Morton <chromatix99@gmail.com>
Tested-by: Pete Heist <pete@heistp.net>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
include/net/inet_ecn.h | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/include/net/inet_ecn.h b/include/net/inet_ecn.h
index 563457fec557..ba77f47ef61e 100644
--- a/include/net/inet_ecn.h
+++ b/include/net/inet_ecn.h
@@ -8,6 +8,7 @@
#include <net/inet_sock.h>
#include <net/dsfield.h>
+#include <net/checksum.h>
enum {
INET_ECN_NOT_ECT = 0,
@@ -75,8 +76,8 @@ static inline void INET_ECN_dontxmit(struct sock *sk)
static inline int IP_ECN_set_ce(struct iphdr *iph)
{
- u32 check = (__force u32)iph->check;
u32 ecn = (iph->tos + 1) & INET_ECN_MASK;
+ __be16 check_add;
/*
* After the last operation we have (in binary):
@@ -93,23 +94,20 @@ static inline int IP_ECN_set_ce(struct iphdr *iph)
* INET_ECN_ECT_1 => check += htons(0xFFFD)
* INET_ECN_ECT_0 => check += htons(0xFFFE)
*/
- check += (__force u16)htons(0xFFFB) + (__force u16)htons(ecn);
+ check_add = (__force __be16)((__force u16)htons(0xFFFB) +
+ (__force u16)htons(ecn));
- iph->check = (__force __sum16)(check + (check>=0xFFFF));
+ iph->check = csum16_add(iph->check, check_add);
iph->tos |= INET_ECN_CE;
return 1;
}
static inline int IP_ECN_set_ect1(struct iphdr *iph)
{
- u32 check = (__force u32)iph->check;
-
if ((iph->tos & INET_ECN_MASK) != INET_ECN_ECT_0)
return 0;
- check += (__force u16)htons(0x1);
-
- iph->check = (__force __sum16)(check + (check>=0xFFFF));
+ iph->check = csum16_add(iph->check, htons(0x1));
iph->tos ^= INET_ECN_MASK;
return 1;
}
--
2.29.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next v3] inet_ecn: Use csum16_add() helper for IP_ECN_set_* helpers
2020-12-11 14:26 [PATCH net-next v3] inet_ecn: Use csum16_add() helper for IP_ECN_set_* helpers Toke Høiland-Jørgensen
@ 2020-12-15 3:10 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2020-12-15 3:10 UTC (permalink / raw)
To: =?utf-8?b?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2VuIDx0b2tlQHJlZGhhdC5jb20+?=
Cc: davem, kuba, netdev, chromatix99, pete
Hello:
This patch was applied to netdev/net-next.git (refs/heads/master):
On Fri, 11 Dec 2020 15:26:38 +0100 you wrote:
> Jakub pointed out that the IP_ECN_set* helpers basically open-code
> csum16_add(), so let's switch them over to using the helper instead.
>
> v2:
> - Use __be16 for check_add stack variable in IP_ECN_set_ce() (kbot)
> v3:
> - Turns out we need __force casts to do arithmetic on __be16 types
>
> [...]
Here is the summary with links:
- [net-next,v3] inet_ecn: Use csum16_add() helper for IP_ECN_set_* helpers
https://git.kernel.org/netdev/net-next/c/0780b4145634
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-15 3:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-11 14:26 [PATCH net-next v3] inet_ecn: Use csum16_add() helper for IP_ECN_set_* helpers Toke Høiland-Jørgensen
2020-12-15 3:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).