我读过许多关于UDP数据包大小的文章,但一直无法得出正确的结论。
许多服务将最大的UDP数据包限制在512字节(如dns)
假定internet上的最小MTU是576,IPv4报头的大小是20字节,UDP报头的大小是8字节。这就为用户数据留下了548个字节可用
我是否能够使用548大小的数据包而不产生数据包碎片?或者DNS的创造者知道一些事情,这就是为什么他们把它限制在512字节。
我能安全的把数据设置在548字节以上吗?
我读过许多关于UDP数据包大小的文章,但一直无法得出正确的结论。
许多服务将最大的UDP数据包限制在512字节(如dns)
假定internet上的最小MTU是576,IPv4报头的大小是20字节,UDP报头的大小是8字节。这就为用户数据留下了548个字节可用
我是否能够使用548大小的数据包而不产生数据包碎片?或者DNS的创造者知道一些事情,这就是为什么他们把它限制在512字节。
我能安全的把数据设置在548字节以上吗?
当前回答
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.
其他回答
IPv4最小重组缓冲区大小为576,IPv6为1500。从这里减去标题大小。参见W. Richard Stevens的UNIX网络编程:)
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.
I've read some good answers here; however, there are some minor mistakes. Some have answered that the Message Length field in the UDP header is a max of 65535 (0xFFFF); this is technically true. Some have answered that the actual maximum is (65535 - IPHL - UDPHL = 65507). The mistake, is that the Message Length field in the UDP Header includes all payload (Layers 5-7), plus the length of the UDP Header (8 Bytes). What this means is that if the message length field is 200 Bytes (0x00C8), the payload is actually 192 Bytes (0x00C0).
固定不变的是IP数据报的最大大小是65535字节。这个数字是L3和L4报头加上5-7层有效载荷的总和。IP头+ UDP头+层5-7 = 65535(最大)。
UDP数据报的最大大小最正确的答案是65515字节(0xFFEB),因为UDP数据报包括UDP头。UDP有效载荷最大大小的最正确答案是65507字节,因为UDP有效载荷不包括UDP头。
我担心我会引起不安的反应,但尽管如此,为了澄清我是否错了,或者那些看到这个问题并对答案感兴趣的人:
我对https://www.rfc-editor.org/rfc/rfc1122的理解,它的状态是“官方规范”,因此是这个问题中使用的术语的参考,它既没有被另一个RFC取代,也没有与以下内容相矛盾的错误:
从理论上讲,ie。根据书面规范,像https://www.rfc-editor.org/rfc/rfc1122#section-4这样的UDP没有“数据包大小”。因此答案可能是“不确定的”
在实践中,这就是这个问题可能寻求的(以及可以根据当前的技术进行更新),这可能是不同的,我不知道。
如果我造成了困扰,我道歉。https://www.rfc-editor.org/rfc/rfc1122#page-8“互联网协议套件”和“架构假设”并没有让我清楚地知道我所做的“假设”,基于我所听到的,这些层是分开的。Ie。UDP所在的层不需要关心IP所在的层(IP层确实有像重组,EMTU_R,碎片和MMS_R (https://www.rfc-editor.org/rfc/rfc1122#page-56))
考虑到IPV6的大小为1500,我认为运营商不会为IPV4和IPV6提供单独的路径(它们都是不同类型的IP),迫使它们使用旧的、冗余的、维护成本更高、可靠性更低的IPV4设备。这没有任何意义。此外,这样做可能很容易被认为是为某些流量提供优惠待遇——在他们可能不太关心的规则下(除非他们被抓住),这是不允许的。
因此,1472对于外部使用应该是安全的(尽管这并不意味着像DNS这样的应用程序不知道EDNS将接受它),如果你谈论的是内部网络,你更可能知道你的网络布局,在这种情况下,巨型数据包大小适用于非碎片数据包,因此对于4096 - 4068字节,对于英特尔卡的9014字节缓冲区,包大小为…… 等待……8086字节,是最大的…巧合吗?窃笑
* * * * * * * *更新
各种答案给出软件供应商允许的最大值或假设封装的各种答案。用户并没有要求尽可能低的值(比如安全的UDP大小为“0”),而是要求最大的安全数据包大小。
各个层的封装值可以被多次包含。因为一旦封装了一个流,就没有什么可以禁止的了,比如说,在它下面有一个VPN层,在它上面有一个完全复制的封装层。
由于这个问题是关于最大安全值的,我假设他们谈论的是可以接收的UDP数据包的最大安全值。由于没有UDP数据包是保证的,如果你收到一个UDP数据包,最大的安全大小将是IPv4上的1个数据包或1472字节。
注意——如果你使用IPv6,最大大小将是1452字节,因为IPv6的报头大小是40字节,IPv4是20字节(无论哪种方式,仍然必须允许8字节的UDP报头)。