]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgparse: Emit a warning for misplaced "tcp-response content" rules
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 21 Nov 2024 08:55:03 +0000 (09:55 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 21 Nov 2024 08:55:04 +0000 (09:55 +0100)
When a "tcp-response content" rule is placed after a "http-response" rule, a
warning is now emitted, just like for rules applied on the requests.

include/haproxy/cfgparse.h
src/cfgparse-listen.c
src/tcp_rules.c

index de23bb74668c4d8241eb8f9a0baa5ab6b217884d..7b89b7a1f40c686f46cc9b52dc20d108110223a9 100644 (file)
@@ -131,6 +131,7 @@ void cfg_restore_sections(struct list *backup_sections);
 int warnif_misplaced_tcp_req_conn(struct proxy *proxy, const char *file, int line, const char *arg1, const char *arg2);
 int warnif_misplaced_tcp_req_sess(struct proxy *proxy, const char *file, int line, const char *arg, const char *arg2);
 int warnif_misplaced_tcp_req_cont(struct proxy *proxy, const char *file, int line, const char *arg, const char *arg2);
+int warnif_misplaced_tcp_res_cont(struct proxy *proxy, const char *file, int line, const char *arg, const char *arg2);
 int warnif_misplaced_quic_init(struct proxy *proxy, const char *file, int line, const char *arg, const char *arg2);
 int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line);
 int warnif_tcp_http_cond(const struct proxy *px, const struct acl_cond *cond);
index 235733343308ef69a837cfbd22a76da3f0ec8497..6167f596e5d759e1caa46440c958dca3e5c10de9 100644 (file)
@@ -132,6 +132,19 @@ static int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int
        return 0;
 }
 
+/* Report a warning if a rule is placed after an 'http_response' rule.
+ * Return 1 if the warning has been emitted, otherwise 0.
+ */
+static int warnif_rule_after_http_res(struct proxy *proxy, const char *file, int line, const char *arg1, const char *arg2)
+{
+       if (!LIST_ISEMPTY(&proxy->http_res_rules)) {
+               ha_warning("parsing [%s:%d] : a '%s%s%s' rule placed after an 'http-response' rule will still be processed before.\n",
+                          file, line, arg1, (arg2 ? " ": ""), (arg2 ? arg2 : ""));
+               return 1;
+       }
+       return 0;
+}
+
 /* Report a warning if a rule is placed after a redirect rule.
  * Return 1 if the warning has been emitted, otherwise 0.
  */
@@ -199,6 +212,12 @@ int warnif_misplaced_tcp_req_cont(struct proxy *proxy, const char *file, int lin
                warnif_misplaced_monitor(proxy, file, line, arg1, arg2);
 }
 
+/* report a warning if a "tcp response content" rule is dangerously placed */
+int warnif_misplaced_tcp_res_cont(struct proxy *proxy, const char *file, int line, const char *arg1, const char *arg2)
+{
+       return  warnif_rule_after_http_res(proxy, file, line, arg1, arg2);
+}
+
 /* report a warning if a "tcp request session" rule is dangerously placed */
 int warnif_misplaced_tcp_req_sess(struct proxy *proxy, const char *file, int line, const char *arg1, const char *arg2)
 {
index b8848e525062a9dc8431a83f0e296f313a1a2dae..fcc47b3d124660b3172822c78da78590b772ef59 100644 (file)
@@ -1200,6 +1200,8 @@ static int tcp_parse_tcp_rep(char **args, int section_type, struct proxy *curpx,
                        warn++;
                }
 
+               /* the following function directly emits the warning */
+               warnif_misplaced_tcp_res_cont(curpx, file, line, args[0], args[1]);
                LIST_APPEND(&curpx->tcp_rep.inspect_rules, &rule->list);
        }
        else {