]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MAJOR: log: implement proper postparsing for logformat expressions
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 23 Feb 2024 16:26:32 +0000 (17:26 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 4 Apr 2024 17:10:01 +0000 (19:10 +0200)
commit7a21c3a4ef1577985621953a79e2776ef97837ab
tree011c165b1ef587e32083765e1bf3751a5bb143d4
parent56d8074798772978f37fbca5667ad3d3ddc8ab20
MAJOR: log: implement proper postparsing for logformat expressions

This patch tries to address a design flaw with how logformat expressions
are parsed from config. Indeed, some parse_logformat_string() calls are
performed during config parsing when the proxy mode is not yet known.

Here's a config example that illustrates the issue:

  defaults
     mode tcp

  listen test
     bind :8888
     http-response set-header custom-hdr "%trl" # needs http
     mode http

The above config should work, because the effective proxy mode is http,
yet haproxy fails with this error:

  [ALERT]    (99051) : config : parsing [repro.conf:6] : error detected in proxy 'test' while parsing 'http-response set-header' rule : format tag 'trl' is reserved for HTTP mode.

To fix the issue once and for all, let's implement smart postparsing for
logformat expressions encountered during config parsing:

  - split parse_logformat_string() (and subfonctions) in order to create a
    new lf_expr_postcheck() function that must be called to finish
    preparing and checking the logformat expression once the proxy type is
    known.
  - save some config hints info during parse_logformat_string() to
    generate more precise error messages during lf_expr_postcheck(), if
    needed, we rely on curpx->conf.args.{file,line} hints for that because
    parse_logformat_string() doesn't know about current file and line
    number.
  - lf_expr_postcheck() uses PR_FL_CHECKED proxy flag to know if the
    function may try to make the proxy compatible with the expression, or
    if it should simply fail as soon as an incompatibility is detected.
  - if parse_logformat_string() is called from an unchecked proxy, then
    schedule the expression for postparsing, else (ie: during runtime),
    run the postcheck right away.

This change will also allow for some logformat expression error handling
simplifications in the future.
include/haproxy/log-t.h
include/haproxy/log.h
include/haproxy/proxy-t.h
src/http_act.c
src/http_client.c
src/http_htx.c
src/http_rules.c
src/log.c
src/proxy.c
src/vars.c