]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: spoe: Add internal sample fetch to retrieve the SPOE engine ID
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 5 Jul 2024 13:25:21 +0000 (15:25 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 12 Jul 2024 13:27:05 +0000 (15:27 +0200)
The internal sample fetch "spoe.engine-id" is added. It may be used to
retrieve the current engine identifier, but only if the client endpoint is
an SPOE applet. For now, this sample is not documented. It will only be used
to set the connection pool name for a specific engine. This way, several
engine can use the same SPOP backend without sharing their idle connections.

The documentation will be added later, mainly because other SPOE sample
fetches will be added, and some changes are expected.

The related issue is #2502.

src/flt_spoe.c

index c5f2006dc46077774e61a875520fc696970aec41..c31bfb1924cec841a64f051fe5fbd91c9ecf0d1d 100644 (file)
@@ -2984,6 +2984,31 @@ static enum act_parse_ret parse_send_spoe_group(const char **args, int *orig_arg
 }
 
 
+/* returns the engine ID of the SPOE */
+static int smp_fetch_spoe_engine_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       struct appctx *appctx;
+       struct spoe_agent *agent;
+
+        if (!smp->strm)
+                return 0;
+
+       appctx = sc_appctx(smp->strm->scf);
+       if (!appctx || appctx->applet != &spoe_applet)
+               return 0;
+
+       agent = spoe_appctx_agent(appctx);
+       if (!agent)
+               return 0;
+
+       smp->data.type = SMP_T_STR;
+       smp->data.u.str.area = agent->engine_id;
+       smp->data.u.str.data = strlen(agent->engine_id);
+       smp->flags = SMP_F_CONST;
+
+       return 1;
+}
+
 /* Declare the filter parser for "spoe" keyword */
 static struct flt_kw_list flt_kws = { "SPOE", { }, {
                { "spoe", parse_spoe_flt, NULL },
@@ -3025,3 +3050,11 @@ static struct action_kw_list http_res_action_kws = { { }, {
 };
 
 INITCALL1(STG_REGISTER, http_res_keywords_register, &http_res_action_kws);
+
+
+static struct sample_fetch_kw_list smp_kws = {ILH, {
+       { "spoe.engine-id",  smp_fetch_spoe_engine_id, 0, NULL, SMP_T_STR, SMP_USE_INTRN},
+       {},
+}};
+
+INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws);