*/
#include <string.h>
+#include <stdio.h>
#include <byteswap.h>
-#include <vsprintf.h>
#include <gpxe/in.h>
+#include <gpxe/ip.h>
#include <gpxe/dhcp.h>
#include <gpxe/async.h>
#include <gpxe/netdevice.h>
+#include <gpxe/dns.h>
+#include <usr/ifmgmt.h>
#include <usr/dhcpmgmt.h>
/** @file
*
*/
+/* Avoid dragging in dns.o */
+struct in_addr nameserver;
+
/**
* Configure network device via DHCP
*
int dhcp ( struct net_device *netdev ) {
static struct dhcp_option_block *dhcp_options = NULL;
struct dhcp_session dhcp;
- struct in_addr address = { htonl ( 0 ) };
- struct in_addr netmask = { htonl ( 0 ) };
+ struct in_addr address = { 0 };
+ struct in_addr netmask = { 0 };
struct in_addr gateway = { INADDR_NONE };
+ struct async async;
int rc;
+ /* Check we can open the interface first */
+ if ( ( rc = ifopen ( netdev ) ) != 0 )
+ return rc;
+
/* Free up any previously-acquired options */
if ( dhcp_options ) {
unregister_dhcp_options ( dhcp_options );
dhcp_options = NULL;
}
+ /* Clear any existing routing table entry */
+ del_ipv4_address ( netdev );
+
/* Issue DHCP request */
printf ( "DHCP (%s %s)...", netdev->name, netdev_hwaddr ( netdev ) );
memset ( &dhcp, 0, sizeof ( dhcp ) );
dhcp.netdev = netdev;
- if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 ) {
- printf ( "failed\n" );
+ if ( ( rc = async_block ( &async,
+ start_dhcp ( &dhcp, &async ) ) ) != 0 ) {
+ printf ( "failed (%s)\n", strerror ( rc ) );
return rc;
}
printf ( "done\n" );
return rc;
}
+ /* Retrieve other DHCP options that we care about */
+ find_dhcp_ipv4_option ( dhcp_options, DHCP_DNS_SERVERS,
+ &nameserver );
+
return 0;
}