views:

4254

answers:

5

I've read a number of articles about UDP packet sizes but have been unable to come to a conclusion on whats correct.

A number of services restrict the largest UDP packet to 512 bytes (like dns)

Given the minimum MTU on the internet is 576 , and the size of the IPv4 header is 20 bytes, and the UDP header 8 bytes. This leaves 548 bytes available for user data

Would i be able to use packets up to the size of 548 without packet fragmentation? Or is there something the creators of DNS knew about, and that why they restricted it to 512 bytes.

Could I even go higher than 548 bytes safely?

A: 

512 is your best bet. It's used elsewhere and is a nice even number (half of 1024).

Justin Niessner
+1  A: 

The theoretical limit (on Windows) for the maximum size of a UDP packet is 65507 bytes. This is documented here:

The correct maximum UDP message size is 65507, as determined by the following formula: 0xffff - (sizeof(IP Header) + sizeof(UDP Header)) = 65535-(20+8) = 65507

That being said, most protocols limit to a much smaller size - usually either 512 or occasionally 8192. You can often go higher than 548 safely if you are on a reliable network - but if you're broadcasting across the internet at large, the larger you go, the more likely you'll be to run into packet transmission problems and loss.

Reed Copsey
A: 

"The Domain Name System defaults to using UDP for queries and replies with a DNS payload limit of 512 bytes. Larger replies cause an initial truncation indication leading to a subsequent handling via TCP with substantially higher overhead."

Taken from http://www.ietf.org/proceedings/98aug/I-D/draft-ietf-dnsind-udp-size-02.txt which you should read

As to why it is 512bytes, is probably due to some historical data, as a lot of other stuff is already (and old firewalls etc may be limited to only be able to handle dns udp packages bellow 512byte limit).

Basically if its under 512, there will be no fragmentation, and preferably it will go fast.

You can send more data ofcourse, but then tcp will be used with a bit larger overhead. Depending on the quality of the lines used and their MTU and the size of the tcp packet, the fragmentation (if any) will be handled by the "network (passing servers)".

Unless you know the network (routers used etc) you cant decide on a packet that will not get fragmented. You can however write an easy script that tests sending packages with bigger size each time until you notice the fragmentation.

Milan
+2  A: 

It is true that a typical IPv4 header is 20 bytes, and the UDP header is 8 bytes. However it is possible to include IP options which can increase the size of the IP header to as much as 60 bytes. In addition, sometimes it is necessary for intermediate nodes to encapsulate datagrams inside of another protocol such as IPsec (used for VPNs and the like) in order to route the packet to its destination. So if you do not know the MTU on your particular network path, it is best to leave a reasonable margin for other header information that you may not have anticipated. A 512-byte UDP payload is generally considered to do that, although even that does not leave quite enough space for a maximum size IP header.

mark4o
A: 

IPv4 maximum reassembly buffer size is 576, IPv6 has it at 1500. Subtract header sizes from here. See Stevens UNP :)

Nikolai N Fetissov