mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
MINOR: stick-table: Add prefixes to stick-table names.
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.
This commit is contained in:
parent
015e4d7d93
commit
c02766a267
@ -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);
|
||||
|
@ -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.
|
||||
*/
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user