mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-12-02 16:21:27 +01:00
MINOR: cfgdiag: adjust diag on servers
Adjust code dealing with diagnostics performed on server. The objective is to extract the check on duplicate cookies in a dedicated function outside of the proxies/servers loop. This does not have any noticeable impact. This patch is merely a code improvment to implement easily new future diagnostics on servers.
This commit is contained in:
parent
d12971dfea
commit
d92f8f84fb
@ -8,6 +8,10 @@
|
|||||||
#include <haproxy/proxy.h>
|
#include <haproxy/proxy.h>
|
||||||
#include <haproxy/server.h>
|
#include <haproxy/server.h>
|
||||||
|
|
||||||
|
struct cookie_entry {
|
||||||
|
struct ebpt_node node;
|
||||||
|
};
|
||||||
|
|
||||||
/* Use this function to emit diagnostic.
|
/* Use this function to emit diagnostic.
|
||||||
* This can be used as a shortcut to set value pointed by <ret> to 1 at the
|
* This can be used as a shortcut to set value pointed by <ret> to 1 at the
|
||||||
* same time.
|
* same time.
|
||||||
@ -41,43 +45,42 @@ static inline void *diag_alloc(size_t size)
|
|||||||
* value. Backup servers are not taken into account as it can be quite common to
|
* value. Backup servers are not taken into account as it can be quite common to
|
||||||
* share cookie values in this case.
|
* share cookie values in this case.
|
||||||
*/
|
*/
|
||||||
static void check_server_cookies(int *ret)
|
static void srv_diag_cookies(int *ret, struct server *srv, struct eb_root *cookies_tree)
|
||||||
{
|
{
|
||||||
struct cookie_entry {
|
|
||||||
struct ebpt_node node;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct proxy *px;
|
|
||||||
struct server *srv;
|
|
||||||
|
|
||||||
struct eb_root cookies_tree = EB_ROOT_UNIQUE;
|
|
||||||
struct ebpt_node *cookie_node;
|
struct ebpt_node *cookie_node;
|
||||||
struct cookie_entry *cookie_entry;
|
|
||||||
struct ebpt_node *node;
|
|
||||||
|
|
||||||
for (px = proxies_list; px; px = px->next) {
|
|
||||||
for (srv = px->srv; srv; srv = srv->next) {
|
|
||||||
/* do not take into account backup servers */
|
/* do not take into account backup servers */
|
||||||
if (!srv->cookie || (srv->flags & SRV_F_BACKUP))
|
if (!srv->cookie || (srv->flags & SRV_F_BACKUP))
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
cookie_node = ebis_lookup(&cookies_tree, srv->cookie);
|
cookie_node = ebis_lookup(cookies_tree, srv->cookie);
|
||||||
if (cookie_node) {
|
if (cookie_node) {
|
||||||
diag_warning(ret, "parsing [%s:%d] : 'server %s' : same cookie value is set for a previous non-backup server in the same backend, it may break connection persistence\n",
|
diag_warning(ret, "parsing [%s:%d] : 'server %s' : same cookie value is set for a previous non-backup server in the same backend, it may break connection persistence\n",
|
||||||
srv->conf.file, srv->conf.line, srv->id);
|
srv->conf.file, srv->conf.line, srv->id);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
cookie_entry = diag_alloc(sizeof(*cookie_entry));
|
cookie_node = diag_alloc(sizeof(*cookie_node));
|
||||||
cookie_entry->node.key = srv->cookie;
|
cookie_node->key = srv->cookie;
|
||||||
ebis_insert(&cookies_tree, &cookie_entry->node);
|
ebis_insert(cookies_tree, cookie_node);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* clear the tree and free its entries */
|
/* Perform a series of diagnostics on every servers from the configuration. */
|
||||||
while ((node = ebpt_first(&cookies_tree))) {
|
static void run_servers_diag(int *ret)
|
||||||
cookie_entry = ebpt_entry(node, struct cookie_entry, node);
|
{
|
||||||
eb_delete(&node->node);
|
struct eb_root cookies_tree = EB_ROOT_UNIQUE;
|
||||||
free(cookie_entry);
|
struct ebpt_node *cookie_node;
|
||||||
|
struct proxy *px;
|
||||||
|
struct server *srv;
|
||||||
|
|
||||||
|
for (px = proxies_list; px; px = px->next) {
|
||||||
|
for (srv = px->srv; srv; srv = srv->next)
|
||||||
|
srv_diag_cookies(ret, srv, &cookies_tree);
|
||||||
|
|
||||||
|
/* clear the cookies tree before passing to the next proxy */
|
||||||
|
while ((cookie_node = ebpt_first(&cookies_tree))) {
|
||||||
|
ebpt_delete(cookie_node);
|
||||||
|
free(cookie_node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +94,7 @@ int cfg_run_diagnostics()
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
check_server_cookies(&ret);
|
run_servers_diag(&ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user