Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

skbuff: render the checksum comment to documentation

Long time ago Tom added a giant comment to skbuff.h explaining
checksums. Now that we have a place in Documentation for skbuff
docs we should render it. Sprinkle some markup while at it.

Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+119 -84
+6
Documentation/networking/skbuff.rst
··· 29 29 30 30 .. kernel-doc:: include/linux/skbuff.h 31 31 :doc: dataref and headerless skbs 32 + 33 + Checksum information 34 + -------------------- 35 + 36 + .. kernel-doc:: include/linux/skbuff.h 37 + :doc: skb checksums
+113 -84
include/linux/skbuff.h
··· 43 43 #include <linux/netfilter/nf_conntrack_common.h> 44 44 #endif 45 45 46 - /* The interface for checksum offload between the stack and networking drivers 46 + /** 47 + * DOC: skb checksums 48 + * 49 + * The interface for checksum offload between the stack and networking drivers 47 50 * is as follows... 48 51 * 49 - * A. IP checksum related features 52 + * IP checksum related features 53 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 50 54 * 51 55 * Drivers advertise checksum offload capabilities in the features of a device. 52 56 * From the stack's point of view these are capabilities offered by the driver. 53 57 * A driver typically only advertises features that it is capable of offloading 54 58 * to its device. 55 59 * 56 - * The checksum related features are: 60 + * .. flat-table:: Checksum related device features 61 + * :widths: 1 10 57 62 * 58 - * NETIF_F_HW_CSUM - The driver (or its device) is able to compute one 59 - * IP (one's complement) checksum for any combination 60 - * of protocols or protocol layering. The checksum is 61 - * computed and set in a packet per the CHECKSUM_PARTIAL 62 - * interface (see below). 63 + * * - %NETIF_F_HW_CSUM 64 + * - The driver (or its device) is able to compute one 65 + * IP (one's complement) checksum for any combination 66 + * of protocols or protocol layering. The checksum is 67 + * computed and set in a packet per the CHECKSUM_PARTIAL 68 + * interface (see below). 63 69 * 64 - * NETIF_F_IP_CSUM - Driver (device) is only able to checksum plain 65 - * TCP or UDP packets over IPv4. These are specifically 66 - * unencapsulated packets of the form IPv4|TCP or 67 - * IPv4|UDP where the Protocol field in the IPv4 header 68 - * is TCP or UDP. The IPv4 header may contain IP options. 69 - * This feature cannot be set in features for a device 70 - * with NETIF_F_HW_CSUM also set. This feature is being 71 - * DEPRECATED (see below). 70 + * * - %NETIF_F_IP_CSUM 71 + * - Driver (device) is only able to checksum plain 72 + * TCP or UDP packets over IPv4. These are specifically 73 + * unencapsulated packets of the form IPv4|TCP or 74 + * IPv4|UDP where the Protocol field in the IPv4 header 75 + * is TCP or UDP. The IPv4 header may contain IP options. 76 + * This feature cannot be set in features for a device 77 + * with NETIF_F_HW_CSUM also set. This feature is being 78 + * DEPRECATED (see below). 72 79 * 73 - * NETIF_F_IPV6_CSUM - Driver (device) is only able to checksum plain 74 - * TCP or UDP packets over IPv6. These are specifically 75 - * unencapsulated packets of the form IPv6|TCP or 76 - * IPv6|UDP where the Next Header field in the IPv6 77 - * header is either TCP or UDP. IPv6 extension headers 78 - * are not supported with this feature. This feature 79 - * cannot be set in features for a device with 80 - * NETIF_F_HW_CSUM also set. This feature is being 81 - * DEPRECATED (see below). 80 + * * - %NETIF_F_IPV6_CSUM 81 + * - Driver (device) is only able to checksum plain 82 + * TCP or UDP packets over IPv6. These are specifically 83 + * unencapsulated packets of the form IPv6|TCP or 84 + * IPv6|UDP where the Next Header field in the IPv6 85 + * header is either TCP or UDP. IPv6 extension headers 86 + * are not supported with this feature. This feature 87 + * cannot be set in features for a device with 88 + * NETIF_F_HW_CSUM also set. This feature is being 89 + * DEPRECATED (see below). 82 90 * 83 - * NETIF_F_RXCSUM - Driver (device) performs receive checksum offload. 84 - * This flag is only used to disable the RX checksum 85 - * feature for a device. The stack will accept receive 86 - * checksum indication in packets received on a device 87 - * regardless of whether NETIF_F_RXCSUM is set. 91 + * * - %NETIF_F_RXCSUM 92 + * - Driver (device) performs receive checksum offload. 93 + * This flag is only used to disable the RX checksum 94 + * feature for a device. The stack will accept receive 95 + * checksum indication in packets received on a device 96 + * regardless of whether NETIF_F_RXCSUM is set. 88 97 * 89 - * B. Checksumming of received packets by device. Indication of checksum 90 - * verification is set in skb->ip_summed. Possible values are: 98 + * Checksumming of received packets by device 99 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 91 100 * 92 - * CHECKSUM_NONE: 101 + * Indication of checksum verification is set in &sk_buff.ip_summed. 102 + * Possible values are: 103 + * 104 + * - %CHECKSUM_NONE 93 105 * 94 106 * Device did not checksum this packet e.g. due to lack of capabilities. 95 107 * The packet contains full (though not verified) checksum in packet but 96 108 * not in skb->csum. Thus, skb->csum is undefined in this case. 97 109 * 98 - * CHECKSUM_UNNECESSARY: 110 + * - %CHECKSUM_UNNECESSARY 99 111 * 100 112 * The hardware you're dealing with doesn't calculate the full checksum 101 - * (as in CHECKSUM_COMPLETE), but it does parse headers and verify checksums 102 - * for specific protocols. For such packets it will set CHECKSUM_UNNECESSARY 103 - * if their checksums are okay. skb->csum is still undefined in this case 113 + * (as in %CHECKSUM_COMPLETE), but it does parse headers and verify checksums 114 + * for specific protocols. For such packets it will set %CHECKSUM_UNNECESSARY 115 + * if their checksums are okay. &sk_buff.csum is still undefined in this case 104 116 * though. A driver or device must never modify the checksum field in the 105 117 * packet even if checksum is verified. 106 118 * 107 - * CHECKSUM_UNNECESSARY is applicable to following protocols: 108 - * TCP: IPv6 and IPv4. 109 - * UDP: IPv4 and IPv6. A device may apply CHECKSUM_UNNECESSARY to a 119 + * %CHECKSUM_UNNECESSARY is applicable to following protocols: 120 + * 121 + * - TCP: IPv6 and IPv4. 122 + * - UDP: IPv4 and IPv6. A device may apply CHECKSUM_UNNECESSARY to a 110 123 * zero UDP checksum for either IPv4 or IPv6, the networking stack 111 124 * may perform further validation in this case. 112 - * GRE: only if the checksum is present in the header. 113 - * SCTP: indicates the CRC in SCTP header has been validated. 114 - * FCOE: indicates the CRC in FC frame has been validated. 125 + * - GRE: only if the checksum is present in the header. 126 + * - SCTP: indicates the CRC in SCTP header has been validated. 127 + * - FCOE: indicates the CRC in FC frame has been validated. 115 128 * 116 - * skb->csum_level indicates the number of consecutive checksums found in 117 - * the packet minus one that have been verified as CHECKSUM_UNNECESSARY. 129 + * &sk_buff.csum_level indicates the number of consecutive checksums found in 130 + * the packet minus one that have been verified as %CHECKSUM_UNNECESSARY. 118 131 * For instance if a device receives an IPv6->UDP->GRE->IPv4->TCP packet 119 132 * and a device is able to verify the checksums for UDP (possibly zero), 120 - * GRE (checksum flag is set) and TCP, skb->csum_level would be set to 133 + * GRE (checksum flag is set) and TCP, &sk_buff.csum_level would be set to 121 134 * two. If the device were only able to verify the UDP checksum and not 122 135 * GRE, either because it doesn't support GRE checksum or because GRE 123 136 * checksum is bad, skb->csum_level would be set to zero (TCP checksum is 124 137 * not considered in this case). 125 138 * 126 - * CHECKSUM_COMPLETE: 139 + * - %CHECKSUM_COMPLETE 127 140 * 128 141 * This is the most generic way. The device supplied checksum of the _whole_ 129 - * packet as seen by netif_rx() and fills in skb->csum. This means the 142 + * packet as seen by netif_rx() and fills in &sk_buff.csum. This means the 130 143 * hardware doesn't need to parse L3/L4 headers to implement this. 131 144 * 132 145 * Notes: 146 + * 133 147 * - Even if device supports only some protocols, but is able to produce 134 148 * skb->csum, it MUST use CHECKSUM_COMPLETE, not CHECKSUM_UNNECESSARY. 135 149 * - CHECKSUM_COMPLETE is not applicable to SCTP and FCoE protocols. 136 150 * 137 - * CHECKSUM_PARTIAL: 151 + * - %CHECKSUM_PARTIAL 138 152 * 139 153 * A checksum is set up to be offloaded to a device as described in the 140 154 * output description for CHECKSUM_PARTIAL. This may occur on a packet ··· 160 146 * packet that are after the checksum being offloaded are not considered to 161 147 * be verified. 162 148 * 163 - * C. Checksumming on transmit for non-GSO. The stack requests checksum offload 164 - * in the skb->ip_summed for a packet. Values are: 149 + * Checksumming on transmit for non-GSO 150 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 165 151 * 166 - * CHECKSUM_PARTIAL: 152 + * The stack requests checksum offload in the &sk_buff.ip_summed for a packet. 153 + * Values are: 154 + * 155 + * - %CHECKSUM_PARTIAL 167 156 * 168 157 * The driver is required to checksum the packet as seen by hard_start_xmit() 169 - * from skb->csum_start up to the end, and to record/write the checksum at 170 - * offset skb->csum_start + skb->csum_offset. A driver may verify that the 158 + * from &sk_buff.csum_start up to the end, and to record/write the checksum at 159 + * offset &sk_buff.csum_start + &sk_buff.csum_offset. 160 + * A driver may verify that the 171 161 * csum_start and csum_offset values are valid values given the length and 172 162 * offset of the packet, but it should not attempt to validate that the 173 163 * checksum refers to a legitimate transport layer checksum -- it is the ··· 183 165 * checksum calculation to the device, or call skb_checksum_help (in the case 184 166 * that the device does not support offload for a particular checksum). 185 167 * 186 - * NETIF_F_IP_CSUM and NETIF_F_IPV6_CSUM are being deprecated in favor of 187 - * NETIF_F_HW_CSUM. New devices should use NETIF_F_HW_CSUM to indicate 168 + * %NETIF_F_IP_CSUM and %NETIF_F_IPV6_CSUM are being deprecated in favor of 169 + * %NETIF_F_HW_CSUM. New devices should use %NETIF_F_HW_CSUM to indicate 188 170 * checksum offload capability. 189 - * skb_csum_hwoffload_help() can be called to resolve CHECKSUM_PARTIAL based 171 + * skb_csum_hwoffload_help() can be called to resolve %CHECKSUM_PARTIAL based 190 172 * on network device checksumming capabilities: if a packet does not match 191 - * them, skb_checksum_help or skb_crc32c_help (depending on the value of 192 - * csum_not_inet, see item D.) is called to resolve the checksum. 173 + * them, skb_checksum_help() or skb_crc32c_help() (depending on the value of 174 + * &sk_buff.csum_not_inet, see :ref:`crc`) 175 + * is called to resolve the checksum. 193 176 * 194 - * CHECKSUM_NONE: 177 + * - %CHECKSUM_NONE 195 178 * 196 179 * The skb was already checksummed by the protocol, or a checksum is not 197 180 * required. 198 181 * 199 - * CHECKSUM_UNNECESSARY: 182 + * - %CHECKSUM_UNNECESSARY 200 183 * 201 184 * This has the same meaning as CHECKSUM_NONE for checksum offload on 202 185 * output. 203 186 * 204 - * CHECKSUM_COMPLETE: 187 + * - %CHECKSUM_COMPLETE 188 + * 205 189 * Not used in checksum output. If a driver observes a packet with this value 206 - * set in skbuff, it should treat the packet as if CHECKSUM_NONE were set. 190 + * set in skbuff, it should treat the packet as if %CHECKSUM_NONE were set. 207 191 * 208 - * D. Non-IP checksum (CRC) offloads 192 + * .. _crc: 209 193 * 210 - * NETIF_F_SCTP_CRC - This feature indicates that a device is capable of 211 - * offloading the SCTP CRC in a packet. To perform this offload the stack 212 - * will set csum_start and csum_offset accordingly, set ip_summed to 213 - * CHECKSUM_PARTIAL and set csum_not_inet to 1, to provide an indication in 214 - * the skbuff that the CHECKSUM_PARTIAL refers to CRC32c. 215 - * A driver that supports both IP checksum offload and SCTP CRC32c offload 216 - * must verify which offload is configured for a packet by testing the 217 - * value of skb->csum_not_inet; skb_crc32c_csum_help is provided to resolve 218 - * CHECKSUM_PARTIAL on skbs where csum_not_inet is set to 1. 194 + * Non-IP checksum (CRC) offloads 195 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 219 196 * 220 - * NETIF_F_FCOE_CRC - This feature indicates that a device is capable of 221 - * offloading the FCOE CRC in a packet. To perform this offload the stack 222 - * will set ip_summed to CHECKSUM_PARTIAL and set csum_start and csum_offset 223 - * accordingly. Note that there is no indication in the skbuff that the 224 - * CHECKSUM_PARTIAL refers to an FCOE checksum, so a driver that supports 225 - * both IP checksum offload and FCOE CRC offload must verify which offload 226 - * is configured for a packet, presumably by inspecting packet headers. 197 + * .. flat-table:: 198 + * :widths: 1 10 227 199 * 228 - * E. Checksumming on output with GSO. 200 + * * - %NETIF_F_SCTP_CRC 201 + * - This feature indicates that a device is capable of 202 + * offloading the SCTP CRC in a packet. To perform this offload the stack 203 + * will set csum_start and csum_offset accordingly, set ip_summed to 204 + * %CHECKSUM_PARTIAL and set csum_not_inet to 1, to provide an indication 205 + * in the skbuff that the %CHECKSUM_PARTIAL refers to CRC32c. 206 + * A driver that supports both IP checksum offload and SCTP CRC32c offload 207 + * must verify which offload is configured for a packet by testing the 208 + * value of &sk_buff.csum_not_inet; skb_crc32c_csum_help() is provided to 209 + * resolve %CHECKSUM_PARTIAL on skbs where csum_not_inet is set to 1. 229 210 * 230 - * In the case of a GSO packet (skb_is_gso(skb) is true), checksum offload 211 + * * - %NETIF_F_FCOE_CRC 212 + * - This feature indicates that a device is capable of offloading the FCOE 213 + * CRC in a packet. To perform this offload the stack will set ip_summed 214 + * to %CHECKSUM_PARTIAL and set csum_start and csum_offset 215 + * accordingly. Note that there is no indication in the skbuff that the 216 + * %CHECKSUM_PARTIAL refers to an FCOE checksum, so a driver that supports 217 + * both IP checksum offload and FCOE CRC offload must verify which offload 218 + * is configured for a packet, presumably by inspecting packet headers. 219 + * 220 + * Checksumming on output with GSO 221 + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 222 + * 223 + * In the case of a GSO packet (skb_is_gso() is true), checksum offload 231 224 * is implied by the SKB_GSO_* flags in gso_type. Most obviously, if the 232 - * gso_type is SKB_GSO_TCPV4 or SKB_GSO_TCPV6, TCP checksum offload as 225 + * gso_type is %SKB_GSO_TCPV4 or %SKB_GSO_TCPV6, TCP checksum offload as 233 226 * part of the GSO operation is implied. If a checksum is being offloaded 234 - * with GSO then ip_summed is CHECKSUM_PARTIAL, and both csum_start and 227 + * with GSO then ip_summed is %CHECKSUM_PARTIAL, and both csum_start and 235 228 * csum_offset are set to refer to the outermost checksum being offloaded 236 229 * (two offloaded checksums are possible with UDP encapsulation). 237 230 */