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 ( char *iscsiname ) {
17 char *initiator_iqn = "iqn.1900-01.localdomain.localhost:initiator";
20 struct sockaddr_in sin;
21 struct sockaddr_tcpip st;
24 memset ( &target, 0, sizeof ( target ) );
25 target.sin.sin_family = AF_INET;
26 target.sin.sin_port = htons ( ISCSI_PORT );
27 target_iqn = strchr ( iscsiname, ':' );
30 printf ( "Invalid iSCSI DHCP path\n" );
33 inet_aton ( iscsiname, &target.sin.sin_addr );
35 return test_iscsiboot ( initiator_iqn, &target.st, target_iqn );
38 static int test_dhcp_hello ( char *helloname ) {
41 struct sockaddr_in sin;
42 struct sockaddr_tcpip st;
45 memset ( &target, 0, sizeof ( target ) );
46 target.sin.sin_family = AF_INET;
47 target.sin.sin_port = htons ( 80 );
48 message = strchr ( helloname, ':' );
51 printf ( "Invalid hello path\n" );
54 inet_aton ( helloname, &target.sin.sin_addr );
56 test_hello ( &target.st, message );
60 static int test_dhcp_boot ( struct net_device *netdev, char *filename ) {
61 if ( strncmp ( filename, "aoe:", 4 ) == 0 ) {
62 return test_dhcp_aoe_boot ( netdev, &filename[4] );
63 } else if ( strncmp ( filename, "iscsi:", 6 ) == 0 ) {
64 return test_dhcp_iscsi_boot ( &filename[6] );
65 } else if ( strncmp ( filename, "hello:", 6 ) == 0 ) {
66 return test_dhcp_hello ( &filename[6] );
68 printf ( "Don't know how to boot %s\n", filename );
69 return -EPROTONOSUPPORT;
73 int test_dhcp ( struct net_device *netdev ) {
74 struct dhcp_session dhcp;
75 struct in_addr address = { htonl ( 0 ) };
76 struct in_addr netmask = { htonl ( 0 ) };
77 struct in_addr gateway = { INADDR_NONE };
81 /* Bring IP interface up with address 0.0.0.0 */
82 if ( ( rc = add_ipv4_address ( netdev, address, netmask,
86 /* Issue DHCP request */
88 memset ( &dhcp, 0, sizeof ( dhcp ) );
90 if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 ) {
91 printf ( "failed\n" );
96 /* Register options received via DHCP */
97 register_dhcp_options ( dhcp.options );
99 /* Retrieve IP address configuration */
100 find_global_dhcp_ipv4_option ( DHCP_EB_YIADDR, &address );
101 find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask );
102 find_global_dhcp_ipv4_option ( DHCP_ROUTERS, &gateway );
104 printf ( "IP %s", inet_ntoa ( address ) );
105 printf ( " netmask %s", inet_ntoa ( netmask ) );
106 printf ( " gateway %s\n", inet_ntoa ( gateway ) );
108 dhcp_snprintf ( filename, sizeof ( filename ),
109 find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
110 if ( ! filename[0] ) {
111 printf ( "No filename specified!\n" );
115 printf ( "Bootfile name %s\n", filename );
117 /* Remove old IP address configuration */
118 del_ipv4_address ( netdev );
120 /* Set up new IP address configuration */
121 if ( ( rc = add_ipv4_address ( netdev, address, netmask,
123 goto out_no_del_ipv4;
126 if ( ( rc = test_dhcp_boot ( netdev, filename ) ) != 0 ) {
127 printf ( "Boot failed\n" );
132 /* Unregister and free DHCP options */
133 unregister_dhcp_options ( dhcp.options );
134 free_dhcp_options ( dhcp.options );
136 /* Take down IP interface */
137 del_ipv4_address ( netdev );