6 #include <gpxe/iscsi.h>
8 static int test_dhcp_aoe_boot ( struct net_device *netdev,
10 unsigned int drivenum;
12 drivenum = find_global_dhcp_num_option ( DHCP_EB_BIOS_DRIVE );
13 return test_aoeboot ( netdev, aoename, drivenum );
16 static int test_dhcp_iscsi_boot ( struct net_device *netdev __unused,
18 char *initiator_iqn = "iqn.1900-01.localdomain.localhost:initiator";
21 struct sockaddr_in sin;
22 struct sockaddr_tcpip st;
25 memset ( &target, 0, sizeof ( target ) );
26 target.sin.sin_family = AF_INET;
27 target.sin.sin_port = htons ( ISCSI_PORT );
28 target_iqn = strchr ( iscsiname, ':' ) + 1;
30 printf ( "Invalid iSCSI DHCP path\n" );
33 inet_aton ( iscsiname, &target.sin.sin_addr );
35 return test_iscsiboot ( initiator_iqn, &target, target_iqn );
38 static int test_dhcp_boot ( struct net_device *netdev, char *filename ) {
39 if ( strncmp ( filename, "aoe:", 4 ) == 0 ) {
40 return test_dhcp_aoe_boot ( netdev, &filename[4] );
41 } else if ( strncmp ( filename, "iscsi:", 6 ) == 0 ) {
42 return test_dhcp_iscsi_boot ( netdev, &filename[6] );
44 printf ( "Don't know how to boot %s\n", filename );
45 return -EPROTONOSUPPORT;
49 int test_dhcp ( struct net_device *netdev ) {
50 struct dhcp_session dhcp;
51 struct in_addr address = { htonl ( 0 ) };
52 struct in_addr netmask = { htonl ( 0 ) };
53 struct in_addr gateway = { INADDR_NONE };
57 /* Bring IP interface up with address 0.0.0.0 */
58 if ( ( rc = add_ipv4_address ( netdev, address, netmask,
62 /* Issue DHCP request */
64 memset ( &dhcp, 0, sizeof ( dhcp ) );
66 if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 ) {
67 printf ( "failed\n" );
72 /* Register options received via DHCP */
73 register_dhcp_options ( dhcp.options );
75 /* Retrieve IP address configuration */
76 find_global_dhcp_ipv4_option ( DHCP_EB_YIADDR, &address );
77 find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask );
78 find_global_dhcp_ipv4_option ( DHCP_ROUTERS, &gateway );
80 printf ( "IP %s", inet_ntoa ( address ) );
81 printf ( " netmask %s", inet_ntoa ( netmask ) );
82 printf ( " gateway %s\n", inet_ntoa ( gateway ) );
84 dhcp_snprintf ( filename, sizeof ( filename ),
85 find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
86 if ( ! filename[0] ) {
87 printf ( "No filename specified!\n" );
91 printf ( "Bootfile name %s\n", filename );
93 /* Remove old IP address configuration */
94 del_ipv4_address ( netdev );
96 /* Set up new IP address configuration */
97 if ( ( rc = add_ipv4_address ( netdev, address, netmask,
102 if ( ( rc = test_dhcp_boot ( netdev, filename ) ) != 0 ) {
103 printf ( "Boot failed\n" );
108 /* Unregister and free DHCP options */
109 unregister_dhcp_options ( dhcp.options );
110 free_dhcp_options ( dhcp.options );
112 /* Take down IP interface */
113 del_ipv4_address ( netdev );