Ticket #397 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

UDP checksum calculated incorrectly

Reported by: kosma Owned by: kosma
Priority: high Milestone: UMPA 0.3 - L2
Component: UMPA Version: current svn
Keywords: Cc:

Description (last modified by getxsick) (diff)

The following sample program generates incorrect UDP checksum.

import umit.umpa
import umit.umpa.protocols

ethernet = umit.umpa.protocols.Ethernet(
    src="00:11:09:81:ec:dc",
    dst="00:1e:e5:6d:7b:42",
)
ip = umit.umpa.protocols.IP(
        src="192.168.1.234",
        dst="156.17.70.157",
)
udp = umit.umpa.protocols.UDP(
        srcport=1234,
        dstport=1234,
)
payload = umit.umpa.protocols.Payload(
        data="UMPAPA\n"
)

packet = umit.umpa.Packet(ethernet, ip, udp, payload)
socket = umit.umpa.SocketL2()
socket.send(packet)

Wireshark complains about:

User Datagram Protocol, Src Port: 1234 (1234), Dst Port: 1234 (1234)
(...)
Checksum: 0x5129 [incorrect, should be 0x50f2 (maybe caused by "UDP checksum offload"?)]

Attachments

udp_fix.patch (349 bytes) - added by kosma 3 years ago.
udp_fix_tests.patch (1.9 kB) - added by kosma 3 years ago.

Change History

  Changed 3 years ago by kosma

  • status changed from new to assigned
  • summary changed from UDP checksum calcualted incorrectly to UDP checksum calculated incorrectly

follow-up: ↓ 3   Changed 3 years ago by getxsick

What if you do not use Ethernet protocol? How about the trunk? How about TCP?

in reply to: ↑ 2   Changed 3 years ago by kosma

Replying to getxsick:

What if you do not use Ethernet protocol? How about the trunk? How about TCP?

UDP with trunk - checksum incorrect. TCP with trunk - checksum correct.

Will investigate further.

  Changed 3 years ago by getxsick

If so, please change in description to trunk.

How about the milestone. 0.3 is not released yet. Please do not mess it up.

  Changed 3 years ago by kosma

  • version changed from current svn (branch) to current svn

  Changed 3 years ago by kosma

  • milestone changed from UMPA 0.5 to UMPA 0.3 - L2+UDP fix

Changed 3 years ago by kosma

  Changed 3 years ago by kosma

Apparently the bug was caused by a typo. _checksum belongs to post_raw; _length to pre_raw. Even the comment mentions Length.

  Changed 3 years ago by getxsick

Why unit tests don't catch this bug? If it wasn't covered, please provide tests for this case along with patch.

  Changed 3 years ago by luis

This is a bug from trunk.

I tested in both branches and it happens when UDP have payload. If UDP doesn't contain payload it will work fine.

Note: tested under GNU/Linux.

  Changed 3 years ago by getxsick

  • description modified (diff)

luis, does it happen after the patch is applied? do i understand you correctly?

  Changed 3 years ago by luis

Ok.

I tested the patch. It is working fine for me.

I just noticed that the bug doesn't exists with a empty UDP Packet (without payload).

  Changed 3 years ago by kosma

Yes, that is correct. This is because without payload the protocol_bits value is zero and the assignment:

self.get_field('_checksum')._tmp_value = protocol_bits

forces the checksum to be 0x0000 which means 'checksum not calculated'.

  Changed 3 years ago by getxsick

Can anyone test it under Windows?

Also, I would like to see appropriate unit tests for this case.

  Changed 3 years ago by luis

Tested under Windows XP SP2. It works fine.

Just missing tests.

Changed 3 years ago by kosma

  Changed 3 years ago by kosma

Attached a fix with proper unit tests. Please review.

  Changed 3 years ago by luis

works for me.

  Changed 3 years ago by getxsick

so, kosma, please apply the patch and close the ticket.

  Changed 3 years ago by kosma

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in r5615.

Note: See TracTickets for help on using tickets.