Commit 9a49850d authored by Tom Herbert's avatar Tom Herbert Committed by David S. Miller

tcp: Fix conditions to determine checksum offload

In tcp_send_sendpage and tcp_sendmsg we check the route capabilities to
determine if checksum offload can be performed. This check currently
does not take the IP protocol into account for devices that advertise
only one of NETIF_F_IPV6_CSUM or NETIF_F_IP_CSUM. This patch adds a
function to check capabilities for checksum offload with a socket
called sk_check_csum_caps. This function checks for specific IPv4 or
IPv6 offload support based on the family of the socket.
Signed-off-by: default avatarTom Herbert <tom@herbertland.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c8cd0989
...@@ -1791,6 +1791,15 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags) ...@@ -1791,6 +1791,15 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
sk->sk_route_caps &= ~flags; sk->sk_route_caps &= ~flags;
} }
static inline bool sk_check_csum_caps(struct sock *sk)
{
return (sk->sk_route_caps & NETIF_F_HW_CSUM) ||
(sk->sk_family == PF_INET &&
(sk->sk_route_caps & NETIF_F_IP_CSUM)) ||
(sk->sk_family == PF_INET6 &&
(sk->sk_route_caps & NETIF_F_IPV6_CSUM));
}
static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb, static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
struct iov_iter *from, char *to, struct iov_iter *from, char *to,
int copy, int offset) int copy, int offset)
......
...@@ -1018,7 +1018,7 @@ int tcp_sendpage(struct sock *sk, struct page *page, int offset, ...@@ -1018,7 +1018,7 @@ int tcp_sendpage(struct sock *sk, struct page *page, int offset,
ssize_t res; ssize_t res;
if (!(sk->sk_route_caps & NETIF_F_SG) || if (!(sk->sk_route_caps & NETIF_F_SG) ||
!(sk->sk_route_caps & NETIF_F_CSUM_MASK)) !sk_check_csum_caps(sk))
return sock_no_sendpage(sk->sk_socket, page, offset, size, return sock_no_sendpage(sk->sk_socket, page, offset, size,
flags); flags);
...@@ -1175,7 +1175,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) ...@@ -1175,7 +1175,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
/* /*
* Check whether we can use HW checksum. * Check whether we can use HW checksum.
*/ */
if (sk->sk_route_caps & NETIF_F_CSUM_MASK) if (sk_check_csum_caps(sk))
skb->ip_summed = CHECKSUM_PARTIAL; skb->ip_summed = CHECKSUM_PARTIAL;
skb_entail(sk, skb); skb_entail(sk, skb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment