mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 07:07:04 +02:00
MINOR: server: implement GUID support
This commit is similar to previous one, except that it implements GUID support for server instances. A guid_node field is inserted into server structure. A new "guid" server keyword is defined.
This commit is contained in:
parent
da754b4533
commit
8259456981
@ -16922,6 +16922,11 @@ force-tlsv13
|
|||||||
the server. This option is also available on global statement
|
the server. This option is also available on global statement
|
||||||
"ssl-default-server-options". See also "ssl-min-ver" and ssl-max-ver".
|
"ssl-default-server-options". See also "ssl-min-ver" and ssl-max-ver".
|
||||||
|
|
||||||
|
guid <string>
|
||||||
|
Specify a case-sensitive global unique ID for this server. This must be
|
||||||
|
unique accross all haproxy configuration on every object types. See "guid"
|
||||||
|
proxy keyword description for more information on its format.
|
||||||
|
|
||||||
id <value>
|
id <value>
|
||||||
May be used in the following contexts: tcp, http, log
|
May be used in the following contexts: tcp, http, log
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <haproxy/connection-t.h>
|
#include <haproxy/connection-t.h>
|
||||||
#include <haproxy/counters-t.h>
|
#include <haproxy/counters-t.h>
|
||||||
#include <haproxy/freq_ctr-t.h>
|
#include <haproxy/freq_ctr-t.h>
|
||||||
|
#include <haproxy/guid-t.h>
|
||||||
#include <haproxy/listener-t.h>
|
#include <haproxy/listener-t.h>
|
||||||
#include <haproxy/obj_type-t.h>
|
#include <haproxy/obj_type-t.h>
|
||||||
#include <haproxy/queue-t.h>
|
#include <haproxy/queue-t.h>
|
||||||
@ -466,6 +467,8 @@ struct server {
|
|||||||
|
|
||||||
event_hdl_sub_list e_subs; /* event_hdl: server's subscribers list (atomically updated) */
|
event_hdl_sub_list e_subs; /* event_hdl: server's subscribers list (atomically updated) */
|
||||||
|
|
||||||
|
struct guid_node guid; /* GUID global tree node */
|
||||||
|
|
||||||
/* warning, these structs are huge, keep them at the bottom */
|
/* warning, these structs are huge, keep them at the bottom */
|
||||||
struct conn_src conn_src; /* connection source settings */
|
struct conn_src conn_src; /* connection source settings */
|
||||||
struct sockaddr_storage addr; /* the address to connect to, doesn't include the port */
|
struct sockaddr_storage addr; /* the address to connect to, doesn't include the port */
|
||||||
|
10
src/guid.c
10
src/guid.c
@ -3,6 +3,7 @@
|
|||||||
#include <import/ebistree.h>
|
#include <import/ebistree.h>
|
||||||
#include <haproxy/obj_type.h>
|
#include <haproxy/obj_type.h>
|
||||||
#include <haproxy/proxy.h>
|
#include <haproxy/proxy.h>
|
||||||
|
#include <haproxy/server-t.h>
|
||||||
#include <haproxy/tools.h>
|
#include <haproxy/tools.h>
|
||||||
|
|
||||||
/* GUID global tree */
|
/* GUID global tree */
|
||||||
@ -45,6 +46,10 @@ int guid_insert(enum obj_type *objt, const char *uid, char **errmsg)
|
|||||||
guid = &__objt_proxy(objt)->guid;
|
guid = &__objt_proxy(objt)->guid;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OBJ_TYPE_SERVER:
|
||||||
|
guid = &__objt_server(objt)->guid;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
/* No guid support for this objtype. */
|
/* No guid support for this objtype. */
|
||||||
ABORT_NOW();
|
ABORT_NOW();
|
||||||
@ -110,12 +115,17 @@ char *guid_name(const struct guid_node *guid)
|
|||||||
{
|
{
|
||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
struct proxy *px;
|
struct proxy *px;
|
||||||
|
struct server *srv;
|
||||||
|
|
||||||
switch (obj_type(guid->obj_type)) {
|
switch (obj_type(guid->obj_type)) {
|
||||||
case OBJ_TYPE_PROXY:
|
case OBJ_TYPE_PROXY:
|
||||||
px = __objt_proxy(guid->obj_type);
|
px = __objt_proxy(guid->obj_type);
|
||||||
return memprintf(&msg, "%s %s", proxy_cap_str(px->cap), px->id);
|
return memprintf(&msg, "%s %s", proxy_cap_str(px->cap), px->id);
|
||||||
|
|
||||||
|
case OBJ_TYPE_SERVER:
|
||||||
|
srv = __objt_server(guid->obj_type);
|
||||||
|
return memprintf(&msg, "server %s/%s", srv->proxy->id, srv->id);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
28
src/server.c
28
src/server.c
@ -28,6 +28,7 @@
|
|||||||
#include <haproxy/dict-t.h>
|
#include <haproxy/dict-t.h>
|
||||||
#include <haproxy/errors.h>
|
#include <haproxy/errors.h>
|
||||||
#include <haproxy/global.h>
|
#include <haproxy/global.h>
|
||||||
|
#include <haproxy/guid.h>
|
||||||
#include <haproxy/log.h>
|
#include <haproxy/log.h>
|
||||||
#include <haproxy/mailers.h>
|
#include <haproxy/mailers.h>
|
||||||
#include <haproxy/namespace.h>
|
#include <haproxy/namespace.h>
|
||||||
@ -926,6 +927,28 @@ static int srv_parse_error_limit(char **args, int *cur_arg,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Parse the "guid" keyword */
|
||||||
|
static int srv_parse_guid(char **args, int *cur_arg,
|
||||||
|
struct proxy *curproxy, struct server *newsrv, char **err)
|
||||||
|
{
|
||||||
|
const char *guid;
|
||||||
|
char *guid_err = NULL;
|
||||||
|
|
||||||
|
if (!*args[*cur_arg + 1]) {
|
||||||
|
memprintf(err, "'%s' : expects an argument", args[*cur_arg]);
|
||||||
|
return ERR_ALERT | ERR_FATAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
guid = args[*cur_arg + 1];
|
||||||
|
if (guid_insert(&newsrv->obj_type, guid, &guid_err)) {
|
||||||
|
memprintf(err, "'%s': %s", args[*cur_arg], guid_err);
|
||||||
|
ha_free(&guid_err);
|
||||||
|
return ERR_ALERT | ERR_FATAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse the "ws" keyword */
|
/* Parse the "ws" keyword */
|
||||||
static int srv_parse_ws(char **args, int *cur_arg,
|
static int srv_parse_ws(char **args, int *cur_arg,
|
||||||
struct proxy *curproxy, struct server *newsrv, char **err)
|
struct proxy *curproxy, struct server *newsrv, char **err)
|
||||||
@ -2251,6 +2274,7 @@ static struct srv_kw_list srv_kws = { "ALL", { }, {
|
|||||||
{ "disabled", srv_parse_disabled, 0, 1, 1 }, /* Start the server in 'disabled' state */
|
{ "disabled", srv_parse_disabled, 0, 1, 1 }, /* Start the server in 'disabled' state */
|
||||||
{ "enabled", srv_parse_enabled, 0, 1, 0 }, /* Start the server in 'enabled' state */
|
{ "enabled", srv_parse_enabled, 0, 1, 0 }, /* Start the server in 'enabled' state */
|
||||||
{ "error-limit", srv_parse_error_limit, 1, 1, 1 }, /* Configure the consecutive count of check failures to consider a server on error */
|
{ "error-limit", srv_parse_error_limit, 1, 1, 1 }, /* Configure the consecutive count of check failures to consider a server on error */
|
||||||
|
{ "guid", srv_parse_guid, 1, 0, 1 }, /* Set global unique ID of the server */
|
||||||
{ "ws", srv_parse_ws, 1, 1, 1 }, /* websocket protocol */
|
{ "ws", srv_parse_ws, 1, 1, 1 }, /* websocket protocol */
|
||||||
{ "hash-key", srv_parse_hash_key, 1, 1, 1 }, /* Configure how chash keys are computed */
|
{ "hash-key", srv_parse_hash_key, 1, 1, 1 }, /* Configure how chash keys are computed */
|
||||||
{ "id", srv_parse_id, 1, 0, 1 }, /* set id# of server */
|
{ "id", srv_parse_id, 1, 0, 1 }, /* set id# of server */
|
||||||
@ -2856,6 +2880,8 @@ struct server *new_server(struct proxy *proxy)
|
|||||||
|
|
||||||
MT_LIST_INIT(&srv->sess_conns);
|
MT_LIST_INIT(&srv->sess_conns);
|
||||||
|
|
||||||
|
guid_init(&srv->guid);
|
||||||
|
|
||||||
srv->extra_counters = NULL;
|
srv->extra_counters = NULL;
|
||||||
#ifdef USE_OPENSSL
|
#ifdef USE_OPENSSL
|
||||||
HA_RWLOCK_INIT(&srv->ssl_ctx.lock);
|
HA_RWLOCK_INIT(&srv->ssl_ctx.lock);
|
||||||
@ -2918,6 +2944,8 @@ struct server *srv_drop(struct server *srv)
|
|||||||
if (HA_ATOMIC_SUB_FETCH(&srv->refcount, 1))
|
if (HA_ATOMIC_SUB_FETCH(&srv->refcount, 1))
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
|
guid_remove(&srv->guid);
|
||||||
|
|
||||||
/* make sure we are removed from our 'next->prev_deleted' list
|
/* make sure we are removed from our 'next->prev_deleted' list
|
||||||
* This doesn't require full thread isolation as we're using mt lists
|
* This doesn't require full thread isolation as we're using mt lists
|
||||||
* However this could easily be turned into regular list if required
|
* However this could easily be turned into regular list if required
|
||||||
|
Loading…
Reference in New Issue
Block a user