浏览代码

[Misc] Kill off long-redundant tests/dhcptest.c

tags/v0.9.4
Michael Brown 16 年前
父节点
当前提交
720e256c50
共有 1 个文件被更改,包括 0 次插入270 次删除
  1. 0
    270
      src/tests/dhcptest.c

+ 0
- 270
src/tests/dhcptest.c 查看文件

@@ -1,270 +0,0 @@
1
-#include <string.h>
2
-#include <stdlib.h>
3
-#include <stdio.h>
4
-#include <errno.h>
5
-#include <byteswap.h>
6
-#include <gpxe/ip.h>
7
-#include <gpxe/dhcp.h>
8
-#include <gpxe/iscsi.h>
9
-#include <gpxe/netdevice.h>
10
-
11
-#if 0
12
-
13
-static int test_dhcp_aoe_boot ( struct net_device *netdev,
14
-				char *aoename ) {
15
-	unsigned int drivenum;
16
-	
17
-	drivenum = find_global_dhcp_num_option ( DHCP_EB_BIOS_DRIVE );
18
-	return test_aoeboot ( netdev, aoename, drivenum );
19
-}
20
-
21
-enum {
22
-	RP_LITERAL = 0,
23
-	RP_SERVERNAME,
24
-	RP_PROTOCOL,
25
-	RP_PORT,
26
-	RP_LUN,
27
-	RP_TARGETNAME,
28
-	NUM_RP_COMPONENTS
29
-};
30
-
31
-static int iscsi_split_root_path ( char *root_path,
32
-				   char * components[NUM_RP_COMPONENTS] ) {
33
-	int component = 0;
34
-	
35
-	while ( 1 ) {
36
-		components[component++] = root_path;
37
-		if ( component == NUM_RP_COMPONENTS ) {
38
-			return 0;
39
-		}
40
-		for ( ; *root_path != ':' ; root_path++ ) {
41
-			if ( ! *root_path )
42
-				return -EINVAL;
43
-		}
44
-		*(root_path++) = '\0';
45
-	}
46
-}
47
-
48
-static int test_dhcp_iscsi_boot ( struct net_device *netdev ) {
49
-	char root_path[256];
50
-	char *rp_components[NUM_RP_COMPONENTS];
51
-	char initiator_iqn_buf[64];
52
-	char *initiator_iqn = initiator_iqn_buf;
53
-	char username[32];
54
-	char password[32];
55
-	union {
56
-		struct sockaddr_in sin;
57
-		struct sockaddr_tcpip st;
58
-	} target;
59
-	unsigned int drivenum;
60
-	unsigned int lun;
61
-	struct dhcp_option *option;
62
-	int rc;
63
-
64
-	memset ( &target, 0, sizeof ( target ) );
65
-	target.sin.sin_family = AF_INET;
66
-
67
-	dhcp_snprintf ( root_path, sizeof ( root_path ),
68
-			find_global_dhcp_option ( DHCP_ROOT_PATH ) );
69
-
70
-	printf ( "Root path \"%s\"\n", root_path );
71
-
72
-	if ( ( rc = iscsi_split_root_path ( root_path, rp_components ) ) != 0 )
73
-		goto bad_root_path;
74
-
75
-	if ( strcmp ( rp_components[RP_LITERAL], "iscsi" ) != 0 )
76
-		goto bad_root_path;
77
-
78
-	if ( inet_aton ( rp_components[RP_SERVERNAME],
79
-			 &target.sin.sin_addr ) == 0 )
80
-		goto bad_root_path;
81
-
82
-	target.sin.sin_port = strtoul ( rp_components[RP_PORT], NULL, 0 );
83
-	if ( ! target.st.st_port )
84
-		target.st.st_port = htons ( ISCSI_PORT );
85
-
86
-	lun = strtoul ( rp_components[RP_LUN], NULL, 0 );
87
-	
88
-	dhcp_snprintf ( initiator_iqn_buf, sizeof ( initiator_iqn_buf ),
89
-			find_global_dhcp_option ( DHCP_ISCSI_INITIATOR_IQN ) );
90
-	if ( ! initiator_iqn_buf[0] )
91
-		initiator_iqn = "iqn.1900-01.localdomain.localhost:initiator";
92
-	dhcp_snprintf ( username, sizeof ( username ),
93
-			find_global_dhcp_option ( DHCP_EB_USERNAME ) );
94
-	dhcp_snprintf ( password, sizeof ( password ),
95
-			find_global_dhcp_option ( DHCP_EB_PASSWORD ) );
96
-
97
-	drivenum = find_global_dhcp_num_option ( DHCP_EB_BIOS_DRIVE );
98
-
99
-	return test_iscsiboot ( initiator_iqn, &target.st,
100
-				rp_components[RP_TARGETNAME], lun,
101
-				username, password, netdev, drivenum );
102
-
103
- bad_root_path:
104
-	printf ( "Invalid iSCSI root path\n" );
105
-	return -EINVAL;
106
-}
107
-
108
-static int test_dhcp_hello ( char *helloname ) {
109
-	char *message;
110
-	union {
111
-		struct sockaddr_in sin;
112
-		struct sockaddr_tcpip st;
113
-	} target;
114
-
115
-	memset ( &target, 0, sizeof ( target ) );
116
-	target.sin.sin_family = AF_INET;
117
-	target.sin.sin_port = htons ( 80 );
118
-	message = strchr ( helloname, ':' );
119
-	*message++ = '\0';
120
-	if ( ! message ) {
121
-		printf ( "Invalid hello path\n" );
122
-		return -EINVAL;
123
-	}
124
-	inet_aton ( helloname, &target.sin.sin_addr );	
125
-
126
-	test_hello ( &target.st, message );
127
-	return 0;
128
-}
129
-
130
-static int test_dhcp_http ( struct net_device *netdev, char *url ) {
131
-	union {
132
-		struct sockaddr_in sin;
133
-		struct sockaddr_tcpip st;
134
-	} target;
135
-
136
-	memset ( &target, 0, sizeof ( target ) );
137
-	target.sin.sin_family = AF_INET;
138
-	target.sin.sin_port = htons ( 80 );
139
-
140
-	char *addr = url + 7; // http://
141
-        char *file = strchr(addr, '/');
142
-	*file = '\0'; // for printf and inet_aton to work
143
-	printf("connecting to %s\n", addr);
144
-	inet_aton ( addr, &target.sin.sin_addr );
145
-	*file = '/';
146
-	test_http ( netdev, &target.st, file );
147
-	return 0;
148
-}
149
-
150
-static int test_dhcp_ftp ( struct net_device *netdev, char *ftpname ) {
151
-	union {
152
-		struct sockaddr_in sin;
153
-		struct sockaddr_tcpip st;
154
-	} target;
155
-	char *filename;
156
-
157
-	filename = strchr ( ftpname, ':' );
158
-	if ( ! filename ) {
159
-		printf ( "Invalid FTP path \"%s\"\n", ftpname );
160
-		return -EINVAL;
161
-	}
162
-	*filename++ = '\0';
163
-
164
-	memset ( &target, 0, sizeof ( target ) );
165
-	target.sin.sin_family = AF_INET;
166
-	target.sin.sin_port = htons ( 21 );
167
-	inet_aton ( ftpname, &target.sin.sin_addr );
168
-
169
-	test_ftp ( &target, filename );
170
-	return 0;	
171
-}
172
-
173
-static int test_dhcp_tftp ( struct net_device *netdev, char *tftpname ) {
174
-	union {
175
-		struct sockaddr_in sin;
176
-		struct sockaddr_tcpip st;
177
-	} target;
178
-
179
-	memset ( &target, 0, sizeof ( target ) );
180
-	target.sin.sin_family = AF_INET;
181
-	target.sin.sin_port = htons ( 69 );
182
-	find_global_dhcp_ipv4_option ( DHCP_EB_SIADDR,
183
-				       &target.sin.sin_addr );
184
-
185
-	return test_tftp ( netdev, &target.st, tftpname );
186
-}
187
-
188
-static int test_dhcp_boot ( struct net_device *netdev, char *filename ) {
189
-	/*
190
-	if ( strncmp ( filename, "aoe:", 4 ) == 0 ) {
191
-		return test_dhcp_aoe_boot ( netdev, &filename[4] );
192
-	} 
193
-	*/
194
-	//	if ( strncmp ( filename, "iscsi:", 6 ) == 0 ) {
195
-	if ( ! filename[0] ) {
196
-		return test_dhcp_iscsi_boot ( netdev );
197
-	}
198
-	/*
199
-	if ( strncmp ( filename, "ftp:", 4 ) == 0 ) {
200
-		return test_dhcp_ftp ( netdev, &filename[4] );
201
-	}
202
-	*/
203
-	/*
204
-	if ( strncmp ( filename, "hello:", 6 ) == 0 ) {
205
-		return test_dhcp_hello ( &filename[6] );
206
-	}
207
-	if ( strncmp ( filename, "http:", 5 ) == 0 ) {
208
-		return test_dhcp_http ( netdev, filename );
209
-	}
210
-	*/
211
-	return test_dhcp_tftp ( netdev, filename );
212
-
213
-	return -EPROTONOSUPPORT;
214
-}
215
-
216
-int test_dhcp ( struct net_device *netdev ) {
217
-	struct dhcp_session dhcp;
218
-	struct in_addr address = { htonl ( 0 ) };
219
-	struct in_addr netmask = { htonl ( 0 ) };
220
-	struct in_addr gateway = { INADDR_NONE };
221
-	char filename[256];
222
-	int rc;
223
-
224
-	/* Issue DHCP request */
225
-	printf ( "DHCP (%s)...", netdev->name );
226
-	memset ( &dhcp, 0, sizeof ( dhcp ) );
227
-	dhcp.netdev = netdev;
228
-	if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 ) {
229
-		printf ( "failed\n" );
230
-		goto out_no_options;
231
-	}
232
-	printf ( "done\n" );
233
-
234
-	/* Register options received via DHCP */
235
-	register_dhcp_options ( dhcp.options );
236
-
237
-	/* Retrieve IP address configuration */
238
-	find_global_dhcp_ipv4_option ( DHCP_EB_YIADDR, &address );
239
-	find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask );
240
-	find_global_dhcp_ipv4_option ( DHCP_ROUTERS, &gateway );
241
-
242
-	dhcp_snprintf ( filename, sizeof ( filename ),
243
-			find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
244
-	
245
-	if ( filename[0] )
246
-		printf ( "Bootfile name \"%s\"\n", filename );
247
-
248
-	/* Set up new IP address configuration */
249
-	if ( ( rc = add_ipv4_address ( netdev, address, netmask,
250
-				       gateway ) ) != 0 )
251
-		goto out_no_del_ipv4;
252
-
253
-	route();
254
-
255
-	/* Test boot */
256
-	if ( ( rc = test_dhcp_boot ( netdev, filename ) ) != 0 ) {
257
-		printf ( "Boot failed: %s\n", strerror ( rc ) );
258
-		goto out;
259
-	}
260
-	
261
- out:
262
-	/* Unregister and free DHCP options */
263
-	unregister_dhcp_options ( dhcp.options );
264
-	dhcpopt_put ( dhcp.options );
265
- out_no_options:
266
- out_no_del_ipv4:
267
-	return rc;
268
-}
269
-
270
-#endif

正在加载...
取消
保存