summaryrefslogtreecommitdiffstats
path: root/src/net/tcp
diff options
context:
space:
mode:
authorMichael Brown2006-04-30 18:59:45 +0200
committerMichael Brown2006-04-30 18:59:45 +0200
commit9e1becaf8a2bd12b5f75ee77b6bb138992bb1a6c (patch)
tree0e4a50f1b14abc877b9d24736eff4d77b43a8d05 /src/net/tcp
parentHalf-way tidy (diff)
downloadipxe-9e1becaf8a2bd12b5f75ee77b6bb138992bb1a6c.tar.gz
ipxe-9e1becaf8a2bd12b5f75ee77b6bb138992bb1a6c.tar.xz
ipxe-9e1becaf8a2bd12b5f75ee77b6bb138992bb1a6c.zip
Merge TCP aborted(), timedout() and closed() methods into a single
closed() method with a reason code.
Diffstat (limited to 'src/net/tcp')
-rw-r--r--src/net/tcp/ftp.c144
-rw-r--r--src/net/tcp/hello.c22
2 files changed, 104 insertions, 62 deletions
diff --git a/src/net/tcp/ftp.c b/src/net/tcp/ftp.c
index dae1714a..46119cd7 100644
--- a/src/net/tcp/ftp.c
+++ b/src/net/tcp/ftp.c
@@ -12,6 +12,12 @@
*
*/
+/*****************************************************************************
+ *
+ * FTP control channel
+ *
+ */
+
/** An FTP control channel string */
struct ftp_string {
/** String format */
@@ -25,8 +31,18 @@ struct ftp_string {
off_t data_offset;
};
-#define ftp_string_offset( fieldname ) \
- offsetof ( struct ftp_request, fieldname )
+/** FTP control channel strings */
+static const struct ftp_string ftp_strings[] = {
+ [FTP_CONNECT] = { "", 0 },
+ [FTP_USER] = { "USER anonymous\r\n", 0 },
+ [FTP_PASS] = { "PASS etherboot@etherboot.org\r\n", 0 },
+ [FTP_TYPE] = { "TYPE I\r\n", 0 },
+ [FTP_PASV] = { "PASV\r\n", 0 },
+ [FTP_RETR] = { "RETR %s\r\n",
+ offsetof ( struct ftp_request, filename ) },
+ [FTP_QUIT] = { "QUIT\r\n", 0 },
+ [FTP_DONE] = { "", 0 },
+};
/**
* Get data associated with an FTP control channel string
@@ -40,23 +56,23 @@ static inline const void * ftp_string_data ( struct ftp_request *ftp,
return * ( ( void ** ) ( ( ( void * ) ftp ) + data_offset ) );
}
-/** FTP control channel strings */
-const struct ftp_string ftp_strings[] = {
- [FTP_CONNECT] = { "", 0 },
- [FTP_USER] = { "USER anonymous\r\n", 0 },
- [FTP_PASS] = { "PASS etherboot@etherboot.org\r\n", 0 },
- [FTP_TYPE] = { "TYPE I\r\n", 0 },
- [FTP_PASV] = { "PASV\r\n", 0 },
- [FTP_RETR] = { "RETR %s\r\n", ftp_string_offset ( filename ) },
- [FTP_QUIT] = { "QUIT\r\n", 0 },
- [FTP_DONE] = { "", 0 },
-};
-
-static inline struct ftp_request *
-tcp_to_ftp ( struct tcp_connection *conn ) {
+/**
+ * Get FTP request from control TCP connection
+ *
+ * @v conn TCP connection
+ * @ret ftp FTP request
+ */
+static inline struct ftp_request * tcp_to_ftp ( struct tcp_connection *conn ) {
return container_of ( conn, struct ftp_request, tcp );
}
+/**
+ * Mark FTP request as complete
+ *
+ * @v ftp FTP request
+ * @v complete Completion indicator
+ *
+ */
static void ftp_complete ( struct ftp_request *ftp, int complete ) {
ftp->complete = complete;
tcp_close ( &ftp->tcp_data );
@@ -87,7 +103,7 @@ static void ftp_parse_value ( char **text, uint8_t *value, size_t len ) {
}
/**
- * Handle a response from an FTP server
+ * Handle an FTP control channel response
*
* @v ftp FTP request
*
@@ -132,6 +148,16 @@ static void ftp_reply ( struct ftp_request *ftp ) {
ftp_complete ( ftp, -EPROTO );
}
+/**
+ * Handle new data arriving on FTP control channel
+ *
+ * @v conn TCP connection
+ * @v data New data
+ * @v len Length of new data
+ *
+ * Data is collected until a complete line is received, at which point
+ * its information is passed to ftp_reply().
+ */
static void ftp_newdata ( struct tcp_connection *conn,
void *data, size_t len ) {
struct ftp_request *ftp = tcp_to_ftp ( conn );
@@ -178,6 +204,11 @@ static void ftp_newdata ( struct tcp_connection *conn,
ftp->recvsize = recvsize;
}
+/**
+ * Handle acknowledgement of data sent on FTP control channel
+ *
+ * @v conn TCP connection
+ */
static void ftp_acked ( struct tcp_connection *conn, size_t len ) {
struct ftp_request *ftp = tcp_to_ftp ( conn );
@@ -185,6 +216,11 @@ static void ftp_acked ( struct tcp_connection *conn, size_t len ) {
ftp->already_sent += len;
}
+/**
+ * Construct data to send on FTP control channel
+ *
+ * @v conn TCP connection
+ */
static void ftp_senddata ( struct tcp_connection *conn ) {
struct ftp_request *ftp = tcp_to_ftp ( conn );
const struct ftp_string *string;
@@ -200,50 +236,72 @@ static void ftp_senddata ( struct tcp_connection *conn ) {
len - ftp->already_sent );
}
-static void ftp_aborted ( struct tcp_connection *conn ) {
- struct ftp_request *ftp = tcp_to_ftp ( conn );
-
- ftp_complete ( ftp, -ECONNABORTED );
-}
-
-static void ftp_timedout ( struct tcp_connection *conn ) {
- struct ftp_request *ftp = tcp_to_ftp ( conn );
-
- ftp_complete ( ftp, -ETIMEDOUT );
-}
-
-static void ftp_closed ( struct tcp_connection *conn ) {
+/**
+ * Handle control channel being closed
+ *
+ * @v conn TCP connection
+ *
+ * When the control channel is closed, the data channel must also be
+ * closed, if it is currently open.
+ */
+static void ftp_closed ( struct tcp_connection *conn, int status ) {
struct ftp_request *ftp = tcp_to_ftp ( conn );
- ftp_complete ( ftp, 1 );
+ ftp_complete ( ftp, status ? status : 1 );
}
+/** FTP control channel operations */
static struct tcp_operations ftp_tcp_operations = {
- .aborted = ftp_aborted,
- .timedout = ftp_timedout,
.closed = ftp_closed,
.acked = ftp_acked,
.newdata = ftp_newdata,
.senddata = ftp_senddata,
};
+/*****************************************************************************
+ *
+ * FTP control channel
+ *
+ */
+
+/**
+ * Get FTP request from data TCP connection
+ *
+ * @v conn TCP connection
+ * @ret ftp FTP request
+ */
static inline struct ftp_request *
tcp_to_ftp_data ( struct tcp_connection *conn ) {
return container_of ( conn, struct ftp_request, tcp_data );
}
-static void ftp_data_aborted ( struct tcp_connection *conn ) {
- struct ftp_request *ftp = tcp_to_ftp_data ( conn );
-
- ftp_complete ( ftp, -ECONNABORTED );
-}
-
-static void ftp_data_timedout ( struct tcp_connection *conn ) {
+/**
+ * Handle data channel being closed
+ *
+ * @v conn TCP connection
+ *
+ * When the data channel is closed, the control channel should be left
+ * alone; the server will send a completion message via the control
+ * channel which we'll pick up.
+ *
+ * If the data channel is closed due to an error, we abort the request.
+ */
+static void ftp_data_closed ( struct tcp_connection *conn, int status ) {
struct ftp_request *ftp = tcp_to_ftp_data ( conn );
- ftp_complete ( ftp, -ETIMEDOUT );
+ if ( status )
+ ftp_complete ( ftp, status );
}
+/**
+ * Handle new data arriving on the FTP data channel
+ *
+ * @v conn TCP connection
+ * @v data New data
+ * @v len Length of new data
+ *
+ * Data is handed off to the callback registered in the FTP request.
+ */
static void ftp_data_newdata ( struct tcp_connection *conn,
void *data, size_t len ) {
struct ftp_request *ftp = tcp_to_ftp_data ( conn );
@@ -251,9 +309,9 @@ static void ftp_data_newdata ( struct tcp_connection *conn,
ftp->callback ( data, len );
}
+/** FTP data channel operations */
static struct tcp_operations ftp_data_tcp_operations = {
- .aborted = ftp_data_aborted,
- .timedout = ftp_data_timedout,
+ .closed = ftp_data_closed,
.newdata = ftp_data_newdata,
};
diff --git a/src/net/tcp/hello.c b/src/net/tcp/hello.c
index 2407e686..baaf8c76 100644
--- a/src/net/tcp/hello.c
+++ b/src/net/tcp/hello.c
@@ -13,7 +13,7 @@
* message (hello_request::message). Any data received from the
* server will be passed to the callback function,
* hello_request::callback(), and once the connection has been closed,
- * hello_request::complete will be set to 1.
+ * hello_request::complete will be set to a non-zero value.
*
* To use this code, do something like:
*
@@ -49,24 +49,10 @@ tcp_to_hello ( struct tcp_connection *conn ) {
return container_of ( conn, struct hello_request, tcp );
}
-static void hello_aborted ( struct tcp_connection *conn ) {
+static void hello_closed ( struct tcp_connection *conn, int status ) {
struct hello_request *hello = tcp_to_hello ( conn );
- printf ( "Connection aborted\n" );
- hello->complete = 1;
-}
-
-static void hello_timedout ( struct tcp_connection *conn ) {
- struct hello_request *hello = tcp_to_hello ( conn );
-
- printf ( "Connection timed out\n" );
- hello->complete = 1;
-}
-
-static void hello_closed ( struct tcp_connection *conn ) {
- struct hello_request *hello = tcp_to_hello ( conn );
-
- hello->complete = 1;
+ hello->complete = ( status ? status : 1 );
}
static void hello_connected ( struct tcp_connection *conn ) {
@@ -113,8 +99,6 @@ static void hello_senddata ( struct tcp_connection *conn ) {
}
static struct tcp_operations hello_tcp_operations = {
- .aborted = hello_aborted,
- .timedout = hello_timedout,
.closed = hello_closed,
.connected = hello_connected,
.acked = hello_acked,