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.
diff --git a/src/proto_quic.c b/src/proto_quic.c
index 2186aa5..5d9240c 100644
--- a/src/proto_quic.c
+++ b/src/proto_quic.c
@@ -267,6 +267,8 @@
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 @@
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 a621ecb..55d31fe 100644
--- a/src/proto_sockpair.c
+++ b/src/proto_sockpair.c
@@ -283,6 +283,8 @@
{
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 a160b1b..77433b0 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -266,6 +266,8 @@
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 @@
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 cc98e0d..da39e69 100644
--- a/src/proto_uxst.c
+++ b/src/proto_uxst.c
@@ -211,6 +211,8 @@
struct server *srv;
struct proxy *be;
+ BUG_ON(!conn->dst);
+
switch (obj_type(conn->target)) {
case OBJ_TYPE_PROXY:
be = __objt_proxy(conn->target);