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