Introduced a new sample fetch keyword "fe_exist" that checks if a
frontend with a given name exists.
---
v2: added documentation for the fe_exist converter

 doc/configuration.txt | 10 ++++++++++
 src/frontend.c        | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/doc/configuration.txt b/doc/configuration.txt
index 0c36951d7..6913008ae 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -20971,6 +20971,7 @@ eth.proto                                          
binary       integer
 eth.src                                            binary       binary
 eth.vlan                                           binary       integer
 even                                               integer      boolean
+fe_exist                                           string       boolean
 field(index,delimiters[,count])                    string       string
 fix_is_valid                                       binary       boolean
 fix_tag_value(tag)                                 binary       binary
@@ -21501,6 +21502,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_exist
+  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_exist }
+
 fix_is_valid
   Parses a binary payload and performs sanity checks regarding FIX (Financial
   Information eXchange):
diff --git a/src/frontend.c b/src/frontend.c
index 1df11fcb7..2ca788cbf 100644
--- a/src/frontend.c
+++ b/src/frontend.c
@@ -323,6 +323,16 @@ smp_fetch_fe_tarpit_timeout(const struct arg *args, struct 
sample *smp, const ch
        return 1;
 }
 
+static int
+sample_conv_fe_exist(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.
@@ -341,6 +351,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_exist", sample_conv_fe_exist, 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.
  */
-- 
2.43.0

Reply via email to