· IP checksum
a. 接收报文
struct iphdr *iph = ip_hdr(skb);
if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
goto checksum_error;
b. 发送报文
ip_send_check(iph);
{
iph->check = 0;
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
}
· UDP checksum
a. 网卡设备属性
#define NETIF_F_IP_CSUM 2 /* 基于IPv4的L4层checksum. */
#define NETIF_F_NO_CSUM 4 /* 设备可靠不需要L4层checksum. loopack. */
#define NETIF_F_HW_CSUM 8 /* 基于所有协议的L4层checksum*/
#define NETIF_F_IPV6_CSUM 16 /* 基于IPv6的L4层checksum*/
通过ethtool可以查看网卡是否支持硬件checksum
ethtool -k eth0
Offload parameters for eth0:
Cannot get device rx csum settings: Operation not supported
Cannot get device udp large send offload settings: Operation not supported