Browse Source

ip: Move checksum convert defines to inet

Move convert_csum from udp_sock to inet_sock. This allows the
possibility that we can use convert checksum for different types
of sockets and also allows convert checksum to be enabled from
inet layer (what we'll want to do when enabling IP_CHECKSUM cmsg).

Signed-off-by: Tom Herbert <therbert@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Tom Herbert 10 years ago
parent
commit
224d019c4f
6 changed files with 22 additions and 19 deletions
  1. 1 15
      include/linux/udp.h
  2. 17 0
      include/net/inet_sock.h
  3. 1 1
      net/ipv4/fou.c
  4. 1 1
      net/ipv4/udp.c
  5. 1 1
      net/ipv4/udp_tunnel.c
  6. 1 1
      net/ipv6/udp.c

+ 1 - 15
include/linux/udp.h

@@ -49,11 +49,7 @@ struct udp_sock {
 	unsigned int	 corkflag;	/* Cork is required */
 	unsigned int	 corkflag;	/* Cork is required */
 	__u8		 encap_type;	/* Is this an Encapsulation socket? */
 	__u8		 encap_type;	/* Is this an Encapsulation socket? */
 	unsigned char	 no_check6_tx:1,/* Send zero UDP6 checksums on TX? */
 	unsigned char	 no_check6_tx:1,/* Send zero UDP6 checksums on TX? */
-			 no_check6_rx:1,/* Allow zero UDP6 checksums on RX? */
-			 convert_csum:1;/* On receive, convert checksum
-					 * unnecessary to checksum complete
-					 * if possible.
-					 */
+			 no_check6_rx:1;/* Allow zero UDP6 checksums on RX? */
 	/*
 	/*
 	 * Following member retains the information to create a UDP header
 	 * Following member retains the information to create a UDP header
 	 * when the socket is uncorked.
 	 * when the socket is uncorked.
@@ -102,16 +98,6 @@ static inline bool udp_get_no_check6_rx(struct sock *sk)
 	return udp_sk(sk)->no_check6_rx;
 	return udp_sk(sk)->no_check6_rx;
 }
 }
 
 
-static inline void udp_set_convert_csum(struct sock *sk, bool val)
-{
-	udp_sk(sk)->convert_csum = val;
-}
-
-static inline bool udp_get_convert_csum(struct sock *sk)
-{
-	return udp_sk(sk)->convert_csum;
-}
-
 #define udp_portaddr_for_each_entry(__sk, node, list) \
 #define udp_portaddr_for_each_entry(__sk, node, list) \
 	hlist_nulls_for_each_entry(__sk, node, list, __sk_common.skc_portaddr_node)
 	hlist_nulls_for_each_entry(__sk, node, list, __sk_common.skc_portaddr_node)
 
 

+ 17 - 0
include/net/inet_sock.h

@@ -184,6 +184,7 @@ struct inet_sock {
 				mc_all:1,
 				mc_all:1,
 				nodefrag:1;
 				nodefrag:1;
 	__u8			rcv_tos;
 	__u8			rcv_tos;
+	__u8			convert_csum;
 	int			uc_index;
 	int			uc_index;
 	int			mc_index;
 	int			mc_index;
 	__be32			mc_addr;
 	__be32			mc_addr;
@@ -250,4 +251,20 @@ static inline __u8 inet_sk_flowi_flags(const struct sock *sk)
 	return flags;
 	return flags;
 }
 }
 
 
+static inline void inet_inc_convert_csum(struct sock *sk)
+{
+	inet_sk(sk)->convert_csum++;
+}
+
+static inline void inet_dec_convert_csum(struct sock *sk)
+{
+	if (inet_sk(sk)->convert_csum > 0)
+		inet_sk(sk)->convert_csum--;
+}
+
+static inline bool inet_get_convert_csum(struct sock *sk)
+{
+	return !!inet_sk(sk)->convert_csum;
+}
+
 #endif	/* _INET_SOCK_H */
 #endif	/* _INET_SOCK_H */

+ 1 - 1
net/ipv4/fou.c

@@ -490,7 +490,7 @@ static int fou_create(struct net *net, struct fou_cfg *cfg,
 	sk->sk_user_data = fou;
 	sk->sk_user_data = fou;
 	fou->sock = sock;
 	fou->sock = sock;
 
 
-	udp_set_convert_csum(sk, true);
+	inet_inc_convert_csum(sk);
 
 
 	sk->sk_allocation = GFP_ATOMIC;
 	sk->sk_allocation = GFP_ATOMIC;
 
 

+ 1 - 1
net/ipv4/udp.c

@@ -1806,7 +1806,7 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
 	if (sk != NULL) {
 	if (sk != NULL) {
 		int ret;
 		int ret;
 
 
-		if (udp_sk(sk)->convert_csum && uh->check && !IS_UDPLITE(sk))
+		if (inet_get_convert_csum(sk) && uh->check && !IS_UDPLITE(sk))
 			skb_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
 			skb_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
 						 inet_compute_pseudo);
 						 inet_compute_pseudo);
 
 

+ 1 - 1
net/ipv4/udp_tunnel.c

@@ -63,7 +63,7 @@ void setup_udp_tunnel_sock(struct net *net, struct socket *sock,
 	inet_sk(sk)->mc_loop = 0;
 	inet_sk(sk)->mc_loop = 0;
 
 
 	/* Enable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */
 	/* Enable CHECKSUM_UNNECESSARY to CHECKSUM_COMPLETE conversion */
-	udp_set_convert_csum(sk, true);
+	inet_inc_convert_csum(sk);
 
 
 	rcu_assign_sk_user_data(sk, cfg->sk_user_data);
 	rcu_assign_sk_user_data(sk, cfg->sk_user_data);
 
 

+ 1 - 1
net/ipv6/udp.c

@@ -909,7 +909,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
 			goto csum_error;
 			goto csum_error;
 		}
 		}
 
 
-		if (udp_sk(sk)->convert_csum && uh->check && !IS_UDPLITE(sk))
+		if (inet_get_convert_csum(sk) && uh->check && !IS_UDPLITE(sk))
 			skb_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
 			skb_checksum_try_convert(skb, IPPROTO_UDP, uh->check,
 						 ip6_compute_pseudo);
 						 ip6_compute_pseudo);