diff options
| author | Michael Brown | 2006-07-20 04:49:59 +0200 |
|---|---|---|
| committer | Michael Brown | 2006-07-20 04:49:59 +0200 |
| commit | 00a1f000b192f277e52b1d2ac63b2a066a9814a3 (patch) | |
| tree | 25bf2441524fe96cf46e99032143f71acfeb2c68 /src/tests/dhcptest.c | |
| parent | Free up any allocated options if we fail (diff) | |
| download | ipxe-00a1f000b192f277e52b1d2ac63b2a066a9814a3.tar.gz ipxe-00a1f000b192f277e52b1d2ac63b2a066a9814a3.tar.xz ipxe-00a1f000b192f277e52b1d2ac63b2a066a9814a3.zip | |
Added dhcp_ipv4_option() and friends.
Added test code to configure the interface for IPv4 after DHCP.
Diffstat (limited to 'src/tests/dhcptest.c')
| -rw-r--r-- | src/tests/dhcptest.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/tests/dhcptest.c b/src/tests/dhcptest.c index d35e02c2e..b61535f2e 100644 --- a/src/tests/dhcptest.c +++ b/src/tests/dhcptest.c @@ -1,10 +1,49 @@ #include <string.h> +#include <vsprintf.h> +#include <byteswap.h> +#include <gpxe/ip.h> #include <gpxe/dhcp.h> int test_dhcp ( struct net_device *netdev ) { struct dhcp_session dhcp; + struct in_addr address = { htonl ( 0 ) }; + struct in_addr netmask = { htonl ( 0 ) }; + struct in_addr gateway = { INADDR_NONE }; + int rc; + /* Bring IP interface up with address 0.0.0.0 */ + if ( ( rc = add_ipv4_address ( netdev, address, netmask, + gateway ) ) != 0 ) + goto out_no_del_ipv4; + + /* Issue DHCP request */ memset ( &dhcp, 0, sizeof ( dhcp ) ); dhcp.netdev = netdev; - return async_wait ( start_dhcp ( &dhcp ) ); + if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 ) + goto out_no_options; + + /* Retrieve IP address configuration */ + find_dhcp_ipv4_option ( dhcp.options, DHCP_EB_YIADDR, &address ); + find_dhcp_ipv4_option ( dhcp.options, DHCP_SUBNET_MASK, &netmask ); + find_dhcp_ipv4_option ( dhcp.options, DHCP_ROUTERS, &gateway ); + + /* Remove old IP address configuration */ + del_ipv4_address ( netdev ); + + /* Set up new IP address configuration */ + if ( ( rc = add_ipv4_address ( netdev, address, netmask, + gateway ) ) != 0 ) + goto out_no_del_ipv4; + + printf ( "IP %s", inet_ntoa ( address ) ); + printf ( " netmask %s", inet_ntoa ( netmask ) ); + printf ( " gateway %s\n", inet_ntoa ( gateway ) ); + + /* Free DHCP options */ + free_dhcp_options ( dhcp.options ); + out_no_options: + /* Take down IP interface */ + del_ipv4_address ( netdev ); + out_no_del_ipv4: + return rc; } |
