Remove the now-totally-obsolete sockaddr_in field from tcp.h.
* remote server.
*/
void ( *callback ) ( char *data, size_t len );
+ /** Eventual return status */
+ int rc;
/** Asynchronous operation for this FTP operation */
struct async_operation aop;
*/
struct tcp_connection {
struct sockaddr_tcpip peer; /* Remote socket address */
-
- /* FIXME: this field should no longer be present */
- struct sockaddr_in sin;
-
uint16_t local_port; /* Local port, in network byte order */
int tcp_state; /* TCP state */
int tcp_lstate; /* Last TCP state */
extern struct tcpip_protocol tcp_protocol;
+static inline int tcp_closed ( struct tcp_connection *conn ) {
+ return ( conn->tcp_state == TCP_CLOSED );
+}
+
extern void tcp_init_conn ( struct tcp_connection *conn );
extern int tcp_connect ( struct tcp_connection *conn );
extern int tcp_connectto ( struct tcp_connection *conn,
return container_of ( conn, struct ftp_request, tcp );
}
+static void ftp_set_status ( struct ftp_request *ftp, int rc ) {
+ if ( ! ftp->rc )
+ ftp->rc = rc;
+}
+
+static void ftp_clear_status ( struct ftp_request *ftp ) {
+ ftp->rc = 0;
+}
+
/**
- * Mark FTP request as complete
+ * Mark FTP operation as complete
*
* @v ftp FTP request
- * @v rc Return status code
- *
*/
-static void ftp_done ( struct ftp_request *ftp, int rc ) {
- tcp_close ( &ftp->tcp_data );
- tcp_close ( &ftp->tcp );
- async_done ( &ftp->aop, rc );
+static void ftp_done ( struct ftp_request *ftp ) {
+ async_done ( &ftp->aop, ftp->rc );
}
/**
/* Open passive connection when we get "PASV" response */
if ( ftp->state == FTP_PASV ) {
char *ptr = ftp->passive_text;
-
- ftp_parse_value ( &ptr,
- ( uint8_t * ) &ftp->tcp_data.sin.sin_addr,
- sizeof ( ftp->tcp_data.sin.sin_addr ) );
- ftp_parse_value ( &ptr,
- ( uint8_t * ) &ftp->tcp_data.sin.sin_port,
- sizeof ( ftp->tcp_data.sin.sin_port ) );
+ struct sockaddr_in *sin =
+ ( struct sockaddr_in * ) &ftp->tcp_data.peer;
+
+ sin->sin_family = AF_INET;
+ ftp_parse_value ( &ptr, ( uint8_t * ) &sin->sin_addr,
+ sizeof ( sin->sin_addr ) );
+ ftp_parse_value ( &ptr, ( uint8_t * ) &sin->sin_port,
+ sizeof ( sin->sin_port ) );
tcp_connect ( &ftp->tcp_data );
}
err:
/* Flag protocol error and close connections */
- ftp_done ( ftp, -EPROTO );
+ ftp_set_status ( ftp, -EPROTO );
+ tcp_close ( &ftp->tcp );
}
/**
static void ftp_closed ( struct tcp_connection *conn, int status ) {
struct ftp_request *ftp = tcp_to_ftp ( conn );
- ftp_done ( ftp, status );
+ /* Close data channel and record status */
+ ftp_set_status ( ftp, status );
+ tcp_close ( &ftp->tcp_data );
+
+ /* Mark FTP operation as complete if we are the last
+ * connection to close
+ */
+ if ( tcp_closed ( &ftp->tcp_data ) )
+ ftp_done ( ftp );
}
/** FTP control channel operations */
*/
static void ftp_data_closed ( struct tcp_connection *conn, int status ) {
struct ftp_request *ftp = tcp_to_ftp_data ( conn );
+
+ /* If there was an error, close control channel and record status */
+ if ( status ) {
+ ftp_set_status ( ftp, status );
+ tcp_close ( &ftp->tcp );
+ }
- if ( status )
- ftp_done ( ftp, status );
+ /* Mark FTP operation as complete if we are the last
+ * connection to close
+ */
+ if ( tcp_closed ( &ftp->tcp ) )
+ ftp_done ( ftp );
}
/**
ftp->tcp_data.tcp_op = &ftp_data_tcp_operations;
ftp->recvbuf = ftp->status_text;
ftp->recvsize = sizeof ( ftp->status_text ) - 1;
+ ftp_clear_status ( ftp );
tcp_connect ( &ftp->tcp );
return &ftp->aop;
}
return test_aoeboot ( netdev, aoename, drivenum );
}
-static int test_dhcp_iscsi_boot ( struct net_device *netdev, char *iscsiname ) {
- char *initiator_iqn = "iqn.1900-01.localdomain.localhost:initiator";
+static int test_dhcp_iscsi_boot ( struct net_device *netdev,
+ char *iscsiname ) {
+ char initiator_iqn_buf[32];
+ char *initiator_iqn = initiator_iqn_buf;
char username[32];
char password[32];
char *target_iqn;
struct sockaddr_tcpip st;
} target;
unsigned int drivenum;
+ struct dhcp_option *option;
memset ( &target, 0, sizeof ( target ) );
target.sin.sin_family = AF_INET;
}
inet_aton ( iscsiname, &target.sin.sin_addr );
+ dhcp_snprintf ( initiator_iqn, sizeof ( initiator_iqn ),
+ find_global_dhcp_option ( DHCP_ISCSI_INITIATOR_IQN ) );
+ if ( ! *initiator_iqn )
+ initiator_iqn = "iqn.1900-01.localdomain.localhost:initiator";
dhcp_snprintf ( username, sizeof ( username ),
find_global_dhcp_option ( DHCP_EB_USERNAME ) );
dhcp_snprintf ( password, sizeof ( password ),
return 0;
}
+static int test_dhcp_ftp ( struct net_device *netdev, char *ftpname ) {
+ union {
+ struct sockaddr_in sin;
+ struct sockaddr_tcpip st;
+ } target;
+ char *filename;
+
+ filename = strchr ( ftpname, ':' );
+ if ( ! filename ) {
+ printf ( "Invalid FTP path \"%s\"\n", ftpname );
+ return -EINVAL;
+ }
+ *filename++ = '\0';
+
+ memset ( &target, 0, sizeof ( target ) );
+ target.sin.sin_family = AF_INET;
+ target.sin.sin_port = htons ( 21 );
+ inet_aton ( ftpname, &target.sin.sin_addr );
+
+ test_ftp ( &target, filename );
+ return 0;
+}
+
static int test_dhcp_tftp ( struct net_device *netdev, char *tftpname ) {
union {
struct sockaddr_in sin;
}
static int test_dhcp_boot ( struct net_device *netdev, char *filename ) {
+ /*
if ( strncmp ( filename, "aoe:", 4 ) == 0 ) {
return test_dhcp_aoe_boot ( netdev, &filename[4] );
- } else if ( strncmp ( filename, "iscsi:", 6 ) == 0 ) {
+ }
+ */
+ if ( strncmp ( filename, "iscsi:", 6 ) == 0 ) {
return test_dhcp_iscsi_boot ( netdev, &filename[6] );
- } else if ( strncmp ( filename, "hello:", 6 ) == 0 ) {
+ }
+ if ( strncmp ( filename, "ftp:", 4 ) == 0 ) {
+ return test_dhcp_ftp ( netdev, &filename[4] );
+ }
+ /*
+ if ( strncmp ( filename, "hello:", 6 ) == 0 ) {
return test_dhcp_hello ( &filename[6] );
- } else if ( strncmp ( filename, "http:", 5 ) == 0 ) {
+ }
+ if ( strncmp ( filename, "http:", 5 ) == 0 ) {
return test_dhcp_http ( netdev, filename );
- } else {
- return test_dhcp_tftp ( netdev, filename );
}
+ return test_dhcp_tftp ( netdev, filename );
+ */
+ return -EPROTONOSUPPORT;
}
int test_dhcp ( struct net_device *netdev ) {
}
}
-void test_ftp ( struct in_addr server, const char *filename ) {
+void test_ftp ( struct sockaddr_tcpip *server, const char *filename ) {
struct ftp_request ftp;
int rc;
- printf ( "FTP fetching %s:%s\n", inet_ntoa ( server ), filename );
+ printf ( "FTP fetching %s\n", filename );
memset ( &ftp, 0, sizeof ( ftp ) );
- ftp.tcp.sin.sin_addr.s_addr = server.s_addr;
- ftp.tcp.sin.sin_port = htons ( FTP_PORT );
+ memcpy ( &ftp.tcp.peer, server, sizeof ( ftp.tcp.peer ) );
ftp.filename = filename;
ftp.callback = test_ftp_callback;