我正在研究网络,我有一个关于 ARP 表应该何时更新的问题。
考虑这种情况:
主机 A 在其 ARP 表中具有主机 B 的 MAC 地址。
主机 B 的 ARP 表为空。
主机 A 向主机 B 发送一条消息。在封装该消息的链路层帧中,有关于主机 A 的 MAC 地址的信息。
我的问题是,当主机 B 收到消息时,它是否会自动更新 ARP 表以获取主机 A 的 MAC 地址,或者它是否必须在下次与主机 A 通信时发送 ARP 广播才能找到主机 A ?
我正在研究网络,我有一个关于 ARP 表应该何时更新的问题。
考虑这种情况:
主机 A 在其 ARP 表中具有主机 B 的 MAC 地址。
主机 B 的 ARP 表为空。
主机 A 向主机 B 发送一条消息。在封装该消息的链路层帧中,有关于主机 A 的 MAC 地址的信息。
我的问题是,当主机 B 收到消息时,它是否会自动更新 ARP 表以获取主机 A 的 MAC 地址,或者它是否必须在下次与主机 A 通信时发送 ARP 广播才能找到主机 A ?
我的问题是,当主机 B 收到消息时,它是否会自动更新 ARP 表以获取主机 A 的 MAC 地址,或者下次它想与主机 A 通信时是否必须发送 ARP 广播来查找主机 A ?
只有 ARP 消息会更新 ARP 表。
ARP 是一个进程,就像 IPv4 是一个进程一样。以太网有一个EtherType字段(其他使用 MAC 寻址的 IEEE 协议也有类似的东西)。该字段告诉以太网应该将帧的有效负载发送到哪个进程。
当 EtherType 为0x0800时,帧载荷发送到 IPv4,因为它是 IPv4 数据包;当 EtherType 为 时0x86dd,将帧载荷发送到 IPv6,因为它是 IPv6 数据包;当 EtherType 是0x0806帧有效负载时,因为它是一个 ARP 数据包,所以将其发送到 ARP。如您所见,ARP 永远不会看到除 ARP 数据包之外的任何数据包。
这似乎是一个弱点,但这是设计使然。以太网由于各种原因有很多广播,主机必须处理所有这些广播以查看广播是否与它相关。许多广播是针对 ARP 的,但其他广播是出于其他原因,并且您将在 ARP 表中为您的主机没有兴趣与之通信的主机添加条目。即使一个主机看到一个不是发往它的 ARP 广播,也会首先检查源主机是否在它的 ARP 表中。如果是,则更新 ARP 表,如果不是,则忽略它。这在今天可能看起来没什么大不了的,但是当主机(甚至被认为是大型主机)只有最小的 RAM 时,这是一个非常大的问题。ARP 是在 1982 年定义的,当时 IBM PC(1981 年发布)仍然带有 64K 的 RAM。
ARP 在RFC 826, An Ethernet Address Resolution Protocol中有详细说明,它具有如何处理接收到的 ARP 数据包的伪代码:
否定条件表示处理结束并丢弃数据包。
?Do I have the hardware type in ar$hrd? Yes: (almost definitely) [optionally check the hardware length ar$hln] ?Do I speak the protocol in ar$pro? Yes: [optionally check the protocol length ar$pln] Merge_flag := false If the pair <protocol type, sender protocol address> is already in my translation table, update the sender hardware address field of the entry with the new information in the packet and set Merge_flag to true. ?Am I the target protocol address? Yes: If Merge_flag is false, add the triplet <protocol type, sender protocol address, sender hardware address> to the translation table. ?Is the opcode ares_op$REQUEST? (NOW look at the opcode!!) Yes: Swap hardware and protocol fields, putting the local hardware and protocol addresses in the sender fields. Set the ar$op field to ares_op$REPLY Send the packet to the (new) target hardware address on the same hardware on which the request was received.