Skip to content

Commit e58a30d

Browse files
committed
MINOR: cfgparse: Emit a warning for misplaced "tcp-response content" rules
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.
1 parent 5dcd3b0 commit e58a30d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

include/haproxy/cfgparse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ void cfg_restore_sections(struct list *backup_sections);
131131
int warnif_misplaced_tcp_req_conn(struct proxy *proxy, const char *file, int line, const char *arg1, const char *arg2);
132132
int warnif_misplaced_tcp_req_sess(struct proxy *proxy, const char *file, int line, const char *arg, const char *arg2);
133133
int warnif_misplaced_tcp_req_cont(struct proxy *proxy, const char *file, int line, const char *arg, const char *arg2);
134+
int warnif_misplaced_tcp_res_cont(struct proxy *proxy, const char *file, int line, const char *arg, const char *arg2);
134135
int warnif_misplaced_quic_init(struct proxy *proxy, const char *file, int line, const char *arg, const char *arg2);
135136
int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line);
136137
int warnif_tcp_http_cond(const struct proxy *px, const struct acl_cond *cond);

src/cfgparse-listen.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ static int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int
132132
return 0;
133133
}
134134

135+
/* Report a warning if a rule is placed after an 'http_response' rule.
136+
* Return 1 if the warning has been emitted, otherwise 0.
137+
*/
138+
static int warnif_rule_after_http_res(struct proxy *proxy, const char *file, int line, const char *arg1, const char *arg2)
139+
{
140+
if (!LIST_ISEMPTY(&proxy->http_res_rules)) {
141+
ha_warning("parsing [%s:%d] : a '%s%s%s' rule placed after an 'http-response' rule will still be processed before.\n",
142+
file, line, arg1, (arg2 ? " ": ""), (arg2 ? arg2 : ""));
143+
return 1;
144+
}
145+
return 0;
146+
}
147+
135148
/* Report a warning if a rule is placed after a redirect rule.
136149
* Return 1 if the warning has been emitted, otherwise 0.
137150
*/
@@ -199,6 +212,12 @@ int warnif_misplaced_tcp_req_cont(struct proxy *proxy, const char *file, int lin
199212
warnif_misplaced_monitor(proxy, file, line, arg1, arg2);
200213
}
201214

215+
/* report a warning if a "tcp response content" rule is dangerously placed */
216+
int warnif_misplaced_tcp_res_cont(struct proxy *proxy, const char *file, int line, const char *arg1, const char *arg2)
217+
{
218+
return warnif_rule_after_http_res(proxy, file, line, arg1, arg2);
219+
}
220+
202221
/* report a warning if a "tcp request session" rule is dangerously placed */
203222
int warnif_misplaced_tcp_req_sess(struct proxy *proxy, const char *file, int line, const char *arg1, const char *arg2)
204223
{

src/tcp_rules.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,8 @@ static int tcp_parse_tcp_rep(char **args, int section_type, struct proxy *curpx,
12001200
warn++;
12011201
}
12021202

1203+
/* the following function directly emits the warning */
1204+
warnif_misplaced_tcp_res_cont(curpx, file, line, args[0], args[1]);
12031205
LIST_APPEND(&curpx->tcp_rep.inspect_rules, &rule->list);
12041206
}
12051207
else {

0 commit comments

Comments
 (0)