Linux UDP IP 分片和 MTU
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3712151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UDP IP Fragmentation and MTU
提问by wolfcastle
I'm trying to understand some behavior I'm seeing in the context of sending UDP packets.
我试图了解我在发送 UDP 数据包的上下文中看到的一些行为。
I have two little Java programs: one that transmits UDP packets, and the other that receives them. I'm running them locally on my network between two computers that are connected via a single switch.
我有两个小 Java 程序:一个传输 UDP 数据包,另一个接收它们。我在通过单个交换机连接的两台计算机之间的网络上本地运行它们。
The MTU setting (reported by /sbin/ifconfig) is 1500 on both network adapters.
两个网络适配器上的 MTU 设置(由 /sbin/ifconfig 报告)都是 1500。
- If I send packets with a size < 1500, I receive them. Expected.
- If I send packets with 1500 < size < 24258 I receive them. Expected. I have confirmed via wireshark that the IP layer is fragmenting them.
- If I send packets with size > 24258, they are lost. Not Expected.When I run wireshark on the receiving side, I don't see any of these packets.
- 如果我发送大小小于 1500 的数据包,我会收到它们。预期的。
- 如果我发送 1500 < 大小 < 24258 的数据包,我会收到它们。预期的。我已经通过 Wireshark 确认 IP 层正在对它们进行分段。
- 如果我发送大小大于 24258 的数据包,它们就会丢失。不预期。当我在接收端运行wireshark 时,我看不到任何这些数据包。
I was able to see similar behavior with ping -s.
我能够看到与 ping -s 类似的行为。
ping -s 24258 hostA
works but
ping -s 24258 hostA
有效但
ping -s 24259 hostA
fails.
ping -s 24259 hostA
失败。
Does anyone understand what may be happening, or have ideas of what I should be looking for?
有没有人了解可能会发生什么,或者对我应该寻找什么有想法?
Both computers are running CentOS 5 64-bit. I'm using a 1.6 JDK, but I don't really think it's a programming problem, it's a networking or maybe OS problem.
两台计算机都运行 CentOS 5 64 位。我使用的是 1.6 JDK,但我真的不认为这是编程问题、网络问题或操作系统问题。
采纳答案by Dan Moulding
Implementations of the IP protocol are not required to be capable of handling arbitrarily large packets. In theory, the maximum possible IP packet size is 65,535 octets, but the standard only requires that implementations support at least 576 octets.
IP 协议的实现不需要能够处理任意大的数据包。理论上,最大可能的 IP 数据包大小为 65,535 个八位字节,但该标准仅要求实现支持至少 576 个八位字节。
It would appear that your host's implementation supports a maximum size much greater than 576, but still significantly smaller than the maximum theoretical size of 65,535. (I don't think the switch should be a problem, because it shouldn't need to do any defragmentation -- it's not even operating at the IP layer).
看起来您的主机实现支持的最大大小远大于 576,但仍显着小于 65,535 的最大理论大小。(我不认为交换机应该是一个问题,因为它不需要进行任何碎片整理——它甚至不在 IP 层运行)。
The IP standard further recommends that hosts not send packets larger than 576 bytes, unless they are certain that the receiving host can handle the larger packet size. You should maybe consider whether or not it would be better for your program to send a smaller packet size. 24,529 seems awfully large to me. I think there may be a possibility that a lot of hosts won't handle packets that large.
IP 标准进一步建议主机不要发送大于 576 字节的数据包,除非他们确定接收主机可以处理更大的数据包大小。您可能应该考虑发送较小的数据包是否对您的程序更好。24,529 对我来说似乎非常大。我认为可能有很多主机不会处理那么大的数据包。
Note that these packet size limits are entirely separate from MTU (the maximum frame size supported by the data link layer protocol).
请注意,这些数据包大小限制与 MTU(数据链路层协议支持的最大帧大小)完全分开。
回答by Kaleb Pederson
I found the following which may be of interest:
我发现以下内容可能会引起您的兴趣:
- Determine the maximum size of a UDP datagram packet on Linux
- Set the DF bit in the IP header and send continually larger packets to determine at what point a packet is fragmented as per Path MTU Discovery. Packet fragmentation should then result in a ICMP type 3 packet with code 4indicating that the packet was too large to be sent without being fragmented.
- 确定 Linux 上 UDP 数据报包的最大大小
- 设置 IP 标头中的 DF 位并不断发送更大的数据包,以确定数据包在哪个点根据路径 MTU 发现进行分段。然后,数据包分段应导致 ICMP 类型 3 数据包的代码为 4,表明数据包太大而无法在不分段的情况下发送。
Dan's answer is useful but note that after headers you're really limited to 65507 bytes.
Dan 的回答很有用,但请注意,在标题之后,您实际上仅限于 65507 字节。