From: Christopher Faulet Date: Thu, 8 Nov 2018 10:34:21 +0000 (+0100) Subject: MINOR: lua/htx: Forbid lua usage when the HTX is enabled on a proxy X-Git-Tag: v1.9-dev7~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afd8f10be928e34404e4fd8a36141fa88fb0212c;p=thirdparty%2Fhaproxy.git MINOR: lua/htx: Forbid lua usage when the HTX is enabled on a proxy For now, the lua scripts are not compatible with the new HTX internal representation of HTTP messages. Thus, for a given proxy, when the option "http-use-htx" is enabled, an error is triggered if any lua's action/service/sample-fetch/converter is also configured. --- diff --git a/src/hlua.c b/src/hlua.c index 2364317745..33bf71ee48 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -5756,6 +5756,11 @@ static int hlua_sample_conv_wrapper(const struct arg *arg_p, struct sample *smp, if (!stream) return 0; + if (IS_HTX_STRM(stream)) { + SEND_ERR(stream->be, "Lua converter '%s': Lua fetches cannot be used when the" + " HTX internal representation is enabled.\n", fcn->name); + return 0; + } /* In the execution wrappers linked with a stream, the * Lua context can be not initialized. This behavior * permits to save performances because a systematic @@ -5888,6 +5893,12 @@ static int hlua_sample_fetch_wrapper(const struct arg *arg_p, struct sample *smp if (!stream) return 0; + if (IS_HTX_STRM(stream)) { + SEND_ERR(stream->be, "Lua sample-fetch '%s': Lua fetches cannot be used when the" + " HTX internal representation is enabled.\n", fcn->name); + return 0; + } + /* In the execution wrappers linked with a stream, the * Lua context can be not initialized. This behavior * permits to save performances because a systematic @@ -6833,6 +6844,11 @@ static enum act_parse_ret action_register_lua(const char **args, int *cur_arg, s struct hlua_function *fcn = rule->kw->private; int i; + if (px->options2 & PR_O2_USE_HTX) { + memprintf(err, "Lua actions cannot be used when the HTX internal representation is enabled"); + return ACT_RET_PRS_ERR; + } + /* Memory for the rule. */ rule->arg.hlua_rule = calloc(1, sizeof(*rule->arg.hlua_rule)); if (!rule->arg.hlua_rule) { @@ -6875,6 +6891,11 @@ static enum act_parse_ret action_register_service_http(const char **args, int *c { struct hlua_function *fcn = rule->kw->private; + if (px->options2 & PR_O2_USE_HTX) { + memprintf(err, "Lua services cannot be used when the HTX internal representation is enabled"); + return ACT_RET_PRS_ERR; + } + /* HTTP applets are forbidden in tcp-request rules. * HTTP applet request requires everything initilized by * "http_process_request" (analyzer flag AN_REQ_HTTP_INNER). @@ -7007,6 +7028,11 @@ static enum act_parse_ret action_register_service_tcp(const char **args, int *cu { struct hlua_function *fcn = rule->kw->private; + if (px->options2 & PR_O2_USE_HTX) { + memprintf(err, "Lua services cannot be used when the HTX internal representation is enabled"); + return ACT_RET_PRS_ERR; + } + /* Memory for the rule. */ rule->arg.hlua_rule = calloc(1, sizeof(*rule->arg.hlua_rule)); if (!rule->arg.hlua_rule) { @@ -7494,6 +7520,34 @@ static struct cfg_kw_list cfg_kws = {{ },{ { 0, NULL, NULL }, }}; +static int hlua_check_config() +{ + struct proxy *px; + struct acl *acl; + struct acl_expr *expr; + struct sample_fetch *fetch; + int err = 0; + + for (px = proxies_list; px; px = px->next) { + if (!(px->options2 & PR_O2_USE_HTX)) + continue; + + list_for_each_entry(acl, &px->acl, list) { + list_for_each_entry(expr, &acl->expr, list) { + fetch = expr->smp->fetch; + if (fetch->process != hlua_sample_fetch_wrapper) + continue; + + ha_alert("config: %s '%s': sample-fetch '%s' cannot be used used " + "when the HTX internal representation is enabled.\n", + proxy_type_str(px), px->id, fetch->kw); + err++; + } + } + } + return err; +} + /* This function can fail with an abort() due to an Lua critical error. * We are in the initialisation process of HAProxy, this abort() is * tolerated. @@ -8161,4 +8215,5 @@ static void __hlua_init(void) char *ptr = NULL; memprintf(&ptr, "Built with Lua version : %s", LUA_RELEASE); hap_register_build_opts(ptr, 1); + cfg_register_postparser("hlua", hlua_check_config); }