From: Willy Tarreau Date: Thu, 4 Oct 2012 18:20:46 +0000 (+0200) Subject: MEDIUM: connection: it's not the data layer's role to validate the connection X-Git-Tag: v1.5-dev13~209 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=665e6ee7aadef06b0fdf0c311808c68fb2a96bed;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/raw_sock.c b/src/raw_sock.c index 9298ed780f..52a48a5e4e 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 8bc5bbbb25..e857c129bb 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;