Sfoglia il codice sorgente

[dhcp] Accept BOOTP as well as DHCP

tags/v0.9.4
Michael Brown 15 anni fa
parent
commit
aa8d972581
2 ha cambiato i file con 10 aggiunte e 7 eliminazioni
  1. 1
    0
      src/include/gpxe/dhcp.h
  2. 9
    7
      src/net/udp/dhcp.c

+ 1
- 0
src/include/gpxe/dhcp.h Vedi File

102
 
102
 
103
 /** DHCP message type */
103
 /** DHCP message type */
104
 #define DHCP_MESSAGE_TYPE 53
104
 #define DHCP_MESSAGE_TYPE 53
105
+#define DHCPNONE 0
105
 #define DHCPDISCOVER 1
106
 #define DHCPDISCOVER 1
106
 #define DHCPOFFER 2
107
 #define DHCPOFFER 2
107
 #define DHCPREQUEST 3
108
 #define DHCPREQUEST 3

+ 9
- 7
src/net/udp/dhcp.c Vedi File

65
 
65
 
66
 /** Raw option data for options common to all DHCP requests */
66
 /** Raw option data for options common to all DHCP requests */
67
 static uint8_t dhcp_request_options_data[] = {
67
 static uint8_t dhcp_request_options_data[] = {
68
-	DHCP_MAX_MESSAGE_SIZE, DHCP_WORD ( ETH_MAX_MTU ),
68
+	DHCP_MAX_MESSAGE_SIZE,
69
+	DHCP_WORD ( ETH_MAX_MTU - 20 /* IP header */ - 8 /* UDP header */ ),
69
 	DHCP_CLIENT_ARCHITECTURE, DHCP_WORD ( 0 ),
70
 	DHCP_CLIENT_ARCHITECTURE, DHCP_WORD ( 0 ),
70
 	DHCP_CLIENT_NDI, DHCP_OPTION ( 1 /* UNDI */ , 2, 1 /* v2.1 */ ),
71
 	DHCP_CLIENT_NDI, DHCP_OPTION ( 1 /* UNDI */ , 2, 1 /* v2.1 */ ),
71
 	DHCP_VENDOR_CLASS_ID,
72
 	DHCP_VENDOR_CLASS_ID,
128
  */
129
  */
129
 static inline const char * dhcp_msgtype_name ( unsigned int msgtype ) {
130
 static inline const char * dhcp_msgtype_name ( unsigned int msgtype ) {
130
 	switch ( msgtype ) {
131
 	switch ( msgtype ) {
131
-	case 0:			return "BOOTP"; /* Non-DHCP packet */
132
+	case DHCPNONE:		return "BOOTP"; /* Non-DHCP packet */
132
 	case DHCPDISCOVER:	return "DHCPDISCOVER";
133
 	case DHCPDISCOVER:	return "DHCPDISCOVER";
133
 	case DHCPOFFER:		return "DHCPOFFER";
134
 	case DHCPOFFER:		return "DHCPOFFER";
134
 	case DHCPREQUEST:	return "DHCPREQUEST";
135
 	case DHCPREQUEST:	return "DHCPREQUEST";
685
  */
686
  */
686
 static void dhcp_rx_dhcpoffer ( struct dhcp_session *dhcp,
687
 static void dhcp_rx_dhcpoffer ( struct dhcp_session *dhcp,
687
 				struct dhcp_settings *dhcpoffer ) {
688
 				struct dhcp_settings *dhcpoffer ) {
688
-	struct in_addr server_id;
689
+	struct in_addr server_id = { 0 };
689
 	char vci[9]; /* "PXEClient" */
690
 	char vci[9]; /* "PXEClient" */
690
 	int len;
691
 	int len;
691
 	uint8_t ignore_proxy = 0;
692
 	uint8_t ignore_proxy = 0;
697
 	     != sizeof ( server_id ) ) {
698
 	     != sizeof ( server_id ) ) {
698
 		DBGC ( dhcp, "DHCP %p received DHCPOFFER %p missing server "
699
 		DBGC ( dhcp, "DHCP %p received DHCPOFFER %p missing server "
699
 		       "identifier\n", dhcp, dhcpoffer );
700
 		       "identifier\n", dhcp, dhcpoffer );
700
-		return;
701
+		/* Could be a valid BOOTP offer; do not abort processing */
701
 	}
702
 	}
702
 
703
 
703
 	/* If there is an IP address, it's a normal DHCPOFFER */
704
 	/* If there is an IP address, it's a normal DHCPOFFER */
714
 	 */
715
 	 */
715
 	len = dhcppkt_fetch ( &dhcpoffer->dhcppkt, DHCP_VENDOR_CLASS_ID,
716
 	len = dhcppkt_fetch ( &dhcpoffer->dhcppkt, DHCP_VENDOR_CLASS_ID,
716
 			      vci, sizeof ( vci ) );
717
 			      vci, sizeof ( vci ) );
717
-	if ( ( len >= ( int ) sizeof ( vci ) ) &&
718
+	if ( ( server_id.s_addr != 0 ) &&
719
+	     ( len >= ( int ) sizeof ( vci ) ) &&
718
 	     ( strncmp ( "PXEClient", vci, sizeof ( vci ) ) == 0 ) ) {
720
 	     ( strncmp ( "PXEClient", vci, sizeof ( vci ) ) == 0 ) ) {
719
 		DBGC ( dhcp, "DHCP %p received DHCPOFFER %p from %s is a "
721
 		DBGC ( dhcp, "DHCP %p received DHCPOFFER %p from %s is a "
720
 		       "ProxyDHCPOFFER\n",
722
 		       "ProxyDHCPOFFER\n",
924
 	/* Handle packet based on current state */
926
 	/* Handle packet based on current state */
925
 	switch ( dhcp->state ) {
927
 	switch ( dhcp->state ) {
926
 	case DHCP_STATE_DISCOVER:
928
 	case DHCP_STATE_DISCOVER:
927
-		if ( ( msgtype == DHCPOFFER ) &&
929
+		if ( ( ( msgtype == DHCPOFFER ) || ( msgtype == DHCPNONE ) ) &&
928
 		     ( src_port == htons ( BOOTPS_PORT ) ) )
930
 		     ( src_port == htons ( BOOTPS_PORT ) ) )
929
 			dhcp_rx_dhcpoffer ( dhcp, dhcpset );
931
 			dhcp_rx_dhcpoffer ( dhcp, dhcpset );
930
 		break;
932
 		break;
931
 	case DHCP_STATE_REQUEST:
933
 	case DHCP_STATE_REQUEST:
932
-		if ( ( msgtype == DHCPACK ) &&
934
+		if ( ( ( msgtype == DHCPACK ) || ( msgtype == DHCPNONE ) ) &&
933
 		     ( src_port == htons ( BOOTPS_PORT ) ) )
935
 		     ( src_port == htons ( BOOTPS_PORT ) ) )
934
 			dhcp_rx_dhcpack ( dhcp, dhcpset );
936
 			dhcp_rx_dhcpack ( dhcp, dhcpset );
935
 		break;
937
 		break;

Loading…
Annulla
Salva