]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP/MINOR: connection: Improve consistency of PPv2 related constants
authorAlexander Stephan <alexander.stephan@sap.com>
Mon, 14 Aug 2023 19:10:11 +0000 (21:10 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 29 Aug 2023 13:15:47 +0000 (15:15 +0200)
This patch improves readability by scoping HA proxy related PPv2 constants
with a 'HA" prefix. Besides, a new constant for the length of a CRC32C
TLV is introduced. The length is derived from the PPv2 spec, so 32 Bit.

include/haproxy/connection-t.h
src/connection.c

index 451eb8d9715e8e6aae876b5b3759159d8bd86912..bb6edb1c10d89d766b8025cd27270ddc6e4c23dd 100644 (file)
@@ -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 */
index c56b4f3089c6dbbacd73600434c0a079f97b7e9c..101ac4f596bb6ddd03bf6e8e699bd8622b4c92c7 100644 (file)
@@ -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;