Skip to content

Commit 2cc53ec

Browse files
alexanderstephanwtarreau
authored andcommitted
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.
1 parent 0a4f699 commit 2cc53ec

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

doc/configuration.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20182,8 +20182,15 @@ fc_pp_unique_id : string
2018220182
header, if any.
2018320183

2018420184
fc_pp_tlv(<id>) : string
20185-
Returns the TLV value for the given TLV ID which must be a numeric
20186-
value between 0 and 255.
20185+
Returns the TLV value for the given TLV ID. The ID must either be a numeric
20186+
value between 0 and 255 or one of the following supported symbolic names
20187+
that correspond to the TLV constant suffixes in the PPv2 spec:
20188+
"ALPN": PP2_TYPE_ALPN, "AUTHORITY": PP2_TYPE_AUTHORITY,
20189+
"CRC32": PP2_TYPE_CRC32C, "NETNS": PP2_TYPE_NETNS, "NOOP: PP2_TYPE_NOOP",
20190+
"SSL": PP2_TYPE_SSL, "SSL_CIPHER": PP2_SUBTYPE_SSL_CIPHER,
20191+
"SSL_CN": PP2_SUBTYPE_SSL_CN, "SSL_KEY_ALG": PP2_SUBTYPE_SSL_KEY_ALG,
20192+
"SSL_SIG_ALG": PP2_SUBTYPE_SSL_SIG_ALG,
20193+
"SSL_VERSION": PP2_SUBTYPE_SSL_VERSION, "UNIQUE_ID": PP2_TYPE_UNIQUE_ID.
2018720194

2018820195
The received value must be smaller or equal to 1024 bytes. This is done to
2018920196
prevent potential DoS attacks. Values smaller or equal to 256 bytes will be

src/connection.c

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,22 +2261,50 @@ int smp_fetch_fc_rcvd_proxy(const struct arg *args, struct sample *smp, const ch
22612261

22622262
/*
22632263
* This function checks the TLV type converter configuration.
2264-
* It expects the corresponding TLV type as a string representing the number.
2265-
* args[0] will be turned into the numerical value of the TLV type string.
2264+
* It expects the corresponding TLV type as a string representing the number
2265+
* or a constant. args[0] will be turned into the numerical value of the
2266+
* TLV type string.
22662267
*/
22672268
static int smp_check_tlv_type(struct arg *args, char **err)
22682269
{
22692270
int type;
22702271
char *endp;
2271-
2272-
type = strtoul(args[0].data.str.area, &endp, 0);
2273-
if (endp && *endp != '\0') {
2274-
memprintf(err, "Could not convert type '%s'", args[0].data.str.area);
2275-
return 0;
2272+
struct ist input = ist2(args[0].data.str.area, args[0].data.str.data);
2273+
2274+
if (isteqi(input, ist("ALPN")) != 0)
2275+
type = PP2_TYPE_ALPN;
2276+
else if (isteqi(input, ist("AUTHORITY")) != 0)
2277+
type = PP2_TYPE_AUTHORITY;
2278+
else if (isteqi(input, ist("CRC32C")) != 0)
2279+
type = PP2_TYPE_CRC32C;
2280+
else if (isteqi(input, ist("NOOP")) != 0)
2281+
type = PP2_TYPE_NOOP;
2282+
else if (isteqi(input, ist("UNIQUE_ID")) != 0)
2283+
type = PP2_TYPE_UNIQUE_ID;
2284+
else if (isteqi(input, ist("SSL")) != 0)
2285+
type = PP2_TYPE_SSL;
2286+
else if (isteqi(input, ist("SSL_VERSION")) != 0)
2287+
type = PP2_SUBTYPE_SSL_VERSION;
2288+
else if (isteqi(input, ist("SSL_CN")) != 0)
2289+
type = PP2_SUBTYPE_SSL_CN;
2290+
else if (isteqi(input, ist("SSL_CIPHER")) != 0)
2291+
type = PP2_SUBTYPE_SSL_CIPHER;
2292+
else if (isteqi(input, ist("SSL_SIG_ALG")) != 0)
2293+
type = PP2_SUBTYPE_SSL_SIG_ALG;
2294+
else if (isteqi(input, ist("SSL_KEY_ALG")) != 0)
2295+
type = PP2_SUBTYPE_SSL_KEY_ALG;
2296+
else if (isteqi(input, ist("NETNS")) != 0)
2297+
type = PP2_TYPE_NETNS;
2298+
else {
2299+
type = strtoul(input.ptr, &endp, 0);
2300+
if (endp && *endp != '\0') {
2301+
memprintf(err, "Could not convert type '%s'", input.ptr);
2302+
return 0;
2303+
}
22762304
}
22772305

22782306
if (type < 0 || type > 255) {
2279-
memprintf(err, "Invalid TLV Type '%s'", args[0].data.str.area);
2307+
memprintf(err, "Invalid TLV Type '%s'", input.ptr);
22802308
return 0;
22812309
}
22822310

0 commit comments

Comments
 (0)