aboutsummaryrefslogtreecommitdiffstats
path: root/gpxe/src/usr/dhcpmgmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'gpxe/src/usr/dhcpmgmt.c')
-rw-r--r--gpxe/src/usr/dhcpmgmt.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/gpxe/src/usr/dhcpmgmt.c b/gpxe/src/usr/dhcpmgmt.c
index 6acf7f6d..f82a3bb8 100644
--- a/gpxe/src/usr/dhcpmgmt.c
+++ b/gpxe/src/usr/dhcpmgmt.c
@@ -16,6 +16,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+FILE_LICENCE ( GPL2_OR_LATER );
+
#include <string.h>
#include <stdio.h>
#include <errno.h>
@@ -26,6 +28,8 @@
#include <usr/ifmgmt.h>
#include <usr/dhcpmgmt.h>
+#define LINK_WAIT_MS 15000
+
/** @file
*
* DHCP management
@@ -33,16 +37,31 @@
*/
int dhcp ( struct net_device *netdev ) {
+ uint8_t *chaddr;
+ uint8_t hlen;
+ uint16_t flags;
int rc;
/* Check we can open the interface first */
if ( ( rc = ifopen ( netdev ) ) != 0 )
return rc;
+ /* Wait for link-up */
+ if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 )
+ return rc;
+
/* Perform DHCP */
- printf ( "DHCP (%s %s)", netdev->name, netdev_hwaddr ( netdev ) );
- if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 )
+ chaddr = dhcp_chaddr ( netdev, &hlen, &flags );
+ printf ( "DHCP (%s ", netdev->name );
+ while ( hlen-- )
+ printf ( "%02x%c", *(chaddr++), ( hlen ? ':' : ')' ) );
+
+ if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 ) {
rc = monojob_wait ( "" );
+ } else if ( rc > 0 ) {
+ printf ( " using cached\n" );
+ rc = 0;
+ }
return rc;
}