Browse Source

[dhcp] Request broadcast responses when we already have an IPv4 address

FCoE requires the use of multiple local unicast link-layer addresses.
To avoid the complexity of managing multiple addresses, iPXE operates
in promiscuous mode.  As a consequence, any unicast packets with
non-matching IPv4 addresses are rejected at the IPv4 layer (rather
than at the link layer).

This can cause problems when issuing a second DHCP request: if the
address chosen by the DHCP server does not match the existing address,
then the DHCP response will itself be rejected.

Fix by requesting a broadcast response from the DHCP server if the
network interface already has any IPv4 addresses.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
c0942408b7
3 changed files with 10 additions and 1 deletions
  1. 2
    0
      src/include/ipxe/ip.h
  2. 1
    1
      src/net/ipv4.c
  3. 7
    0
      src/net/udp/dhcp.c

+ 2
- 0
src/include/ipxe/ip.h View File

@@ -86,4 +86,6 @@ extern struct list_head ipv4_miniroutes;
86 86
 
87 87
 extern struct net_protocol ipv4_protocol __net_protocol;
88 88
 
89
+extern int ipv4_has_any_addr ( struct net_device *netdev );
90
+
89 91
 #endif /* _IPXE_IP_H */

+ 1
- 1
src/net/ipv4.c View File

@@ -408,7 +408,7 @@ static int ipv4_tx ( struct io_buffer *iobuf,
408 408
  * @v netdev		Network device
409 409
  * @ret has_any_addr	Network device has any IPv4 address
410 410
  */
411
-static int ipv4_has_any_addr ( struct net_device *netdev ) {
411
+int ipv4_has_any_addr ( struct net_device *netdev ) {
412 412
 	struct ipv4_miniroute *miniroute;
413 413
 
414 414
 	list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {

+ 7
- 0
src/net/udp/dhcp.c View File

@@ -941,6 +941,13 @@ int dhcp_create_packet ( struct dhcp_packet *dhcppkt,
941 941
 				      &dhcphdr->flags );
942 942
 	memcpy ( dhcphdr->options, options, options_len );
943 943
 
944
+	/* If the network device already has an IPv4 address then
945
+	 * unicast responses from the DHCP server may be rejected, so
946
+	 * request broadcast responses.
947
+	 */
948
+	if ( ipv4_has_any_addr ( netdev ) )
949
+		dhcphdr->flags |= htons ( BOOTP_FL_BROADCAST );
950
+
944 951
 	/* Initialise DHCP packet structure */
945 952
 	memset ( dhcppkt, 0, sizeof ( *dhcppkt ) );
946 953
 	dhcppkt_init ( dhcppkt, data, max_len );

Loading…
Cancel
Save