User Tools

Site Tools


mywiki:linux:checksum

Linux Checksum Calculation Logic

API Comments
skb_checksum_help
ip_fast_csum
csum_fold
skb_checksum
csum_tcpudp_magic
nf_ip_checksum
csum_tcpudp_nofold
csum_replace4
csum_replace2
nf_nat_ipv4_csum_recalc
csum_tcpudp_magic

skb→csum_start = skb_transport_header(skb) - skb→head;

skb→csum_offset = offsetof(struct tcphdr, check);

TSO is a hardware feature whereas GSO is a software feature.

In the sense, TSO needs “the device” to break the frame into MTU sized segments. BUT, GSO is a strategy followed by kernel to avoid processing smaller packets throughout the stack to improve the porformance

Linux Checksum offloading

  1. For bridging and non-udp/tcp packet, no so called offloading support in tx path
  2. For Fragmented packets, no checksum offloading support in tx path
  3. For UDP/TCP routing packet (incremental), no checksum offloading support in tx path. at the same time, no ip_summed flag change
  4. Only Linux local output UDP/TCP’s checksum can be offloaded in tx path
  5. For L2TP related tunnels, only inner UDP/TCP can be offloaded, outer UDP/TCP is done by linux itself in tx path.

Below variables in skb is very important for checksum offloading:

  1. ip_summed (CHECKSUM_PARTIAL)
  2. encapsulation
  3. inner_network_header/network_header
  4. inner_transport_header/transport_header

Linux Checksum

union {

    __wsum                       csum;
    struct {
        __u16  csum_start;
        __u16  csum_offset;
   };
}; 
Variables/Direction skb→ip_summed skb→csum or csum_start/offset
Input CHECKSUM_NONE 0 not valid SW need do L4 payload + pseudo header verification
CHECKSUM_UNNECESSARY 1 not valid HW already do L4 payload + pseudo header verification
CHECKSUM_COMPLETE 2 csum valid (stored with L4 payload checksum) SW need to do skb→csum + pseudo header verification
Output CHECKSUM_NONE 0 not valid SW already do necessary L4 checksum calculation
CHECKSUM_PARTIAL 3 csum_start/offset valid SW already do pseudo header and HW need to further calculate its payload based on
mywiki/linux/checksum.txt · Last modified: by 127.0.0.1