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.
This commit is contained in:
Willy Tarreau 2022-05-02 17:45:12 +02:00
parent 04e9acaef4
commit 158b6cf102
4 changed files with 8 additions and 10 deletions

View 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) {

View 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;

View 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) {

View 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);