]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: connection: add an ->init function to data layer
authorWilly Tarreau <wtarreau@exceliance.fr>
Fri, 31 Aug 2012 11:54:11 +0000 (13:54 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 3 Sep 2012 18:47:34 +0000 (20:47 +0200)
SSL need to initialize the data layer before proceeding with data. At
the moment, this data layer is automatically initialized from itself,
which will not be possible once we extract connection from sessions
since we'll only create the data layer once the handshake is finished.

So let's have the application layer initialize the data layer before
using it.

include/proto/connection.h
include/types/connection.h
src/proto_tcp.c
src/session.c

index 7c8e2cb0d73e993957773b1cebe78f275efb2c06..007f9e26384a3354da16f9478fb0afe1f23ed470 100644 (file)
  */
 int conn_fd_handler(int fd);
 
+/* calls the init() function of the data layer if any. Returns <0 in case of
+ * error.
+ */
+static inline int conn_data_init(struct connection *conn)
+{
+       if (conn->data && conn->data->init)
+               return conn->data->init(conn);
+       return 0;
+}
+
 /* Calls the close() function of the data layer if any */
 static inline void conn_data_close(struct connection *conn)
 {
index 2fbd7793066001e338a12ee59358e46cb4d419cb..0e12bb5d16073c17c27876a1c4ec15093b4b2190 100644 (file)
@@ -143,6 +143,7 @@ struct data_ops {
        void (*shutr)(struct connection *, int);    /* shutr function */
        void (*shutw)(struct connection *, int);    /* shutw function */
        void (*close)(struct connection *);         /* close the data channel on the connection */
+       int  (*init)(struct connection *conn);      /* initialize the data layer */
 };
 
 /* app_cb describes read and write callbacks which are called upon detected I/O
index af9dbf95b0e7ce590b7b8ac8090933d7278fdda2..99741dc2dc18c99163a280c7a7b292202fb58b27 100644 (file)
@@ -458,6 +458,10 @@ int tcp_connect_server(struct connection *conn, int data)
        fdtab[fd].iocb = conn_fd_handler;
        fd_insert(fd);
        conn_sock_want_send(conn);  /* for connect status */
+
+       if (conn_data_init(conn) < 0)
+               return SN_ERR_RESOURCE;
+
        if (data)
                conn_data_want_send(conn);  /* prepare to send data if any */
 
index db13fc632540569d74b1ae8fcb2d7d0319b73991..6b784cfe38ca9eeab2daacf96d4203ff65c74225 100644 (file)
@@ -278,6 +278,8 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
        fdtab[cfd].flags = 0;
        fdtab[cfd].iocb = conn_fd_handler;
        conn_data_want_recv(&s->si[0].conn);
+       if (conn_data_init(&s->si[0].conn) < 0)
+               goto out_free_rep;
 
        if (p->accept && (ret = p->accept(s)) <= 0) {
                /* Either we had an unrecoverable error (<0) or work is