include/linux/skbuff.h: checksumming documentation
Subsystems (2)
I have been reading the documentation on the checksumming of packets with respect to adding the hardware tcp/udp/ip checksumming features of the DM900A and DM9000B chips.
Looking at the received packets documentation (as follows):
* UNNECESSARY: device parsed packet and wouldbe verified checksum.
* skb->csum is undefined.
* It is bad option, but, unfortunately, many of vendors do this. * Apparently with secret goal to sell you new device, when you * will add new protocol to your host. F.e. IPv6. 8)
The first line does not make sense, and the rest of it is an unslightly rant about hardware manufacturers.
I think this comment is a bit hard, hardware is not like software where when something new comes along you can simply recompile. It is difficult to make a device which will cope with any protocol that comes along in the future.
Following on:
* COMPLETE: the most generic way. Device supplied checksum of _all_
* the packet as seen by netif_rx in skb->csum. * NOTE: Even if device supports only some protocols, but * is able to produce some skb->csum, it MUST use COMPLETE, * not UNNECESSARY.
So, where does this get applied to? From examination of some of the other drivers this seems to be the contents of skb->ip_summed in the skb.
Another problem with this is that it is ambiguous to how far the protocol support reaches to change COMPLETE to UNNECESSARY... does it cover the contents of this skb, the packet received, or all the packets the device receives?
For a device that supports IP checksumming for IPv4 and UDP and TCP over IPv4, then would the following pseudo-code be correct:
if (packet_is_ipv4) {
if (payload_is_udp() || payload_is_tcp()) {
/* the TCP/UDP packet passed checksumming */
skb->ip_csummed = CHECKSUM_UNNECESSARY;
} else {
/* the ip checksum passed, but we do not know
* what protocol is within the IP payload such
* as ICMP, etc. */
skb->ip_csummed = ??
}
} else
/* cannot handled non ipv4 packets */
ski->ip_csummed = CHECKSUM_NONE;I will have to research what the chip does with checksumming on IP fragments as, IIRC, the UDP and TCP checksums cover the entriety of the data before fragmentation.
Signature · 3 lines
Ben ([email protected], http://www.fluff.org/) 'a smiley only costs 4 bytes'
Quoted 3 lines
The first line does not make sense, and the rest of it is an unslightly rant about hardware manufacturers.
The documentation is kind of confusing.
It took me some time to figure this whole thing out.
Note that Linux TCP stack does not support IP checksum offload. Only TCP/UDP offload is supported - but to confuse all we have skb->ipsummed, which in reality holds the L4 partial checksum state.
Also, note that the stack always does the L4 pseudo header calculation, even though the underlying device might be able to perform it. Only the L4 payload
checksum is offloaded to the device.
The driver exports its capability using the features flag (eg. NETIF_F_HW_CSUM). In transmit path, Linux TCP stack calculates the L4 partial checksum (pseudo-header only),
and puts the partial checksum in skb->csum. Look at tcp_v4_send_check. CHECKSUM_PARTIAL means that the device is capable of performing partial L4 checksum offload.
The emac driver then grabs this partial checksum and XORs it with the checksum over the data,
puts this new checksum in the tcp packet header, and sends the packet out.
For RX side, if the driver is capable of computing the complete L4 checksum, it marksskb->ipsummed = CHECKSUM_UNNECESARY. If it computes the partial L4 checksum, it puts the partial L4 checksum in skb->csum and marks ip_summed as CHECKSUM_COMPLETE.
The tcp stack then XORs this value with the psuedo header.
See tcp_v4_checksum_init() which is called from tcp_v4_rcv
Quoted 4 lines
I will have to research what the chip does with checksumming on IP fragments as, IIRC, the UDP and TCP checksums cover the entriety of the data before fragmentation.
Look at Intel e1000 driver to understand checksum offload.
Thanks,
Prodyut Hazarika
Quoted 2 lines · prodyut hazarika
Note that Linux TCP stack does not support IP checksum offload.
Unless you've got options, the IP header is only 20 bytes. Plus we've just written it so it's hot in the cache, so calculating the IP checksum is essentially free.
Cheers,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt