From da754b45338a88d418e7d6c2e69234c05c686155 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 26 Mar 2024 15:26:43 +0100 Subject: [PATCH] MINOR: proxy: implement GUID support 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 | 9 +++++++++ include/haproxy/proxy-t.h | 3 +++ src/guid.c | 12 ++++++++++++ src/proxy.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+) diff --git a/doc/configuration.txt b/doc/configuration.txt index 68af0a844a..240785cde8 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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 See also : "maxconn", "server" +guid + 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 Specify the balancing factor for bounded-load consistent hashing diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h index 3dfa4d818d..f15c0ec13a 100644 --- a/include/haproxy/proxy-t.h +++ b/include/haproxy/proxy-t.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -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); }; diff --git a/src/guid.c b/src/guid.c index 1f21164271..d0f5fbc078 100644 --- a/src/guid.c +++ b/src/guid.c @@ -2,6 +2,7 @@ #include #include +#include #include /* 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; } diff --git a/src/proxy.c b/src/proxy.c index 2be87912f9..34067b04b1 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -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 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 }, }}; -- 2.39.5