Nulik
Nulik

Reputation: 7380

duplicate udp packets: how often it happens?

I am developing a protocol over UDP to be used in a local network, there will be only a switch (cisco, 3com, etc) between source and destination, both Linux systems, same MTU. How often should I expect udp packets to be duplicated (obviously not by me but by the switch or maybe the server) at the destination in this case? I need this to know if to implement a duplication check in my code or not.

Upvotes: 8

Views: 16833

Answers (4)

Carlos Villacorta
Carlos Villacorta

Reputation: 19

I am actually suffering some issues on an application since I haven't implemented checks to avoid duplicated packets.

Adding a simple increment check wouldn't work as expected sometimes. Why? Routers can change the inbound/outbound routes for UDP packets easily even in real time, wich can cause a delay in some packets. This can cause the next scenario:

  • Program A send 3 UDP packets with the incremental IDs 1, 2 and 3 to Program B.
  • Program B receives the UDP Packets in the order 2, 1 and 3. Not what you would expect.

So, instead I am betting in same-same-but-different mechanism:

  • Add a few random values in your packet.
  • Generate a checksum of the packet when your program receive them.
  • Save the last N checksums (Ex.: N=100) of the packets.
  • Every time you get a packet, search for a duplicated checksum in your list. Discard if found.

Hopefully this will help you avoid duplicated packets completely. It doesn't matter if your protocol it's un/encrypted, the random values will help you to get unique checksums (hopefully you won't have a checksum collision in the last N packets).

Upvotes: 0

Uri Raz
Uri Raz

Reputation: 434

From memory of a story I've read ~20 years ago...

There was a faulty router that duplicated UDP packets. Long story short it was found that some interrupt was raised excessively frequently. That caused the following scenario:

  1. The router went to the outgoing packets queue
  2. It sent the packet and before it marked it as sent...
  3. An interrupt was raised.
  4. For some reason, after handling the interrupt, the router went back to check the outgoing packet queue, rather than marking the packet as sent (an unrelated bug?), causing it to retransmit the same packet until the interval between the interrupts was long enough to finish step 2.

Upvotes: 3

Strix
Strix

Reputation: 1114

Switches will send packets to all interfaces when using broadcasts or under extreme conditions (full MAC Address Table). This can lead to duplication if there is a loop between two or more switches and if the Spanning Tree Protocol is not used. So the answer is rarely.

Upvotes: 10

Ashok Vairavan
Ashok Vairavan

Reputation: 1972

The possibility to receive duplicate UDP packets in destination host depends on number of destination interfaces that receives the packet from the source host. The destination will receive three duplicate UDP packets if three of its interfaces(eth1, eth2, eth_int) can fetch the packets from source at same time.

Upvotes: 0

Related Questions