mirror of https://github.com/ipxe/ipxe.git
Added some debug messages and DHCP test code
parent
317b962b65
commit
6d9d48537e
|
@ -433,4 +433,6 @@ extern unsigned long find_global_dhcp_num_option ( unsigned int tag );
|
||||||
extern void delete_dhcp_option ( struct dhcp_option_block *options,
|
extern void delete_dhcp_option ( struct dhcp_option_block *options,
|
||||||
unsigned int tag );
|
unsigned int tag );
|
||||||
|
|
||||||
|
extern struct async_operation * start_dhcp ( struct dhcp_session *dhcp );
|
||||||
|
|
||||||
#endif /* _GPXE_DHCP_H */
|
#endif /* _GPXE_DHCP_H */
|
||||||
|
|
|
@ -58,6 +58,26 @@ static uint8_t dhcp_request_options_data[] = {
|
||||||
DHCP_END
|
DHCP_END
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name a DHCP packet type
|
||||||
|
*
|
||||||
|
* @v msgtype DHCP message type
|
||||||
|
* @ret string DHCP mesasge type name
|
||||||
|
*/
|
||||||
|
static inline const char * dhcp_message_type_name ( unsigned int msgtype ) {
|
||||||
|
switch ( msgtype ) {
|
||||||
|
case DHCPDISCOVER: return "DHCPDISCOVER";
|
||||||
|
case DHCPOFFER: return "DHCPOFFER";
|
||||||
|
case DHCPREQUEST: return "DHCPREQUEST";
|
||||||
|
case DHCPDECLINE: return "DHCPDECLINE";
|
||||||
|
case DHCPACK: return "DHCPACK";
|
||||||
|
case DHCPNAK: return "DHCPNAK";
|
||||||
|
case DHCPRELEASE: return "DHCPRELEASE";
|
||||||
|
case DHCPINFORM: return "DHCPINFORM";
|
||||||
|
default: return "DHCP<invalid>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Options common to all DHCP requests */
|
/** Options common to all DHCP requests */
|
||||||
static struct dhcp_option_block dhcp_request_options = {
|
static struct dhcp_option_block dhcp_request_options = {
|
||||||
.data = dhcp_request_options_data,
|
.data = dhcp_request_options_data,
|
||||||
|
@ -419,6 +439,8 @@ static void dhcp_senddata ( struct udp_connection *conn,
|
||||||
struct dhcp_packet dhcppkt;
|
struct dhcp_packet dhcppkt;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
DBG ( "Transmitting %s\n", dhcp_message_type_name ( dhcp->state ) );
|
||||||
|
|
||||||
assert ( ( dhcp->state == DHCPDISCOVER ) ||
|
assert ( ( dhcp->state == DHCPDISCOVER ) ||
|
||||||
( dhcp->state == DHCPREQUEST ) );
|
( dhcp->state == DHCPREQUEST ) );
|
||||||
|
|
||||||
|
@ -455,7 +477,7 @@ static void dhcp_newdata ( struct udp_connection *conn,
|
||||||
|
|
||||||
/* Check for matching transaction ID */
|
/* Check for matching transaction ID */
|
||||||
if ( dhcphdr->xid != dhcp->xid ) {
|
if ( dhcphdr->xid != dhcp->xid ) {
|
||||||
DBG ( "DHCP wrong transaction ID (wanted %08x, got %08x)\n",
|
DBG ( "DHCP wrong transaction ID (wanted %08lx, got %08lx)\n",
|
||||||
ntohl ( dhcphdr->xid ), ntohl ( dhcp->xid ) );
|
ntohl ( dhcphdr->xid ), ntohl ( dhcp->xid ) );
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -467,6 +489,10 @@ static void dhcp_newdata ( struct udp_connection *conn,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DBG ( "Received %s\n",
|
||||||
|
dhcp_message_type_name ( find_dhcp_num_option ( options,
|
||||||
|
DHCP_MESSAGE_TYPE ) ) );
|
||||||
|
|
||||||
/* Proof of concept: just dump out the parsed options */
|
/* Proof of concept: just dump out the parsed options */
|
||||||
hex_dump ( options->data, options->len );
|
hex_dump ( options->data, options->len );
|
||||||
free_dhcp_options ( options );
|
free_dhcp_options ( options );
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#include <string.h>
|
||||||
|
#include <gpxe/dhcp.h>
|
||||||
|
|
||||||
|
int test_dhcp ( struct net_device *netdev ) {
|
||||||
|
struct dhcp_session dhcp;
|
||||||
|
|
||||||
|
memset ( &dhcp, 0, sizeof ( dhcp ) );
|
||||||
|
dhcp.netdev = netdev;
|
||||||
|
return async_wait ( start_dhcp ( &dhcp ) );
|
||||||
|
}
|
Loading…
Reference in New Issue