Hi All,
On 6/2/20 1:10 PM, Tim Düsterhus wrote:
> Emeric,
>
> Am 02.06.20 um 11:29 schrieb Emeric Brun:
>> In attachement a proposed patch for this issue.
>>
>
> Thanks. The changes to the doc look good to me.
>
> Regarding peers.c:
>
>> +/* network key types;
>> + * network types were directly and mistakenly
>> + * mapped on sample types, to keep backward
>> + * compatiblitiy we keep those values but
>> + * we now use a internal/network mapping
>> + * to avoid further mistakes adding or
>> + * modifying internals types
>> + */
>> +enum {
>> + PEER_KT_ANY = 0, /* any type */
>> + PEER_KT_RESV1, /* UNUSED */
>> + PEER_KT_SINT, /* signed 64bits integer type */
>> + PEER_KT_RESV2, /* UNUSED */
>
> Maybe call this RESV3 to make it clear that the numeric value is '3'.
>
>> + PEER_KT_IPV4, /* ipv4 type */
>> + PEER_KT_IPV6, /* ipv6 type */
>> + PEER_KT_STR, /* char string type */
>> + PEER_KT_BIN, /* buffer type */
>> + PEER_KT_TYPES /* number of types, must always be last */
>> +};
>
> -
>
>> + * Note: Undeclared mapping maps entry to SMP_ST_ANY == 0
>
> This should read SMP_T_ANY.
>
> Also backporting instructions are missing from the commit message.
>
> Other than that the patch looks good to me, but I didn't actually test a
> binary compiled from it.
>
> Best regards
> Tim Düsterhus
>
Thank you Tim!
Here the updated patch.
R,
Emeric
>From c58eed60557fd20e8b972cc3ab4b45e4e598e558 Mon Sep 17 00:00:00 2001
From: Emeric Brun <[email protected]>
Date: Tue, 2 Jun 2020 11:17:42 +0200
Subject: [PATCH] BUG/MINOR: peers: fix internal/network key type mapping.
Network types were directly and mistakenly mapped on sample types:
This patch fix the doc with values effectively used to keep backward
compatiblitiy on existing implementations.
In addition it adds an internal/network mapping for key types to avoid
further mistakes adding or modifying internals types.
This patch should be backported on all maintained branches,
particularly until v1.8 included for documentation part.
---
doc/peers-v2.0.txt | 10 +++++-----
src/peers.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/doc/peers-v2.0.txt b/doc/peers-v2.0.txt
index 477e7bb84..344cb5609 100644
--- a/doc/peers-v2.0.txt
+++ b/doc/peers-v2.0.txt
@@ -191,11 +191,11 @@ between the "Sender Table ID" to identify it directly in case of "Table Switch M
Table Type present the numeric type of key used to store stick table entries:
integer
- 0: signed integer
- 1: IPv4 address
- 2: IPv6 address
- 3: string
- 4: binary
+ 2: signed integer
+ 4: IPv4 address
+ 5: IPv6 address
+ 6: string
+ 7: binary
Table Keylen present the key length or max length in case of strings or binary (padded with 0).
diff --git a/src/peers.c b/src/peers.c
index 2e54ab94d..9782ff3c1 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -125,6 +125,48 @@ enum {
PEER_MSG_ERR_SIZELIMIT,
};
+/* network key types;
+ * network types were directly and mistakenly
+ * mapped on sample types, to keep backward
+ * compatiblitiy we keep those values but
+ * we now use a internal/network mapping
+ * to avoid further mistakes adding or
+ * modifying internals types
+ */
+enum {
+ PEER_KT_ANY = 0, /* any type */
+ PEER_KT_RESV1, /* UNUSED */
+ PEER_KT_SINT, /* signed 64bits integer type */
+ PEER_KT_RESV3, /* UNUSED */
+ PEER_KT_IPV4, /* ipv4 type */
+ PEER_KT_IPV6, /* ipv6 type */
+ PEER_KT_STR, /* char string type */
+ PEER_KT_BIN, /* buffer type */
+ PEER_KT_TYPES /* number of types, must always be last */
+};
+
+/* Map used to retrieve network type from internal type
+ * Note: Undeclared mapping maps entry to PEER_KT_ANY == 0
+ */
+static int peer_net_key_type[SMP_TYPES] = {
+ [SMP_T_SINT] = PEER_KT_SINT,
+ [SMP_T_IPV4] = PEER_KT_IPV4,
+ [SMP_T_IPV6] = PEER_KT_IPV6,
+ [SMP_T_STR] = PEER_KT_STR,
+ [SMP_T_BIN] = PEER_KT_BIN,
+};
+
+/* Map used to retrieve internal type from external type
+ * Note: Undeclared mapping maps entry to SMP_T_ANY == 0
+ */
+static int peer_int_key_type[PEER_KT_TYPES] = {
+ [PEER_KT_SINT] = SMP_T_SINT,
+ [PEER_KT_IPV4] = SMP_T_IPV4,
+ [PEER_KT_IPV6] = SMP_T_IPV6,
+ [PEER_KT_STR] = SMP_T_STR,
+ [PEER_KT_BIN] = SMP_T_BIN,
+};
+
/*
* Parameters used by functions to build peer protocol messages. */
struct peer_prep_params {
@@ -620,7 +662,7 @@ static int peer_prepare_switchmsg(char *msg, size_t size, struct peer_prep_param
/* encode table type */
- intencode(st->table->type, &cursor);
+ intencode(peer_net_key_type[st->table->type], &cursor);
/* encode table key size */
intencode(st->table->key_size, &cursor);
@@ -1655,7 +1697,7 @@ static inline int peer_treat_definemsg(struct appctx *appctx, struct peer *p,
if (!*msg_cur)
goto malformed_exit;
- if (p->remote_table->table->type != table_type
+ if (p->remote_table->table->type != peer_int_key_type[table_type]
|| p->remote_table->table->key_size != table_keylen) {
p->remote_table = NULL;
goto ignore_msg;
--
2.17.1