From: Pierre Cheynier Date: Fri, 17 Apr 2026 07:37:14 +0000 (+0000) Subject: MINOR: sample: converter for frontend existence check X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=85c3f3c1fd0003bc972f61dbf23a25cf9ed93ef6;p=thirdparty%2Fhaproxy.git MINOR: sample: converter for frontend existence check Introduced a new sample converter using keyword "fe_exists" checking if a frontend with a given name exists. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 3ddd176f1..461c07b40 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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(,[,]) 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): diff --git a/src/frontend.c b/src/frontend.c index 383878212..79acbb00f 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -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 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 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 as its list will be overwritten. * Please take care of keeping this list alphabetically sorted. */