From: Kuniyuki Iwashima <kuniyu@amazon•com>
To: "David S. Miller" <davem@davemloft•net>,
Eric Dumazet <edumazet@google•com>,
Jakub Kicinski <kuba@kernel•org>, Paolo Abeni <pabeni@redhat•com>,
David Ahern <dsahern@kernel•org>,
Willem de Bruijn <willemdebruijn.kernel@gmail•com>
Cc: Kuniyuki Iwashima <kuniyu@amazon•com>,
Kuniyuki Iwashima <kuni1840@gmail•com>, <netdev@vger•kernel.org>
Subject: [PATCH v1 net-next 11/14] udp: Optimise ulen tests in __udp[46]_lib_rcv().
Date: Mon, 29 May 2023 18:03:45 -0700 [thread overview]
Message-ID: <20230530010348.21425-12-kuniyu@amazon.com> (raw)
In-Reply-To: <20230530010348.21425-1-kuniyu@amazon.com>
In __udp4_lib_rcv(), we need not call udp_hdr() unless we call
pskb_trim_rcsum().
In __udp6_lib_rcv(), we can save two unneeded conditions for every
jumbo payload that never be true.
if (ulen > skb->len)
goto short_packet;
if (ulen == 0)
ulen = skb->len;
if (ulen < skb->len)
Note the number of tests for non-jumbo IPv6 payload is not changed.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon•com>
---
net/ipv4/udp.c | 8 +++++---
net/ipv6/udp.c | 30 +++++++++++++++++-------------
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 23ebea2b84e4..eb968d20d5a8 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2325,10 +2325,12 @@ static int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable)
if (ulen > skb->len)
goto short_packet;
- if (ulen < sizeof(*uh) || pskb_trim_rcsum(skb, ulen))
- goto short_packet;
+ if (ulen < sizeof(*uh)) {
+ if (pskb_trim_rcsum(skb, ulen))
+ goto short_packet;
- uh = udp_hdr(skb);
+ uh = udp_hdr(skb);
+ }
if (udp4_csum_init(skb, uh))
goto csum_error;
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index ee859679427a..6f5c29af4157 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -966,23 +966,27 @@ static int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable)
uh = udp_hdr(skb);
ulen = ntohs(uh->len);
- if (ulen > skb->len)
- goto short_packet;
+ if (ulen) {
+ if (ulen > skb->len)
+ goto short_packet;
- /* Check for jumbo payload */
- if (ulen == 0)
- ulen = skb->len;
+ if (ulen < sizeof(*uh))
+ goto short_packet;
- if (ulen < sizeof(*uh))
- goto short_packet;
+ if (ulen < skb->len) {
+ if (pskb_trim_rcsum(skb, ulen))
+ goto short_packet;
- if (ulen < skb->len) {
- if (pskb_trim_rcsum(skb, ulen))
- goto short_packet;
+ saddr = &ipv6_hdr(skb)->saddr;
+ daddr = &ipv6_hdr(skb)->daddr;
+ uh = udp_hdr(skb);
+ }
+ } else {
+ /* jumbo payload */
+ ulen = skb->len;
- saddr = &ipv6_hdr(skb)->saddr;
- daddr = &ipv6_hdr(skb)->daddr;
- uh = udp_hdr(skb);
+ if (ulen < sizeof(*uh))
+ goto short_packet;
}
if (udp6_csum_init(skb, uh))
--
2.30.2
next prev parent reply other threads:[~2023-05-30 1:09 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-30 1:03 [PATCH v1 net-next 00/14] udp: Farewell to UDP-Lite Kuniyuki Iwashima
2023-05-30 1:03 ` [PATCH v1 net-next 01/14] udp: Random clenaup Kuniyuki Iwashima
2023-05-30 12:56 ` Simon Horman
2023-05-30 1:03 ` [PATCH v1 net-next 02/14] udplite: Retire UDP-Lite for IPv6 Kuniyuki Iwashima
2023-05-30 13:01 ` Simon Horman
2023-05-30 17:49 ` Kuniyuki Iwashima
2023-05-30 1:03 ` [PATCH v1 net-next 03/14] ipv6: Remove IPV6_ADDRFORM support for IPPROTO_UDPLITE Kuniyuki Iwashima
2023-05-30 14:22 ` Simon Horman
2023-05-30 1:03 ` [PATCH v1 net-next 04/14] udplite: Retire UDP-Lite for IPv4 Kuniyuki Iwashima
2023-05-30 1:03 ` [PATCH v1 net-next 05/14] udp: Remove UDP-Lite SNMP stats Kuniyuki Iwashima
2023-05-30 14:24 ` Simon Horman
2023-05-30 1:03 ` [PATCH v1 net-next 06/14] udp: Remove UDPLITE_SEND_CSCOV and UDPLITE_RECV_CSCOV Kuniyuki Iwashima
2023-05-30 1:03 ` [PATCH v1 net-next 07/14] udp: Remove pcslen, pcrlen, and pcflag in struct udp_sock Kuniyuki Iwashima
2023-05-30 1:03 ` [PATCH v1 net-next 08/14] udp: Remove csum branch for UDP-Lite Kuniyuki Iwashima
2023-05-30 1:03 ` [PATCH v1 net-next 09/14] udp: Don't pass proto to udp[46]_csum_init() Kuniyuki Iwashima
2023-05-30 1:03 ` [PATCH v1 net-next 10/14] udp: Don't pass proto to __udp[46]_lib_rcv() Kuniyuki Iwashima
2023-05-30 1:03 ` Kuniyuki Iwashima [this message]
2023-05-30 1:03 ` [PATCH v1 net-next 12/14] udp: Remove udp_table in struct proto Kuniyuki Iwashima
2023-05-30 1:03 ` [PATCH v1 net-next 13/14] udp: Remove udp_table in struct udp_seq_afinfo Kuniyuki Iwashima
2023-05-30 1:03 ` [PATCH v1 net-next 14/14] udp: Don't pass udp_table to __udp[46]_lib_lookup() Kuniyuki Iwashima
2023-05-30 2:15 ` [PATCH v1 net-next 00/14] udp: Farewell to UDP-Lite Willem de Bruijn
2023-05-30 17:34 ` Kuniyuki Iwashima
2023-05-30 20:16 ` Willem de Bruijn
2023-05-30 22:14 ` Jakub Kicinski
2023-05-31 1:01 ` Kuniyuki Iwashima
2023-05-31 4:25 ` Eric Dumazet
2023-05-31 5:10 ` Jakub Kicinski
2023-05-31 6:24 ` Paolo Abeni
2023-05-31 6:44 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230530010348.21425-12-kuniyu@amazon.com \
--to=kuniyu@amazon$(echo .)com \
--cc=davem@davemloft$(echo .)net \
--cc=dsahern@kernel$(echo .)org \
--cc=edumazet@google$(echo .)com \
--cc=kuba@kernel$(echo .)org \
--cc=kuni1840@gmail$(echo .)com \
--cc=netdev@vger$(echo .)kernel.org \
--cc=pabeni@redhat$(echo .)com \
--cc=willemdebruijn.kernel@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox