Bläddra i källkod

Changed to use the generic stream API.

tags/v0.9.3
Michael Brown 17 år sedan
förälder
incheckning
6d32f0e6e2
10 ändrade filer med 490 tillägg och 531 borttagningar
  1. 5
    5
      src/include/gpxe/ftp.h
  2. 3
    3
      src/include/gpxe/http.h
  3. 4
    4
      src/include/gpxe/iscsi.h
  4. 5
    2
      src/include/gpxe/stream.h
  5. 2
    99
      src/include/gpxe/tcp.h
  6. 48
    6
      src/net/stream.c
  7. 272
    299
      src/net/tcp.c
  8. 60
    51
      src/net/tcp/ftp.c
  9. 29
    21
      src/net/tcp/http.c
  10. 62
    41
      src/net/tcp/iscsi.c

+ 5
- 5
src/include/gpxe/ftp.h Visa fil

@@ -9,7 +9,7 @@
9 9
 
10 10
 #include <stdint.h>
11 11
 #include <gpxe/async.h>
12
-#include <gpxe/tcp.h>
12
+#include <gpxe/stream.h>
13 13
 
14 14
 struct buffer;
15 15
 
@@ -57,10 +57,10 @@ struct ftp_request {
57 57
 	char status_text[4];
58 58
 	/** Passive-mode parameters, as text */
59 59
 	char passive_text[24]; /* "aaa,bbb,ccc,ddd,eee,fff" */
60
-	/** TCP application for the control channel */
61
-	struct tcp_application tcp;
62
-	/** TCP application for the data channel */
63
-	struct tcp_application tcp_data;
60
+	/** Stream application for the control channel */
61
+	struct stream_application stream;
62
+	/** Stream application for the data channel */
63
+	struct stream_application stream_data;
64 64
 };
65 65
 
