解惑:DHCP OFFER和ACK是单播还是广播?
问题:DHCP OFFER/ACK是单播还是广播?
目前有三种常见的观点:
1. 单播;
2. 广播;
3. 根据客户端发送的DHCP报文中的广播位(broadcast bit,或称为BOOTP flag)来确定。客户端DHCP报文中的广播位是0,服务器就以单播回复;反之广播位是1,服务器就以广播回复。
观点3通常被大家广泛接受,但其并非完全正确。
实际案例
案例1:
用wireshark对DHCP的抓包分析_wireshark dhcp-CSDN博客文章浏览阅读6.4k次,点赞57次,收藏102次。本文介绍了DHCP协议的概述、报文格式详解,以及如何通过Wireshark抓包工具观察DHCP的通信流程,包括DHCPDiscover、DHCPOffer、DHCPRequest和DHCPAck报文。DHCP通过动态分配IP地址,显著提高了网络管理效率。https://blog.csdn.net/ZZZCY2003/article/details/137230417在这篇文章中,作者抓包得到的DHCP OFFER/ACK都是单播。客户端发送的DHCP DISCOVER/REQUEST中的广播位为0,因此服务器以单播回复不难理解。
案例2:
笔者在某H3C路由器(V7版本软件)的网络中,抓包得到的DHCP OFFER/ACK都是广播。
观察客户端发送的DHCP DISCOVER报文,其广播位同样为0。
协议分析
在前述两个案例中,客户端发送的报文广播位都是0,但为何服务器却分别以单播和广播两种方式进行回复?是否有一个案例中的网络设备对DHCP的实现有错误?
通过查阅RFC,可以得到答案。
RFC 2131: Dynamic Host Configuration Protocol https://www.rfc-editor.org/rfc/rfc2131RFC 1542: Clarifications and Extensions for the Bootstrap Protocol https://www.rfc-editor.org/rfc/rfc1542
RFC 2131 - 4.1
A client that cannot receive unicast IP datagrams until its protocol
software has been configured with an IP address SHOULD set the
BROADCAST bit in the 'flags' field to 1 in any DHCPDISCOVER or
DHCPREQUEST messages that client sends. The BROADCAST bit will
provide a hint to the DHCP server and BOOTP relay agent to broadcast
any messages to the client on the client's subnet. A client that can
receive unicast IP datagrams before its protocol software has been
configured SHOULD clear the BROADCAST bit to 0. The BOOTP
clarifications document discusses the ramifications of the use of the
BROADCAST bit [21].A server or relay agent sending or relaying a DHCP message directly
to a DHCP client (i.e., not to a relay agent specified in the
'giaddr' field) SHOULD examine the BROADCAST bit in the 'flags'
field. If this bit is set to 1, the DHCP message SHOULD be sent as
an IP broadcast using an IP broadcast address (preferably 0xffffffff)
as the IP destination address and the link-layer broadcast address as
the link-layer destination address. If the BROADCAST bit is cleared
to 0, the message SHOULD be sent as an IP unicast to the IP address
specified in the 'yiaddr' field and the link-layer address specified
in the 'chaddr' field. If unicasting is not possible, the message
MAY be sent as an IP broadcast using an IP broadcast address
(preferably 0xffffffff) as the IP destination address and the link-
layer broadcast address as the link-layer destination address.[21] Wimer, W., "Clarifications and Extensions for the Bootstrap
Protocol", RFC 1542, Carnegie Mellon University, October 1993.
(以下是笔者翻译的中文译本,不必咬文嚼字,意思对即可)
若客户端在其协议软件被配置IP地址之前都无法接收单播IP数据报,则宜(SHOULD)将客户端发送的任意DHCPDISCOVER或DHCPREQUEST消息中的广播位置1。广播位将向DHCP服务器和BOOTP中继代理做出提示,以便在客户端的网络中将任意消息广播给客户端。若客户端在其协议软件被配置以先即可接收单播IP数据报,则宜(SHOULD)将广播位清空为0。BOOTP说明文档讨论了使用广播位的后果[21]。
服务器或中继代理在发送或中继直达DHCP客户端的DHCP消息时(而不是发给“giaddr”字段中指定的中继代理),宜(SHOULD)考虑“flags”字段中的广播位。如果广播位被置为1,DHCP消息宜(SHOULD)作为IP广播发送,使用IP广播地址(首选是0xffffffff)作为IP目的地址,并使用链路层广播地址作为链路层目的地址。如果广播位被清空为0,消息宜(SHOULD)作为IP单播发送至“yiaddr”字段中指定的IP地址,以及“chaddr”字段中的链路层地址。如果无法使用单播,消息可(MAY)作为IP广播发送,使用IP广播地址(首选0xffffffff)作为IP目的地址,并使用链路层广播地址作为链路层目的地址。
RFC 1542 - 5.4
If the 'giaddr' field is set to 0.0.0.0, then the client resides on
one of the same networks as the BOOTP server. The server SHOULD
examine the newly-defined BROADCAST flag (see Sections 2.2, 3.1.1 and
4.1.2 for more information). If this flag is set to 1 or the server
has prior knowledge that the client is unable to receive unicast
BOOTREPLY messages, the reply SHOULD be sent as an IP broadcast using
the IP limited broadcast address 255.255.255.255 as the IP
destination address and the link-layer broadcast address as the
link-layer destination address. If the BROADCAST flag is cleared
(0), the reply SHOULD be sent as an IP unicast to the IP address
specified by the 'yiaddr' field and the link-layer address specified
in the 'chaddr' field. If unicasting is not possible, the reply MAY
be sent as a broadcast in which case it SHOULD be sent to the link-
layer broadcast address using the IP limited broadcast address
255.255.255.255 as the IP destination address. In any case, the UDP
destination port MUST be set to BOOTPC (68).
(以下是笔者翻译的中文译本,不必咬文嚼字,意思对即可)
如果“giaddr”字段设为0.0.0.0,则客户端与BOOTP服务器在同一网络中。服务器宜(SHOULD)考虑新定义的广播标志。如果该标志被设为1,或服务器拥有关于客户端无法接收单播BOOTPREPLY消息的先验知识(prior knowledge),回复宜(SHOULD)作为IP广播发送,使用IP受限广播地址255.255.255.255作为目的地址,使用链路层广播地址作为链路层目的地址。如果广播标志被清空(0),回复宜(SHOULD)作为IP单播发送至“yiaddr”字段指定的IP地址,以及“chaddr”字段指定的链路层地址。如果不能使用单播,回复可(MAY)作为广播发送,在这种情况下,宜(SHOULD)使用IP受限广播地址255.255.255.255作为IP目的地址,将其发送至链路层广播地址。任何情况下,UDP目的端口都应(MUST)设为BOOTPC(68)。
文件中的MUST、SHOULD、MAY,可对应我国标准化文件中的“应”、“宜”、“可”,按强度不同依次表示:强制,不得有偏差;推荐,但不作强制性要求;可以,但通常不建议如此。
从以上两个RFC文件中可以看出:
1. 广播位的使用在RFC 2131中属于推荐项目而非强制要求。实践中,服务器发送的DHCP OFFER报文(广播形式),广播位为0或1,对客户端都没有影响;
2. 即使客户端在DHCP DISCOVER/REQUEST报文中将广播位设为0,服务器仍然允许使用广播进行回复(尽管RFC并不建议,但这种行为并不违反RFC)。
总结
DHCP OFFER/ACK报文是单播还是广播,受多个因素影响。既要看客户端发送的DHCP报文中广播位的设置,又要看DHCP服务器的具体实现。
原文地址:https://blog.csdn.net/robur/article/details/145139366
免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!