All of lore.kernel.org
 help / color / mirror / Atom feed
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 09/14] udp: Don't pass proto to udp[46]_csum_init().
Date: Mon, 29 May 2023 18:03:43 -0700	[thread overview]
Message-ID: <20230530010348.21425-10-kuniyu@amazon.com> (raw)
In-Reply-To: <20230530010348.21425-1-kuniyu@amazon.com>

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@amazon.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


  parent reply	other threads:[~2023-05-30  1:08 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 ` Kuniyuki Iwashima [this message]
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 ` [PATCH v1 net-next 11/14] udp: Optimise ulen tests in __udp[46]_lib_rcv() Kuniyuki Iwashima
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-10-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.