66 66
 extern int ftp_get ( struct uri *uri, struct buffer *buffer,

+ 3
- 3
src/include/gpxe/http.h Visa fil

@@ -8,7 +8,7 @@
8 8
  */
9 9
 
10 10
 #include <stdint.h>
11
-#include <gpxe/tcp.h>
11
+#include <gpxe/stream.h>
12 12
 #include <gpxe/async.h>
13 13
 #include <gpxe/linebuf.h>
14 14
 #include <gpxe/uri.h>
@@ -43,8 +43,8 @@ struct http_request {
43 43
 
44 44
 	/** Server address */
45 45
 	struct sockaddr server;
46
-	/** TCP application for this request */
47
-	struct tcp_application tcp;
46
+	/** Stream application for this request */
47
+	struct stream_application stream;
48 48
 	/** Number of bytes already sent */
49 49
 	size_t tx_offset;
50 50
 	/** RX state */

+ 4
- 4
src/include/gpxe/iscsi.h Visa fil

@@ -8,7 +8,7 @@
8 8
  */
9 9
 
10 10
 #include <stdint.h>
11
-#include <gpxe/tcp.h>
11
+#include <gpxe/stream.h>
12 12
 #include <gpxe/async.h>
13 13
 #include <gpxe/scsi.h>
14 14
 #include <gpxe/chap.h>
@@ -489,7 +489,7 @@ struct iscsi_session {
489 489
 	/** Initiator IQN */
490 490
 	const char *initiator_iqn;
491 491
 	/** Target address */
492
-	struct sockaddr_tcpip target;
492
+	struct sockaddr target;
493 493
 	/** Target IQN */
494 494
 	const char *target_iqn;
495 495
 	/** Logical Unit Number (LUN) */
@@ -499,8 +499,8 @@ struct iscsi_session {
499 499
 	/** Password */
500 500
 	const char *password;
501 501
 
502
-	/** TCP application for this session */
503
-	struct tcp_application tcp;
502
+	/** Stream application for this session */
503
+	struct stream_application stream;
504 504
 	/** Session status
505 505
 	 *
506 506
 	 * This is the bitwise-OR of zero or more ISCSI_STATUS_XXX

+ 5
- 2
src/include/gpxe/stream.h Visa fil

@@ -125,7 +125,7 @@ struct stream_connection_operations {
125 125
 	 * application's senddata() method.
126 126
 	 */
127 127
 	int ( * send ) ( struct stream_connection *conn,
128
-			 void *data, size_t len );
128
+			 const void *data, size_t len );
129 129
 	/**
130 130
 	 * Notify connection that data is available to send
131 131
 	 *
@@ -167,6 +167,9 @@ struct stream_connection {
167 167
 	struct stream_connection_operations *op;	
168 168
 };
169 169
 
170
+extern void stream_associate ( struct stream_application *app,
171
+			       struct stream_connection *conn );
172
+
170 173
 extern void stream_connected ( struct stream_connection *conn );
171 174
 extern void stream_closed ( struct stream_connection *conn, int rc );
172 175
 extern void stream_senddata ( struct stream_connection *conn,
@@ -181,7 +184,7 @@ extern int stream_connect ( struct stream_application *app,
181 184
 			    struct sockaddr *peer );
182 185
 extern void stream_close ( struct stream_application *app );
183 186
 extern int stream_send ( struct stream_application *app,
184
-			 void *data, size_t len );
187
+			 const void *data, size_t len );
185 188
 extern int stream_kick ( struct stream_application *app );
186 189
 
187 190
 #endif /* _GPXE_STREAM_H */

+ 2
- 99
src/include/gpxe/tcp.h Visa fil

@@ -11,6 +11,7 @@
11 11
 
12 12
 #include "latch.h"
13 13
 #include <gpxe/tcpip.h>
14
+#include <gpxe/stream.h>
14 15
 
15 16
 /**
16 17
  * A TCP header
@@ -252,105 +253,7 @@ struct tcp_mss_option {
252 253
  */
253 254
 #define TCP_MSL ( 2 * 60 * TICKS_PER_SEC )
254 255
 
255
-struct tcp_application;
256
-
257
-/**
258
- * TCP operations
259
- *
260
- */
261
-struct tcp_operations {
262
-	/*
263
-	 * Connection closed
264
-	 *
265
-	 * @v app	TCP application
266
-	 * @v status	Error code, if any
267
-	 *
268
-	 * This is called when the connection is closed for any
269
-	 * reason, including timeouts or aborts.  The status code
270
-	 * contains the negative error number, if the closure is due
271
-	 * to an error.
272
-	 *
273
-	 * When closed() is called, the application no longer has a
274
-	 * valid TCP connection.  Note that connected() may not have
275
-	 * been called before closed(), if the close is due to an
276
-	 * error during connection setup.
277
-	 */
278
-	void ( * closed ) ( struct tcp_application *app, int status );
279
-	/**
280
-	 * Connection established
281
-	 *
282
-	 * @v app	TCP application
283
-	 */
284
-	void ( * connected ) ( struct tcp_application *app );
285
-	/**
286
-	 * Data acknowledged
287
-	 *
288
-	 * @v app	TCP application
289
-	 * @v len	Length of acknowledged data
290
-	 *
291
-	 * @c len is guaranteed to not exceed the outstanding amount
292
-	 * of unacknowledged data.
293
-	 */
294
-	void ( * acked ) ( struct tcp_application *app, size_t len );
295
-	/**
296
-	 * New data received
297
-	 *
298
-	 * @v app	TCP application
299
-	 * @v data	Data
300
-	 * @v len	Length of data
301
-	 */
302
-	void ( * newdata ) ( struct tcp_application *app,
303
-			     void *data, size_t len );
304
-	/**
305
-	 * Transmit data
306
-	 *
307
-	 * @v app	TCP application
308
-	 * @v buf	Temporary data buffer
309
-	 * @v len	Length of temporary data buffer
310
-	 *
311
-	 * The application should transmit whatever it currently wants
312
-	 * to send using tcp_send().  If retransmissions are required,
313
-	 * senddata() will be called again and the application must
314
-	 * regenerate the data.  The easiest way to implement this is
315
-	 * to ensure that senddata() never changes the application's
316
-	 * state.
317
-	 *
318
-	 * The application may use the temporary data buffer to
319
-	 * construct the data to be sent.  Note that merely filling
320
-	 * the buffer will do nothing; the application must call
321
-	 * tcp_send() in order to actually transmit the data.  Use of
322
-	 * the buffer is not compulsory; the application may call
323
-	 * tcp_send() on any block of data.
324
-	 */
325
-	void ( * senddata ) ( struct tcp_application *app, void *buf,
326
-			      size_t len );
327
-};
328
-
329
-struct tcp_connection;
330
-
331
-/**
332
- * A TCP application
333
- *
334
- * This data structure represents an application with a TCP connection.
335
- */
336
-struct tcp_application {
337
-	/** TCP connection data
338
-	 *
339
-	 * This is filled in by TCP calls that initiate a connection,
340
-	 * and reset to NULL when the connection is closed.
341
-	 */
342
-	struct tcp_connection *conn;
343
-	/** TCP connection operations table */
344
-	struct tcp_operations *tcp_op;
345
-};
346
-
347
-extern int tcp_connect ( struct tcp_application *app,
348
-			 struct sockaddr_tcpip *peer,
349
-			 uint16_t local_port );
350
-extern void tcp_close ( struct tcp_application *app );
351
-extern int tcp_senddata ( struct tcp_application *app );
352
-extern int tcp_send ( struct tcp_application *app, const void *data, 
353
-		      size_t len );
256
+extern int tcp_open ( struct stream_application *app );
354 257
 
355 258
 extern struct tcpip_protocol tcp_protocol;
356 259
 

+ 48
- 6
src/net/stream.c Visa fil

@@ -25,8 +25,26 @@
25 25
 #include <stdint.h>
26 26
 #include <string.h>
27 27
 #include <errno.h>
28
+#include <assert.h>
28 29
 #include <gpxe/stream.h>
29 30
 
31
+/**
32
+ * Associate application with connection
33
+ *
34
+ * @v app		Stream application
35
+ * @v conn		Stream connection
36
+ */
37
+void stream_associate ( struct stream_application *app,
38
+			struct stream_connection *conn ) {
39
+
40
+	DBGC ( app, "Stream %p associating with connection %p\n", app, conn );
41
+
42
+	assert ( conn->app == NULL );
43
+	assert ( app->conn == NULL );
44
+	conn->app = app;
45
+	app->conn = conn;
46
+}
47
+
30 48
 /**
31 49
  * Connection established
32 50
  *
@@ -45,7 +63,8 @@ void stream_connected ( struct stream_connection *conn ) {
45 63
 	}
46 64
 
47 65
 	/* Hand off to application */
48
-	app->op->connected ( app );
66
+	if ( app->op->connected )
67
+		app->op->connected ( app );
49 68
 }
50 69
 
51 70
 /**
@@ -66,8 +85,13 @@ void stream_closed ( struct stream_connection *conn, int rc ) {
66 85
 		return;
67 86
 	}
68 87
 
88
+	/* Disassociate application from connection */
89
+	app->conn = NULL;
90
+	conn->app = NULL;
91
+
69 92
 	/* Hand off to application */
70
-	app->op->closed ( app, rc );
93
+	if ( app->op->closed )
94
+		app->op->closed ( app, rc );
71 95
 }
72 96
 
73 97
 /**
@@ -91,7 +115,8 @@ void stream_senddata ( struct stream_connection *conn,
91 115
 	}
92 116
 
93 117
 	/* Hand off to application */
94
-	app->op->senddata ( app, data, len );
118
+	if ( app->op->senddata )
119
+		app->op->senddata ( app, data, len );
95 120
 }
96 121
 
97 122
 /**
@@ -116,7 +141,8 @@ void stream_acked ( struct stream_connection *conn, size_t len ) {
116 141
 	}
117 142
 
118 143
 	/* Hand off to application */
119
-	app->op->acked ( app, len );
144
+	if ( app->op->acked )
145
+		app->op->acked ( app, len );
120 146
 }
121 147
 
122 148
 /**
@@ -140,7 +166,8 @@ void stream_newdata ( struct stream_connection *conn,
140 166
 	}
141 167
 
142 168
 	/* Hand off to application */
