[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230530010348.21425-10-kuniyu@amazon.com>
Date: Mon, 29 May 2023 18:03:43 -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 09/14] udp: Don't pass proto to udp[46]_csum_init().
We passed IPPROTO_UDPLITE as proto to __udp[46]_lib_rcv(), which passes
it to udp[46]_csum_init().
However, we no longer call __udp[46]_lib_rcv() with IPPROTO_UDPLITE, so
proto is always IPPROTO_UDP in udp[46]_csum_init(), and we can hard-code
it.
Also, udp6_csum_init() is not called from other functions, so we move it
to net/ipv6/udp.c as a static function.
Signed-off-by: Kuniyuki Iwashima <kuniyu@...zon.com>
---
include/net/ip6_checksum.h | 1 -
net/ipv4/udp.c | 7 +++----
net/ipv6/ip6_checksum.c | 33 ---------------------------------
net/ipv6/udp.c | 34 +++++++++++++++++++++++++++++++++-
4 files changed, 36 insertions(+), 39 deletions(-)
diff --git a/include/net/ip6_checksum.h b/include/net/ip6_checksum.h
index c8a96b888277..f9e03cc7a19c 100644
--- a/include/net/ip6_checksum.h
+++ b/include/net/ip6_checksum.h
@@ -83,5 +83,4 @@ void udp6_set_csum(bool nocheck, struct sk_buff *skb,
const struct in6_addr *saddr,
const struct in6_addr *daddr, int len);
-int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh, int proto);
#endif
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index aee075fb5f4f..f8a545c6e3e7 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2247,15 +2247,14 @@ static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
* Otherwise, csum completion requires checksumming packet body,
* including udp header and folding it to skb->csum.
*/
-static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh,
- int proto)
+static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh)
{
int err;
/* Note, we are only interested in != 0 or == 0, thus the
* force to int.
*/
- err = (__force int)skb_checksum_init_zero_check(skb, proto, uh->check,
+ err = (__force int)skb_checksum_init_zero_check(skb, IPPROTO_UDP, uh->check,
inet_compute_pseudo);
if (err)
return err;
@@ -2335,7 +2334,7 @@ static int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
uh = udp_hdr(skb);
}
- if (udp4_csum_init(skb, uh, proto))
+ if (udp4_csum_init(skb, uh))
goto csum_error;
sk = skb_steal_sock(skb, &refcounted);
diff --git a/net/ipv6/ip6_checksum.c b/net/ipv6/ip6_checksum.c
index 1362db7a3660..e1a594873675 100644
--- a/net/ipv6/ip6_checksum.c
+++ b/net/ipv6/ip6_checksum.c
@@ -62,39 +62,6 @@ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
EXPORT_SYMBOL(csum_ipv6_magic);
#endif
-int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh, int proto)
-{
- int err;
-
- /* To support RFC 6936 (allow zero checksum in UDP/IPV6 for tunnels)
- * we accept a checksum of zero here. When we find the socket
- * for the UDP packet we'll check if that socket allows zero checksum
- * for IPv6 (set by socket option).
- *
- * Note, we are only interested in != 0 or == 0, thus the
- * force to int.
- */
- err = (__force int)skb_checksum_init_zero_check(skb, proto, uh->check,
- ip6_compute_pseudo);
- if (err)
- return err;
-
- if (skb->ip_summed == CHECKSUM_COMPLETE && !skb->csum_valid) {
- /* If SW calculated the value, we know it's bad */
- if (skb->csum_complete_sw)
- return 1;
-
- /* HW says the value is bad. Let's validate that.
- * skb->csum is no longer the full packet checksum,
- * so don't treat is as such.
- */
- skb_checksum_complete_unset(skb);
- }
-
- return 0;
-}
-EXPORT_SYMBOL(udp6_csum_init);
-
/* Function to set UDP checksum for an IPv6 UDP packet. This is intended
* for the simple case like when setting the checksum for a UDP tunnel.
*/
diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 21d48f8803d0..170bbaa4a9d4 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -896,6 +896,38 @@ static void udp6_sk_rx_dst_set(struct sock *sk, struct dst_entry *dst)
}
}
+static int udp6_csum_init(struct sk_buff *skb, struct udphdr *uh)
+{
+ int err;
+
+ /* To support RFC 6936 (allow zero checksum in UDP/IPV6 for tunnels)
+ * we accept a checksum of zero here. When we find the socket
+ * for the UDP packet we'll check if that socket allows zero checksum
+ * for IPv6 (set by socket option).
+ *
+ * Note, we are only interested in != 0 or == 0, thus the
+ * force to int.
+ */
+ err = (__force int)skb_checksum_init_zero_check(skb, IPPROTO_UDP, uh->check,
+ ip6_compute_pseudo);
+ if (err)
+ return err;
+
+ if (skb->ip_summed == CHECKSUM_COMPLETE && !skb->csum_valid) {
+ /* If SW calculated the value, we know it's bad */
+ if (skb->csum_complete_sw)
+ return 1;
+
+ /* HW says the value is bad. Let's validate that.
+ * skb->csum is no longer the full packet checksum,
+ * so don't treat is as such.
+ */
+ skb_checksum_complete_unset(skb);
+ }
+
+ return 0;
+}
+
/* wrapper for udp_queue_rcv_skb tacking care of csum conversion and
* return code conversion for ip layer consumption
*/
@@ -956,7 +988,7 @@ static int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
}
}
- if (udp6_csum_init(skb, uh, proto))
+ if (udp6_csum_init(skb, uh))
goto csum_error;
/* Check if the socket is already available, e.g. due to early demux */
--
2.30.2
Powered by blists - more mailing lists