]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: converter for frontend existence check
authorPierre Cheynier <p.cheynier@criteo.com>
Fri, 17 Apr 2026 07:37:14 +0000 (07:37 +0000)
committerWilliam Lallemand <wlallemand@haproxy.com>
Fri, 24 Apr 2026 13:22:09 +0000 (15:22 +0200)
Introduced a new sample converter using keyword "fe_exists" checking if
a frontend with a given name exists.

doc/configuration.txt
src/frontend.c

index 3ddd176f14b799463ecf15a9c19ba9b04f1d583b..461c07b4045ddbe31366e703d0b61a3573d7610f 100644 (file)
@@ -21018,6 +21018,7 @@ eth.proto                                          binary       integer
 eth.src                                            binary       binary
 eth.vlan                                           binary       integer
 even                                               integer      boolean
+fe_exists                                          string       boolean
 field(index,delimiters[,count])                    string       string
 fix_is_valid                                       binary       boolean
 fix_tag_value(tag)                                 binary       binary
@@ -21548,6 +21549,15 @@ field(<index>,<delimiters>[,<count>])
       str(f1_f2_f3__f5),field(-2,_,3) # f2_f3_
       str(f1_f2_f3__f5),field(-3,_,0) # f1_f2_f3
 
+fe_exists
+  Takes a frontend name as input value and returns a boolean TRUE if the said
+  frontend with that name exists in the current configuration, otherwise returns
+  FALSE. Can be used in places where checking the existence of a frontend from a
+  dynamic name is valuable, like map lookups or answering to an external check.
+
+  Example :
+      http-request deny unless { var(txn.fe_name),fe_exists }
+
 fix_is_valid
   Parses a binary payload and performs sanity checks regarding FIX (Financial
   Information eXchange):
index 3838782126cacb2b19fe641998ddb3f87abd36e5..79acbb00f7605d9dda7c3d0461dd11dfc7363b6b 100644 (file)
@@ -326,6 +326,16 @@ smp_fetch_fe_tarpit_timeout(const struct arg *args, struct sample *smp, const ch
        return 1;
 }
 
+static int
+sample_conv_fe_exists(const struct arg *args, struct sample *smp, void *private)
+{
+       if (!smp_make_safe(smp))
+               return 0;
+
+       smp->data.type = SMP_T_BOOL;
+       smp->data.u.sint = proxy_fe_by_name(smp->data.u.str.area) != NULL;
+       return 1;
+}
 
 /* Note: must not be declared <const> as its list will be overwritten.
  * Please take care of keeping this list alphabetically sorted.
@@ -344,6 +354,14 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
 
 INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws);
 
+/* Note: must not be declared <const> as its list will be overwritten */
+static struct sample_conv_kw_list sample_conv_kws = {ILH, {
+       { "fe_exists", sample_conv_fe_exists, 0, NULL, SMP_T_STR, SMP_T_BOOL },
+       { /* END */ },
+}};
+
+INITCALL1(STG_REGISTER, sample_register_convs, &sample_conv_kws);
+
 /* Note: must not be declared <const> as its list will be overwritten.
  * Please take care of keeping this list alphabetically sorted.
  */