[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230530010348.21425-12-kuniyu@amazon.com>
Date: Mon, 29 May 2023 18:03:45 -0700
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: "David S. Miller" <davem@...emloft.net>, Eric Dumazet
<edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo Abeni
<pabeni@...hat.com>, David Ahern <dsahern@...nel.org>, Willem de Bruijn
<willemdebruijn.kernel@...il.com>
CC: Kuniyuki Iwashima <kuniyu@...zon.com>, Kuniyuki Iwashima
<kuni1840@...il.com>, <netdev@...r.kernel.org>
Subject: [PATCH v1 net-next 11/14] udp: Optimise ulen tests in __udp[46]_lib_rcv().
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@...zon.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
Powered by blists - more mailing lists