Browse Source

Changed to use the generic stream API.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
6d32f0e6e2

+ 5
- 5
src/include/gpxe/ftp.h View File

9
 
9
 
10
 #include <stdint.h>
10
 #include <stdint.h>
11
 #include <gpxe/async.h>
11
 #include <gpxe/async.h>
12
-#include <gpxe/tcp.h>
12
+#include <gpxe/stream.h>
13
 
13
 
14
 struct buffer;
14
 struct buffer;
15
 
15
 
57
 	char status_text[4];
57
 	char status_text[4];
58
 	/** Passive-mode parameters, as text */
58
 	/** Passive-mode parameters, as text */
59
 	char passive_text[24]; /* "aaa,bbb,ccc,ddd,eee,fff" */
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
 extern int ftp_get ( struct uri *uri, struct buffer *buffer,
66
 extern int ftp_get ( struct uri *uri, struct buffer *buffer,

+ 3
- 3
src/include/gpxe/http.h View File

8
  */
8
  */
9
 
9
 
10
 #include <stdint.h>
10
 #include <stdint.h>
11
-#include <gpxe/tcp.h>
11
+#include <gpxe/stream.h>
12
 #include <gpxe/async.h>
12
 #include <gpxe/async.h>
13
 #include <gpxe/linebuf.h>
13
 #include <gpxe/linebuf.h>
14
 #include <gpxe/uri.h>
14
 #include <gpxe/uri.h>
43
 
43
 
44
 	/** Server address */
44
 	/** Server address */
45
 	struct sockaddr server;
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
 	/** Number of bytes already sent */
48
 	/** Number of bytes already sent */
49
 	size_t tx_offset;
49
 	size_t tx_offset;
50
 	/** RX state */
50
 	/** RX state */

+ 4
- 4
src/include/gpxe/iscsi.h View File

8
  */
8
  */
9
 
9
 
10
 #include <stdint.h>
10
 #include <stdint.h>
11
-#include <gpxe/tcp.h>
11
+#include <gpxe/stream.h>
12
 #include <gpxe/async.h>
12
 #include <gpxe/async.h>
13
 #include <gpxe/scsi.h>
13
 #include <gpxe/scsi.h>
14
 #include <gpxe/chap.h>
14
 #include <gpxe/chap.h>
489
 	/** Initiator IQN */
489
 	/** Initiator IQN */
490
 	const char *initiator_iqn;
490
 	const char *initiator_iqn;
491
 	/** Target address */
491
 	/** Target address */
492
-	struct sockaddr_tcpip target;
492
+	struct sockaddr target;
493
 	/** Target IQN */
493
 	/** Target IQN */
494
 	const char *target_iqn;
494
 	const char *target_iqn;
495
 	/** Logical Unit Number (LUN) */
495
 	/** Logical Unit Number (LUN) */
499
 	/** Password */
499
 	/** Password */
500
 	const char *password;
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
 	/** Session status
504
 	/** Session status
505
 	 *
505
 	 *
506
 	 * This is the bitwise-OR of zero or more ISCSI_STATUS_XXX
506
 	 * This is the bitwise-OR of zero or more ISCSI_STATUS_XXX

+ 5
- 2
src/include/gpxe/stream.h View File

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

+ 2
- 99
src/include/gpxe/tcp.h View File

11
 
11
 
12
 #include "latch.h"
12
 #include "latch.h"
13
 #include <gpxe/tcpip.h>
13
 #include <gpxe/tcpip.h>
14
+#include <gpxe/stream.h>
14
 
15
 
15
 /**
16
 /**
16
  * A TCP header
17
  * A TCP header
252
  */
253
  */
253
 #define TCP_MSL ( 2 * 60 * TICKS_PER_SEC )
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
 extern struct tcpip_protocol tcp_protocol;
258
 extern struct tcpip_protocol tcp_protocol;
356
 
259
 

+ 48
- 6
src/net/stream.c View File

25
 #include <stdint.h>
25
 #include <stdint.h>
26
 #include <string.h>
26
 #include <string.h>
27
 #include <errno.h>
27
 #include <errno.h>
28
+#include <assert.h>
28
 #include <gpxe/stream.h>
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
  * Connection established
49
  * Connection established
32
  *
50
  *
45
 	}
63
 	}
46
 
64
 
47
 	/* Hand off to application */
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
 		return;
85
 		return;
67
 	}
86
 	}
68
 
87
 
88
+	/* Disassociate application from connection */
89
+	app->conn = NULL;
90
+	conn->app = NULL;
91
+
69
 	/* Hand off to application */
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
 	}
115
 	}
92
 
116
 
93
 	/* Hand off to application */
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
 	}
141
 	}
117
 
142
 
118
 	/* Hand off to application */
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
 	}
166
 	}
141
 
167
 
142
 	/* Hand off to application */
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
 	}
190
 	}
164
 
191
 
165
 	/* Hand off to connection */
192
 	/* Hand off to connection */
193
+	if ( ! conn->op->bind )
194
+		return -ENOTSUP;
166
 	if ( ( rc = conn->op->bind ( conn, local ) ) != 0 ) {
195
 	if ( ( rc = conn->op->bind ( conn, local ) ) != 0 ) {
167
 		DBGC ( app, "Stream %p failed to bind: %s\n",
196
 		DBGC ( app, "Stream %p failed to bind: %s\n",
168
 		       app, strerror ( rc ) );
197
 		       app, strerror ( rc ) );
192
 	}
221
 	}
193
 
222
 
194
 	/* Hand off to connection */
223
 	/* Hand off to connection */
224
+	if ( ! conn->op->connect )
225
+		return -ENOTSUP;
195
 	if ( ( rc = conn->op->connect ( conn, peer ) ) != 0 ) {
226
 	if ( ( rc = conn->op->connect ( conn, peer ) ) != 0 ) {
196
 		DBGC ( app, "Stream %p failed to connect: %s\n",
227
 		DBGC ( app, "Stream %p failed to connect: %s\n",
197
 		       app, strerror ( rc ) );
228
 		       app, strerror ( rc ) );
217
 		return;
248
 		return;
218
 	}
249
 	}
219
 
250
 
251
+	/* Disassociate application from connection */
252
+	app->conn = NULL;
253
+	conn->app = NULL;
254
+
220
 	/* Hand off to connection */
255
 	/* Hand off to connection */
256
+	if ( ! conn->op->close )
257
+		return;
221
 	conn->op->close ( conn );
258
 	conn->op->close ( conn );
222
 }
259
 }
223
 
260
 
232
  * This method should be called only in the context of an
269
  * This method should be called only in the context of an
233
  * application's senddata() method.
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
 	struct stream_connection *conn = app->conn;
274
 	struct stream_connection *conn = app->conn;
237
 	int rc;
275
 	int rc;
238
 
276
 
245
 	}
283
 	}
246
 
284
 
247
 	/* Hand off to connection */
285
 	/* Hand off to connection */
286
+	if ( ! conn->op->send )
287
+		return -ENOTSUP;
248
 	if ( ( rc = conn->op->send ( conn, data, len ) ) != 0 ) {
288
 	if ( ( rc = conn->op->send ( conn, data, len ) ) != 0 ) {
249
 		DBGC ( app, "Stream %p failed to send %zd bytes: %s\n",
289
 		DBGC ( app, "Stream %p failed to send %zd bytes: %s\n",
250
 		       app, len, strerror ( rc ) );
290
 		       app, len, strerror ( rc ) );
273
 	}
313
 	}
274
 
314
 
275
 	/* Hand off to connection */
315
 	/* Hand off to connection */
316
+	if ( ! conn->op->send )
317
+		return -ENOTSUP;
276
 	if ( ( rc = conn->op->kick ( conn ) ) != 0 ) {
318
 	if ( ( rc = conn->op->kick ( conn ) ) != 0 ) {
277
 		DBGC ( app, "Stream %p failed to kick connection: %s\n",
319
 		DBGC ( app, "Stream %p failed to kick connection: %s\n",
278
 		       app, strerror ( rc ) );
320
 		       app, strerror ( rc ) );

+ 272
- 299
src/net/tcp.c
File diff suppressed because it is too large
View File


+ 60
- 51
src/net/tcp/ftp.c View File

4
 #include <string.h>
4
 #include <string.h>
5
 #include <assert.h>
5
 #include <assert.h>
6
 #include <errno.h>
6
 #include <errno.h>
7
+#include <byteswap.h>
7
 #include <gpxe/async.h>
8
 #include <gpxe/async.h>
8
 #include <gpxe/buffer.h>
9
 #include <gpxe/buffer.h>
9
 #include <gpxe/uri.h>
10
 #include <gpxe/uri.h>
10
 #include <gpxe/download.h>
11
 #include <gpxe/download.h>
12
+#include <gpxe/tcp.h>
11
 #include <gpxe/ftp.h>
13
 #include <gpxe/ftp.h>
12
 
14
 
13
 /** @file
15
 /** @file
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
  * @ret ftp		FTP request
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
 
62
 
60
 	DBGC ( ftp, "FTP %p completed with status %d\n", ftp, rc );
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
 	/* Mark asynchronous operation as complete */
69
 	/* Mark asynchronous operation as complete */
67
 	async_done ( &ftp->async, rc );
70
 	async_done ( &ftp->async, rc );
70
 /**
73
 /**
71
  * Parse FTP byte sequence value
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
  * This parses an FTP byte sequence value (e.g. the "aaa,bbb,ccc,ddd"
80
  * This parses an FTP byte sequence value (e.g. the "aaa,bbb,ccc,ddd"
78
  * form for IP addresses in PORT commands) into a byte sequence.  @c
81
  * form for IP addresses in PORT commands) into a byte sequence.  @c
93
 /**
96
 /**
94
  * Handle an FTP control channel response
97
  * Handle an FTP control channel response
95
  *
98
  *
96
- * @v ftp	FTP request
99
+ * @v ftp		FTP request
97
  *
100
  *
98
  * This is called once we have received a complete response line.
101
  * This is called once we have received a complete response line.
99
  */
102
  */
121
 		char *ptr = ftp->passive_text;
124
 		char *ptr = ftp->passive_text;
122
 		union {
125
 		union {
123
 			struct sockaddr_in sin;
126
 			struct sockaddr_in sin;
124
-			struct sockaddr_tcpip st;
127
+			struct sockaddr sa;
125
 		} sa;
128
 		} sa;
126
 		int rc;
129
 		int rc;
127
 
130
 
130
 				  sizeof ( sa.sin.sin_addr ) );
133
 				  sizeof ( sa.sin.sin_addr ) );
131
 		ftp_parse_value ( &ptr, ( uint8_t * ) &sa.sin.sin_port,
134
 		ftp_parse_value ( &ptr, ( uint8_t * ) &sa.sin.sin_port,
132
 				  sizeof ( sa.sin.sin_port ) );
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
 			DBGC ( ftp, "FTP %p could not make data connection\n",
144
 			DBGC ( ftp, "FTP %p could not make data connection\n",
135
 			       ftp );
145
 			       ftp );
136
 			ftp_done ( ftp, rc );
146
 			ftp_done ( ftp, rc );
154
 /**
164
 /**
155
  * Handle new data arriving on FTP control channel
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
  * Data is collected until a complete line is received, at which point
171
  * Data is collected until a complete line is received, at which point
162
  * its information is passed to ftp_reply().
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
 			  void *data, size_t len ) {
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
 	char *recvbuf = ftp->recvbuf;
177
 	char *recvbuf = ftp->recvbuf;
168
 	size_t recvsize = ftp->recvsize;
178
 	size_t recvsize = ftp->recvsize;
169
 	char c;
179
 	char c;
210
 /**
220
 /**
211
  * Handle acknowledgement of data sent on FTP control channel
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
 	/* Mark off ACKed portion of the currently-transmitted data */
228
 	/* Mark off ACKed portion of the currently-transmitted data */
219
 	ftp->already_sent += len;
229
 	ftp->already_sent += len;
222
 /**
232
 /**
223
  * Construct data to send on FTP control channel
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
 			   void *buf, size_t len ) {
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
 	/* Send the as-yet-unACKed portion of the string for the
243
 	/* Send the as-yet-unACKed portion of the string for the
234
 	 * current state.
244
 	 * current state.
235
 	 */
245
 	 */
236
 	len = snprintf ( buf, len, ftp_strings[ftp->state], ftp->uri->path );
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
  * Handle control channel being closed
251
  * Handle control channel being closed
242
  *
252
  *
243
- * @v app		TCP application
253
+ * @v app		Stream application
244
  *
254
  *
245
  * When the control channel is closed, the data channel must also be
255
  * When the control channel is closed, the data channel must also be
246
  * closed, if it is currently open.
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
 	DBGC ( ftp, "FTP %p control connection closed: %s\n",
261
 	DBGC ( ftp, "FTP %p control connection closed: %s\n",
252
 	       ftp, strerror ( rc ) );
262
 	       ftp, strerror ( rc ) );
256
 }
266
 }
257
 
267
 
258
 /** FTP control channel operations */
268
 /** FTP control channel operations */
259
-static struct tcp_operations ftp_tcp_operations = {
269
+static struct stream_application_operations ftp_stream_operations = {
260
 	.closed		= ftp_closed,
270
 	.closed		= ftp_closed,
261
 	.acked		= ftp_acked,
271
 	.acked		= ftp_acked,
262
 	.newdata	= ftp_newdata,
272
 	.newdata	= ftp_newdata,
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
  * @ret ftp		FTP request
286
  * @ret ftp		FTP request
277
  */
287
  */
278
 static inline struct ftp_request *
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
  * Handle data channel being closed
294
  * Handle data channel being closed
285
  *
295
  *
286
- * @v app		TCP application
296
+ * @v app		Stream application
287
  *
297
  *
288
  * When the data channel is closed, the control channel should be left
298
  * When the data channel is closed, the control channel should be left
289
  * alone; the server will send a completion message via the control
299
  * alone; the server will send a completion message via the control
291
  *
301
  *
292
  * If the data channel is closed due to an error, we abort the request.
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
 	DBGC ( ftp, "FTP %p data connection closed: %s\n",
307
 	DBGC ( ftp, "FTP %p data connection closed: %s\n",
298
 	       ftp, strerror ( rc ) );
308
 	       ftp, strerror ( rc ) );
305
 /**
315
 /**
306
  * Handle new data arriving on the FTP data channel
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
 			       void *data, size_t len ) {
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
 	int rc;
325
 	int rc;
316
 
326
 
317
 	/* Fill data buffer */
327
 	/* Fill data buffer */
325
 }
335
 }
326
 
336
 
327
 /** FTP data channel operations */
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
 	.closed		= ftp_data_closed,
339
 	.closed		= ftp_data_closed,
330
 	.newdata	= ftp_data_newdata,
340
 	.newdata	= ftp_data_newdata,
331
 };
341
 };
353
 	.reap = ftp_reap,
363
 	.reap = ftp_reap,
354
 };
364
 };
355
 
365
 
356
-#warning "Quick name resolution hack"
357
-#include <byteswap.h>
358
-
359
 /**
366
 /**
360
  * Initiate an FTP connection
367
  * Initiate an FTP connection
361
  *
368
  *
387
 	ftp->already_sent = 0;
394
 	ftp->already_sent = 0;
388
 	ftp->recvbuf = ftp->status_text;
395
 	ftp->recvbuf = ftp->status_text;
389
 	ftp->recvsize = sizeof ( ftp->status_text ) - 1;
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
 #warning "Quick name resolution hack"
400
 #warning "Quick name resolution hack"
394
 	union {
401
 	union {
395
-		struct sockaddr_tcpip st;
402
+		struct sockaddr sa;
396
 		struct sockaddr_in sin;
403
 		struct sockaddr_in sin;
397
 	} server;
404
 	} server;
398
 	server.sin.sin_port = htons ( FTP_PORT );
405
 	server.sin.sin_port = htons ( FTP_PORT );
404
 
411
 
405
 	DBGC ( ftp, "FTP %p fetching %s\n", ftp, ftp->uri->path );
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
 		goto err;
417
 		goto err;
409
 
418
 
410
 	async_init ( &ftp->async, &ftp_async_operations, parent );
419
 	async_init ( &ftp->async, &ftp_async_operations, parent );

+ 29
- 21
src/net/tcp/http.c View File

36
 #include <gpxe/buffer.h>
36
 #include <gpxe/buffer.h>
37
 #include <gpxe/download.h>
37
 #include <gpxe/download.h>
38
 #include <gpxe/resolv.h>
38
 #include <gpxe/resolv.h>
39
+#include <gpxe/tcp.h>
39
 #include <gpxe/http.h>
40
 #include <gpxe/http.h>
40
 
41
 
41
 static struct async_operations http_async_operations;
42
 static struct async_operations http_async_operations;
42
 
43
 
43
 static inline struct http_request *
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
  */
55
  */
55
 static void http_done ( struct http_request *http, int rc ) {
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
 	/* Prevent further processing of any current packet */
61
 	/* Prevent further processing of any current packet */
61
 	http->rx_state = HTTP_RX_DEAD;
62
 	http->rx_state = HTTP_RX_DEAD;
271
  * @v data		New data
272
  * @v data		New data
272
  * @v len		Length of new data
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
 			   void *data, size_t len ) {
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
 	const char *buf = data;
278
 	const char *buf = data;
278
 	char *line;
279
 	char *line;
279
 	int rc;
280
 	int rc;
319
 /**
320
 /**
320
  * Send HTTP data
321
  * Send HTTP data
321
  *
322
  *
322
- * @v app		TCP application
323
+ * @v app		Stream application
323
  * @v buf		Temporary data buffer
324
  * @v buf		Temporary data buffer
324
  * @v len		Length of temporary data buffer
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
 			    void *buf, size_t len ) {
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
 	const char *path = http->uri->path;
330
 	const char *path = http->uri->path;
330
 	const char *host = http->uri->host;
331
 	const char *host = http->uri->host;
331
 
332
 
338
 			 "Host: %s\r\n"
339
 			 "Host: %s\r\n"
339
 			 "\r\n", path, host );
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
  * HTTP data acknowledged
347
  * HTTP data acknowledged
346
  *
348
  *
347
- * @v app		TCP application
349
+ * @v app		Stream application
348
  * @v len		Length of acknowledged data
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
 	http->tx_offset += len;
355
 	http->tx_offset += len;
354
 }
356
 }
356
 /**
358
 /**
357
  * HTTP connection closed by network stack
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
 	DBGC ( http, "HTTP %p connection closed: %s\n",
366
 	DBGC ( http, "HTTP %p connection closed: %s\n",
365
 	       http, strerror ( rc ) );
367
 	       http, strerror ( rc ) );
367
 	http_done ( http, rc );
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
 	.closed		= http_closed,
374
 	.closed		= http_closed,
373
 	.acked		= http_acked,
375
 	.acked		= http_acked,
374
 	.newdata	= http_newdata,
376
 	.newdata	= http_newdata,
395
 	http->uri = uri;
397
 	http->uri = uri;
396
 	http->buffer = buffer;
398
 	http->buffer = buffer;
397
 	async_init ( &http->async, &http_async_operations, parent );
399
 	async_init ( &http->async, &http_async_operations, parent );
400
+	http->stream.op = &http_stream_operations;
398
 
401
 
399
 	/* Start name resolution.  The download proper will start when
402
 	/* Start name resolution.  The download proper will start when
400
 	 * name resolution completes.
403
 	 * name resolution completes.
432
 	}
435
 	}
433
 
436
 
434
 	/* Otherwise, start the HTTP connection */
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
 	st->st_port = htons ( uri_port ( http->uri, HTTP_PORT ) );
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
 		       http, strerror ( rc ) );
447
 		       http, strerror ( rc ) );
440
 		http_done ( http, rc );
448
 		http_done ( http, rc );
441
 		return;
449
 		return;

+ 62
- 41
src/net/tcp/iscsi.c View File

26
 #include <gpxe/scsi.h>
26
 #include <gpxe/scsi.h>
27
 #include <gpxe/process.h>
27
 #include <gpxe/process.h>
28
 #include <gpxe/uaccess.h>
28
 #include <gpxe/uaccess.h>
29
+#include <gpxe/tcp.h>
29
 #include <gpxe/iscsi.h>
30
 #include <gpxe/iscsi.h>
30
 
31
 
31
 /** @file
32
 /** @file
85
  */
86
  */
86
 static void iscsi_close ( struct iscsi_session *iscsi ) {
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
 	/* Clear connection status */
92
 	/* Clear connection status */
92
 	iscsi->status = 0;
93
 	iscsi->status = 0;
338
 		len = remaining;
339
 		len = remaining;
339
 	copy_from_user ( buf, iscsi->command->data_out, offset, len );
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
 static void iscsi_tx_login_request ( struct iscsi_session *iscsi,
508
 static void iscsi_tx_login_request ( struct iscsi_session *iscsi,
508
 				     void *buf, size_t len ) {
509
 				     void *buf, size_t len ) {
509
 	len = iscsi_build_login_request_strings ( iscsi, buf, len );
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
 		   len - iscsi->tx_offset );
512
 		   len - iscsi->tx_offset );
512
 }
513
 }
513
 
514
 
750
 	if ( response->status_class == ISCSI_STATUS_REDIRECT ) {
751
 	if ( response->status_class == ISCSI_STATUS_REDIRECT ) {
751
 		DBGC ( iscsi, "iSCSI %p redirecting to new server\n", iscsi );
752
 		DBGC ( iscsi, "iSCSI %p redirecting to new server\n", iscsi );
752
 		iscsi_close ( iscsi );
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
 			iscsi_done ( iscsi, rc );
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
 		return;
767
 		return;
760
 	}
768
 	}
810
 
818
 
811
 /****************************************************************************
819
 /****************************************************************************
812
  *
820
  *
813
- * iSCSI to TCP interface
821
+ * iSCSI to stream interface
814
  *
822
  *
815
  */
823
  */
816
 
824
 
817
 static inline struct iscsi_session *
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
 }
897
 }
890
 
898
 
891
 /**
899
 /**
892
- * Handle TCP ACKs
900
+ * Handle stream ACKs
893
  *
901
  *
894
  * @v iscsi		iSCSI session
902
  * @v iscsi		iSCSI session
895
  * 
903
  * 
896
  * Updates iscsi->tx_offset and, if applicable, transitions to the
904
  * Updates iscsi->tx_offset and, if applicable, transitions to the
897
  * next TX state.
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
 	struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
909
 	struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
902
 	enum iscsi_tx_state next_state;
910
 	enum iscsi_tx_state next_state;
903
 	
911
 	
953
  * 
961
  * 
954
  * Constructs data to be sent for the current TX state
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
 			     void *buf, size_t len ) {
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
 	struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
967
 	struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
960
 	static const char pad[] = { '\0', '\0', '\0' };
968
 	static const char pad[] = { '\0', '\0', '\0' };
961
 
969
 
964
 		/* Nothing to send */
972
 		/* Nothing to send */
965
 		break;
973
 		break;
966
 	case ISCSI_TX_BHS:
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
 			   ( sizeof ( iscsi->tx_bhs ) - iscsi->tx_offset ) );
976
 			   ( sizeof ( iscsi->tx_bhs ) - iscsi->tx_offset ) );
969
 		break;
977
 		break;
970
 	case ISCSI_TX_AHS:
978
 	case ISCSI_TX_AHS:
975
 		iscsi_tx_data ( iscsi, buf, len );
983
 		iscsi_tx_data ( iscsi, buf, len );
976
 		break;
984
 		break;
977
 	case ISCSI_TX_DATA_PADDING:
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
 		break;
988
 		break;
981
 	default:
989
 	default:
982
 		assert ( 0 );
990
 		assert ( 0 );
1068
 /**
1076
 /**
1069
  * Receive new data
1077
  * Receive new data
1070
  *
1078
  *
1071
- * @v tcp		TCP application
1079
+ * @v stream		Stream application
1072
  * @v data		Received data
1080
  * @v data		Received data
1073
  * @v len		Length of received data
1081
  * @v len		Length of received data
1074
  *
1082
  *
1079
  * always has a full copy of the BHS available, even for portions of
1087
  * always has a full copy of the BHS available, even for portions of
1080
  * the data in different packets to the BHS.
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
 			    size_t len ) {
1091
 			    size_t len ) {
1084
-	struct iscsi_session *iscsi = tcp_to_iscsi ( app );
1092
+	struct iscsi_session *iscsi = stream_to_iscsi ( app );
1085
 	struct iscsi_bhs_common *common = &iscsi->rx_bhs.common;
1093
 	struct iscsi_bhs_common *common = &iscsi->rx_bhs.common;
1086
 	void ( *process ) ( struct iscsi_session *iscsi, void *data,
1094
 	void ( *process ) ( struct iscsi_session *iscsi, void *data,
1087
 			    size_t len, size_t remaining );
1095
 			    size_t len, size_t remaining );
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
  * @v status		Error code, if any
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
 	int rc;
1157
 	int rc;
1150
 
1158
 
1151
 	/* Even a graceful close counts as an error for iSCSI */
1159
 	/* Even a graceful close counts as an error for iSCSI */
1159
 	if ( ++iscsi->retry_count <= ISCSI_MAX_RETRIES ) {
1167
 	if ( ++iscsi->retry_count <= ISCSI_MAX_RETRIES ) {
1160
 		DBGC ( iscsi, "iSCSI %p retrying connection (retry #%d)\n",
1168
 		DBGC ( iscsi, "iSCSI %p retrying connection (retry #%d)\n",
1161
 		       iscsi, iscsi->retry_count );
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
 			iscsi_done ( iscsi, rc );
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
 	} else {
1182
 	} else {
1168
 		DBGC ( iscsi, "iSCSI %p retry count exceeded\n", iscsi );
1183
 		DBGC ( iscsi, "iSCSI %p retry count exceeded\n", iscsi );
1169
 		iscsi->instant_rc = status;
1184
 		iscsi->instant_rc = status;
1170
 		iscsi_done ( iscsi, status );
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
 	assert ( iscsi->rx_state == ISCSI_RX_BHS );
1199
 	assert ( iscsi->rx_state == ISCSI_RX_BHS );
1184
 	assert ( iscsi->rx_offset == 0 );
1200
 	assert ( iscsi->rx_offset == 0 );
1194
 	iscsi_start_login ( iscsi );
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
 	.closed		= iscsi_closed,
1215
 	.closed		= iscsi_closed,
1200
 	.connected	= iscsi_connected,
1216
 	.connected	= iscsi_connected,
1201
 	.acked		= iscsi_acked,
1217
 	.acked		= iscsi_acked,
1224
 	} else if ( iscsi->status ) {
1240
 	} else if ( iscsi->status ) {
1225
 		/* Session already open: issue command */
1241
 		/* Session already open: issue command */
1226
 		iscsi_start_command ( iscsi );
1242
 		iscsi_start_command ( iscsi );
1227
-		tcp_senddata ( &iscsi->tcp );
1243
+		stream_kick ( &iscsi->stream );
1228
 	} else {
1244
 	} else {
1229
 		/* Session not open: initiate login */
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
 			return rc;
1256
 			return rc;
1236
 		}
1257
 		}
1237
 	}
1258
 	}

Loading…
Cancel
Save