mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-08 08:07:10 +02:00
MINOR: proxy: support storing defaults sections into their own tree
Now we'll have a tree of named defaults sections. The regular insertion and lookup functions take care of the capability in order to select the appropriate tree. A new function proxy_destroy_defaults() removes a proxy from this tree and frees it entirely.
This commit is contained in:
parent
c02ab03142
commit
0a0f6a7e4f
@ -58,6 +58,7 @@ int proxy_cfg_ensure_no_http(struct proxy *curproxy);
|
|||||||
void init_new_proxy(struct proxy *p);
|
void init_new_proxy(struct proxy *p);
|
||||||
void proxy_preset_defaults(struct proxy *defproxy);
|
void proxy_preset_defaults(struct proxy *defproxy);
|
||||||
void proxy_free_defaults(struct proxy *defproxy);
|
void proxy_free_defaults(struct proxy *defproxy);
|
||||||
|
void proxy_destroy_defaults(struct proxy *px);
|
||||||
struct proxy *alloc_new_proxy(const char *name, unsigned int cap, const char *file, int linenum,
|
struct proxy *alloc_new_proxy(const char *name, unsigned int cap, const char *file, int linenum,
|
||||||
const struct proxy *defproxy, char **errmsg);
|
const struct proxy *defproxy, char **errmsg);
|
||||||
int get_backend_server(const char *bk_name, const char *sv_name,
|
int get_backend_server(const char *bk_name, const char *sv_name,
|
||||||
|
35
src/proxy.c
35
src/proxy.c
@ -53,6 +53,7 @@ int listeners; /* # of proxy listeners, set by cfgparse */
|
|||||||
struct proxy *proxies_list = NULL; /* list of all existing proxies */
|
struct proxy *proxies_list = NULL; /* list of all existing proxies */
|
||||||
struct eb_root used_proxy_id = EB_ROOT; /* list of proxy IDs in use */
|
struct eb_root used_proxy_id = EB_ROOT; /* list of proxy IDs in use */
|
||||||
struct eb_root proxy_by_name = EB_ROOT; /* tree of proxies sorted by name */
|
struct eb_root proxy_by_name = EB_ROOT; /* tree of proxies sorted by name */
|
||||||
|
struct eb_root defproxy_by_name = EB_ROOT; /* tree of default proxies sorted by name (dups possible) */
|
||||||
unsigned int error_snapshot_id = 0; /* global ID assigned to each error then incremented */
|
unsigned int error_snapshot_id = 0; /* global ID assigned to each error then incremented */
|
||||||
|
|
||||||
/* proxy->options */
|
/* proxy->options */
|
||||||
@ -738,13 +739,16 @@ static int proxy_parse_tcpka_intvl(char **args, int section, struct proxy *proxy
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This function inserts proxy <px> into the tree of known proxies. The proxy's
|
/* This function inserts proxy <px> into the tree of known proxies (regular
|
||||||
* name is used as the storing key so it must already have been initialized.
|
* ones or defaults depending on px->cap & PR_CAP_DEF). The proxy's name is
|
||||||
|
* used as the storing key so it must already have been initialized.
|
||||||
*/
|
*/
|
||||||
void proxy_store_name(struct proxy *px)
|
void proxy_store_name(struct proxy *px)
|
||||||
{
|
{
|
||||||
|
struct eb_root *root = (px->cap & PR_CAP_DEF) ? &defproxy_by_name : &proxy_by_name;
|
||||||
|
|
||||||
px->conf.by_name.key = px->id;
|
px->conf.by_name.key = px->id;
|
||||||
ebis_insert(&proxy_by_name, &px->conf.by_name);
|
ebis_insert(root, &px->conf.by_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns a pointer to the first proxy matching capabilities <cap> and id
|
/* Returns a pointer to the first proxy matching capabilities <cap> and id
|
||||||
@ -774,21 +778,25 @@ struct proxy *proxy_find_by_id(int id, int cap, int table)
|
|||||||
|
|
||||||
/* Returns a pointer to the first proxy matching either name <name>, or id
|
/* Returns a pointer to the first proxy matching either name <name>, or id
|
||||||
* <name> if <name> begins with a '#'. NULL is returned if no match is found.
|
* <name> if <name> begins with a '#'. NULL is returned if no match is found.
|
||||||
* If <table> is non-zero, it only considers proxies having a table.
|
* If <table> is non-zero, it only considers proxies having a table. The search
|
||||||
|
* is made into the regular proxies, unless <cap> has PR_CAP_DEF set in which
|
||||||
|
* case it's searched into the defproxy tree.
|
||||||
*/
|
*/
|
||||||
struct proxy *proxy_find_by_name(const char *name, int cap, int table)
|
struct proxy *proxy_find_by_name(const char *name, int cap, int table)
|
||||||
{
|
{
|
||||||
struct proxy *curproxy;
|
struct proxy *curproxy;
|
||||||
|
|
||||||
if (*name == '#') {
|
if (*name == '#' && !(cap & PR_CAP_DEF)) {
|
||||||
curproxy = proxy_find_by_id(atoi(name + 1), cap, table);
|
curproxy = proxy_find_by_id(atoi(name + 1), cap, table);
|
||||||
if (curproxy)
|
if (curproxy)
|
||||||
return curproxy;
|
return curproxy;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
struct eb_root *root;
|
||||||
struct ebpt_node *node;
|
struct ebpt_node *node;
|
||||||
|
|
||||||
for (node = ebis_lookup(&proxy_by_name, name); node; node = ebpt_next(node)) {
|
root = (cap & PR_CAP_DEF) ? &defproxy_by_name : &proxy_by_name;
|
||||||
|
for (node = ebis_lookup(root, name); node; node = ebpt_next(node)) {
|
||||||
curproxy = container_of(node, struct proxy, conf.by_name);
|
curproxy = container_of(node, struct proxy, conf.by_name);
|
||||||
|
|
||||||
if (strcmp(curproxy->id, name) != 0)
|
if (strcmp(curproxy->id, name) != 0)
|
||||||
@ -1156,6 +1164,21 @@ void proxy_free_defaults(struct proxy *defproxy)
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* delete a defproxy from the tree if still in it, frees its content and its
|
||||||
|
* storage. Nothing is done if <px> is NULL or if it doesn't have PR_CAP_DEF
|
||||||
|
* set, allowing to pass it the direct result of a lookup function.
|
||||||
|
*/
|
||||||
|
void proxy_destroy_defaults(struct proxy *px)
|
||||||
|
{
|
||||||
|
if (!px)
|
||||||
|
return;
|
||||||
|
if (!(px->cap & PR_CAP_DEF))
|
||||||
|
return;
|
||||||
|
ebpt_delete(&px->conf.by_name);
|
||||||
|
proxy_free_defaults(px);
|
||||||
|
free(px);
|
||||||
|
}
|
||||||
|
|
||||||
/* Allocates a new proxy <name> of type <cap> found at position <file:linenum>,
|
/* Allocates a new proxy <name> of type <cap> found at position <file:linenum>,
|
||||||
* preset it from the defaults of <defproxy> and returns it. Un case of error,
|
* preset it from the defaults of <defproxy> and returns it. Un case of error,
|
||||||
* an alert is printed and NULL is returned. If <errmsg> is not NULL, an error
|
* an alert is printed and NULL is returned. If <errmsg> is not NULL, an error
|
||||||
|
Loading…
Reference in New Issue
Block a user