From 665e6ee7aadef06b0fdf0c311808c68fb2a96bed Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 4 Oct 2012 20:20:46 +0200 Subject: [PATCH] MEDIUM: connection: it's not the data layer's role to validate the connection Till now we used to perform the L4_CONN check in the data layer (eg: stream interface) but that does not make sense, because some transport layers will imply that the connection is opened (eg: SSL), and also because the complexity to check for this is higher in the data layer than in the transport layer. This is so much true that some read0 cases did not validate the connection. So as of now, the transport layer is responsible for clearing L4_CONN when it detects an activity, and the data layer may safely rely on this flag. This only impacts a minor change in raw_sock and stream_interface for now. --- src/raw_sock.c | 11 +++++++++++ src/stream_interface.c | 6 ------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/raw_sock.c b/src/raw_sock.c index 9298ed780..52a48a5e4 100644 --- a/src/raw_sock.c +++ b/src/raw_sock.c @@ -156,10 +156,13 @@ int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int co } } /* while */ + if (unlikely(conn->flags & CO_FL_WAIT_L4_CONN) && retval) + conn->flags &= ~CO_FL_WAIT_L4_CONN; return retval; out_read0: conn_sock_read0(conn); + conn->flags &= ~CO_FL_WAIT_L4_CONN; return retval; } @@ -190,6 +193,8 @@ int raw_sock_from_pipe(struct connection *conn, struct pipe *pipe) done += ret; pipe->data -= ret; } + if (unlikely(conn->flags & CO_FL_WAIT_L4_CONN) && done) + conn->flags &= ~CO_FL_WAIT_L4_CONN; return done; } @@ -269,10 +274,14 @@ static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int coun break; } } + + if (unlikely(conn->flags & CO_FL_WAIT_L4_CONN) && done) + conn->flags &= ~CO_FL_WAIT_L4_CONN; return done; read0: conn_sock_read0(conn); + conn->flags &= ~CO_FL_WAIT_L4_CONN; return done; } @@ -330,6 +339,8 @@ static int raw_sock_from_buf(struct connection *conn, struct buffer *buf, int fl break; } } + if (unlikely(conn->flags & CO_FL_WAIT_L4_CONN) && done) + conn->flags &= ~CO_FL_WAIT_L4_CONN; return done; } diff --git a/src/stream_interface.c b/src/stream_interface.c index 8bc5bbbb2..e857c129b 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -721,9 +721,6 @@ static int si_conn_send_loop(struct connection *conn) if (ret <= 0) break; - if (si->conn.flags & CO_FL_WAIT_L4_CONN) - si->conn.flags &= ~CO_FL_WAIT_L4_CONN; - b->flags |= CF_WRITE_PARTIAL; if (!b->buf.o) { @@ -1049,9 +1046,6 @@ static void si_conn_recv_cb(struct connection *conn) b_adv(&b->buf, fwd); } - if (conn->flags & CO_FL_WAIT_L4_CONN) - conn->flags &= ~CO_FL_WAIT_L4_CONN; - b->flags |= CF_READ_PARTIAL; b->total += ret;