7 int test_dhcp ( struct net_device *netdev ) {
8 struct dhcp_session dhcp;
9 struct in_addr address = { htonl ( 0 ) };
10 struct in_addr netmask = { htonl ( 0 ) };
11 struct in_addr gateway = { INADDR_NONE };
15 /* Bring IP interface up with address 0.0.0.0 */
16 if ( ( rc = add_ipv4_address ( netdev, address, netmask,
20 /* Issue DHCP request */
21 memset ( &dhcp, 0, sizeof ( dhcp ) );
23 if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 )
26 /* Register options received via DHCP */
27 register_dhcp_options ( dhcp.options );
29 /* Retrieve IP address configuration */
30 find_global_dhcp_ipv4_option ( DHCP_EB_YIADDR, &address );
31 find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask );
32 find_global_dhcp_ipv4_option ( DHCP_ROUTERS, &gateway );
34 printf ( "IP %s", inet_ntoa ( address ) );
35 printf ( " netmask %s", inet_ntoa ( netmask ) );
36 printf ( " gateway %s\n", inet_ntoa ( gateway ) );
38 dhcp_snprintf ( filename, sizeof ( filename ),
39 find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
40 if ( ! filename[0] ) {
41 printf ( "No filename specified!\n" );
45 printf ( "Bootfile name %s\n", filename );
47 /* Remove old IP address configuration */
48 del_ipv4_address ( netdev );
50 /* Set up new IP address configuration */
51 if ( ( rc = add_ipv4_address ( netdev, address, netmask,
55 /* Proof of concept: check for "aoe:" prefix and if found, do
56 * test AoE boot with AoE options.
58 if ( strncmp ( filename, "aoe:", 4 ) == 0 ) {
59 unsigned int drivenum;
61 drivenum = find_global_dhcp_num_option ( DHCP_EB_BIOS_DRIVE );
62 test_aoeboot ( netdev, &filename[4], drivenum );
64 printf ( "Don't know how to boot %s\n", filename );
68 /* Unregister and free DHCP options */
69 unregister_dhcp_options ( dhcp.options );
70 free_dhcp_options ( dhcp.options );
72 /* Take down IP interface */
73 del_ipv4_address ( netdev );