dhcpmgmt.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <string.h>
00022 #include <stdio.h>
00023 #include <errno.h>
00024 #include <gpxe/netdevice.h>
00025 #include <gpxe/dhcp.h>
00026 #include <gpxe/monojob.h>
00027 #include <gpxe/process.h>
00028 #include <usr/ifmgmt.h>
00029 #include <usr/dhcpmgmt.h>
00030
00031 #define LINK_WAIT_MS 15000
00032
00033
00034
00035
00036
00037
00038
00039 int dhcp ( struct net_device *netdev ) {
00040 uint8_t *chaddr;
00041 uint8_t hlen;
00042 uint16_t flags;
00043 int rc;
00044
00045
00046 if ( ( rc = ifopen ( netdev ) ) != 0 )
00047 return rc;
00048
00049
00050 if ( ( rc = iflinkwait ( netdev, LINK_WAIT_MS ) ) != 0 )
00051 return rc;
00052
00053
00054 chaddr = dhcp_chaddr ( netdev, &hlen, &flags );
00055 printf ( "DHCP (%s ", netdev->name );
00056 while ( hlen-- )
00057 printf ( "%02x%c", *(chaddr++), ( hlen ? ':' : ')' ) );
00058
00059 if ( ( rc = start_dhcp ( &monojob, netdev ) ) == 0 ) {
00060 rc = monojob_wait ( "" );
00061 } else if ( rc > 0 ) {
00062 printf ( " using cached\n" );
00063 rc = 0;
00064 }
00065
00066 return rc;
00067 }
00068
00069 int pxebs ( struct net_device *netdev, unsigned int pxe_type ) {
00070 int rc;
00071
00072
00073 printf ( "PXEBS (%s type %d)", netdev->name, pxe_type );
00074 if ( ( rc = start_pxebs ( &monojob, netdev, pxe_type ) ) == 0 )
00075 rc = monojob_wait ( "" );
00076
00077 return rc;
00078 }