]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: Add common TLV types as constants for fc_pp_tlv
authorAlexander Stephan <alexander.stephan@sap.com>
Wed, 16 Aug 2023 14:32:13 +0000 (16:32 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 29 Aug 2023 13:32:02 +0000 (15:32 +0200)
This patch adds common TLV types as specified in the PPv2 spec.
We will use the suffix of the type, e.g., PP2_TYPE_AUTHORITY becomes AUTHORITY.

doc/configuration.txt
src/connection.c

index 14b3d35e5c5fcf0589c48e30d616147643a982f2..28ca4c6bceba03121b2760703a0b5091306e1487 100644 (file)
@@ -20182,8 +20182,15 @@ fc_pp_unique_id : string
   header, if any.
 
 fc_pp_tlv(<id>) : string
-  Returns the TLV value for the given TLV ID which must be a numeric
-  value between 0 and 255.
+  Returns the TLV value for the given TLV ID. The ID must either be a numeric
+  value between 0 and 255 or one of the following supported symbolic names
+  that correspond to the TLV constant suffixes in the PPv2 spec:
+  "ALPN": PP2_TYPE_ALPN, "AUTHORITY": PP2_TYPE_AUTHORITY,
+  "CRC32": PP2_TYPE_CRC32C, "NETNS": PP2_TYPE_NETNS, "NOOP: PP2_TYPE_NOOP",
+  "SSL": PP2_TYPE_SSL, "SSL_CIPHER": PP2_SUBTYPE_SSL_CIPHER,
+  "SSL_CN": PP2_SUBTYPE_SSL_CN, "SSL_KEY_ALG": PP2_SUBTYPE_SSL_KEY_ALG,
+  "SSL_SIG_ALG": PP2_SUBTYPE_SSL_SIG_ALG,
+  "SSL_VERSION": PP2_SUBTYPE_SSL_VERSION, "UNIQUE_ID": PP2_TYPE_UNIQUE_ID.
 
   The received value must be smaller or equal to 1024 bytes. This is done to
   prevent potential DoS attacks. Values smaller or equal to 256 bytes will be
index 9e0f778a01364fd3df3ef7f3de35637c1c37dbcf..5d84d60374192c51ff82fc16aa62444d6631a25e 100644 (file)
@@ -2261,22 +2261,50 @@ int smp_fetch_fc_rcvd_proxy(const struct arg *args, struct sample *smp, const ch
 
 /*
  * This function checks the TLV type converter configuration.
- * It expects the corresponding TLV type as a string representing the number.
- * args[0] will be turned into the numerical value of the TLV type string.
+ * It expects the corresponding TLV type as a string representing the number
+ * or a constant. args[0] will be turned into the numerical value of the
+ * TLV type string.
  */
 static int smp_check_tlv_type(struct arg *args, char **err)
 {
        int type;
        char *endp;
-
-       type = strtoul(args[0].data.str.area, &endp, 0);
-       if (endp && *endp != '\0') {
-               memprintf(err, "Could not convert type '%s'", args[0].data.str.area);
-               return 0;
+       struct ist input = ist2(args[0].data.str.area, args[0].data.str.data);
+
+       if (isteqi(input, ist("ALPN")) != 0)
+               type = PP2_TYPE_ALPN;
+       else if (isteqi(input, ist("AUTHORITY")) != 0)
+               type = PP2_TYPE_AUTHORITY;
+       else if (isteqi(input, ist("CRC32C")) != 0)
+               type = PP2_TYPE_CRC32C;
+       else if (isteqi(input, ist("NOOP")) != 0)
+               type = PP2_TYPE_NOOP;
+       else if (isteqi(input, ist("UNIQUE_ID")) != 0)
+               type = PP2_TYPE_UNIQUE_ID;
+       else if (isteqi(input, ist("SSL")) != 0)
+               type = PP2_TYPE_SSL;
+       else if (isteqi(input, ist("SSL_VERSION")) != 0)
+               type = PP2_SUBTYPE_SSL_VERSION;
+       else if (isteqi(input, ist("SSL_CN")) != 0)
+               type = PP2_SUBTYPE_SSL_CN;
+       else if (isteqi(input, ist("SSL_CIPHER")) != 0)
+               type = PP2_SUBTYPE_SSL_CIPHER;
+       else if (isteqi(input, ist("SSL_SIG_ALG")) != 0)
+               type = PP2_SUBTYPE_SSL_SIG_ALG;
+       else if (isteqi(input, ist("SSL_KEY_ALG")) != 0)
+               type = PP2_SUBTYPE_SSL_KEY_ALG;
+       else if (isteqi(input, ist("NETNS")) != 0)
+               type = PP2_TYPE_NETNS;
+       else {
+               type = strtoul(input.ptr, &endp, 0);
+               if (endp && *endp != '\0') {
+                       memprintf(err, "Could not convert type '%s'", input.ptr);
+                       return 0;
+               }
        }
 
        if (type < 0 || type > 255) {
-               memprintf(err, "Invalid TLV Type '%s'", args[0].data.str.area);
+               memprintf(err, "Invalid TLV Type '%s'", input.ptr);
                return 0;
        }