diff --git a/include/proto/stick_table.h b/include/proto/stick_table.h index 3010d812e..a1dd06a1b 100644 --- a/include/proto/stick_table.h +++ b/include/proto/stick_table.h @@ -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); diff --git a/include/types/stick_table.h b/include/types/stick_table.h index a4baeb37e..384a0a853 100644 --- a/include/types/stick_table.h +++ b/include/types/stick_table.h @@ -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. */ diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 7537bc2ec..b46e119fa 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -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; diff --git a/src/cfgparse.c b/src/cfgparse.c index c7db11068..9a0861736 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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; diff --git a/src/stick_table.c b/src/stick_table.c index 87a26e6a9..d7e1eb8af 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -695,13 +695,18 @@ int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *ke } /* - * Parse a line with as number in configuration file to configure the - * stick-table with as address and as ID. - * provides the "peers" section pointer only if this function is called from a "peers" section. + * Parse a line with as number in configuration file to configure + * the stick-table with as address and as ID. + * provides the "peers" section pointer only if this function is called + * from a "peers" section. + * is the stick-table name which is sent over the network. It must be equal + * to if this stick-table is parsed from a proxy section, and prefixed by + * "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;