Amaury Denoyelle | fc6ac53 | 2021-04-27 10:46:36 +0200 | [diff] [blame] | 1 | #define _GNU_SOURCE /* for cpu_set_t from haproxy/cpuset.h */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
| 5 | #include <netdb.h> |
| 6 | #include <ctype.h> |
| 7 | #include <pwd.h> |
| 8 | #include <grp.h> |
| 9 | #include <errno.h> |
| 10 | #include <sys/types.h> |
| 11 | #include <sys/stat.h> |
| 12 | #include <fcntl.h> |
| 13 | #include <unistd.h> |
| 14 | |
Eric Salama | 7cea606 | 2020-10-02 11:58:19 +0200 | [diff] [blame] | 15 | #include <haproxy/buf.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 16 | #include <haproxy/cfgparse.h> |
Amaury Denoyelle | a6f9c5d | 2021-04-23 16:58:08 +0200 | [diff] [blame] | 17 | #ifdef USE_CPU_AFFINITY |
Amaury Denoyelle | c90932b | 2021-04-14 16:16:03 +0200 | [diff] [blame] | 18 | #include <haproxy/cpuset.h> |
Amaury Denoyelle | a6f9c5d | 2021-04-23 16:58:08 +0200 | [diff] [blame] | 19 | #endif |
Willy Tarreau | 0a3bd39 | 2020-06-04 08:52:38 +0200 | [diff] [blame] | 20 | #include <haproxy/compression.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 21 | #include <haproxy/global.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 22 | #include <haproxy/log.h> |
Dragan Dosen | 13cd54c | 2020-06-18 18:24:05 +0200 | [diff] [blame] | 23 | #include <haproxy/peers.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 24 | #include <haproxy/tools.h> |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 25 | |
Willy Tarreau | a0e8eb8 | 2021-03-12 09:30:14 +0100 | [diff] [blame] | 26 | /* some keywords that are still being parsed using strcmp() and are not |
| 27 | * registered anywhere. They are used as suggestions for mistyped words. |
| 28 | */ |
| 29 | static const char *common_kw_list[] = { |
| 30 | "global", "daemon", "master-worker", "noepoll", "nokqueue", |
| 31 | "noevports", "nopoll", "busy-polling", "set-dumpable", |
| 32 | "insecure-fork-wanted", "insecure-setuid-wanted", "nosplice", |
| 33 | "nogetaddrinfo", "noreuseport", "quiet", "zero-warning", |
| 34 | "tune.runqueue-depth", "tune.maxpollevents", "tune.maxaccept", |
Willy Tarreau | eb9d90a | 2021-06-11 15:29:31 +0200 | [diff] [blame] | 35 | "tune.recv_enough", "tune.buffers.limit", |
Willy Tarreau | a0e8eb8 | 2021-03-12 09:30:14 +0100 | [diff] [blame] | 36 | "tune.buffers.reserve", "tune.bufsize", "tune.maxrewrite", |
| 37 | "tune.idletimer", "tune.rcvbuf.client", "tune.rcvbuf.server", |
| 38 | "tune.sndbuf.client", "tune.sndbuf.server", "tune.pipesize", |
| 39 | "tune.http.cookielen", "tune.http.logurilen", "tune.http.maxhdr", |
| 40 | "tune.comp.maxlevel", "tune.pattern.cache-size", "uid", "gid", |
Willy Tarreau | 51ec03a | 2021-09-22 11:55:22 +0200 | [diff] [blame] | 41 | "external-check", "user", "group", "nbproc", "maxconn", |
Willy Tarreau | a0e8eb8 | 2021-03-12 09:30:14 +0100 | [diff] [blame] | 42 | "ssl-server-verify", "maxconnrate", "maxsessrate", "maxsslrate", |
| 43 | "maxcomprate", "maxpipes", "maxzlibmem", "maxcompcpuusage", "ulimit-n", |
| 44 | "chroot", "description", "node", "pidfile", "unix-bind", "log", |
| 45 | "log-send-hostname", "server-state-base", "server-state-file", |
| 46 | "log-tag", "spread-checks", "max-spread-checks", "cpu-map", "setenv", |
| 47 | "presetenv", "unsetenv", "resetenv", "strict-limits", "localpeer", |
Amaury Denoyelle | 0f50cb9 | 2021-03-26 18:50:33 +0100 | [diff] [blame] | 48 | "numa-cpu-mapping", "defaults", "listen", "frontend", "backend", |
| 49 | "peers", "resolvers", |
Willy Tarreau | a0e8eb8 | 2021-03-12 09:30:14 +0100 | [diff] [blame] | 50 | NULL /* must be last */ |
| 51 | }; |
| 52 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 53 | /* |
| 54 | * parse a line in a <global> section. Returns the error code, 0 if OK, or |
| 55 | * any combination of : |
| 56 | * - ERR_ABORT: must abort ASAP |
| 57 | * - ERR_FATAL: we can continue parsing but not start the service |
| 58 | * - ERR_WARN: a warning has been emitted |
| 59 | * - ERR_ALERT: an alert has been emitted |
| 60 | * Only the two first ones can stop processing, the two others are just |
| 61 | * indicators. |
| 62 | */ |
| 63 | int cfg_parse_global(const char *file, int linenum, char **args, int kwm) |
| 64 | { |
| 65 | int err_code = 0; |
| 66 | char *errmsg = NULL; |
| 67 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 68 | if (strcmp(args[0], "global") == 0) { /* new section */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 69 | /* no option, nothing special to do */ |
| 70 | alertif_too_many_args(0, file, linenum, args, &err_code); |
| 71 | goto out; |
| 72 | } |
Amaury Denoyelle | d2e53cd | 2021-05-06 16:21:39 +0200 | [diff] [blame] | 73 | else if (strcmp(args[0], "expose-experimental-directives") == 0) { |
| 74 | experimental_directives_allowed = 1; |
| 75 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 76 | else if (strcmp(args[0], "daemon") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 77 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 78 | goto out; |
| 79 | global.mode |= MODE_DAEMON; |
| 80 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 81 | else if (strcmp(args[0], "master-worker") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 82 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 83 | goto out; |
| 84 | if (*args[1]) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 85 | if (strcmp(args[1], "no-exit-on-failure") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 86 | global.tune.options |= GTUNE_NOEXIT_ONFAILURE; |
| 87 | } else { |
| 88 | ha_alert("parsing [%s:%d] : '%s' only supports 'no-exit-on-failure' option.\n", file, linenum, args[0]); |
| 89 | err_code |= ERR_ALERT | ERR_FATAL; |
| 90 | goto out; |
| 91 | } |
| 92 | } |
| 93 | global.mode |= MODE_MWORKER; |
| 94 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 95 | else if (strcmp(args[0], "noepoll") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 96 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 97 | goto out; |
| 98 | global.tune.options &= ~GTUNE_USE_EPOLL; |
| 99 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 100 | else if (strcmp(args[0], "nokqueue") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 101 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 102 | goto out; |
| 103 | global.tune.options &= ~GTUNE_USE_KQUEUE; |
| 104 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 105 | else if (strcmp(args[0], "noevports") == 0) { |
Emmanuel Hocdet | 0ba4f48 | 2019-04-08 16:53:32 +0000 | [diff] [blame] | 106 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 107 | goto out; |
| 108 | global.tune.options &= ~GTUNE_USE_EVPORTS; |
| 109 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 110 | else if (strcmp(args[0], "nopoll") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 111 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 112 | goto out; |
| 113 | global.tune.options &= ~GTUNE_USE_POLL; |
| 114 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 115 | else if (strcmp(args[0], "busy-polling") == 0) { /* "no busy-polling" or "busy-polling" */ |
Willy Tarreau | beb859a | 2018-11-22 18:07:59 +0100 | [diff] [blame] | 116 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 117 | goto out; |
| 118 | if (kwm == KWM_NO) |
| 119 | global.tune.options &= ~GTUNE_BUSY_POLLING; |
| 120 | else |
| 121 | global.tune.options |= GTUNE_BUSY_POLLING; |
| 122 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 123 | else if (strcmp(args[0], "set-dumpable") == 0) { /* "no set-dumpable" or "set-dumpable" */ |
Willy Tarreau | 636848a | 2019-04-15 19:38:50 +0200 | [diff] [blame] | 124 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 125 | goto out; |
| 126 | if (kwm == KWM_NO) |
| 127 | global.tune.options &= ~GTUNE_SET_DUMPABLE; |
| 128 | else |
| 129 | global.tune.options |= GTUNE_SET_DUMPABLE; |
| 130 | } |
Amaury Denoyelle | befeae8 | 2021-07-09 17:14:30 +0200 | [diff] [blame] | 131 | else if (strcmp(args[0], "h2-workaround-bogus-websocket-clients") == 0) { /* "no h2-workaround-bogus-websocket-clients" or "h2-workaround-bogus-websocket-clients" */ |
| 132 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 133 | goto out; |
| 134 | if (kwm == KWM_NO) |
| 135 | global.tune.options &= ~GTUNE_DISABLE_H2_WEBSOCKET; |
| 136 | else |
| 137 | global.tune.options |= GTUNE_DISABLE_H2_WEBSOCKET; |
| 138 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 139 | else if (strcmp(args[0], "insecure-fork-wanted") == 0) { /* "no insecure-fork-wanted" or "insecure-fork-wanted" */ |
Willy Tarreau | d96f112 | 2019-12-03 07:07:36 +0100 | [diff] [blame] | 140 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 141 | goto out; |
| 142 | if (kwm == KWM_NO) |
| 143 | global.tune.options &= ~GTUNE_INSECURE_FORK; |
| 144 | else |
| 145 | global.tune.options |= GTUNE_INSECURE_FORK; |
| 146 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 147 | else if (strcmp(args[0], "insecure-setuid-wanted") == 0) { /* "no insecure-setuid-wanted" or "insecure-setuid-wanted" */ |
Willy Tarreau | a45a8b5 | 2019-12-06 16:31:45 +0100 | [diff] [blame] | 148 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 149 | goto out; |
| 150 | if (kwm == KWM_NO) |
| 151 | global.tune.options &= ~GTUNE_INSECURE_SETUID; |
| 152 | else |
| 153 | global.tune.options |= GTUNE_INSECURE_SETUID; |
| 154 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 155 | else if (strcmp(args[0], "nosplice") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 156 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 157 | goto out; |
| 158 | global.tune.options &= ~GTUNE_USE_SPLICE; |
| 159 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 160 | else if (strcmp(args[0], "nogetaddrinfo") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 161 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 162 | goto out; |
| 163 | global.tune.options &= ~GTUNE_USE_GAI; |
| 164 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 165 | else if (strcmp(args[0], "noreuseport") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 166 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 167 | goto out; |
| 168 | global.tune.options &= ~GTUNE_USE_REUSEPORT; |
| 169 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 170 | else if (strcmp(args[0], "quiet") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 171 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 172 | goto out; |
| 173 | global.mode |= MODE_QUIET; |
| 174 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 175 | else if (strcmp(args[0], "zero-warning") == 0) { |
Willy Tarreau | 3eb10b8 | 2020-04-15 16:42:39 +0200 | [diff] [blame] | 176 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 177 | goto out; |
| 178 | global.mode |= MODE_ZERO_WARNING; |
| 179 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 180 | else if (strcmp(args[0], "tune.runqueue-depth") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 181 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 182 | goto out; |
| 183 | if (global.tune.runqueue_depth != 0) { |
| 184 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 185 | err_code |= ERR_ALERT; |
| 186 | goto out; |
| 187 | } |
| 188 | if (*(args[1]) == 0) { |
| 189 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 190 | err_code |= ERR_ALERT | ERR_FATAL; |
| 191 | goto out; |
| 192 | } |
| 193 | global.tune.runqueue_depth = atol(args[1]); |
| 194 | |
| 195 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 196 | else if (strcmp(args[0], "tune.maxpollevents") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 197 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 198 | goto out; |
| 199 | if (global.tune.maxpollevents != 0) { |
| 200 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 201 | err_code |= ERR_ALERT; |
| 202 | goto out; |
| 203 | } |
| 204 | if (*(args[1]) == 0) { |
| 205 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 206 | err_code |= ERR_ALERT | ERR_FATAL; |
| 207 | goto out; |
| 208 | } |
| 209 | global.tune.maxpollevents = atol(args[1]); |
| 210 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 211 | else if (strcmp(args[0], "tune.maxaccept") == 0) { |
Christopher Faulet | 6b02ab8 | 2019-04-30 14:03:56 +0200 | [diff] [blame] | 212 | long max; |
| 213 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 214 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 215 | goto out; |
| 216 | if (global.tune.maxaccept != 0) { |
| 217 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 218 | err_code |= ERR_ALERT; |
| 219 | goto out; |
| 220 | } |
| 221 | if (*(args[1]) == 0) { |
| 222 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 223 | err_code |= ERR_ALERT | ERR_FATAL; |
| 224 | goto out; |
| 225 | } |
Christopher Faulet | 6b02ab8 | 2019-04-30 14:03:56 +0200 | [diff] [blame] | 226 | max = atol(args[1]); |
| 227 | if (/*max < -1 || */max > INT_MAX) { |
| 228 | ha_alert("parsing [%s:%d] : '%s' expects -1 or an integer from 0 to INT_MAX.\n", file, linenum, args[0]); |
| 229 | err_code |= ERR_ALERT | ERR_FATAL; |
| 230 | goto out; |
| 231 | } |
| 232 | global.tune.maxaccept = max; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 233 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 234 | else if (strcmp(args[0], "tune.chksize") == 0) { |
Willy Tarreau | eb9d90a | 2021-06-11 15:29:31 +0200 | [diff] [blame] | 235 | ha_alert("parsing [%s:%d]: option '%s' is not supported any more (tune.bufsize is used instead).\n", file, linenum, args[0]); |
| 236 | err_code |= ERR_ALERT | ERR_FATAL; |
| 237 | goto out; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 238 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 239 | else if (strcmp(args[0], "tune.recv_enough") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 240 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 241 | goto out; |
| 242 | if (*(args[1]) == 0) { |
| 243 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 245 | goto out; |
| 246 | } |
| 247 | global.tune.recv_enough = atol(args[1]); |
| 248 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 249 | else if (strcmp(args[0], "tune.buffers.limit") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 250 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 251 | goto out; |
| 252 | if (*(args[1]) == 0) { |
| 253 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 254 | err_code |= ERR_ALERT | ERR_FATAL; |
| 255 | goto out; |
| 256 | } |
| 257 | global.tune.buf_limit = atol(args[1]); |
| 258 | if (global.tune.buf_limit) { |
| 259 | if (global.tune.buf_limit < 3) |
| 260 | global.tune.buf_limit = 3; |
| 261 | if (global.tune.buf_limit <= global.tune.reserved_bufs) |
| 262 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 263 | } |
| 264 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 265 | else if (strcmp(args[0], "tune.buffers.reserve") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 266 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 267 | goto out; |
| 268 | if (*(args[1]) == 0) { |
| 269 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 270 | err_code |= ERR_ALERT | ERR_FATAL; |
| 271 | goto out; |
| 272 | } |
| 273 | global.tune.reserved_bufs = atol(args[1]); |
| 274 | if (global.tune.reserved_bufs < 2) |
| 275 | global.tune.reserved_bufs = 2; |
| 276 | if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs) |
| 277 | global.tune.buf_limit = global.tune.reserved_bufs + 1; |
| 278 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 279 | else if (strcmp(args[0], "tune.bufsize") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 280 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 281 | goto out; |
| 282 | if (*(args[1]) == 0) { |
| 283 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 284 | err_code |= ERR_ALERT | ERR_FATAL; |
| 285 | goto out; |
| 286 | } |
| 287 | global.tune.bufsize = atol(args[1]); |
Willy Tarreau | c77d364 | 2018-12-12 06:19:42 +0100 | [diff] [blame] | 288 | /* round it up to support a two-pointer alignment at the end */ |
| 289 | global.tune.bufsize = (global.tune.bufsize + 2 * sizeof(void *) - 1) & -(2 * sizeof(void *)); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 290 | if (global.tune.bufsize <= 0) { |
| 291 | ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 292 | err_code |= ERR_ALERT | ERR_FATAL; |
| 293 | goto out; |
| 294 | } |
| 295 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 296 | else if (strcmp(args[0], "tune.maxrewrite") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 297 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 298 | goto out; |
| 299 | if (*(args[1]) == 0) { |
| 300 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 301 | err_code |= ERR_ALERT | ERR_FATAL; |
| 302 | goto out; |
| 303 | } |
| 304 | global.tune.maxrewrite = atol(args[1]); |
| 305 | if (global.tune.maxrewrite < 0) { |
| 306 | ha_alert("parsing [%s:%d] : '%s' expects a positive integer argument.\n", file, linenum, args[0]); |
| 307 | err_code |= ERR_ALERT | ERR_FATAL; |
| 308 | goto out; |
| 309 | } |
| 310 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 311 | else if (strcmp(args[0], "tune.idletimer") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 312 | unsigned int idle; |
| 313 | const char *res; |
| 314 | |
| 315 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 316 | goto out; |
| 317 | if (*(args[1]) == 0) { |
| 318 | ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 319 | err_code |= ERR_ALERT | ERR_FATAL; |
| 320 | goto out; |
| 321 | } |
| 322 | |
| 323 | res = parse_time_err(args[1], &idle, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 324 | if (res == PARSE_TIME_OVER) { |
| 325 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 65535 ms.\n", |
| 326 | file, linenum, args[1], args[0]); |
| 327 | err_code |= ERR_ALERT | ERR_FATAL; |
| 328 | goto out; |
| 329 | } |
| 330 | else if (res == PARSE_TIME_UNDER) { |
| 331 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n", |
| 332 | file, linenum, args[1], args[0]); |
| 333 | err_code |= ERR_ALERT | ERR_FATAL; |
| 334 | goto out; |
| 335 | } |
| 336 | else if (res) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 337 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s>.\n", |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 338 | file, linenum, *res, args[0]); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 339 | err_code |= ERR_ALERT | ERR_FATAL; |
| 340 | goto out; |
| 341 | } |
| 342 | |
| 343 | if (idle > 65535) { |
| 344 | ha_alert("parsing [%s:%d] : '%s' expects a timer value between 0 and 65535 ms.\n", file, linenum, args[0]); |
| 345 | err_code |= ERR_ALERT | ERR_FATAL; |
| 346 | goto out; |
| 347 | } |
| 348 | global.tune.idle_timer = idle; |
| 349 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 350 | else if (strcmp(args[0], "tune.rcvbuf.client") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 351 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 352 | goto out; |
| 353 | if (global.tune.client_rcvbuf != 0) { |
| 354 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 355 | err_code |= ERR_ALERT; |
| 356 | goto out; |
| 357 | } |
| 358 | if (*(args[1]) == 0) { |
| 359 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 361 | goto out; |
| 362 | } |
| 363 | global.tune.client_rcvbuf = atol(args[1]); |
| 364 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 365 | else if (strcmp(args[0], "tune.rcvbuf.server") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 366 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 367 | goto out; |
| 368 | if (global.tune.server_rcvbuf != 0) { |
| 369 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 370 | err_code |= ERR_ALERT; |
| 371 | goto out; |
| 372 | } |
| 373 | if (*(args[1]) == 0) { |
| 374 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 375 | err_code |= ERR_ALERT | ERR_FATAL; |
| 376 | goto out; |
| 377 | } |
| 378 | global.tune.server_rcvbuf = atol(args[1]); |
| 379 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 380 | else if (strcmp(args[0], "tune.sndbuf.client") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 381 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 382 | goto out; |
| 383 | if (global.tune.client_sndbuf != 0) { |
| 384 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 385 | err_code |= ERR_ALERT; |
| 386 | goto out; |
| 387 | } |
| 388 | if (*(args[1]) == 0) { |
| 389 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 390 | err_code |= ERR_ALERT | ERR_FATAL; |
| 391 | goto out; |
| 392 | } |
| 393 | global.tune.client_sndbuf = atol(args[1]); |
| 394 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 395 | else if (strcmp(args[0], "tune.sndbuf.server") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 396 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 397 | goto out; |
| 398 | if (global.tune.server_sndbuf != 0) { |
| 399 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 400 | err_code |= ERR_ALERT; |
| 401 | goto out; |
| 402 | } |
| 403 | if (*(args[1]) == 0) { |
| 404 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 405 | err_code |= ERR_ALERT | ERR_FATAL; |
| 406 | goto out; |
| 407 | } |
| 408 | global.tune.server_sndbuf = atol(args[1]); |
| 409 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 410 | else if (strcmp(args[0], "tune.pipesize") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 411 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 412 | goto out; |
| 413 | if (*(args[1]) == 0) { |
| 414 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 415 | err_code |= ERR_ALERT | ERR_FATAL; |
| 416 | goto out; |
| 417 | } |
| 418 | global.tune.pipesize = atol(args[1]); |
| 419 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 420 | else if (strcmp(args[0], "tune.http.cookielen") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 421 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 422 | goto out; |
| 423 | if (*(args[1]) == 0) { |
| 424 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 425 | err_code |= ERR_ALERT | ERR_FATAL; |
| 426 | goto out; |
| 427 | } |
| 428 | global.tune.cookie_len = atol(args[1]) + 1; |
| 429 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 430 | else if (strcmp(args[0], "tune.http.logurilen") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 431 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 432 | goto out; |
| 433 | if (*(args[1]) == 0) { |
| 434 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 435 | err_code |= ERR_ALERT | ERR_FATAL; |
| 436 | goto out; |
| 437 | } |
| 438 | global.tune.requri_len = atol(args[1]) + 1; |
| 439 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 440 | else if (strcmp(args[0], "tune.http.maxhdr") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 441 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 442 | goto out; |
| 443 | if (*(args[1]) == 0) { |
| 444 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 445 | err_code |= ERR_ALERT | ERR_FATAL; |
| 446 | goto out; |
| 447 | } |
| 448 | global.tune.max_http_hdr = atoi(args[1]); |
| 449 | if (global.tune.max_http_hdr < 1 || global.tune.max_http_hdr > 32767) { |
| 450 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 32767\n", |
| 451 | file, linenum, args[0]); |
| 452 | err_code |= ERR_ALERT | ERR_FATAL; |
| 453 | goto out; |
| 454 | } |
| 455 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 456 | else if (strcmp(args[0], "tune.comp.maxlevel") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 457 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 458 | goto out; |
| 459 | if (*args[1]) { |
| 460 | global.tune.comp_maxlevel = atoi(args[1]); |
| 461 | if (global.tune.comp_maxlevel < 1 || global.tune.comp_maxlevel > 9) { |
| 462 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 463 | file, linenum, args[0]); |
| 464 | err_code |= ERR_ALERT | ERR_FATAL; |
| 465 | goto out; |
| 466 | } |
| 467 | } else { |
| 468 | ha_alert("parsing [%s:%d] : '%s' expects a numeric value between 1 and 9\n", |
| 469 | file, linenum, args[0]); |
| 470 | err_code |= ERR_ALERT | ERR_FATAL; |
| 471 | goto out; |
| 472 | } |
| 473 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 474 | else if (strcmp(args[0], "tune.pattern.cache-size") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 475 | if (*args[1]) { |
| 476 | global.tune.pattern_cache = atoi(args[1]); |
| 477 | if (global.tune.pattern_cache < 0) { |
| 478 | ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 479 | file, linenum, args[0]); |
| 480 | err_code |= ERR_ALERT | ERR_FATAL; |
| 481 | goto out; |
| 482 | } |
| 483 | } else { |
| 484 | ha_alert("parsing [%s:%d] : '%s' expects a positive numeric value\n", |
| 485 | file, linenum, args[0]); |
| 486 | err_code |= ERR_ALERT | ERR_FATAL; |
| 487 | goto out; |
| 488 | } |
| 489 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 490 | else if (strcmp(args[0], "uid") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 491 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 492 | goto out; |
| 493 | if (global.uid != 0) { |
| 494 | ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
| 495 | err_code |= ERR_ALERT; |
| 496 | goto out; |
| 497 | } |
| 498 | if (*(args[1]) == 0) { |
| 499 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 500 | err_code |= ERR_ALERT | ERR_FATAL; |
| 501 | goto out; |
| 502 | } |
| 503 | if (strl2irc(args[1], strlen(args[1]), &global.uid) != 0) { |
| 504 | ha_warning("parsing [%s:%d] : uid: string '%s' is not a number.\n | You might want to use the 'user' parameter to use a system user name.\n", file, linenum, args[1]); |
| 505 | err_code |= ERR_WARN; |
| 506 | goto out; |
| 507 | } |
| 508 | |
| 509 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 510 | else if (strcmp(args[0], "gid") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 511 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 512 | goto out; |
| 513 | if (global.gid != 0) { |
| 514 | ha_alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum); |
| 515 | err_code |= ERR_ALERT; |
| 516 | goto out; |
| 517 | } |
| 518 | if (*(args[1]) == 0) { |
| 519 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 520 | err_code |= ERR_ALERT | ERR_FATAL; |
| 521 | goto out; |
| 522 | } |
| 523 | if (strl2irc(args[1], strlen(args[1]), &global.gid) != 0) { |
| 524 | ha_warning("parsing [%s:%d] : gid: string '%s' is not a number.\n | You might want to use the 'group' parameter to use a system group name.\n", file, linenum, args[1]); |
| 525 | err_code |= ERR_WARN; |
| 526 | goto out; |
| 527 | } |
| 528 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 529 | else if (strcmp(args[0], "external-check") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 530 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 531 | goto out; |
| 532 | global.external_check = 1; |
| 533 | } |
| 534 | /* user/group name handling */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 535 | else if (strcmp(args[0], "user") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 536 | struct passwd *ha_user; |
| 537 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 538 | goto out; |
| 539 | if (global.uid != 0) { |
| 540 | ha_alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum); |
| 541 | err_code |= ERR_ALERT; |
| 542 | goto out; |
| 543 | } |
| 544 | errno = 0; |
| 545 | ha_user = getpwnam(args[1]); |
| 546 | if (ha_user != NULL) { |
| 547 | global.uid = (int)ha_user->pw_uid; |
| 548 | } |
| 549 | else { |
| 550 | ha_alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno)); |
| 551 | err_code |= ERR_ALERT | ERR_FATAL; |
| 552 | } |
| 553 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 554 | else if (strcmp(args[0], "group") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 555 | struct group *ha_group; |
| 556 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 557 | goto out; |
| 558 | if (global.gid != 0) { |
| 559 | ha_alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum); |
| 560 | err_code |= ERR_ALERT; |
| 561 | goto out; |
| 562 | } |
| 563 | errno = 0; |
| 564 | ha_group = getgrnam(args[1]); |
| 565 | if (ha_group != NULL) { |
| 566 | global.gid = (int)ha_group->gr_gid; |
| 567 | } |
| 568 | else { |
| 569 | ha_alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno)); |
| 570 | err_code |= ERR_ALERT | ERR_FATAL; |
| 571 | } |
| 572 | } |
| 573 | /* end of user/group name handling*/ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 574 | else if (strcmp(args[0], "nbproc") == 0) { |
Willy Tarreau | b63dbb7 | 2021-06-11 16:50:29 +0200 | [diff] [blame] | 575 | ha_alert("parsing [%s:%d] : nbproc is not supported any more since HAProxy 2.5. Threads will automatically be used on multi-processor machines if available.\n", file, linenum); |
| 576 | err_code |= ERR_ALERT | ERR_FATAL; |
| 577 | goto out; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 578 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 579 | else if (strcmp(args[0], "maxconn") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 580 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 581 | goto out; |
| 582 | if (global.maxconn != 0) { |
| 583 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 584 | err_code |= ERR_ALERT; |
| 585 | goto out; |
| 586 | } |
| 587 | if (*(args[1]) == 0) { |
| 588 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 589 | err_code |= ERR_ALERT | ERR_FATAL; |
| 590 | goto out; |
| 591 | } |
| 592 | global.maxconn = atol(args[1]); |
| 593 | #ifdef SYSTEM_MAXCONN |
Willy Tarreau | ca783d4 | 2019-03-13 10:03:07 +0100 | [diff] [blame] | 594 | if (global.maxconn > SYSTEM_MAXCONN && cfg_maxconn <= SYSTEM_MAXCONN) { |
| 595 | ha_alert("parsing [%s:%d] : maxconn value %d too high for this system.\nLimiting to %d. Please use '-n' to force the value.\n", file, linenum, global.maxconn, SYSTEM_MAXCONN); |
| 596 | global.maxconn = SYSTEM_MAXCONN; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 597 | err_code |= ERR_ALERT; |
| 598 | } |
| 599 | #endif /* SYSTEM_MAXCONN */ |
| 600 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 601 | else if (strcmp(args[0], "ssl-server-verify") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 602 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 603 | goto out; |
| 604 | if (*(args[1]) == 0) { |
| 605 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 606 | err_code |= ERR_ALERT | ERR_FATAL; |
| 607 | goto out; |
| 608 | } |
| 609 | if (strcmp(args[1],"none") == 0) |
| 610 | global.ssl_server_verify = SSL_SERVER_VERIFY_NONE; |
| 611 | else if (strcmp(args[1],"required") == 0) |
| 612 | global.ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED; |
| 613 | else { |
| 614 | ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, linenum, args[0]); |
| 615 | err_code |= ERR_ALERT | ERR_FATAL; |
| 616 | goto out; |
| 617 | } |
| 618 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 619 | else if (strcmp(args[0], "maxconnrate") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 620 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 621 | goto out; |
| 622 | if (global.cps_lim != 0) { |
| 623 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 624 | err_code |= ERR_ALERT; |
| 625 | goto out; |
| 626 | } |
| 627 | if (*(args[1]) == 0) { |
| 628 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 629 | err_code |= ERR_ALERT | ERR_FATAL; |
| 630 | goto out; |
| 631 | } |
| 632 | global.cps_lim = atol(args[1]); |
| 633 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 634 | else if (strcmp(args[0], "maxsessrate") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 635 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 636 | goto out; |
| 637 | if (global.sps_lim != 0) { |
| 638 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 639 | err_code |= ERR_ALERT; |
| 640 | goto out; |
| 641 | } |
| 642 | if (*(args[1]) == 0) { |
| 643 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 644 | err_code |= ERR_ALERT | ERR_FATAL; |
| 645 | goto out; |
| 646 | } |
| 647 | global.sps_lim = atol(args[1]); |
| 648 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 649 | else if (strcmp(args[0], "maxsslrate") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 650 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 651 | goto out; |
| 652 | if (global.ssl_lim != 0) { |
| 653 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 654 | err_code |= ERR_ALERT; |
| 655 | goto out; |
| 656 | } |
| 657 | if (*(args[1]) == 0) { |
| 658 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 659 | err_code |= ERR_ALERT | ERR_FATAL; |
| 660 | goto out; |
| 661 | } |
| 662 | global.ssl_lim = atol(args[1]); |
| 663 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 664 | else if (strcmp(args[0], "maxcomprate") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 665 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 666 | goto out; |
| 667 | if (*(args[1]) == 0) { |
| 668 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument in kb/s.\n", file, linenum, args[0]); |
| 669 | err_code |= ERR_ALERT | ERR_FATAL; |
| 670 | goto out; |
| 671 | } |
| 672 | global.comp_rate_lim = atoi(args[1]) * 1024; |
| 673 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 674 | else if (strcmp(args[0], "maxpipes") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 675 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 676 | goto out; |
| 677 | if (global.maxpipes != 0) { |
| 678 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 679 | err_code |= ERR_ALERT; |
| 680 | goto out; |
| 681 | } |
| 682 | if (*(args[1]) == 0) { |
| 683 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 684 | err_code |= ERR_ALERT | ERR_FATAL; |
| 685 | goto out; |
| 686 | } |
| 687 | global.maxpipes = atol(args[1]); |
| 688 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 689 | else if (strcmp(args[0], "maxzlibmem") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 690 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 691 | goto out; |
| 692 | if (*(args[1]) == 0) { |
| 693 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 694 | err_code |= ERR_ALERT | ERR_FATAL; |
| 695 | goto out; |
| 696 | } |
| 697 | global.maxzlibmem = atol(args[1]) * 1024L * 1024L; |
| 698 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 699 | else if (strcmp(args[0], "maxcompcpuusage") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 700 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 701 | goto out; |
| 702 | if (*(args[1]) == 0) { |
| 703 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 704 | err_code |= ERR_ALERT | ERR_FATAL; |
| 705 | goto out; |
| 706 | } |
| 707 | compress_min_idle = 100 - atoi(args[1]); |
| 708 | if (compress_min_idle > 100) { |
| 709 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument between 0 and 100.\n", file, linenum, args[0]); |
| 710 | err_code |= ERR_ALERT | ERR_FATAL; |
| 711 | goto out; |
| 712 | } |
| 713 | } |
| 714 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 715 | else if (strcmp(args[0], "ulimit-n") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 716 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 717 | goto out; |
| 718 | if (global.rlimit_nofile != 0) { |
| 719 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 720 | err_code |= ERR_ALERT; |
| 721 | goto out; |
| 722 | } |
| 723 | if (*(args[1]) == 0) { |
| 724 | ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); |
| 725 | err_code |= ERR_ALERT | ERR_FATAL; |
| 726 | goto out; |
| 727 | } |
| 728 | global.rlimit_nofile = atol(args[1]); |
| 729 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 730 | else if (strcmp(args[0], "chroot") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 731 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 732 | goto out; |
| 733 | if (global.chroot != NULL) { |
| 734 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 735 | err_code |= ERR_ALERT; |
| 736 | goto out; |
| 737 | } |
| 738 | if (*(args[1]) == 0) { |
| 739 | ha_alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]); |
| 740 | err_code |= ERR_ALERT | ERR_FATAL; |
| 741 | goto out; |
| 742 | } |
| 743 | global.chroot = strdup(args[1]); |
| 744 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 745 | else if (strcmp(args[0], "description") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 746 | int i, len=0; |
| 747 | char *d; |
| 748 | |
| 749 | if (!*args[1]) { |
| 750 | ha_alert("parsing [%s:%d]: '%s' expects a string argument.\n", |
| 751 | file, linenum, args[0]); |
| 752 | err_code |= ERR_ALERT | ERR_FATAL; |
| 753 | goto out; |
| 754 | } |
| 755 | |
| 756 | for (i = 1; *args[i]; i++) |
| 757 | len += strlen(args[i]) + 1; |
| 758 | |
| 759 | if (global.desc) |
| 760 | free(global.desc); |
| 761 | |
| 762 | global.desc = d = calloc(1, len); |
| 763 | |
| 764 | d += snprintf(d, global.desc + len - d, "%s", args[1]); |
| 765 | for (i = 2; *args[i]; i++) |
| 766 | d += snprintf(d, global.desc + len - d, " %s", args[i]); |
| 767 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 768 | else if (strcmp(args[0], "node") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 769 | int i; |
| 770 | char c; |
| 771 | |
| 772 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 773 | goto out; |
| 774 | |
| 775 | for (i=0; args[1][i]; i++) { |
| 776 | c = args[1][i]; |
| 777 | if (!isupper((unsigned char)c) && !islower((unsigned char)c) && |
| 778 | !isdigit((unsigned char)c) && c != '_' && c != '-' && c != '.') |
| 779 | break; |
| 780 | } |
| 781 | |
| 782 | if (!i || args[1][i]) { |
| 783 | ha_alert("parsing [%s:%d]: '%s' requires valid node name - non-empty string" |
| 784 | " with digits(0-9), letters(A-Z, a-z), dot(.), hyphen(-) or underscode(_).\n", |
| 785 | file, linenum, args[0]); |
| 786 | err_code |= ERR_ALERT | ERR_FATAL; |
| 787 | goto out; |
| 788 | } |
| 789 | |
| 790 | if (global.node) |
| 791 | free(global.node); |
| 792 | |
| 793 | global.node = strdup(args[1]); |
| 794 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 795 | else if (strcmp(args[0], "pidfile") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 796 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 797 | goto out; |
| 798 | if (global.pidfile != NULL) { |
| 799 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 800 | err_code |= ERR_ALERT; |
| 801 | goto out; |
| 802 | } |
| 803 | if (*(args[1]) == 0) { |
| 804 | ha_alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]); |
| 805 | err_code |= ERR_ALERT | ERR_FATAL; |
| 806 | goto out; |
| 807 | } |
| 808 | global.pidfile = strdup(args[1]); |
| 809 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 810 | else if (strcmp(args[0], "unix-bind") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 811 | int cur_arg = 1; |
| 812 | while (*(args[cur_arg])) { |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 813 | if (strcmp(args[cur_arg], "prefix") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 814 | if (global.unix_bind.prefix != NULL) { |
| 815 | ha_alert("parsing [%s:%d] : unix-bind '%s' already specified. Continuing.\n", file, linenum, args[cur_arg]); |
| 816 | err_code |= ERR_ALERT; |
| 817 | cur_arg += 2; |
| 818 | continue; |
| 819 | } |
| 820 | |
| 821 | if (*(args[cur_arg+1]) == 0) { |
| 822 | ha_alert("parsing [%s:%d] : unix_bind '%s' expects a path as an argument.\n", file, linenum, args[cur_arg]); |
| 823 | err_code |= ERR_ALERT | ERR_FATAL; |
| 824 | goto out; |
| 825 | } |
| 826 | global.unix_bind.prefix = strdup(args[cur_arg+1]); |
| 827 | cur_arg += 2; |
| 828 | continue; |
| 829 | } |
| 830 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 831 | if (strcmp(args[cur_arg], "mode") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 832 | |
| 833 | global.unix_bind.ux.mode = strtol(args[cur_arg + 1], NULL, 8); |
| 834 | cur_arg += 2; |
| 835 | continue; |
| 836 | } |
| 837 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 838 | if (strcmp(args[cur_arg], "uid") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 839 | |
| 840 | global.unix_bind.ux.uid = atol(args[cur_arg + 1 ]); |
| 841 | cur_arg += 2; |
| 842 | continue; |
| 843 | } |
| 844 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 845 | if (strcmp(args[cur_arg], "gid") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 846 | |
| 847 | global.unix_bind.ux.gid = atol(args[cur_arg + 1 ]); |
| 848 | cur_arg += 2; |
| 849 | continue; |
| 850 | } |
| 851 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 852 | if (strcmp(args[cur_arg], "user") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 853 | struct passwd *user; |
| 854 | |
| 855 | user = getpwnam(args[cur_arg + 1]); |
| 856 | if (!user) { |
| 857 | ha_alert("parsing [%s:%d] : '%s' : '%s' unknown user.\n", |
| 858 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 859 | err_code |= ERR_ALERT | ERR_FATAL; |
| 860 | goto out; |
| 861 | } |
| 862 | |
| 863 | global.unix_bind.ux.uid = user->pw_uid; |
| 864 | cur_arg += 2; |
| 865 | continue; |
| 866 | } |
| 867 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 868 | if (strcmp(args[cur_arg], "group") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 869 | struct group *group; |
| 870 | |
| 871 | group = getgrnam(args[cur_arg + 1]); |
| 872 | if (!group) { |
| 873 | ha_alert("parsing [%s:%d] : '%s' : '%s' unknown group.\n", |
| 874 | file, linenum, args[0], args[cur_arg + 1 ]); |
| 875 | err_code |= ERR_ALERT | ERR_FATAL; |
| 876 | goto out; |
| 877 | } |
| 878 | |
| 879 | global.unix_bind.ux.gid = group->gr_gid; |
| 880 | cur_arg += 2; |
| 881 | continue; |
| 882 | } |
| 883 | |
| 884 | ha_alert("parsing [%s:%d] : '%s' only supports the 'prefix', 'mode', 'uid', 'gid', 'user' and 'group' options.\n", |
| 885 | file, linenum, args[0]); |
| 886 | err_code |= ERR_ALERT | ERR_FATAL; |
| 887 | goto out; |
| 888 | } |
| 889 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 890 | else if (strcmp(args[0], "log") == 0) { /* "no log" or "log ..." */ |
Emeric Brun | 9533a70 | 2021-04-02 10:13:43 +0200 | [diff] [blame] | 891 | if (!parse_logsrv(args, &global.logsrvs, (kwm == KWM_NO), file, linenum, &errmsg)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 892 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 893 | err_code |= ERR_ALERT | ERR_FATAL; |
| 894 | goto out; |
| 895 | } |
| 896 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 897 | else if (strcmp(args[0], "log-send-hostname") == 0) { /* set the hostname in syslog header */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 898 | char *name; |
| 899 | |
| 900 | if (global.log_send_hostname != NULL) { |
| 901 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 902 | err_code |= ERR_ALERT; |
| 903 | goto out; |
| 904 | } |
| 905 | |
| 906 | if (*(args[1])) |
| 907 | name = args[1]; |
| 908 | else |
| 909 | name = hostname; |
| 910 | |
| 911 | free(global.log_send_hostname); |
| 912 | global.log_send_hostname = strdup(name); |
| 913 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 914 | else if (strcmp(args[0], "server-state-base") == 0) { /* path base where HAProxy can find server state files */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 915 | if (global.server_state_base != NULL) { |
| 916 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 917 | err_code |= ERR_ALERT; |
| 918 | goto out; |
| 919 | } |
| 920 | |
| 921 | if (!*(args[1])) { |
| 922 | ha_alert("parsing [%s:%d] : '%s' expects one argument: a directory path.\n", file, linenum, args[0]); |
| 923 | err_code |= ERR_FATAL; |
| 924 | goto out; |
| 925 | } |
| 926 | |
| 927 | global.server_state_base = strdup(args[1]); |
| 928 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 929 | else if (strcmp(args[0], "server-state-file") == 0) { /* path to the file where HAProxy can load the server states */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 930 | if (global.server_state_file != NULL) { |
| 931 | ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); |
| 932 | err_code |= ERR_ALERT; |
| 933 | goto out; |
| 934 | } |
| 935 | |
| 936 | if (!*(args[1])) { |
| 937 | ha_alert("parsing [%s:%d] : '%s' expect one argument: a file path.\n", file, linenum, args[0]); |
| 938 | err_code |= ERR_FATAL; |
| 939 | goto out; |
| 940 | } |
| 941 | |
| 942 | global.server_state_file = strdup(args[1]); |
| 943 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 944 | else if (strcmp(args[0], "log-tag") == 0) { /* tag to report to syslog */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 945 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 946 | goto out; |
| 947 | if (*(args[1]) == 0) { |
| 948 | ha_alert("parsing [%s:%d] : '%s' expects a tag for use in syslog.\n", file, linenum, args[0]); |
| 949 | err_code |= ERR_ALERT | ERR_FATAL; |
| 950 | goto out; |
| 951 | } |
| 952 | chunk_destroy(&global.log_tag); |
Eric Salama | 7cea606 | 2020-10-02 11:58:19 +0200 | [diff] [blame] | 953 | chunk_initlen(&global.log_tag, strdup(args[1]), strlen(args[1]), strlen(args[1])); |
| 954 | if (b_orig(&global.log_tag) == NULL) { |
| 955 | chunk_destroy(&global.log_tag); |
| 956 | ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", file, linenum, args[0]); |
| 957 | err_code |= ERR_ALERT | ERR_FATAL; |
| 958 | goto out; |
| 959 | } |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 960 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 961 | else if (strcmp(args[0], "spread-checks") == 0) { /* random time between checks (0-50) */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 962 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 963 | goto out; |
| 964 | if (global.spread_checks != 0) { |
| 965 | ha_alert("parsing [%s:%d]: spread-checks already specified. Continuing.\n", file, linenum); |
| 966 | err_code |= ERR_ALERT; |
| 967 | goto out; |
| 968 | } |
| 969 | if (*(args[1]) == 0) { |
| 970 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 971 | err_code |= ERR_ALERT | ERR_FATAL; |
| 972 | goto out; |
| 973 | } |
| 974 | global.spread_checks = atol(args[1]); |
| 975 | if (global.spread_checks < 0 || global.spread_checks > 50) { |
| 976 | ha_alert("parsing [%s:%d]: 'spread-checks' needs a positive value in range 0..50.\n", file, linenum); |
| 977 | err_code |= ERR_ALERT | ERR_FATAL; |
| 978 | } |
| 979 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 980 | else if (strcmp(args[0], "max-spread-checks") == 0) { /* maximum time between first and last check */ |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 981 | const char *err; |
| 982 | unsigned int val; |
| 983 | |
| 984 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 985 | goto out; |
| 986 | if (*(args[1]) == 0) { |
| 987 | ha_alert("parsing [%s:%d]: '%s' expects an integer argument (0..50).\n", file, linenum, args[0]); |
| 988 | err_code |= ERR_ALERT | ERR_FATAL; |
| 989 | goto out; |
| 990 | } |
| 991 | |
| 992 | err = parse_time_err(args[1], &val, TIME_UNIT_MS); |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 993 | if (err == PARSE_TIME_OVER) { |
| 994 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s>, maximum value is 2147483647 ms (~24.8 days).\n", |
| 995 | file, linenum, args[1], args[0]); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 996 | err_code |= ERR_ALERT | ERR_FATAL; |
| 997 | } |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 998 | else if (err == PARSE_TIME_UNDER) { |
| 999 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s>, minimum non-null value is 1 ms.\n", |
| 1000 | file, linenum, args[1], args[0]); |
| 1001 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1002 | } |
| 1003 | else if (err) { |
| 1004 | ha_alert("parsing [%s:%d]: unsupported character '%c' in '%s' (wants an integer delay).\n", file, linenum, *err, args[0]); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1005 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1006 | } |
Willy Tarreau | 9faebe3 | 2019-06-07 19:00:37 +0200 | [diff] [blame] | 1007 | global.max_spread_checks = val; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1008 | } |
| 1009 | else if (strcmp(args[0], "cpu-map") == 0) { |
| 1010 | /* map a process list to a CPU set */ |
| 1011 | #ifdef USE_CPU_AFFINITY |
| 1012 | char *slash; |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1013 | unsigned long proc = 0, thread = 0; |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1014 | int j, n, autoinc; |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1015 | struct hap_cpuset cpus, cpus_copy; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1016 | |
| 1017 | if (!*args[1] || !*args[2]) { |
| 1018 | ha_alert("parsing [%s:%d] : %s expects a process number " |
| 1019 | " ('all', 'odd', 'even', a number from 1 to %d or a range), " |
| 1020 | " followed by a list of CPU ranges with numbers from 0 to %d.\n", |
Willy Tarreau | 5799e9c | 2019-03-05 18:14:03 +0100 | [diff] [blame] | 1021 | file, linenum, args[0], LONGBITS, LONGBITS - 1); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1022 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1023 | goto out; |
| 1024 | } |
| 1025 | |
| 1026 | if ((slash = strchr(args[1], '/')) != NULL) |
| 1027 | *slash = 0; |
| 1028 | |
Willy Tarreau | 5799e9c | 2019-03-05 18:14:03 +0100 | [diff] [blame] | 1029 | /* note: we silently ignore processes over MAX_PROCS and |
| 1030 | * threads over MAX_THREADS so as not to make configurations a |
| 1031 | * pain to maintain. |
| 1032 | */ |
| 1033 | if (parse_process_number(args[1], &proc, LONGBITS, &autoinc, &errmsg)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1034 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 1035 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1036 | goto out; |
| 1037 | } |
| 1038 | |
| 1039 | if (slash) { |
Willy Tarreau | 5799e9c | 2019-03-05 18:14:03 +0100 | [diff] [blame] | 1040 | if (parse_process_number(slash+1, &thread, LONGBITS, NULL, &errmsg)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1041 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 1042 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1043 | goto out; |
| 1044 | } |
| 1045 | *slash = '/'; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Amaury Denoyelle | a808235 | 2021-04-06 16:46:15 +0200 | [diff] [blame] | 1048 | if (parse_cpu_set((const char **)args+2, &cpus, 0, &errmsg)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1049 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
| 1050 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1051 | goto out; |
| 1052 | } |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1053 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1054 | if (autoinc && |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1055 | my_popcountl(proc) != ha_cpuset_count(&cpus) && |
| 1056 | my_popcountl(thread) != ha_cpuset_count(&cpus)) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1057 | ha_alert("parsing [%s:%d] : %s : PROC/THREAD range and CPU sets " |
| 1058 | "must have the same size to be automatically bound\n", |
| 1059 | file, linenum, args[0]); |
| 1060 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1061 | goto out; |
| 1062 | } |
| 1063 | |
Willy Tarreau | 7764a57 | 2019-07-16 15:10:34 +0200 | [diff] [blame] | 1064 | /* we now have to deal with 3 real cases : |
| 1065 | * cpu-map P-Q => mapping for whole processes, numbers P to Q |
| 1066 | * cpu-map P-Q/1 => mapping of first thread of processes P to Q |
| 1067 | * cpu-map 1/T-U => mapping of threads T to U of process 1 |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1068 | * (note: P=Q=1 since 2.5). |
Willy Tarreau | 7764a57 | 2019-07-16 15:10:34 +0200 | [diff] [blame] | 1069 | * Otherwise other combinations are silently ignored since nbthread |
| 1070 | * and nbproc cannot both be >1 : |
| 1071 | * cpu-map P-Q/T => mapping for thread T for processes P to Q. |
| 1072 | * Only one of T,Q may be > 1, others ignored. |
| 1073 | * cpu-map P/T-U => mapping for threads T to U of process P. Only |
| 1074 | * one of P,U may be > 1, others ignored. |
| 1075 | */ |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1076 | if (!thread || thread == 0x1) { |
| 1077 | /* mapping for whole process. E.g. cpu-map 1 0-3 or cpu-map 1/1 0-3 */ |
| 1078 | ha_cpuset_assign(&cpus_copy, &cpus); |
| 1079 | |
| 1080 | if (!autoinc) |
Willy Tarreau | 44ea631 | 2021-06-15 08:57:56 +0200 | [diff] [blame] | 1081 | ha_cpuset_assign(&cpu_map.proc, &cpus); |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1082 | else { |
Willy Tarreau | 44ea631 | 2021-06-15 08:57:56 +0200 | [diff] [blame] | 1083 | ha_cpuset_zero(&cpu_map.proc); |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1084 | n = ha_cpuset_ffs(&cpus_copy) - 1; |
| 1085 | ha_cpuset_clr(&cpus_copy, n); |
Willy Tarreau | 44ea631 | 2021-06-15 08:57:56 +0200 | [diff] [blame] | 1086 | ha_cpuset_set(&cpu_map.proc, n); |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1087 | } |
| 1088 | } else { |
| 1089 | /* first process, iterate on threads. E.g. cpu-map 1/1-4 0-3 */ |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1090 | ha_cpuset_assign(&cpus_copy, &cpus); |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1091 | for (j = n = 0; j < MAX_THREADS; j++) { |
| 1092 | /* No mapping for this thread */ |
| 1093 | if (!(thread & (1UL << j))) |
Willy Tarreau | 81492c9 | 2019-05-03 09:41:23 +0200 | [diff] [blame] | 1094 | continue; |
| 1095 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1096 | if (!autoinc) |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1097 | ha_cpuset_assign(&cpu_map.thread[j], &cpus); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1098 | else { |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1099 | ha_cpuset_zero(&cpu_map.thread[j]); |
Amaury Denoyelle | 982fb53 | 2021-04-21 18:39:58 +0200 | [diff] [blame] | 1100 | n = ha_cpuset_ffs(&cpus_copy) - 1; |
| 1101 | ha_cpuset_clr(&cpus_copy, n); |
Willy Tarreau | bda7c1d | 2021-06-15 08:49:05 +0200 | [diff] [blame] | 1102 | ha_cpuset_set(&cpu_map.thread[j], n); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1103 | } |
| 1104 | } |
Amaury Denoyelle | a2944ec | 2021-04-15 18:07:07 +0200 | [diff] [blame] | 1105 | |
| 1106 | HA_DIAG_WARNING_COND(proc != 0x1 && thread != 0x1, |
| 1107 | "parsing [%s:%d] : cpu-map statement is considered invalid and thus ignored as it addresses multiple processes and threads at the same time. At least one of them should be 1 and only 1.", file, linenum); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1108 | } |
| 1109 | #else |
| 1110 | ha_alert("parsing [%s:%d] : '%s' is not enabled, please check build options for USE_CPU_AFFINITY.\n", |
| 1111 | file, linenum, args[0]); |
| 1112 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1113 | goto out; |
| 1114 | #endif /* ! USE_CPU_AFFINITY */ |
| 1115 | } |
| 1116 | else if (strcmp(args[0], "setenv") == 0 || strcmp(args[0], "presetenv") == 0) { |
| 1117 | if (alertif_too_many_args(3, file, linenum, args, &err_code)) |
| 1118 | goto out; |
| 1119 | |
| 1120 | if (*(args[2]) == 0) { |
| 1121 | ha_alert("parsing [%s:%d]: '%s' expects a name and a value.\n", file, linenum, args[0]); |
| 1122 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1123 | goto out; |
| 1124 | } |
| 1125 | |
| 1126 | /* "setenv" overwrites, "presetenv" only sets if not yet set */ |
| 1127 | if (setenv(args[1], args[2], (args[0][0] == 's')) != 0) { |
| 1128 | ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[1], strerror(errno)); |
| 1129 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1130 | goto out; |
| 1131 | } |
| 1132 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1133 | else if (strcmp(args[0], "unsetenv") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1134 | int arg; |
| 1135 | |
| 1136 | if (*(args[1]) == 0) { |
| 1137 | ha_alert("parsing [%s:%d]: '%s' expects at least one variable name.\n", file, linenum, args[0]); |
| 1138 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1139 | goto out; |
| 1140 | } |
| 1141 | |
| 1142 | for (arg = 1; *args[arg]; arg++) { |
| 1143 | if (unsetenv(args[arg]) != 0) { |
| 1144 | ha_alert("parsing [%s:%d]: '%s' failed on variable '%s' : %s.\n", file, linenum, args[0], args[arg], strerror(errno)); |
| 1145 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1146 | goto out; |
| 1147 | } |
| 1148 | } |
| 1149 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1150 | else if (strcmp(args[0], "resetenv") == 0) { |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1151 | extern char **environ; |
| 1152 | char **env = environ; |
| 1153 | |
| 1154 | /* args contain variable names to keep, one per argument */ |
| 1155 | while (*env) { |
| 1156 | int arg; |
| 1157 | |
| 1158 | /* look for current variable in among all those we want to keep */ |
| 1159 | for (arg = 1; *args[arg]; arg++) { |
| 1160 | if (strncmp(*env, args[arg], strlen(args[arg])) == 0 && |
| 1161 | (*env)[strlen(args[arg])] == '=') |
| 1162 | break; |
| 1163 | } |
| 1164 | |
| 1165 | /* delete this variable */ |
| 1166 | if (!*args[arg]) { |
| 1167 | char *delim = strchr(*env, '='); |
| 1168 | |
| 1169 | if (!delim || delim - *env >= trash.size) { |
| 1170 | ha_alert("parsing [%s:%d]: '%s' failed to unset invalid variable '%s'.\n", file, linenum, args[0], *env); |
| 1171 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1172 | goto out; |
| 1173 | } |
| 1174 | |
| 1175 | memcpy(trash.area, *env, delim - *env); |
| 1176 | trash.area[delim - *env] = 0; |
| 1177 | |
| 1178 | if (unsetenv(trash.area) != 0) { |
| 1179 | ha_alert("parsing [%s:%d]: '%s' failed to unset variable '%s' : %s.\n", file, linenum, args[0], *env, strerror(errno)); |
| 1180 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1181 | goto out; |
| 1182 | } |
| 1183 | } |
| 1184 | else |
| 1185 | env++; |
| 1186 | } |
| 1187 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1188 | else if (strcmp(args[0], "strict-limits") == 0) { /* "no strict-limits" or "strict-limits" */ |
William Dauchy | 0fec3ab | 2019-10-27 20:08:11 +0100 | [diff] [blame] | 1189 | if (alertif_too_many_args(0, file, linenum, args, &err_code)) |
| 1190 | goto out; |
| 1191 | if (kwm == KWM_NO) |
| 1192 | global.tune.options &= ~GTUNE_STRICT_LIMITS; |
William Dauchy | 0fec3ab | 2019-10-27 20:08:11 +0100 | [diff] [blame] | 1193 | } |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 1194 | else if (strcmp(args[0], "localpeer") == 0) { |
Dragan Dosen | 13cd54c | 2020-06-18 18:24:05 +0200 | [diff] [blame] | 1195 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
| 1196 | goto out; |
| 1197 | |
| 1198 | if (*(args[1]) == 0) { |
| 1199 | ha_alert("parsing [%s:%d] : '%s' expects a name as an argument.\n", |
| 1200 | file, linenum, args[0]); |
| 1201 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1202 | goto out; |
| 1203 | } |
| 1204 | |
| 1205 | if (global.localpeer_cmdline != 0) { |
| 1206 | ha_warning("parsing [%s:%d] : '%s' ignored since it is already set by using the '-L' " |
| 1207 | "command line argument.\n", file, linenum, args[0]); |
| 1208 | err_code |= ERR_WARN; |
| 1209 | goto out; |
| 1210 | } |
| 1211 | |
| 1212 | if (cfg_peers) { |
| 1213 | ha_warning("parsing [%s:%d] : '%s' ignored since it is used after 'peers' section.\n", |
| 1214 | file, linenum, args[0]); |
| 1215 | err_code |= ERR_WARN; |
| 1216 | goto out; |
| 1217 | } |
| 1218 | |
| 1219 | free(localpeer); |
| 1220 | if ((localpeer = strdup(args[1])) == NULL) { |
| 1221 | ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n", |
| 1222 | file, linenum, args[0]); |
| 1223 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1224 | goto out; |
| 1225 | } |
| 1226 | setenv("HAPROXY_LOCALPEER", localpeer, 1); |
| 1227 | } |
Amaury Denoyelle | 0f50cb9 | 2021-03-26 18:50:33 +0100 | [diff] [blame] | 1228 | else if (strcmp(args[0], "numa-cpu-mapping") == 0) { |
| 1229 | global.numa_cpu_mapping = (kwm == KWM_NO) ? 0 : 1; |
| 1230 | } |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1231 | else { |
| 1232 | struct cfg_kw_list *kwl; |
Willy Tarreau | a0e8eb8 | 2021-03-12 09:30:14 +0100 | [diff] [blame] | 1233 | const char *best; |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1234 | int index; |
| 1235 | int rc; |
| 1236 | |
| 1237 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
| 1238 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
| 1239 | if (kwl->kw[index].section != CFG_GLOBAL) |
| 1240 | continue; |
| 1241 | if (strcmp(kwl->kw[index].kw, args[0]) == 0) { |
Amaury Denoyelle | d2e53cd | 2021-05-06 16:21:39 +0200 | [diff] [blame] | 1242 | if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) { |
Amaury Denoyelle | 86c1d0f | 2021-05-07 15:07:21 +0200 | [diff] [blame] | 1243 | ha_alert("%s\n", errmsg); |
Amaury Denoyelle | d2e53cd | 2021-05-06 16:21:39 +0200 | [diff] [blame] | 1244 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1245 | goto out; |
| 1246 | } |
| 1247 | |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1248 | rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg); |
| 1249 | if (rc < 0) { |
| 1250 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 1251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1252 | } |
| 1253 | else if (rc > 0) { |
| 1254 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
| 1255 | err_code |= ERR_WARN; |
| 1256 | goto out; |
| 1257 | } |
| 1258 | goto out; |
| 1259 | } |
| 1260 | } |
| 1261 | } |
| 1262 | |
Willy Tarreau | 101df31 | 2021-03-15 09:12:41 +0100 | [diff] [blame] | 1263 | best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_GLOBAL, common_kw_list); |
Willy Tarreau | a0e8eb8 | 2021-03-12 09:30:14 +0100 | [diff] [blame] | 1264 | if (best) |
| 1265 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best); |
| 1266 | else |
| 1267 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global"); |
Willy Tarreau | 36b9e22 | 2018-11-11 15:19:52 +0100 | [diff] [blame] | 1268 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1269 | } |
| 1270 | |
| 1271 | out: |
| 1272 | free(errmsg); |
| 1273 | return err_code; |
| 1274 | } |
| 1275 | |