]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stick-table: Add prefixes to stick-table names.
authorFrédéric Lécaille <flecaille@haproxy.com>
Wed, 20 Mar 2019 14:06:55 +0000 (15:06 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 7 May 2019 04:54:07 +0000 (06:54 +0200)
With this patch we add a prefix to stick-table names declared in "peers" sections
concatenating the "peers" section name followed by a '/' character with
the stick-table name. Consequently, "peers" sections have their own
namespace for their stick-tables. Obviously, these stick-table names are not the
ones which should be sent over the network. So these configurations must be
compatible and should make A and B peers communicate with peers protocol:

    # haproxy A config, old way stick-table declerations
    peers mypeers
        peer A ...
        peer B ...

    backend t1
        stick-table type string size 10m store gpc0 peers mypeers

    # haproxy B config, new way stick-table declerations
    peers mypeers
        peer A ...
        peer B ...
        table t1 type string size store gpc0 10m

This "network" name is stored in ->nid new field of stktable struct. The "local"
stktable-name is still stored in ->id.

include/proto/stick_table.h
include/types/stick_table.h
src/cfgparse-listen.c
src/cfgparse.c
src/stick_table.c

index 3010d812e1503c05f5038136151649e325c4525f..a1dd06a1bd3f9fdd3ae554835346758a2784a556 100644 (file)
@@ -43,7 +43,7 @@ int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcount);
 int stktable_init(struct stktable *t);
 int stktable_parse_type(char **args, int *idx, unsigned long *type, size_t *key_size);
 int parse_stick_table(const char *file, int linenum, char **args,
-                      struct stktable *t, char *id, struct peers *peers);
+                      struct stktable *t, char *id, char *nid, struct peers *peers);
 struct stksess *stktable_get_entry(struct stktable *table, struct stktable_key *key);
 struct stksess *stktable_set_entry(struct stktable *table, struct stksess *nts);
 void stktable_touch_with_exp(struct stktable *t, struct stksess *ts, int decrefcount, int expire);
index a4baeb37eeb6ae057dc404081c65ed9d74605518..384a0a853aa3fee264aad04fa8083ef51d567b29 100644 (file)
@@ -144,7 +144,8 @@ struct stksess {
 
 /* stick table */
 struct stktable {
-       char *id;                 /* table id name */
+       char *id;                 /* local table id name. */
+       char *nid;                /* table id name sent over the network with peers protocol. */
        struct stktable *next;    /* The stick-table may be linked when belonging to
                                   * the same configuration section.
                                   */
index 7537bc2eca40caa5f15e8bccfc946815244dc754..b46e119fa22838c41b201fdbd02630ffcf4999e6 100644 (file)
@@ -1739,7 +1739,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
-               err_code |= parse_stick_table(file, linenum, args, curproxy->table, curproxy->id, NULL);
+               err_code |= parse_stick_table(file, linenum, args, curproxy->table,
+                                             curproxy->id, curproxy->id, NULL);
                if (err_code & ERR_FATAL)
                        goto out;
 
index c7db11068e72b558a6b018b0e4c66bb34766939a..9a086173698a51fcafac63f2f2551d019a24eb6d 100644 (file)
@@ -860,6 +860,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
        else if (!strcmp(args[0], "table")) {
                struct stktable *t, *other;
                char *id;
+               size_t prefix_len;
 
                /* Line number and peer ID are updated only if this peer is the local one. */
                if (init_peers_frontend(file, -1, NULL, curpeers) != 0) {
@@ -878,8 +879,27 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
+               /* Build the stick-table name, concatenating the "peers" section name
+                * followed by a '/' character and the table name argument.
+                */
+               chunk_reset(&trash);
+               if (!chunk_strcpy(&trash, curpeers->id) || !chunk_memcat(&trash, "/", 1)) {
+                       ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n",
+                                file, linenum, args[0], args[1]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
+
+               prefix_len = trash.data;
+               if (!chunk_strcat(&trash, args[1])) {
+                       ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n",
+                                file, linenum, args[0], args[1]);
+                       err_code |= ERR_ALERT | ERR_FATAL;
+                       goto out;
+               }
+
                t = calloc(1, sizeof *t);
-               id = strdup(args[1]);
+               id = strdup(trash.area);
                if (!t || !id) {
                        ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n",
                                 file, linenum, args[0], args[1]);
@@ -887,7 +907,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
-               err_code |= parse_stick_table(file, linenum, args, t, id, curpeers);
+               err_code |= parse_stick_table(file, linenum, args, t, id, id + prefix_len, curpeers);
                if (err_code & ERR_FATAL)
                        goto out;
 
index 87a26e6a9f3590b05afb2e4161665db7f978a361..d7e1eb8afaa74cdab447b3b1f5f0b30a7df3b0ee 100644 (file)
@@ -695,13 +695,18 @@ int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *ke
 }
 
 /*
- * Parse a line with <linenum> as number in <file> configuration file to configure the
- * stick-table with <t> as address and  <id> as ID.
- * <peers> provides the "peers" section pointer only if this function is called from a "peers" section.
+ * Parse a line with <linenum> as number in <file> configuration file to configure
+ * the stick-table with <t> as address and  <id> as ID.
+ * <peers> provides the "peers" section pointer only if this function is called
+ * from a "peers" section.
+ * <nid> is the stick-table name which is sent over the network. It must be equal
+ * to <id> if this stick-table is parsed from a proxy section, and prefixed by <peers>
+ * "peers" section name followed by a '/' character if parsed from a "peers" section.
+ * This is the responsability of the caller to check this.
  * Return an error status with ERR_* flags set if required, 0 if no error was encountered.
  */
 int parse_stick_table(const char *file, int linenum, char **args,
-                      struct stktable *t, char *id, struct peers *peers)
+                      struct stktable *t, char *id, char *nid, struct peers *peers)
 {
        int err_code = 0;
        int idx = 1;
@@ -720,6 +725,7 @@ int parse_stick_table(const char *file, int linenum, char **args,
        }
 
        t->id =  id;
+       t->nid =  nid;
        t->type = (unsigned int)-1;
        t->conf.file = file;
        t->conf.line = linenum;