uip: verify TCP and UDP checksums using the RX descriptor flag

The TODO next to the disabled TCP checksum code asks which bit of the RX tag
carries the result. It is bit 2 of byte 1: the hardware sets it when the L4
checksum is bad.

That answers the question for UDP as well, which was not being checked either
because UIP_CONF_UDP_CHECKSUMS is 0. Both paths now read the flag instead of
running a checksum over the payload on the 8051.

A zero UDP checksum, which is optional in IPv4, is not flagged by the hardware,
so DHCP keeps working and no extra condition is needed.

rx_headers lives in rtlplayground.c, which the host tests do not link, so
test_httpd_tx carries the storage itself the way it already carries uip_buf.
A zeroed descriptor reads as a good checksum, so the existing scenarios are
unaffected.

A new scenario sets the flag on a request and expects it counted as a checksum
error and left unanswered, then sends the same request with the flag clear and
expects it served. Built against uip.c without this change, those first two
checks fail and the two control checks still pass, so the scenario tells the
two versions apart rather than merely exercising the code.

Costs 156 bytes of code on SWTGW218AS and no extra XDATA.
This commit is contained in:
d00f committed 2026-09-20 00:35:10 +02:00
1 parent 7d47edb649
commit 9984649177
3 files changed
+53 -9

No files matched your search

+15 -9
View File
@@ -95,6 +95,9 @@
#endif /* UIP_CONF_IPV6 */
#include "../rtl837x_common.h"
#include "../rtl837x_regs.h"
extern __xdata uint8_t rx_headers[16];
/*---------------------------------------------------------------------------*/
/* Variable definitions. */
@@ -1120,6 +1123,12 @@ uip_process(u8_t flag) __banked
goto drop;
}
#else /* UIP_UDP_CHECKSUMS */
if (rx_headers[1] & RX_TAG_L4_CSUM_BAD) {
UIP_STAT(++uip_stat.udp.drop);
UIP_STAT(++uip_stat.udp.chkerr);
UIP_LOG("udp: bad checksum.");
goto drop;
}
uip_len = uip_len - UIP_IPUDPH_LEN;
#endif /* UIP_UDP_CHECKSUMS */
@@ -1200,15 +1209,12 @@ uip_process(u8_t flag) __banked
/* Start of TCP input header processing code. */
// BUG: We need to reimplement this with RTL837x TCP checksum checking
// i.e. figure out which bit in the RX-tag states the checksum is correct
// if(uip_tcpchksum() != 0xffff) { /* Compute and check the TCP
// checksum. */
// UIP_STAT(++uip_stat.tcp.drop);
// UIP_STAT(++uip_stat.tcp.chkerr);
// UIP_LOG("tcp: bad checksum.");
// goto drop;
// }
if (rx_headers[1] & RX_TAG_L4_CSUM_BAD) {
UIP_STAT(++uip_stat.tcp.drop);
UIP_STAT(++uip_stat.tcp.chkerr);
UIP_LOG("tcp: bad checksum.");
goto drop;
}
/* Demultiplex this segment. */