Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1 | /* |
| 2 | * "tcp" rules processing |
| 3 | * |
| 4 | * Copyright 2000-2016 Willy Tarreau <w@1wt.eu> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
Willy Tarreau | dcc048a | 2020-06-04 19:11:43 +0200 | [diff] [blame] | 12 | #include <haproxy/acl.h> |
Willy Tarreau | 122eba9 | 2020-06-04 10:15:32 +0200 | [diff] [blame] | 13 | #include <haproxy/action.h> |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 14 | #include <haproxy/api.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 15 | #include <haproxy/arg-t.h> |
Willy Tarreau | 278161c | 2020-06-04 11:18:28 +0200 | [diff] [blame] | 16 | #include <haproxy/capture-t.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 17 | #include <haproxy/cfgparse.h> |
Willy Tarreau | f1d32c4 | 2020-06-04 21:07:02 +0200 | [diff] [blame] | 18 | #include <haproxy/channel.h> |
Willy Tarreau | 7ea393d | 2020-06-04 18:02:10 +0200 | [diff] [blame] | 19 | #include <haproxy/connection.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 20 | #include <haproxy/global.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 21 | #include <haproxy/list.h> |
Willy Tarreau | aeed4a8 | 2020-06-04 22:01:04 +0200 | [diff] [blame] | 22 | #include <haproxy/log.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 23 | #include <haproxy/proxy.h> |
Willy Tarreau | e6ce10b | 2020-06-04 15:33:47 +0200 | [diff] [blame] | 24 | #include <haproxy/sample.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 25 | #include <haproxy/stick_table.h> |
| 26 | #include <haproxy/stream-t.h> |
Willy Tarreau | 5e539c9 | 2020-06-04 20:45:39 +0200 | [diff] [blame] | 27 | #include <haproxy/stream_interface.h> |
Willy Tarreau | 8b550af | 2020-06-04 17:42:48 +0200 | [diff] [blame] | 28 | #include <haproxy/tcp_rules.h> |
Willy Tarreau | c2f7c58 | 2020-06-02 18:15:32 +0200 | [diff] [blame] | 29 | #include <haproxy/ticks.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 30 | #include <haproxy/tools.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 31 | #include <haproxy/trace.h> |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 32 | |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 33 | |
Christopher Faulet | eea8fc7 | 2019-11-05 16:18:10 +0100 | [diff] [blame] | 34 | #define TRACE_SOURCE &trace_strm |
| 35 | |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 36 | /* List head of all known action keywords for "tcp-request connection" */ |
| 37 | struct list tcp_req_conn_keywords = LIST_HEAD_INIT(tcp_req_conn_keywords); |
| 38 | struct list tcp_req_sess_keywords = LIST_HEAD_INIT(tcp_req_sess_keywords); |
| 39 | struct list tcp_req_cont_keywords = LIST_HEAD_INIT(tcp_req_cont_keywords); |
| 40 | struct list tcp_res_cont_keywords = LIST_HEAD_INIT(tcp_res_cont_keywords); |
| 41 | |
| 42 | /* |
| 43 | * Register keywords. |
| 44 | */ |
| 45 | void tcp_req_conn_keywords_register(struct action_kw_list *kw_list) |
| 46 | { |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 47 | LIST_APPEND(&tcp_req_conn_keywords, &kw_list->list); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void tcp_req_sess_keywords_register(struct action_kw_list *kw_list) |
| 51 | { |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 52 | LIST_APPEND(&tcp_req_sess_keywords, &kw_list->list); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void tcp_req_cont_keywords_register(struct action_kw_list *kw_list) |
| 56 | { |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 57 | LIST_APPEND(&tcp_req_cont_keywords, &kw_list->list); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void tcp_res_cont_keywords_register(struct action_kw_list *kw_list) |
| 61 | { |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 62 | LIST_APPEND(&tcp_res_cont_keywords, &kw_list->list); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Return the struct tcp_req_action_kw associated to a keyword. |
| 67 | */ |
Thierry Fournier | 7a71a6d | 2020-11-28 17:40:24 +0100 | [diff] [blame] | 68 | struct action_kw *tcp_req_conn_action(const char *kw) |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 69 | { |
| 70 | return action_lookup(&tcp_req_conn_keywords, kw); |
| 71 | } |
| 72 | |
Thierry Fournier | 7a71a6d | 2020-11-28 17:40:24 +0100 | [diff] [blame] | 73 | struct action_kw *tcp_req_sess_action(const char *kw) |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 74 | { |
| 75 | return action_lookup(&tcp_req_sess_keywords, kw); |
| 76 | } |
| 77 | |
Thierry Fournier | 7a71a6d | 2020-11-28 17:40:24 +0100 | [diff] [blame] | 78 | struct action_kw *tcp_req_cont_action(const char *kw) |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 79 | { |
| 80 | return action_lookup(&tcp_req_cont_keywords, kw); |
| 81 | } |
| 82 | |
Thierry Fournier | 7a71a6d | 2020-11-28 17:40:24 +0100 | [diff] [blame] | 83 | struct action_kw *tcp_res_cont_action(const char *kw) |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 84 | { |
| 85 | return action_lookup(&tcp_res_cont_keywords, kw); |
| 86 | } |
| 87 | |
| 88 | /* This function performs the TCP request analysis on the current request. It |
| 89 | * returns 1 if the processing can continue on next analysers, or zero if it |
| 90 | * needs more data, encounters an error, or wants to immediately abort the |
| 91 | * request. It relies on buffers flags, and updates s->req->analysers. The |
| 92 | * function may be called for frontend rules and backend rules. It only relies |
| 93 | * on the backend pointer so this works for both cases. |
| 94 | */ |
| 95 | int tcp_inspect_request(struct stream *s, struct channel *req, int an_bit) |
| 96 | { |
| 97 | struct session *sess = s->sess; |
| 98 | struct act_rule *rule; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 99 | int partial; |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 100 | int act_opts = 0; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 101 | |
Christopher Faulet | eea8fc7 | 2019-11-05 16:18:10 +0100 | [diff] [blame] | 102 | DBG_TRACE_ENTER(STRM_EV_STRM_ANA|STRM_EV_TCP_ANA, s); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 103 | |
| 104 | /* We don't know whether we have enough data, so must proceed |
| 105 | * this way : |
| 106 | * - iterate through all rules in their declaration order |
| 107 | * - if one rule returns MISS, it means the inspect delay is |
| 108 | * not over yet, then return immediately, otherwise consider |
| 109 | * it as a non-match. |
| 110 | * - if one rule returns OK, then return OK |
| 111 | * - if one rule returns KO, then return KO |
| 112 | */ |
| 113 | |
Christopher Faulet | cb59e0b | 2021-09-30 14:56:30 +0200 | [diff] [blame] | 114 | if ((req->flags & (CF_EOI|CF_SHUTR|CF_READ_ERROR)) || channel_full(req, global.tune.maxrewrite) || |
Christopher Faulet | 7833596 | 2021-09-23 14:46:32 +0200 | [diff] [blame] | 115 | si_rx_blocked_room(chn_prod(req)) || |
Christopher Faulet | 2747fbb | 2020-07-28 11:56:13 +0200 | [diff] [blame] | 116 | !s->be->tcp_req.inspect_delay || tick_is_expired(s->rules_exp, now_ms)) |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 117 | partial = SMP_OPT_FINAL; |
| 118 | else |
| 119 | partial = 0; |
| 120 | |
| 121 | /* If "the current_rule_list" match the executed rule list, we are in |
| 122 | * resume condition. If a resume is needed it is always in the action |
| 123 | * and never in the ACL or converters. In this case, we initialise the |
| 124 | * current rule, and go to the action execution point. |
| 125 | */ |
| 126 | if (s->current_rule) { |
| 127 | rule = s->current_rule; |
| 128 | s->current_rule = NULL; |
| 129 | if (s->current_rule_list == &s->be->tcp_req.inspect_rules) |
| 130 | goto resume_execution; |
| 131 | } |
| 132 | s->current_rule_list = &s->be->tcp_req.inspect_rules; |
| 133 | |
| 134 | list_for_each_entry(rule, &s->be->tcp_req.inspect_rules, list) { |
| 135 | enum acl_test_res ret = ACL_TEST_PASS; |
| 136 | |
| 137 | if (rule->cond) { |
| 138 | ret = acl_exec_cond(rule->cond, s->be, sess, s, SMP_OPT_DIR_REQ | partial); |
| 139 | if (ret == ACL_TEST_MISS) |
| 140 | goto missing_data; |
| 141 | |
| 142 | ret = acl_pass(ret); |
| 143 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 144 | ret = !ret; |
| 145 | } |
| 146 | |
| 147 | if (ret) { |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 148 | act_opts |= ACT_OPT_FIRST; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 149 | resume_execution: |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 150 | |
| 151 | /* Always call the action function if defined */ |
| 152 | if (rule->action_ptr) { |
| 153 | if (partial & SMP_OPT_FINAL) |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 154 | act_opts |= ACT_OPT_FINAL; |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 155 | |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 156 | switch (rule->action_ptr(rule, s->be, s->sess, s, act_opts)) { |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 157 | case ACT_RET_CONT: |
| 158 | break; |
| 159 | case ACT_RET_STOP: |
| 160 | case ACT_RET_DONE: |
| 161 | goto end; |
| 162 | case ACT_RET_YIELD: |
| 163 | s->current_rule = rule; |
Christopher Faulet | 99aaca9 | 2020-07-28 11:30:19 +0200 | [diff] [blame] | 164 | if (partial & SMP_OPT_FINAL) { |
| 165 | send_log(s->be, LOG_WARNING, |
| 166 | "Internal error: yield not allowed if the inspect-delay expired " |
| 167 | "for the tcp-request content actions."); |
| 168 | goto internal; |
| 169 | } |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 170 | goto missing_data; |
| 171 | case ACT_RET_DENY: |
| 172 | goto deny; |
| 173 | case ACT_RET_ABRT: |
| 174 | goto abort; |
| 175 | case ACT_RET_ERR: |
| 176 | goto internal; |
| 177 | case ACT_RET_INV: |
| 178 | goto invalid; |
| 179 | } |
| 180 | continue; /* eval the next rule */ |
| 181 | } |
| 182 | |
| 183 | /* If not action function defined, check for known actions */ |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 184 | if (rule->action == ACT_ACTION_ALLOW) { |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 185 | goto end; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 186 | } |
| 187 | else if (rule->action == ACT_ACTION_DENY) { |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 188 | goto deny; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 189 | } |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 193 | end: |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 194 | /* if we get there, it means we have no rule which matches, or |
| 195 | * we have an explicit accept, so we apply the default accept. |
| 196 | */ |
| 197 | req->analysers &= ~an_bit; |
Christopher Faulet | 2747fbb | 2020-07-28 11:56:13 +0200 | [diff] [blame] | 198 | req->analyse_exp = s->rules_exp = TICK_ETERNITY; |
Christopher Faulet | eea8fc7 | 2019-11-05 16:18:10 +0100 | [diff] [blame] | 199 | DBG_TRACE_LEAVE(STRM_EV_STRM_ANA|STRM_EV_TCP_ANA, s); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 200 | return 1; |
| 201 | |
| 202 | missing_data: |
| 203 | channel_dont_connect(req); |
| 204 | /* just set the request timeout once at the beginning of the request */ |
Christopher Faulet | 2747fbb | 2020-07-28 11:56:13 +0200 | [diff] [blame] | 205 | if (!tick_isset(s->rules_exp) && s->be->tcp_req.inspect_delay) |
| 206 | s->rules_exp = tick_add(now_ms, s->be->tcp_req.inspect_delay); |
| 207 | req->analyse_exp = tick_first((tick_is_expired(req->analyse_exp, now_ms) ? 0 : req->analyse_exp), s->rules_exp); |
Christopher Faulet | eea8fc7 | 2019-11-05 16:18:10 +0100 | [diff] [blame] | 208 | DBG_TRACE_DEVEL("waiting for more data", STRM_EV_STRM_ANA|STRM_EV_TCP_ANA, s); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 209 | return 0; |
| 210 | |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 211 | deny: |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 212 | _HA_ATOMIC_INC(&sess->fe->fe_counters.denied_req); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 213 | if (sess->listener && sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 214 | _HA_ATOMIC_INC(&sess->listener->counters->denied_req); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 215 | goto reject; |
| 216 | |
| 217 | internal: |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 218 | _HA_ATOMIC_INC(&sess->fe->fe_counters.internal_errors); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 219 | if (sess->listener && sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 220 | _HA_ATOMIC_INC(&sess->listener->counters->internal_errors); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 221 | if (!(s->flags & SF_ERR_MASK)) |
| 222 | s->flags |= SF_ERR_INTERNAL; |
| 223 | goto reject; |
| 224 | |
| 225 | invalid: |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 226 | _HA_ATOMIC_INC(&sess->fe->fe_counters.failed_req); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 227 | if (sess->listener && sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 228 | _HA_ATOMIC_INC(&sess->listener->counters->failed_req); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 229 | |
| 230 | reject: |
| 231 | si_must_kill_conn(chn_prod(req)); |
| 232 | channel_abort(req); |
| 233 | channel_abort(&s->res); |
| 234 | |
| 235 | abort: |
| 236 | req->analysers &= AN_REQ_FLT_END; |
| 237 | |
| 238 | if (!(s->flags & SF_ERR_MASK)) |
| 239 | s->flags |= SF_ERR_PRXCOND; |
| 240 | if (!(s->flags & SF_FINST_MASK)) |
| 241 | s->flags |= SF_FINST_R; |
| 242 | DBG_TRACE_DEVEL("leaving on error|deny|abort", STRM_EV_STRM_ANA|STRM_EV_TCP_ANA|STRM_EV_TCP_ERR, s); |
| 243 | return 0; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /* This function performs the TCP response analysis on the current response. It |
| 247 | * returns 1 if the processing can continue on next analysers, or zero if it |
| 248 | * needs more data, encounters an error, or wants to immediately abort the |
| 249 | * response. It relies on buffers flags, and updates s->rep->analysers. The |
| 250 | * function may be called for backend rules. |
| 251 | */ |
| 252 | int tcp_inspect_response(struct stream *s, struct channel *rep, int an_bit) |
| 253 | { |
| 254 | struct session *sess = s->sess; |
| 255 | struct act_rule *rule; |
| 256 | int partial; |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 257 | int act_opts = 0; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 258 | |
Christopher Faulet | eea8fc7 | 2019-11-05 16:18:10 +0100 | [diff] [blame] | 259 | DBG_TRACE_ENTER(STRM_EV_STRM_ANA|STRM_EV_TCP_ANA, s); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 260 | |
| 261 | /* We don't know whether we have enough data, so must proceed |
| 262 | * this way : |
| 263 | * - iterate through all rules in their declaration order |
| 264 | * - if one rule returns MISS, it means the inspect delay is |
| 265 | * not over yet, then return immediately, otherwise consider |
| 266 | * it as a non-match. |
| 267 | * - if one rule returns OK, then return OK |
| 268 | * - if one rule returns KO, then return KO |
| 269 | */ |
Christopher Faulet | cb59e0b | 2021-09-30 14:56:30 +0200 | [diff] [blame] | 270 | if ((rep->flags & (CF_EOI|CF_SHUTR|CF_READ_ERROR)) || channel_full(rep, global.tune.maxrewrite) || |
Christopher Faulet | 7833596 | 2021-09-23 14:46:32 +0200 | [diff] [blame] | 271 | si_rx_blocked_room(chn_prod(rep)) || |
Christopher Faulet | 2747fbb | 2020-07-28 11:56:13 +0200 | [diff] [blame] | 272 | !s->be->tcp_rep.inspect_delay || tick_is_expired(s->rules_exp, now_ms)) |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 273 | partial = SMP_OPT_FINAL; |
| 274 | else |
| 275 | partial = 0; |
| 276 | |
| 277 | /* If "the current_rule_list" match the executed rule list, we are in |
| 278 | * resume condition. If a resume is needed it is always in the action |
| 279 | * and never in the ACL or converters. In this case, we initialise the |
| 280 | * current rule, and go to the action execution point. |
| 281 | */ |
| 282 | if (s->current_rule) { |
| 283 | rule = s->current_rule; |
| 284 | s->current_rule = NULL; |
| 285 | if (s->current_rule_list == &s->be->tcp_rep.inspect_rules) |
| 286 | goto resume_execution; |
| 287 | } |
| 288 | s->current_rule_list = &s->be->tcp_rep.inspect_rules; |
Christopher Faulet | 2747fbb | 2020-07-28 11:56:13 +0200 | [diff] [blame] | 289 | s->rules_exp = TICK_ETERNITY; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 290 | |
| 291 | list_for_each_entry(rule, &s->be->tcp_rep.inspect_rules, list) { |
| 292 | enum acl_test_res ret = ACL_TEST_PASS; |
| 293 | |
| 294 | if (rule->cond) { |
| 295 | ret = acl_exec_cond(rule->cond, s->be, sess, s, SMP_OPT_DIR_RES | partial); |
Christopher Faulet | 2747fbb | 2020-07-28 11:56:13 +0200 | [diff] [blame] | 296 | if (ret == ACL_TEST_MISS) |
| 297 | goto missing_data; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 298 | |
| 299 | ret = acl_pass(ret); |
| 300 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 301 | ret = !ret; |
| 302 | } |
| 303 | |
| 304 | if (ret) { |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 305 | act_opts |= ACT_OPT_FIRST; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 306 | resume_execution: |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 307 | /* Always call the action function if defined */ |
| 308 | if (rule->action_ptr) { |
| 309 | if (partial & SMP_OPT_FINAL) |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 310 | act_opts |= ACT_OPT_FINAL; |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 311 | |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 312 | switch (rule->action_ptr(rule, s->be, s->sess, s, act_opts)) { |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 313 | case ACT_RET_CONT: |
| 314 | break; |
| 315 | case ACT_RET_STOP: |
| 316 | case ACT_RET_DONE: |
| 317 | goto end; |
| 318 | case ACT_RET_YIELD: |
| 319 | s->current_rule = rule; |
Christopher Faulet | 99aaca9 | 2020-07-28 11:30:19 +0200 | [diff] [blame] | 320 | if (partial & SMP_OPT_FINAL) { |
| 321 | send_log(s->be, LOG_WARNING, |
| 322 | "Internal error: yield not allowed if the inspect-delay expired " |
| 323 | "for the tcp-response content actions."); |
| 324 | goto internal; |
| 325 | } |
Christopher Faulet | 2747fbb | 2020-07-28 11:56:13 +0200 | [diff] [blame] | 326 | channel_dont_close(rep); |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 327 | goto missing_data; |
| 328 | case ACT_RET_DENY: |
| 329 | goto deny; |
| 330 | case ACT_RET_ABRT: |
| 331 | goto abort; |
| 332 | case ACT_RET_ERR: |
| 333 | goto internal; |
| 334 | case ACT_RET_INV: |
| 335 | goto invalid; |
| 336 | } |
| 337 | continue; /* eval the next rule */ |
| 338 | } |
| 339 | |
| 340 | /* If not action function defined, check for known actions */ |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 341 | if (rule->action == ACT_ACTION_ALLOW) { |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 342 | goto end; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 343 | } |
| 344 | else if (rule->action == ACT_ACTION_DENY) { |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 345 | goto deny; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 346 | } |
| 347 | else if (rule->action == ACT_TCP_CLOSE) { |
| 348 | chn_prod(rep)->flags |= SI_FL_NOLINGER | SI_FL_NOHALF; |
Willy Tarreau | 0f9cd7b | 2019-01-31 19:02:43 +0100 | [diff] [blame] | 349 | si_must_kill_conn(chn_prod(rep)); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 350 | si_shutr(chn_prod(rep)); |
| 351 | si_shutw(chn_prod(rep)); |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 352 | goto end; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 357 | end: |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 358 | /* if we get there, it means we have no rule which matches, or |
| 359 | * we have an explicit accept, so we apply the default accept. |
| 360 | */ |
| 361 | rep->analysers &= ~an_bit; |
Christopher Faulet | 2747fbb | 2020-07-28 11:56:13 +0200 | [diff] [blame] | 362 | rep->analyse_exp = s->rules_exp = TICK_ETERNITY; |
Christopher Faulet | eea8fc7 | 2019-11-05 16:18:10 +0100 | [diff] [blame] | 363 | DBG_TRACE_LEAVE(STRM_EV_STRM_ANA|STRM_EV_TCP_ANA, s); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 364 | return 1; |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 365 | |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 366 | missing_data: |
Christopher Faulet | 54f3e18 | 2020-07-29 12:00:23 +0200 | [diff] [blame] | 367 | /* just set the analyser timeout once at the beginning of the response */ |
Christopher Faulet | 2747fbb | 2020-07-28 11:56:13 +0200 | [diff] [blame] | 368 | if (!tick_isset(s->rules_exp) && s->be->tcp_rep.inspect_delay) |
| 369 | s->rules_exp = tick_add(now_ms, s->be->tcp_rep.inspect_delay); |
| 370 | rep->analyse_exp = tick_first((tick_is_expired(rep->analyse_exp, now_ms) ? 0 : rep->analyse_exp), s->rules_exp); |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 371 | DBG_TRACE_DEVEL("waiting for more data", STRM_EV_STRM_ANA|STRM_EV_TCP_ANA, s); |
| 372 | return 0; |
| 373 | |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 374 | deny: |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 375 | _HA_ATOMIC_INC(&s->sess->fe->fe_counters.denied_resp); |
| 376 | _HA_ATOMIC_INC(&s->be->be_counters.denied_resp); |
William Lallemand | 36119de | 2021-03-08 15:26:48 +0100 | [diff] [blame] | 377 | if (s->sess->listener && s->sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 378 | _HA_ATOMIC_INC(&s->sess->listener->counters->denied_resp); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 379 | if (objt_server(s->target)) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 380 | _HA_ATOMIC_INC(&__objt_server(s->target)->counters.denied_resp); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 381 | goto reject; |
| 382 | |
| 383 | internal: |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 384 | _HA_ATOMIC_INC(&s->sess->fe->fe_counters.internal_errors); |
| 385 | _HA_ATOMIC_INC(&s->be->be_counters.internal_errors); |
William Lallemand | 36119de | 2021-03-08 15:26:48 +0100 | [diff] [blame] | 386 | if (s->sess->listener && s->sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 387 | _HA_ATOMIC_INC(&s->sess->listener->counters->internal_errors); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 388 | if (objt_server(s->target)) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 389 | _HA_ATOMIC_INC(&__objt_server(s->target)->counters.internal_errors); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 390 | if (!(s->flags & SF_ERR_MASK)) |
| 391 | s->flags |= SF_ERR_INTERNAL; |
| 392 | goto reject; |
| 393 | |
| 394 | invalid: |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 395 | _HA_ATOMIC_INC(&s->be->be_counters.failed_resp); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 396 | if (objt_server(s->target)) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 397 | _HA_ATOMIC_INC(&__objt_server(s->target)->counters.failed_resp); |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 398 | |
| 399 | reject: |
| 400 | si_must_kill_conn(chn_prod(rep)); |
| 401 | channel_abort(rep); |
| 402 | channel_abort(&s->req); |
| 403 | |
| 404 | abort: |
Christopher Faulet | 19dbf2d | 2020-07-28 11:40:07 +0200 | [diff] [blame] | 405 | rep->analysers &= AN_RES_FLT_END; |
Christopher Faulet | 282992e | 2019-12-16 12:34:31 +0100 | [diff] [blame] | 406 | |
| 407 | if (!(s->flags & SF_ERR_MASK)) |
| 408 | s->flags |= SF_ERR_PRXCOND; |
| 409 | if (!(s->flags & SF_FINST_MASK)) |
| 410 | s->flags |= SF_FINST_D; |
| 411 | DBG_TRACE_DEVEL("leaving on error", STRM_EV_STRM_ANA|STRM_EV_TCP_ANA|STRM_EV_TCP_ERR, s); |
| 412 | return 0; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | |
| 416 | /* This function performs the TCP layer4 analysis on the current request. It |
| 417 | * returns 0 if a reject rule matches, otherwise 1 if either an accept rule |
| 418 | * matches or if no more rule matches. It can only use rules which don't need |
| 419 | * any data. This only works on connection-based client-facing stream interfaces. |
| 420 | */ |
| 421 | int tcp_exec_l4_rules(struct session *sess) |
| 422 | { |
| 423 | struct act_rule *rule; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 424 | struct connection *conn = objt_conn(sess->origin); |
| 425 | int result = 1; |
| 426 | enum acl_test_res ret; |
| 427 | |
| 428 | if (!conn) |
| 429 | return result; |
| 430 | |
| 431 | list_for_each_entry(rule, &sess->fe->tcp_req.l4_rules, list) { |
| 432 | ret = ACL_TEST_PASS; |
| 433 | |
| 434 | if (rule->cond) { |
| 435 | ret = acl_exec_cond(rule->cond, sess->fe, sess, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL); |
| 436 | ret = acl_pass(ret); |
| 437 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 438 | ret = !ret; |
| 439 | } |
| 440 | |
| 441 | if (ret) { |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 442 | /* Always call the action function if defined */ |
| 443 | if (rule->action_ptr) { |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 444 | switch (rule->action_ptr(rule, sess->fe, sess, NULL, ACT_OPT_FINAL | ACT_OPT_FIRST)) { |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 445 | case ACT_RET_YIELD: |
| 446 | /* yield is not allowed at this point. If this return code is |
| 447 | * used it is a bug, so I prefer to abort the process. |
| 448 | */ |
| 449 | send_log(sess->fe, LOG_WARNING, |
| 450 | "Internal error: yield not allowed with tcp-request connection actions."); |
| 451 | /* fall through */ |
| 452 | case ACT_RET_STOP: |
| 453 | case ACT_RET_DONE: |
| 454 | goto end; |
| 455 | case ACT_RET_CONT: |
| 456 | break; |
| 457 | case ACT_RET_DENY: |
| 458 | case ACT_RET_ABRT: |
| 459 | case ACT_RET_ERR: |
| 460 | case ACT_RET_INV: |
| 461 | result = 0; |
| 462 | goto end; |
| 463 | } |
| 464 | continue; /* eval the next rule */ |
| 465 | } |
| 466 | |
| 467 | /* If not action function defined, check for known actions */ |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 468 | if (rule->action == ACT_ACTION_ALLOW) { |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 469 | goto end; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 470 | } |
| 471 | else if (rule->action == ACT_ACTION_DENY) { |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 472 | _HA_ATOMIC_INC(&sess->fe->fe_counters.denied_conn); |
Willy Tarreau | a12dde0 | 2016-12-22 18:14:41 +0100 | [diff] [blame] | 473 | if (sess->listener && sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 474 | _HA_ATOMIC_INC(&sess->listener->counters->denied_conn); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 475 | |
| 476 | result = 0; |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 477 | goto end; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 478 | } |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 479 | else if (rule->action == ACT_TCP_EXPECT_PX) { |
Willy Tarreau | 4450b58 | 2020-01-23 15:23:13 +0100 | [diff] [blame] | 480 | if (!(conn->flags & CO_FL_HANDSHAKE)) { |
Olivier Houchard | fe50bfb | 2019-05-27 12:09:19 +0200 | [diff] [blame] | 481 | if (xprt_add_hs(conn) < 0) { |
| 482 | result = 0; |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 483 | goto end; |
Olivier Houchard | fe50bfb | 2019-05-27 12:09:19 +0200 | [diff] [blame] | 484 | } |
| 485 | } |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 486 | conn->flags |= CO_FL_ACCEPT_PROXY; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 487 | } |
| 488 | else if (rule->action == ACT_TCP_EXPECT_CIP) { |
Willy Tarreau | 4450b58 | 2020-01-23 15:23:13 +0100 | [diff] [blame] | 489 | if (!(conn->flags & CO_FL_HANDSHAKE)) { |
Olivier Houchard | fe50bfb | 2019-05-27 12:09:19 +0200 | [diff] [blame] | 490 | if (xprt_add_hs(conn) < 0) { |
| 491 | result = 0; |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 492 | goto end; |
Olivier Houchard | fe50bfb | 2019-05-27 12:09:19 +0200 | [diff] [blame] | 493 | } |
| 494 | } |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 495 | conn->flags |= CO_FL_ACCEPT_CIP; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 496 | } |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 497 | } |
| 498 | } |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 499 | end: |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 500 | return result; |
| 501 | } |
| 502 | |
| 503 | /* This function performs the TCP layer5 analysis on the current request. It |
| 504 | * returns 0 if a reject rule matches, otherwise 1 if either an accept rule |
| 505 | * matches or if no more rule matches. It can only use rules which don't need |
| 506 | * any data. This only works on session-based client-facing stream interfaces. |
| 507 | * An example of valid use case is to track a stick-counter on the source |
| 508 | * address extracted from the proxy protocol. |
| 509 | */ |
| 510 | int tcp_exec_l5_rules(struct session *sess) |
| 511 | { |
| 512 | struct act_rule *rule; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 513 | int result = 1; |
| 514 | enum acl_test_res ret; |
| 515 | |
| 516 | list_for_each_entry(rule, &sess->fe->tcp_req.l5_rules, list) { |
| 517 | ret = ACL_TEST_PASS; |
| 518 | |
| 519 | if (rule->cond) { |
| 520 | ret = acl_exec_cond(rule->cond, sess->fe, sess, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL); |
| 521 | ret = acl_pass(ret); |
| 522 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 523 | ret = !ret; |
| 524 | } |
| 525 | |
| 526 | if (ret) { |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 527 | /* Always call the action function if defined */ |
| 528 | if (rule->action_ptr) { |
Christopher Faulet | 105ba6c | 2019-12-18 14:41:51 +0100 | [diff] [blame] | 529 | switch (rule->action_ptr(rule, sess->fe, sess, NULL, ACT_OPT_FINAL | ACT_OPT_FIRST)) { |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 530 | case ACT_RET_YIELD: |
| 531 | /* yield is not allowed at this point. If this return code is |
| 532 | * used it is a bug, so I prefer to abort the process. |
| 533 | */ |
| 534 | send_log(sess->fe, LOG_WARNING, |
| 535 | "Internal error: yield not allowed with tcp-request session actions."); |
| 536 | /* fall through */ |
| 537 | case ACT_RET_STOP: |
| 538 | case ACT_RET_DONE: |
| 539 | goto end; |
| 540 | case ACT_RET_CONT: |
| 541 | break; |
| 542 | case ACT_RET_DENY: |
| 543 | case ACT_RET_ABRT: |
| 544 | case ACT_RET_ERR: |
| 545 | case ACT_RET_INV: |
| 546 | result = 0; |
| 547 | goto end; |
| 548 | } |
| 549 | continue; /* eval the next rule */ |
| 550 | } |
| 551 | |
| 552 | /* If not action function defined, check for known actions */ |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 553 | if (rule->action == ACT_ACTION_ALLOW) { |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 554 | goto end; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 555 | } |
| 556 | else if (rule->action == ACT_ACTION_DENY) { |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 557 | _HA_ATOMIC_INC(&sess->fe->fe_counters.denied_sess); |
Willy Tarreau | a12dde0 | 2016-12-22 18:14:41 +0100 | [diff] [blame] | 558 | if (sess->listener && sess->listener->counters) |
Willy Tarreau | 4781b15 | 2021-04-06 13:53:36 +0200 | [diff] [blame] | 559 | _HA_ATOMIC_INC(&sess->listener->counters->denied_sess); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 560 | |
| 561 | result = 0; |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 562 | goto end; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 563 | } |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 564 | } |
| 565 | } |
Christopher Faulet | cd26e8a | 2019-12-18 11:13:39 +0100 | [diff] [blame] | 566 | end: |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 567 | return result; |
| 568 | } |
| 569 | |
| 570 | /* Parse a tcp-response rule. Return a negative value in case of failure */ |
| 571 | static int tcp_parse_response_rule(char **args, int arg, int section_type, |
Willy Tarreau | 0182516 | 2021-03-09 09:53:46 +0100 | [diff] [blame] | 572 | struct proxy *curpx, const struct proxy *defpx, |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 573 | struct act_rule *rule, char **err, |
| 574 | unsigned int where, |
| 575 | const char *file, int line) |
| 576 | { |
| 577 | if (curpx == defpx || !(curpx->cap & PR_CAP_BE)) { |
| 578 | memprintf(err, "%s %s is only allowed in 'backend' sections", |
| 579 | args[0], args[1]); |
| 580 | return -1; |
| 581 | } |
| 582 | |
| 583 | if (strcmp(args[arg], "accept") == 0) { |
| 584 | arg++; |
| 585 | rule->action = ACT_ACTION_ALLOW; |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 586 | rule->flags |= ACT_FLAG_FINAL; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 587 | } |
| 588 | else if (strcmp(args[arg], "reject") == 0) { |
| 589 | arg++; |
| 590 | rule->action = ACT_ACTION_DENY; |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 591 | rule->flags |= ACT_FLAG_FINAL; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 592 | } |
| 593 | else if (strcmp(args[arg], "close") == 0) { |
| 594 | arg++; |
| 595 | rule->action = ACT_TCP_CLOSE; |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 596 | rule->flags |= ACT_FLAG_FINAL; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 597 | } |
| 598 | else { |
| 599 | struct action_kw *kw; |
| 600 | kw = tcp_res_cont_action(args[arg]); |
| 601 | if (kw) { |
| 602 | arg++; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 603 | rule->kw = kw; |
| 604 | if (kw->parse((const char **)args, &arg, curpx, rule, err) == ACT_RET_PRS_ERR) |
| 605 | return -1; |
| 606 | } else { |
Willy Tarreau | db67b0e | 2021-03-12 13:46:10 +0100 | [diff] [blame] | 607 | const char *extra[] = { "accept", "reject", "close", NULL }; |
| 608 | const char *best = action_suggest(args[arg], &tcp_res_cont_keywords, extra); |
| 609 | |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 610 | action_build_list(&tcp_res_cont_keywords, &trash); |
| 611 | memprintf(err, |
Willy Tarreau | db67b0e | 2021-03-12 13:46:10 +0100 | [diff] [blame] | 612 | "'%s %s' expects 'accept', 'close', 'reject', %s in %s '%s' (got '%s').%s%s%s", |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 613 | args[0], args[1], trash.area, |
Willy Tarreau | db67b0e | 2021-03-12 13:46:10 +0100 | [diff] [blame] | 614 | proxy_type_str(curpx), curpx->id, args[arg], |
| 615 | best ? " Did you mean '" : "", |
| 616 | best ? best : "", |
| 617 | best ? "' maybe ?" : ""); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 618 | return -1; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | if (strcmp(args[arg], "if") == 0 || strcmp(args[arg], "unless") == 0) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 623 | if ((rule->cond = build_acl_cond(file, line, &curpx->acl, curpx, (const char **)args+arg, err)) == NULL) { |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 624 | memprintf(err, |
| 625 | "'%s %s %s' : error detected in %s '%s' while parsing '%s' condition : %s", |
| 626 | args[0], args[1], args[2], proxy_type_str(curpx), curpx->id, args[arg], *err); |
| 627 | return -1; |
| 628 | } |
| 629 | } |
| 630 | else if (*args[arg]) { |
| 631 | memprintf(err, |
| 632 | "'%s %s %s' only accepts 'if' or 'unless', in %s '%s' (got '%s')", |
| 633 | args[0], args[1], args[2], proxy_type_str(curpx), curpx->id, args[arg]); |
| 634 | return -1; |
| 635 | } |
| 636 | return 0; |
| 637 | } |
| 638 | |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 639 | |
| 640 | /* This function executes a track-sc* actions. On success, it returns |
| 641 | * ACT_RET_CONT. If it must yield, it return ACT_RET_YIELD. Otherwsize |
| 642 | * ACT_RET_ERR is returned. |
| 643 | */ |
| 644 | static enum act_return tcp_action_track_sc(struct act_rule *rule, struct proxy *px, |
| 645 | struct session *sess, struct stream *s, int flags) |
| 646 | { |
| 647 | struct stksess *ts; |
| 648 | struct stktable *t; |
| 649 | struct stktable_key *key; |
| 650 | struct sample smp; |
| 651 | int opt; |
| 652 | |
Christopher Faulet | 6730779 | 2020-02-10 09:54:49 +0100 | [diff] [blame] | 653 | opt = SMP_OPT_DIR_REQ; |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 654 | if (flags & ACT_FLAG_FINAL) |
| 655 | opt |= SMP_OPT_FINAL; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 656 | |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 657 | t = rule->arg.trk_ctr.table.t; |
Christopher Faulet | 6730779 | 2020-02-10 09:54:49 +0100 | [diff] [blame] | 658 | if (rule->from == ACT_F_TCP_REQ_CNT) { /* L7 rules: use the stream */ |
| 659 | if (stkctr_entry(&s->stkctr[rule->action])) |
| 660 | goto end; |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 661 | |
Christopher Faulet | 6730779 | 2020-02-10 09:54:49 +0100 | [diff] [blame] | 662 | key = stktable_fetch_key(t, s->be, sess, s, opt, rule->arg.trk_ctr.expr, &smp); |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 663 | |
Christopher Faulet | 6730779 | 2020-02-10 09:54:49 +0100 | [diff] [blame] | 664 | if ((smp.flags & SMP_F_MAY_CHANGE) && !(flags & ACT_FLAG_FINAL)) |
| 665 | return ACT_RET_YIELD; /* key might appear later */ |
| 666 | |
| 667 | if (key && (ts = stktable_get_entry(t, key))) { |
| 668 | stream_track_stkctr(&s->stkctr[rule->action], t, ts); |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 669 | stkctr_set_flags(&s->stkctr[rule->action], STKCTR_TRACK_CONTENT); |
| 670 | if (sess->fe != s->be) |
| 671 | stkctr_set_flags(&s->stkctr[rule->action], STKCTR_TRACK_BACKEND); |
| 672 | } |
| 673 | } |
Christopher Faulet | 6730779 | 2020-02-10 09:54:49 +0100 | [diff] [blame] | 674 | else { /* L4/L5 rules: use the session */ |
| 675 | if (stkctr_entry(&sess->stkctr[rule->action])) |
| 676 | goto end; |
| 677 | |
| 678 | key = stktable_fetch_key(t, sess->fe, sess, NULL, opt, rule->arg.trk_ctr.expr, NULL); |
| 679 | if (key && (ts = stktable_get_entry(t, key))) |
| 680 | stream_track_stkctr(&sess->stkctr[rule->action], t, ts); |
| 681 | } |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 682 | |
| 683 | end: |
| 684 | return ACT_RET_CONT; |
| 685 | } |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 686 | |
Christopher Faulet | d73b96d | 2019-12-19 17:27:03 +0100 | [diff] [blame] | 687 | /* This function executes a capture actions. It executes a fetch expression, |
| 688 | * turns the result into a string and puts it in a capture slot. On success, it |
| 689 | * returns ACT_RET_CONT. If it must yield, it return ACT_RET_YIELD. Otherwsize |
| 690 | * ACT_RET_ERR is returned. |
| 691 | */ |
| 692 | static enum act_return tcp_action_capture(struct act_rule *rule, struct proxy *px, |
| 693 | struct session *sess, struct stream *s, int flags) |
| 694 | { |
| 695 | struct sample *key; |
| 696 | struct cap_hdr *h = rule->arg.cap.hdr; |
| 697 | char **cap = s->req_cap; |
| 698 | int len, opt; |
| 699 | |
| 700 | opt = ((rule->from == ACT_F_TCP_REQ_CNT) ? SMP_OPT_DIR_REQ : SMP_OPT_DIR_RES); |
| 701 | if (flags & ACT_FLAG_FINAL) |
| 702 | opt |= SMP_OPT_FINAL; |
| 703 | |
| 704 | key = sample_fetch_as_type(s->be, sess, s, opt, rule->arg.cap.expr, SMP_T_STR); |
| 705 | if (!key) |
| 706 | goto end; |
| 707 | |
| 708 | if ((key->flags & SMP_F_MAY_CHANGE) && !(flags & ACT_FLAG_FINAL)) |
| 709 | return ACT_RET_YIELD; /* key might appear later */ |
| 710 | |
| 711 | if (cap[h->index] == NULL) { |
| 712 | cap[h->index] = pool_alloc(h->pool); |
| 713 | if (cap[h->index] == NULL) /* no more capture memory, ignore error */ |
| 714 | goto end; |
| 715 | } |
| 716 | |
| 717 | len = key->data.u.str.data; |
| 718 | if (len > h->len) |
| 719 | len = h->len; |
| 720 | |
| 721 | memcpy(cap[h->index], key->data.u.str.area, len); |
| 722 | cap[h->index][len] = 0; |
| 723 | |
| 724 | end: |
| 725 | return ACT_RET_CONT; |
| 726 | } |
| 727 | |
Christopher Faulet | adfc6e8 | 2020-01-14 15:05:33 +0100 | [diff] [blame] | 728 | static void release_tcp_capture(struct act_rule * rule) |
| 729 | { |
| 730 | release_sample_expr(rule->arg.cap.expr); |
| 731 | } |
| 732 | |
| 733 | |
| 734 | static void release_tcp_track_sc(struct act_rule * rule) |
| 735 | { |
| 736 | release_sample_expr(rule->arg.trk_ctr.expr); |
| 737 | } |
| 738 | |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 739 | /* Parse a tcp-request rule. Return a negative value in case of failure */ |
| 740 | static int tcp_parse_request_rule(char **args, int arg, int section_type, |
Willy Tarreau | 0182516 | 2021-03-09 09:53:46 +0100 | [diff] [blame] | 741 | struct proxy *curpx, const struct proxy *defpx, |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 742 | struct act_rule *rule, char **err, |
| 743 | unsigned int where, const char *file, int line) |
| 744 | { |
| 745 | if (curpx == defpx) { |
| 746 | memprintf(err, "%s %s is not allowed in 'defaults' sections", |
| 747 | args[0], args[1]); |
| 748 | return -1; |
| 749 | } |
| 750 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 751 | if (strcmp(args[arg], "accept") == 0) { |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 752 | arg++; |
| 753 | rule->action = ACT_ACTION_ALLOW; |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 754 | rule->flags |= ACT_FLAG_FINAL; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 755 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 756 | else if (strcmp(args[arg], "reject") == 0) { |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 757 | arg++; |
| 758 | rule->action = ACT_ACTION_DENY; |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 759 | rule->flags |= ACT_FLAG_FINAL; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 760 | } |
| 761 | else if (strcmp(args[arg], "capture") == 0) { |
| 762 | struct sample_expr *expr; |
| 763 | struct cap_hdr *hdr; |
| 764 | int kw = arg; |
| 765 | int len = 0; |
| 766 | |
| 767 | if (!(curpx->cap & PR_CAP_FE)) { |
| 768 | memprintf(err, |
| 769 | "'%s %s %s' : proxy '%s' has no frontend capability", |
| 770 | args[0], args[1], args[kw], curpx->id); |
| 771 | return -1; |
| 772 | } |
| 773 | |
| 774 | if (!(where & SMP_VAL_FE_REQ_CNT)) { |
| 775 | memprintf(err, |
| 776 | "'%s %s' is not allowed in '%s %s' rules in %s '%s'", |
| 777 | args[arg], args[arg+1], args[0], args[1], proxy_type_str(curpx), curpx->id); |
| 778 | return -1; |
| 779 | } |
| 780 | |
| 781 | arg++; |
| 782 | |
| 783 | curpx->conf.args.ctx = ARGC_CAP; |
Willy Tarreau | e3b57bf | 2020-02-14 16:50:14 +0100 | [diff] [blame] | 784 | expr = sample_parse_expr(args, &arg, file, line, err, &curpx->conf.args, NULL); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 785 | if (!expr) { |
| 786 | memprintf(err, |
| 787 | "'%s %s %s' : %s", |
| 788 | args[0], args[1], args[kw], *err); |
| 789 | return -1; |
| 790 | } |
| 791 | |
| 792 | if (!(expr->fetch->val & where)) { |
| 793 | memprintf(err, |
| 794 | "'%s %s %s' : fetch method '%s' extracts information from '%s', none of which is available here", |
| 795 | args[0], args[1], args[kw], args[arg-1], sample_src_names(expr->fetch->use)); |
Christopher Faulet | fdb6fbf | 2020-01-14 15:05:56 +0100 | [diff] [blame] | 796 | release_sample_expr(expr); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 797 | return -1; |
| 798 | } |
| 799 | |
| 800 | if (strcmp(args[arg], "len") == 0) { |
| 801 | arg++; |
| 802 | if (!args[arg]) { |
| 803 | memprintf(err, |
| 804 | "'%s %s %s' : missing length value", |
| 805 | args[0], args[1], args[kw]); |
Christopher Faulet | fdb6fbf | 2020-01-14 15:05:56 +0100 | [diff] [blame] | 806 | release_sample_expr(expr); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 807 | return -1; |
| 808 | } |
| 809 | /* we copy the table name for now, it will be resolved later */ |
| 810 | len = atoi(args[arg]); |
| 811 | if (len <= 0) { |
| 812 | memprintf(err, |
| 813 | "'%s %s %s' : length must be > 0", |
| 814 | args[0], args[1], args[kw]); |
Christopher Faulet | fdb6fbf | 2020-01-14 15:05:56 +0100 | [diff] [blame] | 815 | release_sample_expr(expr); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 816 | return -1; |
| 817 | } |
| 818 | arg++; |
| 819 | } |
| 820 | |
| 821 | if (!len) { |
| 822 | memprintf(err, |
| 823 | "'%s %s %s' : a positive 'len' argument is mandatory", |
| 824 | args[0], args[1], args[kw]); |
| 825 | free(expr); |
| 826 | return -1; |
| 827 | } |
| 828 | |
| 829 | hdr = calloc(1, sizeof(*hdr)); |
Remi Tricot-Le Breton | 8cb0336 | 2021-05-17 10:08:16 +0200 | [diff] [blame] | 830 | if (!hdr) { |
| 831 | memprintf(err, "parsing [%s:%d] : out of memory", file, line); |
| 832 | release_sample_expr(expr); |
| 833 | return -1; |
| 834 | } |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 835 | hdr->next = curpx->req_cap; |
| 836 | hdr->name = NULL; /* not a header capture */ |
| 837 | hdr->namelen = 0; |
| 838 | hdr->len = len; |
| 839 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
| 840 | hdr->index = curpx->nb_req_cap++; |
| 841 | |
| 842 | curpx->req_cap = hdr; |
| 843 | curpx->to_log |= LW_REQHDR; |
| 844 | |
Christopher Faulet | 711ed6a | 2019-07-16 14:16:10 +0200 | [diff] [blame] | 845 | /* check if we need to allocate an http_txn struct for HTTP parsing */ |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 846 | curpx->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
| 847 | |
| 848 | rule->arg.cap.expr = expr; |
| 849 | rule->arg.cap.hdr = hdr; |
Christopher Faulet | d73b96d | 2019-12-19 17:27:03 +0100 | [diff] [blame] | 850 | rule->action = ACT_CUSTOM; |
| 851 | rule->action_ptr = tcp_action_capture; |
| 852 | rule->check_ptr = check_capture; |
Christopher Faulet | adfc6e8 | 2020-01-14 15:05:33 +0100 | [diff] [blame] | 853 | rule->release_ptr = release_tcp_capture; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 854 | } |
Frédéric Lécaille | a41d531 | 2018-01-29 12:05:07 +0100 | [diff] [blame] | 855 | else if (strncmp(args[arg], "track-sc", 8) == 0) { |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 856 | struct sample_expr *expr; |
| 857 | int kw = arg; |
Frédéric Lécaille | a41d531 | 2018-01-29 12:05:07 +0100 | [diff] [blame] | 858 | unsigned int tsc_num; |
| 859 | const char *tsc_num_str; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 860 | |
| 861 | arg++; |
| 862 | |
Frédéric Lécaille | a41d531 | 2018-01-29 12:05:07 +0100 | [diff] [blame] | 863 | tsc_num_str = &args[kw][8]; |
| 864 | if (cfg_parse_track_sc_num(&tsc_num, tsc_num_str, tsc_num_str + strlen(tsc_num_str), err) == -1) { |
| 865 | memprintf(err, "'%s %s %s' : %s", args[0], args[1], args[kw], *err); |
| 866 | return -1; |
| 867 | } |
| 868 | |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 869 | curpx->conf.args.ctx = ARGC_TRK; |
Willy Tarreau | e3b57bf | 2020-02-14 16:50:14 +0100 | [diff] [blame] | 870 | expr = sample_parse_expr(args, &arg, file, line, err, &curpx->conf.args, NULL); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 871 | if (!expr) { |
| 872 | memprintf(err, |
| 873 | "'%s %s %s' : %s", |
| 874 | args[0], args[1], args[kw], *err); |
| 875 | return -1; |
| 876 | } |
| 877 | |
| 878 | if (!(expr->fetch->val & where)) { |
| 879 | memprintf(err, |
| 880 | "'%s %s %s' : fetch method '%s' extracts information from '%s', none of which is available here", |
| 881 | args[0], args[1], args[kw], args[arg-1], sample_src_names(expr->fetch->use)); |
Christopher Faulet | fdb6fbf | 2020-01-14 15:05:56 +0100 | [diff] [blame] | 882 | release_sample_expr(expr); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 883 | return -1; |
| 884 | } |
| 885 | |
Christopher Faulet | 711ed6a | 2019-07-16 14:16:10 +0200 | [diff] [blame] | 886 | /* check if we need to allocate an http_txn struct for HTTP parsing */ |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 887 | curpx->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
| 888 | |
| 889 | if (strcmp(args[arg], "table") == 0) { |
| 890 | arg++; |
| 891 | if (!args[arg]) { |
| 892 | memprintf(err, |
| 893 | "'%s %s %s' : missing table name", |
| 894 | args[0], args[1], args[kw]); |
Christopher Faulet | fdb6fbf | 2020-01-14 15:05:56 +0100 | [diff] [blame] | 895 | release_sample_expr(expr); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 896 | return -1; |
| 897 | } |
| 898 | /* we copy the table name for now, it will be resolved later */ |
| 899 | rule->arg.trk_ctr.table.n = strdup(args[arg]); |
| 900 | arg++; |
| 901 | } |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 902 | rule->action = tsc_num; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 903 | rule->arg.trk_ctr.expr = expr; |
Christopher Faulet | ac98d81 | 2019-12-18 09:20:16 +0100 | [diff] [blame] | 904 | rule->action_ptr = tcp_action_track_sc; |
Christopher Faulet | 78880fb | 2017-09-18 14:43:55 +0200 | [diff] [blame] | 905 | rule->check_ptr = check_trk_action; |
Christopher Faulet | adfc6e8 | 2020-01-14 15:05:33 +0100 | [diff] [blame] | 906 | rule->release_ptr = release_tcp_track_sc; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 907 | } |
| 908 | else if (strcmp(args[arg], "expect-proxy") == 0) { |
| 909 | if (strcmp(args[arg+1], "layer4") != 0) { |
| 910 | memprintf(err, |
| 911 | "'%s %s %s' only supports 'layer4' in %s '%s' (got '%s')", |
| 912 | args[0], args[1], args[arg], proxy_type_str(curpx), curpx->id, args[arg+1]); |
| 913 | return -1; |
| 914 | } |
| 915 | |
| 916 | if (!(where & SMP_VAL_FE_CON_ACC)) { |
| 917 | memprintf(err, |
| 918 | "'%s %s' is not allowed in '%s %s' rules in %s '%s'", |
| 919 | args[arg], args[arg+1], args[0], args[1], proxy_type_str(curpx), curpx->id); |
| 920 | return -1; |
| 921 | } |
| 922 | |
| 923 | arg += 2; |
| 924 | rule->action = ACT_TCP_EXPECT_PX; |
| 925 | } |
| 926 | else if (strcmp(args[arg], "expect-netscaler-cip") == 0) { |
| 927 | if (strcmp(args[arg+1], "layer4") != 0) { |
| 928 | memprintf(err, |
| 929 | "'%s %s %s' only supports 'layer4' in %s '%s' (got '%s')", |
| 930 | args[0], args[1], args[arg], proxy_type_str(curpx), curpx->id, args[arg+1]); |
| 931 | return -1; |
| 932 | } |
| 933 | |
| 934 | if (!(where & SMP_VAL_FE_CON_ACC)) { |
| 935 | memprintf(err, |
| 936 | "'%s %s' is not allowed in '%s %s' rules in %s '%s'", |
| 937 | args[arg], args[arg+1], args[0], args[1], proxy_type_str(curpx), curpx->id); |
| 938 | return -1; |
| 939 | } |
| 940 | |
| 941 | arg += 2; |
| 942 | rule->action = ACT_TCP_EXPECT_CIP; |
| 943 | } |
| 944 | else { |
| 945 | struct action_kw *kw; |
| 946 | if (where & SMP_VAL_FE_CON_ACC) { |
| 947 | /* L4 */ |
| 948 | kw = tcp_req_conn_action(args[arg]); |
| 949 | rule->kw = kw; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 950 | } else if (where & SMP_VAL_FE_SES_ACC) { |
| 951 | /* L5 */ |
| 952 | kw = tcp_req_sess_action(args[arg]); |
| 953 | rule->kw = kw; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 954 | } else { |
| 955 | /* L6 */ |
| 956 | kw = tcp_req_cont_action(args[arg]); |
| 957 | rule->kw = kw; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 958 | } |
| 959 | if (kw) { |
| 960 | arg++; |
| 961 | if (kw->parse((const char **)args, &arg, curpx, rule, err) == ACT_RET_PRS_ERR) |
| 962 | return -1; |
| 963 | } else { |
Christopher Faulet | a561ffb | 2021-03-19 08:53:26 +0100 | [diff] [blame] | 964 | const char *extra[] = { "accept", "reject", "capture", "track-sc", "expect-proxy", "expect-netscaler-cip", NULL }; |
Willy Tarreau | db67b0e | 2021-03-12 13:46:10 +0100 | [diff] [blame] | 965 | const char *best = NULL; |
| 966 | |
| 967 | |
| 968 | if (where & SMP_VAL_FE_CON_ACC) { |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 969 | action_build_list(&tcp_req_conn_keywords, &trash); |
Willy Tarreau | db67b0e | 2021-03-12 13:46:10 +0100 | [diff] [blame] | 970 | best = action_suggest(args[arg], &tcp_req_conn_keywords, extra); |
| 971 | } |
| 972 | else if (where & SMP_VAL_FE_SES_ACC) { |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 973 | action_build_list(&tcp_req_sess_keywords, &trash); |
Willy Tarreau | db67b0e | 2021-03-12 13:46:10 +0100 | [diff] [blame] | 974 | best = action_suggest(args[arg], &tcp_req_sess_keywords, extra); |
| 975 | } |
| 976 | else { |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 977 | action_build_list(&tcp_req_cont_keywords, &trash); |
Willy Tarreau | db67b0e | 2021-03-12 13:46:10 +0100 | [diff] [blame] | 978 | best = action_suggest(args[arg], &tcp_req_cont_keywords, extra); |
| 979 | } |
| 980 | |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 981 | memprintf(err, |
Christopher Faulet | a561ffb | 2021-03-19 08:53:26 +0100 | [diff] [blame] | 982 | "'%s %s' expects 'accept', 'reject', 'capture', 'expect-proxy', 'expect-netscaler-cip', 'track-sc0' ... 'track-sc%d', %s " |
Willy Tarreau | db67b0e | 2021-03-12 13:46:10 +0100 | [diff] [blame] | 983 | "in %s '%s' (got '%s').%s%s%s\n", |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 984 | args[0], args[1], MAX_SESS_STKCTR-1, |
| 985 | trash.area, proxy_type_str(curpx), |
Willy Tarreau | db67b0e | 2021-03-12 13:46:10 +0100 | [diff] [blame] | 986 | curpx->id, args[arg], |
| 987 | best ? " Did you mean '" : "", |
| 988 | best ? best : "", |
| 989 | best ? "' maybe ?" : ""); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 990 | return -1; |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | if (strcmp(args[arg], "if") == 0 || strcmp(args[arg], "unless") == 0) { |
Christopher Faulet | 1b421ea | 2017-09-22 14:38:56 +0200 | [diff] [blame] | 995 | if ((rule->cond = build_acl_cond(file, line, &curpx->acl, curpx, (const char **)args+arg, err)) == NULL) { |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 996 | memprintf(err, |
| 997 | "'%s %s %s' : error detected in %s '%s' while parsing '%s' condition : %s", |
| 998 | args[0], args[1], args[2], proxy_type_str(curpx), curpx->id, args[arg], *err); |
| 999 | return -1; |
| 1000 | } |
| 1001 | } |
| 1002 | else if (*args[arg]) { |
| 1003 | memprintf(err, |
| 1004 | "'%s %s %s' only accepts 'if' or 'unless', in %s '%s' (got '%s')", |
| 1005 | args[0], args[1], args[2], proxy_type_str(curpx), curpx->id, args[arg]); |
| 1006 | return -1; |
| 1007 | } |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | /* This function should be called to parse a line starting with the "tcp-response" |
| 1012 | * keyword. |
| 1013 | */ |
| 1014 | static int tcp_parse_tcp_rep(char **args, int section_type, struct proxy *curpx, |
Willy Tarreau | 0182516 | 2021-03-09 09:53:46 +0100 | [diff] [blame] | 1015 | const struct proxy *defpx, const char *file, int line, |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1016 | char **err) |
| 1017 | { |
| 1018 | const char *ptr = NULL; |
| 1019 | unsigned int val; |
| 1020 | int warn = 0; |
| 1021 | int arg; |
| 1022 | struct act_rule *rule; |
| 1023 | unsigned int where; |
| 1024 | const struct acl *acl; |
| 1025 | const char *kw; |
| 1026 | |
| 1027 | if (!*args[1]) { |
| 1028 | memprintf(err, "missing argument for '%s' in %s '%s'", |
| 1029 | args[0], proxy_type_str(curpx), curpx->id); |
| 1030 | return -1; |
| 1031 | } |
| 1032 | |
| 1033 | if (strcmp(args[1], "inspect-delay") == 0) { |
| 1034 | if (curpx == defpx || !(curpx->cap & PR_CAP_BE)) { |
| 1035 | memprintf(err, "%s %s is only allowed in 'backend' sections", |
| 1036 | args[0], args[1]); |
| 1037 | return -1; |
| 1038 | } |
| 1039 | |
| 1040 | if (!*args[2] || (ptr = parse_time_err(args[2], &val, TIME_UNIT_MS))) { |
| 1041 | memprintf(err, |
| 1042 | "'%s %s' expects a positive delay in milliseconds, in %s '%s'", |
| 1043 | args[0], args[1], proxy_type_str(curpx), curpx->id); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 1044 | |
| 1045 | if (ptr == PARSE_TIME_OVER) |
| 1046 | memprintf(err, "%s (timer overflow in '%s', maximum value is 2147483647 ms or ~24.8 days)", *err, args[2]); |
| 1047 | else if (ptr == PARSE_TIME_UNDER) |
| 1048 | memprintf(err, "%s (timer underflow in '%s', minimum non-null value is 1 ms)", *err, args[2]); |
| 1049 | else if (ptr) |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1050 | memprintf(err, "%s (unexpected character '%c')", *err, *ptr); |
| 1051 | return -1; |
| 1052 | } |
| 1053 | |
| 1054 | if (curpx->tcp_rep.inspect_delay) { |
| 1055 | memprintf(err, "ignoring %s %s (was already defined) in %s '%s'", |
| 1056 | args[0], args[1], proxy_type_str(curpx), curpx->id); |
| 1057 | return 1; |
| 1058 | } |
| 1059 | curpx->tcp_rep.inspect_delay = val; |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | rule = calloc(1, sizeof(*rule)); |
Remi Tricot-Le Breton | 2ca42b4 | 2021-05-12 18:24:18 +0200 | [diff] [blame] | 1064 | if (!rule) { |
| 1065 | memprintf(err, "parsing [%s:%d] : out of memory", file, line); |
| 1066 | return -1; |
| 1067 | } |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1068 | LIST_INIT(&rule->list); |
| 1069 | arg = 1; |
| 1070 | where = 0; |
| 1071 | |
| 1072 | if (strcmp(args[1], "content") == 0) { |
| 1073 | arg++; |
| 1074 | |
| 1075 | if (curpx->cap & PR_CAP_FE) |
| 1076 | where |= SMP_VAL_FE_RES_CNT; |
| 1077 | if (curpx->cap & PR_CAP_BE) |
| 1078 | where |= SMP_VAL_BE_RES_CNT; |
Christopher Faulet | cb9106b | 2019-12-19 15:23:17 +0100 | [diff] [blame] | 1079 | rule->from = ACT_F_TCP_RES_CNT; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1080 | if (tcp_parse_response_rule(args, arg, section_type, curpx, defpx, rule, err, where, file, line) < 0) |
| 1081 | goto error; |
| 1082 | |
| 1083 | acl = rule->cond ? acl_cond_conflicts(rule->cond, where) : NULL; |
| 1084 | if (acl) { |
| 1085 | if (acl->name && *acl->name) |
| 1086 | memprintf(err, |
| 1087 | "acl '%s' will never match in '%s %s' because it only involves keywords that are incompatible with '%s'", |
| 1088 | acl->name, args[0], args[1], sample_ckp_names(where)); |
| 1089 | else |
| 1090 | memprintf(err, |
| 1091 | "anonymous acl will never match in '%s %s' because it uses keyword '%s' which is incompatible with '%s'", |
| 1092 | args[0], args[1], |
| 1093 | LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, |
| 1094 | sample_ckp_names(where)); |
| 1095 | |
| 1096 | warn++; |
| 1097 | } |
| 1098 | else if (rule->cond && acl_cond_kw_conflicts(rule->cond, where, &acl, &kw)) { |
| 1099 | if (acl->name && *acl->name) |
| 1100 | memprintf(err, |
| 1101 | "acl '%s' involves keyword '%s' which is incompatible with '%s'", |
| 1102 | acl->name, kw, sample_ckp_names(where)); |
| 1103 | else |
| 1104 | memprintf(err, |
| 1105 | "anonymous acl involves keyword '%s' which is incompatible with '%s'", |
| 1106 | kw, sample_ckp_names(where)); |
| 1107 | warn++; |
| 1108 | } |
| 1109 | |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 1110 | LIST_APPEND(&curpx->tcp_rep.inspect_rules, &rule->list); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1111 | } |
| 1112 | else { |
| 1113 | memprintf(err, |
| 1114 | "'%s' expects 'inspect-delay' or 'content' in %s '%s' (got '%s')", |
| 1115 | args[0], proxy_type_str(curpx), curpx->id, args[1]); |
| 1116 | goto error; |
| 1117 | } |
| 1118 | |
| 1119 | return warn; |
| 1120 | error: |
| 1121 | free(rule); |
| 1122 | return -1; |
| 1123 | } |
| 1124 | |
| 1125 | |
| 1126 | /* This function should be called to parse a line starting with the "tcp-request" |
| 1127 | * keyword. |
| 1128 | */ |
| 1129 | static int tcp_parse_tcp_req(char **args, int section_type, struct proxy *curpx, |
Willy Tarreau | 0182516 | 2021-03-09 09:53:46 +0100 | [diff] [blame] | 1130 | const struct proxy *defpx, const char *file, int line, |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1131 | char **err) |
| 1132 | { |
| 1133 | const char *ptr = NULL; |
| 1134 | unsigned int val; |
| 1135 | int warn = 0; |
| 1136 | int arg; |
| 1137 | struct act_rule *rule; |
| 1138 | unsigned int where; |
| 1139 | const struct acl *acl; |
| 1140 | const char *kw; |
| 1141 | |
| 1142 | if (!*args[1]) { |
| 1143 | if (curpx == defpx) |
| 1144 | memprintf(err, "missing argument for '%s' in defaults section", args[0]); |
| 1145 | else |
| 1146 | memprintf(err, "missing argument for '%s' in %s '%s'", |
| 1147 | args[0], proxy_type_str(curpx), curpx->id); |
| 1148 | return -1; |
| 1149 | } |
| 1150 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1151 | if (strcmp(args[1], "inspect-delay") == 0) { |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1152 | if (curpx == defpx) { |
| 1153 | memprintf(err, "%s %s is not allowed in 'defaults' sections", |
| 1154 | args[0], args[1]); |
| 1155 | return -1; |
| 1156 | } |
| 1157 | |
| 1158 | if (!*args[2] || (ptr = parse_time_err(args[2], &val, TIME_UNIT_MS))) { |
| 1159 | memprintf(err, |
| 1160 | "'%s %s' expects a positive delay in milliseconds, in %s '%s'", |
| 1161 | args[0], args[1], proxy_type_str(curpx), curpx->id); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 1162 | |
| 1163 | if (ptr == PARSE_TIME_OVER) |
| 1164 | memprintf(err, "%s (timer overflow in '%s', maximum value is 2147483647 ms or ~24.8 days)", *err, args[2]); |
| 1165 | else if (ptr == PARSE_TIME_UNDER) |
| 1166 | memprintf(err, "%s (timer underflow in '%s', minimum non-null value is 1 ms)", *err, args[2]); |
| 1167 | else if (ptr) |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1168 | memprintf(err, "%s (unexpected character '%c')", *err, *ptr); |
| 1169 | return -1; |
| 1170 | } |
| 1171 | |
| 1172 | if (curpx->tcp_req.inspect_delay) { |
| 1173 | memprintf(err, "ignoring %s %s (was already defined) in %s '%s'", |
| 1174 | args[0], args[1], proxy_type_str(curpx), curpx->id); |
| 1175 | return 1; |
| 1176 | } |
| 1177 | curpx->tcp_req.inspect_delay = val; |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | rule = calloc(1, sizeof(*rule)); |
Remi Tricot-Le Breton | 2ca42b4 | 2021-05-12 18:24:18 +0200 | [diff] [blame] | 1182 | if (!rule) { |
| 1183 | memprintf(err, "parsing [%s:%d] : out of memory", file, line); |
| 1184 | return -1; |
| 1185 | } |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1186 | LIST_INIT(&rule->list); |
| 1187 | arg = 1; |
| 1188 | where = 0; |
| 1189 | |
| 1190 | if (strcmp(args[1], "content") == 0) { |
| 1191 | arg++; |
| 1192 | |
| 1193 | if (curpx->cap & PR_CAP_FE) |
| 1194 | where |= SMP_VAL_FE_REQ_CNT; |
| 1195 | if (curpx->cap & PR_CAP_BE) |
| 1196 | where |= SMP_VAL_BE_REQ_CNT; |
Christopher Faulet | cb9106b | 2019-12-19 15:23:17 +0100 | [diff] [blame] | 1197 | rule->from = ACT_F_TCP_REQ_CNT; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1198 | if (tcp_parse_request_rule(args, arg, section_type, curpx, defpx, rule, err, where, file, line) < 0) |
| 1199 | goto error; |
| 1200 | |
| 1201 | acl = rule->cond ? acl_cond_conflicts(rule->cond, where) : NULL; |
| 1202 | if (acl) { |
| 1203 | if (acl->name && *acl->name) |
| 1204 | memprintf(err, |
| 1205 | "acl '%s' will never match in '%s %s' because it only involves keywords that are incompatible with '%s'", |
| 1206 | acl->name, args[0], args[1], sample_ckp_names(where)); |
| 1207 | else |
| 1208 | memprintf(err, |
| 1209 | "anonymous acl will never match in '%s %s' because it uses keyword '%s' which is incompatible with '%s'", |
| 1210 | args[0], args[1], |
| 1211 | LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, |
| 1212 | sample_ckp_names(where)); |
| 1213 | |
| 1214 | warn++; |
| 1215 | } |
| 1216 | else if (rule->cond && acl_cond_kw_conflicts(rule->cond, where, &acl, &kw)) { |
| 1217 | if (acl->name && *acl->name) |
| 1218 | memprintf(err, |
| 1219 | "acl '%s' involves keyword '%s' which is incompatible with '%s'", |
| 1220 | acl->name, kw, sample_ckp_names(where)); |
| 1221 | else |
| 1222 | memprintf(err, |
| 1223 | "anonymous acl involves keyword '%s' which is incompatible with '%s'", |
| 1224 | kw, sample_ckp_names(where)); |
| 1225 | warn++; |
| 1226 | } |
| 1227 | |
| 1228 | /* the following function directly emits the warning */ |
| 1229 | warnif_misplaced_tcp_cont(curpx, file, line, args[0]); |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 1230 | LIST_APPEND(&curpx->tcp_req.inspect_rules, &rule->list); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1231 | } |
| 1232 | else if (strcmp(args[1], "connection") == 0) { |
| 1233 | arg++; |
| 1234 | |
| 1235 | if (!(curpx->cap & PR_CAP_FE)) { |
| 1236 | memprintf(err, "%s %s is not allowed because %s %s is not a frontend", |
| 1237 | args[0], args[1], proxy_type_str(curpx), curpx->id); |
| 1238 | goto error; |
| 1239 | } |
| 1240 | |
| 1241 | where |= SMP_VAL_FE_CON_ACC; |
Christopher Faulet | cb9106b | 2019-12-19 15:23:17 +0100 | [diff] [blame] | 1242 | rule->from = ACT_F_TCP_REQ_CON; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1243 | if (tcp_parse_request_rule(args, arg, section_type, curpx, defpx, rule, err, where, file, line) < 0) |
| 1244 | goto error; |
| 1245 | |
| 1246 | acl = rule->cond ? acl_cond_conflicts(rule->cond, where) : NULL; |
| 1247 | if (acl) { |
| 1248 | if (acl->name && *acl->name) |
| 1249 | memprintf(err, |
| 1250 | "acl '%s' will never match in '%s %s' because it only involves keywords that are incompatible with '%s'", |
| 1251 | acl->name, args[0], args[1], sample_ckp_names(where)); |
| 1252 | else |
| 1253 | memprintf(err, |
| 1254 | "anonymous acl will never match in '%s %s' because it uses keyword '%s' which is incompatible with '%s'", |
| 1255 | args[0], args[1], |
| 1256 | LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, |
| 1257 | sample_ckp_names(where)); |
| 1258 | |
| 1259 | warn++; |
| 1260 | } |
| 1261 | else if (rule->cond && acl_cond_kw_conflicts(rule->cond, where, &acl, &kw)) { |
| 1262 | if (acl->name && *acl->name) |
| 1263 | memprintf(err, |
| 1264 | "acl '%s' involves keyword '%s' which is incompatible with '%s'", |
| 1265 | acl->name, kw, sample_ckp_names(where)); |
| 1266 | else |
| 1267 | memprintf(err, |
| 1268 | "anonymous acl involves keyword '%s' which is incompatible with '%s'", |
| 1269 | kw, sample_ckp_names(where)); |
| 1270 | warn++; |
| 1271 | } |
| 1272 | |
| 1273 | /* the following function directly emits the warning */ |
| 1274 | warnif_misplaced_tcp_conn(curpx, file, line, args[0]); |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 1275 | LIST_APPEND(&curpx->tcp_req.l4_rules, &rule->list); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1276 | } |
| 1277 | else if (strcmp(args[1], "session") == 0) { |
| 1278 | arg++; |
| 1279 | |
| 1280 | if (!(curpx->cap & PR_CAP_FE)) { |
| 1281 | memprintf(err, "%s %s is not allowed because %s %s is not a frontend", |
| 1282 | args[0], args[1], proxy_type_str(curpx), curpx->id); |
| 1283 | goto error; |
| 1284 | } |
| 1285 | |
| 1286 | where |= SMP_VAL_FE_SES_ACC; |
Christopher Faulet | cb9106b | 2019-12-19 15:23:17 +0100 | [diff] [blame] | 1287 | rule->from = ACT_F_TCP_REQ_SES; |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1288 | if (tcp_parse_request_rule(args, arg, section_type, curpx, defpx, rule, err, where, file, line) < 0) |
| 1289 | goto error; |
| 1290 | |
| 1291 | acl = rule->cond ? acl_cond_conflicts(rule->cond, where) : NULL; |
| 1292 | if (acl) { |
| 1293 | if (acl->name && *acl->name) |
| 1294 | memprintf(err, |
| 1295 | "acl '%s' will never match in '%s %s' because it only involves keywords that are incompatible with '%s'", |
| 1296 | acl->name, args[0], args[1], sample_ckp_names(where)); |
| 1297 | else |
| 1298 | memprintf(err, |
| 1299 | "anonymous acl will never match in '%s %s' because it uses keyword '%s' which is incompatible with '%s'", |
| 1300 | args[0], args[1], |
| 1301 | LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, |
| 1302 | sample_ckp_names(where)); |
| 1303 | warn++; |
| 1304 | } |
| 1305 | else if (rule->cond && acl_cond_kw_conflicts(rule->cond, where, &acl, &kw)) { |
| 1306 | if (acl->name && *acl->name) |
| 1307 | memprintf(err, |
| 1308 | "acl '%s' involves keyword '%s' which is incompatible with '%s'", |
| 1309 | acl->name, kw, sample_ckp_names(where)); |
| 1310 | else |
| 1311 | memprintf(err, |
| 1312 | "anonymous acl involves keyword '%s' which is incompatible with '%s'", |
| 1313 | kw, sample_ckp_names(where)); |
| 1314 | warn++; |
| 1315 | } |
| 1316 | |
| 1317 | /* the following function directly emits the warning */ |
| 1318 | warnif_misplaced_tcp_sess(curpx, file, line, args[0]); |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 1319 | LIST_APPEND(&curpx->tcp_req.l5_rules, &rule->list); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1320 | } |
| 1321 | else { |
| 1322 | if (curpx == defpx) |
| 1323 | memprintf(err, |
| 1324 | "'%s' expects 'inspect-delay', 'connection', or 'content' in defaults section (got '%s')", |
| 1325 | args[0], args[1]); |
| 1326 | else |
| 1327 | memprintf(err, |
| 1328 | "'%s' expects 'inspect-delay', 'connection', or 'content' in %s '%s' (got '%s')", |
| 1329 | args[0], proxy_type_str(curpx), curpx->id, args[1]); |
| 1330 | goto error; |
| 1331 | } |
| 1332 | |
| 1333 | return warn; |
| 1334 | error: |
| 1335 | free(rule); |
| 1336 | return -1; |
| 1337 | } |
| 1338 | |
| 1339 | static struct cfg_kw_list cfg_kws = {ILH, { |
| 1340 | { CFG_LISTEN, "tcp-request", tcp_parse_tcp_req }, |
| 1341 | { CFG_LISTEN, "tcp-response", tcp_parse_tcp_rep }, |
| 1342 | { 0, NULL, NULL }, |
| 1343 | }}; |
| 1344 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 1345 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |
Willy Tarreau | 3971310 | 2016-11-25 15:49:32 +0100 | [diff] [blame] | 1346 | |
| 1347 | /* |
| 1348 | * Local variables: |
| 1349 | * c-indent-level: 8 |
| 1350 | * c-basic-offset: 8 |
| 1351 | * End: |
| 1352 | */ |