MINOR: connection: get rid of the CO_FL_ADDR_*_SET flags
Just like for the conn_stream, now that these addresses are dynamically
allocated, there is no single case where the pointer is set without the
corresponding flag, and the flag is used as a permission to dereference
the pointer. Let's just replace the test of the flag with a test of the
pointer and remove all flag assignment. This makes the code clearer
(especially in "if" conditions) and saves the need for future code to
think about properly setting the flag after setting the pointer.
diff --git a/dev/flags/flags.c b/dev/flags/flags.c
index 2164a35..3bcbb7f 100644
--- a/dev/flags/flags.c
+++ b/dev/flags/flags.c
@@ -163,8 +163,6 @@
SHOW_FLAG(f, CO_FL_SOCKS4_SEND);
SHOW_FLAG(f, CO_FL_EARLY_DATA);
SHOW_FLAG(f, CO_FL_EARLY_SSL_HS);
- SHOW_FLAG(f, CO_FL_ADDR_TO_SET);
- SHOW_FLAG(f, CO_FL_ADDR_FROM_SET);
SHOW_FLAG(f, CO_FL_WAIT_ROOM);
SHOW_FLAG(f, CO_FL_WANT_DRAIN);
SHOW_FLAG(f, CO_FL_XPRT_READY);
diff --git a/include/haproxy/connection-t.h b/include/haproxy/connection-t.h
index 22160f3..77e31eb 100644
--- a/include/haproxy/connection-t.h
+++ b/include/haproxy/connection-t.h
@@ -100,8 +100,8 @@
CO_FL_WAIT_ROOM = 0x00000800, /* data sink is full */
/* These flags are used to report whether the from/to addresses are set or not */
- CO_FL_ADDR_FROM_SET = 0x00001000, /* addr.from is set */
- CO_FL_ADDR_TO_SET = 0x00002000, /* addr.to is set */
+ /* unused: 0x00001000 */
+ /* unused: 0x00002000 */
CO_FL_EARLY_SSL_HS = 0x00004000, /* We have early data pending, don't start SSL handshake yet */
CO_FL_EARLY_DATA = 0x00008000, /* At least some of the data are early data */
diff --git a/include/haproxy/connection.h b/include/haproxy/connection.h
index 8240a6d..30e689e 100644
--- a/include/haproxy/connection.h
+++ b/include/haproxy/connection.h
@@ -327,17 +327,13 @@
/* Returns the source address of the connection or NULL if not set */
static inline const struct sockaddr_storage *conn_src(struct connection *conn)
{
- if (conn->flags & CO_FL_ADDR_FROM_SET)
- return conn->src;
- return NULL;
+ return conn->src;
}
/* Returns the destination address of the connection or NULL if not set */
static inline const struct sockaddr_storage *conn_dst(struct connection *conn)
{
- if (conn->flags & CO_FL_ADDR_TO_SET)
- return conn->dst;
- return NULL;
+ return conn->dst;
}
/* Retrieves the connection's original source address. Returns non-zero on
@@ -346,7 +342,7 @@
*/
static inline int conn_get_src(struct connection *conn)
{
- if (conn->flags & CO_FL_ADDR_FROM_SET)
+ if (conn->src)
return 1;
if (!conn_ctrl_ready(conn))
@@ -375,7 +371,6 @@
sockaddr_free(&conn->src);
return 0;
done:
- conn->flags |= CO_FL_ADDR_FROM_SET;
return 1;
}
@@ -385,7 +380,7 @@
*/
static inline int conn_get_dst(struct connection *conn)
{
- if (conn->flags & CO_FL_ADDR_TO_SET)
+ if (conn->dst)
return 1;
if (!conn_ctrl_ready(conn))
@@ -414,7 +409,6 @@
sockaddr_free(&conn->dst);
return 0;
done:
- conn->flags |= CO_FL_ADDR_TO_SET;
return 1;
}
diff --git a/src/connection.c b/src/connection.c
index abe4fd6..e3e1bc8 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -2088,10 +2088,10 @@
chunk_appendf(buf, " %s/%s", conn_get_xprt_name(conn), conn_get_ctrl_name(conn));
- if (conn->flags & CO_FL_ADDR_FROM_SET && addr_to_str(conn->src, addr, sizeof(addr)))
+ if (conn->src && addr_to_str(conn->src, addr, sizeof(addr)))
chunk_appendf(buf, " src=%s:%d", addr, get_host_port(conn->src));
- if (conn->flags & CO_FL_ADDR_TO_SET && addr_to_str(conn->dst, addr, sizeof(addr)))
+ if (conn->dst && addr_to_str(conn->dst, addr, sizeof(addr)))
chunk_appendf(buf, " dst=%s:%d", addr, get_host_port(conn->dst));
return buf->data - old_len;
diff --git a/src/proto_quic.c b/src/proto_quic.c
index 5d9240c..5c20045 100644
--- a/src/proto_quic.c
+++ b/src/proto_quic.c
@@ -505,8 +505,6 @@
conn->flags &= ~CO_FL_WAIT_L4_CONN;
}
- conn->flags |= CO_FL_ADDR_TO_SET;
-
conn_ctrl_init(conn); /* registers the FD */
HA_ATOMIC_OR(&fdtab[fd].state, FD_LINGER_RISK); /* close hard if needed */
diff --git a/src/proto_sockpair.c b/src/proto_sockpair.c
index 55d31fe..9126fe6 100644
--- a/src/proto_sockpair.c
+++ b/src/proto_sockpair.c
@@ -352,8 +352,6 @@
conn->flags &= ~CO_FL_WAIT_L4_CONN;
- conn->flags |= CO_FL_ADDR_TO_SET;
-
/* Prepare to send a few handshakes related to the on-wire protocol. */
if (conn->send_proxy_ofs)
conn->flags |= CO_FL_SEND_PROXY;
@@ -484,7 +482,6 @@
/* just like with UNIX sockets, only the family is filled */
conn->src->ss_family = AF_UNIX;
conn->handle.fd = cfd;
- conn->flags |= CO_FL_ADDR_FROM_SET;
ret = CO_AC_DONE;
goto done;
}
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 77433b0..42342d6 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -552,8 +552,6 @@
conn->flags &= ~CO_FL_WAIT_L4_CONN;
}
- conn->flags |= CO_FL_ADDR_TO_SET;
-
conn_ctrl_init(conn); /* registers the FD */
HA_ATOMIC_OR(&fdtab[fd].state, FD_LINGER_RISK); /* close hard if needed */
diff --git a/src/proto_uxst.c b/src/proto_uxst.c
index da39e69..2a32fa6 100644
--- a/src/proto_uxst.c
+++ b/src/proto_uxst.c
@@ -336,8 +336,6 @@
conn->flags &= ~CO_FL_WAIT_L4_CONN;
}
- conn->flags |= CO_FL_ADDR_TO_SET;
-
/* Prepare to send a few handshakes related to the on-wire protocol. */
if (conn->send_proxy_ofs)
conn->flags |= CO_FL_SEND_PROXY;
diff --git a/src/quic_sock.c b/src/quic_sock.c
index b6d2d18..a0f8129 100644
--- a/src/quic_sock.c
+++ b/src/quic_sock.c
@@ -157,7 +157,7 @@
if (!sockaddr_alloc(&cli_conn->src, saddr, sizeof *saddr))
goto out_free_conn;
- cli_conn->flags |= CO_FL_ADDR_FROM_SET | CO_FL_FDLESS;
+ cli_conn->flags |= CO_FL_FDLESS;
qc->conn = cli_conn;
cli_conn->handle.qc = qc;
diff --git a/src/sock.c b/src/sock.c
index 6f58aec..602e9c5 100644
--- a/src/sock.c
+++ b/src/sock.c
@@ -116,7 +116,6 @@
conn->src = addr;
conn->handle.fd = cfd;
- conn->flags |= CO_FL_ADDR_FROM_SET;
ret = CO_AC_DONE;
goto done;
}