Skip to content

Commit d1a7330

Browse files
Darleletcapflam
authored andcommitted
BUG/MEDIUM: log: fix lf_expr_postcheck() behavior with default section
Since 7a21c3a ("MAJOR: log: implement proper postparsing for logformat expressions"), logformat expressions stored in a default section are not postchecked anymore. This is because the REGISTER_POST_PROXY_CHECK() only evaluates regular proxies. Because of this, proxy options which are automatically enabled on the proxy depending on the logformat expression features in use are not set on the default proxy, which means such options are not passed to the regular proxies that inherit from it (proxies that and will actually be running the logformat expression during runtime). Because of that, a logformat expression stored inside a default section and executed by a regular proxy may not behave properly. Also, since 03ca16f ("OPTIM: log: resolve logformat options during postparsing"), it's even worse because logformat node options postresoving is also skipped, which may also alter logformat expression encoding feature. To fix the issue, let's add a special case for default proxies in parse_logformat_string() and lf_expr_postcheck() so that default proxies are postchecked on the fly during parsing time in a "relaxed" way as we cannot assume that the features involved in the logformat expression won't be compatible with the proxy actually running it since we may have different types of proxies inheriting from the same default section. This bug was discovered while trying to address GH #2597. It should be backported to 3.0 with 7a21c3a and 03ca16f. (cherry picked from commit e4f122f) Signed-off-by: Christopher Faulet <[email protected]>
1 parent 310c0dd commit d1a7330

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/log.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,15 +870,17 @@ int parse_logformat_string(const char *fmt, struct proxy *curproxy,
870870
if (!ret)
871871
goto fail;
872872

873-
if (!(curproxy->flags & PR_FL_CHECKED)) {
873+
if (!(curproxy->cap & PR_CAP_DEF) &&
874+
!(curproxy->flags & PR_FL_CHECKED)) {
874875
/* add the lf_expr to the proxy checks to delay postparsing
875876
* since config-related proxy properties are not stable yet
876877
*/
877878
LIST_APPEND(&curproxy->conf.lf_checks, &lf_expr->list);
878879
}
879880
else {
880-
/* probably called during runtime or with proxy already checked,
881-
* perform the postcheck right away
881+
/* default proxy, or regular proxy and probably called during
882+
* runtime or with proxy already checked, perform the postcheck
883+
* right away
882884
*/
883885
if (!lf_expr_postcheck(lf_expr, curproxy, err))
884886
goto fail;
@@ -948,11 +950,17 @@ static int lf_expr_postcheck_node_opt(struct lf_expr *lf_expr, struct logformat_
948950
* compatible with logformat expression, but once the proxy is checked, we fail
949951
* as soon as we face incompatibilities)
950952
*
953+
* If the proxy is a default section, then allow the postcheck to succeed:
954+
* the logformat expression may or may not work properly depending on the
955+
* actual proxy that effectively runs it during runtime, but we have to stay
956+
* permissive since we cannot assume it won't work.
957+
*
951958
* It returns 1 on success and 0 on error, <err> will be set in case of error.
952959
*/
953960
int lf_expr_postcheck(struct lf_expr *lf_expr, struct proxy *px, char **err)
954961
{
955962
struct logformat_node *lf;
963+
int default_px = (px->cap & PR_CAP_DEF);
956964

957965
if (!(px->flags & PR_FL_CHECKED))
958966
px->to_log |= LW_INIT;
@@ -987,7 +995,8 @@ int lf_expr_postcheck(struct lf_expr *lf_expr, struct proxy *px, char **err)
987995
px->to_log |= LW_REQ;
988996
}
989997
else if (lf->type == LOG_FMT_ALIAS) {
990-
if (lf->alias->mode == PR_MODE_HTTP && px->mode != PR_MODE_HTTP) {
998+
if (lf->alias->mode == PR_MODE_HTTP &&
999+
!default_px && px->mode != PR_MODE_HTTP) {
9911000
memprintf(err, "format alias '%s' is reserved for HTTP mode",
9921001
lf->alias->name);
9931002
goto fail;
@@ -1006,7 +1015,7 @@ int lf_expr_postcheck(struct lf_expr *lf_expr, struct proxy *px, char **err)
10061015
if (!lf_expr_postcheck_node_opt(lf_expr, lf, err))
10071016
goto fail;
10081017
}
1009-
if ((px->to_log & (LW_REQ | LW_RESP)) &&
1018+
if (!default_px && (px->to_log & (LW_REQ | LW_RESP)) &&
10101019
(px->mode != PR_MODE_HTTP && !(px->options & PR_O_HTTP_UPG))) {
10111020
memprintf(err, "logformat expression not usable here (at least one node depends on HTTP mode)");
10121021
goto fail;

0 commit comments

Comments
 (0)