[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] net: Transmit zero UDP checksum as 0xFFFF
From: |
Ed Swierk |
Subject: |
Re: [Qemu-devel] [PATCH] net: Transmit zero UDP checksum as 0xFFFF |
Date: |
Tue, 14 Nov 2017 18:46:56 -0800 |
On Tue, Nov 14, 2017 at 6:10 PM, Jason Wang <address@hidden> wrote:
>
>
> On 2017年11月15日 07:25, Ed Swierk wrote:
>>
>> 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, as 0x0000 is a special
>> value meaning no checksum.
>>
>> Substitute 0xFFFF whenever a checksum is computed as zero on a UDP
>> datagram. Doing this on IPv4 packets and TCP segments is unnecessary
>> but legal.
>>
>> (While it is tempting to make the substitution in
>> net_checksum_finish(), that function is also used by receivers to
>> verify checksums, and in that case the expected value is always
>> 0x0000.)
>
>
> Then looks like you'd better have an wrapper for net_checksum_finish() and
> do things there.
I'll do that in v2.
>> index 1019b50..e820132 100644
>> --- a/hw/net/net_rx_pkt.c
>> +++ b/hw/net/net_rx_pkt.c
>> @@ -588,6 +588,9 @@ bool net_rx_pkt_fix_l4_csum(struct NetRxPkt *pkt)
>> /* Calculate L4 checksum */
>> csum = cpu_to_be16(_net_rx_pkt_calc_l4_csum(pkt));
>> + if (!csum) {
>> + csum = 0xFFFF; /* For UDP, zero checksum must be sent as 0xFFFF
>> */
>> + }
>
>
> I thought we should only do this for tx?
We need to do this any time we modify the checksum field in a UDP
datagram header for someone else to verify. Normally this happens on
the tx path, and that someone is a remote system. But here
net_rx_pkt_fix_l4_csum() is used to fill in the checksum on packets
received with the NEEDS_CSUM vhdr flag before passing them along to
the guest.
--Ed