]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: implement GUID support
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 26 Mar 2024 14:26:43 +0000 (15:26 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 5 Apr 2024 13:40:42 +0000 (15:40 +0200)
Implement proxy identiciation through GUID. As such, a guid_node member
is inserted into proxy structure. A proxy keyword "guid" is defined to
allow user to fix its value.

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

index 68af0a844adcad180afaee755222b541d8477b54..240785cde803244d6991c76a5898d110af880992 100644 (file)
@@ -4902,6 +4902,7 @@ error-log-format                          X          X         X         -
 force-persist                             -          -         X         X
 filter                                    -          X         X         X
 fullconn                                  X          -         X         X
+guid                                      -          X         X         X
 hash-balance-factor                       X          -         X         X
 hash-key                                  X          -         X         X
 hash-type                                 X          -         X         X
@@ -6666,6 +6667,14 @@ fullconn <conns>
   See also : "maxconn", "server"
 
 
+guid <string>
+  Specify a case-sensitive global unique ID for this proxy. This must be unique
+  accross all haproxy configuration on every object types. Format is left
+  unspecified to allow the user to select its naming policy. The only
+  restriction is its length which cannot be greater than 127 characters. All
+  alphanumerical values and '.', ':', '-' and '_' characters are valid.
+
+
 hash-balance-factor <factor>
   Specify the balancing factor for bounded-load consistent hashing
 
index 3dfa4d818db0fd3b1232730690950853cfc67c6e..f15c0ec13a530e9dda0b07c96fbbb3d9faa1e2e4 100644 (file)
@@ -35,6 +35,7 @@
 #include <haproxy/compression-t.h>
 #include <haproxy/counters-t.h>
 #include <haproxy/freq_ctr-t.h>
+#include <haproxy/guid-t.h>
 #include <haproxy/obj_type-t.h>
 #include <haproxy/queue-t.h>
 #include <haproxy/server-t.h>
@@ -457,6 +458,8 @@ struct proxy {
                                                 */
        struct list filter_configs;             /* list of the filters that are declared on this proxy */
 
+       struct guid_node guid;                  /* GUID global tree node */
+
        EXTRA_COUNTERS(extra_counters_fe);
        EXTRA_COUNTERS(extra_counters_be);
 };
index 1f211642719c110e215e89b3d6cfca6032e61ede..d0f5fbc0789b3a9c50f53534a268d86a0517b67b 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <import/ebistree.h>
 #include <haproxy/obj_type.h>
+#include <haproxy/proxy.h>
 #include <haproxy/tools.h>
 
 /* GUID global tree */
@@ -40,6 +41,10 @@ int guid_insert(enum obj_type *objt, const char *uid, char **errmsg)
        }
 
        switch (obj_type(objt)) {
+       case OBJ_TYPE_PROXY:
+               guid = &__objt_proxy(objt)->guid;
+               break;
+
        default:
                /* No guid support for this objtype. */
                ABORT_NOW();
@@ -103,7 +108,14 @@ struct guid_node *guid_lookup(const char *uid)
  */
 char *guid_name(const struct guid_node *guid)
 {
+       char *msg = NULL;
+       struct proxy *px;
+
        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);
+
        default:
                break;
        }
index 2be87912f9fe517383ca1a5792b1f2c2d16302f2..34067b04b129823a7eda111cb8f52f7ee511523d 100644 (file)
@@ -29,6 +29,7 @@
 #include <haproxy/fd.h>
 #include <haproxy/filters.h>
 #include <haproxy/global.h>
+#include <haproxy/guid.h>
 #include <haproxy/http_ana.h>
 #include <haproxy/http_htx.h>
 #include <haproxy/http_ext.h>
@@ -232,6 +233,8 @@ void free_proxy(struct proxy *p)
                free_acl_cond(cond);
        }
 
+       guid_remove(&p->guid);
+
        EXTRA_COUNTERS_FREE(p->extra_counters_fe);
        EXTRA_COUNTERS_FREE(p->extra_counters_be);
 
@@ -1010,6 +1013,33 @@ static int proxy_parse_tcpka_intvl(char **args, int section, struct proxy *proxy
 }
 #endif
 
+static int proxy_parse_guid(char **args, int section_type, struct proxy *curpx,
+                            const struct proxy *defpx, const char *file, int line,
+                            char **err)
+{
+       const char *guid;
+       char *guid_err = NULL;
+
+       if (curpx->cap & PR_CAP_DEF) {
+               ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, line, args[0]);
+               return -1;
+       }
+
+       if (!*args[1]) {
+               memprintf(err, "'%s' : expects an argument", args[0]);
+               return -1;
+       }
+
+       guid = args[1];
+       if (guid_insert(&curpx->obj_type, guid, &guid_err)) {
+               memprintf(err, "'%s': %s", args[0], guid_err);
+               ha_free(&guid_err);
+               return -1;
+       }
+
+       return 0;
+}
+
 /* This function inserts proxy <px> into the tree of known proxies (regular
  * 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.
@@ -1348,6 +1378,8 @@ void init_new_proxy(struct proxy *p)
        /* Default to only allow L4 retries */
        p->retry_type = PR_RE_CONN_FAILED;
 
+       guid_init(&p->guid);
+
        p->extra_counters_fe = NULL;
        p->extra_counters_be = NULL;
 
@@ -2569,6 +2601,7 @@ static struct cfg_kw_list cfg_kws = {ILH, {
        { CFG_LISTEN, "clitcpka-intvl", proxy_parse_tcpka_intvl },
        { CFG_LISTEN, "srvtcpka-intvl", proxy_parse_tcpka_intvl },
 #endif
+       { CFG_LISTEN, "guid", proxy_parse_guid },
        { 0, NULL, NULL },
 }};