]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: Add function to get src/dst without updating the connection
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 22 Oct 2021 14:33:28 +0000 (16:33 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 27 Oct 2021 09:34:21 +0000 (11:34 +0200)
conn_get_src() and conn_get_dst() functions are used to fill the source and
destination addresses of a connection. On success, ->src and ->dst
connection fields can be safely used.

For convenience, 2 new functions are added here: conn_src() and conn_dst().
These functions return the corresponding address, as a const and only if it
is already set. Otherwise NULL is returned.

include/haproxy/connection.h

index a140aa7baf2f5575e44d9b7a204a4d5fc9f0df30..bacf7ca440cef3937cf2fd6833bb89c9e1c9ffc3 100644 (file)
@@ -407,6 +407,22 @@ static inline struct connection *cs_conn(const struct conn_stream *cs)
        return cs ? cs->conn : NULL;
 }
 
+/* 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;
+}
+
+/* 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;
+}
+
 /* Retrieves the connection's original source address. Returns non-zero on
  * success or zero on failure. The operation is only performed once and the
  * address is stored in the connection for future use.