+TCP IP Checksum by interface

At present, ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM and ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM are global.

Is there an accepted solution for two interfaces of different types? In my current scenario, I have a wifi and doesn’t do it, and the STM32H5 which does. Disabling this will give me warnings in the stm32h5 NetworkInterface.c, which is non ideal.

Right now, it is compile time option which means same for both the interfaces. Can be a good enhancement if you want to contribute :wink:

Erik wrote:

At present, ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM and ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM are global, which shows that the macro’s are older than the support for multiple interfaces.

You could also write:

#ifdef ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM
    #undef ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM
#endif
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM   ipconfigENABLE

#ifdef ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM
    #undef ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM
#endif
#define ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM   ipconfigENABLE

Although some compilers will still complain about the #undef.

I have seen the problem before: Ethernet had CRC, WiFi did not.
What I did is turn on CRC checking and add manual CRC calculations in the WiFi module: before sending and after reception.
So the WiFi module would ignore at the macros ipconfigDRIVER_INCLUDED_[RX|TX]_IP_CHECKSUM.

We could also add 2 new bits to NetworkInterface_t: CRC_RX_check and CRC_TX_check, and add an API to access them.

Some notes:

For a Network Intellectual Property (IP), the RX and TX paths are separated. One should explicitly check CRC checking/setting in both directions.
Very often CRC’s of outgoing ICMP packets are not set correctly. In other cases you must set the CRC of ICMP packets explcitly to 0x0000. Otherwise it will not be set correctly.
The CRC of UDP may be zero, this was a way of gaining speed. We try to encourage to always set and check the UDP checksum.

By default, they’re not accepted:

#define ipconfigUDP_PASS_ZERO_CHECKSUM_PACKETS    ipconfigDISABLE

There are more macros that are supplied as “global settings”, see ipconfigZERO_COPY_[RX|TX]_DRIVER.
Needless to say that whatever we change, I try to keep the code backward compatible. And if not, the compiler should give clear information.

Input from other users is welcome

1 Like