143
-	app->op->newdata ( app, data, len );
169
+	if ( app->op->newdata )
170
+		app->op->newdata ( app, data, len );
144 171
 }
145 172
 
146 173
 /**
@@ -163,6 +190,8 @@ int stream_bind ( struct stream_application *app, struct sockaddr *local ) {
163 190
 	}
164 191
 
165 192
 	/* Hand off to connection */
193
+	if ( ! conn->op->bind )
194
+		return -ENOTSUP;
166 195
 	if ( ( rc = conn->op->bind ( conn, local ) ) != 0 ) {
167 196
 		DBGC ( app, "Stream %p failed to bind: %s\n",
168 197
 		       app, strerror ( rc ) );
@@ -192,6 +221,8 @@ int stream_connect ( struct stream_application *app, struct sockaddr *peer ) {
192 221
 	}
193 222
 
194 223
 	/* Hand off to connection */
224
+	if ( ! conn->op->connect )
225
+		return -ENOTSUP;
195 226
 	if ( ( rc = conn->op->connect ( conn, peer ) ) != 0 ) {
196 227
 		DBGC ( app, "Stream %p failed to connect: %s\n",
197 228
 		       app, strerror ( rc ) );
@@ -217,7 +248,13 @@ void stream_close ( struct stream_application *app ) {
217 248
 		return;
218 249
 	}
219 250
 
251
+	/* Disassociate application from connection */
252
+	app->conn = NULL;
253
+	conn->app = NULL;
254
+
220 255
 	/* Hand off to connection */
256
+	if ( ! conn->op->close )
257
+		return;
221 258
 	conn->op->close ( conn );
222 259
 }
223 260
 
@@ -232,7 +269,8 @@ void stream_close ( struct stream_application *app ) {
232 269
  * This method should be called only in the context of an
233 270
  * application's senddata() method.
234 271
  */
235
-int stream_send ( struct stream_application *app, void *data, size_t len ) {
272
+int stream_send ( struct stream_application *app,
273
+		  const void *data, size_t len ) {
236 274
 	struct stream_connection *conn = app->conn;
237 275
 	int rc;
238 276
 
@@ -245,6 +283,8 @@ int stream_send ( struct stream_application *app, void *data, size_t len ) {
245 283
 	}
246 284
 
247 285
 	/* Hand off to connection */
286
+	if ( ! conn->op->send )
287
+		return -ENOTSUP;
248 288
 	if ( ( rc = conn->op->send ( conn, data, len ) ) != 0 ) {
249 289
 		DBGC ( app, "Stream %p failed to send %zd bytes: %s\n",
250 290
 		       app, len, strerror ( rc ) );
@@ -273,6 +313,8 @@ int stream_kick ( struct stream_application *app ) {
273 313
 	}
274 314
 
275 315
 	/* Hand off to connection */
316
+	if ( ! conn->op->send )
317
+		return -ENOTSUP;
276 318
 	if ( ( rc = conn->op->kick ( conn ) ) != 0 ) {
277 319
 		DBGC ( app, "Stream %p failed to kick connection: %s\n",
278 320
 		       app, strerror ( rc ) );

+ 272
- 299
src/net/tcp.c
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 60
- 51
src/net/tcp/ftp.c Visa fil

@@ -4,10 +4,12 @@
4 4
 #include <string.h>
5 5
 #include <assert.h>
6 6
 #include <errno.h>
7
+#include <byteswap.h>
7 8
 #include <gpxe/async.h>
8 9
 #include <gpxe/buffer.h>
9 10
 #include <gpxe/uri.h>
10 11
 #include <gpxe/download.h>
12
+#include <gpxe/tcp.h>
11 13
 #include <gpxe/ftp.h>
12 14
 
13 15
 /** @file
@@ -40,13 +42,14 @@ static const char * ftp_strings[] = {
40 42
 };
41 43
 
42 44
 /**
43
- * Get FTP request from control TCP application
45
+ * Get FTP request from control stream application
44 46
  *
45
- * @v app		TCP application
47
+ * @v app		Stream application
46 48
  * @ret ftp		FTP request
47 49
  */
48
-static inline struct ftp_request * tcp_to_ftp ( struct tcp_application *app ) {
49
-	return container_of ( app, struct ftp_request, tcp );
50
+static inline struct ftp_request *
51
+stream_to_ftp ( struct stream_application *app ) {
52
+	return container_of ( app, struct ftp_request, stream );
50 53
 }
51 54
 
52 55
 /**
@@ -59,9 +62,9 @@ static void ftp_done ( struct ftp_request *ftp, int rc ) {
59 62
 
60 63
 	DBGC ( ftp, "FTP %p completed with status %d\n", ftp, rc );
61 64
 
62
-	/* Close both TCP connections */
63
-	tcp_close ( &ftp->tcp );
64
-	tcp_close ( &ftp->tcp_data );
65
+	/* Close both stream connections */
66
+	stream_close ( &ftp->stream );
67
+	stream_close ( &ftp->stream_data );
65 68
 
66 69
 	/* Mark asynchronous operation as complete */
67 70
 	async_done ( &ftp->async, rc );
@@ -70,9 +73,9 @@ static void ftp_done ( struct ftp_request *ftp, int rc ) {
70 73
 /**
71 74
  * Parse FTP byte sequence value
72 75
  *
73
- * @v text	Text string
74
- * @v value	Value buffer
75
- * @v len	Length of value buffer
76
+ * @v text		Text string
77
+ * @v value		Value buffer
78
+ * @v len		Length of value buffer
76 79
  *
77 80
  * This parses an FTP byte sequence value (e.g. the "aaa,bbb,ccc,ddd"
78 81
  * form for IP addresses in PORT commands) into a byte sequence.  @c
@@ -93,7 +96,7 @@ static void ftp_parse_value ( char **text, uint8_t *value, size_t len ) {
93 96
 /**
94 97
  * Handle an FTP control channel response
95 98
  *
96
- * @v ftp	FTP request
99
+ * @v ftp		FTP request
97 100
  *
98 101
  * This is called once we have received a complete response line.
99 102
  */
@@ -121,7 +124,7 @@ static void ftp_reply ( struct ftp_request *ftp ) {
121 124
 		char *ptr = ftp->passive_text;
122 125
 		union {
123 126
 			struct sockaddr_in sin;
124
-			struct sockaddr_tcpip st;
127
+			struct sockaddr sa;
125 128
 		} sa;
126 129
 		int rc;
127 130
 
@@ -130,7 +133,14 @@ static void ftp_reply ( struct ftp_request *ftp ) {
130 133
 				  sizeof ( sa.sin.sin_addr ) );
131 134
 		ftp_parse_value ( &ptr, ( uint8_t * ) &sa.sin.sin_port,
132 135
 				  sizeof ( sa.sin.sin_port ) );
133
-		if ( ( rc = tcp_connect ( &ftp->tcp_data, &sa.st, 0 ) ) != 0 ){
136
+		if ( ( rc = tcp_open ( &ftp->stream_data ) ) != 0 ) {
137
+			DBGC ( ftp, "FTP %p could not open data connection\n",
138
+			       ftp );
139
+			ftp_done ( ftp, rc );
140
+			return;
141
+		}
142
+		if ( ( rc = stream_connect ( &ftp->stream_data,
143
+					     &sa.sa ) ) != 0 ){
134 144
 			DBGC ( ftp, "FTP %p could not make data connection\n",
135 145
 			       ftp );
136 146
 			ftp_done ( ftp, rc );
@@ -154,16 +164,16 @@ static void ftp_reply ( struct ftp_request *ftp ) {
154 164
 /**
155 165
  * Handle new data arriving on FTP control channel
156 166
  *
157
- * @v app	TCP application
158
- * @v data	New data
159
- * @v len	Length of new data
167
+ * @v app		Stream application
168
+ * @v data		New data
169
+ * @v len		Length of new data
160 170
  *
161 171
  * Data is collected until a complete line is received, at which point
162 172
  * its information is passed to ftp_reply().
163 173
  */
164
-static void ftp_newdata ( struct tcp_application *app,
174
+static void ftp_newdata ( struct stream_application *app,
165 175
 			  void *data, size_t len ) {
166
-	struct ftp_request *ftp = tcp_to_ftp ( app );
176
+	struct ftp_request *ftp = stream_to_ftp ( app );
167 177
 	char *recvbuf = ftp->recvbuf;
168 178
 	size_t recvsize = ftp->recvsize;
169 179
 	char c;
@@ -210,10 +220,10 @@ static void ftp_newdata ( struct tcp_application *app,
210 220
 /**
211 221
  * Handle acknowledgement of data sent on FTP control channel
212 222
  *
213
- * @v app	TCP application
223
+ * @v app		Stream application
214 224
  */
215
-static void ftp_acked ( struct tcp_application *app, size_t len ) {
216
-	struct ftp_request *ftp = tcp_to_ftp ( app );
225
+static void ftp_acked ( struct stream_application *app, size_t len ) {
226
+	struct ftp_request *ftp = stream_to_ftp ( app );
217 227
 	
218 228
 	/* Mark off ACKed portion of the currently-transmitted data */
219 229
 	ftp->already_sent += len;
@@ -222,31 +232,31 @@ static void ftp_acked ( struct tcp_application *app, size_t len ) {
222 232
 /**
223 233
  * Construct data to send on FTP control channel
224 234
  *
225
- * @v app	TCP application
226
- * @v buf	Temporary data buffer
227
- * @v len	Length of temporary data buffer
235
+ * @v app		Stream application
236
+ * @v buf		Temporary data buffer
237
+ * @v len		Length of temporary data buffer
228 238
  */
229
-static void ftp_senddata ( struct tcp_application *app,
239
+static void ftp_senddata ( struct stream_application *app,
230 240
 			   void *buf, size_t len ) {
231
-	struct ftp_request *ftp = tcp_to_ftp ( app );
241
+	struct ftp_request *ftp = stream_to_ftp ( app );
232 242
 
233 243
 	/* Send the as-yet-unACKed portion of the string for the
234 244
 	 * current state.
235 245
 	 */
236 246
 	len = snprintf ( buf, len, ftp_strings[ftp->state], ftp->uri->path );
237
-	tcp_send ( app, buf + ftp->already_sent, len - ftp->already_sent );
247
+	stream_send ( app, buf + ftp->already_sent, len - ftp->already_sent );
238 248
 }
239 249
 
240 250
 /**
241 251
  * Handle control channel being closed
242 252
  *
243
- * @v app		TCP application
253
+ * @v app		Stream application
244 254
  *
245 255
  * When the control channel is closed, the data channel must also be
246 256
  * closed, if it is currently open.
247 257
  */
248
-static void ftp_closed ( struct tcp_application *app, int rc ) {
249
-	struct ftp_request *ftp = tcp_to_ftp ( app );
258
+static void ftp_closed ( struct stream_application *app, int rc ) {
259
+	struct ftp_request *ftp = stream_to_ftp ( app );
250 260
 
251 261
 	DBGC ( ftp, "FTP %p control connection closed: %s\n",
252 262
 	       ftp, strerror ( rc ) );
@@ -256,7 +266,7 @@ static void ftp_closed ( struct tcp_application *app, int rc ) {
256 266
 }
257 267
 
258 268
 /** FTP control channel operations */
259
-static struct tcp_operations ftp_tcp_operations = {
269
+static struct stream_application_operations ftp_stream_operations = {
260 270
 	.closed		= ftp_closed,
261 271
 	.acked		= ftp_acked,
262 272
 	.newdata	= ftp_newdata,
@@ -270,20 +280,20 @@ static struct tcp_operations ftp_tcp_operations = {
270 280
  */
271 281
 
272 282
 /**
273
- * Get FTP request from data TCP application
283
+ * Get FTP request from data stream application
274 284
  *
275
- * @v app		TCP application
285
+ * @v app		Stream application
276 286
  * @ret ftp		FTP request
277 287
  */
278 288
 static inline struct ftp_request *
279
-tcp_to_ftp_data ( struct tcp_application *app ) {
280
-	return container_of ( app, struct ftp_request, tcp_data );
289
+stream_to_ftp_data ( struct stream_application *app ) {
290
+	return container_of ( app, struct ftp_request, stream_data );
281 291
 }
282 292
 
283 293
 /**
284 294
  * Handle data channel being closed
285 295
  *
286
- * @v app		TCP application
296
+ * @v app		Stream application
287 297
  *
288 298
  * When the data channel is closed, the control channel should be left
289 299
  * alone; the server will send a completion message via the control
@@ -291,8 +301,8 @@ tcp_to_ftp_data ( struct tcp_application *app ) {
291 301
  *
292 302
  * If the data channel is closed due to an error, we abort the request.
293 303
  */
294
-static void ftp_data_closed ( struct tcp_application *app, int rc ) {
295
-	struct ftp_request *ftp = tcp_to_ftp_data ( app );
304
+static void ftp_data_closed ( struct stream_application *app, int rc ) {
305
+	struct ftp_request *ftp = stream_to_ftp_data ( app );
296 306
 
297 307
 	DBGC ( ftp, "FTP %p data connection closed: %s\n",
298 308
 	       ftp, strerror ( rc ) );
@@ -305,13 +315,13 @@ static void ftp_data_closed ( struct tcp_application *app, int rc ) {
305 315
 /**
306 316
  * Handle new data arriving on the FTP data channel
307 317
  *
308
- * @v app	TCP application
309
- * @v data	New data
310
- * @v len	Length of new data
318
+ * @v app		Stream application
319
+ * @v data		New data
320
+ * @v len		Length of new data
311 321
  */
312
-static void ftp_data_newdata ( struct tcp_application *app,
322
+static void ftp_data_newdata ( struct stream_application *app,
313 323
 			       void *data, size_t len ) {
314
-	struct ftp_request *ftp = tcp_to_ftp_data ( app );
324
+	struct ftp_request *ftp = stream_to_ftp_data ( app );
315 325
 	int rc;
316 326
 
317 327
 	/* Fill data buffer */
@@ -325,7 +335,7 @@ static void ftp_data_newdata ( struct tcp_application *app,
325 335
 }
326 336
 
327 337
 /** FTP data channel operations */
328
-static struct tcp_operations ftp_data_tcp_operations = {
338
+static struct stream_application_operations ftp_data_stream_operations = {
329 339
 	.closed		= ftp_data_closed,
330 340
 	.newdata	= ftp_data_newdata,
331 341
 };
@@ -353,9 +363,6 @@ static struct async_operations ftp_async_operations = {
353 363
 	.reap = ftp_reap,
354 364
 };
355 365
 
356
-#warning "Quick name resolution hack"
357
-#include <byteswap.h>
358
-
359 366
 /**
360 367
  * Initiate an FTP connection
361 368
  *
@@ -387,12 +394,12 @@ int ftp_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
387 394
 	ftp->already_sent = 0;
388 395
 	ftp->recvbuf = ftp->status_text;
389 396
 	ftp->recvsize = sizeof ( ftp->status_text ) - 1;
390
-	ftp->tcp.tcp_op = &ftp_tcp_operations;
391
-	ftp->tcp_data.tcp_op = &ftp_data_tcp_operations;
397
+	ftp->stream.op = &ftp_stream_operations;
398
+	ftp->stream_data.op = &ftp_data_stream_operations;
392 399
 
393 400
 #warning "Quick name resolution hack"
394 401
 	union {
395
-		struct sockaddr_tcpip st;
402
+		struct sockaddr sa;
396 403
 		struct sockaddr_in sin;
397 404
 	} server;
398 405
 	server.sin.sin_port = htons ( FTP_PORT );
@@ -404,7 +411,9 @@ int ftp_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
404 411
 
405 412
 	DBGC ( ftp, "FTP %p fetching %s\n", ftp, ftp->uri->path );
406 413
 
407
-	if ( ( rc = tcp_connect ( &ftp->tcp, &server.st, 0 ) ) != 0 )
414
+	if ( ( rc = tcp_open ( &ftp->stream ) ) != 0 )
415
+		goto err;
416
+	if ( ( rc = stream_connect ( &ftp->stream, &server.sa ) ) != 0 )
408 417
 		goto err;
409 418
 
410 419
 	async_init ( &ftp->async, &ftp_async_operations, parent );

+ 29
- 21
src/net/tcp/http.c Visa fil

@@ -36,13 +36,14 @@
36 36
 #include <gpxe/buffer.h>
37 37
 #include <gpxe/download.h>
38 38
 #include <gpxe/resolv.h>
39
+#include <gpxe/tcp.h>
39 40
 #include <gpxe/http.h>
40 41
 
41 42
 static struct async_operations http_async_operations;
42 43
 
43 44
 static inline struct http_request *
44
-tcp_to_http ( struct tcp_application *app ) {
45
-	return container_of ( app, struct http_request, tcp );
45
+stream_to_http ( struct stream_application *app ) {
46
+	return container_of ( app, struct http_request, stream );
46 47
 }
47 48
 
48 49
 /**
@@ -54,8 +55,8 @@ tcp_to_http ( struct tcp_application *app ) {
54 55
  */
55 56
 static void http_done ( struct http_request *http, int rc ) {
56 57
 
57
-	/* Close TCP connection */
58
-	tcp_close ( &http->tcp );
58
+	/* Close stream connection */
59
+	stream_close ( &http->stream );
59 60
 
60 61
 	/* Prevent further processing of any current packet */
61 62
 	http->rx_state = HTTP_RX_DEAD;
@@ -271,9 +272,9 @@ static void http_rx_data ( struct http_request *http,
271 272
  * @v data		New data
272 273
  * @v len		Length of new data
273 274
  */
274
-static void http_newdata ( struct tcp_application *app,
275
+static void http_newdata ( struct stream_application *app,
275 276
 			   void *data, size_t len ) {
276
-	struct http_request *http = tcp_to_http ( app );
277
+	struct http_request *http = stream_to_http ( app );
277 278
 	const char *buf = data;
278 279
 	char *line;
279 280
 	int rc;
@@ -319,13 +320,13 @@ static void http_newdata ( struct tcp_application *app,
319 320
 /**
320 321
  * Send HTTP data
321 322
  *
322
- * @v app		TCP application
323
+ * @v app		Stream application
323 324
  * @v buf		Temporary data buffer
324 325
  * @v len		Length of temporary data buffer
325 326
  */
326
-static void http_senddata ( struct tcp_application *app,
327
+static void http_senddata ( struct stream_application *app,
327 328
 			    void *buf, size_t len ) {
328
-	struct http_request *http = tcp_to_http ( app );
329
+	struct http_request *http = stream_to_http ( app );
329 330
 	const char *path = http->uri->path;
330 331
 	const char *host = http->uri->host;
331 332
 
@@ -338,17 +339,18 @@ static void http_senddata ( struct tcp_application *app,
338 339
 			 "Host: %s\r\n"
339 340
 			 "\r\n", path, host );
340 341
 
341
-	tcp_send ( app, ( buf + http->tx_offset ), ( len - http->tx_offset ) );
342
+	stream_send ( app, ( buf + http->tx_offset ),
343
+		      ( len - http->tx_offset ) );
342 344
 }
343 345
 
344 346
 /**
345 347
  * HTTP data acknowledged
346 348
  *
347
- * @v app		TCP application
349
+ * @v app		Stream application
348 350
  * @v len		Length of acknowledged data
349 351
  */
350
-static void http_acked ( struct tcp_application *app, size_t len ) {
351
-	struct http_request *http = tcp_to_http ( app );
352
+static void http_acked ( struct stream_application *app, size_t len ) {
353
+	struct http_request *http = stream_to_http ( app );
352 354
 
353 355
 	http->tx_offset += len;
354 356
 }
@@ -356,10 +358,10 @@ static void http_acked ( struct tcp_application *app, size_t len ) {
356 358
 /**
357 359
  * HTTP connection closed by network stack
358 360
  *
359
- * @v app		TCP application
361
+ * @v app		Stream application
360 362
  */
361
-static void http_closed ( struct tcp_application *app, int rc ) {
362
-	struct http_request *http = tcp_to_http ( app );
363
+static void http_closed ( struct stream_application *app, int rc ) {
364
+	struct http_request *http = stream_to_http ( app );
363 365
 
364 366
 	DBGC ( http, "HTTP %p connection closed: %s\n",
365 367
 	       http, strerror ( rc ) );
@@ -367,8 +369,8 @@ static void http_closed ( struct tcp_application *app, int rc ) {
367 369
 	http_done ( http, rc );
368 370
 }
369 371
 
370
-/** HTTP TCP operations */
371
-static struct tcp_operations http_tcp_operations = {
372
+/** HTTP stream operations */
373
+static struct stream_application_operations http_stream_operations = {
372 374
 	.closed		= http_closed,
373 375
 	.acked		= http_acked,
374 376
 	.newdata	= http_newdata,
@@ -395,6 +397,7 @@ int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
395 397
 	http->uri = uri;
396 398
 	http->buffer = buffer;
397 399
 	async_init ( &http->async, &http_async_operations, parent );
400
+	http->stream.op = &http_stream_operations;
398 401
 
399 402
 	/* Start name resolution.  The download proper will start when
400 403
 	 * name resolution completes.
@@ -432,10 +435,15 @@ static void http_sigchld ( struct async *async, enum signal signal __unused ) {
432 435
 	}
433 436
 
434 437
 	/* Otherwise, start the HTTP connection */
435
-	http->tcp.tcp_op = &http_tcp_operations;
438
+	if ( ( rc = tcp_open ( &http->stream ) ) != 0 ) {
439
+		DBGC ( http, "HTTP %p could not open stream connection: %s\n",
440
+		       http, strerror ( rc ) );
441
+		http_done ( http, rc );
442
+		return;
443
+	}
436 444
 	st->st_port = htons ( uri_port ( http->uri, HTTP_PORT ) );
437
-	if ( ( rc = tcp_connect ( &http->tcp, st, 0 ) ) != 0 ) {
438
-		DBGC ( http, "HTTP %p could not open TCP connection: %s\n",
445
+	if ( ( rc = stream_connect ( &http->stream, &http->server ) ) != 0 ) {
446
+		DBGC ( http, "HTTP %p could not connect stream: %s\n",
439 447
 		       http, strerror ( rc ) );
440 448
 		http_done ( http, rc );
441 449
 		return;

+ 62
- 41
src/net/tcp/iscsi.c Visa fil

@@ -26,6 +26,7 @@
26 26
 #include <gpxe/scsi.h>
27 27
 #include <gpxe/process.h>
28 28
 #include <gpxe/uaccess.h>
29
+#include <gpxe/tcp.h>
29 30
 #include <gpxe/iscsi.h>
30 31
 
31 32
 /** @file
@@ -85,8 +86,8 @@ static void iscsi_rx_buffered_data_done ( struct iscsi_session *iscsi ) {
85 86
  */
86 87
 static void iscsi_close ( struct iscsi_session *iscsi ) {
87 88
 
88
-	/* Close TCP connection */
89
-	tcp_close ( &iscsi->tcp );
89
+	/* Close stream connection */
90
+	stream_close ( &iscsi->stream );
90 91
 
91 92
 	/* Clear connection status */
92 93
 	iscsi->status = 0;
@@ -338,7 +339,7 @@ static void iscsi_tx_data_out ( struct iscsi_session *iscsi,
338 339
 		len = remaining;
339 340
 	copy_from_user ( buf, iscsi->command->data_out, offset, len );
340 341
 
341
-	tcp_send ( &iscsi->tcp, buf, len );
342
+	stream_send ( &iscsi->stream, buf, len );
342 343
 }
343 344
 
344 345
 /****************************************************************************
@@ -507,7 +508,7 @@ static void iscsi_login_request_done ( struct iscsi_session *iscsi ) {
507 508
 static void iscsi_tx_login_request ( struct iscsi_session *iscsi,
508 509
 				     void *buf, size_t len ) {
509 510
 	len = iscsi_build_login_request_strings ( iscsi, buf, len );
510
-	tcp_send ( &iscsi->tcp, buf + iscsi->tx_offset,
511
+	stream_send ( &iscsi->stream, buf + iscsi->tx_offset,
511 512
 		   len - iscsi->tx_offset );
512 513
 }
513 514
 
@@ -750,11 +751,18 @@ static void iscsi_rx_login_response ( struct iscsi_session *iscsi, void *data,
750 751
 	if ( response->status_class == ISCSI_STATUS_REDIRECT ) {
751 752
 		DBGC ( iscsi, "iSCSI %p redirecting to new server\n", iscsi );
752 753
 		iscsi_close ( iscsi );
753
-		if ( ( rc = tcp_connect ( &iscsi->tcp, &iscsi->target,
754
-					  0 ) ) != 0 ) {
755
-			DBGC ( iscsi, "iSCSI %p could not open TCP "
756
-			       "connection: %s\n", iscsi, strerror ( rc ) );
754
+		if ( ( rc = tcp_open ( &iscsi->stream ) ) != 0 ) {
755
+			DBGC ( iscsi, "iSCSI %p could not open stream: %s\n ",
756
+			       iscsi, strerror ( rc ) );
757 757
 			iscsi_done ( iscsi, rc );
758
+			return;
759
+		}
760
+		if ( ( rc = stream_connect ( &iscsi->stream,
761
+					     &iscsi->target ) != 0 ) != 0 ) {
762
+			DBGC ( iscsi, "iSCSI %p could not connect: %s\n ",
763
+			       iscsi, strerror ( rc ) );
764
+			iscsi_done ( iscsi, rc );
765
+			return;
758 766
 		}
759 767
 		return;
760 768
 	}
@@ -810,13 +818,13 @@ static void iscsi_rx_login_response ( struct iscsi_session *iscsi, void *data,
810 818
 
811 819
 /****************************************************************************
812 820
  *
813
- * iSCSI to TCP interface
821
+ * iSCSI to stream interface
814 822
  *
815 823
  */
816 824
 
817 825
 static inline struct iscsi_session *
818
-tcp_to_iscsi ( struct tcp_application *app ) {
819
-	return container_of ( app, struct iscsi_session, tcp );
826
+stream_to_iscsi ( struct stream_application *app ) {
827
+	return container_of ( app, struct iscsi_session, stream );
820 828
 }
821 829
 
822 830
 /**
@@ -889,15 +897,15 @@ static void iscsi_tx_done ( struct iscsi_session *iscsi ) {
889 897
 }
890 898
 
891 899
 /**
892
- * Handle TCP ACKs
900
+ * Handle stream ACKs
893 901
  *
894 902
  * @v iscsi		iSCSI session
895 903
  * 
896 904
  * Updates iscsi->tx_offset and, if applicable, transitions to the
897 905
  * next TX state.
898 906
  */
899
-static void iscsi_acked ( struct tcp_application *app, size_t len ) {
900
-	struct iscsi_session *iscsi = tcp_to_iscsi ( app );
907
+static void iscsi_acked ( struct stream_application *app, size_t len ) {
908
+	struct iscsi_session *iscsi = stream_to_iscsi ( app );
901 909
 	struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
902 910
 	enum iscsi_tx_state next_state;
903 911
 	
@@ -953,9 +961,9 @@ static void iscsi_acked ( struct tcp_application *app, size_t len ) {
953 961
  * 
954 962
  * Constructs data to be sent for the current TX state
955 963
  */
956
-static void iscsi_senddata ( struct tcp_application *app,
964
+static void iscsi_senddata ( struct stream_application *app,
957 965
 			     void *buf, size_t len ) {
958
-	struct iscsi_session *iscsi = tcp_to_iscsi ( app );
966
+	struct iscsi_session *iscsi = stream_to_iscsi ( app );
959 967
 	struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
960 968
 	static const char pad[] = { '\0', '\0', '\0' };
961 969
 
@@ -964,7 +972,7 @@ static void iscsi_senddata ( struct tcp_application *app,
964 972
 		/* Nothing to send */
965 973
 		break;
966 974
 	case ISCSI_TX_BHS:
967
-		tcp_send ( app, &iscsi->tx_bhs.bytes[iscsi->tx_offset],
975
+		stream_send ( app, &iscsi->tx_bhs.bytes[iscsi->tx_offset],
968 976
 			   ( sizeof ( iscsi->tx_bhs ) - iscsi->tx_offset ) );
969 977
 		break;
970 978
 	case ISCSI_TX_AHS:
@@ -975,8 +983,8 @@ static void iscsi_senddata ( struct tcp_application *app,
975 983
 		iscsi_tx_data ( iscsi, buf, len );
976 984
 		break;
977 985
 	case ISCSI_TX_DATA_PADDING:
978
-		tcp_send ( app, pad, ( ISCSI_DATA_PAD_LEN ( common->lengths )
979
-					- iscsi->tx_offset ) );
986
+		stream_send ( app, pad, ( ISCSI_DATA_PAD_LEN( common->lengths )
987
+					  - iscsi->tx_offset ) );
980 988
 		break;
981 989
 	default:
982 990
 		assert ( 0 );
@@ -1068,7 +1076,7 @@ static void iscsi_rx_bhs ( struct iscsi_session *iscsi, void *data,
1068 1076
 /**
1069 1077
  * Receive new data
1070 1078
  *
1071
- * @v tcp		TCP application
1079
+ * @v stream		Stream application
1072 1080
  * @v data		Received data
1073 1081
  * @v len		Length of received data
1074 1082
  *
@@ -1079,9 +1087,9 @@ static void iscsi_rx_bhs ( struct iscsi_session *iscsi, void *data,
1079 1087
  * always has a full copy of the BHS available, even for portions of
1080 1088
  * the data in different packets to the BHS.
1081 1089
  */
1082
-static void iscsi_newdata ( struct tcp_application *app, void *data,
1090
+static void iscsi_newdata ( struct stream_application *app, void *data,
1083 1091
 			    size_t len ) {
1084
-	struct iscsi_session *iscsi = tcp_to_iscsi ( app );
1092
+	struct iscsi_session *iscsi = stream_to_iscsi ( app );
1085 1093
 	struct iscsi_bhs_common *common = &iscsi->rx_bhs.common;
1086 1094
 	void ( *process ) ( struct iscsi_session *iscsi, void *data,
1087 1095
 			    size_t len, size_t remaining );
@@ -1138,14 +1146,14 @@ static void iscsi_newdata ( struct tcp_application *app, void *data,
1138 1146
 }
1139 1147
 
1140 1148
 /**
1141
- * Handle TCP connection closure
1149
+ * Handle stream connection closure
1142 1150
  *
1143
- * @v app		TCP application
1151
+ * @v app		Stream application
1144 1152
  * @v status		Error code, if any
1145 1153
  *
1146 1154
  */
1147
-static void iscsi_closed ( struct tcp_application *app, int status ) {
1148
-	struct iscsi_session *iscsi = tcp_to_iscsi ( app );
1155
+static void iscsi_closed ( struct stream_application *app, int status ) {
1156
+	struct iscsi_session *iscsi = stream_to_iscsi ( app );
1149 1157
 	int rc;
1150 1158
 
1151 1159
 	/* Even a graceful close counts as an error for iSCSI */
@@ -1159,26 +1167,34 @@ static void iscsi_closed ( struct tcp_application *app, int status ) {
1159 1167
 	if ( ++iscsi->retry_count <= ISCSI_MAX_RETRIES ) {
1160 1168
 		DBGC ( iscsi, "iSCSI %p retrying connection (retry #%d)\n",
1161 1169
 		       iscsi, iscsi->retry_count );
1162
-		if ( ( rc = tcp_connect ( app, &iscsi->target, 0 ) ) != 0 ) {
1163
-			DBGC ( iscsi, "iSCSI %p could not open TCP "
1164
-			       "connection: %s\n", iscsi, strerror ( rc ) );
1170
+		if ( ( rc = tcp_open ( app ) ) != 0 ) {
1171
+			DBGC ( iscsi, "iSCSI %p could not open stream: %s\n ",
1172
+			       iscsi, strerror ( rc ) );
1165 1173
 			iscsi_done ( iscsi, rc );
1174
+			return;
1175
+		}
1176
+		if ( ( rc = stream_connect ( app, &iscsi->target ) ) != 0 ){
1177
+			DBGC ( iscsi, "iSCSI %p could not connect: %s\n",
1178
+			       iscsi, strerror ( rc ) );
1179
+			iscsi_done ( iscsi, rc );
1180
+			return;
1166 1181
 		}
1167 1182
 	} else {
1168 1183
 		DBGC ( iscsi, "iSCSI %p retry count exceeded\n", iscsi );
1169 1184
 		iscsi->instant_rc = status;
1170 1185
 		iscsi_done ( iscsi, status );
1186
+		return;
1171 1187
 	}
1172 1188
 }
1173 1189
 
1174 1190
 /**
1175
- * Handle TCP connection opening
1191
+ * Handle stream connection opening
1176 1192
  *
1177
- * @v app		TCP application
1193
+ * @v app		Stream application
1178 1194
  *
1179 1195
  */
1180
-static void iscsi_connected ( struct tcp_application *app ) {
1181
-	struct iscsi_session *iscsi = tcp_to_iscsi ( app );
1196
+static void iscsi_connected ( struct stream_application *app ) {
1197
+	struct iscsi_session *iscsi = stream_to_iscsi ( app );
1182 1198
 
1183 1199
 	assert ( iscsi->rx_state == ISCSI_RX_BHS );
1184 1200
 	assert ( iscsi->rx_offset == 0 );
@@ -1194,8 +1210,8 @@ static void iscsi_connected ( struct tcp_application *app ) {
1194 1210
 	iscsi_start_login ( iscsi );
1195 1211
 }
1196 1212
 
1197
-/** iSCSI TCP operations */
1198
-static struct tcp_operations iscsi_tcp_operations = {
1213
+/** iSCSI stream operations */
1214
+static struct stream_application_operations iscsi_stream_operations = {
1199 1215
 	.closed		= iscsi_closed,
1200 1216
 	.connected	= iscsi_connected,
1201 1217
 	.acked		= iscsi_acked,
@@ -1224,14 +1240,19 @@ int iscsi_issue ( struct iscsi_session *iscsi, struct scsi_command *command,
1224 1240
 	} else if ( iscsi->status ) {
1225 1241
 		/* Session already open: issue command */
1226 1242
 		iscsi_start_command ( iscsi );
1227
-		tcp_senddata ( &iscsi->tcp );
1243
+		stream_kick ( &iscsi->stream );
1228 1244
 	} else {
1229 1245
 		/* Session not open: initiate login */
1230
-		iscsi->tcp.tcp_op = &iscsi_tcp_operations;
1231
-		if ( ( rc = tcp_connect ( &iscsi->tcp, &iscsi->target,
1232
-					  0 ) ) != 0 ) {
1233
-			DBGC ( iscsi, "iSCSI %p could not open TCP "
1234
-			       "connection: %s\n", iscsi, strerror ( rc ) );
1246
+		iscsi->stream.op = &iscsi_stream_operations;
1247
+		if ( ( rc = tcp_open ( &iscsi->stream ) ) != 0 ) {
1248
+			DBGC ( iscsi, "iSCSI %p could not open stream: %s\n ",
1249
+			       iscsi, strerror ( rc ) );
1250
+			return rc;
1251
+		}
1252
+		if ( ( rc = stream_connect ( &iscsi->stream,
1253
+					     &iscsi->target ) ) != 0 ) {
1254
+			DBGC ( iscsi, "iSCSI %p could not connect: %s\n",
1255
+			       iscsi, strerror ( rc ) );
1235 1256
 			return rc;
1236 1257
 		}
1237 1258
 	}

Laddar…
Avbryt
Spara