From 3961c1ca02ad3c8ce1dbc725eb07411e1dbee1d8 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 20 May 2009 08:16:51 +0100 Subject: [PATCH] [dhcp] Send broadcast PXE boot server discovery requests to port 67 We currently send all boot server discovery requests to port 4011. Section 2.2.1 of the PXE spec states that boot server discovery packets should be "sent broadcast (port 67), multicast (port 4011), or unicast (port 4011)". Adjust our behaviour so that any boot server discovery packets that are sent to the broadcast address are directed to port 67 rather than port 4011. This is required for operation with dnsmasq as a PXE server, since dnsmasq listens only on port 67, and relies upon this (specified) behaviour. This change may break some setups using the (itself very broken) Linux PXE server from kano.org.uk. This server will, in its default configuration, listen only on port 4011. It never constructs a boot server list (PXE_BOOT_SERVERS, option 43.8), and uses the wrong definitions for the discovery control bits (PXE_DISCOVERY_CONTROL, option 43.6). The upshot is that it will always instruct the client to perform multicast and broadcast discovery only. In setups lacking a valid multicast route on the server side, this used to work because gPXE would eventually give up on the (non-responsive) multicast address and send a broadcast request to port 4011, which the Linux PXE server would respond to. Now that gPXE correctly sends this broadcast request to port 67 instead, it is never seen by the Linux PXE server, and the boot fails. The fix is to either (a) set up a multicast route correctly on the server side before starting the PXE server, or (b) edit /etc/pxe.conf to contain the server's unicast address in the "multicast_address" field (a hack that happens to work). Suggested-by: Simon Kelley --- src/net/udp/dhcp.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/net/udp/dhcp.c b/src/net/udp/dhcp.c index 851b75e1..d44e38f6 100644 --- a/src/net/udp/dhcp.c +++ b/src/net/udp/dhcp.c @@ -670,8 +670,13 @@ static int dhcp_pxebs_tx ( struct dhcp_session *dhcp, struct dhcp_pxe_boot_menu_item menu_item = { 0, 0 }; int rc; + /* Set server address */ + peer->sin_addr = *(dhcp->pxe_attempt); + peer->sin_port = ( ( peer->sin_addr.s_addr == INADDR_BROADCAST ) ? + htons ( BOOTPS_PORT ) : htons ( PXE_PORT ) ); + DBGC ( dhcp, "DHCP %p PXEBS REQUEST to %s:%d for type %d\n", - dhcp, inet_ntoa ( *(dhcp->pxe_attempt) ), PXE_PORT, + dhcp, inet_ntoa ( peer->sin_addr ), ntohs ( peer->sin_port ), ntohs ( dhcp->pxe_type ) ); /* Set boot menu item */ @@ -680,10 +685,6 @@ static int dhcp_pxebs_tx ( struct dhcp_session *dhcp, &menu_item, sizeof ( menu_item ) ) ) != 0 ) return rc; - /* Set server address */ - peer->sin_addr = *(dhcp->pxe_attempt); - peer->sin_port = htons ( PXE_PORT ); - return 0; } @@ -743,7 +744,8 @@ static void dhcp_pxebs_rx ( struct dhcp_session *dhcp, DBGC ( dhcp, "\n" ); /* Filter out unacceptable responses */ - if ( peer->sin_port != htons ( PXE_PORT ) ) + if ( ( peer->sin_port != htons ( BOOTPS_PORT ) ) && + ( peer->sin_port != htons ( PXE_PORT ) ) ) return; if ( msgtype != DHCPACK ) return;