diff --git a/include/haproxy/connection.h b/include/haproxy/connection.h index a50b0bb4f..c4d9e06e8 100644 --- a/include/haproxy/connection.h +++ b/include/haproxy/connection.h @@ -37,7 +37,6 @@ #include #include #include -#include extern struct pool_head *pool_head_connection; @@ -79,6 +78,17 @@ int conn_recv_socks4_proxy_response(struct connection *conn); /* If we delayed the mux creation because we were waiting for the handshake, do it now */ int conn_create_mux(struct connection *conn); +/* connection hash stuff */ +uint64_t conn_calculate_hash(const struct conn_hash_params *params); +uint64_t conn_hash_prehash(char *buf, size_t size); +void conn_hash_update(char *buf, size_t *idx, + const void *data, size_t size, + enum conn_hash_params_t *flags, + enum conn_hash_params_t type); +uint64_t conn_hash_digest(char *buf, size_t bufsize, + enum conn_hash_params_t flags); + + extern struct idle_conns idle_conns[MAX_THREADS]; /* returns true if the transport layer is ready */ @@ -1195,39 +1205,6 @@ static inline int conn_upgrade_mux_fe(struct connection *conn, void *ctx, struct return 0; } -/* Generate the hash of a connection with params as input - * Each non-null field of params is taken into account for the hash calcul. - */ -uint64_t conn_calculate_hash(const struct conn_hash_params *params); - -static inline uint64_t conn_hash_prehash(char *buf, size_t size) -{ - return XXH64(buf, size, 0); -} - -/* Append into at offset in preparation for connection hash - * calcul. is incremented beyond data . In the same time, - * are updated with for the hash header. - */ -static inline void conn_hash_update(char *buf, size_t *idx, - const void *data, size_t size, - enum conn_hash_params_t *flags, - enum conn_hash_params_t type) -{ - memcpy(&buf[*idx], data, size); - *idx += size; - *flags |= type; -} - -static inline uint64_t conn_hash_digest(char *buf, size_t bufsize, - enum conn_hash_params_t flags) -{ - const uint64_t flags_u64 = (uint64_t)flags; - const uint64_t hash = XXH64(buf, bufsize, 0); - - return (flags_u64 << CONN_HASH_PAYLOAD_LEN) | CONN_HASH_GET_PAYLOAD(hash); -} - /* boolean, returns true if connection is over SSL */ static inline int conn_is_ssl(struct connection *conn) diff --git a/src/connection.c b/src/connection.c index 2e734f724..1dcba8a94 100644 --- a/src/connection.c +++ b/src/connection.c @@ -26,6 +26,7 @@ #include #include #include +#include DECLARE_POOL(pool_head_connection, "connection", sizeof(struct connection)); @@ -1627,6 +1628,37 @@ static void conn_calculate_hash_sockaddr(const struct sockaddr_storage *ss, } } +/* Generate the hash of a connection with params as input + * Each non-null field of params is taken into account for the hash calcul. + */ +uint64_t conn_hash_prehash(char *buf, size_t size) +{ + return XXH64(buf, size, 0); +} + +/* Append into at offset in preparation for connection hash + * calcul. is incremented beyond data . In the same time, + * are updated with for the hash header. + */ +void conn_hash_update(char *buf, size_t *idx, + const void *data, size_t size, + enum conn_hash_params_t *flags, + enum conn_hash_params_t type) +{ + memcpy(&buf[*idx], data, size); + *idx += size; + *flags |= type; +} + +uint64_t conn_hash_digest(char *buf, size_t bufsize, + enum conn_hash_params_t flags) +{ + const uint64_t flags_u64 = (uint64_t)flags; + const uint64_t hash = XXH64(buf, bufsize, 0); + + return (flags_u64 << CONN_HASH_PAYLOAD_LEN) | CONN_HASH_GET_PAYLOAD(hash); +} + uint64_t conn_calculate_hash(const struct conn_hash_params *params) { char *buf;