有关DHCP服务器 offer ack 包单播广播问题

来源:互联网 发布:买家淘宝怎么刷信誉 编辑:程序博客网 时间:2024/05/16 05:41

     通常情况下,都会说DHCP Server 这端的offer包和ack包是广播出去的,但是这个在具体情况下是怎么样的呢,通过rfc2131可以知道,这个其实是和client端的broadcast bit位的设置是有关系的,其中有这样一段描述:

 

   If the 'giaddr' field in a DHCP message from a client is non-zero,the server sends any return messages to the 'DHCP server' port on the BOOTP relay agent whose address appears in 'giaddr'. If the 'giaddr' field is zero and the 'ciaddr' field is nonzero, then the server unicasts DHCPOFFER and DHCPACK messages to the address in 'ciaddr'.If 'giaddr' is zero and 'ciaddr' is zero, and the broadcast bit is set, then the server broadcasts DHCPOFFER and DHCPACK messages to 0xffffffff. If the broadcast bit is not set and 'giaddr' is zero and 'ciaddr' is zero, then the server unicasts DHCPOFFER and DHCPACK messages to the client's hardware address and 'yiaddr' address.  In all cases, when 'giaddr' is zero, the server broadcasts any DHCPNAK messages to 0xffffffff.

 

   首先说明一下这个giaddr域,rfc中给的描述是Relay agent IP address, used in booting via a relay agent.也就是中继的地址,一般在有中继的情况下都是单播的,目的地址就是该中继的地址。

 

   那么在没有中继的情况下,首先看ciaddr域是否为零,如果不为零,就是单播,目的地址就是该ciaddr域中的地址;如果ciaddr域为零,再看其是否设置了broadcast bit位,如果设置了,就全F地址广播,如果没有设置,就是单播,目的地址是该client的硬件地址(L2)和yiaddr域中的地址(L3)。broadcast bit位是由client端决定的。

 

   The leftmost bit is defined as the BROADCAST (B) flag.  The semantics of this flag are discussed in section 4.1 of this document(就是上面的那一段描述). The remaining bits of the flags field are reserved for future use.  They MUST be set to zero by clients and ignored by servers and relay agents.

 

                0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
                |B|             MBZ             |
                +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

                B:  BROADCAST flag

                MBZ:  MUST BE ZERO (reserved for future use)

                Figure 2:  Format of the 'flags' field

 

Server端行为

Field      DHCPOFFER            DHCPACK             DHCPNAK
-----      ---------            -------             -------
'ciaddr'   0                    'ciaddr' from       0
                                DHCPREQUEST or 0
'yiaddr'   IP address offered   IP address          0
           to client            assigned to client
'siaddr'   IP address of next   IP address of next  0
           bootstrap server     bootstrap server
'flags'    'flags' from         'flags' from        'flags' from
           client DHCPDISCOVER  client DHCPREQUEST  client DHCPREQUEST
           message              message             message
'giaddr'   'giaddr' from        'giaddr' from       'giaddr' from
           client DHCPDISCOVER  client DHCPREQUEST  client DHCPREQUEST
           message              message             message
'chaddr'   'chaddr' from        'chaddr' from       'chaddr' from
           client DHCPDISCOVER  client DHCPREQUEST  client DHCPREQUEST
           message              message             message

 

 

Client端行为 

Field      DHCPDISCOVER          DHCPREQUEST           DHCPDECLINE,
           DHCPINFORM                                  DHCPRELEASE
-----      ------------          -----------           -----------
'flags'    Set 'BROADCAST'       Set 'BROADCAST'       0
           flag if client        flag if client
           requires broadcast    requires broadcast
           reply                 reply
'ciaddr'   0 (DHCPDISCOVER)      0 or client's         0 (DHCPDECLINE)
           client's              network address       client's network
           network address       (BOUND/RENEW/REBIND)  address
           (DHCPINFORM)                                (DHCPRELEASE)
'yiaddr'   0                     0                     0
'siaddr'   0                     0                     0
'giaddr'   0                     0                     0
'chaddr'   client's hardware     client's hardware     client's hardware
           address               address               address

 

 

   我在某论坛上看到过一个帖子,记录了这样一个实验结果:

 

用unix做dhcp服务器,用win客户端获取得到的结果:(第2层信息)
dhcp discover(目的mac是广播)
dhcp offer(目的mac是单播,指向客户端mac)
dhcp request(目的mac是广播)
dhcp reply(目的mac是单播,指向客户端mac)

如果用win做dhcp服务器,客户端也是win:(第2层信息)
dhcp discover(目的mac是广播)
dhcp offer(目的mac是广播)
dhcp request(目的mac是广播)
dhcp reply(目的mac是广播)

 

这是一个很不可思议的结果,照说如果是相同的客户端,其broadcast bit位的设置应该是相同的,和server应该是没关系的,按照协议,server应该不会自行改掉broadcast bit位的--只有可能是两次实验的客户端不同,确切的说是客户端broadcast bit位的设置不同,而和特定的操作系统是没有关系的。

 

原创粉丝点击