BUG/MINOR: peers: set the proxy's name to the peers section name

For some poor historical reasons, the name of a peers proxy used to be
set to the name of the local peer itself. That causes some confusion when
multiple sections are present because the same proxy name appears at
multiple places in "show peers", but since 2.5 where parsing errors include
the proxy name, a config like this one :

   peers foo
       server foobar blah

Would report this when the local peer name isn't "foobar":

   'server (null)/foobar' : invalid address: 'blah' in 'blah'

And this when it is foobar:

   'server foobar/foobar' : invalid address: 'blah' in 'blah'

This is wrong, confusing and not very practical. This commit addresses
all this by using the peers section's name when it's created. This now
allows to report messages such as:

   'server foo/foobar' : invalid address: 'blah' in 'blah'

Which make it clear that the section is called "foo" and the server
"foobar".

This may be backported to 2.5, though the patch may be simplified if
needed, by just adding the change at the output of init_peers_frontend().
This commit is contained in:
Willy Tarreau 2022-05-31 09:10:19 +02:00
parent 50e77b2b85
commit 356866acce

View File

@ -566,13 +566,12 @@ unsigned long parse_cpu_set(const char **args, struct hap_cpuset *cpu_set,
#endif
/* Allocate and initialize the frontend of a "peers" section found in
* file <file> at line <linenum> with <id> as ID.
* file <file> at line <linenum> for section <peers>.
* Return 0 if succeeded, -1 if not.
* Note that this function may be called from "default-server"
* or "peer" lines.
*/
static int init_peers_frontend(const char *file, int linenum,
const char *id, struct peers *peers)
static int init_peers_frontend(const char *file, int linenum, struct peers *peers)
{
struct proxy *p;
@ -594,8 +593,9 @@ static int init_peers_frontend(const char *file, int linenum,
peers->peers_fe = p;
out:
if (id && !p->id)
p->id = strdup(id);
if (!p->id && peers->id)
p->id = strdup(peers->id);
free(p->conf.file);
p->conf.args.file = p->conf.file = strdup(file);
if (linenum != -1)
@ -697,7 +697,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
cur_arg = 1;
if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) {
if (init_peers_frontend(file, linenum, curpeers) != 0) {
err_code |= ERR_ALERT | ERR_ABORT;
goto out;
}
@ -766,7 +766,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
goto out;
}
else if (strcmp(args[0], "default-server") == 0) {
if (init_peers_frontend(file, -1, NULL, curpeers) != 0) {
if (init_peers_frontend(file, -1, curpeers) != 0) {
err_code |= ERR_ALERT | ERR_ABORT;
goto out;
}
@ -774,7 +774,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
SRV_PARSE_DEFAULT_SERVER|SRV_PARSE_IN_PEER_SECTION|SRV_PARSE_INITIAL_RESOLVE);
}
else if (strcmp(args[0], "log") == 0) {
if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) {
if (init_peers_frontend(file, linenum, curpeers) != 0) {
err_code |= ERR_ALERT | ERR_ABORT;
goto out;
}
@ -871,7 +871,6 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
/* Line number and peer ID are updated only if this peer is the local one. */
if (init_peers_frontend(file,
newpeer->local ? linenum: -1,
newpeer->local ? newpeer->id : NULL,
curpeers) != 0) {
err_code |= ERR_ALERT | ERR_ABORT;
goto out;
@ -953,7 +952,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
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) {
if (init_peers_frontend(file, -1, curpeers) != 0) {
err_code |= ERR_ALERT | ERR_ABORT;
goto out;
}