net: skip TCP/UDP pseudo-header checksum with hardware offload

When supporting hardware checksum offloading, the network protocol stack
does not perform TCP/UDP pseudo-header checksum calculation.

Skip TCP/UDP pseudo header checksum calculation in network protocol stack

Signed-off-by: daichuan <daichuan@xiaomi.com>
This commit is contained in:
daichuan
2025-08-30 01:18:20 +08:00
committed by Xiang Xiao
parent 42da4e322a
commit 99bf7c3c5f
8 changed files with 237 additions and 137 deletions
+38
View File
@@ -173,6 +173,44 @@ Ioctls for IP Addresses
to manage IPv6 addresses, by which you don't need to care about the
slot it stored.
Hardware Checksum Offload
=========================
The structure :c:struct:`net_driver_s` includes fields to support hardware
checksum offloading. This feature allows the network stack to delegate
checksum calculation to the network device hardware, improving performance.
Checksum Configuration Options
------------------------------
* :c:macro:`CONFIG_NETDEV_CHECKSUM`: Enable support for hardware checksum
offloading in the network stack. This option requires the architecture
to support it (:c:macro:`ARCH_HAVE_NETDEV_CHECKSUM_HW`).
Implementation Details
----------------------
When :c:macro:`CONFIG_NETDEV_CHECKSUM` is enabled, the driver should use the
following helper functions to retrieve checksum offload information:
* :c:func:`netdev_checksum_start`: Get the offset from the beginning of the
packet to the start of the L4 header (checksum calculation start).
* :c:func:`netdev_checksum_offset`: Get the offset from the start of the L4
header to the checksum field.
* :c:func:`netdev_upperlayer_header_checksum`: Calculate the pseudo-header
checksum.
.. code-block:: c
#ifdef CONFIG_NETDEV_CHECKSUM
int netdev_checksum_start(FAR struct net_driver_s *dev);
int netdev_checksum_offset(FAR struct net_driver_s *dev);
uint16_t netdev_upperlayer_header_checksum(FAR struct net_driver_s *dev);
#endif
Drivers that support hardware checksum offloading should use these functions
to configure the hardware accordingly before transmitting the packet.
[1]: https://man7.org/linux/man-pages/man7/netdevice.7.html
[2]: e.g. 'eth0:0' stands for the secondary address on eth0