diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h index a1e01dd4e..eaca98899 100644 --- a/include/haproxy/proxy-t.h +++ b/include/haproxy/proxy-t.h @@ -424,9 +424,11 @@ struct proxy { struct list listeners; /* list of listeners belonging to this frontend */ struct list errors; /* list of all custom error files */ struct arg_list args; /* sample arg list that need to be resolved */ - unsigned int refcount; /* refcount on this proxy (only used for default proxy for now) */ struct ebpt_node by_name; /* proxies are stored sorted by name here */ struct list lf_checks; /* list of logformats found in the proxy section that needs to be checked during postparse */ + const char *file_prev; /* file of the previous instance found with the same name, or NULL */ + int line_prev; /* line of the previous instance found with the same name, or 0 */ + unsigned int refcount; /* refcount on this proxy (only used for default proxy for now) */ } conf; /* config information */ struct http_ext *http_ext; /* http ext options */ struct eb_root used_server_addr; /* list of server addresses in use */ diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index e190e6e16..bb722b3ee 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -229,6 +229,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) struct acl_cond *cond = NULL; char *errmsg = NULL; struct bind_conf *bind_conf; + const char *file_prev = NULL; + int line_prev = 0; if (!last_defproxy) { /* we need a default proxy and none was created yet */ @@ -325,6 +327,18 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) err_code |= ERR_ALERT | ERR_ABORT; goto out; } + + /* if the other proxy exists, we don't need to keep it + * since neither will support being explicitly referenced + * so let's drop it from the index but keep a reference to + * its location for error messages. + */ + if (curproxy) { + file_prev = curproxy->conf.file; + line_prev = curproxy->conf.line; + proxy_unref_or_destroy_defaults(curproxy); + curproxy = NULL; + } } curproxy = proxy_find_by_name(args[1], 0, 0); @@ -351,8 +365,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) curr_defproxy = last_defproxy; if (strcmp(args[arg], "from") == 0) { - struct ebpt_node *next_by_name; - curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0); if (!curr_defproxy) { @@ -361,12 +373,11 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) goto out; } - if ((next_by_name = ebpt_next_dup(&curr_defproxy->conf.by_name))) { - struct proxy *px2 = container_of(next_by_name, struct proxy, conf.by_name); - + if (curr_defproxy->conf.line_prev) { ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name, - curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line); + curr_defproxy->conf.file, curr_defproxy->conf.line, + curr_defproxy->conf.file_prev, curr_defproxy->conf.line_prev); err_code |= ERR_ALERT | ERR_FATAL; } @@ -394,6 +405,9 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) goto out; } + curproxy->conf.file_prev = file_prev; + curproxy->conf.line_prev = line_prev; + if (curr_defproxy && (!LIST_ISEMPTY(&curr_defproxy->http_req_rules) || !LIST_ISEMPTY(&curr_defproxy->http_res_rules) || !LIST_ISEMPTY(&curr_defproxy->http_after_res_rules) ||