From: Christopher Faulet Date: Fri, 5 Jul 2024 13:25:21 +0000 (+0200) Subject: MINOR: spoe: Add internal sample fetch to retrieve the SPOE engine ID X-Git-Tag: v3.1-dev4~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=706a57d55a315432848c54d7a202bfe174183918;p=thirdparty%2Fhaproxy.git MINOR: spoe: Add internal sample fetch to retrieve the SPOE engine ID 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. --- diff --git a/src/flt_spoe.c b/src/flt_spoe.c index c5f2006dc4..c31bfb1924 100644 --- a/src/flt_spoe.c +++ b/src/flt_spoe.c @@ -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);