]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: server: implement GUID support
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 26 Mar 2024 14:01:35 +0000 (15:01 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 5 Apr 2024 13:40:42 +0000 (15:40 +0200)
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.

doc/configuration.txt
include/haproxy/server-t.h
src/guid.c
src/server.c

index 240785cde803244d6991c76a5898d110af880992..c42f9ea59459f702d511b31dcebe3c026c1ea4fe 100644 (file)
@@ -16922,6 +16922,11 @@ force-tlsv13
   the server. This option is also available on global statement
   "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>
   May be used in the following contexts: tcp, http, log
 
index 70489ff784db30f7df64287bd6631f8f18ebecd9..3bc2371e153aea12a29158498fb33a05cdba177d 100644 (file)
@@ -32,6 +32,7 @@
 #include <haproxy/connection-t.h>
 #include <haproxy/counters-t.h>
 #include <haproxy/freq_ctr-t.h>
+#include <haproxy/guid-t.h>
 #include <haproxy/listener-t.h>
 #include <haproxy/obj_type-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) */
 
+       struct guid_node guid;                  /* GUID global tree node */
+
        /* warning, these structs are huge, keep them at the bottom */
        struct conn_src conn_src;               /* connection source settings */
        struct sockaddr_storage addr;           /* the address to connect to, doesn't include the port */
index d0f5fbc0789b3a9c50f53534a268d86a0517b67b..af04f1a816e34abf1056a7c1616e3dbc510f5663 100644 (file)
@@ -3,6 +3,7 @@
 #include <import/ebistree.h>
 #include <haproxy/obj_type.h>
 #include <haproxy/proxy.h>
+#include <haproxy/server-t.h>
 #include <haproxy/tools.h>
 
 /* GUID global tree */
@@ -45,6 +46,10 @@ int guid_insert(enum obj_type *objt, const char *uid, char **errmsg)
                guid = &__objt_proxy(objt)->guid;
                break;
 
+       case OBJ_TYPE_SERVER:
+               guid = &__objt_server(objt)->guid;
+               break;
+
        default:
                /* No guid support for this objtype. */
                ABORT_NOW();
@@ -110,12 +115,17 @@ char *guid_name(const struct guid_node *guid)
 {
        char *msg = NULL;
        struct proxy *px;
+       struct server *srv;
 
        switch (obj_type(guid->obj_type)) {
        case OBJ_TYPE_PROXY:
                px = __objt_proxy(guid->obj_type);
                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:
                break;
        }
index e537473e9ca5d8c0b15a074426715bbae8458254..281afbf0811986f77c99b47d92969b4859149147 100644 (file)
@@ -28,6 +28,7 @@
 #include <haproxy/dict-t.h>
 #include <haproxy/errors.h>
 #include <haproxy/global.h>
+#include <haproxy/guid.h>
 #include <haproxy/log.h>
 #include <haproxy/mailers.h>
 #include <haproxy/namespace.h>
@@ -926,6 +927,28 @@ static int srv_parse_error_limit(char **args, int *cur_arg,
        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 */
 static int srv_parse_ws(char **args, int *cur_arg,
                         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 */
        { "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 */
+       { "guid",                 srv_parse_guid,                 1,  0,  1 }, /* Set global unique ID of the server */
        { "ws",                   srv_parse_ws,                   1,  1,  1 }, /* websocket protocol */
        { "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 */
@@ -2856,6 +2880,8 @@ struct server *new_server(struct proxy *proxy)
 
        MT_LIST_INIT(&srv->sess_conns);
 
+       guid_init(&srv->guid);
+
        srv->extra_counters = NULL;
 #ifdef USE_OPENSSL
        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))
                goto end;
 
+       guid_remove(&srv->guid);
+
        /* make sure we are removed from our 'next->prev_deleted' list
         * This doesn't require full thread isolation as we're using mt lists
         * However this could easily be turned into regular list if required