[tls] Use intf_insert() to add TLS to an interface
Restructure the use of add_tls() to insert a TLS filter onto an existing interface. This allows for the possibility of using add_tls() to start TLS on an existing connection (as used in several protocols which will negotiate the choice to use TLS before the ClientHello is sent). Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -236,7 +236,6 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
|
||||
struct http_connection *conn;
|
||||
struct http_scheme *scheme;
|
||||
struct sockaddr_tcpip server;
|
||||
struct interface *socket;
|
||||
unsigned int port;
|
||||
int rc;
|
||||
|
||||
@@ -296,15 +295,16 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
|
||||
/* Open socket */
|
||||
memset ( &server, 0, sizeof ( server ) );
|
||||
server.st_port = htons ( port );
|
||||
socket = &conn->socket;
|
||||
if ( scheme->filter &&
|
||||
( ( rc = scheme->filter ( socket, uri->host, &socket ) ) != 0 ) )
|
||||
goto err_filter;
|
||||
if ( ( rc = xfer_open_named_socket ( socket, SOCK_STREAM,
|
||||
if ( ( rc = xfer_open_named_socket ( &conn->socket, SOCK_STREAM,
|
||||
( struct sockaddr * ) &server,
|
||||
uri->host, NULL ) ) != 0 )
|
||||
goto err_open;
|
||||
|
||||
/* Add filter, if any */
|
||||
if ( scheme->filter &&
|
||||
( ( rc = scheme->filter ( &conn->socket, uri->host ) ) != 0 ) )
|
||||
goto err_filter;
|
||||
|
||||
/* Attach to parent interface, mortalise self, and return */
|
||||
intf_plug_plug ( &conn->xfer, xfer );
|
||||
ref_put ( &conn->refcnt );
|
||||
@@ -313,8 +313,8 @@ int http_connect ( struct interface *xfer, struct uri *uri ) {
|
||||
conn->scheme->name, conn->uri->host, port );
|
||||
return 0;
|
||||
|
||||
err_open:
|
||||
err_filter:
|
||||
err_open:
|
||||
DBGC2 ( conn, "HTTPCONN %p could not create %s://%s:%d: %s\n", conn,
|
||||
conn->scheme->name, conn->uri->host, port, strerror ( rc ) );
|
||||
http_conn_close ( conn, rc );
|
||||
|
||||
Reference in New Issue
Block a user