From 2cc53ecc8f4dc89da728ca9766e65579b7b50419 Mon Sep 17 00:00:00 2001 From: Alexander Stephan Date: Wed, 16 Aug 2023 16:32:13 +0200 Subject: [PATCH] MINOR: sample: Add common TLV types as constants for fc_pp_tlv 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 | 11 +++++++++-- src/connection.c | 44 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 14b3d35..28ca4c6 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -20182,8 +20182,15 @@ fc_pp_unique_id : string header, if any. fc_pp_tlv() : 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 diff --git a/src/connection.c b/src/connection.c index 9e0f778..5d84d60 100644 --- a/src/connection.c +++ b/src/connection.c @@ -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; } -- 1.7.10.4