diff --git a/include/haproxy/connection-t.h b/include/haproxy/connection-t.h index 451eb8d97..bb6edb1c1 100644 --- a/include/haproxy/connection-t.h +++ b/include/haproxy/connection-t.h @@ -626,10 +626,11 @@ struct mux_proto_list { #define PP2_CLIENT_CERT_CONN 0x02 #define PP2_CLIENT_CERT_SESS 0x04 -/* Max length of the authority TLV */ -#define PP2_AUTHORITY_MAX 255 +#define PP2_CRC32C_LEN 4 /* Length of a CRC32C TLV value */ -#define TLV_HEADER_SIZE 3 +#define TLV_HEADER_SIZE 3 + +#define HA_PP2_AUTHORITY_MAX 255 /* Maximum length of an authority TLV */ struct proxy_hdr_v2 { uint8_t sig[12]; /* hex 0D 0A 0D 0A 00 0D 0A 51 55 49 54 0A */ diff --git a/src/connection.c b/src/connection.c index c56b4f308..101ac4f59 100644 --- a/src/connection.c +++ b/src/connection.c @@ -37,7 +37,7 @@ DECLARE_POOL(pool_head_connection, "connection", sizeof(struct connection)); DECLARE_POOL(pool_head_conn_hash_node, "conn_hash_node", sizeof(struct conn_hash_node)); DECLARE_POOL(pool_head_sockaddr, "sockaddr", sizeof(struct sockaddr_storage)); -DECLARE_POOL(pool_head_authority, "authority", PP2_AUTHORITY_MAX); +DECLARE_POOL(pool_head_authority, "authority", HA_PP2_AUTHORITY_MAX); struct idle_conns idle_conns[MAX_THREADS] = { }; struct xprt_ops *registered_xprt[XPRT_ENTRIES] = { NULL, }; @@ -1100,7 +1100,7 @@ int conn_recv_proxy(struct connection *conn, int flag) uint32_t n_crc32c; /* Verify that this TLV is exactly 4 bytes long */ - if (istlen(tlv) != 4) + if (istlen(tlv) != PP2_CRC32C_LEN) goto bad_header; n_crc32c = read_n32(istptr(tlv)); @@ -1121,12 +1121,12 @@ int conn_recv_proxy(struct connection *conn, int flag) } #endif case PP2_TYPE_AUTHORITY: { - if (istlen(tlv) > PP2_AUTHORITY_MAX) + if (istlen(tlv) > HA_PP2_AUTHORITY_MAX) goto bad_header; conn->proxy_authority = ist2(pool_alloc(pool_head_authority), 0); if (!isttest(conn->proxy_authority)) goto fail; - if (istcpy(&conn->proxy_authority, tlv, PP2_AUTHORITY_MAX) < 0) { + if (istcpy(&conn->proxy_authority, tlv, HA_PP2_AUTHORITY_MAX) < 0) { /* This is impossible, because we verified that the TLV value fits. */ my_unreachable(); goto fail;