]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: get rid of the CO_FL_ADDR_*_SET flags
authorWilly Tarreau <w@1wt.eu>
Mon, 2 May 2022 15:47:46 +0000 (17:47 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 2 May 2022 15:47:46 +0000 (17:47 +0200)
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.

dev/flags/flags.c
include/haproxy/connection-t.h
include/haproxy/connection.h
src/connection.c
src/proto_quic.c
src/proto_sockpair.c
src/proto_tcp.c
src/proto_uxst.c
src/quic_sock.c
src/sock.c

index 2164a352b92046ee6953e65e947841fdcd3ef25c..3bcbb7f2872308adce0211258cb72c1aa48406d3 100644 (file)
@@ -163,8 +163,6 @@ void show_conn_flags(unsigned int f)
        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);
index 22160f3f30dd14e223651ecf7a5daeef12c0a724..77e31eb46976a487cdd435c1d15785a0d7a9cf38 100644 (file)
@@ -100,8 +100,8 @@ enum {
        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 */
index 8240a6d40bf3793bad984bebe4879d771aa72946..30e689e1558deeb1bb979c8b07ecc82a4a050cf3 100644 (file)
@@ -327,17 +327,13 @@ static inline void conn_force_unsubscribe(struct connection *conn)
 /* 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 const struct sockaddr_storage *conn_dst(struct connection *conn)
  */
 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 @@ static inline int conn_get_src(struct connection *conn)
        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_src(struct connection *conn)
  */
 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 @@ static inline int conn_get_dst(struct connection *conn)
        sockaddr_free(&conn->dst);
        return 0;
  done:
-       conn->flags |= CO_FL_ADDR_TO_SET;
        return 1;
 }
 
index abe4fd66e4e5112efb0510f3de92aa0a9f917dbc..e3e1bc87659fbc058dd8a6bd2cdaf880f00339ef 100644 (file)
@@ -2088,10 +2088,10 @@ int conn_append_debug_info(struct buffer *buf, const struct connection *conn, co
 
        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;
index 5d9240cb774d0be863bb06ded2ccf321c24b0db2..5c20045276a236e6d81004e6fd4a133c8066913f 100644 (file)
@@ -505,8 +505,6 @@ int quic_connect_server(struct connection *conn, int flags)
                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 */
 
index 55d31febc076301903f38f910304443df7559025..9126fe63de59203cdbfa4446488204c0f1e173c8 100644 (file)
@@ -352,8 +352,6 @@ static int sockpair_connect_server(struct connection *conn, int flags)
 
        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 @@ struct connection *sockpair_accept_conn(struct listener *l, int *status)
                /* 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;
        }
index 77433b0e523a83c7222bcdfdbb92a82fbe36f420..42342d652cc0fab4412c406a9cb62f12773b358b 100644 (file)
@@ -552,8 +552,6 @@ int tcp_connect_server(struct connection *conn, int flags)
                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 */
 
index da39e69801dc327dedb6fe3f28e4cb2b911ecac0..2a32fa677d904a6862261f5dde4b76ff645fe6ac 100644 (file)
@@ -336,8 +336,6 @@ static int uxst_connect_server(struct connection *conn, int flags)
                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;
index b6d2d18dca5e92075519e20dd34e53f06bac5f34..a0f8129f49e8fdda555194b0ccfedcd0858f1e08 100644 (file)
@@ -157,7 +157,7 @@ static int new_quic_cli_conn(struct quic_conn *qc, struct listener *l,
        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;
 
index 6f58aec2f4d5f102550f9b037bdbc47554f97998..602e9c55bd04eae456fafc0d0570103374623162 100644 (file)
@@ -116,7 +116,6 @@ struct connection *sock_accept_conn(struct listener *l, int *status)
 
                conn->src = addr;
                conn->handle.fd = cfd;
-               conn->flags |= CO_FL_ADDR_FROM_SET;
                ret = CO_AC_DONE;
                goto done;
        }