]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: protocol: make sure the connect_* functions always receive a dst
authorWilly Tarreau <w@1wt.eu>
Mon, 2 May 2022 15:45:12 +0000 (17:45 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 2 May 2022 15:47:31 +0000 (17:47 +0200)
Some of the protocol-level ->connect() functions currently dereference
the connection's destination address while others test it and return an
error. There's normally no more non-bogus code path that calls such
functions without a valid destination address on the connection, so
let's unify these functions and just place a BUG_ON() there, and drop
the useless test that's supposed to return an internal error.

src/proto_quic.c
src/proto_sockpair.c
src/proto_tcp.c
src/proto_uxst.c

index 2186aa5aa81bf85c15d1bbaf5f34552349bbd8df..5d9240cb774d0be863bb06ded2ccf321c24b0db2 100644 (file)
@@ -267,6 +267,8 @@ int quic_connect_server(struct connection *conn, int flags)
        struct conn_src *src;
        struct sockaddr_storage *addr;
 
+       BUG_ON(!conn->dst);
+
        conn->flags |= CO_FL_WAIT_L4_CONN; /* connection in progress */
 
        switch (obj_type(conn->target)) {
@@ -283,11 +285,6 @@ int quic_connect_server(struct connection *conn, int flags)
                return SF_ERR_INTERNAL;
        }
 
-       if (!conn->dst) {
-               conn->flags |= CO_FL_ERROR;
-               return SF_ERR_INTERNAL;
-       }
-
        fd = conn->handle.fd = sock_create_server_socket(conn);
 
        if (fd == -1) {
index a621ecbea2df6b84322f490c84f02d61e20b96ea..55d31febc076301903f38f910304443df7559025 100644 (file)
@@ -283,6 +283,8 @@ static int sockpair_connect_server(struct connection *conn, int flags)
 {
        int sv[2], fd, dst_fd = -1;
 
+       BUG_ON(!conn->dst);
+
        /* the FD is stored in the sockaddr struct */
        dst_fd = ((struct sockaddr_in *)conn->dst)->sin_addr.s_addr;
 
index a160b1b87af9bbab19c3b674d28cc8b70ad4a20e..77433b0e523a83c7222bcdfdbb92a82fbe36f420 100644 (file)
@@ -266,6 +266,8 @@ int tcp_connect_server(struct connection *conn, int flags)
        int use_fastopen = 0;
        struct sockaddr_storage *addr;
 
+       BUG_ON(!conn->dst);
+
        conn->flags |= CO_FL_WAIT_L4_CONN; /* connection in progress */
 
        switch (obj_type(conn->target)) {
@@ -290,11 +292,6 @@ int tcp_connect_server(struct connection *conn, int flags)
                return SF_ERR_INTERNAL;
        }
 
-       if (!conn->dst) {
-               conn->flags |= CO_FL_ERROR;
-               return SF_ERR_INTERNAL;
-       }
-
        fd = conn->handle.fd = sock_create_server_socket(conn);
 
        if (fd == -1) {
index cc98e0d5cd016c2835de20c29796f535af82f9d5..da39e69801dc327dedb6fe3f28e4cb2b911ecac0 100644 (file)
@@ -211,6 +211,8 @@ static int uxst_connect_server(struct connection *conn, int flags)
        struct server *srv;
        struct proxy *be;
 
+       BUG_ON(!conn->dst);
+
        switch (obj_type(conn->target)) {
        case OBJ_TYPE_PROXY:
                be = __objt_proxy(conn->target);