22

为什么要在 UDP 数据报中添加伪标头以计算 UDP 校验和?这背后的原因是什么?

4

5 回答 5

26

最接近您将获得“直接从马嘴里”的答案来自以下链接的 David P. Reed。

http://www.postel.org/pipermail/end2end-interest/2005-February/004616.html

答案的简短版本是“伪标头由于历史原因而存在”。

最初,TCP/IP 是一个单一的整体协议(仅称为 TCP)。当他们决定将其拆分为 TCP 和 IP(以及其他)时,他们并没有将两者完全分开:IP 地址仍然被认为是 TCP 的一部分,但它们只是从 IP 层“继承”而来而不是在 TCP 标头中重复。TCP 校验和对部分 IP 标头(包括 IP 地址)进行操作的原因是因为他们打算使用密码学来加密和验证 TCP 有效负载,并且他们希望伪标头中的 IP 地址和其他 TCP 参数是受验证码保护。这将使中间人无法篡改 IP 源地址和目标地址:中间路由器不会注意到篡改,

由于种种原因,那个宏大的加密计划都没有实现,但取代它的 TCP 校验和仍然在伪标头上运行,就好像这是一件有用的事情。是的,它为您提供了一些针对随机错误的额外保护,但这不是它存在的原因。坦率地说,没有它我们会更好:TCP和IP之间的耦合意味着你必须在更改IP时重新定义TCP。因此,IPv6 的定义包括 TCP 和 UDP 伪报头的新定义(参见 RFC 2460,s8.1)。为什么 IPv6 设计者选择延续这种耦合而不是借此机会废除它,我无法理解。

于 2010-05-15T13:30:13.090 回答
20

从 TCP 或 UDP 的角度来看,数据包不包含 IP 地址。(IP 是它们下面的层。)

因此,为了进行正确的校验和,需要包含一个“伪标头”。它是“伪”的,因为它实际上不是 UDP 数据报的一部分。它包含IP头中最重要的部分,即源地址和目的地址、协议号和数据长度。

这是为了确保 UDP 校验和考虑这些字段。

于 2008-12-11T11:43:27.130 回答
10

"The purpose of using a pseudo-header is to verify that the UDP datagram has reached its correct destination. The key to understanding the pseudo-header lies in realizing that the correct destination consists of a specific machine and a specific protocol port within that machine. The UDP header itself specifies only the protocol port number. Thus, to verify the destination, UDP on the sending machine computes a checksum that covers the destination IP address as well as the UDP datagram. The pseudo-header is not transmitted with the UDP datagram, nor is it included in the length."

E. Comer - Internetworking with TCP/IP 4th edition.

于 2014-02-09T12:04:29.437 回答
9

在设计这些协议时,他们的一个严重问题是主机接收到的数据包认为它是他们的,但实际上不是。如果在传输过程中 IP 报头中的一些位被翻转并且数据包改变了路线(但 IP 校验和仍然正确),重定向接收器的 TCP/UDP 堆栈仍然可以知道拒绝数据包。

尽管伪标题打破了层分离习惯,但它被认为可以提高可靠性。

于 2009-02-27T17:01:45.847 回答
0

Pseudo IP header contains the source IP, destination IP, protocol and Total length fields. Now, by including these fields in TCP checksum, we are verifying the checksum for these fields both at Network layer and Transport layer, thus doing a double check to ensure that the data is delivered to the correct host.

于 2020-01-29T02:53:12.933 回答