Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <netdb.h> |
| 5 | #include <ctype.h> |
| 6 | #include <pwd.h> |
| 7 | #include <grp.h> |
| 8 | #include <errno.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <sys/stat.h> |
| 11 | #include <fcntl.h> |
| 12 | #include <unistd.h> |
| 13 | |
Willy Tarreau | dcc048a | 2020-06-04 19:11:43 +0200 | [diff] [blame] | 14 | #include <haproxy/acl.h> |
Eric Salama | 7cea606 | 2020-10-02 11:58:19 +0200 | [diff] [blame] | 15 | #include <haproxy/buf.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 | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 18 | #include <haproxy/check.h> |
Willy Tarreau | 0a3bd39 | 2020-06-04 08:52:38 +0200 | [diff] [blame] | 19 | #include <haproxy/compression-t.h> |
Willy Tarreau | 7ea393d | 2020-06-04 18:02:10 +0200 | [diff] [blame] | 20 | #include <haproxy/connection.h> |
Willy Tarreau | bcc6733 | 2020-06-05 15:31:31 +0200 | [diff] [blame] | 21 | #include <haproxy/extcheck.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 22 | #include <haproxy/http_htx.h> |
Willy Tarreau | c761f84 | 2020-06-04 11:40:28 +0200 | [diff] [blame] | 23 | #include <haproxy/http_rules.h> |
Willy Tarreau | 213e990 | 2020-06-04 14:58:24 +0200 | [diff] [blame] | 24 | #include <haproxy/listener.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 25 | #include <haproxy/log.h> |
Willy Tarreau | 872f2ea | 2020-06-04 18:46:44 +0200 | [diff] [blame] | 26 | #include <haproxy/peers.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 27 | #include <haproxy/protocol.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 28 | #include <haproxy/proxy.h> |
Willy Tarreau | e6ce10b | 2020-06-04 15:33:47 +0200 | [diff] [blame] | 29 | #include <haproxy/sample.h> |
Willy Tarreau | 1e56f92 | 2020-06-04 23:20:13 +0200 | [diff] [blame] | 30 | #include <haproxy/server.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 31 | #include <haproxy/stats-t.h> |
Willy Tarreau | 872f2ea | 2020-06-04 18:46:44 +0200 | [diff] [blame] | 32 | #include <haproxy/stick_table.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 33 | #include <haproxy/tcpcheck.h> |
| 34 | #include <haproxy/uri_auth.h> |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 35 | |
Willy Tarreau | 7d0c143 | 2021-02-12 12:29:28 +0100 | [diff] [blame] | 36 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 37 | /* Report a warning if a rule is placed after a 'tcp-request session' rule. |
| 38 | * Return 1 if the warning has been emitted, otherwise 0. |
| 39 | */ |
| 40 | int warnif_rule_after_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 41 | { |
| 42 | if (!LIST_ISEMPTY(&proxy->tcp_req.l5_rules)) { |
| 43 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request session' rule will still be processed before.\n", |
| 44 | file, line, arg); |
| 45 | return 1; |
| 46 | } |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | /* Report a warning if a rule is placed after a 'tcp-request content' rule. |
| 51 | * Return 1 if the warning has been emitted, otherwise 0. |
| 52 | */ |
| 53 | int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 54 | { |
| 55 | if (!LIST_ISEMPTY(&proxy->tcp_req.inspect_rules)) { |
| 56 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'tcp-request content' rule will still be processed before.\n", |
| 57 | file, line, arg); |
| 58 | return 1; |
| 59 | } |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | /* Report a warning if a rule is placed after a 'monitor fail' rule. |
| 64 | * Return 1 if the warning has been emitted, otherwise 0. |
| 65 | */ |
| 66 | int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg) |
| 67 | { |
| 68 | if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) { |
| 69 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n", |
| 70 | file, line, arg); |
| 71 | return 1; |
| 72 | } |
| 73 | return 0; |
| 74 | } |
| 75 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 76 | /* Report a warning if a rule is placed after an 'http_request' rule. |
| 77 | * Return 1 if the warning has been emitted, otherwise 0. |
| 78 | */ |
| 79 | int warnif_rule_after_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 80 | { |
| 81 | if (!LIST_ISEMPTY(&proxy->http_req_rules)) { |
| 82 | ha_warning("parsing [%s:%d] : a '%s' rule placed after an 'http-request' rule will still be processed before.\n", |
| 83 | file, line, arg); |
| 84 | return 1; |
| 85 | } |
| 86 | return 0; |
| 87 | } |
| 88 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 89 | /* Report a warning if a rule is placed after a redirect rule. |
| 90 | * Return 1 if the warning has been emitted, otherwise 0. |
| 91 | */ |
| 92 | int warnif_rule_after_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 93 | { |
| 94 | if (!LIST_ISEMPTY(&proxy->redirect_rules)) { |
| 95 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'redirect' rule will still be processed before.\n", |
| 96 | file, line, arg); |
| 97 | return 1; |
| 98 | } |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | /* Report a warning if a rule is placed after a 'use_backend' rule. |
| 103 | * Return 1 if the warning has been emitted, otherwise 0. |
| 104 | */ |
| 105 | int warnif_rule_after_use_backend(struct proxy *proxy, const char *file, int line, const char *arg) |
| 106 | { |
| 107 | if (!LIST_ISEMPTY(&proxy->switching_rules)) { |
| 108 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use_backend' rule will still be processed before.\n", |
| 109 | file, line, arg); |
| 110 | return 1; |
| 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /* Report a warning if a rule is placed after a 'use-server' rule. |
| 116 | * Return 1 if the warning has been emitted, otherwise 0. |
| 117 | */ |
| 118 | int warnif_rule_after_use_server(struct proxy *proxy, const char *file, int line, const char *arg) |
| 119 | { |
| 120 | if (!LIST_ISEMPTY(&proxy->server_rules)) { |
| 121 | ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'use-server' rule will still be processed before.\n", |
| 122 | file, line, arg); |
| 123 | return 1; |
| 124 | } |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | /* report a warning if a redirect rule is dangerously placed */ |
| 129 | int warnif_misplaced_redirect(struct proxy *proxy, const char *file, int line, const char *arg) |
| 130 | { |
| 131 | return warnif_rule_after_use_backend(proxy, file, line, arg) || |
| 132 | warnif_rule_after_use_server(proxy, file, line, arg); |
| 133 | } |
| 134 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 135 | /* report a warning if an http-request rule is dangerously placed */ |
| 136 | int warnif_misplaced_http_req(struct proxy *proxy, const char *file, int line, const char *arg) |
| 137 | { |
Christopher Faulet | 1b6adb4 | 2019-07-17 15:33:14 +0200 | [diff] [blame] | 138 | return warnif_rule_after_redirect(proxy, file, line, arg) || |
| 139 | warnif_misplaced_redirect(proxy, file, line, arg); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | /* report a warning if a block rule is dangerously placed */ |
Christopher Faulet | 8c3b63a | 2019-07-17 15:19:51 +0200 | [diff] [blame] | 143 | int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 144 | { |
| 145 | return warnif_rule_after_http_req(proxy, file, line, arg) || |
| 146 | warnif_misplaced_http_req(proxy, file, line, arg); |
| 147 | } |
| 148 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 149 | /* report a warning if a "tcp request content" rule is dangerously placed */ |
| 150 | int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) |
| 151 | { |
| 152 | return warnif_rule_after_monitor(proxy, file, line, arg) || |
| 153 | warnif_misplaced_monitor(proxy, file, line, arg); |
| 154 | } |
| 155 | |
| 156 | /* report a warning if a "tcp request session" rule is dangerously placed */ |
| 157 | int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) |
| 158 | { |
| 159 | return warnif_rule_after_tcp_cont(proxy, file, line, arg) || |
| 160 | warnif_misplaced_tcp_cont(proxy, file, line, arg); |
| 161 | } |
| 162 | |
| 163 | /* report a warning if a "tcp request connection" rule is dangerously placed */ |
| 164 | int warnif_misplaced_tcp_conn(struct proxy *proxy, const char *file, int line, const char *arg) |
| 165 | { |
| 166 | return warnif_rule_after_tcp_sess(proxy, file, line, arg) || |
| 167 | warnif_misplaced_tcp_sess(proxy, file, line, arg); |
| 168 | } |
| 169 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 170 | int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) |
| 171 | { |
| 172 | static struct proxy *curproxy = NULL; |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 173 | static struct proxy *curr_defproxy = NULL; |
Willy Tarreau | e90904d | 2021-02-12 14:08:31 +0100 | [diff] [blame] | 174 | static struct proxy *last_defproxy = NULL; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 175 | const char *err; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 176 | int rc; |
| 177 | unsigned val; |
| 178 | int err_code = 0; |
| 179 | struct acl_cond *cond = NULL; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 180 | char *errmsg = NULL; |
| 181 | struct bind_conf *bind_conf; |
| 182 | |
Willy Tarreau | e90904d | 2021-02-12 14:08:31 +0100 | [diff] [blame] | 183 | if (!last_defproxy) { |
| 184 | /* we need a default proxy and none was created yet */ |
| 185 | last_defproxy = alloc_new_proxy("", PR_CAP_DEF|PR_CAP_LISTEN, "INIT", 0, NULL, &errmsg); |
| 186 | curr_defproxy = last_defproxy; |
| 187 | if (!last_defproxy) { |
| 188 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 189 | err_code |= ERR_ALERT | ERR_ABORT; |
| 190 | goto out; |
| 191 | } |
Willy Tarreau | 7d0c143 | 2021-02-12 12:29:28 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 194 | if (strcmp(args[0], "listen") == 0) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 195 | rc = PR_CAP_LISTEN; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 196 | else if (strcmp(args[0], "frontend") == 0) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 197 | rc = PR_CAP_FE; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 198 | else if (strcmp(args[0], "backend") == 0) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 199 | rc = PR_CAP_BE; |
Willy Tarreau | e90904d | 2021-02-12 14:08:31 +0100 | [diff] [blame] | 200 | else if (strcmp(args[0], "defaults") == 0) { |
| 201 | /* "defaults" must first delete the last no-name defaults if any */ |
| 202 | proxy_destroy_defaults(proxy_find_by_name("", PR_CAP_DEF, 0)); |
| 203 | curr_defproxy = NULL; |
| 204 | rc = PR_CAP_DEF | PR_CAP_LISTEN; |
| 205 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 206 | else |
| 207 | rc = PR_CAP_NONE; |
| 208 | |
Willy Tarreau | e90904d | 2021-02-12 14:08:31 +0100 | [diff] [blame] | 209 | if ((rc & PR_CAP_LISTEN) && !(rc & PR_CAP_DEF)) { /* new proxy */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 210 | if (!*args[1]) { |
Willy Tarreau | b2ec994 | 2021-02-12 13:28:22 +0100 | [diff] [blame] | 211 | ha_alert("parsing [%s:%d] : '%s' expects an <id> argument\n", |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 212 | file, linenum, args[0]); |
| 213 | err_code |= ERR_ALERT | ERR_ABORT; |
| 214 | goto out; |
| 215 | } |
| 216 | |
| 217 | err = invalid_char(args[1]); |
| 218 | if (err) { |
| 219 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
| 220 | file, linenum, *err, args[0], args[1]); |
| 221 | err_code |= ERR_ALERT | ERR_FATAL; |
| 222 | } |
| 223 | |
| 224 | curproxy = (rc & PR_CAP_FE) ? proxy_fe_by_name(args[1]) : proxy_be_by_name(args[1]); |
| 225 | if (curproxy) { |
| 226 | ha_alert("Parsing [%s:%d]: %s '%s' has the same name as %s '%s' declared at %s:%d.\n", |
| 227 | file, linenum, proxy_cap_str(rc), args[1], proxy_type_str(curproxy), |
| 228 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
| 229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 230 | } |
| 231 | |
Emeric Brun | b0c331f | 2020-10-07 17:05:59 +0200 | [diff] [blame] | 232 | curproxy = log_forward_by_name(args[1]); |
| 233 | if (curproxy) { |
| 234 | ha_alert("Parsing [%s:%d]: %s '%s' has the same name as log forward section '%s' declared at %s:%d.\n", |
| 235 | file, linenum, proxy_cap_str(rc), args[1], |
| 236 | curproxy->id, curproxy->conf.file, curproxy->conf.line); |
| 237 | err_code |= ERR_ALERT | ERR_FATAL; |
| 238 | } |
| 239 | |
Willy Tarreau | 7c0b4d8 | 2021-02-12 14:58:08 +0100 | [diff] [blame] | 240 | if ((*args[2] && (!*args[3] || strcmp(args[2], "from") != 0)) || |
| 241 | alertif_too_many_args(3, file, linenum, args, &err_code)) { |
Willy Tarreau | 7683893 | 2021-02-12 08:49:47 +0100 | [diff] [blame] | 242 | if (rc & PR_CAP_FE) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 243 | ha_alert("parsing [%s:%d] : please use the 'bind' keyword for listening addresses.\n", file, linenum); |
| 244 | goto out; |
| 245 | } |
Willy Tarreau | e90904d | 2021-02-12 14:08:31 +0100 | [diff] [blame] | 246 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 247 | |
Willy Tarreau | e90904d | 2021-02-12 14:08:31 +0100 | [diff] [blame] | 248 | if (rc & PR_CAP_LISTEN) { /* new proxy or defaults section */ |
Willy Tarreau | 7c0b4d8 | 2021-02-12 14:58:08 +0100 | [diff] [blame] | 249 | const char *name = args[1]; |
| 250 | int arg = 2; |
| 251 | |
| 252 | if (rc & PR_CAP_DEF && strcmp(args[1], "from") == 0 && *args[2] && !*args[3]) { |
| 253 | // also support "defaults from blah" (no name then) |
| 254 | arg = 1; |
| 255 | name = ""; |
| 256 | } |
| 257 | |
| 258 | /* only regular proxies inherit from the previous defaults section */ |
| 259 | if (!(rc & PR_CAP_DEF)) |
| 260 | curr_defproxy = last_defproxy; |
| 261 | |
| 262 | if (strcmp(args[arg], "from") == 0) { |
| 263 | curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0); |
| 264 | |
| 265 | if (!curr_defproxy) { |
| 266 | ha_alert("parsing [%s:%d] : defaults section '%s' not found for %s '%s'.\n", file, linenum, args[arg+1], proxy_cap_str(rc), name); |
| 267 | err_code |= ERR_ALERT | ERR_ABORT; |
| 268 | goto out; |
| 269 | } |
| 270 | |
| 271 | if (ebpt_next_dup(&curr_defproxy->conf.by_name)) { |
| 272 | struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name); |
| 273 | |
| 274 | ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n", |
| 275 | file, linenum, args[arg+1], proxy_cap_str(rc), name, |
| 276 | curr_defproxy->conf.file, curr_defproxy->conf.line, px2->conf.file, px2->conf.line); |
| 277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 278 | } |
| 279 | |
| 280 | err = invalid_char(args[arg+1]); |
| 281 | if (err) { |
| 282 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in defaults section name '%s' when designated by its name (section found at %s:%d).\n", |
| 283 | file, linenum, *err, args[arg+1], curr_defproxy->conf.file, curr_defproxy->conf.line); |
| 284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | curproxy = alloc_new_proxy(name, rc, file, linenum, curr_defproxy, &errmsg); |
Willy Tarreau | 7683893 | 2021-02-12 08:49:47 +0100 | [diff] [blame] | 289 | if (!curproxy) { |
Willy Tarreau | 7683893 | 2021-02-12 08:49:47 +0100 | [diff] [blame] | 290 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 291 | err_code |= ERR_ALERT | ERR_ABORT; |
Christopher Faulet | 76edc0f | 2020-01-13 15:52:01 +0100 | [diff] [blame] | 292 | goto out; |
| 293 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 294 | |
Willy Tarreau | e90904d | 2021-02-12 14:08:31 +0100 | [diff] [blame] | 295 | if (rc & PR_CAP_DEF) { |
| 296 | /* last and current proxies must be updated to this one */ |
| 297 | curr_defproxy = last_defproxy = curproxy; |
| 298 | } else { |
| 299 | /* regular proxies are in a list */ |
| 300 | curproxy->next = proxies_list; |
| 301 | proxies_list = curproxy; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 302 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 303 | goto out; |
| 304 | } |
| 305 | else if (curproxy == NULL) { |
| 306 | ha_alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum); |
| 307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 308 | goto out; |
| 309 | } |
| 310 | |
| 311 | /* update the current file and line being parsed */ |
| 312 | curproxy->conf.args.file = curproxy->conf.file; |
| 313 | curproxy->conf.args.line = linenum; |
| 314 | |
| 315 | /* Now let's parse the proxy-specific keywords */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 316 | if (strcmp(args[0], "server") == 0 || |
| 317 | strcmp(args[0], "default-server") == 0 || |
| 318 | strcmp(args[0], "server-template") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 319 | err_code |= parse_server(file, linenum, args, curproxy, curr_defproxy, 1, 0, 0); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 320 | if (err_code & ERR_FATAL) |
| 321 | goto out; |
| 322 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 323 | else if (strcmp(args[0], "bind") == 0) { /* new listen addresses */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 324 | struct listener *l; |
| 325 | int cur_arg; |
| 326 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 327 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 328 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 329 | err_code |= ERR_ALERT | ERR_FATAL; |
| 330 | goto out; |
| 331 | } |
| 332 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 333 | err_code |= ERR_WARN; |
| 334 | |
| 335 | if (!*(args[1])) { |
| 336 | ha_alert("parsing [%s:%d] : '%s' expects {<path>|[addr1]:port1[-end1]}{,[addr]:port[-end]}... as arguments.\n", |
| 337 | file, linenum, args[0]); |
| 338 | err_code |= ERR_ALERT | ERR_FATAL; |
| 339 | goto out; |
| 340 | } |
| 341 | |
| 342 | bind_conf = bind_conf_alloc(curproxy, file, linenum, args[1], xprt_get(XPRT_RAW)); |
| 343 | |
| 344 | /* use default settings for unix sockets */ |
Willy Tarreau | 6e459d7 | 2020-09-03 07:09:09 +0200 | [diff] [blame] | 345 | bind_conf->settings.ux.uid = global.unix_bind.ux.uid; |
| 346 | bind_conf->settings.ux.gid = global.unix_bind.ux.gid; |
| 347 | bind_conf->settings.ux.mode = global.unix_bind.ux.mode; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 348 | |
| 349 | /* NOTE: the following line might create several listeners if there |
| 350 | * are comma-separated IPs or port ranges. So all further processing |
| 351 | * will have to be applied to all listeners created after last_listen. |
| 352 | */ |
| 353 | if (!str2listener(args[1], curproxy, bind_conf, file, linenum, &errmsg)) { |
| 354 | if (errmsg && *errmsg) { |
| 355 | indent_msg(&errmsg, 2); |
| 356 | ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
| 357 | } |
| 358 | else |
| 359 | ha_alert("parsing [%s:%d] : '%s' : error encountered while parsing listening address '%s'.\n", |
| 360 | file, linenum, args[0], args[1]); |
| 361 | err_code |= ERR_ALERT | ERR_FATAL; |
| 362 | goto out; |
| 363 | } |
| 364 | |
| 365 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 366 | /* Set default global rights and owner for unix bind */ |
| 367 | global.maxsock++; |
| 368 | } |
| 369 | |
| 370 | cur_arg = 2; |
| 371 | while (*(args[cur_arg])) { |
| 372 | static int bind_dumped; |
| 373 | struct bind_kw *kw; |
| 374 | char *err; |
| 375 | |
| 376 | kw = bind_find_kw(args[cur_arg]); |
| 377 | if (kw) { |
| 378 | char *err = NULL; |
| 379 | int code; |
| 380 | |
| 381 | if (!kw->parse) { |
| 382 | ha_alert("parsing [%s:%d] : '%s %s' : '%s' option is not implemented in this version (check build options).\n", |
| 383 | file, linenum, args[0], args[1], args[cur_arg]); |
| 384 | cur_arg += 1 + kw->skip ; |
| 385 | err_code |= ERR_ALERT | ERR_FATAL; |
| 386 | goto out; |
| 387 | } |
| 388 | |
| 389 | code = kw->parse(args, cur_arg, curproxy, bind_conf, &err); |
| 390 | err_code |= code; |
| 391 | |
| 392 | if (code) { |
| 393 | if (err && *err) { |
| 394 | indent_msg(&err, 2); |
Emeric Brun | 0655c9b | 2019-10-17 16:45:56 +0200 | [diff] [blame] | 395 | if (((code & (ERR_WARN|ERR_ALERT)) == ERR_WARN)) |
| 396 | ha_warning("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
| 397 | else |
| 398 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], err); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 399 | } |
| 400 | else |
| 401 | ha_alert("parsing [%s:%d] : '%s %s' : error encountered while processing '%s'.\n", |
| 402 | file, linenum, args[0], args[1], args[cur_arg]); |
| 403 | if (code & ERR_FATAL) { |
| 404 | free(err); |
| 405 | cur_arg += 1 + kw->skip; |
| 406 | goto out; |
| 407 | } |
| 408 | } |
| 409 | free(err); |
| 410 | cur_arg += 1 + kw->skip; |
| 411 | continue; |
| 412 | } |
| 413 | |
| 414 | err = NULL; |
| 415 | if (!bind_dumped) { |
| 416 | bind_dump_kws(&err); |
| 417 | indent_msg(&err, 4); |
| 418 | bind_dumped = 1; |
| 419 | } |
| 420 | |
| 421 | ha_alert("parsing [%s:%d] : '%s %s' unknown keyword '%s'.%s%s\n", |
| 422 | file, linenum, args[0], args[1], args[cur_arg], |
| 423 | err ? " Registered keywords :" : "", err ? err : ""); |
| 424 | free(err); |
| 425 | |
| 426 | err_code |= ERR_ALERT | ERR_FATAL; |
| 427 | goto out; |
| 428 | } |
| 429 | goto out; |
| 430 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 431 | else if (strcmp(args[0], "monitor-net") == 0) { /* set the range of IPs to ignore */ |
Willy Tarreau | 9e9919d | 2020-10-14 15:55:23 +0200 | [diff] [blame] | 432 | ha_alert("parsing [%s:%d] : 'monitor-net' doesn't exist anymore. Please use 'http-request return status 200 if { src %s }' instead.\n", file, linenum, args[1]); |
| 433 | err_code |= ERR_ALERT | ERR_FATAL; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 434 | goto out; |
| 435 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 436 | else if (strcmp(args[0], "monitor-uri") == 0) { /* set the URI to intercept */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 437 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 438 | err_code |= ERR_WARN; |
| 439 | |
| 440 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 441 | goto out; |
| 442 | |
| 443 | if (!*args[1]) { |
| 444 | ha_alert("parsing [%s:%d] : '%s' expects an URI.\n", |
| 445 | file, linenum, args[0]); |
| 446 | err_code |= ERR_ALERT | ERR_FATAL; |
| 447 | goto out; |
| 448 | } |
| 449 | |
| 450 | free(curproxy->monitor_uri); |
| 451 | curproxy->monitor_uri_len = strlen(args[1]); |
| 452 | curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1); |
| 453 | memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len); |
| 454 | curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0'; |
| 455 | |
| 456 | goto out; |
| 457 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 458 | else if (strcmp(args[0], "mode") == 0) { /* sets the proxy mode */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 459 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 460 | goto out; |
| 461 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 462 | if (strcmp(args[1], "http") == 0) curproxy->mode = PR_MODE_HTTP; |
| 463 | else if (strcmp(args[1], "tcp") == 0) curproxy->mode = PR_MODE_TCP; |
| 464 | else if (strcmp(args[1], "health") == 0) { |
Willy Tarreau | 77e0dae | 2020-10-14 15:44:27 +0200 | [diff] [blame] | 465 | ha_alert("parsing [%s:%d] : 'mode health' doesn't exist anymore. Please use 'http-request return status 200' instead.\n", file, linenum); |
| 466 | err_code |= ERR_ALERT | ERR_FATAL; |
| 467 | goto out; |
| 468 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 469 | else { |
| 470 | ha_alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]); |
| 471 | err_code |= ERR_ALERT | ERR_FATAL; |
| 472 | goto out; |
| 473 | } |
| 474 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 475 | else if (strcmp(args[0], "id") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 476 | struct eb32_node *node; |
| 477 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 478 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 479 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 480 | file, linenum, args[0]); |
| 481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 482 | goto out; |
| 483 | } |
| 484 | |
| 485 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 486 | goto out; |
| 487 | |
| 488 | if (!*args[1]) { |
| 489 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument.\n", |
| 490 | file, linenum, args[0]); |
| 491 | err_code |= ERR_ALERT | ERR_FATAL; |
| 492 | goto out; |
| 493 | } |
| 494 | |
| 495 | curproxy->uuid = atol(args[1]); |
| 496 | curproxy->conf.id.key = curproxy->uuid; |
| 497 | curproxy->options |= PR_O_FORCED_ID; |
| 498 | |
| 499 | if (curproxy->uuid <= 0) { |
| 500 | ha_alert("parsing [%s:%d]: custom id has to be > 0.\n", |
| 501 | file, linenum); |
| 502 | err_code |= ERR_ALERT | ERR_FATAL; |
| 503 | goto out; |
| 504 | } |
| 505 | |
| 506 | node = eb32_lookup(&used_proxy_id, curproxy->uuid); |
| 507 | if (node) { |
| 508 | struct proxy *target = container_of(node, struct proxy, conf.id); |
| 509 | ha_alert("parsing [%s:%d]: %s %s reuses same custom id as %s %s (declared at %s:%d).\n", |
| 510 | file, linenum, proxy_type_str(curproxy), curproxy->id, |
| 511 | proxy_type_str(target), target->id, target->conf.file, target->conf.line); |
| 512 | err_code |= ERR_ALERT | ERR_FATAL; |
| 513 | goto out; |
| 514 | } |
| 515 | eb32_insert(&used_proxy_id, &curproxy->conf.id); |
| 516 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 517 | else if (strcmp(args[0], "description") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 518 | int i, len=0; |
| 519 | char *d; |
| 520 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 521 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 522 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", |
| 523 | file, linenum, args[0]); |
| 524 | err_code |= ERR_ALERT | ERR_FATAL; |
| 525 | goto out; |
| 526 | } |
| 527 | |
| 528 | if (!*args[1]) { |
| 529 | ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 530 | file, linenum, args[0]); |
| 531 | return -1; |
| 532 | } |
| 533 | |
| 534 | for (i = 1; *args[i]; i++) |
| 535 | len += strlen(args[i]) + 1; |
| 536 | |
| 537 | d = calloc(1, len); |
| 538 | curproxy->desc = d; |
| 539 | |
| 540 | d += snprintf(d, curproxy->desc + len - d, "%s", args[1]); |
| 541 | for (i = 2; *args[i]; i++) |
| 542 | d += snprintf(d, curproxy->desc + len - d, " %s", args[i]); |
| 543 | |
| 544 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 545 | else if (strcmp(args[0], "disabled") == 0) { /* disables this proxy */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 546 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 547 | goto out; |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 548 | curproxy->disabled = 1; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 549 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 550 | else if (strcmp(args[0], "enabled") == 0) { /* enables this proxy (used to revert a disabled default) */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 551 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 552 | goto out; |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 553 | curproxy->disabled = 0; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 554 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 555 | else if (strcmp(args[0], "bind-process") == 0) { /* enable this proxy only on some processes */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 556 | int cur_arg = 1; |
| 557 | unsigned long set = 0; |
| 558 | |
| 559 | while (*args[cur_arg]) { |
| 560 | if (strcmp(args[cur_arg], "all") == 0) { |
| 561 | set = 0; |
| 562 | break; |
| 563 | } |
Willy Tarreau | ff9c914 | 2019-02-07 10:39:36 +0100 | [diff] [blame] | 564 | if (parse_process_number(args[cur_arg], &set, MAX_PROCS, NULL, &errmsg)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 565 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 566 | err_code |= ERR_ALERT | ERR_FATAL; |
| 567 | goto out; |
| 568 | } |
| 569 | cur_arg++; |
| 570 | } |
| 571 | curproxy->bind_proc = set; |
| 572 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 573 | else if (strcmp(args[0], "acl") == 0) { /* add an ACL */ |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 574 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 575 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 577 | goto out; |
| 578 | } |
| 579 | |
| 580 | err = invalid_char(args[1]); |
| 581 | if (err) { |
| 582 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in acl name '%s'.\n", |
| 583 | file, linenum, *err, args[1]); |
| 584 | err_code |= ERR_ALERT | ERR_FATAL; |
| 585 | goto out; |
| 586 | } |
| 587 | |
Tim Duesterhus | 0cf811a | 2020-02-05 21:00:50 +0100 | [diff] [blame] | 588 | if (strcasecmp(args[1], "or") == 0) { |
Tim Duesterhus | f1bc24c | 2020-02-06 22:04:03 +0100 | [diff] [blame] | 589 | ha_alert("parsing [%s:%d] : acl name '%s' will never match. 'or' is used to express a " |
Tim Duesterhus | 0cf811a | 2020-02-05 21:00:50 +0100 | [diff] [blame] | 590 | "logical disjunction within a condition.\n", |
| 591 | file, linenum, args[1]); |
| 592 | err_code |= ERR_ALERT | ERR_FATAL; |
| 593 | goto out; |
| 594 | } |
| 595 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 596 | if (parse_acl((const char **)args + 1, &curproxy->acl, &errmsg, &curproxy->conf.args, file, linenum) == NULL) { |
| 597 | ha_alert("parsing [%s:%d] : error detected while parsing ACL '%s' : %s.\n", |
| 598 | file, linenum, args[1], errmsg); |
| 599 | err_code |= ERR_ALERT | ERR_FATAL; |
| 600 | goto out; |
| 601 | } |
| 602 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 603 | else if (strcmp(args[0], "dynamic-cookie-key") == 0) { /* Dynamic cookies secret key */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 604 | |
| 605 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 606 | err_code |= ERR_WARN; |
| 607 | |
| 608 | if (*(args[1]) == 0) { |
| 609 | ha_alert("parsing [%s:%d] : '%s' expects <secret_key> as argument.\n", |
| 610 | file, linenum, args[0]); |
| 611 | err_code |= ERR_ALERT | ERR_FATAL; |
| 612 | goto out; |
| 613 | } |
| 614 | free(curproxy->dyncookie_key); |
| 615 | curproxy->dyncookie_key = strdup(args[1]); |
| 616 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 617 | else if (strcmp(args[0], "cookie") == 0) { /* cookie name */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 618 | int cur_arg; |
| 619 | |
| 620 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 621 | err_code |= ERR_WARN; |
| 622 | |
| 623 | if (*(args[1]) == 0) { |
| 624 | ha_alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n", |
| 625 | file, linenum, args[0]); |
| 626 | err_code |= ERR_ALERT | ERR_FATAL; |
| 627 | goto out; |
| 628 | } |
| 629 | |
| 630 | curproxy->ck_opts = 0; |
| 631 | curproxy->cookie_maxidle = curproxy->cookie_maxlife = 0; |
| 632 | free(curproxy->cookie_domain); curproxy->cookie_domain = NULL; |
| 633 | free(curproxy->cookie_name); |
| 634 | curproxy->cookie_name = strdup(args[1]); |
| 635 | curproxy->cookie_len = strlen(curproxy->cookie_name); |
| 636 | |
| 637 | cur_arg = 2; |
| 638 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 639 | if (strcmp(args[cur_arg], "rewrite") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 640 | curproxy->ck_opts |= PR_CK_RW; |
| 641 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 642 | else if (strcmp(args[cur_arg], "indirect") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 643 | curproxy->ck_opts |= PR_CK_IND; |
| 644 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 645 | else if (strcmp(args[cur_arg], "insert") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 646 | curproxy->ck_opts |= PR_CK_INS; |
| 647 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 648 | else if (strcmp(args[cur_arg], "nocache") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 649 | curproxy->ck_opts |= PR_CK_NOC; |
| 650 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 651 | else if (strcmp(args[cur_arg], "postonly") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 652 | curproxy->ck_opts |= PR_CK_POST; |
| 653 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 654 | else if (strcmp(args[cur_arg], "preserve") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 655 | curproxy->ck_opts |= PR_CK_PSV; |
| 656 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 657 | else if (strcmp(args[cur_arg], "prefix") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 658 | curproxy->ck_opts |= PR_CK_PFX; |
| 659 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 660 | else if (strcmp(args[cur_arg], "httponly") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 661 | curproxy->ck_opts |= PR_CK_HTTPONLY; |
| 662 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 663 | else if (strcmp(args[cur_arg], "secure") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 664 | curproxy->ck_opts |= PR_CK_SECURE; |
| 665 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 666 | else if (strcmp(args[cur_arg], "domain") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 667 | if (!*args[cur_arg + 1]) { |
| 668 | ha_alert("parsing [%s:%d]: '%s' expects <domain> as argument.\n", |
| 669 | file, linenum, args[cur_arg]); |
| 670 | err_code |= ERR_ALERT | ERR_FATAL; |
| 671 | goto out; |
| 672 | } |
| 673 | |
Joao Morais | e158375 | 2019-10-30 21:04:00 -0300 | [diff] [blame] | 674 | if (!strchr(args[cur_arg + 1], '.')) { |
| 675 | /* rfc6265, 5.2.3 The Domain Attribute */ |
| 676 | ha_warning("parsing [%s:%d]: domain '%s' contains no embedded dot," |
| 677 | " this configuration may not work properly (see RFC6265#5.2.3).\n", |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 678 | file, linenum, args[cur_arg + 1]); |
| 679 | err_code |= ERR_WARN; |
| 680 | } |
| 681 | |
| 682 | err = invalid_domainchar(args[cur_arg + 1]); |
| 683 | if (err) { |
| 684 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in domain name '%s'.\n", |
| 685 | file, linenum, *err, args[cur_arg + 1]); |
| 686 | err_code |= ERR_ALERT | ERR_FATAL; |
| 687 | goto out; |
| 688 | } |
| 689 | |
| 690 | if (!curproxy->cookie_domain) { |
| 691 | curproxy->cookie_domain = strdup(args[cur_arg + 1]); |
| 692 | } else { |
| 693 | /* one domain was already specified, add another one by |
| 694 | * building the string which will be returned along with |
| 695 | * the cookie. |
| 696 | */ |
| 697 | char *new_ptr; |
| 698 | int new_len = strlen(curproxy->cookie_domain) + |
| 699 | strlen("; domain=") + strlen(args[cur_arg + 1]) + 1; |
| 700 | new_ptr = malloc(new_len); |
| 701 | snprintf(new_ptr, new_len, "%s; domain=%s", curproxy->cookie_domain, args[cur_arg+1]); |
| 702 | free(curproxy->cookie_domain); |
| 703 | curproxy->cookie_domain = new_ptr; |
| 704 | } |
| 705 | cur_arg++; |
| 706 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 707 | else if (strcmp(args[cur_arg], "maxidle") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 708 | unsigned int maxidle; |
| 709 | const char *res; |
| 710 | |
| 711 | if (!*args[cur_arg + 1]) { |
| 712 | ha_alert("parsing [%s:%d]: '%s' expects <idletime> in seconds as argument.\n", |
| 713 | file, linenum, args[cur_arg]); |
| 714 | err_code |= ERR_ALERT | ERR_FATAL; |
| 715 | goto out; |
| 716 | } |
| 717 | |
| 718 | res = parse_time_err(args[cur_arg + 1], &maxidle, TIME_UNIT_S); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 719 | if (res == PARSE_TIME_OVER) { |
| 720 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n", |
| 721 | file, linenum, args[cur_arg+1], args[cur_arg]); |
| 722 | err_code |= ERR_ALERT | ERR_FATAL; |
| 723 | goto out; |
| 724 | } |
| 725 | else if (res == PARSE_TIME_UNDER) { |
| 726 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n", |
| 727 | file, linenum, args[cur_arg+1], args[cur_arg]); |
| 728 | err_code |= ERR_ALERT | ERR_FATAL; |
| 729 | goto out; |
| 730 | } |
| 731 | else if (res) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 732 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 733 | file, linenum, *res, args[cur_arg]); |
| 734 | err_code |= ERR_ALERT | ERR_FATAL; |
| 735 | goto out; |
| 736 | } |
| 737 | curproxy->cookie_maxidle = maxidle; |
| 738 | cur_arg++; |
| 739 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 740 | else if (strcmp(args[cur_arg], "maxlife") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 741 | unsigned int maxlife; |
| 742 | const char *res; |
| 743 | |
| 744 | if (!*args[cur_arg + 1]) { |
| 745 | ha_alert("parsing [%s:%d]: '%s' expects <lifetime> in seconds as argument.\n", |
| 746 | file, linenum, args[cur_arg]); |
| 747 | err_code |= ERR_ALERT | ERR_FATAL; |
| 748 | goto out; |
| 749 | } |
| 750 | |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 751 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 752 | res = parse_time_err(args[cur_arg + 1], &maxlife, TIME_UNIT_S); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 753 | if (res == PARSE_TIME_OVER) { |
| 754 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 s (~68 years).\n", |
| 755 | file, linenum, args[cur_arg+1], args[cur_arg]); |
| 756 | err_code |= ERR_ALERT | ERR_FATAL; |
| 757 | goto out; |
| 758 | } |
| 759 | else if (res == PARSE_TIME_UNDER) { |
| 760 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 s.\n", |
| 761 | file, linenum, args[cur_arg+1], args[cur_arg]); |
| 762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 763 | goto out; |
| 764 | } |
| 765 | else if (res) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 766 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
| 767 | file, linenum, *res, args[cur_arg]); |
| 768 | err_code |= ERR_ALERT | ERR_FATAL; |
| 769 | goto out; |
| 770 | } |
| 771 | curproxy->cookie_maxlife = maxlife; |
| 772 | cur_arg++; |
| 773 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 774 | else if (strcmp(args[cur_arg], "dynamic") == 0) { /* Dynamic persistent cookies secret key */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 775 | |
| 776 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[cur_arg], NULL)) |
| 777 | err_code |= ERR_WARN; |
| 778 | curproxy->ck_opts |= PR_CK_DYNAMIC; |
| 779 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 780 | else if (strcmp(args[cur_arg], "attr") == 0) { |
Christopher Faulet | 2f53390 | 2020-01-21 11:06:48 +0100 | [diff] [blame] | 781 | char *val; |
| 782 | if (!*args[cur_arg + 1]) { |
| 783 | ha_alert("parsing [%s:%d]: '%s' expects <value> as argument.\n", |
| 784 | file, linenum, args[cur_arg]); |
| 785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 786 | goto out; |
| 787 | } |
| 788 | val = args[cur_arg + 1]; |
| 789 | while (*val) { |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 790 | if (iscntrl((unsigned char)*val) || *val == ';') { |
Christopher Faulet | 2f53390 | 2020-01-21 11:06:48 +0100 | [diff] [blame] | 791 | ha_alert("parsing [%s:%d]: character '%%x%02X' is not permitted in attribute value.\n", |
| 792 | file, linenum, *val); |
| 793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 794 | goto out; |
| 795 | } |
| 796 | val++; |
| 797 | } |
| 798 | /* don't add ';' for the first attribute */ |
| 799 | if (!curproxy->cookie_attrs) |
| 800 | curproxy->cookie_attrs = strdup(args[cur_arg + 1]); |
| 801 | else |
| 802 | memprintf(&curproxy->cookie_attrs, "%s; %s", curproxy->cookie_attrs, args[cur_arg + 1]); |
| 803 | cur_arg++; |
| 804 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 805 | |
| 806 | else { |
Christopher Faulet | 2f53390 | 2020-01-21 11:06:48 +0100 | [diff] [blame] | 807 | ha_alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache', 'postonly', 'domain', 'maxidle', 'dynamic', 'maxlife' and 'attr' options.\n", |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 808 | file, linenum, args[0]); |
| 809 | err_code |= ERR_ALERT | ERR_FATAL; |
| 810 | goto out; |
| 811 | } |
| 812 | cur_arg++; |
| 813 | } |
| 814 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_IND))) { |
| 815 | ha_alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n", |
| 816 | file, linenum); |
| 817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 818 | } |
| 819 | |
| 820 | if (!POWEROF2(curproxy->ck_opts & (PR_CK_RW|PR_CK_INS|PR_CK_PFX))) { |
| 821 | ha_alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n", |
| 822 | file, linenum); |
| 823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 824 | } |
| 825 | |
| 826 | if ((curproxy->ck_opts & (PR_CK_PSV | PR_CK_INS | PR_CK_IND)) == PR_CK_PSV) { |
| 827 | ha_alert("parsing [%s:%d] : cookie 'preserve' requires at least 'insert' or 'indirect'.\n", |
| 828 | file, linenum); |
| 829 | err_code |= ERR_ALERT | ERR_FATAL; |
| 830 | } |
| 831 | }/* end else if (!strcmp(args[0], "cookie")) */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 832 | else if (strcmp(args[0], "email-alert") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 833 | if (*(args[1]) == 0) { |
| 834 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 835 | file, linenum, args[0]); |
| 836 | err_code |= ERR_ALERT | ERR_FATAL; |
| 837 | goto out; |
| 838 | } |
| 839 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 840 | if (strcmp(args[1], "from") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 841 | if (*(args[1]) == 0) { |
| 842 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 843 | file, linenum, args[1]); |
| 844 | err_code |= ERR_ALERT | ERR_FATAL; |
| 845 | goto out; |
| 846 | } |
| 847 | free(curproxy->email_alert.from); |
| 848 | curproxy->email_alert.from = strdup(args[2]); |
| 849 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 850 | else if (strcmp(args[1], "mailers") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 851 | if (*(args[1]) == 0) { |
| 852 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 853 | file, linenum, args[1]); |
| 854 | err_code |= ERR_ALERT | ERR_FATAL; |
| 855 | goto out; |
| 856 | } |
| 857 | free(curproxy->email_alert.mailers.name); |
| 858 | curproxy->email_alert.mailers.name = strdup(args[2]); |
| 859 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 860 | else if (strcmp(args[1], "myhostname") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 861 | if (*(args[1]) == 0) { |
| 862 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 863 | file, linenum, args[1]); |
| 864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 865 | goto out; |
| 866 | } |
| 867 | free(curproxy->email_alert.myhostname); |
| 868 | curproxy->email_alert.myhostname = strdup(args[2]); |
| 869 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 870 | else if (strcmp(args[1], "level") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 871 | curproxy->email_alert.level = get_log_level(args[2]); |
| 872 | if (curproxy->email_alert.level < 0) { |
| 873 | ha_alert("parsing [%s:%d] : unknown log level '%s' after '%s'\n", |
| 874 | file, linenum, args[1], args[2]); |
| 875 | err_code |= ERR_ALERT | ERR_FATAL; |
| 876 | goto out; |
| 877 | } |
| 878 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 879 | else if (strcmp(args[1], "to") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 880 | if (*(args[1]) == 0) { |
| 881 | ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", |
| 882 | file, linenum, args[1]); |
| 883 | err_code |= ERR_ALERT | ERR_FATAL; |
| 884 | goto out; |
| 885 | } |
| 886 | free(curproxy->email_alert.to); |
| 887 | curproxy->email_alert.to = strdup(args[2]); |
| 888 | } |
| 889 | else { |
| 890 | ha_alert("parsing [%s:%d] : email-alert: unknown argument '%s'.\n", |
| 891 | file, linenum, args[1]); |
| 892 | err_code |= ERR_ALERT | ERR_FATAL; |
| 893 | goto out; |
| 894 | } |
| 895 | /* Indicate that the email_alert is at least partially configured */ |
| 896 | curproxy->email_alert.set = 1; |
| 897 | }/* end else if (!strcmp(args[0], "email-alert")) */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 898 | else if (strcmp(args[0], "persist") == 0) { /* persist */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 899 | if (*(args[1]) == 0) { |
| 900 | ha_alert("parsing [%s:%d] : missing persist method.\n", |
| 901 | file, linenum); |
| 902 | err_code |= ERR_ALERT | ERR_FATAL; |
| 903 | goto out; |
| 904 | } |
| 905 | |
| 906 | if (!strncmp(args[1], "rdp-cookie", 10)) { |
| 907 | curproxy->options2 |= PR_O2_RDPC_PRST; |
| 908 | |
| 909 | if (*(args[1] + 10) == '(') { /* cookie name */ |
| 910 | const char *beg, *end; |
| 911 | |
| 912 | beg = args[1] + 11; |
| 913 | end = strchr(beg, ')'); |
| 914 | |
| 915 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 916 | goto out; |
| 917 | |
| 918 | if (!end || end == beg) { |
| 919 | ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 920 | file, linenum); |
| 921 | err_code |= ERR_ALERT | ERR_FATAL; |
| 922 | goto out; |
| 923 | } |
| 924 | |
| 925 | free(curproxy->rdp_cookie_name); |
| 926 | curproxy->rdp_cookie_name = my_strndup(beg, end - beg); |
| 927 | curproxy->rdp_cookie_len = end-beg; |
| 928 | } |
| 929 | else if (*(args[1] + 10) == '\0') { /* default cookie name 'msts' */ |
| 930 | free(curproxy->rdp_cookie_name); |
| 931 | curproxy->rdp_cookie_name = strdup("msts"); |
| 932 | curproxy->rdp_cookie_len = strlen(curproxy->rdp_cookie_name); |
| 933 | } |
| 934 | else { /* syntax */ |
| 935 | ha_alert("parsing [%s:%d] : persist rdp-cookie(name)' requires an rdp cookie name.\n", |
| 936 | file, linenum); |
| 937 | err_code |= ERR_ALERT | ERR_FATAL; |
| 938 | goto out; |
| 939 | } |
| 940 | } |
| 941 | else { |
| 942 | ha_alert("parsing [%s:%d] : unknown persist method.\n", |
| 943 | file, linenum); |
| 944 | err_code |= ERR_ALERT | ERR_FATAL; |
| 945 | goto out; |
| 946 | } |
| 947 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 948 | else if (strcmp(args[0], "appsession") == 0) { /* cookie name */ |
Tim Duesterhus | 473c283 | 2019-05-06 01:19:52 +0200 | [diff] [blame] | 949 | ha_alert("parsing [%s:%d] : '%s' is not supported anymore since HAProxy 1.6.\n", file, linenum, args[0]); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 950 | err_code |= ERR_ALERT | ERR_FATAL; |
| 951 | goto out; |
| 952 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 953 | else if (strcmp(args[0], "load-server-state-from-file") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 954 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 955 | err_code |= ERR_WARN; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 956 | if (strcmp(args[1], "global") == 0) { /* use the file pointed to by global server-state-file directive */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 957 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_GLOBAL; |
| 958 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 959 | else if (strcmp(args[1], "local") == 0) { /* use the server-state-file-name variable to locate the server-state file */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 960 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_LOCAL; |
| 961 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 962 | else if (strcmp(args[1], "none") == 0) { /* don't use server-state-file directive for this backend */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 963 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
| 964 | } |
| 965 | else { |
| 966 | ha_alert("parsing [%s:%d] : '%s' expects 'global', 'local' or 'none'. Got '%s'\n", |
| 967 | file, linenum, args[0], args[1]); |
| 968 | err_code |= ERR_ALERT | ERR_FATAL; |
| 969 | goto out; |
| 970 | } |
| 971 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 972 | else if (strcmp(args[0], "server-state-file-name") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 973 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 974 | err_code |= ERR_WARN; |
Christopher Faulet | 583b6de | 2021-02-12 09:27:10 +0100 | [diff] [blame] | 975 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 976 | goto out; |
Christopher Faulet | 583b6de | 2021-02-12 09:27:10 +0100 | [diff] [blame] | 977 | |
| 978 | free(curproxy->server_state_file_name); |
| 979 | curproxy->server_state_file_name = NULL; |
| 980 | |
| 981 | if (*(args[1]) == 0 || strcmp(args[1], "use-backend-name") == 0) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 982 | curproxy->server_state_file_name = strdup(curproxy->id); |
| 983 | else |
| 984 | curproxy->server_state_file_name = strdup(args[1]); |
| 985 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 986 | else if (strcmp(args[0], "max-session-srv-conns") == 0) { |
Olivier Houchard | a4d4fdf | 2018-12-14 19:27:06 +0100 | [diff] [blame] | 987 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 988 | err_code |= ERR_WARN; |
| 989 | if (*(args[1]) == 0) { |
| 990 | ha_alert("parsine [%s:%d] : '%s' expects a number. Got no argument\n", |
| 991 | file, linenum, args[0]); |
| 992 | err_code |= ERR_ALERT | ERR_FATAL; |
| 993 | goto out; |
| 994 | } |
| 995 | curproxy->max_out_conns = atoi(args[1]); |
| 996 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 997 | else if (strcmp(args[0], "capture") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 998 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 999 | err_code |= ERR_WARN; |
| 1000 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1001 | if (strcmp(args[1], "cookie") == 0) { /* name of a cookie to capture */ |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1002 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1003 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 1004 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1005 | goto out; |
| 1006 | } |
| 1007 | |
| 1008 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 1009 | goto out; |
| 1010 | |
| 1011 | if (*(args[4]) == 0) { |
| 1012 | ha_alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n", |
| 1013 | file, linenum, args[0]); |
| 1014 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1015 | goto out; |
| 1016 | } |
| 1017 | free(curproxy->capture_name); |
| 1018 | curproxy->capture_name = strdup(args[2]); |
| 1019 | curproxy->capture_namelen = strlen(curproxy->capture_name); |
| 1020 | curproxy->capture_len = atol(args[4]); |
| 1021 | curproxy->to_log |= LW_COOKIE; |
| 1022 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1023 | else if (strcmp(args[1], "request") == 0 && strcmp(args[2], "header") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1024 | struct cap_hdr *hdr; |
| 1025 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1026 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1027 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 1028 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1029 | goto out; |
| 1030 | } |
| 1031 | |
| 1032 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 1033 | goto out; |
| 1034 | |
| 1035 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1036 | ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1037 | file, linenum, args[0], args[1]); |
| 1038 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1039 | goto out; |
| 1040 | } |
| 1041 | |
| 1042 | hdr = calloc(1, sizeof(*hdr)); |
| 1043 | hdr->next = curproxy->req_cap; |
| 1044 | hdr->name = strdup(args[3]); |
| 1045 | hdr->namelen = strlen(args[3]); |
| 1046 | hdr->len = atol(args[5]); |
| 1047 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
| 1048 | hdr->index = curproxy->nb_req_cap++; |
| 1049 | curproxy->req_cap = hdr; |
| 1050 | curproxy->to_log |= LW_REQHDR; |
| 1051 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1052 | else if (strcmp(args[1], "response") == 0 && strcmp(args[2], "header") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1053 | struct cap_hdr *hdr; |
| 1054 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1055 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1056 | ha_alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 1057 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1058 | goto out; |
| 1059 | } |
| 1060 | |
| 1061 | if (alertif_too_many_args_idx(4, 1, file, linenum, args, &err_code)) |
| 1062 | goto out; |
| 1063 | |
| 1064 | if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) { |
| 1065 | ha_alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n", |
| 1066 | file, linenum, args[0], args[1]); |
| 1067 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1068 | goto out; |
| 1069 | } |
| 1070 | hdr = calloc(1, sizeof(*hdr)); |
| 1071 | hdr->next = curproxy->rsp_cap; |
| 1072 | hdr->name = strdup(args[3]); |
| 1073 | hdr->namelen = strlen(args[3]); |
| 1074 | hdr->len = atol(args[5]); |
| 1075 | hdr->pool = create_pool("caphdr", hdr->len + 1, MEM_F_SHARED); |
| 1076 | hdr->index = curproxy->nb_rsp_cap++; |
| 1077 | curproxy->rsp_cap = hdr; |
| 1078 | curproxy->to_log |= LW_RSPHDR; |
| 1079 | } |
| 1080 | else { |
| 1081 | ha_alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n", |
| 1082 | file, linenum, args[0]); |
| 1083 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1084 | goto out; |
| 1085 | } |
| 1086 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1087 | else if (strcmp(args[0], "retries") == 0) { /* connection retries */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1088 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1089 | err_code |= ERR_WARN; |
| 1090 | |
| 1091 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1092 | goto out; |
| 1093 | |
| 1094 | if (*(args[1]) == 0) { |
| 1095 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n", |
| 1096 | file, linenum, args[0]); |
| 1097 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1098 | goto out; |
| 1099 | } |
| 1100 | curproxy->conn_retries = atol(args[1]); |
| 1101 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1102 | else if (strcmp(args[0], "http-request") == 0) { /* request access control: allow/deny/auth */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1103 | struct act_rule *rule; |
| 1104 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1105 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1106 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1107 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1108 | goto out; |
| 1109 | } |
| 1110 | |
| 1111 | if (!LIST_ISEMPTY(&curproxy->http_req_rules) && |
| 1112 | !LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->cond && |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 1113 | (LIST_PREV(&curproxy->http_req_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1114 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 1115 | file, linenum, args[0]); |
| 1116 | err_code |= ERR_WARN; |
| 1117 | } |
| 1118 | |
| 1119 | rule = parse_http_req_cond((const char **)args + 1, file, linenum, curproxy); |
| 1120 | |
| 1121 | if (!rule) { |
| 1122 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1123 | goto out; |
| 1124 | } |
| 1125 | |
| 1126 | err_code |= warnif_misplaced_http_req(curproxy, file, linenum, args[0]); |
| 1127 | err_code |= warnif_cond_conflicts(rule->cond, |
| 1128 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 1129 | file, linenum); |
| 1130 | |
| 1131 | LIST_ADDQ(&curproxy->http_req_rules, &rule->list); |
| 1132 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1133 | else if (strcmp(args[0], "http-response") == 0) { /* response access control */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1134 | struct act_rule *rule; |
| 1135 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1136 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1137 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1138 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1139 | goto out; |
| 1140 | } |
| 1141 | |
| 1142 | if (!LIST_ISEMPTY(&curproxy->http_res_rules) && |
| 1143 | !LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->cond && |
Christopher Faulet | 245cf79 | 2019-12-18 14:58:12 +0100 | [diff] [blame] | 1144 | (LIST_PREV(&curproxy->http_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1145 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 1146 | file, linenum, args[0]); |
| 1147 | err_code |= ERR_WARN; |
| 1148 | } |
| 1149 | |
| 1150 | rule = parse_http_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 1151 | |
| 1152 | if (!rule) { |
| 1153 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1154 | goto out; |
| 1155 | } |
| 1156 | |
| 1157 | err_code |= warnif_cond_conflicts(rule->cond, |
| 1158 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 1159 | file, linenum); |
| 1160 | |
| 1161 | LIST_ADDQ(&curproxy->http_res_rules, &rule->list); |
| 1162 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1163 | else if (strcmp(args[0], "http-after-response") == 0) { |
Christopher Faulet | 6d0c3df | 2020-01-22 09:26:35 +0100 | [diff] [blame] | 1164 | struct act_rule *rule; |
| 1165 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1166 | if (curproxy->cap & PR_CAP_DEF) { |
Christopher Faulet | 6d0c3df | 2020-01-22 09:26:35 +0100 | [diff] [blame] | 1167 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1168 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1169 | goto out; |
| 1170 | } |
| 1171 | |
| 1172 | if (!LIST_ISEMPTY(&curproxy->http_after_res_rules) && |
| 1173 | !LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->cond && |
| 1174 | (LIST_PREV(&curproxy->http_after_res_rules, struct act_rule *, list)->flags & ACT_FLAG_FINAL)) { |
| 1175 | ha_warning("parsing [%s:%d]: previous '%s' action is final and has no condition attached, further entries are NOOP.\n", |
| 1176 | file, linenum, args[0]); |
| 1177 | err_code |= ERR_WARN; |
| 1178 | } |
| 1179 | |
| 1180 | rule = parse_http_after_res_cond((const char **)args + 1, file, linenum, curproxy); |
| 1181 | |
| 1182 | if (!rule) { |
| 1183 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1184 | goto out; |
| 1185 | } |
| 1186 | |
| 1187 | err_code |= warnif_cond_conflicts(rule->cond, |
| 1188 | (curproxy->cap & PR_CAP_BE) ? SMP_VAL_BE_HRS_HDR : SMP_VAL_FE_HRS_HDR, |
| 1189 | file, linenum); |
| 1190 | |
| 1191 | LIST_ADDQ(&curproxy->http_after_res_rules, &rule->list); |
| 1192 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1193 | else if (strcmp(args[0], "http-send-name-header") == 0) { /* send server name in request header */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1194 | /* set the header name and length into the proxy structure */ |
| 1195 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1196 | err_code |= ERR_WARN; |
| 1197 | |
| 1198 | if (!*args[1]) { |
| 1199 | ha_alert("parsing [%s:%d] : '%s' requires a header string.\n", |
| 1200 | file, linenum, args[0]); |
| 1201 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1202 | goto out; |
| 1203 | } |
| 1204 | |
Christopher Faulet | dabcc8e | 2019-10-02 10:45:55 +0200 | [diff] [blame] | 1205 | /* set the desired header name, in lower case */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1206 | free(curproxy->server_id_hdr_name); |
| 1207 | curproxy->server_id_hdr_name = strdup(args[1]); |
| 1208 | curproxy->server_id_hdr_len = strlen(curproxy->server_id_hdr_name); |
Christopher Faulet | dabcc8e | 2019-10-02 10:45:55 +0200 | [diff] [blame] | 1209 | ist2bin_lc(curproxy->server_id_hdr_name, ist2(curproxy->server_id_hdr_name, curproxy->server_id_hdr_len)); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1210 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1211 | else if (strcmp(args[0], "block") == 0) { |
Tim Duesterhus | 7b7c47f | 2019-05-14 20:57:57 +0200 | [diff] [blame] | 1212 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. Use 'http-request deny' which uses the exact same syntax.\n", file, linenum, args[0]); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1213 | |
Tim Duesterhus | 7b7c47f | 2019-05-14 20:57:57 +0200 | [diff] [blame] | 1214 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1215 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1216 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1217 | else if (strcmp(args[0], "redirect") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1218 | struct redirect_rule *rule; |
| 1219 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1220 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1221 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1223 | goto out; |
| 1224 | } |
| 1225 | |
| 1226 | if ((rule = http_parse_redirect_rule(file, linenum, curproxy, (const char **)args + 1, &errmsg, 0, 0)) == NULL) { |
| 1227 | ha_alert("parsing [%s:%d] : error detected in %s '%s' while parsing redirect rule : %s.\n", |
| 1228 | file, linenum, proxy_type_str(curproxy), curproxy->id, errmsg); |
| 1229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1230 | goto out; |
| 1231 | } |
| 1232 | |
| 1233 | LIST_ADDQ(&curproxy->redirect_rules, &rule->list); |
| 1234 | err_code |= warnif_misplaced_redirect(curproxy, file, linenum, args[0]); |
| 1235 | err_code |= warnif_cond_conflicts(rule->cond, |
| 1236 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 1237 | file, linenum); |
| 1238 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1239 | else if (strcmp(args[0], "use_backend") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1240 | struct switching_rule *rule; |
| 1241 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1242 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1243 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1245 | goto out; |
| 1246 | } |
| 1247 | |
| 1248 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 1249 | err_code |= ERR_WARN; |
| 1250 | |
| 1251 | if (*(args[1]) == 0) { |
| 1252 | ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
| 1253 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1254 | goto out; |
| 1255 | } |
| 1256 | |
| 1257 | if (strcmp(args[2], "if") == 0 || strcmp(args[2], "unless") == 0) { |
| 1258 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 1259 | ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 1260 | file, linenum, errmsg); |
| 1261 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1262 | goto out; |
| 1263 | } |
| 1264 | |
| 1265 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_FE_SET_BCK, file, linenum); |
| 1266 | } |
| 1267 | else if (*args[2]) { |
| 1268 | ha_alert("parsing [%s:%d] : unexpected keyword '%s' after switching rule, only 'if' and 'unless' are allowed.\n", |
| 1269 | file, linenum, args[2]); |
| 1270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1271 | goto out; |
| 1272 | } |
| 1273 | |
| 1274 | rule = calloc(1, sizeof(*rule)); |
| 1275 | if (!rule) { |
| 1276 | ha_alert("Out of memory error.\n"); |
| 1277 | goto out; |
| 1278 | } |
| 1279 | rule->cond = cond; |
| 1280 | rule->be.name = strdup(args[1]); |
Tim Duesterhus | 5ce5a15 | 2021-01-03 22:54:43 +0100 | [diff] [blame] | 1281 | if (!rule->be.name) { |
| 1282 | ha_alert("Out of memory error.\n"); |
| 1283 | goto out; |
| 1284 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1285 | rule->line = linenum; |
| 1286 | rule->file = strdup(file); |
| 1287 | if (!rule->file) { |
| 1288 | ha_alert("Out of memory error.\n"); |
| 1289 | goto out; |
| 1290 | } |
| 1291 | LIST_INIT(&rule->list); |
| 1292 | LIST_ADDQ(&curproxy->switching_rules, &rule->list); |
| 1293 | } |
| 1294 | else if (strcmp(args[0], "use-server") == 0) { |
| 1295 | struct server_rule *rule; |
| 1296 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1297 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1298 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1299 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1300 | goto out; |
| 1301 | } |
| 1302 | |
| 1303 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1304 | err_code |= ERR_WARN; |
| 1305 | |
| 1306 | if (*(args[1]) == 0) { |
| 1307 | ha_alert("parsing [%s:%d] : '%s' expects a server name.\n", file, linenum, args[0]); |
| 1308 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1309 | goto out; |
| 1310 | } |
| 1311 | |
| 1312 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 1313 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1314 | file, linenum, args[0]); |
| 1315 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1316 | goto out; |
| 1317 | } |
| 1318 | |
| 1319 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 1320 | ha_alert("parsing [%s:%d] : error detected while parsing switching rule : %s.\n", |
| 1321 | file, linenum, errmsg); |
| 1322 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1323 | goto out; |
| 1324 | } |
| 1325 | |
| 1326 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
| 1327 | |
| 1328 | rule = calloc(1, sizeof(*rule)); |
| 1329 | rule->cond = cond; |
| 1330 | rule->srv.name = strdup(args[1]); |
Jerome Magnin | 824186b | 2020-03-29 09:37:12 +0200 | [diff] [blame] | 1331 | rule->line = linenum; |
| 1332 | rule->file = strdup(file); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1333 | LIST_INIT(&rule->list); |
| 1334 | LIST_ADDQ(&curproxy->server_rules, &rule->list); |
| 1335 | curproxy->be_req_ana |= AN_REQ_SRV_RULES; |
| 1336 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1337 | else if ((strcmp(args[0], "force-persist") == 0) || |
| 1338 | (strcmp(args[0], "ignore-persist") == 0)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1339 | struct persist_rule *rule; |
| 1340 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1341 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1342 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1343 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1344 | goto out; |
| 1345 | } |
| 1346 | |
| 1347 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 1348 | err_code |= ERR_WARN; |
| 1349 | |
| 1350 | if (strcmp(args[1], "if") != 0 && strcmp(args[1], "unless") != 0) { |
| 1351 | ha_alert("parsing [%s:%d] : '%s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1352 | file, linenum, args[0]); |
| 1353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1354 | goto out; |
| 1355 | } |
| 1356 | |
| 1357 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 1, &errmsg)) == NULL) { |
| 1358 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s' rule : %s.\n", |
| 1359 | file, linenum, args[0], errmsg); |
| 1360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1361 | goto out; |
| 1362 | } |
| 1363 | |
| 1364 | /* note: BE_REQ_CNT is the first one after FE_SET_BCK, which is |
| 1365 | * where force-persist is applied. |
| 1366 | */ |
| 1367 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_REQ_CNT, file, linenum); |
| 1368 | |
| 1369 | rule = calloc(1, sizeof(*rule)); |
| 1370 | rule->cond = cond; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1371 | if (strcmp(args[0], "force-persist") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1372 | rule->type = PERSIST_TYPE_FORCE; |
| 1373 | } else { |
| 1374 | rule->type = PERSIST_TYPE_IGNORE; |
| 1375 | } |
| 1376 | LIST_INIT(&rule->list); |
| 1377 | LIST_ADDQ(&curproxy->persist_rules, &rule->list); |
| 1378 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1379 | else if (strcmp(args[0], "stick-table") == 0) { |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1380 | struct stktable *other; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1381 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1382 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1383 | ha_alert("parsing [%s:%d] : 'stick-table' is not supported in 'defaults' section.\n", |
| 1384 | file, linenum); |
| 1385 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1386 | goto out; |
| 1387 | } |
| 1388 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1389 | other = stktable_find_by_name(curproxy->id); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1390 | if (other) { |
| 1391 | ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1392 | file, linenum, curproxy->id, |
| 1393 | other->proxy ? proxy_cap_str(other->proxy->cap) : "peers", |
| 1394 | other->proxy ? other->id : other->peers.p->id, |
| 1395 | other->conf.file, other->conf.line); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1396 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1397 | goto out; |
| 1398 | } |
| 1399 | |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1400 | curproxy->table = calloc(1, sizeof *curproxy->table); |
| 1401 | if (!curproxy->table) { |
| 1402 | ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n", |
| 1403 | file, linenum, args[0], args[1]); |
| 1404 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1405 | goto out; |
| 1406 | } |
| 1407 | |
Frédéric Lécaille | c02766a | 2019-03-20 15:06:55 +0100 | [diff] [blame] | 1408 | err_code |= parse_stick_table(file, linenum, args, curproxy->table, |
| 1409 | curproxy->id, curproxy->id, NULL); |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1410 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1411 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1412 | |
Frédéric Lécaille | d456aa4 | 2019-03-08 14:47:00 +0100 | [diff] [blame] | 1413 | /* Store the proxy in the stick-table. */ |
| 1414 | curproxy->table->proxy = curproxy; |
Frédéric Lécaille | 1b8e68e | 2019-03-14 07:07:41 +0100 | [diff] [blame] | 1415 | |
| 1416 | stktable_store_name(curproxy->table); |
| 1417 | curproxy->table->next = stktables_list; |
| 1418 | stktables_list = curproxy->table; |
Frédéric Lécaille | 015e4d7 | 2019-03-19 14:55:01 +0100 | [diff] [blame] | 1419 | |
| 1420 | /* Add this proxy to the list of proxies which refer to its stick-table. */ |
| 1421 | if (curproxy->table->proxies_list != curproxy) { |
| 1422 | curproxy->next_stkt_ref = curproxy->table->proxies_list; |
| 1423 | curproxy->table->proxies_list = curproxy; |
| 1424 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1425 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1426 | else if (strcmp(args[0], "stick") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1427 | struct sticking_rule *rule; |
| 1428 | struct sample_expr *expr; |
| 1429 | int myidx = 0; |
| 1430 | const char *name = NULL; |
| 1431 | int flags; |
| 1432 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1433 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1434 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1435 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1436 | goto out; |
| 1437 | } |
| 1438 | |
| 1439 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) { |
| 1440 | err_code |= ERR_WARN; |
| 1441 | goto out; |
| 1442 | } |
| 1443 | |
| 1444 | myidx++; |
| 1445 | if ((strcmp(args[myidx], "store") == 0) || |
| 1446 | (strcmp(args[myidx], "store-request") == 0)) { |
| 1447 | myidx++; |
| 1448 | flags = STK_IS_STORE; |
| 1449 | } |
| 1450 | else if (strcmp(args[myidx], "store-response") == 0) { |
| 1451 | myidx++; |
| 1452 | flags = STK_IS_STORE | STK_ON_RSP; |
| 1453 | } |
| 1454 | else if (strcmp(args[myidx], "match") == 0) { |
| 1455 | myidx++; |
| 1456 | flags = STK_IS_MATCH; |
| 1457 | } |
| 1458 | else if (strcmp(args[myidx], "on") == 0) { |
| 1459 | myidx++; |
| 1460 | flags = STK_IS_MATCH | STK_IS_STORE; |
| 1461 | } |
| 1462 | else { |
| 1463 | ha_alert("parsing [%s:%d] : '%s' expects 'on', 'match', or 'store'.\n", file, linenum, args[0]); |
| 1464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1465 | goto out; |
| 1466 | } |
| 1467 | |
| 1468 | if (*(args[myidx]) == 0) { |
| 1469 | ha_alert("parsing [%s:%d] : '%s' expects a fetch method.\n", file, linenum, args[0]); |
| 1470 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1471 | goto out; |
| 1472 | } |
| 1473 | |
| 1474 | curproxy->conf.args.ctx = ARGC_STK; |
Willy Tarreau | e3b57bf | 2020-02-14 16:50:14 +0100 | [diff] [blame] | 1475 | expr = sample_parse_expr(args, &myidx, file, linenum, &errmsg, &curproxy->conf.args, NULL); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1476 | if (!expr) { |
| 1477 | ha_alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], errmsg); |
| 1478 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1479 | goto out; |
| 1480 | } |
| 1481 | |
| 1482 | if (flags & STK_ON_RSP) { |
| 1483 | if (!(expr->fetch->val & SMP_VAL_BE_STO_RUL)) { |
| 1484 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available for 'store-response'.\n", |
| 1485 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
| 1486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1487 | free(expr); |
| 1488 | goto out; |
| 1489 | } |
| 1490 | } else { |
| 1491 | if (!(expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
| 1492 | ha_alert("parsing [%s:%d] : '%s': fetch method '%s' extracts information from '%s', none of which is available during request.\n", |
| 1493 | file, linenum, args[0], expr->fetch->kw, sample_src_names(expr->fetch->use)); |
| 1494 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1495 | free(expr); |
| 1496 | goto out; |
| 1497 | } |
| 1498 | } |
| 1499 | |
Christopher Faulet | 711ed6a | 2019-07-16 14:16:10 +0200 | [diff] [blame] | 1500 | /* check if we need to allocate an http_txn struct for HTTP parsing */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1501 | curproxy->http_needed |= !!(expr->fetch->use & SMP_USE_HTTP_ANY); |
| 1502 | |
| 1503 | if (strcmp(args[myidx], "table") == 0) { |
| 1504 | myidx++; |
| 1505 | name = args[myidx++]; |
| 1506 | } |
| 1507 | |
| 1508 | if (strcmp(args[myidx], "if") == 0 || strcmp(args[myidx], "unless") == 0) { |
| 1509 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + myidx, &errmsg)) == NULL) { |
| 1510 | ha_alert("parsing [%s:%d] : '%s': error detected while parsing sticking condition : %s.\n", |
| 1511 | file, linenum, args[0], errmsg); |
| 1512 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1513 | free(expr); |
| 1514 | goto out; |
| 1515 | } |
| 1516 | } |
| 1517 | else if (*(args[myidx])) { |
| 1518 | ha_alert("parsing [%s:%d] : '%s': unknown keyword '%s'.\n", |
| 1519 | file, linenum, args[0], args[myidx]); |
| 1520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1521 | free(expr); |
| 1522 | goto out; |
| 1523 | } |
| 1524 | if (flags & STK_ON_RSP) |
| 1525 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_STO_RUL, file, linenum); |
| 1526 | else |
| 1527 | err_code |= warnif_cond_conflicts(cond, SMP_VAL_BE_SET_SRV, file, linenum); |
| 1528 | |
| 1529 | rule = calloc(1, sizeof(*rule)); |
| 1530 | rule->cond = cond; |
| 1531 | rule->expr = expr; |
| 1532 | rule->flags = flags; |
| 1533 | rule->table.name = name ? strdup(name) : NULL; |
| 1534 | LIST_INIT(&rule->list); |
| 1535 | if (flags & STK_ON_RSP) |
| 1536 | LIST_ADDQ(&curproxy->storersp_rules, &rule->list); |
| 1537 | else |
| 1538 | LIST_ADDQ(&curproxy->sticking_rules, &rule->list); |
| 1539 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1540 | else if (strcmp(args[0], "stats") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 1541 | if (!(curproxy->cap & PR_CAP_DEF) && curproxy->uri_auth == curr_defproxy->uri_auth) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1542 | curproxy->uri_auth = NULL; /* we must detach from the default config */ |
| 1543 | |
| 1544 | if (!*args[1]) { |
| 1545 | goto stats_error_parsing; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1546 | } else if (strcmp(args[1], "admin") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1547 | struct stats_admin_rule *rule; |
| 1548 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1549 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1550 | ha_alert("parsing [%s:%d]: '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]); |
| 1551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1552 | goto out; |
| 1553 | } |
| 1554 | |
| 1555 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 1556 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1557 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1558 | goto out; |
| 1559 | } |
| 1560 | |
| 1561 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 1562 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 1563 | file, linenum, args[0], args[1]); |
| 1564 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1565 | goto out; |
| 1566 | } |
| 1567 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 1568 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' rule : %s.\n", |
| 1569 | file, linenum, args[0], args[1], errmsg); |
| 1570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1571 | goto out; |
| 1572 | } |
| 1573 | |
| 1574 | err_code |= warnif_cond_conflicts(cond, |
| 1575 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 1576 | file, linenum); |
| 1577 | |
| 1578 | rule = calloc(1, sizeof(*rule)); |
| 1579 | rule->cond = cond; |
| 1580 | LIST_INIT(&rule->list); |
| 1581 | LIST_ADDQ(&curproxy->uri_auth->admin_rules, &rule->list); |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1582 | } else if (strcmp(args[1], "uri") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1583 | if (*(args[2]) == 0) { |
| 1584 | ha_alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum); |
| 1585 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1586 | goto out; |
| 1587 | } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) { |
| 1588 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1589 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1590 | goto out; |
| 1591 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1592 | } else if (strcmp(args[1], "realm") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1593 | if (*(args[2]) == 0) { |
| 1594 | ha_alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum); |
| 1595 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1596 | goto out; |
| 1597 | } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) { |
| 1598 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1599 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1600 | goto out; |
| 1601 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1602 | } else if (strcmp(args[1], "refresh") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1603 | unsigned interval; |
| 1604 | |
| 1605 | err = parse_time_err(args[2], &interval, TIME_UNIT_S); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 1606 | if (err == PARSE_TIME_OVER) { |
| 1607 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to stats refresh interval, maximum value is 2147483647 s (~68 years).\n", |
| 1608 | file, linenum, args[2]); |
| 1609 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1610 | goto out; |
| 1611 | } |
| 1612 | else if (err == PARSE_TIME_UNDER) { |
| 1613 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to stats refresh interval, minimum non-null value is 1 s.\n", |
| 1614 | file, linenum, args[2]); |
| 1615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1616 | goto out; |
| 1617 | } |
| 1618 | else if (err) { |
| 1619 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to stats refresh interval.\n", |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1620 | file, linenum, *err); |
| 1621 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1622 | goto out; |
| 1623 | } else if (!stats_set_refresh(&curproxy->uri_auth, interval)) { |
| 1624 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1625 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1626 | goto out; |
| 1627 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1628 | } else if (strcmp(args[1], "http-request") == 0) { /* request access control: allow/deny/auth */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1629 | struct act_rule *rule; |
| 1630 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1631 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1632 | ha_alert("parsing [%s:%d]: '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 1633 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1634 | goto out; |
| 1635 | } |
| 1636 | |
| 1637 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 1638 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1639 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1640 | goto out; |
| 1641 | } |
| 1642 | |
| 1643 | if (!LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
| 1644 | !LIST_PREV(&curproxy->uri_auth->http_req_rules, struct act_rule *, list)->cond) { |
| 1645 | ha_warning("parsing [%s:%d]: previous '%s' action has no condition attached, further entries are NOOP.\n", |
| 1646 | file, linenum, args[0]); |
| 1647 | err_code |= ERR_WARN; |
| 1648 | } |
| 1649 | |
| 1650 | rule = parse_http_req_cond((const char **)args + 2, file, linenum, curproxy); |
| 1651 | |
| 1652 | if (!rule) { |
| 1653 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1654 | goto out; |
| 1655 | } |
| 1656 | |
| 1657 | err_code |= warnif_cond_conflicts(rule->cond, |
| 1658 | (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR, |
| 1659 | file, linenum); |
| 1660 | LIST_ADDQ(&curproxy->uri_auth->http_req_rules, &rule->list); |
| 1661 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1662 | } else if (strcmp(args[1], "auth") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1663 | if (*(args[2]) == 0) { |
| 1664 | ha_alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum); |
| 1665 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1666 | goto out; |
| 1667 | } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) { |
| 1668 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1669 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1670 | goto out; |
| 1671 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1672 | } else if (strcmp(args[1], "scope") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1673 | if (*(args[2]) == 0) { |
| 1674 | ha_alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum); |
| 1675 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1676 | goto out; |
| 1677 | } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) { |
| 1678 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1679 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1680 | goto out; |
| 1681 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1682 | } else if (strcmp(args[1], "enable") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1683 | if (!stats_check_init_uri_auth(&curproxy->uri_auth)) { |
| 1684 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1685 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1686 | goto out; |
| 1687 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1688 | } else if (strcmp(args[1], "hide-version") == 0) { |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1689 | if (!stats_set_flag(&curproxy->uri_auth, STAT_HIDEVER)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1690 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
| 1691 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1692 | goto out; |
| 1693 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1694 | } else if (strcmp(args[1], "show-legends") == 0) { |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1695 | if (!stats_set_flag(&curproxy->uri_auth, STAT_SHLGNDS)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1696 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1697 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1698 | goto out; |
| 1699 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1700 | } else if (strcmp(args[1], "show-modules") == 0) { |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1701 | if (!stats_set_flag(&curproxy->uri_auth, STAT_SHMODULES)) { |
| 1702 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1703 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1704 | goto out; |
| 1705 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1706 | } else if (strcmp(args[1], "show-node") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1707 | |
| 1708 | if (*args[2]) { |
| 1709 | int i; |
| 1710 | char c; |
| 1711 | |
| 1712 | for (i=0; args[2][i]; i++) { |
| 1713 | c = args[2][i]; |
| 1714 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 1715 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
| 1716 | break; |
| 1717 | } |
| 1718 | |
| 1719 | if (!i || args[2][i]) { |
| 1720 | ha_alert("parsing [%s:%d]: '%s %s' invalid node name - should be a string" |
| 1721 | "with digits(0-9), letters(A-Z, a-z), hyphen(-) or underscode(_).\n", |
| 1722 | file, linenum, args[0], args[1]); |
| 1723 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1724 | goto out; |
| 1725 | } |
| 1726 | } |
| 1727 | |
| 1728 | if (!stats_set_node(&curproxy->uri_auth, args[2])) { |
| 1729 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1730 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1731 | goto out; |
| 1732 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1733 | } else if (strcmp(args[1], "show-desc") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1734 | char *desc = NULL; |
| 1735 | |
| 1736 | if (*args[2]) { |
| 1737 | int i, len=0; |
| 1738 | char *d; |
| 1739 | |
| 1740 | for (i = 2; *args[i]; i++) |
| 1741 | len += strlen(args[i]) + 1; |
| 1742 | |
| 1743 | desc = d = calloc(1, len); |
| 1744 | |
| 1745 | d += snprintf(d, desc + len - d, "%s", args[2]); |
| 1746 | for (i = 3; *args[i]; i++) |
| 1747 | d += snprintf(d, desc + len - d, " %s", args[i]); |
| 1748 | } |
| 1749 | |
| 1750 | if (!*args[2] && !global.desc) |
| 1751 | ha_warning("parsing [%s:%d]: '%s' requires a parameter or 'desc' to be set in the global section.\n", |
| 1752 | file, linenum, args[1]); |
| 1753 | else { |
| 1754 | if (!stats_set_desc(&curproxy->uri_auth, desc)) { |
| 1755 | free(desc); |
| 1756 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
| 1757 | err_code |= ERR_ALERT | ERR_ABORT; |
| 1758 | goto out; |
| 1759 | } |
| 1760 | free(desc); |
| 1761 | } |
| 1762 | } else { |
| 1763 | stats_error_parsing: |
| 1764 | ha_alert("parsing [%s:%d]: %s '%s', expects 'admin', 'uri', 'realm', 'auth', 'scope', 'enable', 'hide-version', 'show-node', 'show-desc' or 'show-legends'.\n", |
| 1765 | file, linenum, *args[1]?"unknown stats parameter":"missing keyword in", args[*args[1]?1:0]); |
| 1766 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1767 | goto out; |
| 1768 | } |
| 1769 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1770 | else if (strcmp(args[0], "option") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1771 | int optnum; |
| 1772 | |
| 1773 | if (*(args[1]) == '\0') { |
| 1774 | ha_alert("parsing [%s:%d]: '%s' expects an option name.\n", |
| 1775 | file, linenum, args[0]); |
| 1776 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1777 | goto out; |
| 1778 | } |
| 1779 | |
| 1780 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1781 | if (strcmp(args[1], cfg_opts[optnum].name) == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1782 | if (cfg_opts[optnum].cap == PR_CAP_NONE) { |
| 1783 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 1784 | file, linenum, cfg_opts[optnum].name); |
| 1785 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1786 | goto out; |
| 1787 | } |
| 1788 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 1789 | goto out; |
| 1790 | |
| 1791 | if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) { |
| 1792 | err_code |= ERR_WARN; |
| 1793 | goto out; |
| 1794 | } |
| 1795 | |
| 1796 | curproxy->no_options &= ~cfg_opts[optnum].val; |
| 1797 | curproxy->options &= ~cfg_opts[optnum].val; |
| 1798 | |
| 1799 | switch (kwm) { |
| 1800 | case KWM_STD: |
| 1801 | curproxy->options |= cfg_opts[optnum].val; |
| 1802 | break; |
| 1803 | case KWM_NO: |
| 1804 | curproxy->no_options |= cfg_opts[optnum].val; |
| 1805 | break; |
| 1806 | case KWM_DEF: /* already cleared */ |
| 1807 | break; |
| 1808 | } |
| 1809 | |
| 1810 | goto out; |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1815 | if (strcmp(args[1], cfg_opts2[optnum].name) == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1816 | if (cfg_opts2[optnum].cap == PR_CAP_NONE) { |
| 1817 | ha_alert("parsing [%s:%d]: option '%s' is not supported due to build options.\n", |
| 1818 | file, linenum, cfg_opts2[optnum].name); |
| 1819 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1820 | goto out; |
| 1821 | } |
| 1822 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 1823 | goto out; |
| 1824 | if (warnifnotcap(curproxy, cfg_opts2[optnum].cap, file, linenum, args[1], NULL)) { |
| 1825 | err_code |= ERR_WARN; |
| 1826 | goto out; |
| 1827 | } |
| 1828 | |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 1829 | /* "[no] option http-use-htx" is deprecated */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1830 | if (strcmp(cfg_opts2[optnum].name, "http-use-htx") == 0) { |
Christopher Faulet | f89f099 | 2019-07-19 11:17:38 +0200 | [diff] [blame] | 1831 | if (kwm ==KWM_NO) { |
| 1832 | ha_warning("parsing [%s:%d]: option '%s' is deprecated and ignored." |
| 1833 | " The HTX mode is now the only supported mode.\n", |
| 1834 | file, linenum, cfg_opts2[optnum].name); |
| 1835 | err_code |= ERR_WARN; |
| 1836 | } |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 1837 | goto out; |
| 1838 | } |
| 1839 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1840 | curproxy->no_options2 &= ~cfg_opts2[optnum].val; |
| 1841 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
| 1842 | |
| 1843 | switch (kwm) { |
| 1844 | case KWM_STD: |
| 1845 | curproxy->options2 |= cfg_opts2[optnum].val; |
| 1846 | break; |
| 1847 | case KWM_NO: |
| 1848 | curproxy->no_options2 |= cfg_opts2[optnum].val; |
| 1849 | break; |
| 1850 | case KWM_DEF: /* already cleared */ |
| 1851 | break; |
| 1852 | } |
| 1853 | goto out; |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | /* HTTP options override each other. They can be cancelled using |
| 1858 | * "no option xxx" which only switches to default mode if the mode |
| 1859 | * was this one (useful for cancelling options set in defaults |
| 1860 | * sections). |
| 1861 | */ |
| 1862 | if (strcmp(args[1], "httpclose") == 0 || strcmp(args[1], "forceclose") == 0) { |
Tim Duesterhus | 10c6c16 | 2019-05-14 20:58:00 +0200 | [diff] [blame] | 1863 | if (strcmp(args[1], "forceclose") == 0) { |
| 1864 | if (!already_warned(WARN_FORCECLOSE_DEPRECATED)) |
| 1865 | ha_warning("parsing [%s:%d]: keyword '%s' is deprecated in favor of 'httpclose', and will not be supported by future versions.\n", |
| 1866 | file, linenum, args[1]); |
| 1867 | err_code |= ERR_WARN; |
| 1868 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1869 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 1870 | goto out; |
| 1871 | if (kwm == KWM_STD) { |
| 1872 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1873 | curproxy->options |= PR_O_HTTP_CLO; |
| 1874 | goto out; |
| 1875 | } |
| 1876 | else if (kwm == KWM_NO) { |
| 1877 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_CLO) |
| 1878 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1879 | goto out; |
| 1880 | } |
| 1881 | } |
| 1882 | else if (strcmp(args[1], "http-server-close") == 0) { |
| 1883 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 1884 | goto out; |
| 1885 | if (kwm == KWM_STD) { |
| 1886 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1887 | curproxy->options |= PR_O_HTTP_SCL; |
| 1888 | goto out; |
| 1889 | } |
| 1890 | else if (kwm == KWM_NO) { |
| 1891 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) |
| 1892 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1893 | goto out; |
| 1894 | } |
| 1895 | } |
| 1896 | else if (strcmp(args[1], "http-keep-alive") == 0) { |
| 1897 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 1898 | goto out; |
| 1899 | if (kwm == KWM_STD) { |
| 1900 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1901 | curproxy->options |= PR_O_HTTP_KAL; |
| 1902 | goto out; |
| 1903 | } |
| 1904 | else if (kwm == KWM_NO) { |
| 1905 | if ((curproxy->options & PR_O_HTTP_MODE) == PR_O_HTTP_KAL) |
| 1906 | curproxy->options &= ~PR_O_HTTP_MODE; |
| 1907 | goto out; |
| 1908 | } |
| 1909 | } |
| 1910 | else if (strcmp(args[1], "http-tunnel") == 0) { |
Christopher Faulet | 73e8ede | 2019-07-16 15:04:46 +0200 | [diff] [blame] | 1911 | ha_warning("parsing [%s:%d]: the option '%s' is deprecated and will be removed in next version.\n", |
| 1912 | file, linenum, args[1]); |
| 1913 | err_code |= ERR_WARN; |
| 1914 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | /* Redispatch can take an integer argument that control when the |
| 1918 | * resispatch occurs. All values are relative to the retries option. |
| 1919 | * This can be cancelled using "no option xxx". |
| 1920 | */ |
| 1921 | if (strcmp(args[1], "redispatch") == 0) { |
| 1922 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL)) { |
| 1923 | err_code |= ERR_WARN; |
| 1924 | goto out; |
| 1925 | } |
| 1926 | |
| 1927 | curproxy->no_options &= ~PR_O_REDISP; |
| 1928 | curproxy->options &= ~PR_O_REDISP; |
| 1929 | |
| 1930 | switch (kwm) { |
| 1931 | case KWM_STD: |
| 1932 | curproxy->options |= PR_O_REDISP; |
| 1933 | curproxy->redispatch_after = -1; |
| 1934 | if(*args[2]) { |
| 1935 | curproxy->redispatch_after = atol(args[2]); |
| 1936 | } |
| 1937 | break; |
| 1938 | case KWM_NO: |
| 1939 | curproxy->no_options |= PR_O_REDISP; |
| 1940 | curproxy->redispatch_after = 0; |
| 1941 | break; |
| 1942 | case KWM_DEF: /* already cleared */ |
| 1943 | break; |
| 1944 | } |
| 1945 | goto out; |
| 1946 | } |
| 1947 | |
| 1948 | if (kwm != KWM_STD) { |
| 1949 | ha_alert("parsing [%s:%d]: negation/default is not supported for option '%s'.\n", |
| 1950 | file, linenum, args[1]); |
| 1951 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1952 | goto out; |
| 1953 | } |
| 1954 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1955 | if (strcmp(args[1], "httplog") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1956 | char *logformat; |
| 1957 | /* generate a complete HTTP log */ |
| 1958 | logformat = default_http_log_format; |
| 1959 | if (*(args[2]) != '\0') { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1960 | if (strcmp(args[2], "clf") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1961 | curproxy->options2 |= PR_O2_CLFLOG; |
| 1962 | logformat = clf_http_log_format; |
| 1963 | } else { |
| 1964 | ha_alert("parsing [%s:%d] : keyword '%s' only supports option 'clf'.\n", file, linenum, args[1]); |
| 1965 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1966 | goto out; |
| 1967 | } |
| 1968 | if (alertif_too_many_args_idx(1, 1, file, linenum, args, &err_code)) |
| 1969 | goto out; |
| 1970 | } |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1971 | if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1972 | char *oldlogformat = "log-format"; |
| 1973 | char *clflogformat = ""; |
| 1974 | |
| 1975 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 1976 | oldlogformat = "option httplog"; |
| 1977 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 1978 | oldlogformat = "option tcplog"; |
| 1979 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 1980 | oldlogformat = "option httplog clf"; |
| 1981 | if (logformat == clf_http_log_format) |
| 1982 | clflogformat = " clf"; |
| 1983 | ha_warning("parsing [%s:%d]: 'option httplog%s' overrides previous '%s' in 'defaults' section.\n", |
| 1984 | file, linenum, clflogformat, oldlogformat); |
| 1985 | } |
| 1986 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 1987 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 1988 | curproxy->conf.logformat_string != clf_http_log_format) |
| 1989 | free(curproxy->conf.logformat_string); |
| 1990 | curproxy->conf.logformat_string = logformat; |
| 1991 | |
| 1992 | free(curproxy->conf.lfs_file); |
| 1993 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 1994 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 1995 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 1996 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 1997 | ha_warning("parsing [%s:%d] : backend '%s' : 'option httplog' directive is ignored in backends.\n", |
| 1998 | file, linenum, curproxy->id); |
| 1999 | err_code |= ERR_WARN; |
| 2000 | } |
| 2001 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2002 | else if (strcmp(args[1], "tcplog") == 0) { |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2003 | if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2004 | char *oldlogformat = "log-format"; |
| 2005 | |
| 2006 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 2007 | oldlogformat = "option httplog"; |
| 2008 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 2009 | oldlogformat = "option tcplog"; |
| 2010 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 2011 | oldlogformat = "option httplog clf"; |
| 2012 | ha_warning("parsing [%s:%d]: 'option tcplog' overrides previous '%s' in 'defaults' section.\n", |
| 2013 | file, linenum, oldlogformat); |
| 2014 | } |
| 2015 | /* generate a detailed TCP log */ |
| 2016 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 2017 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2018 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2019 | free(curproxy->conf.logformat_string); |
| 2020 | curproxy->conf.logformat_string = default_tcp_log_format; |
| 2021 | |
| 2022 | free(curproxy->conf.lfs_file); |
| 2023 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 2024 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 2025 | |
| 2026 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2027 | goto out; |
| 2028 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2029 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2030 | ha_warning("parsing [%s:%d] : backend '%s' : 'option tcplog' directive is ignored in backends.\n", |
| 2031 | file, linenum, curproxy->id); |
| 2032 | err_code |= ERR_WARN; |
| 2033 | } |
| 2034 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2035 | else if (strcmp(args[1], "tcpka") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2036 | /* enable TCP keep-alives on client and server streams */ |
| 2037 | if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL)) |
| 2038 | err_code |= ERR_WARN; |
| 2039 | |
| 2040 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2041 | goto out; |
| 2042 | |
| 2043 | if (curproxy->cap & PR_CAP_FE) |
| 2044 | curproxy->options |= PR_O_TCP_CLI_KA; |
| 2045 | if (curproxy->cap & PR_CAP_BE) |
| 2046 | curproxy->options |= PR_O_TCP_SRV_KA; |
| 2047 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2048 | else if (strcmp(args[1], "httpchk") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2049 | err_code |= proxy_parse_httpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 6c2a743 | 2020-04-09 14:48:48 +0200 | [diff] [blame] | 2050 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2051 | goto out; |
| 2052 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2053 | else if (strcmp(args[1], "ssl-hello-chk") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2054 | err_code |= proxy_parse_ssl_hello_chk_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 811f78c | 2020-04-01 11:10:27 +0200 | [diff] [blame] | 2055 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2056 | goto out; |
| 2057 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2058 | else if (strcmp(args[1], "smtpchk") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2059 | err_code |= proxy_parse_smtpchk_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | fbcc77c | 2020-04-01 20:54:05 +0200 | [diff] [blame] | 2060 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2061 | goto out; |
| 2062 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2063 | else if (strcmp(args[1], "pgsql-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2064 | err_code |= proxy_parse_pgsql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | ce35507 | 2020-04-02 11:44:39 +0200 | [diff] [blame] | 2065 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2066 | goto out; |
| 2067 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2068 | else if (strcmp(args[1], "redis-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2069 | err_code |= proxy_parse_redis_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 33f05df | 2020-04-01 11:08:50 +0200 | [diff] [blame] | 2070 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2071 | goto out; |
| 2072 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2073 | else if (strcmp(args[1], "mysql-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2074 | err_code |= proxy_parse_mysql_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | f2b3be5 | 2020-04-02 18:07:37 +0200 | [diff] [blame] | 2075 | if (err_code & ERR_FATAL) |
| 2076 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2077 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2078 | else if (strcmp(args[1], "ldap-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2079 | err_code |= proxy_parse_ldap_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 1997eca | 2020-04-03 23:13:50 +0200 | [diff] [blame] | 2080 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2081 | goto out; |
| 2082 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2083 | else if (strcmp(args[1], "spop-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2084 | err_code |= proxy_parse_spop_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 267b01b | 2020-04-04 10:27:09 +0200 | [diff] [blame] | 2085 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2086 | goto out; |
| 2087 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2088 | else if (strcmp(args[1], "tcp-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2089 | err_code |= proxy_parse_tcp_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 430e480 | 2020-04-09 15:28:16 +0200 | [diff] [blame] | 2090 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2091 | goto out; |
| 2092 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2093 | else if (strcmp(args[1], "external-check") == 0) { |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2094 | err_code |= proxy_parse_external_check_opt(args, 0, curproxy, curr_defproxy, file, linenum); |
Christopher Faulet | 6f55791 | 2020-04-09 15:58:50 +0200 | [diff] [blame] | 2095 | if (err_code & ERR_FATAL) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2096 | goto out; |
| 2097 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2098 | else if (strcmp(args[1], "forwardfor") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2099 | int cur_arg; |
| 2100 | |
| 2101 | /* insert x-forwarded-for field, but not for the IP address listed as an except. |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 2102 | * set default options (ie: bitfield, header name, etc) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2103 | */ |
| 2104 | |
| 2105 | curproxy->options |= PR_O_FWDFOR | PR_O_FF_ALWAYS; |
| 2106 | |
| 2107 | free(curproxy->fwdfor_hdr_name); |
| 2108 | curproxy->fwdfor_hdr_name = strdup(DEF_XFORWARDFOR_HDR); |
| 2109 | curproxy->fwdfor_hdr_len = strlen(DEF_XFORWARDFOR_HDR); |
| 2110 | |
| 2111 | /* loop to go through arguments - start at 2, since 0+1 = "option" "forwardfor" */ |
| 2112 | cur_arg = 2; |
| 2113 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2114 | if (strcmp(args[cur_arg], "except") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2115 | /* suboption except - needs additional argument for it */ |
| 2116 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_net, &curproxy->except_mask)) { |
| 2117 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2118 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2119 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2120 | goto out; |
| 2121 | } |
| 2122 | /* flush useless bits */ |
| 2123 | curproxy->except_net.s_addr &= curproxy->except_mask.s_addr; |
| 2124 | cur_arg += 2; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2125 | } else if (strcmp(args[cur_arg], "header") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2126 | /* suboption header - needs additional argument for it */ |
| 2127 | if (*(args[cur_arg+1]) == 0) { |
| 2128 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2129 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2130 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2131 | goto out; |
| 2132 | } |
| 2133 | free(curproxy->fwdfor_hdr_name); |
| 2134 | curproxy->fwdfor_hdr_name = strdup(args[cur_arg+1]); |
| 2135 | curproxy->fwdfor_hdr_len = strlen(curproxy->fwdfor_hdr_name); |
| 2136 | cur_arg += 2; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2137 | } else if (strcmp(args[cur_arg], "if-none") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2138 | curproxy->options &= ~PR_O_FF_ALWAYS; |
| 2139 | cur_arg += 1; |
| 2140 | } else { |
| 2141 | /* unknown suboption - catchall */ |
| 2142 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except', 'header' and 'if-none'.\n", |
| 2143 | file, linenum, args[0], args[1]); |
| 2144 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2145 | goto out; |
| 2146 | } |
| 2147 | } /* end while loop */ |
| 2148 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2149 | else if (strcmp(args[1], "originalto") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2150 | int cur_arg; |
| 2151 | |
| 2152 | /* insert x-original-to field, but not for the IP address listed as an except. |
| 2153 | * set default options (ie: bitfield, header name, etc) |
| 2154 | */ |
| 2155 | |
| 2156 | curproxy->options |= PR_O_ORGTO; |
| 2157 | |
| 2158 | free(curproxy->orgto_hdr_name); |
| 2159 | curproxy->orgto_hdr_name = strdup(DEF_XORIGINALTO_HDR); |
| 2160 | curproxy->orgto_hdr_len = strlen(DEF_XORIGINALTO_HDR); |
| 2161 | |
| 2162 | /* loop to go through arguments - start at 2, since 0+1 = "option" "originalto" */ |
| 2163 | cur_arg = 2; |
| 2164 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2165 | if (strcmp(args[cur_arg], "except") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2166 | /* suboption except - needs additional argument for it */ |
| 2167 | if (!*(args[cur_arg+1]) || !str2net(args[cur_arg+1], 1, &curproxy->except_to, &curproxy->except_mask_to)) { |
| 2168 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <address>[/mask] as argument.\n", |
| 2169 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2170 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2171 | goto out; |
| 2172 | } |
| 2173 | /* flush useless bits */ |
| 2174 | curproxy->except_to.s_addr &= curproxy->except_mask_to.s_addr; |
| 2175 | cur_arg += 2; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2176 | } else if (strcmp(args[cur_arg], "header") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2177 | /* suboption header - needs additional argument for it */ |
| 2178 | if (*(args[cur_arg+1]) == 0) { |
| 2179 | ha_alert("parsing [%s:%d] : '%s %s %s' expects <header_name> as argument.\n", |
| 2180 | file, linenum, args[0], args[1], args[cur_arg]); |
| 2181 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2182 | goto out; |
| 2183 | } |
| 2184 | free(curproxy->orgto_hdr_name); |
| 2185 | curproxy->orgto_hdr_name = strdup(args[cur_arg+1]); |
| 2186 | curproxy->orgto_hdr_len = strlen(curproxy->orgto_hdr_name); |
| 2187 | cur_arg += 2; |
| 2188 | } else { |
| 2189 | /* unknown suboption - catchall */ |
| 2190 | ha_alert("parsing [%s:%d] : '%s %s' only supports optional values: 'except' and 'header'.\n", |
| 2191 | file, linenum, args[0], args[1]); |
| 2192 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2193 | goto out; |
| 2194 | } |
| 2195 | } /* end while loop */ |
| 2196 | } |
| 2197 | else { |
| 2198 | ha_alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]); |
| 2199 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2200 | goto out; |
| 2201 | } |
| 2202 | goto out; |
| 2203 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2204 | else if (strcmp(args[0], "default_backend") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2205 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2206 | err_code |= ERR_WARN; |
| 2207 | |
| 2208 | if (*(args[1]) == 0) { |
| 2209 | ha_alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]); |
| 2210 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2211 | goto out; |
| 2212 | } |
| 2213 | free(curproxy->defbe.name); |
| 2214 | curproxy->defbe.name = strdup(args[1]); |
| 2215 | |
| 2216 | if (alertif_too_many_args_idx(1, 0, file, linenum, args, &err_code)) |
| 2217 | goto out; |
| 2218 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2219 | else if (strcmp(args[0], "redispatch") == 0 || strcmp(args[0], "redisp") == 0) { |
Tim Duesterhus | dac168b | 2019-05-14 20:57:58 +0200 | [diff] [blame] | 2220 | ha_alert("parsing [%s:%d] : keyword '%s' directive is not supported anymore since HAProxy 2.1. Use 'option redispatch'.\n", file, linenum, args[0]); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2221 | |
Tim Duesterhus | dac168b | 2019-05-14 20:57:58 +0200 | [diff] [blame] | 2222 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2223 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2224 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2225 | else if (strcmp(args[0], "http-reuse") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2226 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2227 | err_code |= ERR_WARN; |
| 2228 | |
| 2229 | if (strcmp(args[1], "never") == 0) { |
| 2230 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2231 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2232 | curproxy->options |= PR_O_REUSE_NEVR; |
| 2233 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2234 | goto out; |
| 2235 | } |
| 2236 | else if (strcmp(args[1], "safe") == 0) { |
| 2237 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2238 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2239 | curproxy->options |= PR_O_REUSE_SAFE; |
| 2240 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2241 | goto out; |
| 2242 | } |
| 2243 | else if (strcmp(args[1], "aggressive") == 0) { |
| 2244 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2245 | curproxy->options |= PR_O_REUSE_AGGR; |
| 2246 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2247 | goto out; |
| 2248 | } |
| 2249 | else if (strcmp(args[1], "always") == 0) { |
| 2250 | /* enable a graceful server shutdown on an HTTP 404 response */ |
| 2251 | curproxy->options &= ~PR_O_REUSE_MASK; |
| 2252 | curproxy->options |= PR_O_REUSE_ALWS; |
| 2253 | if (alertif_too_many_args_idx(0, 1, file, linenum, args, &err_code)) |
| 2254 | goto out; |
| 2255 | } |
| 2256 | else { |
| 2257 | ha_alert("parsing [%s:%d] : '%s' only supports 'never', 'safe', 'aggressive', 'always'.\n", file, linenum, args[0]); |
| 2258 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2259 | goto out; |
| 2260 | } |
| 2261 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2262 | else if (strcmp(args[0], "monitor") == 0) { |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2263 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2264 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2265 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2266 | goto out; |
| 2267 | } |
| 2268 | |
| 2269 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2270 | err_code |= ERR_WARN; |
| 2271 | |
| 2272 | if (strcmp(args[1], "fail") == 0) { |
| 2273 | /* add a condition to fail monitor requests */ |
| 2274 | if (strcmp(args[2], "if") != 0 && strcmp(args[2], "unless") != 0) { |
| 2275 | ha_alert("parsing [%s:%d] : '%s %s' requires either 'if' or 'unless' followed by a condition.\n", |
| 2276 | file, linenum, args[0], args[1]); |
| 2277 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2278 | goto out; |
| 2279 | } |
| 2280 | |
| 2281 | err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail"); |
| 2282 | if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { |
| 2283 | ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", |
| 2284 | file, linenum, args[0], args[1], errmsg); |
| 2285 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2286 | goto out; |
| 2287 | } |
| 2288 | LIST_ADDQ(&curproxy->mon_fail_cond, &cond->list); |
| 2289 | } |
| 2290 | else { |
| 2291 | ha_alert("parsing [%s:%d] : '%s' only supports 'fail'.\n", file, linenum, args[0]); |
| 2292 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2293 | goto out; |
| 2294 | } |
| 2295 | } |
Willy Tarreau | e573323 | 2019-05-22 19:24:06 +0200 | [diff] [blame] | 2296 | #ifdef USE_TPROXY |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2297 | else if (strcmp(args[0], "transparent") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2298 | /* enable transparent proxy connections */ |
| 2299 | curproxy->options |= PR_O_TRANSP; |
| 2300 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 2301 | goto out; |
| 2302 | } |
| 2303 | #endif |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2304 | else if (strcmp(args[0], "maxconn") == 0) { /* maxconn */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2305 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?")) |
| 2306 | err_code |= ERR_WARN; |
| 2307 | |
| 2308 | if (*(args[1]) == 0) { |
| 2309 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2310 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2311 | goto out; |
| 2312 | } |
| 2313 | curproxy->maxconn = atol(args[1]); |
| 2314 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2315 | goto out; |
| 2316 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2317 | else if (strcmp(args[0], "backlog") == 0) { /* backlog */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2318 | if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL)) |
| 2319 | err_code |= ERR_WARN; |
| 2320 | |
| 2321 | if (*(args[1]) == 0) { |
| 2322 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2323 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2324 | goto out; |
| 2325 | } |
| 2326 | curproxy->backlog = atol(args[1]); |
| 2327 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2328 | goto out; |
| 2329 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2330 | else if (strcmp(args[0], "fullconn") == 0) { /* fullconn */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2331 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?")) |
| 2332 | err_code |= ERR_WARN; |
| 2333 | |
| 2334 | if (*(args[1]) == 0) { |
| 2335 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2336 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2337 | goto out; |
| 2338 | } |
| 2339 | curproxy->fullconn = atol(args[1]); |
| 2340 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2341 | goto out; |
| 2342 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2343 | else if (strcmp(args[0], "grace") == 0) { /* grace time (ms) */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2344 | if (*(args[1]) == 0) { |
| 2345 | ha_alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]); |
| 2346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2347 | goto out; |
| 2348 | } |
| 2349 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 2350 | if (err == PARSE_TIME_OVER) { |
| 2351 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to grace time, maximum value is 2147483647 ms (~24.8 days).\n", |
| 2352 | file, linenum, args[1]); |
| 2353 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2354 | goto out; |
| 2355 | } |
| 2356 | else if (err == PARSE_TIME_UNDER) { |
| 2357 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to grace time, minimum non-null value is 1 ms.\n", |
| 2358 | file, linenum, args[1]); |
| 2359 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2360 | goto out; |
| 2361 | } |
| 2362 | else if (err) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2363 | ha_alert("parsing [%s:%d] : unexpected character '%c' in grace time.\n", |
| 2364 | file, linenum, *err); |
| 2365 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2366 | goto out; |
| 2367 | } |
| 2368 | curproxy->grace = val; |
| 2369 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2370 | goto out; |
Willy Tarreau | ab0a519 | 2020-10-09 19:07:01 +0200 | [diff] [blame] | 2371 | |
| 2372 | ha_warning("parsing [%s:%d]: the '%s' is deprecated and will be removed in a future version.\n", |
| 2373 | file, linenum, args[0]); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2374 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2375 | else if (strcmp(args[0], "dispatch") == 0) { /* dispatch address */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2376 | struct sockaddr_storage *sk; |
| 2377 | int port1, port2; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2378 | |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2379 | if (curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2380 | ha_alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]); |
| 2381 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2382 | goto out; |
| 2383 | } |
| 2384 | else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2385 | err_code |= ERR_WARN; |
| 2386 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2387 | sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL, |
| 2388 | &errmsg, NULL, NULL, |
| 2389 | PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_STREAM | PA_O_XPRT | PA_O_CONNECT); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2390 | if (!sk) { |
| 2391 | ha_alert("parsing [%s:%d] : '%s' : %s\n", file, linenum, args[0], errmsg); |
| 2392 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2393 | goto out; |
| 2394 | } |
| 2395 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2396 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 2397 | goto out; |
| 2398 | |
| 2399 | curproxy->dispatch_addr = *sk; |
| 2400 | curproxy->options |= PR_O_DISPATCH; |
| 2401 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2402 | else if (strcmp(args[0], "balance") == 0) { /* set balancing with optional algorithm */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2403 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2404 | err_code |= ERR_WARN; |
| 2405 | |
| 2406 | if (backend_parse_balance((const char **)args + 1, &errmsg, curproxy) < 0) { |
| 2407 | ha_alert("parsing [%s:%d] : %s %s\n", file, linenum, args[0], errmsg); |
| 2408 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2409 | goto out; |
| 2410 | } |
| 2411 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2412 | else if (strcmp(args[0], "hash-type") == 0) { /* set hashing method */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2413 | /** |
| 2414 | * The syntax for hash-type config element is |
| 2415 | * hash-type {map-based|consistent} [[<algo>] avalanche] |
| 2416 | * |
| 2417 | * The default hash function is sdbm for map-based and sdbm+avalanche for consistent. |
| 2418 | */ |
| 2419 | curproxy->lbprm.algo &= ~(BE_LB_HASH_TYPE | BE_LB_HASH_FUNC | BE_LB_HASH_MOD); |
| 2420 | |
| 2421 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2422 | err_code |= ERR_WARN; |
| 2423 | |
| 2424 | if (strcmp(args[1], "consistent") == 0) { /* use consistent hashing */ |
| 2425 | curproxy->lbprm.algo |= BE_LB_HASH_CONS; |
| 2426 | } |
| 2427 | else if (strcmp(args[1], "map-based") == 0) { /* use map-based hashing */ |
| 2428 | curproxy->lbprm.algo |= BE_LB_HASH_MAP; |
| 2429 | } |
| 2430 | else if (strcmp(args[1], "avalanche") == 0) { |
| 2431 | ha_alert("parsing [%s:%d] : experimental feature '%s %s' is not supported anymore, please use '%s map-based sdbm avalanche' instead.\n", file, linenum, args[0], args[1], args[0]); |
| 2432 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2433 | goto out; |
| 2434 | } |
| 2435 | else { |
| 2436 | ha_alert("parsing [%s:%d] : '%s' only supports 'consistent' and 'map-based'.\n", file, linenum, args[0]); |
| 2437 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2438 | goto out; |
| 2439 | } |
| 2440 | |
| 2441 | /* set the hash function to use */ |
| 2442 | if (!*args[2]) { |
| 2443 | /* the default algo is sdbm */ |
| 2444 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 2445 | |
| 2446 | /* if consistent with no argument, then avalanche modifier is also applied */ |
| 2447 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) |
| 2448 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 2449 | } else { |
| 2450 | /* set the hash function */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2451 | if (strcmp(args[2], "sdbm") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2452 | curproxy->lbprm.algo |= BE_LB_HFCN_SDBM; |
| 2453 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2454 | else if (strcmp(args[2], "djb2") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2455 | curproxy->lbprm.algo |= BE_LB_HFCN_DJB2; |
| 2456 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2457 | else if (strcmp(args[2], "wt6") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2458 | curproxy->lbprm.algo |= BE_LB_HFCN_WT6; |
| 2459 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2460 | else if (strcmp(args[2], "crc32") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2461 | curproxy->lbprm.algo |= BE_LB_HFCN_CRC32; |
| 2462 | } |
| 2463 | else { |
| 2464 | ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]); |
| 2465 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2466 | goto out; |
| 2467 | } |
| 2468 | |
| 2469 | /* set the hash modifier */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2470 | if (strcmp(args[3], "avalanche") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2471 | curproxy->lbprm.algo |= BE_LB_HMOD_AVAL; |
| 2472 | } |
| 2473 | else if (*args[3]) { |
| 2474 | ha_alert("parsing [%s:%d] : '%s' only supports 'avalanche' as a modifier for hash functions.\n", file, linenum, args[0]); |
| 2475 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2476 | goto out; |
| 2477 | } |
| 2478 | } |
| 2479 | } |
| 2480 | else if (strcmp(args[0], "hash-balance-factor") == 0) { |
| 2481 | if (*(args[1]) == 0) { |
| 2482 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 2483 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2484 | goto out; |
| 2485 | } |
Willy Tarreau | 76e84f5 | 2019-01-14 16:50:58 +0100 | [diff] [blame] | 2486 | curproxy->lbprm.hash_balance_factor = atol(args[1]); |
| 2487 | if (curproxy->lbprm.hash_balance_factor != 0 && curproxy->lbprm.hash_balance_factor <= 100) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2488 | ha_alert("parsing [%s:%d] : '%s' must be 0 or greater than 100.\n", file, linenum, args[0]); |
| 2489 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2490 | goto out; |
| 2491 | } |
| 2492 | } |
| 2493 | else if (strcmp(args[0], "unique-id-format") == 0) { |
| 2494 | if (!*(args[1])) { |
| 2495 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2496 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2497 | goto out; |
| 2498 | } |
| 2499 | if (*(args[2])) { |
| 2500 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2501 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2502 | goto out; |
| 2503 | } |
| 2504 | free(curproxy->conf.uniqueid_format_string); |
| 2505 | curproxy->conf.uniqueid_format_string = strdup(args[1]); |
| 2506 | |
| 2507 | free(curproxy->conf.uif_file); |
| 2508 | curproxy->conf.uif_file = strdup(curproxy->conf.args.file); |
| 2509 | curproxy->conf.uif_line = curproxy->conf.args.line; |
| 2510 | } |
| 2511 | |
| 2512 | else if (strcmp(args[0], "unique-id-header") == 0) { |
Tim Duesterhus | 0643b0e | 2020-03-05 17:56:35 +0100 | [diff] [blame] | 2513 | char *copy; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2514 | if (!*(args[1])) { |
| 2515 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2516 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2517 | goto out; |
| 2518 | } |
Tim Duesterhus | 0643b0e | 2020-03-05 17:56:35 +0100 | [diff] [blame] | 2519 | copy = strdup(args[1]); |
| 2520 | if (copy == NULL) { |
| 2521 | ha_alert("parsing [%s:%d] : failed to allocate memory for unique-id-header\n", file, linenum); |
| 2522 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2523 | goto out; |
| 2524 | } |
| 2525 | |
| 2526 | istfree(&curproxy->header_unique_id); |
| 2527 | curproxy->header_unique_id = ist(copy); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | else if (strcmp(args[0], "log-format") == 0) { |
| 2531 | if (!*(args[1])) { |
| 2532 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2533 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2534 | goto out; |
| 2535 | } |
| 2536 | if (*(args[2])) { |
| 2537 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2538 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2539 | goto out; |
| 2540 | } |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2541 | if (curproxy->conf.logformat_string && curproxy->cap & PR_CAP_DEF) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2542 | char *oldlogformat = "log-format"; |
| 2543 | |
| 2544 | if (curproxy->conf.logformat_string == default_http_log_format) |
| 2545 | oldlogformat = "option httplog"; |
| 2546 | else if (curproxy->conf.logformat_string == default_tcp_log_format) |
| 2547 | oldlogformat = "option tcplog"; |
| 2548 | else if (curproxy->conf.logformat_string == clf_http_log_format) |
| 2549 | oldlogformat = "option httplog clf"; |
| 2550 | ha_warning("parsing [%s:%d]: 'log-format' overrides previous '%s' in 'defaults' section.\n", |
| 2551 | file, linenum, oldlogformat); |
| 2552 | } |
| 2553 | if (curproxy->conf.logformat_string != default_http_log_format && |
| 2554 | curproxy->conf.logformat_string != default_tcp_log_format && |
| 2555 | curproxy->conf.logformat_string != clf_http_log_format) |
| 2556 | free(curproxy->conf.logformat_string); |
| 2557 | curproxy->conf.logformat_string = strdup(args[1]); |
| 2558 | |
| 2559 | free(curproxy->conf.lfs_file); |
| 2560 | curproxy->conf.lfs_file = strdup(curproxy->conf.args.file); |
| 2561 | curproxy->conf.lfs_line = curproxy->conf.args.line; |
| 2562 | |
| 2563 | /* get a chance to improve log-format error reporting by |
| 2564 | * reporting the correct line-number when possible. |
| 2565 | */ |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2566 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2567 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format' directive is ignored in backends.\n", |
| 2568 | file, linenum, curproxy->id); |
| 2569 | err_code |= ERR_WARN; |
| 2570 | } |
| 2571 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2572 | else if (strcmp(args[0], "log-format-sd") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2573 | if (!*(args[1])) { |
| 2574 | ha_alert("parsing [%s:%d] : %s expects an argument.\n", file, linenum, args[0]); |
| 2575 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2576 | goto out; |
| 2577 | } |
| 2578 | if (*(args[2])) { |
| 2579 | ha_alert("parsing [%s:%d] : %s expects only one argument, don't forget to escape spaces!\n", file, linenum, args[0]); |
| 2580 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2581 | goto out; |
| 2582 | } |
| 2583 | |
| 2584 | if (curproxy->conf.logformat_sd_string != default_rfc5424_sd_log_format) |
| 2585 | free(curproxy->conf.logformat_sd_string); |
| 2586 | curproxy->conf.logformat_sd_string = strdup(args[1]); |
| 2587 | |
| 2588 | free(curproxy->conf.lfsd_file); |
| 2589 | curproxy->conf.lfsd_file = strdup(curproxy->conf.args.file); |
| 2590 | curproxy->conf.lfsd_line = curproxy->conf.args.line; |
| 2591 | |
| 2592 | /* get a chance to improve log-format-sd error reporting by |
| 2593 | * reporting the correct line-number when possible. |
| 2594 | */ |
Willy Tarreau | 5d095c2 | 2021-02-12 10:15:59 +0100 | [diff] [blame] | 2595 | if (!(curproxy->cap & PR_CAP_DEF) && !(curproxy->cap & PR_CAP_FE)) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2596 | ha_warning("parsing [%s:%d] : backend '%s' : 'log-format-sd' directive is ignored in backends.\n", |
| 2597 | file, linenum, curproxy->id); |
| 2598 | err_code |= ERR_WARN; |
| 2599 | } |
| 2600 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2601 | else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2602 | if (*(args[1]) == 0) { |
| 2603 | ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 2604 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2605 | goto out; |
| 2606 | } |
| 2607 | chunk_destroy(&curproxy->log_tag); |
Eric Salama | 7cea606 | 2020-10-02 11:58:19 +0200 | [diff] [blame] | 2608 | chunk_initlen(&curproxy->log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1])); |
| 2609 | if (b_orig(&curproxy->log_tag) == NULL) { |
| 2610 | chunk_destroy(&curproxy->log_tag); |
| 2611 | ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]); |
| 2612 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2613 | goto out; |
| 2614 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2615 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2616 | else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2617 | if (!parse_logsrv(args, &curproxy->logsrvs, (kwm == KWM_NO), &errmsg)) { |
| 2618 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 2619 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2620 | goto out; |
| 2621 | } |
| 2622 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2623 | else if (strcmp(args[0], "source") == 0) { /* address to which we bind when connecting */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2624 | int cur_arg; |
| 2625 | int port1, port2; |
| 2626 | struct sockaddr_storage *sk; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2627 | |
| 2628 | if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) |
| 2629 | err_code |= ERR_WARN; |
| 2630 | |
| 2631 | if (!*args[1]) { |
| 2632 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optionally '%s' <addr>, and '%s' <name>.\n", |
| 2633 | file, linenum, "source", "usesrc", "interface"); |
| 2634 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2635 | goto out; |
| 2636 | } |
| 2637 | |
Christopher Faulet | 3193037 | 2019-07-15 10:16:58 +0200 | [diff] [blame] | 2638 | /* we must first clear any optional default setting */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2639 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2640 | free(curproxy->conn_src.iface_name); |
| 2641 | curproxy->conn_src.iface_name = NULL; |
| 2642 | curproxy->conn_src.iface_len = 0; |
| 2643 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2644 | sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL, |
| 2645 | &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2646 | if (!sk) { |
| 2647 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 2648 | file, linenum, args[0], args[1], errmsg); |
| 2649 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2650 | goto out; |
| 2651 | } |
| 2652 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2653 | curproxy->conn_src.source_addr = *sk; |
| 2654 | curproxy->conn_src.opts |= CO_SRC_BIND; |
| 2655 | |
| 2656 | cur_arg = 2; |
| 2657 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2658 | if (strcmp(args[cur_arg], "usesrc") == 0) { /* address to use outside */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2659 | #if defined(CONFIG_HAP_TRANSPARENT) |
| 2660 | if (!*args[cur_arg + 1]) { |
| 2661 | ha_alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n", |
| 2662 | file, linenum, "usesrc"); |
| 2663 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2664 | goto out; |
| 2665 | } |
| 2666 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2667 | if (strcmp(args[cur_arg + 1], "client") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2668 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2669 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CLI; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2670 | } else if (strcmp(args[cur_arg + 1], "clientip") == 0) { |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2671 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2672 | curproxy->conn_src.opts |= CO_SRC_TPROXY_CIP; |
| 2673 | } else if (!strncmp(args[cur_arg + 1], "hdr_ip(", 7)) { |
| 2674 | char *name, *end; |
| 2675 | |
| 2676 | name = args[cur_arg+1] + 7; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2677 | while (isspace((unsigned char)*name)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2678 | name++; |
| 2679 | |
| 2680 | end = name; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2681 | while (*end && !isspace((unsigned char)*end) && *end != ',' && *end != ')') |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2682 | end++; |
| 2683 | |
| 2684 | curproxy->conn_src.opts &= ~CO_SRC_TPROXY_MASK; |
| 2685 | curproxy->conn_src.opts |= CO_SRC_TPROXY_DYN; |
Amaury Denoyelle | 69c5c3a | 2021-01-26 14:35:22 +0100 | [diff] [blame] | 2686 | free(curproxy->conn_src.bind_hdr_name); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2687 | curproxy->conn_src.bind_hdr_name = calloc(1, end - name + 1); |
| 2688 | curproxy->conn_src.bind_hdr_len = end - name; |
| 2689 | memcpy(curproxy->conn_src.bind_hdr_name, name, end - name); |
| 2690 | curproxy->conn_src.bind_hdr_name[end-name] = '\0'; |
| 2691 | curproxy->conn_src.bind_hdr_occ = -1; |
| 2692 | |
| 2693 | /* now look for an occurrence number */ |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2694 | while (isspace((unsigned char)*end)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2695 | end++; |
| 2696 | if (*end == ',') { |
| 2697 | end++; |
| 2698 | name = end; |
| 2699 | if (*end == '-') |
| 2700 | end++; |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 2701 | while (isdigit((unsigned char)*end)) |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2702 | end++; |
| 2703 | curproxy->conn_src.bind_hdr_occ = strl2ic(name, end-name); |
| 2704 | } |
| 2705 | |
| 2706 | if (curproxy->conn_src.bind_hdr_occ < -MAX_HDR_HISTORY) { |
| 2707 | ha_alert("parsing [%s:%d] : usesrc hdr_ip(name,num) does not support negative" |
| 2708 | " occurrences values smaller than %d.\n", |
| 2709 | file, linenum, MAX_HDR_HISTORY); |
| 2710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2711 | goto out; |
| 2712 | } |
| 2713 | } else { |
| 2714 | struct sockaddr_storage *sk; |
| 2715 | |
Willy Tarreau | 65ec4e3 | 2020-09-16 19:17:08 +0200 | [diff] [blame] | 2716 | sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL, |
| 2717 | &errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2718 | if (!sk) { |
| 2719 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", |
| 2720 | file, linenum, args[cur_arg], args[cur_arg+1], errmsg); |
| 2721 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2722 | goto out; |
| 2723 | } |
| 2724 | |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2725 | curproxy->conn_src.tproxy_addr = *sk; |
| 2726 | curproxy->conn_src.opts |= CO_SRC_TPROXY_ADDR; |
| 2727 | } |
| 2728 | global.last_checks |= LSTCHK_NETADM; |
| 2729 | #else /* no TPROXY support */ |
| 2730 | ha_alert("parsing [%s:%d] : '%s' not allowed here because support for TPROXY was not compiled in.\n", |
| 2731 | file, linenum, "usesrc"); |
| 2732 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2733 | goto out; |
| 2734 | #endif |
| 2735 | cur_arg += 2; |
| 2736 | continue; |
| 2737 | } |
| 2738 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2739 | if (strcmp(args[cur_arg], "interface") == 0) { /* specifically bind to this interface */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2740 | #ifdef SO_BINDTODEVICE |
| 2741 | if (!*args[cur_arg + 1]) { |
| 2742 | ha_alert("parsing [%s:%d] : '%s' : missing interface name.\n", |
| 2743 | file, linenum, args[0]); |
| 2744 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2745 | goto out; |
| 2746 | } |
| 2747 | free(curproxy->conn_src.iface_name); |
| 2748 | curproxy->conn_src.iface_name = strdup(args[cur_arg + 1]); |
| 2749 | curproxy->conn_src.iface_len = strlen(curproxy->conn_src.iface_name); |
| 2750 | global.last_checks |= LSTCHK_NETADM; |
| 2751 | #else |
| 2752 | ha_alert("parsing [%s:%d] : '%s' : '%s' option not implemented.\n", |
| 2753 | file, linenum, args[0], args[cur_arg]); |
| 2754 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2755 | goto out; |
| 2756 | #endif |
| 2757 | cur_arg += 2; |
| 2758 | continue; |
| 2759 | } |
| 2760 | ha_alert("parsing [%s:%d] : '%s' only supports optional keywords '%s' and '%s'.\n", |
| 2761 | file, linenum, args[0], "interface", "usesrc"); |
| 2762 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2763 | goto out; |
| 2764 | } |
| 2765 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2766 | else if (strcmp(args[0], "usesrc") == 0) { /* address to use outside: needs "source" first */ |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2767 | ha_alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n", |
| 2768 | file, linenum, "usesrc", "source"); |
| 2769 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2770 | goto out; |
| 2771 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2772 | else if (strcmp(args[0], "cliexp") == 0 || strcmp(args[0], "reqrep") == 0) { /* replace request header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2773 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
Willy Tarreau | 262c3f1 | 2019-12-17 06:52:51 +0100 | [diff] [blame] | 2774 | "Use 'http-request replace-path', 'http-request replace-uri' or 'http-request replace-header' instead.\n", |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2775 | file, linenum, args[0]); |
| 2776 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2777 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2778 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2779 | else if (strcmp(args[0], "reqdel") == 0) { /* delete request header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2780 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2781 | "Use 'http-request del-header' instead.\n", file, linenum, args[0]); |
| 2782 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2783 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2784 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2785 | else if (strcmp(args[0], "reqdeny") == 0) { /* deny a request if a header matches this regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2786 | ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1. " |
| 2787 | "Use 'http-request deny' instead.\n", file, linenum, args[0]); |
| 2788 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2789 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2790 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2791 | else if (strcmp(args[0], "reqpass") == 0) { /* pass this header without allowing or denying the request */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2792 | ha_alert("parsing [%s:%d] : The '%s' not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]); |
| 2793 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2794 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2795 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2796 | else if (strcmp(args[0], "reqallow") == 0) { /* allow a request if a header matches this regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2797 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2798 | "Use 'http-request allow' instead.\n", file, linenum, args[0]); |
| 2799 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2800 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2801 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2802 | else if (strcmp(args[0], "reqtarpit") == 0) { /* tarpit a request if a header matches this regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2803 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2804 | "Use 'http-request tarpit' instead.\n", file, linenum, args[0]); |
| 2805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2806 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2807 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2808 | else if (strcmp(args[0], "reqirep") == 0) { /* replace request header from a regex, ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2809 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2810 | "Use 'http-request replace-header' instead.\n", file, linenum, args[0]); |
| 2811 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2812 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2813 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2814 | else if (strcmp(args[0], "reqidel") == 0) { /* delete request header from a regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2815 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2816 | "Use 'http-request del-header' instead.\n", file, linenum, args[0]); |
| 2817 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2818 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2819 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2820 | else if (strcmp(args[0], "reqideny") == 0) { /* deny a request if a header matches this regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2821 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2822 | "Use 'http-request deny' instead.\n", file, linenum, args[0]); |
| 2823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2824 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2825 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2826 | else if (strcmp(args[0], "reqipass") == 0) { /* pass this header without allowing or denying the request */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2827 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1.\n", file, linenum, args[0]); |
| 2828 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2829 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2830 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2831 | else if (strcmp(args[0], "reqiallow") == 0) { /* allow a request if a header matches this regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2832 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2833 | "Use 'http-request allow' instead.\n", file, linenum, args[0]); |
| 2834 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2835 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2836 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2837 | else if (strcmp(args[0], "reqitarpit") == 0) { /* tarpit a request if a header matches this regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2838 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2839 | "Use 'http-request tarpit' instead.\n", file, linenum, args[0]); |
| 2840 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2841 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2842 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2843 | else if (strcmp(args[0], "reqadd") == 0) { /* add request header */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2844 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2845 | "Use 'http-request add-header' instead.\n", file, linenum, args[0]); |
| 2846 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2847 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2848 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2849 | else if (strcmp(args[0], "srvexp") == 0 || strcmp(args[0], "rsprep") == 0) { /* replace response header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2850 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2851 | "Use 'http-response replace-header' instead.\n", file, linenum, args[0]); |
| 2852 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2853 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2854 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2855 | else if (strcmp(args[0], "rspdel") == 0) { /* delete response header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2856 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2857 | "Use 'http-response del-header' .\n", file, linenum, args[0]); |
| 2858 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2859 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2860 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2861 | else if (strcmp(args[0], "rspdeny") == 0) { /* block response header from a regex */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2862 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2863 | "Use 'http-response deny' instead.\n", file, linenum, args[0]); |
| 2864 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2865 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2866 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2867 | else if (strcmp(args[0], "rspirep") == 0) { /* replace response header from a regex ignoring case */ |
Balvinder Singh Rawat | def595e | 2020-03-14 12:11:50 +0530 | [diff] [blame] | 2868 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2869 | "Use 'http-response replace-header' instead.\n", file, linenum, args[0]); |
| 2870 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2871 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2872 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2873 | else if (strcmp(args[0], "rspidel") == 0) { /* delete response header from a regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2874 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2875 | "Use 'http-response del-header' instead.\n", file, linenum, args[0]); |
| 2876 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2877 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2878 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2879 | else if (strcmp(args[0], "rspideny") == 0) { /* block response header from a regex ignoring case */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2880 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2881 | "Use 'http-response deny' instead.\n", file, linenum, args[0]); |
| 2882 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2883 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2884 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 2885 | else if (strcmp(args[0], "rspadd") == 0) { /* add response header */ |
Christopher Faulet | a6a56e6 | 2019-07-17 15:13:28 +0200 | [diff] [blame] | 2886 | ha_alert("parsing [%s:%d] : The '%s' directive is not supported anymore since HAProxy 2.1. " |
| 2887 | "Use 'http-response add-header' instead.\n", file, linenum, args[0]); |
| 2888 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2889 | goto out; |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2890 | } |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2891 | else { |
| 2892 | struct cfg_kw_list *kwl; |
| 2893 | int index; |
| 2894 | |
| 2895 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 2896 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 2897 | if (kwl->kw[index].section != CFG_LISTEN) |
| 2898 | continue; |
| 2899 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
| 2900 | /* prepare error message just in case */ |
Willy Tarreau | ab3410c | 2021-02-12 12:17:30 +0100 | [diff] [blame] | 2901 | rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg); |
Willy Tarreau | 3a1f5fd | 2018-11-11 15:40:36 +0100 | [diff] [blame] | 2902 | if (rc < 0) { |
| 2903 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 2904 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2905 | goto out; |
| 2906 | } |
| 2907 | else if (rc > 0) { |
| 2908 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 2909 | err_code |= ERR_WARN; |
| 2910 | goto out; |
| 2911 | } |
| 2912 | goto out; |
| 2913 | } |
| 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
| 2918 | err_code |= ERR_ALERT | ERR_FATAL; |
| 2919 | goto out; |
| 2920 | } |
| 2921 | out: |
| 2922 | free(errmsg); |
| 2923 | return err_code; |
| 2924 | } |