]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stick-table: make the use of 'gpt' excluding the use of 'gpt0'
authorEmeric Brun <ebrun@haproxy.com>
Wed, 30 Jun 2021 16:58:22 +0000 (18:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 6 Jul 2021 05:24:42 +0000 (07:24 +0200)
This patch makes the use of 'gpt' excluding the use of the legacy
type 'gpt0' on the same table.

It also makes the 'gpt0' related fetches and actions applying
to the first element of the 'gpt' array if stored in table.

doc/configuration.txt
src/stick_table.c

index e4be9bd649ab0a3a4c661489a65316caffc80fe6..f0481a72e61282f9640074a74d32a3f28c7444d3 100644 (file)
@@ -11217,6 +11217,9 @@ stick-table type {ip | integer | string [len <length>] | binary [len <length>]}
       that a large amount of counters will increase the data size and the
       traffic load using peers protocol since all data/counters are pushed
       each time any of them is updated.
+      This data_type will exclude the usage of the legacy data_type 'gpt0'
+      on the same table. Using the 'gpt' array data_type, all 'gpt0' related
+      fetches and actions will apply to the first element of this array.
 
     - gpt0 : first General Purpose Tag. It is a positive 32-bit integer
       integer which may be used for anything. Most of the time it will be used
index 7fcda827bb7772f21fa72686b8322ea12afe3b67..7bf0e5217ab77b1cfe352c3ce9dc17441fc072d9 100644 (file)
@@ -949,6 +949,12 @@ int parse_stick_table(const char *file, int linenum, char **args,
                                }
                        }
                        idx++;
+                       if (t->data_ofs[STKTABLE_DT_GPT] && t->data_ofs[STKTABLE_DT_GPT0]) {
+                               ha_alert("parsing [%s:%d] : %s: simultaneous usage of 'gpt' and 'gpt0' in a same table is not permitted as 'gpt' overrides 'gpt0'.\n",
+                                        file, linenum, args[0]);
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
                }
                else if (strcmp(args[idx], "srvkey") == 0) {
                        char *keytype;
@@ -1475,6 +1481,9 @@ static int sample_conv_table_gpt0(const struct arg *arg_p, struct sample *smp, v
                return 1;
 
        ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPT0);
+       if (!ptr)
+               ptr = stktable_data_ptr_idx(t, ts, STKTABLE_DT_GPT, 0);
+
        if (ptr)
                smp->data.u.sint = stktable_data_cast(ptr, std_t_uint);
 
@@ -2319,6 +2328,9 @@ static enum act_return action_set_gpt0(struct act_rule *rule, struct proxy *px,
 
        /* Store the sample in the required sc, and ignore errors. */
        ptr = stktable_data_ptr(stkctr->table, ts, STKTABLE_DT_GPT0);
+       if (!ptr)
+               ptr = stktable_data_ptr_idx(stkctr->table, ts, STKTABLE_DT_GPT, 0);
+
        if (ptr) {
                if (!rule->arg.gpt.expr)
                        value = (unsigned int)(rule->arg.gpt.value);
@@ -2698,6 +2710,9 @@ smp_fetch_sc_get_gpt0(const struct arg *args, struct sample *smp, const char *kw
                void *ptr;
 
                ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT0);
+               if (!ptr)
+                       ptr = stktable_data_ptr_idx(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPT, 0);
+
                if (!ptr) {
                        if (stkctr == &tmpstkctr)
                                stktable_release(stkctr->table, stkctr_entry(stkctr));