From: Willy Tarreau Date: Tue, 22 Apr 2014 23:32:02 +0000 (+0200) Subject: MEDIUM: config: report misplaced http-request rules X-Git-Tag: v1.5-dev23~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5002f571860b375344c915de298ae41cc3bdaadd;p=thirdparty%2Fhaproxy.git MEDIUM: config: report misplaced http-request rules Recently, the http-request ruleset started to be used a lot and some bug reports were caused by misplaced http-request rules because there was no warning if they're after a redirect or use_backend rule. Let's fix this now. http-request rules are just after the block rules. --- diff --git a/src/cfgparse.c b/src/cfgparse.c index 53b136a36a..7249062ee7 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -320,6 +320,19 @@ int warnif_rule_after_block(struct proxy *proxy, const char *file, int line, con return 0; } +/* Report a warning if a rule is placed after an 'http_request' rule. + * Return 1 if the warning has been emitted, otherwise 0. + */ +int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) +{ + if (!LIST_ISEMPTY(&proxy->http_req_rules)) { + Warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", + file, line, arg); + return 1; + } + return 0; +} + /* Report a warning if a rule is placed after a reqrewrite rule. * Return 1 if the warning has been emitted, otherwise 0. */ @@ -374,6 +387,16 @@ int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int lin /* report a warning if a block rule is dangerously placed */ int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, const char *arg) +{ + return warnif_rule_after_http_req(proxy, file, line, arg) || + warnif_rule_after_reqxxx(proxy, file, line, arg) || + warnif_rule_after_reqadd(proxy, file, line, arg) || + warnif_rule_after_redirect(proxy, file, line, arg) || + warnif_rule_after_use_backend(proxy, file, line, arg); +} + +/* report a warning if an http-request rule is dangerously placed */ +int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) { return warnif_rule_after_reqxxx(proxy, file, line, arg) || warnif_rule_after_reqadd(proxy, file, line, arg) || @@ -2748,6 +2771,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) goto out; } + err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); err_code |= warnif_cond_conflicts(rule->cond, (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, file, linenum);