From 158b6cf102d68f003f323a2f381239fcbb665a7e Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 2 May 2022 17:45:12 +0200 Subject: [PATCH] CLEANUP: protocol: make sure the connect_* functions always receive a dst 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 | 7 ++----- src/proto_sockpair.c | 2 ++ src/proto_tcp.c | 7 ++----- src/proto_uxst.c | 2 ++ 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/proto_quic.c b/src/proto_quic.c index 2186aa5aa..5d9240cb7 100644 --- a/src/proto_quic.c +++ b/src/proto_quic.c @@ -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) { diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c index a621ecbea..55d31febc 100644 --- a/src/proto_sockpair.c +++ b/src/proto_sockpair.c @@ -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; diff --git a/src/proto_tcp.c b/src/proto_tcp.c index a160b1b87..77433b0e5 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -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) { diff --git a/src/proto_uxst.c b/src/proto_uxst.c index cc98e0d5c..da39e6980 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -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);