]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: Add fe_defbe fetcher
authorMarcin Deranek <marcin.deranek@booking.com>
Fri, 13 Apr 2018 12:37:50 +0000 (14:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 16 Apr 2018 13:51:57 +0000 (15:51 +0200)
Patch adds ability to fetch frontend's default backend name in your
logic, so it can be used later to derive other backend names to make routing
decisions.

doc/configuration.txt
src/frontend.c

index 43c91114cef2e20453903dd0fd4466efec360107..22cd73671a4e759e73a4bb261f05196fc0598740 100644 (file)
@@ -13917,6 +13917,10 @@ fc_reordering(<unit>) : integer
   not TCP or if the operating system does not support TCP_INFO, for example
   Linux kernels before 2.4, the sample fetch fails.
 
+fe_defbe : string
+  Returns a string containing the frontend's default backend name. It can be
+  used in frontends to check which backend will handle requests by default.
+
 fe_id : integer
   Returns an integer containing the current frontend's id. It can be used in
   backends to check from which frontend it was called, or to stick all users
index 94d90f59be97d8e8702318cea4a52e84f324c414..361499dbaf92b6065e0e63d5da165a5f2b24c6ea 100644 (file)
@@ -194,6 +194,22 @@ smp_fetch_fe_name(const struct arg *args, struct sample *smp, const char *kw, vo
        return 1;
 }
 
+/* set string to the name of the default backend */
+static int
+smp_fetch_fe_defbe(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       if (!smp->sess->fe->defbe.be)
+               return 0;
+       smp->data.u.str.str = (char *)smp->sess->fe->defbe.be->id;
+       if (!smp->data.u.str.str)
+               return 0;
+
+       smp->data.type = SMP_T_STR;
+       smp->flags = SMP_F_CONST;
+       smp->data.u.str.len = strlen(smp->data.u.str.str);
+       return 1;
+}
+
 /* set temp integer to the number of HTTP requests per second reaching the frontend.
  * Accepts exactly 1 argument. Argument is a frontend, other types will cause
  * an undefined behaviour.
@@ -239,6 +255,7 @@ smp_fetch_fe_conn(const struct arg *args, struct sample *smp, const char *kw, vo
  */
 static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "fe_conn",      smp_fetch_fe_conn,      ARG1(1,FE), NULL, SMP_T_SINT, SMP_USE_INTRN, },
+       { "fe_defbe",     smp_fetch_fe_defbe,     0,          NULL, SMP_T_STR,  SMP_USE_FTEND, },
        { "fe_id",        smp_fetch_fe_id,        0,          NULL, SMP_T_SINT, SMP_USE_FTEND, },
        { "fe_name",      smp_fetch_fe_name,      0,          NULL, SMP_T_STR,  SMP_USE_FTEND, },
        { "fe_req_rate",  smp_fetch_fe_req_rate,  ARG1(1,FE), NULL, SMP_T_SINT, SMP_USE_INTRN, },