mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 06:43:53 -06:00
net: Transmit zero UDP checksum as 0xFFFF
The checksum algorithm used by IPv4, TCP and UDP allows a zero value to be represented by either 0x0000 and 0xFFFF. But per RFC 768, a zero UDP checksum must be transmitted as 0xFFFF because 0x0000 is a special value meaning no checksum. Substitute 0xFFFF whenever a checksum is computed as zero when modifying a UDP datagram header. Doing this on IPv4 and TCP checksums is unnecessary but legal. Add a wrapper for net_checksum_finish() that makes the substitution. (We can't just change net_checksum_finish(), as that function is also used by receivers to verify checksums, and in that case the expected value is always 0x0000.) Signed-off-by: Ed Swierk <eswierk@skyportsystems.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
parent
ebc2327f07
commit
0dacea92d2
5 changed files with 11 additions and 4 deletions
|
@ -33,6 +33,12 @@ net_checksum_add(int len, uint8_t *buf)
|
|||
return net_checksum_add_cont(len, buf, 0);
|
||||
}
|
||||
|
||||
static inline uint16_t
|
||||
net_checksum_finish_nozero(uint32_t sum)
|
||||
{
|
||||
return net_checksum_finish(sum) ?: 0xFFFF;
|
||||
}
|
||||
|
||||
static inline uint16_t
|
||||
net_raw_checksum(uint8_t *data, int length)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue