david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

Changed to use the generic stream API.

This commit is contained in:
Michael Brown 2007-01-31 02:09:13 +00:00
parent 02f18565da
commit 6d32f0e6e2
10 changed files with 500 additions and 541 deletions

View File

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

View File

@ -8,7 +8,7 @@
*/ */
#include <stdint.h> #include <stdint.h>
#include <gpxe/tcp.h> #include <gpxe/stream.h>
#include <gpxe/async.h> #include <gpxe/async.h>
#include <gpxe/linebuf.h> #include <gpxe/linebuf.h>
#include <gpxe/uri.h> #include <gpxe/uri.h>
@ -43,8 +43,8 @@ struct http_request {
/** Server address */ /** Server address */
struct sockaddr server; struct sockaddr server;
/** TCP application for this request */ /** Stream application for this request */
struct tcp_application tcp; struct stream_application stream;
/** Number of bytes already sent */ /** Number of bytes already sent */
size_t tx_offset; size_t tx_offset;
/** RX state */ /** RX state */

View File

@ -8,7 +8,7 @@
*/ */
#include <stdint.h> #include <stdint.h>
#include <gpxe/tcp.h> #include <gpxe/stream.h>
#include <gpxe/async.h> #include <gpxe/async.h>
#include <gpxe/scsi.h> #include <gpxe/scsi.h>
#include <gpxe/chap.h> #include <gpxe/chap.h>
@ -489,7 +489,7 @@ struct iscsi_session {
/** Initiator IQN */ /** Initiator IQN */
const char *initiator_iqn; const char *initiator_iqn;
/** Target address */ /** Target address */
struct sockaddr_tcpip target; struct sockaddr target;
/** Target IQN */ /** Target IQN */
const char *target_iqn; const char *target_iqn;
/** Logical Unit Number (LUN) */ /** Logical Unit Number (LUN) */
@ -499,8 +499,8 @@ struct iscsi_session {
/** Password */ /** Password */
const char *password; const char *password;
/** TCP application for this session */ /** Stream application for this session */
struct tcp_application tcp; struct stream_application stream;
/** Session status /** Session status
* *
* This is the bitwise-OR of zero or more ISCSI_STATUS_XXX * This is the bitwise-OR of zero or more ISCSI_STATUS_XXX

View File

@ -125,7 +125,7 @@ struct stream_connection_operations {
* application's senddata() method. * application's senddata() method.
*/ */
int ( * send ) ( struct stream_connection *conn, int ( * send ) ( struct stream_connection *conn,
void *data, size_t len ); const void *data, size_t len );
/** /**
* Notify connection that data is available to send * Notify connection that data is available to send
* *
@ -167,6 +167,9 @@ struct stream_connection {
struct stream_connection_operations *op; struct stream_connection_operations *op;
}; };
extern void stream_associate ( struct stream_application *app,
struct stream_connection *conn );
extern void stream_connected ( struct stream_connection *conn ); extern void stream_connected ( struct stream_connection *conn );
extern void stream_closed ( struct stream_connection *conn, int rc ); extern void stream_closed ( struct stream_connection *conn, int rc );
extern void stream_senddata ( struct stream_connection *conn, extern void stream_senddata ( struct stream_connection *conn,
@ -181,7 +184,7 @@ extern int stream_connect ( struct stream_application *app,
struct sockaddr *peer ); struct sockaddr *peer );
extern void stream_close ( struct stream_application *app ); extern void stream_close ( struct stream_application *app );
extern int stream_send ( struct stream_application *app, extern int stream_send ( struct stream_application *app,
void *data, size_t len ); const void *data, size_t len );
extern int stream_kick ( struct stream_application *app ); extern int stream_kick ( struct stream_application *app );
#endif /* _GPXE_STREAM_H */ #endif /* _GPXE_STREAM_H */

View File

@ -11,6 +11,7 @@
#include "latch.h" #include "latch.h"
#include <gpxe/tcpip.h> #include <gpxe/tcpip.h>
#include <gpxe/stream.h>
/** /**
* A TCP header * A TCP header
@ -252,105 +253,7 @@ struct tcp_mss_option {
*/ */
#define TCP_MSL ( 2 * 60 * TICKS_PER_SEC ) #define TCP_MSL ( 2 * 60 * TICKS_PER_SEC )
struct tcp_application; extern int tcp_open ( struct stream_application *app );
/**
* TCP operations
*
*/
struct tcp_operations {
/*
* Connection closed
*
* @v app TCP application
* @v status Error code, if any
*
* This is called when the connection is closed for any
* reason, including timeouts or aborts. The status code
* contains the negative error number, if the closure is due
* to an error.
*
* When closed() is called, the application no longer has a
* valid TCP connection. Note that connected() may not have
* been called before closed(), if the close is due to an
* error during connection setup.
*/
void ( * closed ) ( struct tcp_application *app, int status );
/**
* Connection established
*
* @v app TCP application
*/
void ( * connected ) ( struct tcp_application *app );
/**
* Data acknowledged
*
* @v app TCP application
* @v len Length of acknowledged data
*
* @c len is guaranteed to not exceed the outstanding amount
* of unacknowledged data.
*/
void ( * acked ) ( struct tcp_application *app, size_t len );
/**
* New data received
*
* @v app TCP application
* @v data Data
* @v len Length of data
*/
void ( * newdata ) ( struct tcp_application *app,
void *data, size_t len );
/**
* Transmit data
*
* @v app TCP application
* @v buf Temporary data buffer
* @v len Length of temporary data buffer
*
* The application should transmit whatever it currently wants
* to send using tcp_send(). If retransmissions are required,
* senddata() will be called again and the application must
* regenerate the data. The easiest way to implement this is
* to ensure that senddata() never changes the application's
* state.
*
* The application may use the temporary data buffer to
* construct the data to be sent. Note that merely filling
* the buffer will do nothing; the application must call
* tcp_send() in order to actually transmit the data. Use of
* the buffer is not compulsory; the application may call
* tcp_send() on any block of data.
*/
void ( * senddata ) ( struct tcp_application *app, void *buf,
size_t len );
};
struct tcp_connection;
/**
* A TCP application
*
* This data structure represents an application with a TCP connection.
*/
struct tcp_application {
/** TCP connection data
*
* This is filled in by TCP calls that initiate a connection,
* and reset to NULL when the connection is closed.
*/
struct tcp_connection *conn;
/** TCP connection operations table */
struct tcp_operations *tcp_op;
};
extern int tcp_connect ( struct tcp_application *app,
struct sockaddr_tcpip *peer,
uint16_t local_port );
extern void tcp_close ( struct tcp_application *app );
extern int tcp_senddata ( struct tcp_application *app );
extern int tcp_send ( struct tcp_application *app, const void *data,
size_t len );
extern struct tcpip_protocol tcp_protocol; extern struct tcpip_protocol tcp_protocol;

View File

@ -25,8 +25,26 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <assert.h>
#include <gpxe/stream.h> #include <gpxe/stream.h>
/**
* Associate application with connection
*
* @v app Stream application
* @v conn Stream connection
*/
void stream_associate ( struct stream_application *app,
struct stream_connection *conn ) {
DBGC ( app, "Stream %p associating with connection %p\n", app, conn );
assert ( conn->app == NULL );
assert ( app->conn == NULL );
conn->app = app;
app->conn = conn;
}
/** /**
* Connection established * Connection established
* *
@ -45,7 +63,8 @@ void stream_connected ( struct stream_connection *conn ) {
} }
/* Hand off to application */ /* Hand off to application */
app->op->connected ( app ); if ( app->op->connected )
app->op->connected ( app );
} }
/** /**
@ -66,8 +85,13 @@ void stream_closed ( struct stream_connection *conn, int rc ) {
return; return;
} }
/* Disassociate application from connection */
app->conn = NULL;
conn->app = NULL;
/* Hand off to application */ /* Hand off to application */
app->op->closed ( app, rc ); if ( app->op->closed )
app->op->closed ( app, rc );
} }
/** /**
@ -91,7 +115,8 @@ void stream_senddata ( struct stream_connection *conn,
} }
/* Hand off to application */ /* Hand off to application */
app->op->senddata ( app, data, len ); if ( app->op->senddata )
app->op->senddata ( app, data, len );
} }
/** /**
@ -116,7 +141,8 @@ void stream_acked ( struct stream_connection *conn, size_t len ) {
} }
/* Hand off to application */ /* Hand off to application */
app->op->acked ( app, len ); if ( app->op->acked )
app->op->acked ( app, len );
} }
/** /**
@ -140,7 +166,8 @@ void stream_newdata ( struct stream_connection *conn,
} }
/* Hand off to application */ /* Hand off to application */
app->op->newdata ( app, data, len ); if ( app->op->newdata )
app->op->newdata ( app, data, len );
} }
/** /**
@ -163,6 +190,8 @@ int stream_bind ( struct stream_application *app, struct sockaddr *local ) {
} }
/* Hand off to connection */ /* Hand off to connection */
if ( ! conn->op->bind )
return -ENOTSUP;
if ( ( rc = conn->op->bind ( conn, local ) ) != 0 ) { if ( ( rc = conn->op->bind ( conn, local ) ) != 0 ) {
DBGC ( app, "Stream %p failed to bind: %s\n", DBGC ( app, "Stream %p failed to bind: %s\n",
app, strerror ( rc ) ); app, strerror ( rc ) );
@ -192,6 +221,8 @@ int stream_connect ( struct stream_application *app, struct sockaddr *peer ) {
} }
/* Hand off to connection */ /* Hand off to connection */
if ( ! conn->op->connect )
return -ENOTSUP;
if ( ( rc = conn->op->connect ( conn, peer ) ) != 0 ) { if ( ( rc = conn->op->connect ( conn, peer ) ) != 0 ) {
DBGC ( app, "Stream %p failed to connect: %s\n", DBGC ( app, "Stream %p failed to connect: %s\n",
app, strerror ( rc ) ); app, strerror ( rc ) );
@ -217,7 +248,13 @@ void stream_close ( struct stream_application *app ) {
return; return;
} }
/* Disassociate application from connection */
app->conn = NULL;
conn->app = NULL;
/* Hand off to connection */ /* Hand off to connection */
if ( ! conn->op->close )
return;
conn->op->close ( conn ); conn->op->close ( conn );
} }
@ -232,7 +269,8 @@ void stream_close ( struct stream_application *app ) {
* This method should be called only in the context of an * This method should be called only in the context of an
* application's senddata() method. * application's senddata() method.
*/ */
int stream_send ( struct stream_application *app, void *data, size_t len ) { int stream_send ( struct stream_application *app,
const void *data, size_t len ) {
struct stream_connection *conn = app->conn; struct stream_connection *conn = app->conn;
int rc; int rc;
@ -245,6 +283,8 @@ int stream_send ( struct stream_application *app, void *data, size_t len ) {
} }
/* Hand off to connection */ /* Hand off to connection */
if ( ! conn->op->send )
return -ENOTSUP;
if ( ( rc = conn->op->send ( conn, data, len ) ) != 0 ) { if ( ( rc = conn->op->send ( conn, data, len ) ) != 0 ) {
DBGC ( app, "Stream %p failed to send %zd bytes: %s\n", DBGC ( app, "Stream %p failed to send %zd bytes: %s\n",
app, len, strerror ( rc ) ); app, len, strerror ( rc ) );
@ -273,6 +313,8 @@ int stream_kick ( struct stream_application *app ) {
} }
/* Hand off to connection */ /* Hand off to connection */
if ( ! conn->op->send )
return -ENOTSUP;
if ( ( rc = conn->op->kick ( conn ) ) != 0 ) { if ( ( rc = conn->op->kick ( conn ) ) != 0 ) {
DBGC ( app, "Stream %p failed to kick connection: %s\n", DBGC ( app, "Stream %p failed to kick connection: %s\n",
app, strerror ( rc ) ); app, strerror ( rc ) );

File diff suppressed because it is too large Load Diff

View File

@ -4,10 +4,12 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <byteswap.h>
#include <gpxe/async.h> #include <gpxe/async.h>
#include <gpxe/buffer.h> #include <gpxe/buffer.h>
#include <gpxe/uri.h> #include <gpxe/uri.h>
#include <gpxe/download.h> #include <gpxe/download.h>
#include <gpxe/tcp.h>
#include <gpxe/ftp.h> #include <gpxe/ftp.h>
/** @file /** @file
@ -40,13 +42,14 @@ static const char * ftp_strings[] = {
}; };
/** /**
* Get FTP request from control TCP application * Get FTP request from control stream application
* *
* @v app TCP application * @v app Stream application
* @ret ftp FTP request * @ret ftp FTP request
*/ */
static inline struct ftp_request * tcp_to_ftp ( struct tcp_application *app ) { static inline struct ftp_request *
return container_of ( app, struct ftp_request, tcp ); stream_to_ftp ( struct stream_application *app ) {
return container_of ( app, struct ftp_request, stream );
} }
/** /**
@ -59,9 +62,9 @@ static void ftp_done ( struct ftp_request *ftp, int rc ) {
DBGC ( ftp, "FTP %p completed with status %d\n", ftp, rc ); DBGC ( ftp, "FTP %p completed with status %d\n", ftp, rc );
/* Close both TCP connections */ /* Close both stream connections */
tcp_close ( &ftp->tcp ); stream_close ( &ftp->stream );
tcp_close ( &ftp->tcp_data ); stream_close ( &ftp->stream_data );
/* Mark asynchronous operation as complete */ /* Mark asynchronous operation as complete */
async_done ( &ftp->async, rc ); async_done ( &ftp->async, rc );
@ -70,9 +73,9 @@ static void ftp_done ( struct ftp_request *ftp, int rc ) {
/** /**
* Parse FTP byte sequence value * Parse FTP byte sequence value
* *
* @v text Text string * @v text Text string
* @v value Value buffer * @v value Value buffer
* @v len Length of value buffer * @v len Length of value buffer
* *
* This parses an FTP byte sequence value (e.g. the "aaa,bbb,ccc,ddd" * This parses an FTP byte sequence value (e.g. the "aaa,bbb,ccc,ddd"
* form for IP addresses in PORT commands) into a byte sequence. @c * 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 ) {
/** /**
* Handle an FTP control channel response * Handle an FTP control channel response
* *
* @v ftp FTP request * @v ftp FTP request
* *
* This is called once we have received a complete response line. * This is called once we have received a complete response line.
*/ */
@ -121,7 +124,7 @@ static void ftp_reply ( struct ftp_request *ftp ) {
char *ptr = ftp->passive_text; char *ptr = ftp->passive_text;
union { union {
struct sockaddr_in sin; struct sockaddr_in sin;
struct sockaddr_tcpip st; struct sockaddr sa;
} sa; } sa;
int rc; int rc;
@ -130,7 +133,14 @@ static void ftp_reply ( struct ftp_request *ftp ) {
sizeof ( sa.sin.sin_addr ) ); sizeof ( sa.sin.sin_addr ) );
ftp_parse_value ( &ptr, ( uint8_t * ) &sa.sin.sin_port, ftp_parse_value ( &ptr, ( uint8_t * ) &sa.sin.sin_port,
sizeof ( sa.sin.sin_port ) ); sizeof ( sa.sin.sin_port ) );
if ( ( rc = tcp_connect ( &ftp->tcp_data, &sa.st, 0 ) ) != 0 ){ if ( ( rc = tcp_open ( &ftp->stream_data ) ) != 0 ) {
DBGC ( ftp, "FTP %p could not open data connection\n",
ftp );
ftp_done ( ftp, rc );
return;
}
if ( ( rc = stream_connect ( &ftp->stream_data,
&sa.sa ) ) != 0 ){
DBGC ( ftp, "FTP %p could not make data connection\n", DBGC ( ftp, "FTP %p could not make data connection\n",
ftp ); ftp );
ftp_done ( ftp, rc ); ftp_done ( ftp, rc );
@ -154,16 +164,16 @@ static void ftp_reply ( struct ftp_request *ftp ) {
/** /**
* Handle new data arriving on FTP control channel * Handle new data arriving on FTP control channel
* *
* @v app TCP application * @v app Stream application
* @v data New data * @v data New data
* @v len Length of new data * @v len Length of new data
* *
* Data is collected until a complete line is received, at which point * Data is collected until a complete line is received, at which point
* its information is passed to ftp_reply(). * its information is passed to ftp_reply().
*/ */
static void ftp_newdata ( struct tcp_application *app, static void ftp_newdata ( struct stream_application *app,
void *data, size_t len ) { void *data, size_t len ) {
struct ftp_request *ftp = tcp_to_ftp ( app ); struct ftp_request *ftp = stream_to_ftp ( app );
char *recvbuf = ftp->recvbuf; char *recvbuf = ftp->recvbuf;
size_t recvsize = ftp->recvsize; size_t recvsize = ftp->recvsize;
char c; char c;
@ -210,10 +220,10 @@ static void ftp_newdata ( struct tcp_application *app,
/** /**
* Handle acknowledgement of data sent on FTP control channel * Handle acknowledgement of data sent on FTP control channel
* *
* @v app TCP application * @v app Stream application
*/ */
static void ftp_acked ( struct tcp_application *app, size_t len ) { static void ftp_acked ( struct stream_application *app, size_t len ) {
struct ftp_request *ftp = tcp_to_ftp ( app ); struct ftp_request *ftp = stream_to_ftp ( app );
/* Mark off ACKed portion of the currently-transmitted data */ /* Mark off ACKed portion of the currently-transmitted data */
ftp->already_sent += len; ftp->already_sent += len;
@ -222,31 +232,31 @@ static void ftp_acked ( struct tcp_application *app, size_t len ) {
/** /**
* Construct data to send on FTP control channel * Construct data to send on FTP control channel
* *
* @v app TCP application * @v app Stream application
* @v buf Temporary data buffer * @v buf Temporary data buffer
* @v len Length of temporary data buffer * @v len Length of temporary data buffer
*/ */
static void ftp_senddata ( struct tcp_application *app, static void ftp_senddata ( struct stream_application *app,
void *buf, size_t len ) { void *buf, size_t len ) {
struct ftp_request *ftp = tcp_to_ftp ( app ); struct ftp_request *ftp = stream_to_ftp ( app );
/* Send the as-yet-unACKed portion of the string for the /* Send the as-yet-unACKed portion of the string for the
* current state. * current state.
*/ */
len = snprintf ( buf, len, ftp_strings[ftp->state], ftp->uri->path ); len = snprintf ( buf, len, ftp_strings[ftp->state], ftp->uri->path );
tcp_send ( app, buf + ftp->already_sent, len - ftp->already_sent ); stream_send ( app, buf + ftp->already_sent, len - ftp->already_sent );
} }
/** /**
* Handle control channel being closed * Handle control channel being closed
* *
* @v app TCP application * @v app Stream application
* *
* When the control channel is closed, the data channel must also be * When the control channel is closed, the data channel must also be
* closed, if it is currently open. * closed, if it is currently open.
*/ */
static void ftp_closed ( struct tcp_application *app, int rc ) { static void ftp_closed ( struct stream_application *app, int rc ) {
struct ftp_request *ftp = tcp_to_ftp ( app ); struct ftp_request *ftp = stream_to_ftp ( app );
DBGC ( ftp, "FTP %p control connection closed: %s\n", DBGC ( ftp, "FTP %p control connection closed: %s\n",
ftp, strerror ( rc ) ); ftp, strerror ( rc ) );
@ -256,7 +266,7 @@ static void ftp_closed ( struct tcp_application *app, int rc ) {
} }
/** FTP control channel operations */ /** FTP control channel operations */
static struct tcp_operations ftp_tcp_operations = { static struct stream_application_operations ftp_stream_operations = {
.closed = ftp_closed, .closed = ftp_closed,
.acked = ftp_acked, .acked = ftp_acked,
.newdata = ftp_newdata, .newdata = ftp_newdata,
@ -270,20 +280,20 @@ static struct tcp_operations ftp_tcp_operations = {
*/ */
/** /**
* Get FTP request from data TCP application * Get FTP request from data stream application
* *
* @v app TCP application * @v app Stream application
* @ret ftp FTP request * @ret ftp FTP request
*/ */
static inline struct ftp_request * static inline struct ftp_request *
tcp_to_ftp_data ( struct tcp_application *app ) { stream_to_ftp_data ( struct stream_application *app ) {
return container_of ( app, struct ftp_request, tcp_data ); return container_of ( app, struct ftp_request, stream_data );
} }
/** /**
* Handle data channel being closed * Handle data channel being closed
* *
* @v app TCP application * @v app Stream application
* *
* When the data channel is closed, the control channel should be left * When the data channel is closed, the control channel should be left
* alone; the server will send a completion message via the control * alone; the server will send a completion message via the control
@ -291,8 +301,8 @@ tcp_to_ftp_data ( struct tcp_application *app ) {
* *
* If the data channel is closed due to an error, we abort the request. * If the data channel is closed due to an error, we abort the request.
*/ */
static void ftp_data_closed ( struct tcp_application *app, int rc ) { static void ftp_data_closed ( struct stream_application *app, int rc ) {
struct ftp_request *ftp = tcp_to_ftp_data ( app ); struct ftp_request *ftp = stream_to_ftp_data ( app );
DBGC ( ftp, "FTP %p data connection closed: %s\n", DBGC ( ftp, "FTP %p data connection closed: %s\n",
ftp, strerror ( rc ) ); ftp, strerror ( rc ) );
@ -305,13 +315,13 @@ static void ftp_data_closed ( struct tcp_application *app, int rc ) {
/** /**
* Handle new data arriving on the FTP data channel * Handle new data arriving on the FTP data channel
* *
* @v app TCP application * @v app Stream application
* @v data New data * @v data New data
* @v len Length of new data * @v len Length of new data
*/ */
static void ftp_data_newdata ( struct tcp_application *app, static void ftp_data_newdata ( struct stream_application *app,
void *data, size_t len ) { void *data, size_t len ) {
struct ftp_request *ftp = tcp_to_ftp_data ( app ); struct ftp_request *ftp = stream_to_ftp_data ( app );
int rc; int rc;
/* Fill data buffer */ /* Fill data buffer */
@ -325,7 +335,7 @@ static void ftp_data_newdata ( struct tcp_application *app,
} }
/** FTP data channel operations */ /** FTP data channel operations */
static struct tcp_operations ftp_data_tcp_operations = { static struct stream_application_operations ftp_data_stream_operations = {
.closed = ftp_data_closed, .closed = ftp_data_closed,
.newdata = ftp_data_newdata, .newdata = ftp_data_newdata,
}; };
@ -353,9 +363,6 @@ static struct async_operations ftp_async_operations = {
.reap = ftp_reap, .reap = ftp_reap,
}; };
#warning "Quick name resolution hack"
#include <byteswap.h>
/** /**
* Initiate an FTP connection * Initiate an FTP connection
* *
@ -387,12 +394,12 @@ int ftp_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
ftp->already_sent = 0; ftp->already_sent = 0;
ftp->recvbuf = ftp->status_text; ftp->recvbuf = ftp->status_text;
ftp->recvsize = sizeof ( ftp->status_text ) - 1; ftp->recvsize = sizeof ( ftp->status_text ) - 1;
ftp->tcp.tcp_op = &ftp_tcp_operations; ftp->stream.op = &ftp_stream_operations;
ftp->tcp_data.tcp_op = &ftp_data_tcp_operations; ftp->stream_data.op = &ftp_data_stream_operations;
#warning "Quick name resolution hack" #warning "Quick name resolution hack"
union { union {
struct sockaddr_tcpip st; struct sockaddr sa;
struct sockaddr_in sin; struct sockaddr_in sin;
} server; } server;
server.sin.sin_port = htons ( FTP_PORT ); server.sin.sin_port = htons ( FTP_PORT );
@ -404,7 +411,9 @@ int ftp_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
DBGC ( ftp, "FTP %p fetching %s\n", ftp, ftp->uri->path ); DBGC ( ftp, "FTP %p fetching %s\n", ftp, ftp->uri->path );
if ( ( rc = tcp_connect ( &ftp->tcp, &server.st, 0 ) ) != 0 ) if ( ( rc = tcp_open ( &ftp->stream ) ) != 0 )
goto err;
if ( ( rc = stream_connect ( &ftp->stream, &server.sa ) ) != 0 )
goto err; goto err;
async_init ( &ftp->async, &ftp_async_operations, parent ); async_init ( &ftp->async, &ftp_async_operations, parent );

View File

@ -36,13 +36,14 @@
#include <gpxe/buffer.h> #include <gpxe/buffer.h>
#include <gpxe/download.h> #include <gpxe/download.h>
#include <gpxe/resolv.h> #include <gpxe/resolv.h>
#include <gpxe/tcp.h>
#include <gpxe/http.h> #include <gpxe/http.h>
static struct async_operations http_async_operations; static struct async_operations http_async_operations;
static inline struct http_request * static inline struct http_request *
tcp_to_http ( struct tcp_application *app ) { stream_to_http ( struct stream_application *app ) {
return container_of ( app, struct http_request, tcp ); return container_of ( app, struct http_request, stream );
} }
/** /**
@ -54,8 +55,8 @@ tcp_to_http ( struct tcp_application *app ) {
*/ */
static void http_done ( struct http_request *http, int rc ) { static void http_done ( struct http_request *http, int rc ) {
/* Close TCP connection */ /* Close stream connection */
tcp_close ( &http->tcp ); stream_close ( &http->stream );
/* Prevent further processing of any current packet */ /* Prevent further processing of any current packet */
http->rx_state = HTTP_RX_DEAD; http->rx_state = HTTP_RX_DEAD;
@ -271,9 +272,9 @@ static void http_rx_data ( struct http_request *http,
* @v data New data * @v data New data
* @v len Length of new data * @v len Length of new data
*/ */
static void http_newdata ( struct tcp_application *app, static void http_newdata ( struct stream_application *app,
void *data, size_t len ) { void *data, size_t len ) {
struct http_request *http = tcp_to_http ( app ); struct http_request *http = stream_to_http ( app );
const char *buf = data; const char *buf = data;
char *line; char *line;
int rc; int rc;
@ -319,13 +320,13 @@ static void http_newdata ( struct tcp_application *app,
/** /**
* Send HTTP data * Send HTTP data
* *
* @v app TCP application * @v app Stream application
* @v buf Temporary data buffer * @v buf Temporary data buffer
* @v len Length of temporary data buffer * @v len Length of temporary data buffer
*/ */
static void http_senddata ( struct tcp_application *app, static void http_senddata ( struct stream_application *app,
void *buf, size_t len ) { void *buf, size_t len ) {
struct http_request *http = tcp_to_http ( app ); struct http_request *http = stream_to_http ( app );
const char *path = http->uri->path; const char *path = http->uri->path;
const char *host = http->uri->host; const char *host = http->uri->host;
@ -338,17 +339,18 @@ static void http_senddata ( struct tcp_application *app,
"Host: %s\r\n" "Host: %s\r\n"
"\r\n", path, host ); "\r\n", path, host );
tcp_send ( app, ( buf + http->tx_offset ), ( len - http->tx_offset ) ); stream_send ( app, ( buf + http->tx_offset ),
( len - http->tx_offset ) );
} }
/** /**
* HTTP data acknowledged * HTTP data acknowledged
* *
* @v app TCP application * @v app Stream application
* @v len Length of acknowledged data * @v len Length of acknowledged data
*/ */
static void http_acked ( struct tcp_application *app, size_t len ) { static void http_acked ( struct stream_application *app, size_t len ) {
struct http_request *http = tcp_to_http ( app ); struct http_request *http = stream_to_http ( app );
http->tx_offset += len; http->tx_offset += len;
} }
@ -356,10 +358,10 @@ static void http_acked ( struct tcp_application *app, size_t len ) {
/** /**
* HTTP connection closed by network stack * HTTP connection closed by network stack
* *
* @v app TCP application * @v app Stream application
*/ */
static void http_closed ( struct tcp_application *app, int rc ) { static void http_closed ( struct stream_application *app, int rc ) {
struct http_request *http = tcp_to_http ( app ); struct http_request *http = stream_to_http ( app );
DBGC ( http, "HTTP %p connection closed: %s\n", DBGC ( http, "HTTP %p connection closed: %s\n",
http, strerror ( rc ) ); http, strerror ( rc ) );
@ -367,8 +369,8 @@ static void http_closed ( struct tcp_application *app, int rc ) {
http_done ( http, rc ); http_done ( http, rc );
} }
/** HTTP TCP operations */ /** HTTP stream operations */
static struct tcp_operations http_tcp_operations = { static struct stream_application_operations http_stream_operations = {
.closed = http_closed, .closed = http_closed,
.acked = http_acked, .acked = http_acked,
.newdata = http_newdata, .newdata = http_newdata,
@ -395,6 +397,7 @@ int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
http->uri = uri; http->uri = uri;
http->buffer = buffer; http->buffer = buffer;
async_init ( &http->async, &http_async_operations, parent ); async_init ( &http->async, &http_async_operations, parent );
http->stream.op = &http_stream_operations;
/* Start name resolution. The download proper will start when /* Start name resolution. The download proper will start when
* name resolution completes. * name resolution completes.
@ -432,10 +435,15 @@ static void http_sigchld ( struct async *async, enum signal signal __unused ) {
} }
/* Otherwise, start the HTTP connection */ /* Otherwise, start the HTTP connection */
http->tcp.tcp_op = &http_tcp_operations; if ( ( rc = tcp_open ( &http->stream ) ) != 0 ) {
DBGC ( http, "HTTP %p could not open stream connection: %s\n",
http, strerror ( rc ) );
http_done ( http, rc );
return;
}
st->st_port = htons ( uri_port ( http->uri, HTTP_PORT ) ); st->st_port = htons ( uri_port ( http->uri, HTTP_PORT ) );
if ( ( rc = tcp_connect ( &http->tcp, st, 0 ) ) != 0 ) { if ( ( rc = stream_connect ( &http->stream, &http->server ) ) != 0 ) {
DBGC ( http, "HTTP %p could not open TCP connection: %s\n", DBGC ( http, "HTTP %p could not connect stream: %s\n",
http, strerror ( rc ) ); http, strerror ( rc ) );
http_done ( http, rc ); http_done ( http, rc );
return; return;

View File

@ -26,6 +26,7 @@
#include <gpxe/scsi.h> #include <gpxe/scsi.h>
#include <gpxe/process.h> #include <gpxe/process.h>
#include <gpxe/uaccess.h> #include <gpxe/uaccess.h>
#include <gpxe/tcp.h>
#include <gpxe/iscsi.h> #include <gpxe/iscsi.h>
/** @file /** @file
@ -85,8 +86,8 @@ static void iscsi_rx_buffered_data_done ( struct iscsi_session *iscsi ) {
*/ */
static void iscsi_close ( struct iscsi_session *iscsi ) { static void iscsi_close ( struct iscsi_session *iscsi ) {
/* Close TCP connection */ /* Close stream connection */
tcp_close ( &iscsi->tcp ); stream_close ( &iscsi->stream );
/* Clear connection status */ /* Clear connection status */
iscsi->status = 0; iscsi->status = 0;
@ -338,7 +339,7 @@ static void iscsi_tx_data_out ( struct iscsi_session *iscsi,
len = remaining; len = remaining;
copy_from_user ( buf, iscsi->command->data_out, offset, len ); copy_from_user ( buf, iscsi->command->data_out, offset, len );
tcp_send ( &iscsi->tcp, buf, len ); stream_send ( &iscsi->stream, buf, len );
} }
/**************************************************************************** /****************************************************************************
@ -507,7 +508,7 @@ static void iscsi_login_request_done ( struct iscsi_session *iscsi ) {
static void iscsi_tx_login_request ( struct iscsi_session *iscsi, static void iscsi_tx_login_request ( struct iscsi_session *iscsi,
void *buf, size_t len ) { void *buf, size_t len ) {
len = iscsi_build_login_request_strings ( iscsi, buf, len ); len = iscsi_build_login_request_strings ( iscsi, buf, len );
tcp_send ( &iscsi->tcp, buf + iscsi->tx_offset, stream_send ( &iscsi->stream, buf + iscsi->tx_offset,
len - iscsi->tx_offset ); len - iscsi->tx_offset );
} }
@ -750,11 +751,18 @@ static void iscsi_rx_login_response ( struct iscsi_session *iscsi, void *data,
if ( response->status_class == ISCSI_STATUS_REDIRECT ) { if ( response->status_class == ISCSI_STATUS_REDIRECT ) {
DBGC ( iscsi, "iSCSI %p redirecting to new server\n", iscsi ); DBGC ( iscsi, "iSCSI %p redirecting to new server\n", iscsi );
iscsi_close ( iscsi ); iscsi_close ( iscsi );
if ( ( rc = tcp_connect ( &iscsi->tcp, &iscsi->target, if ( ( rc = tcp_open ( &iscsi->stream ) ) != 0 ) {
0 ) ) != 0 ) { DBGC ( iscsi, "iSCSI %p could not open stream: %s\n ",
DBGC ( iscsi, "iSCSI %p could not open TCP " iscsi, strerror ( rc ) );
"connection: %s\n", iscsi, strerror ( rc ) );
iscsi_done ( iscsi, rc ); iscsi_done ( iscsi, rc );
return;
}
if ( ( rc = stream_connect ( &iscsi->stream,
&iscsi->target ) != 0 ) != 0 ) {
DBGC ( iscsi, "iSCSI %p could not connect: %s\n ",
iscsi, strerror ( rc ) );
iscsi_done ( iscsi, rc );
return;
} }
return; return;
} }
@ -810,13 +818,13 @@ static void iscsi_rx_login_response ( struct iscsi_session *iscsi, void *data,
/**************************************************************************** /****************************************************************************
* *
* iSCSI to TCP interface * iSCSI to stream interface
* *
*/ */
static inline struct iscsi_session * static inline struct iscsi_session *
tcp_to_iscsi ( struct tcp_application *app ) { stream_to_iscsi ( struct stream_application *app ) {
return container_of ( app, struct iscsi_session, tcp ); return container_of ( app, struct iscsi_session, stream );
} }
/** /**
@ -889,15 +897,15 @@ static void iscsi_tx_done ( struct iscsi_session *iscsi ) {
} }
/** /**
* Handle TCP ACKs * Handle stream ACKs
* *
* @v iscsi iSCSI session * @v iscsi iSCSI session
* *
* Updates iscsi->tx_offset and, if applicable, transitions to the * Updates iscsi->tx_offset and, if applicable, transitions to the
* next TX state. * next TX state.
*/ */
static void iscsi_acked ( struct tcp_application *app, size_t len ) { static void iscsi_acked ( struct stream_application *app, size_t len ) {
struct iscsi_session *iscsi = tcp_to_iscsi ( app ); struct iscsi_session *iscsi = stream_to_iscsi ( app );
struct iscsi_bhs_common *common = &iscsi->tx_bhs.common; struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
enum iscsi_tx_state next_state; enum iscsi_tx_state next_state;
@ -953,9 +961,9 @@ static void iscsi_acked ( struct tcp_application *app, size_t len ) {
* *
* Constructs data to be sent for the current TX state * Constructs data to be sent for the current TX state
*/ */
static void iscsi_senddata ( struct tcp_application *app, static void iscsi_senddata ( struct stream_application *app,
void *buf, size_t len ) { void *buf, size_t len ) {
struct iscsi_session *iscsi = tcp_to_iscsi ( app ); struct iscsi_session *iscsi = stream_to_iscsi ( app );
struct iscsi_bhs_common *common = &iscsi->tx_bhs.common; struct iscsi_bhs_common *common = &iscsi->tx_bhs.common;
static const char pad[] = { '\0', '\0', '\0' }; static const char pad[] = { '\0', '\0', '\0' };
@ -964,7 +972,7 @@ static void iscsi_senddata ( struct tcp_application *app,
/* Nothing to send */ /* Nothing to send */
break; break;
case ISCSI_TX_BHS: case ISCSI_TX_BHS:
tcp_send ( app, &iscsi->tx_bhs.bytes[iscsi->tx_offset], stream_send ( app, &iscsi->tx_bhs.bytes[iscsi->tx_offset],
( sizeof ( iscsi->tx_bhs ) - iscsi->tx_offset ) ); ( sizeof ( iscsi->tx_bhs ) - iscsi->tx_offset ) );
break; break;
case ISCSI_TX_AHS: case ISCSI_TX_AHS:
@ -975,8 +983,8 @@ static void iscsi_senddata ( struct tcp_application *app,
iscsi_tx_data ( iscsi, buf, len ); iscsi_tx_data ( iscsi, buf, len );
break; break;
case ISCSI_TX_DATA_PADDING: case ISCSI_TX_DATA_PADDING:
tcp_send ( app, pad, ( ISCSI_DATA_PAD_LEN ( common->lengths ) stream_send ( app, pad, ( ISCSI_DATA_PAD_LEN( common->lengths )
- iscsi->tx_offset ) ); - iscsi->tx_offset ) );
break; break;
default: default:
assert ( 0 ); assert ( 0 );
@ -1068,7 +1076,7 @@ static void iscsi_rx_bhs ( struct iscsi_session *iscsi, void *data,
/** /**
* Receive new data * Receive new data
* *
* @v tcp TCP application * @v stream Stream application
* @v data Received data * @v data Received data
* @v len Length of received data * @v len Length of received data
* *
@ -1079,9 +1087,9 @@ static void iscsi_rx_bhs ( struct iscsi_session *iscsi, void *data,
* always has a full copy of the BHS available, even for portions of * always has a full copy of the BHS available, even for portions of
* the data in different packets to the BHS. * the data in different packets to the BHS.
*/ */
static void iscsi_newdata ( struct tcp_application *app, void *data, static void iscsi_newdata ( struct stream_application *app, void *data,
size_t len ) { size_t len ) {
struct iscsi_session *iscsi = tcp_to_iscsi ( app ); struct iscsi_session *iscsi = stream_to_iscsi ( app );
struct iscsi_bhs_common *common = &iscsi->rx_bhs.common; struct iscsi_bhs_common *common = &iscsi->rx_bhs.common;
void ( *process ) ( struct iscsi_session *iscsi, void *data, void ( *process ) ( struct iscsi_session *iscsi, void *data,
size_t len, size_t remaining ); size_t len, size_t remaining );
@ -1138,14 +1146,14 @@ static void iscsi_newdata ( struct tcp_application *app, void *data,
} }
/** /**
* Handle TCP connection closure * Handle stream connection closure
* *
* @v app TCP application * @v app Stream application
* @v status Error code, if any * @v status Error code, if any
* *
*/ */
static void iscsi_closed ( struct tcp_application *app, int status ) { static void iscsi_closed ( struct stream_application *app, int status ) {
struct iscsi_session *iscsi = tcp_to_iscsi ( app ); struct iscsi_session *iscsi = stream_to_iscsi ( app );
int rc; int rc;
/* Even a graceful close counts as an error for iSCSI */ /* Even a graceful close counts as an error for iSCSI */
@ -1159,26 +1167,34 @@ static void iscsi_closed ( struct tcp_application *app, int status ) {
if ( ++iscsi->retry_count <= ISCSI_MAX_RETRIES ) { if ( ++iscsi->retry_count <= ISCSI_MAX_RETRIES ) {
DBGC ( iscsi, "iSCSI %p retrying connection (retry #%d)\n", DBGC ( iscsi, "iSCSI %p retrying connection (retry #%d)\n",
iscsi, iscsi->retry_count ); iscsi, iscsi->retry_count );
if ( ( rc = tcp_connect ( app, &iscsi->target, 0 ) ) != 0 ) { if ( ( rc = tcp_open ( app ) ) != 0 ) {
DBGC ( iscsi, "iSCSI %p could not open TCP " DBGC ( iscsi, "iSCSI %p could not open stream: %s\n ",
"connection: %s\n", iscsi, strerror ( rc ) ); iscsi, strerror ( rc ) );
iscsi_done ( iscsi, rc ); iscsi_done ( iscsi, rc );
return;
}
if ( ( rc = stream_connect ( app, &iscsi->target ) ) != 0 ){
DBGC ( iscsi, "iSCSI %p could not connect: %s\n",
iscsi, strerror ( rc ) );
iscsi_done ( iscsi, rc );
return;
} }
} else { } else {
DBGC ( iscsi, "iSCSI %p retry count exceeded\n", iscsi ); DBGC ( iscsi, "iSCSI %p retry count exceeded\n", iscsi );
iscsi->instant_rc = status; iscsi->instant_rc = status;
iscsi_done ( iscsi, status ); iscsi_done ( iscsi, status );
return;
} }
} }
/** /**
* Handle TCP connection opening * Handle stream connection opening
* *
* @v app TCP application * @v app Stream application
* *
*/ */
static void iscsi_connected ( struct tcp_application *app ) { static void iscsi_connected ( struct stream_application *app ) {
struct iscsi_session *iscsi = tcp_to_iscsi ( app ); struct iscsi_session *iscsi = stream_to_iscsi ( app );
assert ( iscsi->rx_state == ISCSI_RX_BHS ); assert ( iscsi->rx_state == ISCSI_RX_BHS );
assert ( iscsi->rx_offset == 0 ); assert ( iscsi->rx_offset == 0 );
@ -1194,8 +1210,8 @@ static void iscsi_connected ( struct tcp_application *app ) {
iscsi_start_login ( iscsi ); iscsi_start_login ( iscsi );
} }
/** iSCSI TCP operations */ /** iSCSI stream operations */
static struct tcp_operations iscsi_tcp_operations = { static struct stream_application_operations iscsi_stream_operations = {
.closed = iscsi_closed, .closed = iscsi_closed,
.connected = iscsi_connected, .connected = iscsi_connected,
.acked = iscsi_acked, .acked = iscsi_acked,
@ -1224,14 +1240,19 @@ int iscsi_issue ( struct iscsi_session *iscsi, struct scsi_command *command,
} else if ( iscsi->status ) { } else if ( iscsi->status ) {
/* Session already open: issue command */ /* Session already open: issue command */
iscsi_start_command ( iscsi ); iscsi_start_command ( iscsi );
tcp_senddata ( &iscsi->tcp ); stream_kick ( &iscsi->stream );
} else { } else {
/* Session not open: initiate login */ /* Session not open: initiate login */
iscsi->tcp.tcp_op = &iscsi_tcp_operations; iscsi->stream.op = &iscsi_stream_operations;
if ( ( rc = tcp_connect ( &iscsi->tcp, &iscsi->target, if ( ( rc = tcp_open ( &iscsi->stream ) ) != 0 ) {
0 ) ) != 0 ) { DBGC ( iscsi, "iSCSI %p could not open stream: %s\n ",
DBGC ( iscsi, "iSCSI %p could not open TCP " iscsi, strerror ( rc ) );
"connection: %s\n", iscsi, strerror ( rc ) ); return rc;
}
if ( ( rc = stream_connect ( &iscsi->stream,
&iscsi->target ) ) != 0 ) {
DBGC ( iscsi, "iSCSI %p could not connect: %s\n",
iscsi, strerror ( rc ) );
return rc; return rc;
} }
} }