]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: connections: Implement a start() method in ssl_sock.
authorOlivier Houchard <cognet@ci0.org>
Fri, 5 Mar 2021 22:47:00 +0000 (23:47 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 19 Mar 2021 14:33:04 +0000 (15:33 +0100)
Add a start() method to ssl_sock. It is responsible with initiating the
SSL handshake, currently by just scheduling the tasklet, instead of doing
it in the init() method, when all the XPRT may not have been initialized.

src/ssl_sock.c

index ec74a0a2210cb8825714d668896dda13b14f7e42..debd05e6f576172261c798765730b8cf40924d3b 100644 (file)
@@ -5213,6 +5213,25 @@ int ssl_bio_and_sess_init(struct connection *conn, SSL_CTX *ssl_ctx,
        return -1;
 }
 
+/* This function is called when all the XPRT have been initialized. We can
+ * now attempt to start the SSL handshake.
+ */
+static int ssl_sock_start(struct connection *conn, void *xprt_ctx)
+{
+       struct ssl_sock_ctx *ctx = xprt_ctx;
+
+       if (ctx->xprt->start) {
+               int ret;
+
+               ret = ctx->xprt->start(conn, ctx->xprt_ctx);
+               if (ret < 0)
+                       return ret;
+       }
+       tasklet_wakeup(ctx->wait_event.tasklet);
+
+       return 0;
+}
+
 /*
  * This function is called if SSL * context is not yet allocated. The function
  * is designed to be called before any other data-layer operation and sets the
@@ -5289,8 +5308,6 @@ static int ssl_sock_init(struct connection *conn, void **xprt_ctx)
                _HA_ATOMIC_ADD(&sslconns, 1);
                _HA_ATOMIC_ADD(&totalsslconns, 1);
                *xprt_ctx = ctx;
-               /* Start the handshake */
-               tasklet_wakeup(ctx->wait_event.tasklet);
                return 0;
        }
        else if (objt_listener(conn->target)) {
@@ -5324,8 +5341,6 @@ static int ssl_sock_init(struct connection *conn, void **xprt_ctx)
                _HA_ATOMIC_ADD(&sslconns, 1);
                _HA_ATOMIC_ADD(&totalsslconns, 1);
                *xprt_ctx = ctx;
-               /* Start the handshake */
-               tasklet_wakeup(ctx->wait_event.tasklet);
                return 0;
        }
        /* don't know how to handle such a target */
@@ -6939,6 +6954,7 @@ struct xprt_ops ssl_sock = {
        .shutw    = ssl_sock_shutw,
        .close    = ssl_sock_close,
        .init     = ssl_sock_init,
+       .start    = ssl_sock_start,
        .prepare_bind_conf = ssl_sock_prepare_bind_conf,
        .destroy_bind_conf = ssl_sock_destroy_bind_conf,
        .prepare_srv = ssl_sock_prepare_srv_ctx,