]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stktable: add stksess_getkey() helper
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 30 Dec 2024 19:15:50 +0000 (20:15 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 9 Jan 2025 09:56:56 +0000 (10:56 +0100)
stksess_getkey(t, ts) returns a stktable_key struct pointer filled with
data from input <ts> entry in <t> table. Returned pointer uses the
static_table_key variable. Indeed, stktable_key struct is more convenient
to manipulate than having to deal with the key extraction from stktsess
struct directly.

src/stick_table.c

index 31eeff528550efe35227f3e2f5d6da855215f536..7f788f8f7ddd27e688449d0ddfbeab57d5f6b5c4 100644 (file)
@@ -207,6 +207,25 @@ void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key
        }
 }
 
+/*
+ * Get the key in the sticky session <ts> present in table <t>
+ * It cannot fail as it is assumed that if <ts> exists, then the key has
+ * been set.
+ * It uses static_table_key to store the key
+ */
+struct stktable_key *stksess_getkey(struct stktable *t, struct stksess *ts)
+{
+       if (t->type != SMP_T_STR) {
+               static_table_key.key = ts->key.key;
+               static_table_key.key_len = t->key_size;
+       }
+       else {
+               static_table_key.key = ts->key.key;
+               static_table_key.key_len = strnlen2((char *)ts->key.key, t->key_size);
+       }
+       return &static_table_key;
+}
+
 /* return a shard number for key <key> of len <len> present in table <t>. This
  * takes into account the presence or absence of a peers section with shards
  * and the number of shards, the table's hash_seed, and of course the key. The