]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: server: distinguish name references with new SRV_F_NAME_REFD flag
authorAlexander Stephan <alexander.stephan@sap.com>
Thu, 25 Jun 2026 09:04:59 +0000 (09:04 +0000)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 1 Jul 2026 07:11:18 +0000 (09:11 +0200)
Until now, every form of "this server is referenced by something in the
running config" was collapsed onto a single flag, SRV_F_NON_PURGEABLE,
which prevents the server from being removed via 'del server'. This
catches everything but conflates two distinct properties:

  - the server object itself is pinned by another runtime structure
    (e.g. DNS resolution attached to it), versus
  - the server's *name* is referenced statically (use-server rules,
    track chains, sample-fetch arguments of type ARGT_SRV)

These differ for any operation that touches the name but not the
object identity, e.g. the runtime rename feature added next. Removing
a name-referenced server is still forbidden (the rule text would
dangle), but renaming such a server should also be forbidden for the
same reason - while renaming a resolver-pinned server is fine, since
the resolver holds the object pointer and doesn't care about the name.

Introduce SRV_F_NAME_REFD for the name-reference case and move the
three name-based setters (sample.c ARGT_SRV resolution, proxy.c
use-server resolution, server.c track chain setup) from
SRV_F_NON_PURGEABLE to SRV_F_NAME_REFD. The resolvers.c call site
keeps SRV_F_NON_PURGEABLE since it is the object-pinned case.

Adjust 'del server' to check both flags so the set of servers it
refuses to remove is unchanged: same observable behavior, just a
richer internal taxonomy.

A subsequent patch introducing 'set server name' will gate on
SRV_F_NAME_REFD only.

include/haproxy/server-t.h
src/proxy.c
src/sample.c
src/server.c

index 74f206a922f0cae29cac306a96d4bb8a8ce43789..ca332d4a1469d6affa2bc224f063530099bcee42 100644 (file)
@@ -174,6 +174,7 @@ enum srv_init_state {
 #define SRV_F_STRICT_MAXCONN 0x10000     /* maxconn is to be strictly enforced, as a limit of outbound connections */
 #define SRV_F_CHK_NO_AUTO_SNI 0x20000    /* disable automatic SNI selection for healthcheck */
 #define SRV_F_UDP_GSO_NOTSUPP 0x40000    /* UDP GSO is disabled due to a previous error encountered */
+#define SRV_F_NAME_REFD    0x80000       /* this server's name is statically referenced (use-server, track, sample arg) */
 
 /* configured server options for send-proxy (server->pp_opts) */
 #define SRV_PP_V1               0x0001   /* proxy protocol version 1 */
index 885ea679ed87c836e1778dd7a946fcccff7b8688..8592e409a97960ca6b62451f3a11579c73edc836 100644 (file)
@@ -2119,7 +2119,7 @@ int proxy_finalize(struct proxy *px, int *err_code)
                }
                ha_free(&srule->srv.name);
                srule->srv.ptr = target;
-               target->flags |= SRV_F_NON_PURGEABLE;
+               target->flags |= SRV_F_NAME_REFD;
        }
 
        /* find the target table for 'stick' rules */
index fbe7e1afb7b4013df8dab81ad05f14f1e4d6e76c..84ce15c8076ebae58725cd50ab5956e3ee61a97e 100644 (file)
@@ -1538,7 +1538,7 @@ int smp_resolve_args(struct proxy *p, char **err)
                        }
 
                        /* TODO CLI set-var should not prevent server deletion as var value is instantly resolved. */
-                       srv->flags |= SRV_F_NON_PURGEABLE;
+                       srv->flags |= SRV_F_NAME_REFD;
 
                        chunk_destroy(&arg->data.str);
                        arg->unresolved = 0;
index fa7e2583c182ad3121915b974eeed06849ac711e..7f8422f75a0c481779f776cca298087e3c7da56c 100644 (file)
@@ -6532,7 +6532,7 @@ int srv_check_for_deletion(const char *bename, const char *svname, struct proxy
                goto leave;
        }
 
-       if (srv->flags & SRV_F_NON_PURGEABLE) {
+       if (srv->flags & (SRV_F_NON_PURGEABLE | SRV_F_NAME_REFD)) {
                msg = "This server cannot be removed at runtime due to other configuration elements pointing to it.";
                goto leave;
        }
@@ -6783,7 +6783,7 @@ int srv_apply_track(struct server *srv, struct proxy *curproxy)
        srv->track = strack;
        srv->tracknext = strack->trackers;
        strack->trackers = srv;
-       strack->flags |= SRV_F_NON_PURGEABLE;
+       strack->flags |= SRV_F_NAME_REFD;
 
        ha_free(&srv->trackit);