/src/haproxy/src/cfgparse.c
Line | Count | Source |
1 | | /* |
2 | | * Configuration parser |
3 | | * |
4 | | * Copyright 2000-2011 Willy Tarreau <w@1wt.eu> |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or |
7 | | * modify it under the terms of the GNU General Public License |
8 | | * as published by the Free Software Foundation; either version |
9 | | * 2 of the License, or (at your option) any later version. |
10 | | * |
11 | | */ |
12 | | |
13 | | /* This is to have crypt() and sched_setaffinity() defined on Linux */ |
14 | | #define _GNU_SOURCE |
15 | | |
16 | | #ifdef USE_LIBCRYPT |
17 | | #ifdef USE_CRYPT_H |
18 | | /* some platforms such as Solaris need this */ |
19 | | #include <crypt.h> |
20 | | #endif |
21 | | #endif /* USE_LIBCRYPT */ |
22 | | |
23 | | #include <dirent.h> |
24 | | #include <stdio.h> |
25 | | #include <stdlib.h> |
26 | | #include <string.h> |
27 | | #include <netdb.h> |
28 | | #include <ctype.h> |
29 | | #include <pwd.h> |
30 | | #include <grp.h> |
31 | | #include <errno.h> |
32 | | #ifdef USE_CPU_AFFINITY |
33 | | #include <sched.h> |
34 | | #endif |
35 | | #include <sys/types.h> |
36 | | #include <sys/stat.h> |
37 | | #include <unistd.h> |
38 | | |
39 | | #include <import/cebis_tree.h> |
40 | | |
41 | | #include <haproxy/acl.h> |
42 | | #include <haproxy/action.h> |
43 | | #include <haproxy/api.h> |
44 | | #include <haproxy/arg.h> |
45 | | #include <haproxy/auth.h> |
46 | | #include <haproxy/backend.h> |
47 | | #include <haproxy/capture.h> |
48 | | #include <haproxy/cfgcond.h> |
49 | | #include <haproxy/cfgparse.h> |
50 | | #include <haproxy/channel.h> |
51 | | #include <haproxy/check.h> |
52 | | #include <haproxy/chunk.h> |
53 | | #include <haproxy/clock.h> |
54 | | #include <haproxy/counters.h> |
55 | | #ifdef USE_CPU_AFFINITY |
56 | | #include <haproxy/cpuset.h> |
57 | | #include <haproxy/cpu_topo.h> |
58 | | #endif |
59 | | #include <haproxy/connection.h> |
60 | | #include <haproxy/errors.h> |
61 | | #include <haproxy/filters.h> |
62 | | #include <haproxy/frontend.h> |
63 | | #include <haproxy/global.h> |
64 | | #include <haproxy/http_ana.h> |
65 | | #include <haproxy/http_rules.h> |
66 | | #include <haproxy/lb_chash.h> |
67 | | #include <haproxy/lb_fas.h> |
68 | | #include <haproxy/lb_fwlc.h> |
69 | | #include <haproxy/lb_fwrr.h> |
70 | | #include <haproxy/lb_map.h> |
71 | | #include <haproxy/lb_ss.h> |
72 | | #include <haproxy/listener.h> |
73 | | #include <haproxy/log.h> |
74 | | #include <haproxy/sink.h> |
75 | | #include <haproxy/mailers.h> |
76 | | #include <haproxy/namespace.h> |
77 | | #include <haproxy/quic_cc-t.h> |
78 | | #include <haproxy/quic_sock.h> |
79 | | #include <haproxy/quic_tune.h> |
80 | | #include <haproxy/obj_type-t.h> |
81 | | #include <haproxy/openssl-compat.h> |
82 | | #include <haproxy/peers-t.h> |
83 | | #include <haproxy/peers.h> |
84 | | #include <haproxy/pool.h> |
85 | | #include <haproxy/protocol.h> |
86 | | #include <haproxy/proxy.h> |
87 | | #include <haproxy/resolvers.h> |
88 | | #include <haproxy/sample.h> |
89 | | #include <haproxy/server.h> |
90 | | #include <haproxy/session.h> |
91 | | #include <haproxy/stats-t.h> |
92 | | #include <haproxy/stick_table.h> |
93 | | #include <haproxy/stream.h> |
94 | | #include <haproxy/task.h> |
95 | | #include <haproxy/tcp_rules.h> |
96 | | #include <haproxy/tcpcheck.h> |
97 | | #include <haproxy/thread.h> |
98 | | #include <haproxy/tools.h> |
99 | | #include <haproxy/uri_auth.h> |
100 | | |
101 | | |
102 | | /* Used to chain configuration sections definitions. This list |
103 | | * stores struct cfg_section |
104 | | */ |
105 | | struct list sections = LIST_HEAD_INIT(sections); |
106 | | |
107 | | struct list postparsers = LIST_HEAD_INIT(postparsers); |
108 | | |
109 | | extern struct proxy *mworker_proxy; |
110 | | |
111 | | /* curproxy is only valid during parsing and will be NULL afterwards. */ |
112 | | struct proxy *curproxy = NULL; |
113 | | |
114 | | char *cursection = NULL; |
115 | | int cfg_maxpconn = 0; /* # of simultaneous connections per proxy (-N) */ |
116 | | int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */ |
117 | | char *cfg_scope = NULL; /* the current scope during the configuration parsing */ |
118 | | int non_global_section_parsed = 0; |
119 | | |
120 | | /* how to handle default paths */ |
121 | | static enum default_path_mode { |
122 | | DEFAULT_PATH_CURRENT = 0, /* "current": paths are relative to CWD (this is the default) */ |
123 | | DEFAULT_PATH_CONFIG, /* "config": paths are relative to config file */ |
124 | | DEFAULT_PATH_PARENT, /* "parent": paths are relative to config file's ".." */ |
125 | | DEFAULT_PATH_ORIGIN, /* "origin": paths are relative to default_path_origin */ |
126 | | } default_path_mode; |
127 | | |
128 | | char initial_cwd[PATH_MAX]; |
129 | | static char current_cwd[PATH_MAX]; |
130 | | |
131 | | /* List head of all known configuration keywords */ |
132 | | struct cfg_kw_list cfg_keywords = { |
133 | | .list = LIST_HEAD_INIT(cfg_keywords.list) |
134 | | }; |
135 | | |
136 | | /* |
137 | | * converts <str> to a list of listeners which are dynamically allocated. |
138 | | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
139 | | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
140 | | * - <port> is a numerical port from 1 to 65535 ; |
141 | | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
142 | | * This can be repeated as many times as necessary, separated by a coma. |
143 | | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
144 | | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
145 | | * will be replaced with an error message. |
146 | | */ |
147 | | int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err) |
148 | 0 | { |
149 | 0 | struct protocol *proto; |
150 | 0 | char *next, *dupstr; |
151 | 0 | int port, end; |
152 | |
|
153 | 0 | next = dupstr = strdup(str); |
154 | |
|
155 | 0 | while (next && *next) { |
156 | 0 | struct sockaddr_storage *ss2; |
157 | 0 | int fd = -1; |
158 | |
|
159 | 0 | str = next; |
160 | | /* 1) look for the end of the first address */ |
161 | 0 | if ((next = strchr(str, ',')) != NULL) { |
162 | 0 | *next++ = 0; |
163 | 0 | } |
164 | |
|
165 | 0 | ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, NULL, err, |
166 | 0 | (curproxy == global.cli_fe || curproxy == mworker_proxy) ? NULL : global.unix_bind.prefix, |
167 | 0 | NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE | |
168 | 0 | PA_O_SOCKET_FD | PA_O_STREAM | PA_O_XPRT); |
169 | 0 | if (!ss2) |
170 | 0 | goto fail; |
171 | | |
172 | 0 | if (ss2->ss_family == AF_CUST_RHTTP_SRV) { |
173 | | /* Check if a previous non reverse HTTP present is |
174 | | * already defined. If DGRAM or STREAM is set, this |
175 | | * indicates that we are currently parsing the second |
176 | | * or more address. |
177 | | */ |
178 | 0 | if (bind_conf->options & (BC_O_USE_SOCK_DGRAM|BC_O_USE_SOCK_STREAM) && |
179 | 0 | !(bind_conf->options & BC_O_REVERSE_HTTP)) { |
180 | 0 | memprintf(err, "Cannot mix reverse HTTP bind with others.\n"); |
181 | 0 | goto fail; |
182 | 0 | } |
183 | | |
184 | 0 | bind_conf->rhttp_srvname = strdup(str + strlen("rhttp@")); |
185 | 0 | if (!bind_conf->rhttp_srvname) { |
186 | 0 | memprintf(err, "Cannot allocate reverse HTTP bind.\n"); |
187 | 0 | goto fail; |
188 | 0 | } |
189 | | |
190 | 0 | bind_conf->options |= BC_O_REVERSE_HTTP; |
191 | 0 | } |
192 | 0 | else if (bind_conf->options & BC_O_REVERSE_HTTP) { |
193 | | /* Standard address mixed with a previous reverse HTTP one. */ |
194 | 0 | memprintf(err, "Cannot mix reverse HTTP bind with others.\n"); |
195 | 0 | goto fail; |
196 | 0 | } |
197 | | |
198 | | /* OK the address looks correct */ |
199 | 0 | if (proto->proto_type == PROTO_TYPE_DGRAM) |
200 | 0 | bind_conf->options |= BC_O_USE_SOCK_DGRAM; |
201 | 0 | else |
202 | 0 | bind_conf->options |= BC_O_USE_SOCK_STREAM; |
203 | |
|
204 | 0 | if (proto->xprt_type == PROTO_TYPE_DGRAM) |
205 | 0 | bind_conf->options |= BC_O_USE_XPRT_DGRAM; |
206 | 0 | else |
207 | 0 | bind_conf->options |= BC_O_USE_XPRT_STREAM; |
208 | |
|
209 | 0 | if (!create_listeners(bind_conf, ss2, port, end, fd, proto, err)) { |
210 | 0 | memprintf(err, "%s for address '%s'.\n", *err, str); |
211 | 0 | goto fail; |
212 | 0 | } |
213 | 0 | } /* end while(next) */ |
214 | 0 | free(dupstr); |
215 | 0 | return 1; |
216 | 0 | fail: |
217 | 0 | free(dupstr); |
218 | 0 | return 0; |
219 | 0 | } |
220 | | |
221 | | /* |
222 | | * converts <str> to a list of datagram-oriented listeners which are dynamically |
223 | | * allocated. |
224 | | * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where : |
225 | | * - <addr> can be empty or "*" to indicate INADDR_ANY ; |
226 | | * - <port> is a numerical port from 1 to 65535 ; |
227 | | * - <end> indicates to use the range from <port> to <end> instead (inclusive). |
228 | | * This can be repeated as many times as necessary, separated by a coma. |
229 | | * Function returns 1 for success or 0 if error. In case of errors, if <err> is |
230 | | * not NULL, it must be a valid pointer to either NULL or a freeable area that |
231 | | * will be replaced with an error message. |
232 | | */ |
233 | | int str2receiver(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, const char *file, int line, char **err) |
234 | 0 | { |
235 | 0 | struct protocol *proto; |
236 | 0 | char *next, *dupstr; |
237 | 0 | int port, end; |
238 | |
|
239 | 0 | next = dupstr = strdup(str); |
240 | |
|
241 | 0 | while (next && *next) { |
242 | 0 | struct sockaddr_storage *ss2; |
243 | 0 | int fd = -1; |
244 | |
|
245 | 0 | str = next; |
246 | | /* 1) look for the end of the first address */ |
247 | 0 | if ((next = strchr(str, ',')) != NULL) { |
248 | 0 | *next++ = 0; |
249 | 0 | } |
250 | |
|
251 | 0 | ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, NULL, err, |
252 | 0 | curproxy == global.cli_fe ? NULL : global.unix_bind.prefix, |
253 | 0 | NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE | |
254 | 0 | PA_O_SOCKET_FD | PA_O_DGRAM | PA_O_XPRT); |
255 | 0 | if (!ss2) |
256 | 0 | goto fail; |
257 | | |
258 | | /* OK the address looks correct */ |
259 | 0 | if (!create_listeners(bind_conf, ss2, port, end, fd, proto, err)) { |
260 | 0 | memprintf(err, "%s for address '%s'.\n", *err, str); |
261 | 0 | goto fail; |
262 | 0 | } |
263 | 0 | } /* end while(next) */ |
264 | 0 | free(dupstr); |
265 | 0 | return 1; |
266 | 0 | fail: |
267 | 0 | free(dupstr); |
268 | 0 | return 0; |
269 | 0 | } |
270 | | |
271 | | /* |
272 | | * Sends a warning if proxy <proxy> does not have at least one of the |
273 | | * capabilities in <cap>. An optional <hint> may be added at the end |
274 | | * of the warning to help the user. Returns 1 if a warning was emitted |
275 | | * or 0 if the condition is valid. |
276 | | */ |
277 | | int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) |
278 | 0 | { |
279 | 0 | char *msg; |
280 | |
|
281 | 0 | switch (cap) { |
282 | 0 | case PR_CAP_BE: msg = "no backend"; break; |
283 | 0 | case PR_CAP_FE: msg = "no frontend"; break; |
284 | 0 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
285 | 0 | default: msg = "not enough"; break; |
286 | 0 | } |
287 | | |
288 | 0 | if (!(proxy->cap & cap)) { |
289 | 0 | ha_warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n", |
290 | 0 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
291 | 0 | return 1; |
292 | 0 | } |
293 | 0 | return 0; |
294 | 0 | } |
295 | | |
296 | | /* |
297 | | * Sends an alert if proxy <proxy> does not have at least one of the |
298 | | * capabilities in <cap>. An optional <hint> may be added at the end |
299 | | * of the alert to help the user. Returns 1 if an alert was emitted |
300 | | * or 0 if the condition is valid. |
301 | | */ |
302 | | int failifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) |
303 | 0 | { |
304 | 0 | char *msg; |
305 | |
|
306 | 0 | switch (cap) { |
307 | 0 | case PR_CAP_BE: msg = "no backend"; break; |
308 | 0 | case PR_CAP_FE: msg = "no frontend"; break; |
309 | 0 | case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; |
310 | 0 | default: msg = "not enough"; break; |
311 | 0 | } |
312 | | |
313 | 0 | if (!(proxy->cap & cap)) { |
314 | 0 | ha_alert("parsing [%s:%d] : '%s' not allowed because %s '%s' has %s capability.%s\n", |
315 | 0 | file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); |
316 | 0 | return 1; |
317 | 0 | } |
318 | 0 | return 0; |
319 | 0 | } |
320 | | |
321 | | /* |
322 | | * Report an error in <msg> when there are too many arguments. This version is |
323 | | * intended to be used by keyword parsers so that the message will be included |
324 | | * into the general error message. The index is the current keyword in args. |
325 | | * Return 0 if the number of argument is correct, otherwise build a message and |
326 | | * return 1. Fill err_code with an ERR_ALERT and an ERR_FATAL if not null. The |
327 | | * message may also be null, it will simply not be produced (useful to check only). |
328 | | * <msg> and <err_code> are only affected on error. |
329 | | */ |
330 | | int too_many_args_idx(int maxarg, int index, char **args, char **msg, int *err_code) |
331 | 0 | { |
332 | 0 | int i; |
333 | |
|
334 | 0 | if (!*args[index + maxarg + 1]) |
335 | 0 | return 0; |
336 | | |
337 | 0 | if (msg) { |
338 | 0 | *msg = NULL; |
339 | 0 | memprintf(msg, "%s", args[0]); |
340 | 0 | for (i = 1; i <= index; i++) |
341 | 0 | memprintf(msg, "%s %s", *msg, args[i]); |
342 | |
|
343 | 0 | memprintf(msg, "'%s' cannot handle unexpected argument '%s'.", *msg, args[index + maxarg + 1]); |
344 | 0 | } |
345 | 0 | if (err_code) |
346 | 0 | *err_code |= ERR_ALERT | ERR_FATAL; |
347 | |
|
348 | 0 | return 1; |
349 | 0 | } |
350 | | |
351 | | /* |
352 | | * same as too_many_args_idx with a 0 index |
353 | | */ |
354 | | int too_many_args(int maxarg, char **args, char **msg, int *err_code) |
355 | 0 | { |
356 | 0 | return too_many_args_idx(maxarg, 0, args, msg, err_code); |
357 | 0 | } |
358 | | |
359 | | /* |
360 | | * Report a fatal Alert when there is too much arguments |
361 | | * The index is the current keyword in args |
362 | | * Return 0 if the number of argument is correct, otherwise emit an alert and return 1 |
363 | | * Fill err_code with an ERR_ALERT and an ERR_FATAL |
364 | | */ |
365 | | int alertif_too_many_args_idx(int maxarg, int index, const char *file, int linenum, char **args, int *err_code) |
366 | 0 | { |
367 | 0 | char *kw = NULL; |
368 | 0 | int i; |
369 | |
|
370 | 0 | if (!*args[index + maxarg + 1]) |
371 | 0 | return 0; |
372 | | |
373 | 0 | memprintf(&kw, "%s", args[0]); |
374 | 0 | for (i = 1; i <= index; i++) { |
375 | 0 | memprintf(&kw, "%s %s", kw, args[i]); |
376 | 0 | } |
377 | |
|
378 | 0 | ha_alert("parsing [%s:%d] : '%s' cannot handle unexpected argument '%s'.\n", file, linenum, kw, args[index + maxarg + 1]); |
379 | 0 | free(kw); |
380 | 0 | *err_code |= ERR_ALERT | ERR_FATAL; |
381 | 0 | return 1; |
382 | 0 | } |
383 | | |
384 | | /* |
385 | | * same as alertif_too_many_args_idx with a 0 index |
386 | | */ |
387 | | int alertif_too_many_args(int maxarg, const char *file, int linenum, char **args, int *err_code) |
388 | 0 | { |
389 | 0 | return alertif_too_many_args_idx(maxarg, 0, file, linenum, args, err_code); |
390 | 0 | } |
391 | | |
392 | | |
393 | | /* Report it if a request ACL condition uses some keywords that are incompatible |
394 | | * with the place where the ACL is used. It returns either 0 or ERR_WARN so that |
395 | | * its result can be or'ed with err_code. Note that <cond> may be NULL and then |
396 | | * will be ignored. |
397 | | */ |
398 | | int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line) |
399 | 0 | { |
400 | 0 | const struct acl *acl; |
401 | 0 | const char *kw; |
402 | |
|
403 | 0 | if (!cond) |
404 | 0 | return 0; |
405 | | |
406 | 0 | acl = acl_cond_conflicts(cond, where); |
407 | 0 | if (acl) { |
408 | 0 | if (acl->name && *acl->name) |
409 | 0 | ha_warning("parsing [%s:%d] : acl '%s' will never match because it only involves keywords that are incompatible with '%s'\n", |
410 | 0 | file, line, acl->name, sample_ckp_names(where)); |
411 | 0 | else |
412 | 0 | ha_warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n", |
413 | 0 | file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where)); |
414 | 0 | return ERR_WARN; |
415 | 0 | } |
416 | 0 | if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) |
417 | 0 | return 0; |
418 | | |
419 | 0 | if (acl->name && *acl->name) |
420 | 0 | ha_warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n", |
421 | 0 | file, line, acl->name, kw, sample_ckp_names(where)); |
422 | 0 | else |
423 | 0 | ha_warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n", |
424 | 0 | file, line, kw, sample_ckp_names(where)); |
425 | 0 | return ERR_WARN; |
426 | 0 | } |
427 | | |
428 | | /* Report it if an ACL uses a L6 sample fetch from an HTTP proxy. It returns |
429 | | * either 0 or ERR_WARN so that its result can be or'ed with err_code. Note that |
430 | | * <cond> may be NULL and then will be ignored. |
431 | | */ |
432 | | int warnif_tcp_http_cond(const struct proxy *px, const struct acl_cond *cond) |
433 | 0 | { |
434 | 0 | if (!cond || px->mode != PR_MODE_HTTP) |
435 | 0 | return 0; |
436 | | |
437 | 0 | if (cond->use & (SMP_USE_L6REQ|SMP_USE_L6RES)) { |
438 | 0 | ha_warning("Proxy '%s': L6 sample fetches ignored on HTTP proxies (declared at %s:%d).\n", |
439 | 0 | px->id, cond->file, cond->line); |
440 | 0 | return ERR_WARN; |
441 | 0 | } |
442 | 0 | return 0; |
443 | 0 | } |
444 | | |
445 | | /* try to find in <list> the word that looks closest to <word> by counting |
446 | | * transitions between letters, digits and other characters. Will return the |
447 | | * best matching word if found, otherwise NULL. An optional array of extra |
448 | | * words to compare may be passed in <extra>, but it must then be terminated |
449 | | * by a NULL entry. If unused it may be NULL. |
450 | | */ |
451 | | const char *cfg_find_best_match(const char *word, const struct list *list, int section, const char **extra) |
452 | 0 | { |
453 | 0 | uint8_t word_sig[1024]; // 0..25=letter, 26=digit, 27=other, 28=begin, 29=end |
454 | 0 | uint8_t list_sig[1024]; |
455 | 0 | const struct cfg_kw_list *kwl; |
456 | 0 | int index; |
457 | 0 | const char *best_ptr = NULL; |
458 | 0 | int dist, best_dist = INT_MAX; |
459 | |
|
460 | 0 | make_word_fingerprint(word_sig, word); |
461 | 0 | list_for_each_entry(kwl, list, list) { |
462 | 0 | for (index = 0; kwl->kw[index].kw != NULL; index++) { |
463 | 0 | if (kwl->kw[index].section != section) |
464 | 0 | continue; |
465 | | |
466 | 0 | make_word_fingerprint(list_sig, kwl->kw[index].kw); |
467 | 0 | dist = word_fingerprint_distance(word_sig, list_sig); |
468 | 0 | if (dist < best_dist) { |
469 | 0 | best_dist = dist; |
470 | 0 | best_ptr = kwl->kw[index].kw; |
471 | 0 | } |
472 | 0 | } |
473 | 0 | } |
474 | |
|
475 | 0 | while (extra && *extra) { |
476 | 0 | make_word_fingerprint(list_sig, *extra); |
477 | 0 | dist = word_fingerprint_distance(word_sig, list_sig); |
478 | 0 | if (dist < best_dist) { |
479 | 0 | best_dist = dist; |
480 | 0 | best_ptr = *extra; |
481 | 0 | } |
482 | 0 | extra++; |
483 | 0 | } |
484 | |
|
485 | 0 | if (best_dist > 2 * strlen(word) || (best_ptr && best_dist > 2 * strlen(best_ptr))) |
486 | 0 | best_ptr = NULL; |
487 | 0 | return best_ptr; |
488 | 0 | } |
489 | | |
490 | | /* Parse a string representing a process number or a set of processes. It must |
491 | | * be "all", "odd", "even", a number between 1 and <max> or a range with |
492 | | * two such numbers delimited by a dash ('-'). On success, it returns |
493 | | * 0. otherwise it returns 1 with an error message in <err>. |
494 | | * |
495 | | * Note: this function can also be used to parse a thread number or a set of |
496 | | * threads. |
497 | | */ |
498 | | int parse_process_number(const char *arg, unsigned long *proc, int max, int *autoinc, char **err) |
499 | 0 | { |
500 | 0 | if (autoinc) { |
501 | 0 | *autoinc = 0; |
502 | 0 | if (strncmp(arg, "auto:", 5) == 0) { |
503 | 0 | arg += 5; |
504 | 0 | *autoinc = 1; |
505 | 0 | } |
506 | 0 | } |
507 | |
|
508 | 0 | if (strcmp(arg, "all") == 0) |
509 | 0 | *proc |= ~0UL; |
510 | 0 | else if (strcmp(arg, "odd") == 0) |
511 | 0 | *proc |= ~0UL/3UL; /* 0x555....555 */ |
512 | 0 | else if (strcmp(arg, "even") == 0) |
513 | 0 | *proc |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
514 | 0 | else { |
515 | 0 | const char *p, *dash = NULL; |
516 | 0 | unsigned int low, high; |
517 | |
|
518 | 0 | for (p = arg; *p; p++) { |
519 | 0 | if (*p == '-' && !dash) |
520 | 0 | dash = p; |
521 | 0 | else if (!isdigit((unsigned char)*p)) { |
522 | 0 | memprintf(err, "'%s' is not a valid number/range.", arg); |
523 | 0 | return -1; |
524 | 0 | } |
525 | 0 | } |
526 | | |
527 | 0 | low = high = str2uic(arg); |
528 | 0 | if (dash) |
529 | 0 | high = ((!*(dash+1)) ? max : str2uic(dash + 1)); |
530 | |
|
531 | 0 | if (high < low) { |
532 | 0 | unsigned int swap = low; |
533 | 0 | low = high; |
534 | 0 | high = swap; |
535 | 0 | } |
536 | |
|
537 | 0 | if (low < 1 || low > max || high > max) { |
538 | 0 | memprintf(err, "'%s' is not a valid number/range." |
539 | 0 | " It supports numbers from 1 to %d.\n", |
540 | 0 | arg, max); |
541 | 0 | return 1; |
542 | 0 | } |
543 | | |
544 | 0 | for (;low <= high; low++) |
545 | 0 | *proc |= 1UL << (low-1); |
546 | 0 | } |
547 | 0 | *proc &= ~0UL >> (LONGBITS - max); |
548 | |
|
549 | 0 | return 0; |
550 | 0 | } |
551 | | |
552 | | /* Allocate and initialize the frontend of a "peers" section found in |
553 | | * file <file> at line <linenum> with <id> as ID. |
554 | | * Return 0 if succeeded, -1 if not. |
555 | | * Note that this function may be called from "default-server" |
556 | | * or "peer" lines. |
557 | | */ |
558 | | static int init_peers_frontend(const char *file, int linenum, |
559 | | const char *id, struct peers *peers) |
560 | 0 | { |
561 | 0 | struct proxy *p; |
562 | 0 | char *errmsg = NULL; |
563 | |
|
564 | 0 | if (peers->peers_fe) { |
565 | 0 | p = peers->peers_fe; |
566 | 0 | goto out; |
567 | 0 | } |
568 | | |
569 | 0 | p = alloc_new_proxy(NULL, PR_CAP_FE | PR_CAP_BE, &errmsg); |
570 | 0 | if (!p) { |
571 | 0 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
572 | 0 | ha_free(&errmsg); |
573 | 0 | return -1; |
574 | 0 | } |
575 | | |
576 | 0 | peers_setup_frontend(p); |
577 | 0 | p->parent = peers; |
578 | | /* Finally store this frontend. */ |
579 | 0 | peers->peers_fe = p; |
580 | |
|
581 | 0 | out: |
582 | 0 | if (id && !p->id) |
583 | 0 | p->id = strdup(id); |
584 | 0 | drop_file_name(&p->conf.file); |
585 | 0 | p->conf.args.file = p->conf.file = copy_file_name(file); |
586 | 0 | if (linenum != -1) |
587 | 0 | p->conf.args.line = p->conf.line = linenum; |
588 | |
|
589 | 0 | return 0; |
590 | 0 | } |
591 | | |
592 | | /* Only change ->file, ->line and ->arg struct bind_conf member values |
593 | | * if already present. |
594 | | */ |
595 | | static struct bind_conf *bind_conf_uniq_alloc(struct proxy *p, |
596 | | const char *file, int line, |
597 | | const char *arg, struct xprt_ops *xprt) |
598 | 0 | { |
599 | 0 | struct bind_conf *bind_conf; |
600 | |
|
601 | 0 | if (!LIST_ISEMPTY(&p->conf.bind)) { |
602 | 0 | bind_conf = LIST_ELEM((&p->conf.bind)->n, typeof(bind_conf), by_fe); |
603 | | /* |
604 | | * We keep bind_conf->file and bind_conf->line unchanged |
605 | | * to make them available for error messages |
606 | | */ |
607 | 0 | if (arg) { |
608 | 0 | free(bind_conf->arg); |
609 | 0 | bind_conf->arg = strdup(arg); |
610 | 0 | } |
611 | 0 | } |
612 | 0 | else { |
613 | 0 | bind_conf = bind_conf_alloc(p, file, line, arg, xprt); |
614 | 0 | } |
615 | |
|
616 | 0 | return bind_conf; |
617 | 0 | } |
618 | | |
619 | | /* |
620 | | * Allocate a new struct peer parsed at line <linenum> in file <file> |
621 | | * to be added to <peers>. |
622 | | * Returns the new allocated structure if succeeded, NULL if not. |
623 | | */ |
624 | | static struct peer *cfg_peers_add_peer(struct peers *peers, |
625 | | const char *file, int linenum, |
626 | | const char *id, int local) |
627 | 0 | { |
628 | 0 | struct peer *p; |
629 | |
|
630 | 0 | p = calloc(1, sizeof *p); |
631 | 0 | if (!p) { |
632 | 0 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
633 | 0 | return NULL; |
634 | 0 | } |
635 | | |
636 | | /* the peers are linked backwards first */ |
637 | 0 | peers->count++; |
638 | 0 | p->peers = peers; |
639 | 0 | p->next = peers->remote; |
640 | 0 | peers->remote = p; |
641 | 0 | p->conf.file = strdup(file); |
642 | 0 | p->conf.line = linenum; |
643 | 0 | p->last_change = ns_to_sec(now_ns); |
644 | 0 | HA_SPIN_INIT(&p->lock); |
645 | 0 | if (id) |
646 | 0 | p->id = strdup(id); |
647 | 0 | if (local) { |
648 | 0 | p->local = 1; |
649 | 0 | peers->local = p; |
650 | 0 | } |
651 | |
|
652 | 0 | return p; |
653 | 0 | } |
654 | | |
655 | | /* |
656 | | * Parse a line in a <listen>, <frontend> or <backend> section. |
657 | | * Returns the error code, 0 if OK, or any combination of : |
658 | | * - ERR_ABORT: must abort ASAP |
659 | | * - ERR_FATAL: we can continue parsing but not start the service |
660 | | * - ERR_WARN: a warning has been emitted |
661 | | * - ERR_ALERT: an alert has been emitted |
662 | | * Only the two first ones can stop processing, the two others are just |
663 | | * indicators. |
664 | | */ |
665 | | int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) |
666 | 0 | { |
667 | 0 | static struct peers *curpeers = NULL; |
668 | 0 | static struct sockaddr_storage *bind_addr = NULL; |
669 | 0 | static int nb_shards = 0; |
670 | 0 | struct peer *newpeer = NULL; |
671 | 0 | const char *err; |
672 | 0 | struct bind_conf *bind_conf; |
673 | 0 | int err_code = 0; |
674 | 0 | char *errmsg = NULL; |
675 | 0 | static int bind_line, peer_line; |
676 | |
|
677 | 0 | if (strcmp(args[0], "bind") == 0 || strcmp(args[0], "default-bind") == 0) { |
678 | 0 | int cur_arg; |
679 | 0 | struct bind_conf *bind_conf; |
680 | 0 | int ret; |
681 | |
|
682 | 0 | cur_arg = 1; |
683 | |
|
684 | 0 | if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) { |
685 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
686 | 0 | goto out; |
687 | 0 | } |
688 | | |
689 | 0 | bind_conf = bind_conf_uniq_alloc(curpeers->peers_fe, file, linenum, |
690 | 0 | args[1], xprt_get(XPRT_RAW)); |
691 | 0 | if (!bind_conf) { |
692 | 0 | ha_alert("parsing [%s:%d] : '%s %s' : cannot allocate memory.\n", file, linenum, args[0], args[1]); |
693 | 0 | err_code |= ERR_FATAL; |
694 | 0 | goto out; |
695 | 0 | } |
696 | | |
697 | 0 | bind_conf->maxaccept = 1; |
698 | 0 | bind_conf->accept = session_accept_fd; |
699 | 0 | bind_conf->options |= BC_O_UNLIMITED; /* don't make the peers subject to global limits */ |
700 | |
|
701 | 0 | if (*args[0] == 'b') { |
702 | 0 | struct listener *l; |
703 | |
|
704 | 0 | if (peer_line) { |
705 | 0 | ha_alert("parsing [%s:%d] : mixing \"peer\" and \"bind\" line is forbidden\n", file, linenum); |
706 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
707 | 0 | goto out; |
708 | 0 | } |
709 | | |
710 | 0 | if (!LIST_ISEMPTY(&bind_conf->listeners)) { |
711 | 0 | ha_alert("parsing [%s:%d] : One listener per \"peers\" section is authorized but another is already configured at [%s:%d].\n", file, linenum, bind_conf->file, bind_conf->line); |
712 | 0 | err_code |= ERR_FATAL; |
713 | 0 | } |
714 | |
|
715 | 0 | if (!str2listener(args[1], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
716 | 0 | if (errmsg && *errmsg) { |
717 | 0 | indent_msg(&errmsg, 2); |
718 | 0 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
719 | 0 | } |
720 | 0 | else |
721 | 0 | ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
722 | 0 | file, linenum, args[0], args[1], args[1]); |
723 | 0 | err_code |= ERR_FATAL; |
724 | 0 | goto out; |
725 | 0 | } |
726 | | |
727 | | /* Only one listener supported. Compare first listener |
728 | | * against the last one. It must be the same one. |
729 | | */ |
730 | 0 | if (bind_conf->listeners.n != bind_conf->listeners.p) { |
731 | 0 | ha_alert("parsing [%s:%d] : Only one listener per \"peers\" section is authorized. Multiple listening addresses or port range are not supported.\n", file, linenum); |
732 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
733 | 0 | goto out; |
734 | 0 | } |
735 | | /* |
736 | | * Newly allocated listener is at the end of the list |
737 | | */ |
738 | 0 | l = LIST_ELEM(bind_conf->listeners.p, typeof(l), by_bind); |
739 | 0 | bind_addr = &l->rx.addr; |
740 | |
|
741 | 0 | global.maxsock++; /* for the listening socket */ |
742 | |
|
743 | 0 | bind_line = 1; |
744 | 0 | if (cfg_peers->local) { |
745 | | /* Local peer already defined using "server" line has no |
746 | | * address yet, we should update its server's addr:port |
747 | | * settings |
748 | | */ |
749 | 0 | newpeer = cfg_peers->local; |
750 | 0 | BUG_ON(!newpeer->srv); |
751 | 0 | newpeer->srv->addr = *bind_addr; |
752 | 0 | newpeer->srv->svc_port = get_host_port(bind_addr); |
753 | 0 | } |
754 | 0 | else { |
755 | | /* This peer is local. |
756 | | * Note that we do not set the peer ID. This latter is initialized |
757 | | * when parsing "peer" or "server" line. |
758 | | */ |
759 | 0 | newpeer = cfg_peers_add_peer(curpeers, file, linenum, NULL, 1); |
760 | 0 | if (!newpeer) { |
761 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
762 | 0 | goto out; |
763 | 0 | } |
764 | 0 | } |
765 | 0 | cur_arg++; |
766 | 0 | } |
767 | | |
768 | 0 | ret = bind_parse_args_list(bind_conf, args, cur_arg, cursection, file, linenum); |
769 | 0 | err_code |= ret; |
770 | 0 | if (ret != 0) |
771 | 0 | goto out; |
772 | 0 | } |
773 | 0 | else if (strcmp(args[0], "default-server") == 0) { |
774 | 0 | if (init_peers_frontend(file, -1, NULL, curpeers) != 0) { |
775 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
776 | 0 | goto out; |
777 | 0 | } |
778 | 0 | err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, |
779 | 0 | SRV_PARSE_DEFAULT_SERVER|SRV_PARSE_IN_PEER_SECTION|SRV_PARSE_INITIAL_RESOLVE); |
780 | 0 | } |
781 | 0 | else if (strcmp(args[0], "log") == 0) { |
782 | 0 | if (init_peers_frontend(file, linenum, NULL, curpeers) != 0) { |
783 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
784 | 0 | goto out; |
785 | 0 | } |
786 | 0 | if (!parse_logger(args, &curpeers->peers_fe->loggers, (kwm == KWM_NO), file, linenum, &errmsg)) { |
787 | 0 | ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg); |
788 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
789 | 0 | goto out; |
790 | 0 | } |
791 | 0 | } |
792 | 0 | else if (strcmp(args[0], "peers") == 0) { /* new peers section */ |
793 | | /* Initialize these static variables when entering a new "peers" section*/ |
794 | 0 | bind_line = peer_line = 0; |
795 | 0 | bind_addr = NULL; |
796 | 0 | if (!*args[1]) { |
797 | 0 | ha_alert("parsing [%s:%d] : missing name for peers section.\n", file, linenum); |
798 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
799 | 0 | goto out; |
800 | 0 | } |
801 | | |
802 | 0 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) { |
803 | 0 | err_code |= ERR_ABORT; |
804 | 0 | goto out; |
805 | 0 | } |
806 | | |
807 | 0 | err = invalid_char(args[1]); |
808 | 0 | if (err) { |
809 | 0 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
810 | 0 | file, linenum, *err, args[0], args[1]); |
811 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
812 | 0 | goto out; |
813 | 0 | } |
814 | | |
815 | 0 | for (curpeers = cfg_peers; curpeers != NULL; curpeers = curpeers->next) { |
816 | | /* |
817 | | * If there are two proxies with the same name only following |
818 | | * combinations are allowed: |
819 | | */ |
820 | 0 | if (strcmp(curpeers->id, args[1]) == 0) { |
821 | 0 | ha_alert("Parsing [%s:%d]: peers section '%s' has the same name as another peers section declared at %s:%d.\n", |
822 | 0 | file, linenum, args[1], curpeers->conf.file, curpeers->conf.line); |
823 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
824 | 0 | } |
825 | 0 | } |
826 | |
|
827 | 0 | if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) { |
828 | 0 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
829 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
830 | 0 | goto out; |
831 | 0 | } |
832 | | |
833 | 0 | curpeers->next = cfg_peers; |
834 | 0 | cfg_peers = curpeers; |
835 | 0 | curpeers->conf.file = strdup(file); |
836 | 0 | curpeers->conf.line = linenum; |
837 | 0 | curpeers->last_change = ns_to_sec(now_ns); |
838 | 0 | curpeers->id = strdup(args[1]); |
839 | 0 | curpeers->disabled = 0; |
840 | 0 | } |
841 | 0 | else if (strcmp(args[0], "peer") == 0 || |
842 | 0 | strcmp(args[0], "server") == 0) { /* peer or server definition */ |
843 | 0 | struct server *prev_srv; |
844 | 0 | int local_peer, peer; |
845 | 0 | int parse_addr = 0; |
846 | |
|
847 | 0 | peer = *args[0] == 'p'; |
848 | 0 | local_peer = strcmp(args[1], localpeer) == 0; |
849 | | /* The local peer may have already partially been parsed on a "bind" line. */ |
850 | 0 | if (*args[0] == 'p') { |
851 | 0 | if (bind_line) { |
852 | 0 | ha_alert("parsing [%s:%d] : mixing \"peer\" and \"bind\" line is forbidden\n", file, linenum); |
853 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
854 | 0 | goto out; |
855 | 0 | } |
856 | 0 | peer_line = 1; |
857 | 0 | } |
858 | 0 | if (cfg_peers->local && !cfg_peers->local->id && local_peer) { |
859 | | /* The local peer has already been initialized on a "bind" line. |
860 | | * Let's use it and store its ID. |
861 | | */ |
862 | 0 | newpeer = cfg_peers->local; |
863 | 0 | newpeer->id = strdup(localpeer); |
864 | 0 | } |
865 | 0 | else { |
866 | 0 | if (local_peer && cfg_peers->local) { |
867 | 0 | ha_alert("parsing [%s:%d] : '%s %s' : local peer name already referenced at %s:%d. %s\n", |
868 | 0 | file, linenum, args[0], args[1], |
869 | 0 | curpeers->peers_fe->conf.file, curpeers->peers_fe->conf.line, cfg_peers->local->id); |
870 | 0 | err_code |= ERR_FATAL; |
871 | 0 | goto out; |
872 | 0 | } |
873 | 0 | newpeer = cfg_peers_add_peer(curpeers, file, linenum, args[1], local_peer); |
874 | 0 | if (!newpeer) { |
875 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
876 | 0 | goto out; |
877 | 0 | } |
878 | 0 | } |
879 | | |
880 | | /* Line number and peer ID are updated only if this peer is the local one. */ |
881 | 0 | if (init_peers_frontend(file, |
882 | 0 | newpeer->local ? linenum: -1, |
883 | 0 | newpeer->local ? newpeer->id : NULL, |
884 | 0 | curpeers) != 0) { |
885 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
886 | 0 | goto out; |
887 | 0 | } |
888 | | |
889 | | /* This initializes curpeer->peers->peers_fe->srv. |
890 | | * The server address is parsed only if we are parsing a "peer" line, |
891 | | * or if we are parsing a "server" line and the current peer is not the local one. |
892 | | */ |
893 | 0 | parse_addr = (peer || !local_peer) ? SRV_PARSE_PARSE_ADDR : 0; |
894 | 0 | prev_srv = curpeers->peers_fe->srv; |
895 | 0 | err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, |
896 | 0 | SRV_PARSE_IN_PEER_SECTION|parse_addr|SRV_PARSE_INITIAL_RESOLVE); |
897 | 0 | if (curpeers->peers_fe->srv == prev_srv) { |
898 | | /* parse_server didn't add a server: |
899 | | * Remove the newly allocated peer. |
900 | | */ |
901 | 0 | struct peer *p; |
902 | | |
903 | | /* while it is tolerated to have a "server" line without address, it isn't |
904 | | * the case for a "peer" line |
905 | | */ |
906 | 0 | if (peer) { |
907 | 0 | ha_warning("parsing [%s:%d] : '%s %s' : ignoring invalid peer definition (missing address:port)\n", |
908 | 0 | file, linenum, args[0], args[1]); |
909 | 0 | err_code |= ERR_WARN; |
910 | 0 | } |
911 | 0 | else { |
912 | 0 | ha_diag_warning("parsing [%s:%d] : '%s %s' : ignoring server (not a local peer, valid address:port is expected)\n", |
913 | 0 | file, linenum, args[0], args[1]); |
914 | 0 | } |
915 | |
|
916 | 0 | p = curpeers->remote; |
917 | 0 | curpeers->remote = curpeers->remote->next; |
918 | 0 | free(p->id); |
919 | 0 | free(p); |
920 | 0 | if (local_peer) { |
921 | | /* we only get there with incomplete "peer" |
922 | | * line for local peer (missing address): |
923 | | * |
924 | | * reset curpeers and curpeers fields |
925 | | * that are local peer related |
926 | | */ |
927 | 0 | curpeers->local = NULL; |
928 | 0 | ha_free(&curpeers->peers_fe->id); |
929 | 0 | } |
930 | 0 | goto out; |
931 | 0 | } |
932 | | |
933 | 0 | if (!parse_addr && bind_addr) { |
934 | | /* local peer declared using "server": has name but no |
935 | | * address: we use the known "bind" line addr settings |
936 | | * as implicit server's addr and port. |
937 | | */ |
938 | 0 | curpeers->peers_fe->srv->addr = *bind_addr; |
939 | 0 | curpeers->peers_fe->srv->svc_port = get_host_port(bind_addr); |
940 | 0 | } |
941 | |
|
942 | 0 | if (nb_shards && curpeers->peers_fe->srv->shard > nb_shards) { |
943 | 0 | ha_warning("parsing [%s:%d] : '%s %s' : %d peer shard greater value than %d shards value is ignored.\n", |
944 | 0 | file, linenum, args[0], args[1], curpeers->peers_fe->srv->shard, nb_shards); |
945 | 0 | curpeers->peers_fe->srv->shard = 0; |
946 | 0 | err_code |= ERR_WARN; |
947 | 0 | } |
948 | |
|
949 | 0 | if (curpeers->peers_fe->srv->init_addr_methods || curpeers->peers_fe->srv->resolvers_id || |
950 | 0 | curpeers->peers_fe->srv->do_check || curpeers->peers_fe->srv->do_agent) { |
951 | 0 | ha_warning("parsing [%s:%d] : '%s %s' : init_addr, resolvers, check and agent are ignored for peers.\n", file, linenum, args[0], args[1]); |
952 | 0 | err_code |= ERR_WARN; |
953 | 0 | } |
954 | |
|
955 | 0 | HA_SPIN_INIT(&newpeer->lock); |
956 | |
|
957 | 0 | newpeer->srv = curpeers->peers_fe->srv; |
958 | 0 | if (!newpeer->local) |
959 | 0 | goto out; |
960 | | |
961 | | /* The lines above are reserved to "peer" lines. */ |
962 | 0 | if (*args[0] == 's') |
963 | 0 | goto out; |
964 | | |
965 | 0 | bind_conf = bind_conf_uniq_alloc(curpeers->peers_fe, file, linenum, args[2], xprt_get(XPRT_RAW)); |
966 | 0 | if (!bind_conf) { |
967 | 0 | ha_alert("parsing [%s:%d] : '%s %s' : Cannot allocate memory.\n", file, linenum, args[0], args[1]); |
968 | 0 | err_code |= ERR_FATAL; |
969 | 0 | goto out; |
970 | 0 | } |
971 | | |
972 | 0 | bind_conf->maxaccept = 1; |
973 | 0 | bind_conf->accept = session_accept_fd; |
974 | 0 | bind_conf->options |= BC_O_UNLIMITED; /* don't make the peers subject to global limits */ |
975 | |
|
976 | 0 | if (!LIST_ISEMPTY(&bind_conf->listeners)) { |
977 | 0 | ha_alert("parsing [%s:%d] : One listener per \"peers\" section is authorized but another is already configured at [%s:%d].\n", file, linenum, bind_conf->file, bind_conf->line); |
978 | 0 | err_code |= ERR_FATAL; |
979 | 0 | } |
980 | |
|
981 | 0 | if (!str2listener(args[2], curpeers->peers_fe, bind_conf, file, linenum, &errmsg)) { |
982 | 0 | if (errmsg && *errmsg) { |
983 | 0 | indent_msg(&errmsg, 2); |
984 | 0 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
985 | 0 | } |
986 | 0 | else |
987 | 0 | ha_alert("parsing [%s:%d] : '%s %s' : error encountered while parsing listening address %s.\n", |
988 | 0 | file, linenum, args[0], args[1], args[2]); |
989 | 0 | err_code |= ERR_FATAL; |
990 | 0 | goto out; |
991 | 0 | } |
992 | | |
993 | 0 | global.maxsock++; /* for the listening socket */ |
994 | 0 | } |
995 | 0 | else if (strcmp(args[0], "shards") == 0) { |
996 | 0 | char *endptr; |
997 | |
|
998 | 0 | if (!*args[1]) { |
999 | 0 | ha_alert("parsing [%s:%d] : '%s' : missing value\n", file, linenum, args[0]); |
1000 | 0 | err_code |= ERR_FATAL; |
1001 | 0 | goto out; |
1002 | 0 | } |
1003 | | |
1004 | 0 | curpeers->nb_shards = strtol(args[1], &endptr, 10); |
1005 | 0 | if (*endptr != '\0') { |
1006 | 0 | ha_alert("parsing [%s:%d] : '%s' : expects an integer argument, found '%s'\n", |
1007 | 0 | file, linenum, args[0], args[1]); |
1008 | 0 | err_code |= ERR_FATAL; |
1009 | 0 | goto out; |
1010 | 0 | } |
1011 | | |
1012 | 0 | if (!curpeers->nb_shards) { |
1013 | 0 | ha_alert("parsing [%s:%d] : '%s' : expects a strictly positive integer argument\n", |
1014 | 0 | file, linenum, args[0]); |
1015 | 0 | err_code |= ERR_FATAL; |
1016 | 0 | goto out; |
1017 | 0 | } |
1018 | | |
1019 | 0 | nb_shards = curpeers->nb_shards; |
1020 | 0 | } |
1021 | 0 | else if (strcmp(args[0], "table") == 0) { |
1022 | 0 | struct stktable *t, *other; |
1023 | 0 | char *id; |
1024 | 0 | size_t prefix_len; |
1025 | | |
1026 | | /* Line number and peer ID are updated only if this peer is the local one. */ |
1027 | 0 | if (init_peers_frontend(file, -1, NULL, curpeers) != 0) { |
1028 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
1029 | 0 | goto out; |
1030 | 0 | } |
1031 | | |
1032 | | /* Build the stick-table name, concatenating the "peers" section name |
1033 | | * followed by a '/' character and the table name argument. |
1034 | | */ |
1035 | 0 | chunk_reset(&trash); |
1036 | 0 | if (!chunk_strcpy(&trash, curpeers->id)) { |
1037 | 0 | ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n", |
1038 | 0 | file, linenum, args[0], args[1]); |
1039 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1040 | 0 | goto out; |
1041 | 0 | } |
1042 | | |
1043 | 0 | prefix_len = trash.data; |
1044 | 0 | if (!chunk_memcat(&trash, "/", 1) || !chunk_strcat(&trash, args[1])) { |
1045 | 0 | ha_alert("parsing [%s:%d]: '%s %s' : stick-table name too long.\n", |
1046 | 0 | file, linenum, args[0], args[1]); |
1047 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1048 | 0 | goto out; |
1049 | 0 | } |
1050 | | |
1051 | 0 | t = calloc(1, sizeof *t); |
1052 | 0 | id = strdup(trash.area); |
1053 | 0 | if (!t || !id) { |
1054 | 0 | ha_alert("parsing [%s:%d]: '%s %s' : memory allocation failed\n", |
1055 | 0 | file, linenum, args[0], args[1]); |
1056 | 0 | free(t); |
1057 | 0 | free(id); |
1058 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1059 | 0 | goto out; |
1060 | 0 | } |
1061 | | |
1062 | 0 | other = stktable_find_by_name(trash.area); |
1063 | 0 | if (other) { |
1064 | 0 | ha_alert("parsing [%s:%d] : stick-table name '%s' conflicts with table declared in %s '%s' at %s:%d.\n", |
1065 | 0 | file, linenum, args[1], |
1066 | 0 | other->proxy ? proxy_cap_str(other->proxy->cap) : "peers", |
1067 | 0 | other->proxy ? other->id : other->peers.p->id, |
1068 | 0 | other->conf.file, other->conf.line); |
1069 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1070 | 0 | goto out; |
1071 | 0 | } |
1072 | | |
1073 | | |
1074 | 0 | err_code |= parse_stick_table(file, linenum, args, t, id, id + prefix_len, curpeers); |
1075 | 0 | if (err_code & ERR_FATAL) { |
1076 | 0 | free(t); |
1077 | 0 | free(id); |
1078 | 0 | goto out; |
1079 | 0 | } |
1080 | | |
1081 | 0 | stktable_store_name(t); |
1082 | 0 | t->next = stktables_list; |
1083 | 0 | stktables_list = t; |
1084 | 0 | } |
1085 | 0 | else if (strcmp(args[0], "disabled") == 0) { /* disables this peers section */ |
1086 | 0 | curpeers->disabled |= PR_FL_DISABLED; |
1087 | 0 | } |
1088 | 0 | else if (strcmp(args[0], "enabled") == 0) { /* enables this peers section (used to revert a disabled default) */ |
1089 | 0 | curpeers->disabled = 0; |
1090 | 0 | } |
1091 | 0 | else if (*args[0] != 0) { |
1092 | 0 | struct peers_kw_list *pkwl; |
1093 | 0 | int index; |
1094 | 0 | int rc = -1; |
1095 | |
|
1096 | 0 | list_for_each_entry(pkwl, &peers_keywords.list, list) { |
1097 | 0 | for (index = 0; pkwl->kw[index].kw != NULL; index++) { |
1098 | 0 | if (strcmp(pkwl->kw[index].kw, args[0]) == 0) { |
1099 | 0 | rc = pkwl->kw[index].parse(args, curpeers, file, linenum, &errmsg); |
1100 | 0 | if (rc < 0) { |
1101 | 0 | ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
1102 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1103 | 0 | goto out; |
1104 | 0 | } |
1105 | 0 | else if (rc > 0) { |
1106 | 0 | ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); |
1107 | 0 | err_code |= ERR_WARN; |
1108 | 0 | goto out; |
1109 | 0 | } |
1110 | 0 | goto out; |
1111 | 0 | } |
1112 | 0 | } |
1113 | 0 | } |
1114 | | |
1115 | 0 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
1116 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1117 | 0 | goto out; |
1118 | 0 | } |
1119 | | |
1120 | 0 | out: |
1121 | 0 | free(errmsg); |
1122 | 0 | return err_code; |
1123 | 0 | } |
1124 | | |
1125 | | /* |
1126 | | * Parse a line in a <listen>, <frontend> or <backend> section. |
1127 | | * Returns the error code, 0 if OK, or any combination of : |
1128 | | * - ERR_ABORT: must abort ASAP |
1129 | | * - ERR_FATAL: we can continue parsing but not start the service |
1130 | | * - ERR_WARN: a warning has been emitted |
1131 | | * - ERR_ALERT: an alert has been emitted |
1132 | | * Only the two first ones can stop processing, the two others are just |
1133 | | * indicators. |
1134 | | */ |
1135 | | int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm) |
1136 | 0 | { |
1137 | 0 | static struct mailers *curmailers = NULL; |
1138 | 0 | struct mailer *newmailer = NULL; |
1139 | 0 | const char *err; |
1140 | 0 | int err_code = 0; |
1141 | 0 | char *errmsg = NULL; |
1142 | |
|
1143 | 0 | if (strcmp(args[0], "mailers") == 0) { /* new mailers section */ |
1144 | 0 | if (!*args[1]) { |
1145 | 0 | ha_alert("parsing [%s:%d] : missing name for mailers section.\n", file, linenum); |
1146 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
1147 | 0 | goto out; |
1148 | 0 | } |
1149 | | |
1150 | 0 | err = invalid_char(args[1]); |
1151 | 0 | if (err) { |
1152 | 0 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n", |
1153 | 0 | file, linenum, *err, args[0], args[1]); |
1154 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
1155 | 0 | goto out; |
1156 | 0 | } |
1157 | | |
1158 | 0 | for (curmailers = mailers; curmailers != NULL; curmailers = curmailers->next) { |
1159 | | /* |
1160 | | * If there are two proxies with the same name only following |
1161 | | * combinations are allowed: |
1162 | | */ |
1163 | 0 | if (strcmp(curmailers->id, args[1]) == 0) { |
1164 | 0 | ha_alert("Parsing [%s:%d]: mailers section '%s' has the same name as another mailers section declared at %s:%d.\n", |
1165 | 0 | file, linenum, args[1], curmailers->conf.file, curmailers->conf.line); |
1166 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1167 | 0 | } |
1168 | 0 | } |
1169 | |
|
1170 | 0 | if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) { |
1171 | 0 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
1172 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
1173 | 0 | goto out; |
1174 | 0 | } |
1175 | | |
1176 | 0 | curmailers->next = mailers; |
1177 | 0 | mailers = curmailers; |
1178 | 0 | curmailers->conf.file = strdup(file); |
1179 | 0 | curmailers->conf.line = linenum; |
1180 | 0 | curmailers->id = strdup(args[1]); |
1181 | 0 | curmailers->timeout.mail = DEF_MAILALERTTIME;/* XXX: Would like to Skip to the next alert, if any, ASAP. |
1182 | | * But need enough time so that timeouts don't occur |
1183 | | * during tcp procssing. For now just us an arbitrary default. */ |
1184 | 0 | } |
1185 | 0 | else if (strcmp(args[0], "mailer") == 0) { /* mailer definition */ |
1186 | 0 | struct sockaddr_storage *sk; |
1187 | 0 | int port1, port2; |
1188 | 0 | struct protocol *proto; |
1189 | |
|
1190 | 0 | if (!*args[2]) { |
1191 | 0 | ha_alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n", |
1192 | 0 | file, linenum, args[0]); |
1193 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1194 | 0 | goto out; |
1195 | 0 | } |
1196 | | |
1197 | 0 | err = invalid_char(args[1]); |
1198 | 0 | if (err) { |
1199 | 0 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in server name '%s'.\n", |
1200 | 0 | file, linenum, *err, args[1]); |
1201 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1202 | 0 | goto out; |
1203 | 0 | } |
1204 | | |
1205 | 0 | if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) { |
1206 | 0 | ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum); |
1207 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
1208 | 0 | goto out; |
1209 | 0 | } |
1210 | | |
1211 | | /* the mailers are linked backwards first */ |
1212 | 0 | curmailers->count++; |
1213 | 0 | newmailer->next = curmailers->mailer_list; |
1214 | 0 | curmailers->mailer_list = newmailer; |
1215 | 0 | newmailer->mailers = curmailers; |
1216 | 0 | newmailer->conf.file = strdup(file); |
1217 | 0 | newmailer->conf.line = linenum; |
1218 | |
|
1219 | 0 | newmailer->id = strdup(args[1]); |
1220 | |
|
1221 | 0 | sk = str2sa_range(args[2], NULL, &port1, &port2, NULL, &proto, NULL, |
1222 | 0 | &errmsg, NULL, NULL, NULL, |
1223 | 0 | PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_STREAM | PA_O_XPRT | PA_O_CONNECT); |
1224 | 0 | if (!sk) { |
1225 | 0 | ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg); |
1226 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1227 | 0 | goto out; |
1228 | 0 | } |
1229 | | |
1230 | 0 | if (proto->sock_prot != IPPROTO_TCP) { |
1231 | 0 | ha_alert("parsing [%s:%d] : '%s %s' : TCP not supported for this address family.\n", |
1232 | 0 | file, linenum, args[0], args[1]); |
1233 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1234 | 0 | goto out; |
1235 | 0 | } |
1236 | | |
1237 | 0 | newmailer->addr = *sk; |
1238 | 0 | newmailer->proto = proto; |
1239 | 0 | newmailer->xprt = xprt_get(XPRT_RAW); |
1240 | 0 | newmailer->sock_init_arg = NULL; |
1241 | 0 | } |
1242 | 0 | else if (strcmp(args[0], "timeout") == 0) { |
1243 | 0 | if (!*args[1]) { |
1244 | 0 | ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments.\n", |
1245 | 0 | file, linenum, args[0]); |
1246 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1247 | 0 | goto out; |
1248 | 0 | } |
1249 | 0 | else if (strcmp(args[1], "mail") == 0) { |
1250 | 0 | const char *res; |
1251 | 0 | unsigned int timeout_mail; |
1252 | 0 | if (!*args[2]) { |
1253 | 0 | ha_alert("parsing [%s:%d] : '%s %s' expects <time> as argument.\n", |
1254 | 0 | file, linenum, args[0], args[1]); |
1255 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1256 | 0 | goto out; |
1257 | 0 | } |
1258 | 0 | res = parse_time_err(args[2], &timeout_mail, TIME_UNIT_MS); |
1259 | 0 | if (res == PARSE_TIME_OVER) { |
1260 | 0 | ha_alert("parsing [%s:%d]: timer overflow in argument <%s> to <%s %s>, maximum value is 2147483647 ms (~24.8 days).\n", |
1261 | 0 | file, linenum, args[2], args[0], args[1]); |
1262 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1263 | 0 | goto out; |
1264 | 0 | } |
1265 | 0 | else if (res == PARSE_TIME_UNDER) { |
1266 | 0 | ha_alert("parsing [%s:%d]: timer underflow in argument <%s> to <%s %s>, minimum non-null value is 1 ms.\n", |
1267 | 0 | file, linenum, args[2], args[0], args[1]); |
1268 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1269 | 0 | goto out; |
1270 | 0 | } |
1271 | 0 | else if (res) { |
1272 | 0 | ha_alert("parsing [%s:%d]: unexpected character '%c' in argument to <%s %s>.\n", |
1273 | 0 | file, linenum, *res, args[0], args[1]); |
1274 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1275 | 0 | goto out; |
1276 | 0 | } |
1277 | 0 | curmailers->timeout.mail = timeout_mail; |
1278 | 0 | } else { |
1279 | 0 | ha_alert("parsing [%s:%d] : '%s' expects 'mail' and <time> as arguments got '%s'.\n", |
1280 | 0 | file, linenum, args[0], args[1]); |
1281 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1282 | 0 | goto out; |
1283 | 0 | } |
1284 | 0 | } |
1285 | 0 | else if (*args[0] != 0) { |
1286 | 0 | ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); |
1287 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1288 | 0 | goto out; |
1289 | 0 | } |
1290 | | |
1291 | 0 | out: |
1292 | 0 | free(errmsg); |
1293 | 0 | return err_code; |
1294 | 0 | } |
1295 | | |
1296 | | |
1297 | | int |
1298 | | cfg_parse_netns(const char *file, int linenum, char **args, int kwm) |
1299 | 0 | { |
1300 | | #ifdef USE_NS |
1301 | | const char *err; |
1302 | | const char *item = args[0]; |
1303 | | |
1304 | | if (strcmp(item, "namespace_list") == 0) { |
1305 | | return 0; |
1306 | | } |
1307 | | else if (strcmp(item, "namespace") == 0) { |
1308 | | size_t idx = 1; |
1309 | | const char *current; |
1310 | | while (*(current = args[idx++])) { |
1311 | | err = invalid_char(current); |
1312 | | if (err) { |
1313 | | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
1314 | | file, linenum, *err, item, current); |
1315 | | return ERR_ALERT | ERR_FATAL; |
1316 | | } |
1317 | | |
1318 | | if (netns_store_lookup(current, strlen(current))) { |
1319 | | ha_alert("parsing [%s:%d]: Namespace '%s' is already added.\n", |
1320 | | file, linenum, current); |
1321 | | return ERR_ALERT | ERR_FATAL; |
1322 | | } |
1323 | | if (!netns_store_insert(current)) { |
1324 | | ha_alert("parsing [%s:%d]: Cannot open namespace '%s'.\n", |
1325 | | file, linenum, current); |
1326 | | return ERR_ALERT | ERR_FATAL; |
1327 | | } |
1328 | | } |
1329 | | } |
1330 | | |
1331 | | return 0; |
1332 | | #else |
1333 | 0 | ha_alert("parsing [%s:%d]: namespace support is not compiled in.", |
1334 | 0 | file, linenum); |
1335 | 0 | return ERR_ALERT | ERR_FATAL; |
1336 | 0 | #endif |
1337 | 0 | } |
1338 | | |
1339 | | int |
1340 | | cfg_parse_users(const char *file, int linenum, char **args, int kwm) |
1341 | 0 | { |
1342 | |
|
1343 | 0 | int err_code = 0; |
1344 | 0 | const char *err; |
1345 | |
|
1346 | 0 | if (strcmp(args[0], "userlist") == 0) { /* new userlist */ |
1347 | 0 | struct userlist *newul; |
1348 | |
|
1349 | 0 | if (!*args[1]) { |
1350 | 0 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
1351 | 0 | file, linenum, args[0]); |
1352 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1353 | 0 | goto out; |
1354 | 0 | } |
1355 | 0 | if (alertif_too_many_args(1, file, linenum, args, &err_code)) |
1356 | 0 | goto out; |
1357 | | |
1358 | 0 | err = invalid_char(args[1]); |
1359 | 0 | if (err) { |
1360 | 0 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
1361 | 0 | file, linenum, *err, args[0], args[1]); |
1362 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1363 | 0 | goto out; |
1364 | 0 | } |
1365 | | |
1366 | 0 | for (newul = userlist; newul; newul = newul->next) |
1367 | 0 | if (strcmp(newul->name, args[1]) == 0) { |
1368 | 0 | ha_warning("parsing [%s:%d]: ignoring duplicated userlist '%s'.\n", |
1369 | 0 | file, linenum, args[1]); |
1370 | 0 | err_code |= ERR_WARN; |
1371 | 0 | goto out; |
1372 | 0 | } |
1373 | | |
1374 | 0 | newul = calloc(1, sizeof(*newul)); |
1375 | 0 | if (!newul) { |
1376 | 0 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
1377 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
1378 | 0 | goto out; |
1379 | 0 | } |
1380 | | |
1381 | 0 | newul->name = strdup(args[1]); |
1382 | 0 | if (!newul->name) { |
1383 | 0 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
1384 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
1385 | 0 | free(newul); |
1386 | 0 | goto out; |
1387 | 0 | } |
1388 | | |
1389 | 0 | newul->next = userlist; |
1390 | 0 | userlist = newul; |
1391 | |
|
1392 | 0 | } else if (strcmp(args[0], "group") == 0) { /* new group */ |
1393 | 0 | int cur_arg; |
1394 | 0 | const char *err; |
1395 | 0 | struct auth_groups *ag; |
1396 | |
|
1397 | 0 | if (!*args[1]) { |
1398 | 0 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
1399 | 0 | file, linenum, args[0]); |
1400 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1401 | 0 | goto out; |
1402 | 0 | } |
1403 | | |
1404 | 0 | err = invalid_char(args[1]); |
1405 | 0 | if (err) { |
1406 | 0 | ha_alert("parsing [%s:%d]: character '%c' is not permitted in '%s' name '%s'.\n", |
1407 | 0 | file, linenum, *err, args[0], args[1]); |
1408 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1409 | 0 | goto out; |
1410 | 0 | } |
1411 | | |
1412 | 0 | if (!userlist) |
1413 | 0 | goto out; |
1414 | | |
1415 | 0 | for (ag = userlist->groups; ag; ag = ag->next) |
1416 | 0 | if (strcmp(ag->name, args[1]) == 0) { |
1417 | 0 | ha_warning("parsing [%s:%d]: ignoring duplicated group '%s' in userlist '%s'.\n", |
1418 | 0 | file, linenum, args[1], userlist->name); |
1419 | 0 | err_code |= ERR_ALERT; |
1420 | 0 | goto out; |
1421 | 0 | } |
1422 | | |
1423 | 0 | ag = calloc(1, sizeof(*ag)); |
1424 | 0 | if (!ag) { |
1425 | 0 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
1426 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
1427 | 0 | goto out; |
1428 | 0 | } |
1429 | | |
1430 | 0 | ag->name = strdup(args[1]); |
1431 | 0 | if (!ag->name) { |
1432 | 0 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
1433 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
1434 | 0 | free(ag); |
1435 | 0 | goto out; |
1436 | 0 | } |
1437 | | |
1438 | 0 | cur_arg = 2; |
1439 | |
|
1440 | 0 | while (*args[cur_arg]) { |
1441 | 0 | if (strcmp(args[cur_arg], "users") == 0) { |
1442 | 0 | if (ag->groupusers) { |
1443 | 0 | ha_alert("parsing [%s:%d]: 'users' option already defined in '%s' name '%s'.\n", |
1444 | 0 | file, linenum, args[0], args[1]); |
1445 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1446 | 0 | free(ag->groupusers); |
1447 | 0 | free(ag->name); |
1448 | 0 | free(ag); |
1449 | 0 | goto out; |
1450 | 0 | } |
1451 | 0 | ag->groupusers = strdup(args[cur_arg + 1]); |
1452 | 0 | cur_arg += 2; |
1453 | 0 | continue; |
1454 | 0 | } else { |
1455 | 0 | ha_alert("parsing [%s:%d]: '%s' only supports 'users' option.\n", |
1456 | 0 | file, linenum, args[0]); |
1457 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1458 | 0 | free(ag->groupusers); |
1459 | 0 | free(ag->name); |
1460 | 0 | free(ag); |
1461 | 0 | goto out; |
1462 | 0 | } |
1463 | 0 | } |
1464 | | |
1465 | 0 | ag->next = userlist->groups; |
1466 | 0 | userlist->groups = ag; |
1467 | |
|
1468 | 0 | } else if (strcmp(args[0], "user") == 0) { /* new user */ |
1469 | 0 | struct auth_users *newuser; |
1470 | 0 | int cur_arg; |
1471 | |
|
1472 | 0 | if (!*args[1]) { |
1473 | 0 | ha_alert("parsing [%s:%d]: '%s' expects <name> as arguments.\n", |
1474 | 0 | file, linenum, args[0]); |
1475 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1476 | 0 | goto out; |
1477 | 0 | } |
1478 | 0 | if (!userlist) |
1479 | 0 | goto out; |
1480 | | |
1481 | 0 | for (newuser = userlist->users; newuser; newuser = newuser->next) |
1482 | 0 | if (strcmp(newuser->user, args[1]) == 0) { |
1483 | 0 | ha_warning("parsing [%s:%d]: ignoring duplicated user '%s' in userlist '%s'.\n", |
1484 | 0 | file, linenum, args[1], userlist->name); |
1485 | 0 | err_code |= ERR_ALERT; |
1486 | 0 | goto out; |
1487 | 0 | } |
1488 | | |
1489 | 0 | newuser = calloc(1, sizeof(*newuser)); |
1490 | 0 | if (!newuser) { |
1491 | 0 | ha_alert("parsing [%s:%d]: out of memory.\n", file, linenum); |
1492 | 0 | err_code |= ERR_ALERT | ERR_ABORT; |
1493 | 0 | goto out; |
1494 | 0 | } |
1495 | | |
1496 | 0 | newuser->user = strdup(args[1]); |
1497 | |
|
1498 | 0 | newuser->next = userlist->users; |
1499 | 0 | userlist->users = newuser; |
1500 | |
|
1501 | 0 | cur_arg = 2; |
1502 | |
|
1503 | 0 | while (*args[cur_arg]) { |
1504 | 0 | if (strcmp(args[cur_arg], "password") == 0) { |
1505 | | #ifdef USE_LIBCRYPT |
1506 | | if (!crypt("", args[cur_arg + 1])) { |
1507 | | ha_alert("parsing [%s:%d]: the encrypted password used for user '%s' is not supported by crypt(3).\n", |
1508 | | file, linenum, newuser->user); |
1509 | | err_code |= ERR_ALERT | ERR_FATAL; |
1510 | | goto out; |
1511 | | } |
1512 | | #else |
1513 | 0 | ha_warning("parsing [%s:%d]: no crypt(3) support compiled, encrypted passwords will not work.\n", |
1514 | 0 | file, linenum); |
1515 | 0 | err_code |= ERR_ALERT; |
1516 | 0 | #endif |
1517 | 0 | newuser->pass = strdup(args[cur_arg + 1]); |
1518 | 0 | cur_arg += 2; |
1519 | 0 | continue; |
1520 | 0 | } else if (strcmp(args[cur_arg], "insecure-password") == 0) { |
1521 | 0 | newuser->pass = strdup(args[cur_arg + 1]); |
1522 | 0 | newuser->flags |= AU_O_INSECURE; |
1523 | 0 | cur_arg += 2; |
1524 | 0 | continue; |
1525 | 0 | } else if (strcmp(args[cur_arg], "groups") == 0) { |
1526 | 0 | newuser->u.groups_names = strdup(args[cur_arg + 1]); |
1527 | 0 | cur_arg += 2; |
1528 | 0 | continue; |
1529 | 0 | } else { |
1530 | 0 | ha_alert("parsing [%s:%d]: '%s' only supports 'password', 'insecure-password' and 'groups' options.\n", |
1531 | 0 | file, linenum, args[0]); |
1532 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1533 | 0 | goto out; |
1534 | 0 | } |
1535 | 0 | } |
1536 | 0 | } else { |
1537 | 0 | ha_alert("parsing [%s:%d]: unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "users"); |
1538 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1539 | 0 | } |
1540 | | |
1541 | 0 | out: |
1542 | 0 | return err_code; |
1543 | 0 | } |
1544 | | |
1545 | | int |
1546 | | cfg_parse_scope(const char *file, int linenum, char *line) |
1547 | 2.62k | { |
1548 | 2.62k | char *beg, *end, *scope = NULL; |
1549 | 2.62k | int err_code = 0; |
1550 | 2.62k | const char *err; |
1551 | | |
1552 | 2.62k | beg = line + 1; |
1553 | 2.62k | end = strchr(beg, ']'); |
1554 | | |
1555 | | /* Detect end of scope declaration */ |
1556 | 2.62k | if (!end || end == beg) { |
1557 | 986 | ha_alert("parsing [%s:%d] : empty scope name is forbidden.\n", |
1558 | 986 | file, linenum); |
1559 | 986 | err_code |= ERR_ALERT | ERR_FATAL; |
1560 | 986 | goto out; |
1561 | 986 | } |
1562 | | |
1563 | | /* Get scope name and check its validity */ |
1564 | 1.64k | scope = my_strndup(beg, end-beg); |
1565 | 1.64k | err = invalid_char(scope); |
1566 | 1.64k | if (err) { |
1567 | 797 | ha_alert("parsing [%s:%d] : character '%c' is not permitted in a scope name.\n", |
1568 | 797 | file, linenum, *err); |
1569 | 797 | err_code |= ERR_ALERT | ERR_ABORT; |
1570 | 797 | goto out; |
1571 | 797 | } |
1572 | | |
1573 | | /* Be sure to have a scope declaration alone on its line */ |
1574 | 844 | line = end+1; |
1575 | 844 | while (isspace((unsigned char)*line)) |
1576 | 222 | line++; |
1577 | 844 | if (*line && *line != '#' && *line != '\n' && *line != '\r') { |
1578 | 259 | ha_alert("parsing [%s:%d] : character '%c' is not permitted after scope declaration.\n", |
1579 | 259 | file, linenum, *line); |
1580 | 259 | err_code |= ERR_ALERT | ERR_ABORT; |
1581 | 259 | goto out; |
1582 | 259 | } |
1583 | | |
1584 | | /* We have a valid scope declaration, save it */ |
1585 | 585 | free(cfg_scope); |
1586 | 585 | cfg_scope = scope; |
1587 | 585 | scope = NULL; |
1588 | | |
1589 | 2.62k | out: |
1590 | 2.62k | free(scope); |
1591 | 2.62k | return err_code; |
1592 | 585 | } |
1593 | | |
1594 | | int |
1595 | | cfg_parse_track_sc_num(unsigned int *track_sc_num, |
1596 | | const char *arg, const char *end, char **errmsg) |
1597 | 0 | { |
1598 | 0 | const char *p; |
1599 | 0 | unsigned int num; |
1600 | |
|
1601 | 0 | p = arg; |
1602 | 0 | num = read_uint64(&arg, end); |
1603 | |
|
1604 | 0 | if (arg != end) { |
1605 | 0 | memprintf(errmsg, "Wrong track-sc number '%s'", p); |
1606 | 0 | return -1; |
1607 | 0 | } |
1608 | | |
1609 | 0 | if (num >= global.tune.nb_stk_ctr) { |
1610 | 0 | if (!global.tune.nb_stk_ctr) |
1611 | 0 | memprintf(errmsg, "%u track-sc number not usable, stick-counters " |
1612 | 0 | "are disabled by tune.stick-counters", num); |
1613 | 0 | else |
1614 | 0 | memprintf(errmsg, "%u track-sc number exceeding " |
1615 | 0 | "%d (tune.stick-counters-1) value", num, global.tune.nb_stk_ctr - 1); |
1616 | 0 | return -1; |
1617 | 0 | } |
1618 | | |
1619 | 0 | *track_sc_num = num; |
1620 | 0 | return 0; |
1621 | 0 | } |
1622 | | |
1623 | | /* |
1624 | | * Detect a global section after a non-global one and output a diagnostic |
1625 | | * warning. |
1626 | | */ |
1627 | | static void check_section_position(char *section_name, const char *file, int linenum) |
1628 | 0 | { |
1629 | 0 | if (strcmp(section_name, "global") == 0) { |
1630 | 0 | if ((global.mode & MODE_DIAG) && non_global_section_parsed == 1) |
1631 | 0 | _ha_diag_warning("parsing [%s:%d] : global section detected after a non-global one, the prevalence of their statements is unspecified\n", file, linenum); |
1632 | 0 | } |
1633 | 0 | else if (non_global_section_parsed == 0) { |
1634 | 0 | non_global_section_parsed = 1; |
1635 | 0 | } |
1636 | 0 | } |
1637 | | |
1638 | | /* apply the current default_path setting for config file <file>, and |
1639 | | * optionally replace the current path to <origin> if not NULL while the |
1640 | | * default-path mode is set to "origin". Errors are returned into an |
1641 | | * allocated string passed to <err> if it's not NULL. Returns 0 on failure |
1642 | | * or non-zero on success. |
1643 | | */ |
1644 | | static int cfg_apply_default_path(const char *file, const char *origin, char **err) |
1645 | 2.98k | { |
1646 | 2.98k | const char *beg, *end; |
1647 | | |
1648 | | /* make path start at <beg> and end before <end>, and switch it to "" |
1649 | | * if no slash was passed. |
1650 | | */ |
1651 | 2.98k | beg = file; |
1652 | 2.98k | end = strrchr(beg, '/'); |
1653 | 2.98k | if (!end) |
1654 | 2.98k | end = beg; |
1655 | | |
1656 | 2.98k | if (!*initial_cwd) { |
1657 | 1 | if (getcwd(initial_cwd, sizeof(initial_cwd)) == NULL) { |
1658 | 0 | if (err) |
1659 | 0 | memprintf(err, "Impossible to retrieve startup directory name: %s", strerror(errno)); |
1660 | 0 | return 0; |
1661 | 0 | } |
1662 | 1 | } |
1663 | 2.97k | else if (chdir(initial_cwd) == -1) { |
1664 | 0 | if (err) |
1665 | 0 | memprintf(err, "Impossible to get back to initial directory '%s': %s", initial_cwd, strerror(errno)); |
1666 | 0 | return 0; |
1667 | 0 | } |
1668 | | |
1669 | | /* OK now we're (back) to initial_cwd */ |
1670 | | |
1671 | 2.98k | switch (default_path_mode) { |
1672 | 2.98k | case DEFAULT_PATH_CURRENT: |
1673 | | /* current_cwd never set, nothing to do */ |
1674 | 2.98k | return 1; |
1675 | | |
1676 | 0 | case DEFAULT_PATH_ORIGIN: |
1677 | | /* current_cwd set in the config */ |
1678 | 0 | if (origin && |
1679 | 0 | snprintf(current_cwd, sizeof(current_cwd), "%s", origin) > sizeof(current_cwd)) { |
1680 | 0 | if (err) |
1681 | 0 | memprintf(err, "Absolute path too long: '%s'", origin); |
1682 | 0 | return 0; |
1683 | 0 | } |
1684 | 0 | break; |
1685 | | |
1686 | 0 | case DEFAULT_PATH_CONFIG: |
1687 | 0 | if (end - beg >= sizeof(current_cwd)) { |
1688 | 0 | if (err) |
1689 | 0 | memprintf(err, "Config file path too long, cannot use for relative paths: '%s'", file); |
1690 | 0 | return 0; |
1691 | 0 | } |
1692 | 0 | memcpy(current_cwd, beg, end - beg); |
1693 | 0 | current_cwd[end - beg] = 0; |
1694 | 0 | break; |
1695 | | |
1696 | 0 | case DEFAULT_PATH_PARENT: |
1697 | 0 | if (end - beg + 3 >= sizeof(current_cwd)) { |
1698 | 0 | if (err) |
1699 | 0 | memprintf(err, "Config file path too long, cannot use for relative paths: '%s'", file); |
1700 | 0 | return 0; |
1701 | 0 | } |
1702 | 0 | memcpy(current_cwd, beg, end - beg); |
1703 | 0 | if (end > beg) |
1704 | 0 | memcpy(current_cwd + (end - beg), "/..\0", 4); |
1705 | 0 | else |
1706 | 0 | memcpy(current_cwd + (end - beg), "..\0", 3); |
1707 | 0 | break; |
1708 | 2.98k | } |
1709 | | |
1710 | 0 | if (*current_cwd && chdir(current_cwd) == -1) { |
1711 | 0 | if (err) |
1712 | 0 | memprintf(err, "Impossible to get back to directory '%s': %s", initial_cwd, strerror(errno)); |
1713 | 0 | return 0; |
1714 | 0 | } |
1715 | | |
1716 | 0 | return 1; |
1717 | 0 | } |
1718 | | |
1719 | | /* parses a global "default-path" directive. */ |
1720 | | static int cfg_parse_global_def_path(char **args, int section_type, struct proxy *curpx, |
1721 | | const struct proxy *defpx, const char *file, int line, |
1722 | | char **err) |
1723 | 0 | { |
1724 | 0 | int ret = -1; |
1725 | | |
1726 | | /* "current", "config", "parent", "origin <path>" */ |
1727 | |
|
1728 | 0 | if (strcmp(args[1], "current") == 0) |
1729 | 0 | default_path_mode = DEFAULT_PATH_CURRENT; |
1730 | 0 | else if (strcmp(args[1], "config") == 0) |
1731 | 0 | default_path_mode = DEFAULT_PATH_CONFIG; |
1732 | 0 | else if (strcmp(args[1], "parent") == 0) |
1733 | 0 | default_path_mode = DEFAULT_PATH_PARENT; |
1734 | 0 | else if (strcmp(args[1], "origin") == 0) |
1735 | 0 | default_path_mode = DEFAULT_PATH_ORIGIN; |
1736 | 0 | else { |
1737 | 0 | memprintf(err, "%s default-path mode '%s' for '%s', supported modes include 'current', 'config', 'parent', and 'origin'.", *args[1] ? "unsupported" : "missing", args[1], args[0]); |
1738 | 0 | goto end; |
1739 | 0 | } |
1740 | | |
1741 | 0 | if (default_path_mode == DEFAULT_PATH_ORIGIN) { |
1742 | 0 | if (!*args[2]) { |
1743 | 0 | memprintf(err, "'%s %s' expects a directory as an argument.", args[0], args[1]); |
1744 | 0 | goto end; |
1745 | 0 | } |
1746 | 0 | if (!cfg_apply_default_path(file, args[2], err)) { |
1747 | 0 | memprintf(err, "couldn't set '%s' to origin '%s': %s.", args[0], args[2], *err); |
1748 | 0 | goto end; |
1749 | 0 | } |
1750 | 0 | } |
1751 | 0 | else if (!cfg_apply_default_path(file, NULL, err)) { |
1752 | 0 | memprintf(err, "couldn't set '%s' to '%s': %s.", args[0], args[1], *err); |
1753 | 0 | goto end; |
1754 | 0 | } |
1755 | | |
1756 | | /* note that once applied, the path is immediately updated */ |
1757 | | |
1758 | 0 | ret = 0; |
1759 | 0 | end: |
1760 | 0 | return ret; |
1761 | 0 | } |
1762 | | |
1763 | | /* append a copy of string <filename>, ptr to some allocated memory at the at |
1764 | | * the end of the list <li>. |
1765 | | * On failure : return 0 and <err> filled with an error message. |
1766 | | * The caller is responsible for freeing the <err> and <filename> copy |
1767 | | * memory area using free(). |
1768 | | */ |
1769 | | int list_append_cfgfile(struct list *li, const char *filename, char **err) |
1770 | 0 | { |
1771 | 0 | struct cfgfile *entry = NULL; |
1772 | |
|
1773 | 0 | entry = calloc(1, sizeof(*entry)); |
1774 | 0 | if (!entry) { |
1775 | 0 | memprintf(err, "out of memory"); |
1776 | 0 | goto fail_entry; |
1777 | 0 | } |
1778 | | |
1779 | 0 | entry->filename = strdup(filename); |
1780 | 0 | if (!entry->filename) { |
1781 | 0 | memprintf(err, "out of memory"); |
1782 | 0 | goto fail_entry_name; |
1783 | 0 | } |
1784 | | |
1785 | 0 | LIST_APPEND(li, &entry->list); |
1786 | |
|
1787 | 0 | return 1; |
1788 | | |
1789 | 0 | fail_entry_name: |
1790 | 0 | free(entry->filename); |
1791 | 0 | fail_entry: |
1792 | 0 | free(entry); |
1793 | 0 | return 0; |
1794 | 0 | } |
1795 | | |
1796 | | /* loads the content of the given file in memory. On success, returns the number |
1797 | | * of bytes successfully stored at *cfg_content until EOF. On error, emits |
1798 | | * alerts, performs needed clean-up routines and returns -1. |
1799 | | */ |
1800 | | ssize_t load_cfg_in_mem(char *filename, char **cfg_content) |
1801 | 0 | { |
1802 | 0 | size_t bytes_to_read = LINESIZE; |
1803 | 0 | size_t chunk_size = 0; |
1804 | 0 | size_t read_bytes = 0; |
1805 | 0 | struct stat file_stat; |
1806 | 0 | char *new_area; |
1807 | 0 | size_t ret = 0; |
1808 | 0 | FILE *f; |
1809 | | |
1810 | | /* let's try to obtain the size, if regular file */ |
1811 | 0 | if (stat(filename, &file_stat) != 0) { |
1812 | 0 | ha_alert("stat() failed for configuration file %s : %s\n", |
1813 | 0 | filename, strerror(errno)); |
1814 | 0 | return -1; |
1815 | 0 | } |
1816 | | |
1817 | 0 | if (file_stat.st_size > chunk_size) |
1818 | 0 | bytes_to_read = file_stat.st_size; |
1819 | | |
1820 | |
|
1821 | 0 | if ((f = fopen(filename,"r")) == NULL) { |
1822 | 0 | ha_alert("Could not open configuration file %s : %s\n", |
1823 | 0 | filename, strerror(errno)); |
1824 | 0 | return -1; |
1825 | 0 | } |
1826 | | |
1827 | 0 | *cfg_content = NULL; |
1828 | |
|
1829 | 0 | while (1) { |
1830 | 0 | if (!file_stat.st_size && ((read_bytes + bytes_to_read) > MAX_CFG_SIZE)) { |
1831 | 0 | ha_alert("Loading %s: input is too large %ldMB, limited to %dMB. Exiting.\n", |
1832 | 0 | filename, (long)(read_bytes + bytes_to_read)/(1024*1024), |
1833 | 0 | MAX_CFG_SIZE/(1024*1024)); |
1834 | 0 | goto free_mem; |
1835 | 0 | } |
1836 | | |
1837 | 0 | if (read_bytes + bytes_to_read > chunk_size) { |
1838 | 0 | chunk_size = (read_bytes + bytes_to_read) * 2; |
1839 | 0 | new_area = realloc(*cfg_content, chunk_size); |
1840 | 0 | if (new_area == NULL) { |
1841 | 0 | ha_alert("Loading %s: file too long, cannot allocate memory.\n", |
1842 | 0 | filename); |
1843 | 0 | goto free_mem; |
1844 | 0 | } |
1845 | 0 | *cfg_content = new_area; |
1846 | 0 | } |
1847 | | |
1848 | 0 | bytes_to_read = chunk_size - read_bytes; |
1849 | 0 | ret = fread(*cfg_content + read_bytes, sizeof(char), bytes_to_read, f); |
1850 | 0 | read_bytes += ret; |
1851 | |
|
1852 | 0 | if (!ret || feof(f) || ferror(f)) |
1853 | 0 | break; |
1854 | 0 | } |
1855 | | |
1856 | 0 | fclose(f); |
1857 | |
|
1858 | 0 | return read_bytes; |
1859 | | |
1860 | 0 | free_mem: |
1861 | 0 | ha_free(cfg_content); |
1862 | 0 | fclose(f); |
1863 | |
|
1864 | 0 | return -1; |
1865 | 0 | } |
1866 | | |
1867 | | /* |
1868 | | * This function parses the configuration file given in the argument. |
1869 | | * Returns the error code, 0 if OK, -1 if we are run out of memory, |
1870 | | * or any combination of : |
1871 | | * - ERR_ABORT: must abort ASAP |
1872 | | * - ERR_FATAL: we can continue parsing but not start the service |
1873 | | * - ERR_WARN: a warning has been emitted |
1874 | | * - ERR_ALERT: an alert has been emitted |
1875 | | * Only the two first ones can stop processing, the two others are just |
1876 | | * indicators. |
1877 | | */ |
1878 | | int parse_cfg(const struct cfgfile *cfg) |
1879 | 2.98k | { |
1880 | 2.98k | char *thisline = NULL; |
1881 | 2.98k | int linesize = LINESIZE; |
1882 | 2.98k | int linenum = 0; |
1883 | 2.98k | int err_code = 0; |
1884 | 2.98k | struct cfg_section *cs = NULL, *pcs = NULL; |
1885 | 2.98k | struct cfg_section *ics; |
1886 | 2.98k | int readbytes = 0; |
1887 | 2.98k | char *outline = NULL; |
1888 | 2.98k | size_t outlen = 0; |
1889 | 2.98k | size_t outlinesize = 0; |
1890 | 2.98k | int fatal = 0; |
1891 | 2.98k | int missing_lf = -1; |
1892 | 2.98k | int nested_cond_lvl = 0; |
1893 | 2.98k | enum nested_cond_state nested_conds[MAXNESTEDCONDS]; |
1894 | 2.98k | char *errmsg = NULL; |
1895 | 2.98k | const char *cur_position = cfg->content; |
1896 | 2.98k | char *file = cfg->filename; |
1897 | | |
1898 | 2.98k | global.cfg_curr_line = 0; |
1899 | 2.98k | global.cfg_curr_file = file; |
1900 | | |
1901 | 2.98k | if ((thisline = malloc(sizeof(*thisline) * linesize)) == NULL) { |
1902 | 0 | ha_alert("Out of memory trying to allocate a buffer for a configuration line.\n"); |
1903 | 0 | err_code = -1; |
1904 | 0 | goto err; |
1905 | 0 | } |
1906 | | |
1907 | | /* change to the new dir if required */ |
1908 | 2.98k | if (!cfg_apply_default_path(file, NULL, &errmsg)) { |
1909 | 0 | ha_alert("parsing [%s:%d]: failed to apply default-path: %s.\n", file, linenum, errmsg); |
1910 | 0 | free(errmsg); |
1911 | 0 | err_code = -1; |
1912 | 0 | goto err; |
1913 | 0 | } |
1914 | | |
1915 | 32.4k | next_line: |
1916 | 358k | while (fgets_from_mem(thisline + readbytes, linesize - readbytes, |
1917 | 358k | &cur_position, cfg->content + cfg->size)) { |
1918 | 356k | int arg, kwm = KWM_STD; |
1919 | 356k | char *end; |
1920 | 356k | char *args[MAX_LINE_ARGS + 1]; |
1921 | 356k | char *line = thisline; |
1922 | 356k | const char *errptr = NULL; /* first error from parse_line() */ |
1923 | | |
1924 | 356k | if (missing_lf != -1) { |
1925 | 168 | ha_alert("parsing [%s:%d]: Stray NUL character at position %d.\n", |
1926 | 168 | file, linenum, (missing_lf + 1)); |
1927 | 168 | err_code |= ERR_ALERT | ERR_FATAL; |
1928 | 168 | missing_lf = -1; |
1929 | 168 | break; |
1930 | 168 | } |
1931 | | |
1932 | 356k | linenum++; |
1933 | 356k | global.cfg_curr_line = linenum; |
1934 | | |
1935 | 356k | if (fatal >= 50) { |
1936 | 11 | ha_alert("parsing [%s:%d]: too many fatal errors (%d), stopping now.\n", file, linenum, fatal); |
1937 | 11 | break; |
1938 | 11 | } |
1939 | | |
1940 | 356k | end = line + strlen(line); |
1941 | | |
1942 | 356k | if (end-line == linesize-1 && *(end-1) != '\n') { |
1943 | | /* Check if we reached the limit and the last char is not \n. |
1944 | | * Watch out for the last line without the terminating '\n'! |
1945 | | */ |
1946 | 1.83k | char *newline; |
1947 | 1.83k | int newlinesize = linesize * 2; |
1948 | | |
1949 | 1.83k | newline = realloc(thisline, sizeof(*thisline) * newlinesize); |
1950 | 1.83k | if (newline == NULL) { |
1951 | 0 | ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
1952 | 0 | file, linenum); |
1953 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
1954 | 0 | fatal++; |
1955 | 0 | linenum--; |
1956 | 0 | continue; |
1957 | 0 | } |
1958 | | |
1959 | 1.83k | readbytes = linesize - 1; |
1960 | 1.83k | linesize = newlinesize; |
1961 | 1.83k | thisline = newline; |
1962 | 1.83k | linenum--; |
1963 | 1.83k | continue; |
1964 | 1.83k | } |
1965 | | |
1966 | 354k | readbytes = 0; |
1967 | | |
1968 | 354k | if (end > line && *(end-1) == '\n') { |
1969 | | /* kill trailing LF */ |
1970 | 351k | *(end - 1) = 0; |
1971 | 351k | } |
1972 | 2.46k | else { |
1973 | | /* mark this line as truncated */ |
1974 | 2.46k | missing_lf = end - line; |
1975 | 2.46k | } |
1976 | | |
1977 | | /* skip leading spaces */ |
1978 | 354k | while (isspace((unsigned char)*line)) |
1979 | 2.86k | line++; |
1980 | | |
1981 | 354k | if (*line == '[') {/* This is the beginning if a scope */ |
1982 | 2.62k | err_code |= cfg_parse_scope(file, linenum, line); |
1983 | 2.62k | goto next_line; |
1984 | 2.62k | } |
1985 | | |
1986 | 354k | while (1) { |
1987 | 354k | uint32_t err; |
1988 | | |
1989 | 354k | arg = sizeof(args) / sizeof(*args); |
1990 | 354k | outlen = outlinesize; |
1991 | 354k | errptr = NULL; |
1992 | 354k | err = parse_line(line, outline, &outlen, args, &arg, |
1993 | 354k | PARSE_OPT_ENV | PARSE_OPT_DQUOTE | PARSE_OPT_SQUOTE | |
1994 | 354k | PARSE_OPT_BKSLASH | PARSE_OPT_SHARP | PARSE_OPT_WORD_EXPAND, |
1995 | 354k | &errptr); |
1996 | | |
1997 | 354k | if (err & PARSE_ERR_QUOTE) { |
1998 | 1.69k | size_t newpos = sanitize_for_printing(line, errptr - line, 80); |
1999 | | |
2000 | 1.69k | ha_alert("parsing [%s:%d]: unmatched quote at position %d:\n" |
2001 | 1.69k | " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^"); |
2002 | 1.69k | err_code |= ERR_ALERT | ERR_FATAL; |
2003 | 1.69k | fatal++; |
2004 | 1.69k | goto next_line; |
2005 | 1.69k | } |
2006 | | |
2007 | 352k | if (err & PARSE_ERR_BRACE) { |
2008 | 353 | size_t newpos = sanitize_for_printing(line, errptr - line, 80); |
2009 | | |
2010 | 353 | ha_alert("parsing [%s:%d]: unmatched brace in environment variable name at position %d:\n" |
2011 | 353 | " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^"); |
2012 | 353 | err_code |= ERR_ALERT | ERR_FATAL; |
2013 | 353 | fatal++; |
2014 | 353 | goto next_line; |
2015 | 353 | } |
2016 | | |
2017 | 352k | if (err & PARSE_ERR_VARNAME) { |
2018 | 657 | size_t newpos = sanitize_for_printing(line, errptr - line, 80); |
2019 | | |
2020 | 657 | ha_alert("parsing [%s:%d]: forbidden first char in environment variable name at position %d:\n" |
2021 | 657 | " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^"); |
2022 | 657 | err_code |= ERR_ALERT | ERR_FATAL; |
2023 | 657 | fatal++; |
2024 | 657 | goto next_line; |
2025 | 657 | } |
2026 | | |
2027 | 351k | if (err & PARSE_ERR_HEX) { |
2028 | 362 | size_t newpos = sanitize_for_printing(line, errptr - line, 80); |
2029 | | |
2030 | 362 | ha_alert("parsing [%s:%d]: truncated or invalid hexadecimal sequence at position %d:\n" |
2031 | 362 | " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^"); |
2032 | 362 | err_code |= ERR_ALERT | ERR_FATAL; |
2033 | 362 | fatal++; |
2034 | 362 | goto next_line; |
2035 | 362 | } |
2036 | | |
2037 | 351k | if (err & PARSE_ERR_WRONG_EXPAND) { |
2038 | 194 | size_t newpos = sanitize_for_printing(line, errptr - line, 80); |
2039 | | |
2040 | 194 | ha_alert("parsing [%s:%d]: truncated or invalid word expansion sequence at position %d:\n" |
2041 | 194 | " %s\n %*s\n", file, linenum, (int)(errptr-thisline+1), line, (int)(newpos+1), "^"); |
2042 | 194 | err_code |= ERR_ALERT | ERR_FATAL; |
2043 | 194 | fatal++; |
2044 | 194 | goto next_line; |
2045 | 194 | } |
2046 | | |
2047 | 351k | if (err & (PARSE_ERR_TOOLARGE|PARSE_ERR_OVERLAP)) { |
2048 | 2.64k | outlinesize = (outlen + 1023) & -1024; |
2049 | 2.64k | outline = my_realloc2(outline, outlinesize); |
2050 | 2.64k | if (outline == NULL) { |
2051 | 0 | ha_alert("parsing [%s:%d]: line too long, cannot allocate memory.\n", |
2052 | 0 | file, linenum); |
2053 | 0 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2054 | 0 | fatal++; |
2055 | 0 | outlinesize = 0; |
2056 | 0 | goto err; |
2057 | 0 | } |
2058 | | /* try again */ |
2059 | 2.64k | continue; |
2060 | 2.64k | } |
2061 | | |
2062 | 348k | if (err & PARSE_ERR_TOOMANY) { |
2063 | | /* only check this *after* being sure the output is allocated */ |
2064 | 190 | ha_alert("parsing [%s:%d]: too many words, truncating after word %d, position %ld: <%s>.\n", |
2065 | 190 | file, linenum, MAX_LINE_ARGS, (long)(args[MAX_LINE_ARGS-1] - outline + 1), args[MAX_LINE_ARGS-1]); |
2066 | 190 | err_code |= ERR_ALERT | ERR_FATAL; |
2067 | 190 | fatal++; |
2068 | 190 | goto next_line; |
2069 | 190 | } |
2070 | | |
2071 | | /* everything's OK */ |
2072 | 348k | break; |
2073 | 348k | } |
2074 | | |
2075 | | /* dump cfg */ |
2076 | 348k | if (global.mode & MODE_DUMP_CFG) { |
2077 | 0 | if (args[0] != NULL) { |
2078 | 0 | struct cfg_section *sect; |
2079 | 0 | int is_sect = 0; |
2080 | 0 | int i = 0; |
2081 | 0 | uint32_t g_key = HA_ATOMIC_LOAD(&global.anon_key); |
2082 | |
|
2083 | 0 | if (global.mode & MODE_DUMP_NB_L) |
2084 | 0 | qfprintf(stdout, "%d\t", linenum); |
2085 | | |
2086 | | /* if a word is in sections list, is_sect = 1 */ |
2087 | 0 | list_for_each_entry(sect, §ions, list) { |
2088 | | /* look for a section_name, but also a section_parser, because there might be |
2089 | | * only a post_section_parser */ |
2090 | 0 | if (strcmp(args[0], sect->section_name) == 0 && |
2091 | 0 | sect->section_parser) { |
2092 | 0 | is_sect = 1; |
2093 | 0 | break; |
2094 | 0 | } |
2095 | 0 | } |
2096 | |
|
2097 | 0 | if (g_key == 0) { |
2098 | | /* no anonymizing needed, dump the config as-is (but without comments). |
2099 | | * Note: tabs were lost during tokenizing, so we reinsert for non-section |
2100 | | * keywords. |
2101 | | */ |
2102 | 0 | if (!is_sect) |
2103 | 0 | qfprintf(stdout, "\t"); |
2104 | |
|
2105 | 0 | for (i = 0; i < arg; i++) { |
2106 | 0 | qfprintf(stdout, "%s ", args[i]); |
2107 | 0 | } |
2108 | 0 | qfprintf(stdout, "\n"); |
2109 | 0 | continue; |
2110 | 0 | } |
2111 | | |
2112 | | /* We're anonymizing */ |
2113 | | |
2114 | 0 | if (is_sect) { |
2115 | | /* new sections are optionally followed by an identifier */ |
2116 | 0 | if (arg >= 2) { |
2117 | 0 | qfprintf(stdout, "%s %s\n", args[0], HA_ANON_ID(g_key, args[1])); |
2118 | 0 | } |
2119 | 0 | else { |
2120 | 0 | qfprintf(stdout, "%s\n", args[0]); |
2121 | 0 | } |
2122 | 0 | continue; |
2123 | 0 | } |
2124 | | |
2125 | | /* non-section keywords start indented */ |
2126 | 0 | qfprintf(stdout, "\t"); |
2127 | | |
2128 | | /* some keywords deserve special treatment */ |
2129 | 0 | if (!*args[0]) { |
2130 | 0 | qfprintf(stdout, "\n"); |
2131 | 0 | } |
2132 | | |
2133 | 0 | else if (strcmp(args[0], "anonkey") == 0) { |
2134 | 0 | qfprintf(stdout, "%s [...]\n", args[0]); |
2135 | 0 | } |
2136 | | |
2137 | 0 | else if (strcmp(args[0], "maxconn") == 0) { |
2138 | 0 | qfprintf(stdout, "%s %s\n", args[0], args[1]); |
2139 | 0 | } |
2140 | | |
2141 | 0 | else if (strcmp(args[0], "stats") == 0 && |
2142 | 0 | (strcmp(args[1], "timeout") == 0 || strcmp(args[1], "maxconn") == 0)) { |
2143 | 0 | qfprintf(stdout, "%s %s %s\n", args[0], args[1], args[2]); |
2144 | 0 | } |
2145 | | |
2146 | 0 | else if (strcmp(args[0], "stats") == 0 && strcmp(args[1], "socket") == 0) { |
2147 | 0 | qfprintf(stdout, "%s %s ", args[0], args[1]); |
2148 | |
|
2149 | 0 | if (arg > 2) { |
2150 | 0 | qfprintf(stdout, "%s ", hash_ipanon(g_key, args[2], 1)); |
2151 | |
|
2152 | 0 | if (arg > 3) { |
2153 | 0 | qfprintf(stdout, "[...]\n"); |
2154 | 0 | } |
2155 | 0 | else { |
2156 | 0 | qfprintf(stdout, "\n"); |
2157 | 0 | } |
2158 | 0 | } |
2159 | 0 | else { |
2160 | 0 | qfprintf(stdout, "\n"); |
2161 | 0 | } |
2162 | 0 | } |
2163 | | |
2164 | 0 | else if (strcmp(args[0], "timeout") == 0) { |
2165 | 0 | qfprintf(stdout, "%s %s %s\n", args[0], args[1], args[2]); |
2166 | 0 | } |
2167 | | |
2168 | 0 | else if (strcmp(args[0], "mode") == 0) { |
2169 | 0 | qfprintf(stdout, "%s %s\n", args[0], args[1]); |
2170 | 0 | } |
2171 | | |
2172 | | /* It concerns user in global section and in userlist */ |
2173 | 0 | else if (strcmp(args[0], "user") == 0) { |
2174 | 0 | qfprintf(stdout, "%s %s ", args[0], HA_ANON_ID(g_key, args[1])); |
2175 | |
|
2176 | 0 | if (arg > 2) { |
2177 | 0 | qfprintf(stdout, "[...]\n"); |
2178 | 0 | } |
2179 | 0 | else { |
2180 | 0 | qfprintf(stdout, "\n"); |
2181 | 0 | } |
2182 | 0 | } |
2183 | | |
2184 | 0 | else if (strcmp(args[0], "bind") == 0) { |
2185 | 0 | qfprintf(stdout, "%s ", args[0]); |
2186 | 0 | qfprintf(stdout, "%s ", hash_ipanon(g_key, args[1], 1)); |
2187 | 0 | if (arg > 2) { |
2188 | 0 | qfprintf(stdout, "[...]\n"); |
2189 | 0 | } |
2190 | 0 | else { |
2191 | 0 | qfprintf(stdout, "\n"); |
2192 | 0 | } |
2193 | 0 | } |
2194 | | |
2195 | 0 | else if (strcmp(args[0], "server") == 0) { |
2196 | 0 | qfprintf(stdout, "%s %s ", args[0], HA_ANON_ID(g_key, args[1])); |
2197 | |
|
2198 | 0 | if (arg > 2) { |
2199 | 0 | qfprintf(stdout, "%s ", hash_ipanon(g_key, args[2], 1)); |
2200 | 0 | } |
2201 | 0 | if (arg > 3) { |
2202 | 0 | qfprintf(stdout, "[...]\n"); |
2203 | 0 | } |
2204 | 0 | else { |
2205 | 0 | qfprintf(stdout, "\n"); |
2206 | 0 | } |
2207 | 0 | } |
2208 | | |
2209 | 0 | else if (strcmp(args[0], "redirect") == 0) { |
2210 | 0 | qfprintf(stdout, "%s %s ", args[0], args[1]); |
2211 | |
|
2212 | 0 | if (strcmp(args[1], "prefix") == 0 || strcmp(args[1], "location") == 0) { |
2213 | 0 | qfprintf(stdout, "%s ", HA_ANON_PATH(g_key, args[2])); |
2214 | 0 | } |
2215 | 0 | else { |
2216 | 0 | qfprintf(stdout, "%s ", args[2]); |
2217 | 0 | } |
2218 | 0 | if (arg > 3) { |
2219 | 0 | qfprintf(stdout, "[...]"); |
2220 | 0 | } |
2221 | 0 | qfprintf(stdout, "\n"); |
2222 | 0 | } |
2223 | | |
2224 | 0 | else if (strcmp(args[0], "acl") == 0) { |
2225 | 0 | qfprintf(stdout, "%s %s %s ", args[0], HA_ANON_ID(g_key, args[1]), args[2]); |
2226 | |
|
2227 | 0 | if (arg > 3) { |
2228 | 0 | qfprintf(stdout, "[...]"); |
2229 | 0 | } |
2230 | 0 | qfprintf(stdout, "\n"); |
2231 | 0 | } |
2232 | | |
2233 | 0 | else if (strcmp(args[0], "log") == 0) { |
2234 | 0 | qfprintf(stdout, "log "); |
2235 | |
|
2236 | 0 | if (strcmp(args[1], "global") == 0) { |
2237 | 0 | qfprintf(stdout, "%s ", args[1]); |
2238 | 0 | } |
2239 | 0 | else { |
2240 | 0 | qfprintf(stdout, "%s ", hash_ipanon(g_key, args[1], 1)); |
2241 | 0 | } |
2242 | 0 | if (arg > 2) { |
2243 | 0 | qfprintf(stdout, "[...]"); |
2244 | 0 | } |
2245 | 0 | qfprintf(stdout, "\n"); |
2246 | 0 | } |
2247 | | |
2248 | 0 | else if (strcmp(args[0], "peer") == 0) { |
2249 | 0 | qfprintf(stdout, "%s %s ", args[0], HA_ANON_ID(g_key, args[1])); |
2250 | 0 | qfprintf(stdout, "%s ", hash_ipanon(g_key, args[2], 1)); |
2251 | |
|
2252 | 0 | if (arg > 3) { |
2253 | 0 | qfprintf(stdout, "[...]"); |
2254 | 0 | } |
2255 | 0 | qfprintf(stdout, "\n"); |
2256 | 0 | } |
2257 | | |
2258 | 0 | else if (strcmp(args[0], "use_backend") == 0) { |
2259 | 0 | qfprintf(stdout, "%s %s ", args[0], HA_ANON_ID(g_key, args[1])); |
2260 | |
|
2261 | 0 | if (arg > 2) { |
2262 | 0 | qfprintf(stdout, "[...]"); |
2263 | 0 | } |
2264 | 0 | qfprintf(stdout, "\n"); |
2265 | 0 | } |
2266 | | |
2267 | 0 | else if (strcmp(args[0], "default_backend") == 0) { |
2268 | 0 | qfprintf(stdout, "%s %s\n", args[0], HA_ANON_ID(g_key, args[1])); |
2269 | 0 | } |
2270 | | |
2271 | 0 | else if (strcmp(args[0], "source") == 0) { |
2272 | 0 | qfprintf(stdout, "%s %s ", args[0], hash_ipanon(g_key, args[1], 1)); |
2273 | |
|
2274 | 0 | if (arg > 2) { |
2275 | 0 | qfprintf(stdout, "[...]"); |
2276 | 0 | } |
2277 | 0 | qfprintf(stdout, "\n"); |
2278 | 0 | } |
2279 | | |
2280 | 0 | else if (strcmp(args[0], "nameserver") == 0) { |
2281 | 0 | qfprintf(stdout, "%s %s %s ", args[0], |
2282 | 0 | HA_ANON_ID(g_key, args[1]), hash_ipanon(g_key, args[2], 1)); |
2283 | 0 | if (arg > 3) { |
2284 | 0 | qfprintf(stdout, "[...]"); |
2285 | 0 | } |
2286 | 0 | qfprintf(stdout, "\n"); |
2287 | 0 | } |
2288 | | |
2289 | 0 | else if (strcmp(args[0], "http-request") == 0) { |
2290 | 0 | qfprintf(stdout, "%s %s ", args[0], args[1]); |
2291 | 0 | if (arg > 2) |
2292 | 0 | qfprintf(stdout, "[...]"); |
2293 | 0 | qfprintf(stdout, "\n"); |
2294 | 0 | } |
2295 | | |
2296 | 0 | else if (strcmp(args[0], "http-response") == 0) { |
2297 | 0 | qfprintf(stdout, "%s %s ", args[0], args[1]); |
2298 | 0 | if (arg > 2) |
2299 | 0 | qfprintf(stdout, "[...]"); |
2300 | 0 | qfprintf(stdout, "\n"); |
2301 | 0 | } |
2302 | | |
2303 | 0 | else if (strcmp(args[0], "http-after-response") == 0) { |
2304 | 0 | qfprintf(stdout, "%s %s ", args[0], args[1]); |
2305 | 0 | if (arg > 2) |
2306 | 0 | qfprintf(stdout, "[...]"); |
2307 | 0 | qfprintf(stdout, "\n"); |
2308 | 0 | } |
2309 | | |
2310 | 0 | else if (strcmp(args[0], "filter") == 0) { |
2311 | 0 | qfprintf(stdout, "%s %s ", args[0], args[1]); |
2312 | 0 | if (arg > 2) |
2313 | 0 | qfprintf(stdout, "[...]"); |
2314 | 0 | qfprintf(stdout, "\n"); |
2315 | 0 | } |
2316 | | |
2317 | 0 | else if (strcmp(args[0], "errorfile") == 0) { |
2318 | 0 | qfprintf(stdout, "%s %s %s\n", args[0], args[1], HA_ANON_PATH(g_key, args[2])); |
2319 | 0 | } |
2320 | | |
2321 | 0 | else if (strcmp(args[0], "cookie") == 0) { |
2322 | 0 | qfprintf(stdout, "%s %s ", args[0], HA_ANON_ID(g_key, args[1])); |
2323 | 0 | if (arg > 2) |
2324 | 0 | qfprintf(stdout, "%s ", args[2]); |
2325 | 0 | if (arg > 3) |
2326 | 0 | qfprintf(stdout, "[...]"); |
2327 | 0 | qfprintf(stdout, "\n"); |
2328 | 0 | } |
2329 | | |
2330 | 0 | else if (strcmp(args[0], "stats") == 0 && strcmp(args[1], "auth") == 0) { |
2331 | 0 | qfprintf(stdout, "%s %s %s\n", args[0], args[1], HA_ANON_STR(g_key, args[2])); |
2332 | 0 | } |
2333 | | |
2334 | 0 | else { |
2335 | | /* display up to 3 words and mask the rest which might be confidential */ |
2336 | 0 | for (i = 0; i < MIN(arg, 3); i++) { |
2337 | 0 | qfprintf(stdout, "%s ", args[i]); |
2338 | 0 | } |
2339 | 0 | if (arg > 3) { |
2340 | 0 | qfprintf(stdout, "[...]"); |
2341 | 0 | } |
2342 | 0 | qfprintf(stdout, "\n"); |
2343 | 0 | } |
2344 | 0 | } |
2345 | 0 | continue; |
2346 | 0 | } |
2347 | | /* end of config dump */ |
2348 | | |
2349 | | /* empty line */ |
2350 | 348k | if (!*args || !**args) |
2351 | 319k | continue; |
2352 | | |
2353 | | /* check for config macros */ |
2354 | 28.3k | if (*args[0] == '.') { |
2355 | 18.3k | if (strcmp(args[0], ".if") == 0) { |
2356 | 6.14k | const char *errptr = NULL; |
2357 | 6.14k | char *errmsg = NULL; |
2358 | 6.14k | int cond; |
2359 | 6.14k | char *w; |
2360 | | |
2361 | | /* remerge all words into a single expression */ |
2362 | 9.10k | for (w = *args; (w += strlen(w)) < outline + outlen - 1; *w = ' ') |
2363 | 2.96k | ; |
2364 | | |
2365 | 6.14k | nested_cond_lvl++; |
2366 | 6.14k | if (nested_cond_lvl >= MAXNESTEDCONDS) { |
2367 | 6 | ha_alert("parsing [%s:%d]: too many nested '.if', max is %d.\n", file, linenum, MAXNESTEDCONDS); |
2368 | 6 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2369 | 6 | goto err; |
2370 | 6 | } |
2371 | | |
2372 | 6.13k | if (nested_cond_lvl > 1 && |
2373 | 4.16k | (nested_conds[nested_cond_lvl - 1] == NESTED_COND_IF_DROP || |
2374 | 3.80k | nested_conds[nested_cond_lvl - 1] == NESTED_COND_IF_SKIP || |
2375 | 2.66k | nested_conds[nested_cond_lvl - 1] == NESTED_COND_ELIF_DROP || |
2376 | 2.43k | nested_conds[nested_cond_lvl - 1] == NESTED_COND_ELIF_SKIP || |
2377 | 2.99k | nested_conds[nested_cond_lvl - 1] == NESTED_COND_ELSE_DROP)) { |
2378 | 2.99k | nested_conds[nested_cond_lvl] = NESTED_COND_IF_SKIP; |
2379 | 2.99k | goto next_line; |
2380 | 2.99k | } |
2381 | | |
2382 | 3.14k | cond = cfg_eval_condition(args + 1, &errmsg, &errptr); |
2383 | 3.14k | if (cond < 0) { |
2384 | 531 | size_t newpos = sanitize_for_printing(args[1], errptr - args[1], 76); |
2385 | | |
2386 | 531 | ha_alert("parsing [%s:%d]: %s in '.if' at position %d:\n .if %s\n %*s\n", |
2387 | 531 | file, linenum, errmsg, |
2388 | 531 | (int)(errptr-args[1]+1), args[1], (int)(newpos+5), "^"); |
2389 | | |
2390 | 531 | free(errmsg); |
2391 | 531 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2392 | 531 | goto err; |
2393 | 531 | } |
2394 | | |
2395 | 2.61k | if (cond) |
2396 | 1.08k | nested_conds[nested_cond_lvl] = NESTED_COND_IF_TAKE; |
2397 | 1.53k | else |
2398 | 1.53k | nested_conds[nested_cond_lvl] = NESTED_COND_IF_DROP; |
2399 | | |
2400 | 2.61k | goto next_line; |
2401 | 3.14k | } |
2402 | 12.2k | else if (strcmp(args[0], ".elif") == 0) { |
2403 | 3.14k | const char *errptr = NULL; |
2404 | 3.14k | char *errmsg = NULL; |
2405 | 3.14k | int cond; |
2406 | 3.14k | char *w; |
2407 | | |
2408 | | /* remerge all words into a single expression */ |
2409 | 5.01k | for (w = *args; (w += strlen(w)) < outline + outlen - 1; *w = ' ') |
2410 | 1.87k | ; |
2411 | | |
2412 | 3.14k | if (!nested_cond_lvl) { |
2413 | 8 | ha_alert("parsing [%s:%d]: lone '.elif' with no matching '.if'.\n", file, linenum); |
2414 | 8 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2415 | 8 | goto err; |
2416 | 8 | } |
2417 | | |
2418 | 3.13k | if (nested_conds[nested_cond_lvl] == NESTED_COND_ELSE_TAKE || |
2419 | 3.13k | nested_conds[nested_cond_lvl] == NESTED_COND_ELSE_DROP) { |
2420 | 3 | ha_alert("parsing [%s:%d]: '.elif' after '.else' is not permitted.\n", file, linenum); |
2421 | 3 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2422 | 3 | goto err; |
2423 | 3 | } |
2424 | | |
2425 | 3.13k | if (nested_conds[nested_cond_lvl] == NESTED_COND_IF_TAKE || |
2426 | 2.87k | nested_conds[nested_cond_lvl] == NESTED_COND_IF_SKIP || |
2427 | 2.32k | nested_conds[nested_cond_lvl] == NESTED_COND_ELIF_TAKE || |
2428 | 1.95k | nested_conds[nested_cond_lvl] == NESTED_COND_ELIF_SKIP) { |
2429 | 1.95k | nested_conds[nested_cond_lvl] = NESTED_COND_ELIF_SKIP; |
2430 | 1.95k | goto next_line; |
2431 | 1.95k | } |
2432 | | |
2433 | 1.18k | cond = cfg_eval_condition(args + 1, &errmsg, &errptr); |
2434 | 1.18k | if (cond < 0) { |
2435 | 11 | size_t newpos = sanitize_for_printing(args[1], errptr - args[1], 74); |
2436 | | |
2437 | 11 | ha_alert("parsing [%s:%d]: %s in '.elif' at position %d:\n .elif %s\n %*s\n", |
2438 | 11 | file, linenum, errmsg, |
2439 | 11 | (int)(errptr-args[1]+1), args[1], (int)(newpos+7), "^"); |
2440 | | |
2441 | 11 | free(errmsg); |
2442 | 11 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2443 | 11 | goto err; |
2444 | 11 | } |
2445 | | |
2446 | 1.16k | if (cond) |
2447 | 676 | nested_conds[nested_cond_lvl] = NESTED_COND_ELIF_TAKE; |
2448 | 493 | else |
2449 | 493 | nested_conds[nested_cond_lvl] = NESTED_COND_ELIF_DROP; |
2450 | | |
2451 | 1.16k | goto next_line; |
2452 | 1.18k | } |
2453 | 9.09k | else if (strcmp(args[0], ".else") == 0) { |
2454 | 1.38k | if (*args[1]) { |
2455 | 7 | ha_alert("parsing [%s:%d]: Unexpected argument '%s' for '%s'.\n", |
2456 | 7 | file, linenum, args[1], args[0]); |
2457 | 7 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2458 | 7 | break; |
2459 | 7 | } |
2460 | | |
2461 | 1.37k | if (!nested_cond_lvl) { |
2462 | 4 | ha_alert("parsing [%s:%d]: lone '.else' with no matching '.if'.\n", file, linenum); |
2463 | 4 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2464 | 4 | goto err; |
2465 | 4 | } |
2466 | | |
2467 | 1.36k | if (nested_conds[nested_cond_lvl] == NESTED_COND_ELSE_TAKE || |
2468 | 1.36k | nested_conds[nested_cond_lvl] == NESTED_COND_ELSE_DROP) { |
2469 | 5 | ha_alert("parsing [%s:%d]: '.else' after '.else' is not permitted.\n", file, linenum); |
2470 | 5 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2471 | 5 | goto err; |
2472 | 5 | } |
2473 | | |
2474 | 1.36k | if (nested_conds[nested_cond_lvl] == NESTED_COND_IF_TAKE || |
2475 | 1.12k | nested_conds[nested_cond_lvl] == NESTED_COND_IF_SKIP || |
2476 | 642 | nested_conds[nested_cond_lvl] == NESTED_COND_ELIF_TAKE || |
2477 | 1.14k | nested_conds[nested_cond_lvl] == NESTED_COND_ELIF_SKIP) { |
2478 | 1.14k | nested_conds[nested_cond_lvl] = NESTED_COND_ELSE_DROP; |
2479 | 1.14k | } else { |
2480 | | /* otherwise we take the "else" */ |
2481 | 223 | nested_conds[nested_cond_lvl] = NESTED_COND_ELSE_TAKE; |
2482 | 223 | } |
2483 | 1.36k | goto next_line; |
2484 | 1.36k | } |
2485 | 7.71k | else if (strcmp(args[0], ".endif") == 0) { |
2486 | 3.27k | if (*args[1]) { |
2487 | 1 | ha_alert("parsing [%s:%d]: Unexpected argument '%s' for '%s'.\n", |
2488 | 1 | file, linenum, args[1], args[0]); |
2489 | 1 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2490 | 1 | break; |
2491 | 1 | } |
2492 | | |
2493 | 3.27k | if (!nested_cond_lvl) { |
2494 | 3 | ha_alert("parsing [%s:%d]: lone '.endif' with no matching '.if'.\n", file, linenum); |
2495 | 3 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2496 | 3 | break; |
2497 | 3 | } |
2498 | 3.27k | nested_cond_lvl--; |
2499 | 3.27k | goto next_line; |
2500 | 3.27k | } |
2501 | 18.3k | } |
2502 | | |
2503 | 14.4k | if (nested_cond_lvl && |
2504 | 6.20k | (nested_conds[nested_cond_lvl] == NESTED_COND_IF_DROP || |
2505 | 4.33k | nested_conds[nested_cond_lvl] == NESTED_COND_IF_SKIP || |
2506 | 3.18k | nested_conds[nested_cond_lvl] == NESTED_COND_ELIF_DROP || |
2507 | 2.87k | nested_conds[nested_cond_lvl] == NESTED_COND_ELIF_SKIP || |
2508 | 5.59k | nested_conds[nested_cond_lvl] == NESTED_COND_ELSE_DROP)) { |
2509 | | /* The current block is masked out by the conditions */ |
2510 | 5.59k | goto next_line; |
2511 | 5.59k | } |
2512 | | |
2513 | | /* .warning/.error/.notice/.diag */ |
2514 | 8.84k | if (*args[0] == '.' && !(global.mode & MODE_DISCOVERY)) { |
2515 | 1.90k | if (strcmp(args[0], ".alert") == 0) { |
2516 | 199 | if (*args[2]) { |
2517 | 198 | ha_alert("parsing [%s:%d]: Unexpected argument '%s' for '%s'. Use quotes if the message should contain spaces.\n", |
2518 | 198 | file, linenum, args[2], args[0]); |
2519 | 198 | err_code |= ERR_ALERT | ERR_FATAL; |
2520 | 198 | goto next_line; |
2521 | 198 | } |
2522 | | |
2523 | 1 | ha_alert("parsing [%s:%d]: '%s'.\n", file, linenum, args[1]); |
2524 | 1 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2525 | 1 | goto err; |
2526 | 199 | } |
2527 | 1.70k | else if (strcmp(args[0], ".warning") == 0) { |
2528 | 395 | if (*args[2]) { |
2529 | 194 | ha_alert("parsing [%s:%d]: Unexpected argument '%s' for '%s'. Use quotes if the message should contain spaces.\n", |
2530 | 194 | file, linenum, args[2], args[0]); |
2531 | 194 | err_code |= ERR_ALERT | ERR_FATAL; |
2532 | 194 | goto next_line; |
2533 | 194 | } |
2534 | | |
2535 | 201 | ha_warning("parsing [%s:%d]: '%s'.\n", file, linenum, args[1]); |
2536 | 201 | err_code |= ERR_WARN; |
2537 | 201 | goto next_line; |
2538 | 395 | } |
2539 | 1.31k | else if (strcmp(args[0], ".notice") == 0) { |
2540 | 543 | if (*args[2]) { |
2541 | 208 | ha_alert("parsing [%s:%d]: Unexpected argument '%s' for '%s'. Use quotes if the message should contain spaces.\n", |
2542 | 208 | file, linenum, args[2], args[0]); |
2543 | 208 | err_code |= ERR_ALERT | ERR_FATAL; |
2544 | 208 | goto next_line; |
2545 | 208 | } |
2546 | | |
2547 | 335 | ha_notice("parsing [%s:%d]: '%s'.\n", file, linenum, args[1]); |
2548 | 335 | goto next_line; |
2549 | 543 | } |
2550 | 770 | else if (strcmp(args[0], ".diag") == 0) { |
2551 | 508 | if (*args[2]) { |
2552 | 200 | ha_alert("parsing [%s:%d]: Unexpected argument '%s' for '%s'. Use quotes if the message should contain spaces.\n", |
2553 | 200 | file, linenum, args[2], args[0]); |
2554 | 200 | err_code |= ERR_ALERT | ERR_FATAL; |
2555 | 200 | goto next_line; |
2556 | 200 | } |
2557 | | |
2558 | 308 | ha_diag_warning("parsing [%s:%d]: '%s'.\n", file, linenum, args[1]); |
2559 | 308 | goto next_line; |
2560 | 508 | } |
2561 | 262 | else { |
2562 | 262 | ha_alert("parsing [%s:%d]: unknown directive '%s'.\n", file, linenum, args[0]); |
2563 | 262 | err_code |= ERR_ALERT | ERR_FATAL; |
2564 | 262 | fatal++; |
2565 | 262 | break; |
2566 | 262 | } |
2567 | 1.90k | } |
2568 | | |
2569 | | /* now check for empty args on the line. Only do that in normal |
2570 | | * mode to prevent double display during discovery pass. It relies |
2571 | | * on errptr as returned by parse_line() above. |
2572 | | */ |
2573 | 6.93k | if (!(global.mode & MODE_DISCOVERY)) { |
2574 | 6.93k | int check_arg; |
2575 | | |
2576 | 20.6k | for (check_arg = 0; check_arg < arg; check_arg++) { |
2577 | 16.4k | if (!*args[check_arg]) { |
2578 | 2.74k | static int warned_empty; |
2579 | 2.74k | size_t newpos; |
2580 | 2.74k | int suggest = 0; |
2581 | | |
2582 | | /* if an empty arg was found, its pointer should be in <errptr>, except |
2583 | | * for rare cases such as '\x00' etc. We need to check errptr in any case |
2584 | | * and if it's not set, we'll fall back to args's position in the output |
2585 | | * string instead (less accurate but still useful). |
2586 | | */ |
2587 | 2.74k | if (!errptr) { |
2588 | 217 | newpos = args[check_arg] - outline; |
2589 | 217 | if (newpos >= strlen(line)) |
2590 | 137 | newpos = 0; // impossible to report anything, start at the beginning. |
2591 | 217 | errptr = line + newpos; |
2592 | 2.53k | } else if (isalnum((uchar)*errptr) || *errptr == '_') { |
2593 | | /* looks like an environment variable */ |
2594 | 2.41k | suggest = 1; |
2595 | 2.41k | } |
2596 | | |
2597 | | /* sanitize input line in-place */ |
2598 | 2.74k | newpos = sanitize_for_printing(line, errptr - line, 80); |
2599 | 2.74k | ha_alert("parsing [%s:%d]: argument number %d at position %d is empty and marks the end of the " |
2600 | 2.74k | "argument list:\n %s\n %*s\n%s", |
2601 | 2.74k | file, linenum, check_arg, (int)(errptr - thisline + 1), line, (int)(newpos + 1), |
2602 | 2.74k | "^", (warned_empty++) ? "" : |
2603 | 2.74k | ("Aborting to prevent all subsequent arguments from being silently ignored. " |
2604 | 1 | "If this is caused by an environment variable expansion, please have a look at section " |
2605 | 1 | "2.3 of the configuration manual to find solutions to address this.\n")); |
2606 | | |
2607 | 2.74k | if (suggest) { |
2608 | 2.41k | const char *end = errptr; |
2609 | 2.41k | struct ist alt; |
2610 | | |
2611 | 2.83M | while (isalnum((uchar)*end) || *end == '_') |
2612 | 2.83M | end++; |
2613 | | |
2614 | 2.41k | if (end > errptr) { |
2615 | 2.34k | alt = env_suggest(ist2(errptr, end - errptr)); |
2616 | 2.34k | if (isttest(alt)) |
2617 | 117 | ha_notice("Hint: maybe you meant %.*s instead ?\n", (int)istlen(alt), istptr(alt)); |
2618 | 2.34k | } |
2619 | 2.41k | } |
2620 | | |
2621 | 2.74k | err_code |= ERR_ALERT | ERR_FATAL; |
2622 | 2.74k | fatal++; |
2623 | 2.74k | goto next_line; |
2624 | 2.74k | } |
2625 | 16.4k | } |
2626 | 6.93k | } |
2627 | | |
2628 | | /* check for keyword modifiers "no" and "default" */ |
2629 | 4.18k | if (strcmp(args[0], "no") == 0) { |
2630 | 1.68k | char *tmp; |
2631 | | |
2632 | 1.68k | kwm = KWM_NO; |
2633 | 1.68k | tmp = args[0]; |
2634 | 3.96k | for (arg=0; *args[arg+1]; arg++) |
2635 | 2.27k | args[arg] = args[arg+1]; // shift args after inversion |
2636 | 1.68k | *tmp = '\0'; // fix the next arg to \0 |
2637 | 1.68k | args[arg] = tmp; |
2638 | 1.68k | } |
2639 | 2.50k | else if (strcmp(args[0], "default") == 0) { |
2640 | 137 | kwm = KWM_DEF; |
2641 | 496 | for (arg=0; *args[arg+1]; arg++) |
2642 | 359 | args[arg] = args[arg+1]; // shift args after inversion |
2643 | 137 | } |
2644 | | |
2645 | 4.18k | if (kwm != KWM_STD && strcmp(args[0], "option") != 0 && |
2646 | 1.74k | strcmp(args[0], "log") != 0 && strcmp(args[0], "busy-polling") != 0 && |
2647 | 1.58k | strcmp(args[0], "set-dumpable") != 0 && strcmp(args[0], "strict-limits") != 0 && |
2648 | 1.40k | strcmp(args[0], "insecure-fork-wanted") != 0 && |
2649 | 1.33k | strcmp(args[0], "numa-cpu-mapping") != 0) { |
2650 | 1.25k | ha_alert("parsing [%s:%d]: negation/default currently " |
2651 | 1.25k | "supported only for options, log, busy-polling, " |
2652 | 1.25k | "set-dumpable, strict-limits, insecure-fork-wanted " |
2653 | 1.25k | "and numa-cpu-mapping.\n", file, linenum); |
2654 | 1.25k | err_code |= ERR_ALERT | ERR_FATAL; |
2655 | 1.25k | fatal++; |
2656 | 1.25k | } |
2657 | | |
2658 | | /* detect section start */ |
2659 | 4.18k | list_for_each_entry(ics, §ions, list) { |
2660 | 0 | if (strcmp(args[0], ics->section_name) == 0 && ics->section_parser) { |
2661 | 0 | cursection = ics->section_name; |
2662 | 0 | pcs = cs; |
2663 | 0 | cs = ics; |
2664 | 0 | free(global.cfg_curr_section); |
2665 | 0 | global.cfg_curr_section = strdup(*args[1] ? args[1] : args[0]); |
2666 | 0 | check_section_position(args[0], file, linenum); |
2667 | 0 | break; |
2668 | 0 | } |
2669 | 0 | } |
2670 | | |
2671 | 4.18k | if (pcs) { |
2672 | 0 | struct cfg_section *psect; |
2673 | 0 | int status; |
2674 | | |
2675 | | |
2676 | | /* look for every post_section_parser for the previous section name */ |
2677 | 0 | list_for_each_entry(psect, §ions, list) { |
2678 | 0 | if (strcmp(pcs->section_name, psect->section_name) == 0 && |
2679 | 0 | psect->post_section_parser) { |
2680 | | |
2681 | | /* don't call post_section_parser in MODE_DISCOVERY */ |
2682 | 0 | if (global.mode & MODE_DISCOVERY) |
2683 | 0 | goto section_parser; |
2684 | | |
2685 | 0 | status = psect->post_section_parser(); |
2686 | 0 | err_code |= status; |
2687 | 0 | if (status & ERR_FATAL) |
2688 | 0 | fatal++; |
2689 | |
|
2690 | 0 | if (err_code & ERR_ABORT) |
2691 | 0 | goto err; |
2692 | 0 | } |
2693 | 0 | } |
2694 | 0 | } |
2695 | 4.18k | pcs = NULL; |
2696 | | |
2697 | 4.18k | section_parser: |
2698 | 4.18k | if (!cs) { |
2699 | | /* ignore unknown section names during the first read in MODE_DISCOVERY */ |
2700 | 4.18k | if (global.mode & MODE_DISCOVERY) |
2701 | 0 | continue; |
2702 | 4.18k | ha_alert("parsing [%s:%d]: unknown keyword '%s' out of section.\n", file, linenum, args[0]); |
2703 | 4.18k | err_code |= ERR_ALERT | ERR_FATAL; |
2704 | 4.18k | fatal++; |
2705 | 4.18k | } else { |
2706 | 0 | int status; |
2707 | | |
2708 | | /* read only the "global" and "program" sections in MODE_DISCOVERY */ |
2709 | 0 | if (((global.mode & MODE_DISCOVERY) && (strcmp(cs->section_name, "global") != 0) |
2710 | 0 | && (strcmp(cs->section_name, "program") != 0))) |
2711 | 0 | continue; |
2712 | | |
2713 | 0 | status = cs->section_parser(file, linenum, args, kwm); |
2714 | 0 | err_code |= status; |
2715 | 0 | if (status & ERR_FATAL) |
2716 | 0 | fatal++; |
2717 | |
|
2718 | 0 | if (err_code & ERR_ABORT) |
2719 | 0 | goto err; |
2720 | 0 | } |
2721 | 4.18k | } |
2722 | | |
2723 | 2.41k | if (missing_lf != -1) { |
2724 | 1.77k | ha_alert("parsing [%s:%d]: Missing LF on last line, file might have been truncated at position %d.\n", |
2725 | 1.77k | file, linenum, (missing_lf + 1)); |
2726 | 1.77k | err_code |= ERR_ALERT | ERR_FATAL; |
2727 | 1.77k | } |
2728 | | |
2729 | 2.41k | ha_free(&global.cfg_curr_section); |
2730 | | |
2731 | | /* call post_section_parser of the last section when there is no more lines */ |
2732 | 2.41k | if (cs) { |
2733 | 0 | struct cfg_section *psect; |
2734 | 0 | int status; |
2735 | | |
2736 | | /* don't call post_section_parser in MODE_DISCOVERY */ |
2737 | 0 | if (!(global.mode & MODE_DISCOVERY)) { |
2738 | 0 | list_for_each_entry(psect, §ions, list) { |
2739 | 0 | if (strcmp(cs->section_name, psect->section_name) == 0 && |
2740 | 0 | psect->post_section_parser) { |
2741 | |
|
2742 | 0 | status = psect->post_section_parser(); |
2743 | 0 | if (status & ERR_FATAL) |
2744 | 0 | fatal++; |
2745 | |
|
2746 | 0 | err_code |= status; |
2747 | |
|
2748 | 0 | if (err_code & ERR_ABORT) |
2749 | 0 | goto err; |
2750 | |
|
2751 | 0 | } |
2752 | 0 | } |
2753 | 0 | } |
2754 | 0 | } |
2755 | | |
2756 | 2.41k | if (nested_cond_lvl) { |
2757 | 345 | ha_alert("parsing [%s:%d]: non-terminated '.if' block.\n", file, linenum); |
2758 | 345 | err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; |
2759 | 345 | } |
2760 | | |
2761 | 2.98k | err: |
2762 | 2.98k | ha_free(&cfg_scope); |
2763 | 2.98k | cursection = NULL; |
2764 | 2.98k | free(thisline); |
2765 | 2.98k | free(outline); |
2766 | 2.98k | global.cfg_curr_line = 0; |
2767 | 2.98k | global.cfg_curr_file = NULL; |
2768 | | |
2769 | 2.98k | return err_code; |
2770 | 2.41k | } |
2771 | | |
2772 | | /* |
2773 | | * Returns the error code, 0 if OK, or any combination of : |
2774 | | * - ERR_ABORT: must abort ASAP |
2775 | | * - ERR_FATAL: we can continue parsing but not start the service |
2776 | | * - ERR_WARN: a warning has been emitted |
2777 | | * - ERR_ALERT: an alert has been emitted |
2778 | | * Only the two first ones can stop processing, the two others are just |
2779 | | * indicators. |
2780 | | */ |
2781 | | int check_config_validity() |
2782 | 0 | { |
2783 | 0 | int cfgerr = 0; |
2784 | 0 | struct proxy *init_proxies_list = NULL; |
2785 | 0 | struct stktable *t; |
2786 | 0 | struct server *newsrv = NULL; |
2787 | 0 | struct mt_list back; |
2788 | 0 | int err_code = 0; |
2789 | 0 | unsigned int next_pxid = 1; |
2790 | 0 | struct bind_conf *bind_conf; |
2791 | 0 | char *err; |
2792 | 0 | struct cfg_postparser *postparser; |
2793 | 0 | struct resolvers *curr_resolvers = NULL; |
2794 | 0 | int i; |
2795 | |
|
2796 | 0 | bind_conf = NULL; |
2797 | | /* |
2798 | | * Now, check for the integrity of all that we have collected. |
2799 | | */ |
2800 | |
|
2801 | 0 | if (!global.tune.max_http_hdr) |
2802 | 0 | global.tune.max_http_hdr = MAX_HTTP_HDR; |
2803 | |
|
2804 | 0 | if (!global.tune.cookie_len) |
2805 | 0 | global.tune.cookie_len = CAPTURE_LEN; |
2806 | |
|
2807 | 0 | if (!global.tune.requri_len) |
2808 | 0 | global.tune.requri_len = REQURI_LEN; |
2809 | |
|
2810 | 0 | if (!global.thread_limit) |
2811 | 0 | global.thread_limit = MAX_THREADS; |
2812 | |
|
2813 | | #if defined(USE_THREAD) |
2814 | | if (thread_cpus_enabled_at_boot > global.thread_limit) |
2815 | | thread_cpus_enabled_at_boot = global.thread_limit; |
2816 | | #endif |
2817 | 0 | if (global.nbthread > global.thread_limit) { |
2818 | 0 | ha_warning("nbthread forced to a higher value (%d) than the configured thread-hard-limit (%d), enforcing the limit. " |
2819 | 0 | "Please fix either value to remove this warning.\n", |
2820 | 0 | global.nbthread, global.thread_limit); |
2821 | 0 | global.nbthread = global.thread_limit; |
2822 | 0 | } |
2823 | | |
2824 | | /* in the worst case these were supposed to be set in thread_detect_count() */ |
2825 | 0 | BUG_ON(!global.nbthread); |
2826 | 0 | BUG_ON(!global.nbtgroups); |
2827 | |
|
2828 | 0 | if (thread_map_to_groups() < 0) { |
2829 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
2830 | 0 | goto out; |
2831 | 0 | } |
2832 | | |
2833 | 0 | pool_head_requri = create_pool("requri", global.tune.requri_len , MEM_F_SHARED); |
2834 | |
|
2835 | 0 | pool_head_capture = create_pool("capture", global.tune.cookie_len, MEM_F_SHARED); |
2836 | | |
2837 | | /* Post initialisation of the users and groups lists. */ |
2838 | 0 | err_code = userlist_postinit(); |
2839 | 0 | if (err_code != ERR_NONE) |
2840 | 0 | goto out; |
2841 | | |
2842 | | /* first, we will invert the proxy list order */ |
2843 | 0 | curproxy = NULL; |
2844 | 0 | while (proxies_list) { |
2845 | 0 | struct proxy *next; |
2846 | |
|
2847 | 0 | next = proxies_list->next; |
2848 | 0 | proxies_list->next = curproxy; |
2849 | 0 | curproxy = proxies_list; |
2850 | 0 | if (!next) |
2851 | 0 | break; |
2852 | 0 | proxies_list = next; |
2853 | 0 | } |
2854 | | |
2855 | | /* |
2856 | | * we must finish to initialize certain things on the servers, |
2857 | | * as some of the fields may be accessed soon |
2858 | | */ |
2859 | 0 | MT_LIST_FOR_EACH_ENTRY_LOCKED(newsrv, &servers_list, global_list, back) { |
2860 | 0 | err_code |= srv_preinit(newsrv); |
2861 | 0 | if (err_code & ERR_CODE) |
2862 | 0 | goto out; |
2863 | 0 | } |
2864 | | |
2865 | | /* starting to initialize the main proxies list */ |
2866 | 0 | init_proxies_list = proxies_list; |
2867 | |
|
2868 | 0 | init_proxies_list_stage1: |
2869 | 0 | for (curproxy = init_proxies_list; curproxy; curproxy = curproxy->next) { |
2870 | 0 | struct switching_rule *rule; |
2871 | 0 | struct server_rule *srule; |
2872 | 0 | struct sticking_rule *mrule; |
2873 | 0 | struct logger *tmplogger; |
2874 | 0 | unsigned int next_id; |
2875 | |
|
2876 | 0 | proxy_init_per_thr(curproxy); |
2877 | 0 | if (!(curproxy->cap & PR_CAP_INT) && curproxy->uuid < 0) { |
2878 | | /* proxy ID not set, use automatic numbering with first |
2879 | | * spare entry starting with next_pxid. We don't assign |
2880 | | * numbers for internal proxies as they may depend on |
2881 | | * build or config options and we don't want them to |
2882 | | * possibly reuse existing IDs. |
2883 | | */ |
2884 | 0 | next_pxid = proxy_get_next_id(next_pxid); |
2885 | 0 | curproxy->uuid = next_pxid; |
2886 | 0 | proxy_index_id(curproxy); |
2887 | 0 | } |
2888 | |
|
2889 | 0 | if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize >= (256 << 20) && ONLY_ONCE()) { |
2890 | 0 | ha_alert("global.tune.bufsize must be below 256 MB when HTTP is in use (current value = %d).\n", |
2891 | 0 | global.tune.bufsize); |
2892 | 0 | cfgerr++; |
2893 | 0 | } |
2894 | | |
2895 | | /* next IDs are shifted even if the proxy is disabled, this |
2896 | | * guarantees that a proxy that is temporarily disabled in the |
2897 | | * configuration doesn't cause a renumbering. Internal proxies |
2898 | | * that are not assigned a static ID must never shift the IDs |
2899 | | * either since they may appear in any order (Lua, logs, etc). |
2900 | | * The GLOBAL proxy that carries the stats socket has its ID |
2901 | | * forced to zero. |
2902 | | */ |
2903 | 0 | if (curproxy->uuid >= 0) |
2904 | 0 | next_pxid++; |
2905 | |
|
2906 | 0 | if (curproxy->flags & PR_FL_DISABLED) { |
2907 | | /* ensure we don't keep listeners uselessly bound. We |
2908 | | * can't disable their listeners yet (fdtab not |
2909 | | * allocated yet) but let's skip them. |
2910 | | */ |
2911 | 0 | if (curproxy->table) { |
2912 | 0 | ha_free(&curproxy->table->peers.name); |
2913 | 0 | curproxy->table->peers.p = NULL; |
2914 | 0 | } |
2915 | 0 | continue; |
2916 | 0 | } |
2917 | | |
2918 | | /* The current proxy is referencing a default proxy. We must |
2919 | | * finalize its config, but only once. If the default proxy is |
2920 | | * ready (PR_FL_READY) it means it was already fully configured. |
2921 | | */ |
2922 | 0 | if (curproxy->defpx) { |
2923 | 0 | if (!(curproxy->defpx->flags & PR_FL_READY)) { |
2924 | | /* check validity for 'tcp-request' layer 4/5/6/7 rules */ |
2925 | 0 | cfgerr += check_action_rules(&curproxy->defpx->tcp_req.l4_rules, curproxy->defpx, &err_code); |
2926 | 0 | cfgerr += check_action_rules(&curproxy->defpx->tcp_req.l5_rules, curproxy->defpx, &err_code); |
2927 | 0 | cfgerr += check_action_rules(&curproxy->defpx->tcp_req.inspect_rules, curproxy->defpx, &err_code); |
2928 | 0 | cfgerr += check_action_rules(&curproxy->defpx->tcp_rep.inspect_rules, curproxy->defpx, &err_code); |
2929 | 0 | cfgerr += check_action_rules(&curproxy->defpx->http_req_rules, curproxy->defpx, &err_code); |
2930 | 0 | cfgerr += check_action_rules(&curproxy->defpx->http_res_rules, curproxy->defpx, &err_code); |
2931 | 0 | cfgerr += check_action_rules(&curproxy->defpx->http_after_res_rules, curproxy->defpx, &err_code); |
2932 | |
|
2933 | 0 | err = NULL; |
2934 | 0 | i = smp_resolve_args(curproxy->defpx, &err); |
2935 | 0 | cfgerr += i; |
2936 | 0 | if (i) { |
2937 | 0 | indent_msg(&err, 8); |
2938 | 0 | ha_alert("%s%s\n", i > 1 ? "multiple argument resolution errors:" : "", err); |
2939 | 0 | ha_free(&err); |
2940 | 0 | } |
2941 | 0 | else |
2942 | 0 | cfgerr += acl_find_targets(curproxy->defpx); |
2943 | | |
2944 | | /* default proxy is now ready. Set the right FE/BE capabilities */ |
2945 | 0 | curproxy->defpx->flags |= PR_FL_READY; |
2946 | 0 | } |
2947 | 0 | } |
2948 | | |
2949 | | /* check and reduce the bind-proc of each listener */ |
2950 | 0 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
2951 | 0 | int mode = conn_pr_mode_to_proto_mode(curproxy->mode); |
2952 | 0 | const struct mux_proto_list *mux_ent; |
2953 | 0 | int ret; |
2954 | | |
2955 | | |
2956 | | /* Check the mux protocols, if any; before the check the ALPN */ |
2957 | 0 | if (bind_conf->xprt && bind_conf->xprt == xprt_get(XPRT_QUIC)) { |
2958 | 0 | if (!bind_conf->mux_proto) { |
2959 | | /* No protocol was specified. If we're using QUIC at the transport |
2960 | | * layer, we'll instantiate it as a mux as well. If QUIC is not |
2961 | | * compiled in, this will remain NULL. |
2962 | | */ |
2963 | 0 | bind_conf->mux_proto = get_mux_proto(ist("quic")); |
2964 | 0 | } |
2965 | 0 | if (bind_conf->options & BC_O_ACC_PROXY) { |
2966 | 0 | ha_alert("Binding [%s:%d] for %s %s: QUIC protocol does not support PROXY protocol yet." |
2967 | 0 | " 'accept-proxy' option cannot be used with a QUIC listener.\n", |
2968 | 0 | bind_conf->file, bind_conf->line, |
2969 | 0 | proxy_type_str(curproxy), curproxy->id); |
2970 | 0 | cfgerr++; |
2971 | 0 | } |
2972 | 0 | } |
2973 | |
|
2974 | 0 | if (bind_conf->mux_proto) { |
2975 | | /* it is possible that an incorrect mux was referenced |
2976 | | * due to the proxy's mode not being taken into account |
2977 | | * on first pass. Let's adjust it now. |
2978 | | */ |
2979 | 0 | mux_ent = conn_get_best_mux_entry(bind_conf->mux_proto->token, PROTO_SIDE_FE, mode); |
2980 | |
|
2981 | 0 | if (!mux_ent || !isteq(mux_ent->token, bind_conf->mux_proto->token)) { |
2982 | 0 | ha_alert("%s '%s' : MUX protocol '%.*s' is not usable for 'bind %s' at [%s:%d].\n", |
2983 | 0 | proxy_type_str(curproxy), curproxy->id, |
2984 | 0 | (int)bind_conf->mux_proto->token.len, |
2985 | 0 | bind_conf->mux_proto->token.ptr, |
2986 | 0 | bind_conf->arg, bind_conf->file, bind_conf->line); |
2987 | 0 | cfgerr++; |
2988 | 0 | } else { |
2989 | 0 | if ((mux_ent->mux->flags & MX_FL_FRAMED) && !(bind_conf->options & BC_O_USE_SOCK_DGRAM)) { |
2990 | 0 | ha_alert("%s '%s' : frame-based MUX protocol '%.*s' is incompatible with stream transport of 'bind %s' at [%s:%d].\n", |
2991 | 0 | proxy_type_str(curproxy), curproxy->id, |
2992 | 0 | (int)bind_conf->mux_proto->token.len, |
2993 | 0 | bind_conf->mux_proto->token.ptr, |
2994 | 0 | bind_conf->arg, bind_conf->file, bind_conf->line); |
2995 | 0 | cfgerr++; |
2996 | 0 | } |
2997 | 0 | else if (!(mux_ent->mux->flags & MX_FL_FRAMED) && !(bind_conf->options & BC_O_USE_SOCK_STREAM)) { |
2998 | 0 | ha_alert("%s '%s' : stream-based MUX protocol '%.*s' is incompatible with framed transport of 'bind %s' at [%s:%d].\n", |
2999 | 0 | proxy_type_str(curproxy), curproxy->id, |
3000 | 0 | (int)bind_conf->mux_proto->token.len, |
3001 | 0 | bind_conf->mux_proto->token.ptr, |
3002 | 0 | bind_conf->arg, bind_conf->file, bind_conf->line); |
3003 | 0 | cfgerr++; |
3004 | 0 | } |
3005 | 0 | } |
3006 | | |
3007 | | /* update the mux */ |
3008 | 0 | bind_conf->mux_proto = mux_ent; |
3009 | 0 | } |
3010 | | |
3011 | | |
3012 | | /* HTTP frontends with "h2" as ALPN/NPN will work in |
3013 | | * HTTP/2 and absolutely require buffers 16kB or larger. |
3014 | | */ |
3015 | | #ifdef USE_OPENSSL |
3016 | | /* no-alpn ? If so, it's the right moment to remove it */ |
3017 | | if (bind_conf->ssl_conf.alpn_str && !bind_conf->ssl_conf.alpn_len) { |
3018 | | ha_free(&bind_conf->ssl_conf.alpn_str); |
3019 | | } |
3020 | | #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation |
3021 | | else if (!bind_conf->ssl_conf.alpn_str && !bind_conf->ssl_conf.npn_str && |
3022 | | ((bind_conf->options & BC_O_USE_SSL) || bind_conf->xprt == xprt_get(XPRT_QUIC)) && |
3023 | | curproxy->mode == PR_MODE_HTTP && global.tune.bufsize >= 16384) { |
3024 | | |
3025 | | /* Neither ALPN nor NPN were explicitly set nor disabled, we're |
3026 | | * in HTTP mode with an SSL or QUIC listener, we can enable ALPN. |
3027 | | * Note that it's in binary form. First we try to set the ALPN from |
3028 | | * mux proto if set. Otherwise rely on the default ALPN. |
3029 | | */ |
3030 | | if (bind_conf->mux_proto && bind_conf->mux_proto->alpn) |
3031 | | bind_conf->ssl_conf.alpn_str = strdup(bind_conf->mux_proto->alpn); |
3032 | | else if (bind_conf->xprt == xprt_get(XPRT_QUIC)) |
3033 | | bind_conf->ssl_conf.alpn_str = strdup("\002h3"); |
3034 | | else |
3035 | | bind_conf->ssl_conf.alpn_str = strdup("\002h2\010http/1.1"); |
3036 | | |
3037 | | if (!bind_conf->ssl_conf.alpn_str) { |
3038 | | ha_alert("Proxy '%s': out of memory while trying to allocate a default alpn string in 'bind %s' at [%s:%d].\n", |
3039 | | curproxy->id, bind_conf->arg, bind_conf->file, bind_conf->line); |
3040 | | cfgerr++; |
3041 | | err_code |= ERR_FATAL | ERR_ALERT; |
3042 | | goto out; |
3043 | | } |
3044 | | bind_conf->ssl_conf.alpn_len = strlen(bind_conf->ssl_conf.alpn_str); |
3045 | | } |
3046 | | #endif |
3047 | | |
3048 | | if (curproxy->mode == PR_MODE_HTTP && global.tune.bufsize < 16384) { |
3049 | | #ifdef OPENSSL_NPN_NEGOTIATED |
3050 | | /* check NPN */ |
3051 | | if (bind_conf->ssl_conf.npn_str && strstr(bind_conf->ssl_conf.npn_str, "\002h2")) { |
3052 | | ha_alert("HTTP frontend '%s' enables HTTP/2 via NPN at [%s:%d], so global.tune.bufsize must be at least 16384 bytes (%d now).\n", |
3053 | | curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize); |
3054 | | cfgerr++; |
3055 | | } |
3056 | | #endif |
3057 | | #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation |
3058 | | /* check ALPN */ |
3059 | | if (bind_conf->ssl_conf.alpn_str && strstr(bind_conf->ssl_conf.alpn_str, "\002h2")) { |
3060 | | ha_alert("HTTP frontend '%s' enables HTTP/2 via ALPN at [%s:%d], so global.tune.bufsize must be at least 16384 bytes (%d now).\n", |
3061 | | curproxy->id, bind_conf->file, bind_conf->line, global.tune.bufsize); |
3062 | | cfgerr++; |
3063 | | } |
3064 | | #endif |
3065 | | } /* HTTP && bufsize < 16384 */ |
3066 | | #endif |
3067 | |
|
3068 | | #ifdef USE_QUIC |
3069 | | if (bind_conf->xprt == xprt_get(XPRT_QUIC)) { |
3070 | | const struct quic_cc_algo *cc_algo = bind_conf->quic_cc_algo ? |
3071 | | bind_conf->quic_cc_algo : default_quic_cc_algo; |
3072 | | |
3073 | | if (!(cc_algo->flags & QUIC_CC_ALGO_FL_OPT_PACING) && |
3074 | | !(quic_tune.fe.fb_opts & QUIC_TUNE_FB_TX_PACING)) { |
3075 | | ha_warning("Binding [%s:%d] for %s %s: using the selected congestion algorithm without pacing may cause slowdowns or high loss rates during transfers.\n", |
3076 | | bind_conf->file, bind_conf->line, |
3077 | | proxy_type_str(curproxy), curproxy->id); |
3078 | | err_code |= ERR_WARN; |
3079 | | } |
3080 | | } |
3081 | | #endif /* USE_QUIC */ |
3082 | | |
3083 | | /* finish the bind setup */ |
3084 | 0 | ret = bind_complete_thread_setup(bind_conf, &err_code); |
3085 | 0 | if (ret != 0) { |
3086 | 0 | cfgerr += ret; |
3087 | 0 | if (err_code & ERR_FATAL) |
3088 | 0 | goto out; |
3089 | 0 | } |
3090 | | |
3091 | 0 | if (bind_generate_guid(bind_conf)) { |
3092 | 0 | cfgerr++; |
3093 | 0 | err_code |= ERR_FATAL | ERR_ALERT; |
3094 | 0 | goto out; |
3095 | 0 | } |
3096 | 0 | } |
3097 | | |
3098 | 0 | switch (curproxy->mode) { |
3099 | 0 | case PR_MODE_TCP: |
3100 | 0 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
3101 | 0 | cfgerr += proxy_cfg_ensure_no_log(curproxy); |
3102 | 0 | break; |
3103 | | |
3104 | 0 | case PR_MODE_HTTP: |
3105 | 0 | cfgerr += proxy_cfg_ensure_no_log(curproxy); |
3106 | 0 | curproxy->http_needed = 1; |
3107 | 0 | break; |
3108 | | |
3109 | 0 | case PR_MODE_CLI: |
3110 | 0 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
3111 | 0 | cfgerr += proxy_cfg_ensure_no_log(curproxy); |
3112 | 0 | break; |
3113 | | |
3114 | 0 | case PR_MODE_SYSLOG: |
3115 | | /* this mode is initialized as the classic tcp proxy */ |
3116 | 0 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
3117 | 0 | break; |
3118 | | |
3119 | 0 | case PR_MODE_SPOP: |
3120 | 0 | cfgerr += proxy_cfg_ensure_no_http(curproxy); |
3121 | 0 | cfgerr += proxy_cfg_ensure_no_log(curproxy); |
3122 | 0 | break; |
3123 | | |
3124 | 0 | case PR_MODE_PEERS: |
3125 | 0 | case PR_MODES: |
3126 | | /* should not happen, bug gcc warn missing switch statement */ |
3127 | 0 | ha_alert("%s '%s' cannot initialize this proxy mode (peers) in this way. NOTE: PLEASE REPORT THIS TO DEVELOPERS AS YOU'RE NOT SUPPOSED TO BE ABLE TO CREATE A CONFIGURATION TRIGGERING THIS!\n", |
3128 | 0 | proxy_type_str(curproxy), curproxy->id); |
3129 | 0 | cfgerr++; |
3130 | 0 | break; |
3131 | 0 | } |
3132 | | |
3133 | 0 | if (!(curproxy->cap & PR_CAP_INT) && (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->conf.listeners)) { |
3134 | 0 | ha_warning("%s '%s' has no 'bind' directive. Please declare it as a backend if this was intended.\n", |
3135 | 0 | proxy_type_str(curproxy), curproxy->id); |
3136 | 0 | err_code |= ERR_WARN; |
3137 | 0 | } |
3138 | |
|
3139 | 0 | if (curproxy->cap & PR_CAP_BE) { |
3140 | 0 | if (curproxy->lbprm.algo & BE_LB_KIND) { |
3141 | 0 | if (curproxy->options & PR_O_TRANSP) { |
3142 | 0 | ha_alert("%s '%s' cannot use both transparent and balance mode.\n", |
3143 | 0 | proxy_type_str(curproxy), curproxy->id); |
3144 | 0 | cfgerr++; |
3145 | 0 | } |
3146 | | #ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS |
3147 | | else if (curproxy->srv == NULL) { |
3148 | | ha_alert("%s '%s' needs at least 1 server in balance mode.\n", |
3149 | | proxy_type_str(curproxy), curproxy->id); |
3150 | | cfgerr++; |
3151 | | } |
3152 | | #endif |
3153 | 0 | else if (curproxy->options & PR_O_DISPATCH) { |
3154 | 0 | ha_warning("dispatch address of %s '%s' will be ignored in balance mode.\n", |
3155 | 0 | proxy_type_str(curproxy), curproxy->id); |
3156 | 0 | err_code |= ERR_WARN; |
3157 | 0 | } |
3158 | 0 | } |
3159 | 0 | else if (!(curproxy->options & (PR_O_TRANSP | PR_O_DISPATCH))) { |
3160 | | /* If no LB algo is set in a backend, and we're not in |
3161 | | * transparent mode, dispatch mode nor proxy mode, we |
3162 | | * want to use balance random by default. |
3163 | | */ |
3164 | 0 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
3165 | 0 | curproxy->lbprm.algo |= BE_LB_ALGO_RND; |
3166 | 0 | } |
3167 | 0 | } |
3168 | |
|
3169 | 0 | if (curproxy->options & PR_O_DISPATCH) |
3170 | 0 | curproxy->options &= ~PR_O_TRANSP; |
3171 | 0 | else if (curproxy->options & PR_O_TRANSP) |
3172 | 0 | curproxy->options &= ~PR_O_DISPATCH; |
3173 | |
|
3174 | 0 | if ((curproxy->tcpcheck_rules.flags & TCPCHK_RULES_UNUSED_HTTP_RS)) { |
3175 | 0 | ha_warning("%s '%s' uses http-check rules without 'option httpchk', so the rules are ignored.\n", |
3176 | 0 | proxy_type_str(curproxy), curproxy->id); |
3177 | 0 | err_code |= ERR_WARN; |
3178 | 0 | } |
3179 | |
|
3180 | 0 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_TCPCHK_CHK && |
3181 | 0 | (curproxy->tcpcheck_rules.flags & TCPCHK_RULES_PROTO_CHK) != TCPCHK_RULES_HTTP_CHK) { |
3182 | 0 | if (curproxy->options & PR_O_DISABLE404) { |
3183 | 0 | ha_warning("'%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
3184 | 0 | "disable-on-404", proxy_type_str(curproxy), curproxy->id); |
3185 | 0 | err_code |= ERR_WARN; |
3186 | 0 | curproxy->options &= ~PR_O_DISABLE404; |
3187 | 0 | } |
3188 | 0 | if (curproxy->options2 & PR_O2_CHK_SNDST) { |
3189 | 0 | ha_warning("'%s' will be ignored for %s '%s' (requires 'option httpchk').\n", |
3190 | 0 | "send-state", proxy_type_str(curproxy), curproxy->id); |
3191 | 0 | err_code |= ERR_WARN; |
3192 | 0 | curproxy->options2 &= ~PR_O2_CHK_SNDST; |
3193 | 0 | } |
3194 | 0 | } |
3195 | |
|
3196 | 0 | if ((curproxy->options2 & PR_O2_CHK_ANY) == PR_O2_EXT_CHK) { |
3197 | 0 | if (!global.external_check) { |
3198 | 0 | ha_alert("Proxy '%s' : '%s' unable to find required 'global.external-check'.\n", |
3199 | 0 | curproxy->id, "option external-check"); |
3200 | 0 | cfgerr++; |
3201 | 0 | } |
3202 | 0 | if (!curproxy->check_command) { |
3203 | 0 | ha_alert("Proxy '%s' : '%s' unable to find required 'external-check command'.\n", |
3204 | 0 | curproxy->id, "option external-check"); |
3205 | 0 | cfgerr++; |
3206 | 0 | } |
3207 | 0 | if (!(global.tune.options & GTUNE_INSECURE_FORK)) { |
3208 | 0 | ha_warning("Proxy '%s' : 'insecure-fork-wanted' not enabled in the global section, '%s' will likely fail.\n", |
3209 | 0 | curproxy->id, "option external-check"); |
3210 | 0 | err_code |= ERR_WARN; |
3211 | 0 | } |
3212 | 0 | } |
3213 | |
|
3214 | 0 | if (curproxy->email_alert.flags & PR_EMAIL_ALERT_SET) { |
3215 | 0 | if (!(curproxy->email_alert.mailers.name && curproxy->email_alert.from && curproxy->email_alert.to)) { |
3216 | 0 | ha_warning("'email-alert' will be ignored for %s '%s' (the presence any of " |
3217 | 0 | "'email-alert from', 'email-alert level' 'email-alert mailers', " |
3218 | 0 | "'email-alert myhostname', or 'email-alert to' " |
3219 | 0 | "requires each of 'email-alert from', 'email-alert mailers' and 'email-alert to' " |
3220 | 0 | "to be present).\n", |
3221 | 0 | proxy_type_str(curproxy), curproxy->id); |
3222 | 0 | err_code |= ERR_WARN; |
3223 | 0 | free_email_alert(curproxy); |
3224 | 0 | } |
3225 | 0 | if (!curproxy->email_alert.myhostname) |
3226 | 0 | curproxy->email_alert.myhostname = strdup(hostname); |
3227 | 0 | } |
3228 | |
|
3229 | 0 | if (curproxy->check_command) { |
3230 | 0 | int clear = 0; |
3231 | 0 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
3232 | 0 | ha_warning("'%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
3233 | 0 | "external-check command", proxy_type_str(curproxy), curproxy->id); |
3234 | 0 | err_code |= ERR_WARN; |
3235 | 0 | clear = 1; |
3236 | 0 | } |
3237 | 0 | if (curproxy->check_command[0] != '/' && !curproxy->check_path) { |
3238 | 0 | ha_alert("Proxy '%s': '%s' does not have a leading '/' and 'external-check path' is not set.\n", |
3239 | 0 | curproxy->id, "external-check command"); |
3240 | 0 | cfgerr++; |
3241 | 0 | } |
3242 | 0 | if (clear) { |
3243 | 0 | ha_free(&curproxy->check_command); |
3244 | 0 | } |
3245 | 0 | } |
3246 | |
|
3247 | 0 | if (curproxy->check_path) { |
3248 | 0 | if ((curproxy->options2 & PR_O2_CHK_ANY) != PR_O2_EXT_CHK) { |
3249 | 0 | ha_warning("'%s' will be ignored for %s '%s' (requires 'option external-check').\n", |
3250 | 0 | "external-check path", proxy_type_str(curproxy), curproxy->id); |
3251 | 0 | err_code |= ERR_WARN; |
3252 | 0 | ha_free(&curproxy->check_path); |
3253 | 0 | } |
3254 | 0 | } |
3255 | | |
3256 | | /* if a default backend was specified, let's find it */ |
3257 | 0 | if (curproxy->defbe.name) { |
3258 | 0 | struct proxy *target; |
3259 | |
|
3260 | 0 | target = proxy_be_by_name(curproxy->defbe.name); |
3261 | 0 | if (!target) { |
3262 | 0 | ha_alert("Proxy '%s': unable to find required default_backend: '%s'.\n", |
3263 | 0 | curproxy->id, curproxy->defbe.name); |
3264 | 0 | cfgerr++; |
3265 | 0 | } else if (target == curproxy) { |
3266 | 0 | ha_alert("Proxy '%s': loop detected for default_backend: '%s'.\n", |
3267 | 0 | curproxy->id, curproxy->defbe.name); |
3268 | 0 | cfgerr++; |
3269 | 0 | } else if (target->mode != curproxy->mode && |
3270 | 0 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
3271 | |
|
3272 | 0 | ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) as its default backend (see 'mode').\n", |
3273 | 0 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
3274 | 0 | curproxy->conf.file, curproxy->conf.line, |
3275 | 0 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
3276 | 0 | target->conf.file, target->conf.line); |
3277 | 0 | cfgerr++; |
3278 | 0 | } else { |
3279 | 0 | free(curproxy->defbe.name); |
3280 | 0 | curproxy->defbe.be = target; |
3281 | | /* Emit a warning if this proxy also has some servers */ |
3282 | 0 | if (curproxy->srv) { |
3283 | 0 | ha_warning("In proxy '%s', the 'default_backend' rule always has precedence over the servers, which will never be used.\n", |
3284 | 0 | curproxy->id); |
3285 | 0 | err_code |= ERR_WARN; |
3286 | 0 | } |
3287 | 0 | if (target->mode == PR_MODE_HTTP) { |
3288 | | /* at least one of the used backends will provoke an |
3289 | | * HTTP upgrade |
3290 | | */ |
3291 | 0 | curproxy->options |= PR_O_HTTP_UPG; |
3292 | 0 | } |
3293 | 0 | } |
3294 | 0 | } |
3295 | | |
3296 | | /* find the target proxy for 'use_backend' rules */ |
3297 | 0 | list_for_each_entry(rule, &curproxy->switching_rules, list) { |
3298 | 0 | struct proxy *target; |
3299 | 0 | struct logformat_node *node; |
3300 | 0 | char *pxname; |
3301 | | |
3302 | | /* Try to parse the string as a log format expression. If the result |
3303 | | * of the parsing is only one entry containing a simple string, then |
3304 | | * it's a standard string corresponding to a static rule, thus the |
3305 | | * parsing is cancelled and be.name is restored to be resolved. |
3306 | | */ |
3307 | 0 | pxname = rule->be.name; |
3308 | 0 | lf_expr_init(&rule->be.expr); |
3309 | 0 | curproxy->conf.args.ctx = ARGC_UBK; |
3310 | 0 | curproxy->conf.args.file = rule->file; |
3311 | 0 | curproxy->conf.args.line = rule->line; |
3312 | 0 | err = NULL; |
3313 | 0 | if (!parse_logformat_string(pxname, curproxy, &rule->be.expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) { |
3314 | 0 | ha_alert("Parsing [%s:%d]: failed to parse use_backend rule '%s' : %s.\n", |
3315 | 0 | rule->file, rule->line, pxname, err); |
3316 | 0 | free(err); |
3317 | 0 | cfgerr++; |
3318 | 0 | continue; |
3319 | 0 | } |
3320 | 0 | node = LIST_NEXT(&rule->be.expr.nodes.list, struct logformat_node *, list); |
3321 | |
|
3322 | 0 | if (!lf_expr_isempty(&rule->be.expr)) { |
3323 | 0 | if (node->type != LOG_FMT_TEXT || node->list.n != &rule->be.expr.nodes.list) { |
3324 | 0 | rule->dynamic = 1; |
3325 | 0 | free(pxname); |
3326 | | /* backend is not yet known so we cannot assume its type, |
3327 | | * thus we should consider that at least one of the used |
3328 | | * backends may provoke HTTP upgrade |
3329 | | */ |
3330 | 0 | curproxy->options |= PR_O_HTTP_UPG; |
3331 | 0 | continue; |
3332 | 0 | } |
3333 | | /* Only one element in the list, a simple string: free the expression and |
3334 | | * fall back to static rule |
3335 | | */ |
3336 | 0 | lf_expr_deinit(&rule->be.expr); |
3337 | 0 | } |
3338 | | |
3339 | 0 | rule->dynamic = 0; |
3340 | 0 | rule->be.name = pxname; |
3341 | |
|
3342 | 0 | target = proxy_be_by_name(rule->be.name); |
3343 | 0 | if (!target) { |
3344 | 0 | ha_alert("Proxy '%s': unable to find required use_backend: '%s'.\n", |
3345 | 0 | curproxy->id, rule->be.name); |
3346 | 0 | cfgerr++; |
3347 | 0 | } else if (target == curproxy) { |
3348 | 0 | ha_alert("Proxy '%s': loop detected for use_backend: '%s'.\n", |
3349 | 0 | curproxy->id, rule->be.name); |
3350 | 0 | cfgerr++; |
3351 | 0 | } else if (target->mode != curproxy->mode && |
3352 | 0 | !(curproxy->mode == PR_MODE_TCP && target->mode == PR_MODE_HTTP)) { |
3353 | |
|
3354 | 0 | ha_alert("%s %s '%s' (%s:%d) tries to use incompatible %s %s '%s' (%s:%d) in a 'use_backend' rule (see 'mode').\n", |
3355 | 0 | proxy_mode_str(curproxy->mode), proxy_type_str(curproxy), curproxy->id, |
3356 | 0 | curproxy->conf.file, curproxy->conf.line, |
3357 | 0 | proxy_mode_str(target->mode), proxy_type_str(target), target->id, |
3358 | 0 | target->conf.file, target->conf.line); |
3359 | 0 | cfgerr++; |
3360 | 0 | } else { |
3361 | 0 | ha_free(&rule->be.name); |
3362 | 0 | rule->be.backend = target; |
3363 | 0 | if (target->mode == PR_MODE_HTTP) { |
3364 | | /* at least one of the used backends will provoke an |
3365 | | * HTTP upgrade |
3366 | | */ |
3367 | 0 | curproxy->options |= PR_O_HTTP_UPG; |
3368 | 0 | } |
3369 | 0 | } |
3370 | 0 | err_code |= warnif_tcp_http_cond(curproxy, rule->cond); |
3371 | 0 | } |
3372 | | |
3373 | | /* find the target server for 'use_server' rules */ |
3374 | 0 | list_for_each_entry(srule, &curproxy->server_rules, list) { |
3375 | 0 | struct server *target; |
3376 | 0 | struct logformat_node *node; |
3377 | 0 | char *server_name; |
3378 | | |
3379 | | /* We try to parse the string as a log format expression. If the result of the parsing |
3380 | | * is only one entry containing a single string, then it's a standard string corresponding |
3381 | | * to a static rule, thus the parsing is cancelled and we fall back to setting srv.ptr. |
3382 | | */ |
3383 | 0 | server_name = srule->srv.name; |
3384 | 0 | lf_expr_init(&srule->expr); |
3385 | 0 | curproxy->conf.args.ctx = ARGC_USRV; |
3386 | 0 | err = NULL; |
3387 | 0 | if (!parse_logformat_string(server_name, curproxy, &srule->expr, 0, SMP_VAL_FE_HRQ_HDR, &err)) { |
3388 | 0 | ha_alert("Parsing [%s:%d]; use-server rule failed to parse log-format '%s' : %s.\n", |
3389 | 0 | srule->file, srule->line, server_name, err); |
3390 | 0 | free(err); |
3391 | 0 | cfgerr++; |
3392 | 0 | continue; |
3393 | 0 | } |
3394 | 0 | node = LIST_NEXT(&srule->expr.nodes.list, struct logformat_node *, list); |
3395 | |
|
3396 | 0 | if (!lf_expr_isempty(&srule->expr)) { |
3397 | 0 | if (node->type != LOG_FMT_TEXT || node->list.n != &srule->expr.nodes.list) { |
3398 | 0 | srule->dynamic = 1; |
3399 | 0 | free(server_name); |
3400 | 0 | continue; |
3401 | 0 | } |
3402 | | /* Only one element in the list, a simple string: free the expression and |
3403 | | * fall back to static rule |
3404 | | */ |
3405 | 0 | lf_expr_deinit(&srule->expr); |
3406 | 0 | } |
3407 | | |
3408 | 0 | srule->dynamic = 0; |
3409 | 0 | srule->srv.name = server_name; |
3410 | 0 | target = server_find_by_name(curproxy, srule->srv.name); |
3411 | 0 | err_code |= warnif_tcp_http_cond(curproxy, srule->cond); |
3412 | |
|
3413 | 0 | if (!target) { |
3414 | 0 | ha_alert("%s '%s' : unable to find server '%s' referenced in a 'use-server' rule.\n", |
3415 | 0 | proxy_type_str(curproxy), curproxy->id, srule->srv.name); |
3416 | 0 | cfgerr++; |
3417 | 0 | continue; |
3418 | 0 | } |
3419 | 0 | ha_free(&srule->srv.name); |
3420 | 0 | srule->srv.ptr = target; |
3421 | 0 | target->flags |= SRV_F_NON_PURGEABLE; |
3422 | 0 | } |
3423 | | |
3424 | | /* find the target table for 'stick' rules */ |
3425 | 0 | list_for_each_entry(mrule, &curproxy->sticking_rules, list) { |
3426 | 0 | curproxy->be_req_ana |= AN_REQ_STICKING_RULES; |
3427 | 0 | if (mrule->flags & STK_IS_STORE) |
3428 | 0 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
3429 | |
|
3430 | 0 | if (!resolve_stick_rule(curproxy, mrule)) |
3431 | 0 | cfgerr++; |
3432 | |
|
3433 | 0 | err_code |= warnif_tcp_http_cond(curproxy, mrule->cond); |
3434 | 0 | } |
3435 | | |
3436 | | /* find the target table for 'store response' rules */ |
3437 | 0 | list_for_each_entry(mrule, &curproxy->storersp_rules, list) { |
3438 | 0 | curproxy->be_rsp_ana |= AN_RES_STORE_RULES; |
3439 | |
|
3440 | 0 | if (!resolve_stick_rule(curproxy, mrule)) |
3441 | 0 | cfgerr++; |
3442 | 0 | } |
3443 | | |
3444 | | /* check validity for 'tcp-request' layer 4/5/6/7 rules */ |
3445 | 0 | cfgerr += check_action_rules(&curproxy->tcp_req.l4_rules, curproxy, &err_code); |
3446 | 0 | cfgerr += check_action_rules(&curproxy->tcp_req.l5_rules, curproxy, &err_code); |
3447 | 0 | cfgerr += check_action_rules(&curproxy->tcp_req.inspect_rules, curproxy, &err_code); |
3448 | 0 | cfgerr += check_action_rules(&curproxy->tcp_rep.inspect_rules, curproxy, &err_code); |
3449 | 0 | cfgerr += check_action_rules(&curproxy->http_req_rules, curproxy, &err_code); |
3450 | 0 | cfgerr += check_action_rules(&curproxy->http_res_rules, curproxy, &err_code); |
3451 | 0 | cfgerr += check_action_rules(&curproxy->http_after_res_rules, curproxy, &err_code); |
3452 | | |
3453 | | /* Warn is a switch-mode http is used on a TCP listener with servers but no backend */ |
3454 | 0 | if (!curproxy->defbe.name && LIST_ISEMPTY(&curproxy->switching_rules) && curproxy->srv) { |
3455 | 0 | if ((curproxy->options & PR_O_HTTP_UPG) && curproxy->mode == PR_MODE_TCP) |
3456 | 0 | ha_warning("Proxy '%s' : 'switch-mode http' configured for a %s %s with no backend. " |
3457 | 0 | "Incoming connections upgraded to HTTP cannot be routed to TCP servers\n", |
3458 | 0 | curproxy->id, proxy_mode_str(curproxy->mode), proxy_type_str(curproxy)); |
3459 | 0 | } |
3460 | |
|
3461 | 0 | if (curproxy->table && curproxy->table->peers.name) { |
3462 | 0 | struct peers *curpeers; |
3463 | |
|
3464 | 0 | for (curpeers = cfg_peers; curpeers; curpeers = curpeers->next) { |
3465 | 0 | if (strcmp(curpeers->id, curproxy->table->peers.name) == 0) { |
3466 | 0 | ha_free(&curproxy->table->peers.name); |
3467 | 0 | curproxy->table->peers.p = curpeers; |
3468 | 0 | break; |
3469 | 0 | } |
3470 | 0 | } |
3471 | |
|
3472 | 0 | if (!curpeers) { |
3473 | 0 | ha_alert("Proxy '%s': unable to find sync peers '%s'.\n", |
3474 | 0 | curproxy->id, curproxy->table->peers.name); |
3475 | 0 | ha_free(&curproxy->table->peers.name); |
3476 | 0 | curproxy->table->peers.p = NULL; |
3477 | 0 | cfgerr++; |
3478 | 0 | } |
3479 | 0 | else if (curpeers->disabled) { |
3480 | | /* silently disable this peers section */ |
3481 | 0 | curproxy->table->peers.p = NULL; |
3482 | 0 | } |
3483 | 0 | else if (!curpeers->peers_fe) { |
3484 | 0 | ha_alert("Proxy '%s': unable to find local peer '%s' in peers section '%s'.\n", |
3485 | 0 | curproxy->id, localpeer, curpeers->id); |
3486 | 0 | curproxy->table->peers.p = NULL; |
3487 | 0 | cfgerr++; |
3488 | 0 | } |
3489 | 0 | } |
3490 | | |
3491 | |
|
3492 | 0 | if (curproxy->email_alert.mailers.name) { |
3493 | 0 | struct mailers *curmailers = mailers; |
3494 | |
|
3495 | 0 | for (curmailers = mailers; curmailers; curmailers = curmailers->next) { |
3496 | 0 | if (strcmp(curmailers->id, curproxy->email_alert.mailers.name) == 0) |
3497 | 0 | break; |
3498 | 0 | } |
3499 | 0 | if (!curmailers) { |
3500 | 0 | ha_alert("Proxy '%s': unable to find mailers '%s'.\n", |
3501 | 0 | curproxy->id, curproxy->email_alert.mailers.name); |
3502 | 0 | free_email_alert(curproxy); |
3503 | 0 | cfgerr++; |
3504 | 0 | } |
3505 | 0 | else { |
3506 | 0 | err = NULL; |
3507 | 0 | if (init_email_alert(curmailers, curproxy, &err)) { |
3508 | 0 | ha_alert("Proxy '%s': %s.\n", curproxy->id, err); |
3509 | 0 | free(err); |
3510 | 0 | cfgerr++; |
3511 | 0 | } |
3512 | 0 | } |
3513 | 0 | } |
3514 | |
|
3515 | 0 | if (curproxy->uri_auth && !(curproxy->uri_auth->flags & STAT_F_CONVDONE) && |
3516 | 0 | !LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules) && |
3517 | 0 | (curproxy->uri_auth->userlist || curproxy->uri_auth->auth_realm )) { |
3518 | 0 | ha_alert("%s '%s': stats 'auth'/'realm' and 'http-request' can't be used at the same time.\n", |
3519 | 0 | "proxy", curproxy->id); |
3520 | 0 | cfgerr++; |
3521 | 0 | goto out_uri_auth_compat; |
3522 | 0 | } |
3523 | | |
3524 | 0 | if (curproxy->uri_auth && curproxy->uri_auth->userlist && |
3525 | 0 | (!(curproxy->uri_auth->flags & STAT_F_CONVDONE) || |
3526 | 0 | LIST_ISEMPTY(&curproxy->uri_auth->http_req_rules))) { |
3527 | 0 | const char *uri_auth_compat_req[10]; |
3528 | 0 | struct act_rule *rule; |
3529 | 0 | i = 0; |
3530 | | |
3531 | | /* build the ACL condition from scratch. We're relying on anonymous ACLs for that */ |
3532 | 0 | uri_auth_compat_req[i++] = "auth"; |
3533 | |
|
3534 | 0 | if (curproxy->uri_auth->auth_realm) { |
3535 | 0 | uri_auth_compat_req[i++] = "realm"; |
3536 | 0 | uri_auth_compat_req[i++] = curproxy->uri_auth->auth_realm; |
3537 | 0 | } |
3538 | |
|
3539 | 0 | uri_auth_compat_req[i++] = "unless"; |
3540 | 0 | uri_auth_compat_req[i++] = "{"; |
3541 | 0 | uri_auth_compat_req[i++] = "http_auth(.internal-stats-userlist)"; |
3542 | 0 | uri_auth_compat_req[i++] = "}"; |
3543 | 0 | uri_auth_compat_req[i++] = ""; |
3544 | |
|
3545 | 0 | rule = parse_http_req_cond(uri_auth_compat_req, "internal-stats-auth-compat", 0, curproxy); |
3546 | 0 | if (!rule) { |
3547 | 0 | cfgerr++; |
3548 | 0 | break; |
3549 | 0 | } |
3550 | | |
3551 | 0 | LIST_APPEND(&curproxy->uri_auth->http_req_rules, &rule->list); |
3552 | |
|
3553 | 0 | if (curproxy->uri_auth->auth_realm) { |
3554 | 0 | ha_free(&curproxy->uri_auth->auth_realm); |
3555 | 0 | } |
3556 | 0 | curproxy->uri_auth->flags |= STAT_F_CONVDONE; |
3557 | 0 | } |
3558 | 0 | out_uri_auth_compat: |
3559 | | |
3560 | | /* check whether we have a logger that uses RFC5424 log format */ |
3561 | 0 | list_for_each_entry(tmplogger, &curproxy->loggers, list) { |
3562 | 0 | if (tmplogger->format == LOG_FORMAT_RFC5424) { |
3563 | 0 | if (!curproxy->logformat_sd.str) { |
3564 | | /* set the default logformat_sd_string */ |
3565 | 0 | curproxy->logformat_sd.str = default_rfc5424_sd_log_format; |
3566 | 0 | } |
3567 | 0 | break; |
3568 | 0 | } |
3569 | 0 | } |
3570 | | |
3571 | | /* compile the log format */ |
3572 | 0 | if (!(curproxy->cap & PR_CAP_FE)) { |
3573 | 0 | lf_expr_deinit(&curproxy->logformat); |
3574 | 0 | lf_expr_deinit(&curproxy->logformat_sd); |
3575 | 0 | } |
3576 | |
|
3577 | 0 | if (curproxy->logformat.str) { |
3578 | 0 | curproxy->conf.args.ctx = ARGC_LOG; |
3579 | 0 | curproxy->conf.args.file = curproxy->logformat.conf.file; |
3580 | 0 | curproxy->conf.args.line = curproxy->logformat.conf.line; |
3581 | 0 | err = NULL; |
3582 | 0 | if (!lf_expr_compile(&curproxy->logformat, &curproxy->conf.args, |
3583 | 0 | LOG_OPT_MANDATORY|LOG_OPT_MERGE_SPACES, |
3584 | 0 | SMP_VAL_FE_LOG_END, &err) || |
3585 | 0 | !lf_expr_postcheck(&curproxy->logformat, curproxy, &err)) { |
3586 | 0 | ha_alert("Parsing [%s:%d]: failed to parse log-format : %s.\n", |
3587 | 0 | curproxy->logformat.conf.file, curproxy->logformat.conf.line, err); |
3588 | 0 | free(err); |
3589 | 0 | cfgerr++; |
3590 | 0 | } |
3591 | 0 | curproxy->conf.args.file = NULL; |
3592 | 0 | curproxy->conf.args.line = 0; |
3593 | 0 | } |
3594 | |
|
3595 | 0 | if (curproxy->logformat_sd.str) { |
3596 | 0 | curproxy->conf.args.ctx = ARGC_LOGSD; |
3597 | 0 | curproxy->conf.args.file = curproxy->logformat_sd.conf.file; |
3598 | 0 | curproxy->conf.args.line = curproxy->logformat_sd.conf.line; |
3599 | 0 | err = NULL; |
3600 | 0 | if (!lf_expr_compile(&curproxy->logformat_sd, &curproxy->conf.args, |
3601 | 0 | LOG_OPT_MANDATORY|LOG_OPT_MERGE_SPACES, |
3602 | 0 | SMP_VAL_FE_LOG_END, &err) || |
3603 | 0 | !add_to_logformat_list(NULL, NULL, LF_SEPARATOR, &curproxy->logformat_sd, &err) || |
3604 | 0 | !lf_expr_postcheck(&curproxy->logformat_sd, curproxy, &err)) { |
3605 | 0 | ha_alert("Parsing [%s:%d]: failed to parse log-format-sd : %s.\n", |
3606 | 0 | curproxy->logformat_sd.conf.file, curproxy->logformat_sd.conf.line, err); |
3607 | 0 | free(err); |
3608 | 0 | cfgerr++; |
3609 | 0 | } |
3610 | 0 | curproxy->conf.args.file = NULL; |
3611 | 0 | curproxy->conf.args.line = 0; |
3612 | 0 | } |
3613 | |
|
3614 | 0 | if (curproxy->format_unique_id.str) { |
3615 | 0 | int where = 0; |
3616 | |
|
3617 | 0 | curproxy->conf.args.ctx = ARGC_UIF; |
3618 | 0 | curproxy->conf.args.file = curproxy->format_unique_id.conf.file; |
3619 | 0 | curproxy->conf.args.line = curproxy->format_unique_id.conf.line; |
3620 | 0 | err = NULL; |
3621 | 0 | if (curproxy->cap & PR_CAP_FE) |
3622 | 0 | where |= SMP_VAL_FE_HRQ_HDR; |
3623 | 0 | if (curproxy->cap & PR_CAP_BE) |
3624 | 0 | where |= SMP_VAL_BE_HRQ_HDR; |
3625 | 0 | if (!lf_expr_compile(&curproxy->format_unique_id, &curproxy->conf.args, |
3626 | 0 | LOG_OPT_HTTP|LOG_OPT_MERGE_SPACES, where, &err) || |
3627 | 0 | !lf_expr_postcheck(&curproxy->format_unique_id, curproxy, &err)) { |
3628 | 0 | ha_alert("Parsing [%s:%d]: failed to parse unique-id : %s.\n", |
3629 | 0 | curproxy->format_unique_id.conf.file, curproxy->format_unique_id.conf.line, err); |
3630 | 0 | free(err); |
3631 | 0 | cfgerr++; |
3632 | 0 | } |
3633 | 0 | curproxy->conf.args.file = NULL; |
3634 | 0 | curproxy->conf.args.line = 0; |
3635 | 0 | } |
3636 | |
|
3637 | 0 | if (curproxy->logformat_error.str) { |
3638 | 0 | curproxy->conf.args.ctx = ARGC_LOG; |
3639 | 0 | curproxy->conf.args.file = curproxy->logformat_error.conf.file; |
3640 | 0 | curproxy->conf.args.line = curproxy->logformat_error.conf.line; |
3641 | 0 | err = NULL; |
3642 | 0 | if (!lf_expr_compile(&curproxy->logformat_error, &curproxy->conf.args, |
3643 | 0 | LOG_OPT_MANDATORY|LOG_OPT_MERGE_SPACES, |
3644 | 0 | SMP_VAL_FE_LOG_END, &err) || |
3645 | 0 | !lf_expr_postcheck(&curproxy->logformat_error, curproxy, &err)) { |
3646 | 0 | ha_alert("Parsing [%s:%d]: failed to parse error-log-format : %s.\n", |
3647 | 0 | curproxy->logformat_error.conf.file, curproxy->logformat_error.conf.line, err); |
3648 | 0 | free(err); |
3649 | 0 | cfgerr++; |
3650 | 0 | } |
3651 | 0 | curproxy->conf.args.file = NULL; |
3652 | 0 | curproxy->conf.args.line = 0; |
3653 | 0 | } |
3654 | | |
3655 | | /* "balance hash" needs to compile its expression |
3656 | | * (log backends will handle this in proxy log postcheck) |
3657 | | */ |
3658 | 0 | if (curproxy->mode != PR_MODE_SYSLOG && |
3659 | 0 | (curproxy->lbprm.algo & BE_LB_ALGO) == BE_LB_ALGO_SMP) { |
3660 | 0 | int idx = 0; |
3661 | 0 | const char *args[] = { |
3662 | 0 | curproxy->lbprm.arg_str, |
3663 | 0 | NULL, |
3664 | 0 | }; |
3665 | |
|
3666 | 0 | err = NULL; |
3667 | 0 | curproxy->conf.args.ctx = ARGC_USRV; // same context as use_server. |
3668 | 0 | curproxy->lbprm.expr = |
3669 | 0 | sample_parse_expr((char **)args, &idx, |
3670 | 0 | curproxy->conf.file, curproxy->conf.line, |
3671 | 0 | &err, &curproxy->conf.args, NULL); |
3672 | |
|
3673 | 0 | if (!curproxy->lbprm.expr) { |
3674 | 0 | ha_alert("%s '%s' [%s:%d]: failed to parse 'balance hash' expression '%s' in : %s.\n", |
3675 | 0 | proxy_type_str(curproxy), curproxy->id, |
3676 | 0 | curproxy->conf.file, curproxy->conf.line, |
3677 | 0 | curproxy->lbprm.arg_str, err); |
3678 | 0 | ha_free(&err); |
3679 | 0 | cfgerr++; |
3680 | 0 | } |
3681 | 0 | else if (!(curproxy->lbprm.expr->fetch->val & SMP_VAL_BE_SET_SRV)) { |
3682 | 0 | ha_alert("%s '%s' [%s:%d]: error detected while parsing 'balance hash' expression '%s' " |
3683 | 0 | "which requires information from %s, which is not available here.\n", |
3684 | 0 | proxy_type_str(curproxy), curproxy->id, |
3685 | 0 | curproxy->conf.file, curproxy->conf.line, |
3686 | 0 | curproxy->lbprm.arg_str, sample_src_names(curproxy->lbprm.expr->fetch->use)); |
3687 | 0 | cfgerr++; |
3688 | 0 | } |
3689 | 0 | else if (curproxy->mode == PR_MODE_HTTP && (curproxy->lbprm.expr->fetch->use & SMP_USE_L6REQ)) { |
3690 | 0 | ha_warning("%s '%s' [%s:%d]: L6 sample fetch <%s> will be ignored in 'balance hash' expression in HTTP mode.\n", |
3691 | 0 | proxy_type_str(curproxy), curproxy->id, |
3692 | 0 | curproxy->conf.file, curproxy->conf.line, |
3693 | 0 | curproxy->lbprm.arg_str); |
3694 | 0 | } |
3695 | 0 | else |
3696 | 0 | curproxy->http_needed |= !!(curproxy->lbprm.expr->fetch->use & SMP_USE_HTTP_ANY); |
3697 | 0 | } |
3698 | | |
3699 | | /* only now we can check if some args remain unresolved. |
3700 | | * This must be done after the users and groups resolution. |
3701 | | */ |
3702 | 0 | err = NULL; |
3703 | 0 | i = smp_resolve_args(curproxy, &err); |
3704 | 0 | cfgerr += i; |
3705 | 0 | if (i) { |
3706 | 0 | indent_msg(&err, 8); |
3707 | 0 | ha_alert("%s%s\n", i > 1 ? "multiple argument resolution errors:" : "", err); |
3708 | 0 | ha_free(&err); |
3709 | 0 | } else |
3710 | 0 | cfgerr += acl_find_targets(curproxy); |
3711 | |
|
3712 | 0 | if (!(curproxy->cap & PR_CAP_INT) && (curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
3713 | 0 | (((curproxy->cap & PR_CAP_FE) && !curproxy->timeout.client) || |
3714 | 0 | ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && |
3715 | 0 | (!curproxy->timeout.connect || |
3716 | 0 | (!curproxy->timeout.server && (curproxy->mode == PR_MODE_HTTP || !curproxy->timeout.tunnel)))))) { |
3717 | 0 | ha_warning("missing timeouts for %s '%s'.\n" |
3718 | 0 | " | While not properly invalid, you will certainly encounter various problems\n" |
3719 | 0 | " | with such a configuration. To fix this, please ensure that all following\n" |
3720 | 0 | " | timeouts are set to a non-zero value: 'client', 'connect', 'server'.\n", |
3721 | 0 | proxy_type_str(curproxy), curproxy->id); |
3722 | 0 | err_code |= ERR_WARN; |
3723 | 0 | } |
3724 | | |
3725 | | /* Historically, the tarpit and queue timeouts were inherited from contimeout. |
3726 | | * We must still support older configurations, so let's find out whether those |
3727 | | * parameters have been set or must be copied from contimeouts. |
3728 | | */ |
3729 | 0 | if (!curproxy->timeout.tarpit) |
3730 | 0 | curproxy->timeout.tarpit = curproxy->timeout.connect; |
3731 | 0 | if ((curproxy->cap & PR_CAP_BE) && !curproxy->timeout.queue) |
3732 | 0 | curproxy->timeout.queue = curproxy->timeout.connect; |
3733 | |
|
3734 | 0 | if ((curproxy->tcpcheck_rules.flags & TCPCHK_RULES_UNUSED_TCP_RS)) { |
3735 | 0 | ha_warning("%s '%s' uses tcp-check rules without 'option tcp-check', so the rules are ignored.\n", |
3736 | 0 | proxy_type_str(curproxy), curproxy->id); |
3737 | 0 | err_code |= ERR_WARN; |
3738 | 0 | } |
3739 | | |
3740 | | /* ensure that cookie capture length is not too large */ |
3741 | 0 | if (curproxy->capture_len >= global.tune.cookie_len) { |
3742 | 0 | ha_warning("truncating capture length to %d bytes for %s '%s'.\n", |
3743 | 0 | global.tune.cookie_len - 1, proxy_type_str(curproxy), curproxy->id); |
3744 | 0 | err_code |= ERR_WARN; |
3745 | 0 | curproxy->capture_len = global.tune.cookie_len - 1; |
3746 | 0 | } |
3747 | | |
3748 | | /* The small pools required for the capture lists */ |
3749 | 0 | if (curproxy->nb_req_cap) { |
3750 | 0 | curproxy->req_cap_pool = create_pool("ptrcap", |
3751 | 0 | curproxy->nb_req_cap * sizeof(char *), |
3752 | 0 | MEM_F_SHARED); |
3753 | 0 | } |
3754 | |
|
3755 | 0 | if (curproxy->nb_rsp_cap) { |
3756 | 0 | curproxy->rsp_cap_pool = create_pool("ptrcap", |
3757 | 0 | curproxy->nb_rsp_cap * sizeof(char *), |
3758 | 0 | MEM_F_SHARED); |
3759 | 0 | } |
3760 | |
|
3761 | 0 | switch (curproxy->load_server_state_from_file) { |
3762 | 0 | case PR_SRV_STATE_FILE_UNSPEC: |
3763 | 0 | curproxy->load_server_state_from_file = PR_SRV_STATE_FILE_NONE; |
3764 | 0 | break; |
3765 | 0 | case PR_SRV_STATE_FILE_GLOBAL: |
3766 | 0 | if (!global.server_state_file) { |
3767 | 0 | ha_warning("backend '%s' configured to load server state file from global section 'server-state-file' directive. Unfortunately, 'server-state-file' is not set!\n", |
3768 | 0 | curproxy->id); |
3769 | 0 | err_code |= ERR_WARN; |
3770 | 0 | } |
3771 | 0 | break; |
3772 | 0 | } |
3773 | | |
3774 | | /* first, we will invert the servers list order */ |
3775 | 0 | newsrv = NULL; |
3776 | 0 | while (curproxy->srv) { |
3777 | 0 | struct server *next; |
3778 | |
|
3779 | 0 | next = curproxy->srv->next; |
3780 | 0 | curproxy->srv->next = newsrv; |
3781 | 0 | newsrv = curproxy->srv; |
3782 | 0 | if (!next) |
3783 | 0 | break; |
3784 | 0 | curproxy->srv = next; |
3785 | 0 | } |
3786 | | |
3787 | | /* Check that no server name conflicts. This causes trouble in the stats. |
3788 | | * We only emit an error for the first conflict affecting each server, |
3789 | | * in order to avoid combinatory explosion if all servers have the same |
3790 | | * name. Since servers names are stored in a tree before landing here, |
3791 | | * we simply have to check for the current server's duplicates to spot |
3792 | | * conflicts. |
3793 | | */ |
3794 | 0 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
3795 | 0 | struct server *other_srv; |
3796 | | |
3797 | | /* Note: internal servers are not always registered and |
3798 | | * they do not conflict. |
3799 | | */ |
3800 | 0 | if (!ceb_intree(&newsrv->conf.name_node)) |
3801 | 0 | continue; |
3802 | | |
3803 | 0 | for (other_srv = newsrv; |
3804 | 0 | (other_srv = cebis_item_prev_dup(&curproxy->conf.used_server_name, conf.name_node, id, other_srv)); ) { |
3805 | 0 | ha_alert("parsing [%s:%d] : %s '%s', another server named '%s' was already defined at line %d, please use distinct names.\n", |
3806 | 0 | newsrv->conf.file, newsrv->conf.line, |
3807 | 0 | proxy_type_str(curproxy), curproxy->id, |
3808 | 0 | newsrv->id, other_srv->conf.line); |
3809 | 0 | cfgerr++; |
3810 | 0 | break; |
3811 | 0 | } |
3812 | 0 | } |
3813 | | |
3814 | | /* assign automatic UIDs to servers which don't have one yet */ |
3815 | 0 | next_id = 1; |
3816 | 0 | newsrv = curproxy->srv; |
3817 | 0 | while (newsrv != NULL) { |
3818 | 0 | if (!newsrv->puid) { |
3819 | | /* server ID not set, use automatic numbering with first |
3820 | | * spare entry starting with next_svid. |
3821 | | */ |
3822 | 0 | next_id = server_get_next_id(curproxy, next_id); |
3823 | 0 | newsrv->puid = next_id; |
3824 | 0 | server_index_id(curproxy, newsrv); |
3825 | 0 | } |
3826 | |
|
3827 | 0 | next_id++; |
3828 | 0 | newsrv = newsrv->next; |
3829 | 0 | } |
3830 | |
|
3831 | 0 | curproxy->lbprm.wmult = 1; /* default weight multiplier */ |
3832 | 0 | curproxy->lbprm.wdiv = 1; /* default weight divider */ |
3833 | | |
3834 | | /* |
3835 | | * If this server supports a maxconn parameter, it needs a dedicated |
3836 | | * tasks to fill the emptied slots when a connection leaves. |
3837 | | * Also, resolve deferred tracking dependency if needed. |
3838 | | */ |
3839 | 0 | newsrv = curproxy->srv; |
3840 | 0 | while (newsrv != NULL) { |
3841 | 0 | set_usermsgs_ctx(newsrv->conf.file, newsrv->conf.line, &newsrv->obj_type); |
3842 | |
|
3843 | 0 | srv_minmax_conn_apply(newsrv); |
3844 | | |
3845 | | /* this will also properly set the transport layer for |
3846 | | * prod and checks |
3847 | | * if default-server have use_ssl, prerare ssl init |
3848 | | * without activating it */ |
3849 | 0 | if (newsrv->use_ssl == 1 || newsrv->check.use_ssl == 1 || |
3850 | 0 | (newsrv->proxy->options & PR_O_TCPCHK_SSL) || |
3851 | 0 | ((newsrv->flags & SRV_F_DEFSRV_USE_SSL) && newsrv->use_ssl != 1)) { |
3852 | 0 | if (xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv) |
3853 | 0 | cfgerr += xprt_get(XPRT_SSL)->prepare_srv(newsrv); |
3854 | 0 | else if (xprt_get(XPRT_QUIC) && xprt_get(XPRT_QUIC)->prepare_srv) |
3855 | 0 | cfgerr += xprt_get(XPRT_QUIC)->prepare_srv(newsrv); |
3856 | 0 | } |
3857 | |
|
3858 | 0 | if (newsrv->use_ssl == 1 || ((newsrv->flags & SRV_F_DEFSRV_USE_SSL) && newsrv->use_ssl != 1)) { |
3859 | | /* In HTTP only, if the SNI is not set and we can rely on the host |
3860 | | * header value, fill the sni expression accordingly |
3861 | | */ |
3862 | 0 | if (!newsrv->sni_expr && newsrv->proxy->mode == PR_MODE_HTTP && |
3863 | 0 | !(newsrv->ssl_ctx.options & SRV_SSL_O_NO_AUTO_SNI)) { |
3864 | 0 | newsrv->sni_expr = strdup("req.hdr(host),field(1,:)"); |
3865 | |
|
3866 | 0 | err = NULL; |
3867 | 0 | if (server_parse_exprs(newsrv, curproxy, &err)) { |
3868 | 0 | ha_alert("parsing [%s:%d]: failed to parse auto SNI expression: %s\n", |
3869 | 0 | newsrv->conf.file, newsrv->conf.line, err); |
3870 | 0 | free(err); |
3871 | 0 | ++cfgerr; |
3872 | 0 | goto next_srv; |
3873 | 0 | } |
3874 | 0 | } |
3875 | 0 | } |
3876 | | |
3877 | | |
3878 | 0 | if ((newsrv->flags & SRV_F_FASTOPEN) && |
3879 | 0 | ((curproxy->retry_type & (PR_RE_DISCONNECTED | PR_RE_TIMEOUT)) != |
3880 | 0 | (PR_RE_DISCONNECTED | PR_RE_TIMEOUT))) |
3881 | 0 | ha_warning("server has tfo activated, the backend should be configured with at least 'conn-failure', 'empty-response' and 'response-timeout' or we wouldn't be able to retry the connection on failure.\n"); |
3882 | |
|
3883 | 0 | if (newsrv->trackit) { |
3884 | 0 | if (srv_apply_track(newsrv, curproxy)) { |
3885 | 0 | ++cfgerr; |
3886 | 0 | goto next_srv; |
3887 | 0 | } |
3888 | 0 | } |
3889 | | |
3890 | 0 | next_srv: |
3891 | 0 | reset_usermsgs_ctx(); |
3892 | 0 | newsrv = newsrv->next; |
3893 | 0 | } |
3894 | | |
3895 | | /* |
3896 | | * Try to generate dynamic cookies for servers now. |
3897 | | * It couldn't be done earlier, since at the time we parsed |
3898 | | * the server line, we may not have known yet that we |
3899 | | * should use dynamic cookies, or the secret key may not |
3900 | | * have been provided yet. |
3901 | | */ |
3902 | 0 | if (curproxy->ck_opts & PR_CK_DYNAMIC) { |
3903 | 0 | newsrv = curproxy->srv; |
3904 | 0 | while (newsrv != NULL) { |
3905 | 0 | srv_set_dyncookie(newsrv); |
3906 | 0 | newsrv = newsrv->next; |
3907 | 0 | } |
3908 | |
|
3909 | 0 | } |
3910 | | /* We have to initialize the server lookup mechanism depending |
3911 | | * on what LB algorithm was chosen. |
3912 | | */ |
3913 | |
|
3914 | 0 | curproxy->lbprm.algo &= ~(BE_LB_LKUP | BE_LB_PROP_DYN); |
3915 | 0 | switch (curproxy->lbprm.algo & BE_LB_KIND) { |
3916 | 0 | case BE_LB_KIND_RR: |
3917 | 0 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_STATIC) { |
3918 | 0 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
3919 | 0 | init_server_map(curproxy); |
3920 | 0 | } else if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_RR_RANDOM) { |
3921 | 0 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
3922 | 0 | if (chash_init_server_tree(curproxy) < 0) { |
3923 | 0 | cfgerr++; |
3924 | 0 | } |
3925 | 0 | } else { |
3926 | 0 | curproxy->lbprm.algo |= BE_LB_LKUP_RRTREE | BE_LB_PROP_DYN; |
3927 | 0 | fwrr_init_server_groups(curproxy); |
3928 | 0 | } |
3929 | 0 | break; |
3930 | | |
3931 | 0 | case BE_LB_KIND_CB: |
3932 | 0 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_CB_LC) { |
3933 | 0 | curproxy->lbprm.algo |= BE_LB_LKUP_LCTREE | BE_LB_PROP_DYN; |
3934 | 0 | fwlc_init_server_tree(curproxy); |
3935 | 0 | } else { |
3936 | 0 | curproxy->lbprm.algo |= BE_LB_LKUP_FSTREE | BE_LB_PROP_DYN; |
3937 | 0 | fas_init_server_tree(curproxy); |
3938 | 0 | } |
3939 | 0 | break; |
3940 | | |
3941 | 0 | case BE_LB_KIND_HI: |
3942 | 0 | if ((curproxy->lbprm.algo & BE_LB_HASH_TYPE) == BE_LB_HASH_CONS) { |
3943 | 0 | curproxy->lbprm.algo |= BE_LB_LKUP_CHTREE | BE_LB_PROP_DYN; |
3944 | 0 | if (chash_init_server_tree(curproxy) < 0) { |
3945 | 0 | cfgerr++; |
3946 | 0 | } |
3947 | 0 | } else { |
3948 | 0 | curproxy->lbprm.algo |= BE_LB_LKUP_MAP; |
3949 | 0 | init_server_map(curproxy); |
3950 | 0 | } |
3951 | 0 | break; |
3952 | 0 | case BE_LB_KIND_SA: |
3953 | 0 | if ((curproxy->lbprm.algo & BE_LB_PARM) == BE_LB_SA_SS) { |
3954 | 0 | curproxy->lbprm.algo |= BE_LB_PROP_DYN; |
3955 | 0 | init_server_ss(curproxy); |
3956 | 0 | } |
3957 | 0 | break; |
3958 | 0 | } |
3959 | 0 | HA_RWLOCK_INIT(&curproxy->lbprm.lock); |
3960 | |
|
3961 | 0 | if (curproxy->options & PR_O_LOGASAP) |
3962 | 0 | curproxy->to_log &= ~LW_BYTES; |
3963 | |
|
3964 | 0 | if (!(curproxy->cap & PR_CAP_INT) && (curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) && |
3965 | 0 | (curproxy->cap & PR_CAP_FE) && LIST_ISEMPTY(&curproxy->loggers) && |
3966 | 0 | (!lf_expr_isempty(&curproxy->logformat) || !lf_expr_isempty(&curproxy->logformat_sd))) { |
3967 | 0 | ha_warning("log format ignored for %s '%s' since it has no log address.\n", |
3968 | 0 | proxy_type_str(curproxy), curproxy->id); |
3969 | 0 | err_code |= ERR_WARN; |
3970 | 0 | } |
3971 | |
|
3972 | 0 | if (curproxy->mode != PR_MODE_HTTP && !(curproxy->options & PR_O_HTTP_UPG)) { |
3973 | 0 | int optnum; |
3974 | |
|
3975 | 0 | if (curproxy->uri_auth) { |
3976 | 0 | ha_warning("'stats' statement ignored for %s '%s' as it requires HTTP mode.\n", |
3977 | 0 | proxy_type_str(curproxy), curproxy->id); |
3978 | 0 | err_code |= ERR_WARN; |
3979 | 0 | stats_uri_auth_drop(curproxy->uri_auth); |
3980 | 0 | curproxy->uri_auth = NULL; |
3981 | 0 | } |
3982 | |
|
3983 | 0 | if (curproxy->capture_name) { |
3984 | 0 | ha_warning("'capture' statement ignored for %s '%s' as it requires HTTP mode.\n", |
3985 | 0 | proxy_type_str(curproxy), curproxy->id); |
3986 | 0 | err_code |= ERR_WARN; |
3987 | 0 | } |
3988 | |
|
3989 | 0 | if (isttest(curproxy->monitor_uri)) { |
3990 | 0 | ha_warning("'monitor-uri' statement ignored for %s '%s' as it requires HTTP mode.\n", |
3991 | 0 | proxy_type_str(curproxy), curproxy->id); |
3992 | 0 | err_code |= ERR_WARN; |
3993 | 0 | } |
3994 | |
|
3995 | 0 | if (!LIST_ISEMPTY(&curproxy->http_req_rules)) { |
3996 | 0 | ha_warning("'http-request' rules ignored for %s '%s' as they require HTTP mode.\n", |
3997 | 0 | proxy_type_str(curproxy), curproxy->id); |
3998 | 0 | err_code |= ERR_WARN; |
3999 | 0 | } |
4000 | |
|
4001 | 0 | if (!LIST_ISEMPTY(&curproxy->http_res_rules)) { |
4002 | 0 | ha_warning("'http-response' rules ignored for %s '%s' as they require HTTP mode.\n", |
4003 | 0 | proxy_type_str(curproxy), curproxy->id); |
4004 | 0 | err_code |= ERR_WARN; |
4005 | 0 | } |
4006 | |
|
4007 | 0 | if (!LIST_ISEMPTY(&curproxy->http_after_res_rules)) { |
4008 | 0 | ha_warning("'http-after-response' rules ignored for %s '%s' as they require HTTP mode.\n", |
4009 | 0 | proxy_type_str(curproxy), curproxy->id); |
4010 | 0 | err_code |= ERR_WARN; |
4011 | 0 | } |
4012 | |
|
4013 | 0 | if (!LIST_ISEMPTY(&curproxy->redirect_rules)) { |
4014 | 0 | ha_warning("'redirect' rules ignored for %s '%s' as they require HTTP mode.\n", |
4015 | 0 | proxy_type_str(curproxy), curproxy->id); |
4016 | 0 | err_code |= ERR_WARN; |
4017 | 0 | } |
4018 | |
|
4019 | 0 | for (optnum = 0; cfg_opts[optnum].name; optnum++) { |
4020 | 0 | if (cfg_opts[optnum].mode == PR_MODE_HTTP && |
4021 | 0 | (curproxy->cap & cfg_opts[optnum].cap) && |
4022 | 0 | (curproxy->options & cfg_opts[optnum].val)) { |
4023 | 0 | ha_warning("'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
4024 | 0 | cfg_opts[optnum].name, proxy_type_str(curproxy), curproxy->id); |
4025 | 0 | err_code |= ERR_WARN; |
4026 | 0 | curproxy->options &= ~cfg_opts[optnum].val; |
4027 | 0 | } |
4028 | 0 | } |
4029 | |
|
4030 | 0 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) { |
4031 | 0 | if (cfg_opts2[optnum].mode == PR_MODE_HTTP && |
4032 | 0 | (curproxy->cap & cfg_opts2[optnum].cap) && |
4033 | 0 | (curproxy->options2 & cfg_opts2[optnum].val)) { |
4034 | 0 | ha_warning("'option %s' ignored for %s '%s' as it requires HTTP mode.\n", |
4035 | 0 | cfg_opts2[optnum].name, proxy_type_str(curproxy), curproxy->id); |
4036 | 0 | err_code |= ERR_WARN; |
4037 | 0 | curproxy->options2 &= ~cfg_opts2[optnum].val; |
4038 | 0 | } |
4039 | 0 | } |
4040 | |
|
4041 | 0 | #if defined(CONFIG_HAP_TRANSPARENT) |
4042 | 0 | if (curproxy->conn_src.bind_hdr_occ) { |
4043 | 0 | curproxy->conn_src.bind_hdr_occ = 0; |
4044 | 0 | ha_warning("%s '%s' : ignoring use of header %s as source IP in non-HTTP mode.\n", |
4045 | 0 | proxy_type_str(curproxy), curproxy->id, curproxy->conn_src.bind_hdr_name); |
4046 | 0 | err_code |= ERR_WARN; |
4047 | 0 | } |
4048 | 0 | #endif |
4049 | 0 | } |
4050 | | |
4051 | | /* |
4052 | | * ensure that we're not cross-dressing a TCP server into HTTP. |
4053 | | */ |
4054 | 0 | newsrv = curproxy->srv; |
4055 | 0 | while (newsrv != NULL) { |
4056 | 0 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->rdr_len) { |
4057 | 0 | ha_alert("%s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n", |
4058 | 0 | proxy_type_str(curproxy), curproxy->id); |
4059 | 0 | cfgerr++; |
4060 | 0 | } |
4061 | |
|
4062 | 0 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->cklen) { |
4063 | 0 | ha_warning("%s '%s' : ignoring cookie for server '%s' as HTTP mode is disabled.\n", |
4064 | 0 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
4065 | 0 | err_code |= ERR_WARN; |
4066 | 0 | } |
4067 | |
|
4068 | 0 | if ((newsrv->flags & SRV_F_MAPPORTS) && (curproxy->options2 & PR_O2_RDPC_PRST)) { |
4069 | 0 | ha_warning("%s '%s' : RDP cookie persistence will not work for server '%s' because it lacks an explicit port number.\n", |
4070 | 0 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
4071 | 0 | err_code |= ERR_WARN; |
4072 | 0 | } |
4073 | |
|
4074 | 0 | #if defined(CONFIG_HAP_TRANSPARENT) |
4075 | 0 | if (curproxy->mode != PR_MODE_HTTP && newsrv->conn_src.bind_hdr_occ) { |
4076 | 0 | newsrv->conn_src.bind_hdr_occ = 0; |
4077 | 0 | ha_warning("%s '%s' : server %s cannot use header %s as source IP in non-HTTP mode.\n", |
4078 | 0 | proxy_type_str(curproxy), curproxy->id, newsrv->id, newsrv->conn_src.bind_hdr_name); |
4079 | 0 | err_code |= ERR_WARN; |
4080 | 0 | } |
4081 | 0 | #endif |
4082 | |
|
4083 | 0 | if ((curproxy->mode != PR_MODE_HTTP) && (curproxy->options & PR_O_REUSE_MASK) != PR_O_REUSE_NEVR) |
4084 | 0 | curproxy->options &= ~PR_O_REUSE_MASK; |
4085 | 0 | if (curproxy->mode == PR_MODE_SPOP) |
4086 | 0 | curproxy->options |= PR_O_REUSE_ALWS; |
4087 | |
|
4088 | 0 | if ((curproxy->mode != PR_MODE_HTTP) && newsrv->flags & SRV_F_RHTTP) { |
4089 | 0 | ha_alert("%s '%s' : server %s uses reverse HTTP addressing which can only be used with HTTP mode.\n", |
4090 | 0 | proxy_type_str(curproxy), curproxy->id, newsrv->id); |
4091 | 0 | cfgerr++; |
4092 | 0 | err_code |= ERR_FATAL | ERR_ALERT; |
4093 | 0 | goto out; |
4094 | 0 | } |
4095 | | |
4096 | 0 | newsrv = newsrv->next; |
4097 | 0 | } |
4098 | | |
4099 | | /* Check filter configuration, if any */ |
4100 | 0 | cfgerr += flt_check(curproxy); |
4101 | |
|
4102 | 0 | if (curproxy->cap & PR_CAP_FE) { |
4103 | 0 | if (!curproxy->accept) |
4104 | 0 | curproxy->accept = frontend_accept; |
4105 | |
|
4106 | 0 | if (!LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules) || |
4107 | 0 | (curproxy->defpx && !LIST_ISEMPTY(&curproxy->defpx->tcp_req.inspect_rules))) |
4108 | 0 | curproxy->fe_req_ana |= AN_REQ_INSPECT_FE; |
4109 | |
|
4110 | 0 | if (curproxy->mode == PR_MODE_HTTP) { |
4111 | 0 | curproxy->fe_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_PROCESS_FE; |
4112 | 0 | curproxy->fe_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_FE; |
4113 | 0 | } |
4114 | |
|
4115 | 0 | if (curproxy->mode == PR_MODE_CLI) { |
4116 | 0 | curproxy->fe_req_ana |= AN_REQ_WAIT_CLI; |
4117 | 0 | curproxy->fe_rsp_ana |= AN_RES_WAIT_CLI; |
4118 | 0 | } |
4119 | | |
4120 | | /* both TCP and HTTP must check switching rules */ |
4121 | 0 | curproxy->fe_req_ana |= AN_REQ_SWITCHING_RULES; |
4122 | | |
4123 | | /* Add filters analyzers if needed */ |
4124 | 0 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
4125 | 0 | curproxy->fe_req_ana |= AN_REQ_FLT_START_FE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
4126 | 0 | curproxy->fe_rsp_ana |= AN_RES_FLT_START_FE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END; |
4127 | 0 | } |
4128 | 0 | } |
4129 | |
|
4130 | 0 | if (curproxy->cap & PR_CAP_BE) { |
4131 | 0 | if (!LIST_ISEMPTY(&curproxy->tcp_req.inspect_rules) || |
4132 | 0 | (curproxy->defpx && !LIST_ISEMPTY(&curproxy->defpx->tcp_req.inspect_rules))) |
4133 | 0 | curproxy->be_req_ana |= AN_REQ_INSPECT_BE; |
4134 | |
|
4135 | 0 | if (!LIST_ISEMPTY(&curproxy->tcp_rep.inspect_rules) || |
4136 | 0 | (curproxy->defpx && !LIST_ISEMPTY(&curproxy->defpx->tcp_rep.inspect_rules))) |
4137 | 0 | curproxy->be_rsp_ana |= AN_RES_INSPECT; |
4138 | |
|
4139 | 0 | if (curproxy->mode == PR_MODE_HTTP) { |
4140 | 0 | curproxy->be_req_ana |= AN_REQ_WAIT_HTTP | AN_REQ_HTTP_INNER | AN_REQ_HTTP_PROCESS_BE; |
4141 | 0 | curproxy->be_rsp_ana |= AN_RES_WAIT_HTTP | AN_RES_HTTP_PROCESS_BE; |
4142 | 0 | } |
4143 | | |
4144 | | /* If the backend does requires RDP cookie persistence, we have to |
4145 | | * enable the corresponding analyser. |
4146 | | */ |
4147 | 0 | if (curproxy->options2 & PR_O2_RDPC_PRST) |
4148 | 0 | curproxy->be_req_ana |= AN_REQ_PRST_RDP_COOKIE; |
4149 | | |
4150 | | /* Add filters analyzers if needed */ |
4151 | 0 | if (!LIST_ISEMPTY(&curproxy->filter_configs)) { |
4152 | 0 | curproxy->be_req_ana |= AN_REQ_FLT_START_BE | AN_REQ_FLT_XFER_DATA | AN_REQ_FLT_END; |
4153 | 0 | curproxy->be_rsp_ana |= AN_RES_FLT_START_BE | AN_RES_FLT_XFER_DATA | AN_RES_FLT_END; |
4154 | 0 | } |
4155 | 0 | } |
4156 | | |
4157 | | /* Check the mux protocols, if any, for each server attached to |
4158 | | * the current proxy */ |
4159 | 0 | for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { |
4160 | 0 | int mode = conn_pr_mode_to_proto_mode(curproxy->mode); |
4161 | 0 | const struct mux_proto_list *mux_ent; |
4162 | |
|
4163 | 0 | if (srv_is_quic(newsrv)) { |
4164 | 0 | if (!newsrv->mux_proto) { |
4165 | | /* Force QUIC as mux-proto on server with quic addresses, similarly to bind on FE side. */ |
4166 | 0 | newsrv->mux_proto = get_mux_proto(ist("quic")); |
4167 | 0 | } |
4168 | 0 | } |
4169 | |
|
4170 | 0 | if (!newsrv->mux_proto) |
4171 | 0 | continue; |
4172 | | |
4173 | | /* it is possible that an incorrect mux was referenced |
4174 | | * due to the proxy's mode not being taken into account |
4175 | | * on first pass. Let's adjust it now. |
4176 | | */ |
4177 | 0 | mux_ent = conn_get_best_mux_entry(newsrv->mux_proto->token, PROTO_SIDE_BE, mode); |
4178 | |
|
4179 | 0 | if (!mux_ent || !isteq(mux_ent->token, newsrv->mux_proto->token)) { |
4180 | 0 | ha_alert("%s '%s' : MUX protocol '%.*s' is not usable for server '%s' at [%s:%d].\n", |
4181 | 0 | proxy_type_str(curproxy), curproxy->id, |
4182 | 0 | (int)newsrv->mux_proto->token.len, |
4183 | 0 | newsrv->mux_proto->token.ptr, |
4184 | 0 | newsrv->id, newsrv->conf.file, newsrv->conf.line); |
4185 | 0 | cfgerr++; |
4186 | 0 | } |
4187 | 0 | else { |
4188 | 0 | if ((mux_ent->mux->flags & MX_FL_FRAMED) && !srv_is_quic(newsrv)) { |
4189 | 0 | ha_alert("%s '%s' : MUX protocol '%.*s' is incompatible with stream transport used by server '%s' at [%s:%d].\n", |
4190 | 0 | proxy_type_str(curproxy), curproxy->id, |
4191 | 0 | (int)newsrv->mux_proto->token.len, |
4192 | 0 | newsrv->mux_proto->token.ptr, |
4193 | 0 | newsrv->id, newsrv->conf.file, newsrv->conf.line); |
4194 | 0 | cfgerr++; |
4195 | 0 | } |
4196 | 0 | else if (!(mux_ent->mux->flags & MX_FL_FRAMED) && srv_is_quic(newsrv)) { |
4197 | 0 | ha_alert("%s '%s' : MUX protocol '%.*s' is incompatible with framed transport used by server '%s' at [%s:%d].\n", |
4198 | 0 | proxy_type_str(curproxy), curproxy->id, |
4199 | 0 | (int)newsrv->mux_proto->token.len, |
4200 | 0 | newsrv->mux_proto->token.ptr, |
4201 | 0 | newsrv->id, newsrv->conf.file, newsrv->conf.line); |
4202 | 0 | cfgerr++; |
4203 | 0 | } |
4204 | 0 | } |
4205 | | |
4206 | | /* update the mux */ |
4207 | 0 | newsrv->mux_proto = mux_ent; |
4208 | 0 | } |
4209 | | |
4210 | | /* Allocate default tcp-check rules for proxies without |
4211 | | * explicit rules. |
4212 | | */ |
4213 | 0 | if (curproxy->cap & PR_CAP_BE) { |
4214 | 0 | if (!(curproxy->options2 & PR_O2_CHK_ANY)) { |
4215 | 0 | struct tcpcheck_ruleset *rs = NULL; |
4216 | 0 | struct tcpcheck_rules *rules = &curproxy->tcpcheck_rules; |
4217 | |
|
4218 | 0 | curproxy->options2 |= PR_O2_TCPCHK_CHK; |
4219 | |
|
4220 | 0 | rs = find_tcpcheck_ruleset("*tcp-check"); |
4221 | 0 | if (!rs) { |
4222 | 0 | rs = create_tcpcheck_ruleset("*tcp-check"); |
4223 | 0 | if (rs == NULL) { |
4224 | 0 | ha_alert("config: %s '%s': out of memory.\n", |
4225 | 0 | proxy_type_str(curproxy), curproxy->id); |
4226 | 0 | cfgerr++; |
4227 | 0 | } |
4228 | 0 | } |
4229 | |
|
4230 | 0 | free_tcpcheck_vars(&rules->preset_vars); |
4231 | 0 | rules->list = &rs->rules; |
4232 | 0 | rules->flags = 0; |
4233 | 0 | } |
4234 | 0 | } |
4235 | 0 | } |
4236 | | |
4237 | | /* |
4238 | | * We have just initialized the main proxies list |
4239 | | * we must also configure the log-forward proxies list |
4240 | | */ |
4241 | 0 | if (init_proxies_list == proxies_list) { |
4242 | 0 | init_proxies_list = cfg_log_forward; |
4243 | | /* check if list is not null to avoid infinite loop */ |
4244 | 0 | if (init_proxies_list) |
4245 | 0 | goto init_proxies_list_stage1; |
4246 | 0 | } |
4247 | | |
4248 | 0 | if (init_proxies_list == cfg_log_forward) { |
4249 | 0 | init_proxies_list = sink_proxies_list; |
4250 | | /* check if list is not null to avoid infinite loop */ |
4251 | 0 | if (init_proxies_list) |
4252 | 0 | goto init_proxies_list_stage1; |
4253 | 0 | } |
4254 | | |
4255 | | /***********************************************************/ |
4256 | | /* At this point, target names have already been resolved. */ |
4257 | | /***********************************************************/ |
4258 | | |
4259 | 0 | idle_conn_task = task_new_anywhere(); |
4260 | 0 | if (!idle_conn_task) { |
4261 | 0 | ha_alert("parsing : failed to allocate global idle connection task.\n"); |
4262 | 0 | cfgerr++; |
4263 | 0 | } |
4264 | 0 | else { |
4265 | 0 | idle_conn_task->process = srv_cleanup_idle_conns; |
4266 | 0 | idle_conn_task->context = NULL; |
4267 | |
|
4268 | 0 | for (i = 0; i < global.nbthread; i++) { |
4269 | 0 | idle_conns[i].cleanup_task = task_new_on(i); |
4270 | 0 | if (!idle_conns[i].cleanup_task) { |
4271 | 0 | ha_alert("parsing : failed to allocate idle connection tasks for thread '%d'.\n", i); |
4272 | 0 | cfgerr++; |
4273 | 0 | break; |
4274 | 0 | } |
4275 | | |
4276 | 0 | idle_conns[i].cleanup_task->process = srv_cleanup_toremove_conns; |
4277 | 0 | idle_conns[i].cleanup_task->context = NULL; |
4278 | 0 | HA_SPIN_INIT(&idle_conns[i].idle_conns_lock); |
4279 | 0 | MT_LIST_INIT(&idle_conns[i].toremove_conns); |
4280 | 0 | } |
4281 | 0 | } |
4282 | | |
4283 | | /* perform the final checks before creating tasks */ |
4284 | | |
4285 | | /* starting to initialize the main proxies list */ |
4286 | 0 | init_proxies_list = proxies_list; |
4287 | |
|
4288 | 0 | init_proxies_list_stage2: |
4289 | 0 | for (curproxy = init_proxies_list; curproxy; curproxy = curproxy->next) { |
4290 | 0 | struct listener *listener; |
4291 | 0 | unsigned int next_id; |
4292 | | |
4293 | | /* Configure SSL for each bind line. |
4294 | | * Note: if configuration fails at some point, the ->ctx member |
4295 | | * remains NULL so that listeners can later detach. |
4296 | | */ |
4297 | 0 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
4298 | 0 | if (bind_conf->xprt->prepare_bind_conf && |
4299 | 0 | bind_conf->xprt->prepare_bind_conf(bind_conf) < 0) |
4300 | 0 | cfgerr++; |
4301 | 0 | bind_conf->analysers |= curproxy->fe_req_ana; |
4302 | 0 | if (!bind_conf->maxaccept) |
4303 | 0 | bind_conf->maxaccept = global.tune.maxaccept ? global.tune.maxaccept : MAX_ACCEPT; |
4304 | 0 | bind_conf->accept = session_accept_fd; |
4305 | 0 | if (curproxy->options & PR_O_TCP_NOLING) |
4306 | 0 | bind_conf->options |= BC_O_NOLINGER; |
4307 | | |
4308 | | /* smart accept mode is automatic in HTTP mode */ |
4309 | 0 | if ((curproxy->options2 & PR_O2_SMARTACC) || |
4310 | 0 | ((curproxy->mode == PR_MODE_HTTP || (bind_conf->options & BC_O_USE_SSL)) && |
4311 | 0 | !(curproxy->no_options2 & PR_O2_SMARTACC))) |
4312 | 0 | bind_conf->options |= BC_O_NOQUICKACK; |
4313 | 0 | } |
4314 | | |
4315 | | /* adjust this proxy's listeners */ |
4316 | 0 | bind_conf = NULL; |
4317 | 0 | next_id = 1; |
4318 | 0 | list_for_each_entry(listener, &curproxy->conf.listeners, by_fe) { |
4319 | 0 | if (!listener->luid) { |
4320 | | /* listener ID not set, use automatic numbering with first |
4321 | | * spare entry starting with next_luid. |
4322 | | */ |
4323 | 0 | if (listener->by_fe.p != &curproxy->conf.listeners) { |
4324 | 0 | struct listener *prev_li = LIST_PREV(&listener->by_fe, typeof(prev_li), by_fe); |
4325 | 0 | if (prev_li->luid) |
4326 | 0 | next_id = prev_li->luid + 1; |
4327 | 0 | } |
4328 | 0 | next_id = listener_get_next_id(curproxy, next_id); |
4329 | 0 | listener->luid = next_id; |
4330 | 0 | listener_index_id(curproxy, listener); |
4331 | 0 | } |
4332 | 0 | next_id++; |
4333 | | |
4334 | | /* enable separate counters */ |
4335 | 0 | if (curproxy->options2 & PR_O2_SOCKSTAT) { |
4336 | 0 | listener->counters = calloc(1, sizeof(*listener->counters)); |
4337 | 0 | if (!listener->name) |
4338 | 0 | memprintf(&listener->name, "sock-%d", listener->luid); |
4339 | 0 | } |
4340 | |
|
4341 | | #ifdef USE_QUIC |
4342 | | if (listener->bind_conf->xprt == xprt_get(XPRT_QUIC)) { |
4343 | | /* quic_conn are counted against maxconn. */ |
4344 | | listener->bind_conf->options |= BC_O_XPRT_MAXCONN; |
4345 | | listener->rx.quic_curr_handshake = 0; |
4346 | | listener->rx.quic_curr_accept = 0; |
4347 | | |
4348 | | # ifdef USE_QUIC_OPENSSL_COMPAT |
4349 | | /* store the last checked bind_conf in bind_conf */ |
4350 | | if (!(quic_tune.fe.opts & QUIC_TUNE_FE_LISTEN_OFF) && |
4351 | | !(global.tune.options & GTUNE_LIMITED_QUIC) && |
4352 | | listener->bind_conf != bind_conf) { |
4353 | | bind_conf = listener->bind_conf; |
4354 | | ha_alert("Binding [%s:%d] for %s %s: this SSL library does not support the " |
4355 | | "QUIC protocol. A limited compatibility layer may be enabled using " |
4356 | | "the \"limited-quic\" global option if desired.\n", |
4357 | | listener->bind_conf->file, listener->bind_conf->line, |
4358 | | proxy_type_str(curproxy), curproxy->id); |
4359 | | cfgerr++; |
4360 | | } |
4361 | | # endif |
4362 | | |
4363 | | li_init_per_thr(listener); |
4364 | | } |
4365 | | #endif |
4366 | 0 | } |
4367 | | |
4368 | | /* Release unused SSL configs */ |
4369 | 0 | list_for_each_entry(bind_conf, &curproxy->conf.bind, by_fe) { |
4370 | 0 | if (!(bind_conf->options & BC_O_USE_SSL) && bind_conf->xprt->destroy_bind_conf) |
4371 | 0 | bind_conf->xprt->destroy_bind_conf(bind_conf); |
4372 | 0 | } |
4373 | | |
4374 | | /* create the task associated with the proxy */ |
4375 | 0 | curproxy->task = task_new_anywhere(); |
4376 | 0 | if (curproxy->task) { |
4377 | 0 | curproxy->task->context = curproxy; |
4378 | 0 | curproxy->task->process = manage_proxy; |
4379 | 0 | curproxy->flags |= PR_FL_READY; |
4380 | 0 | } else { |
4381 | 0 | ha_alert("Proxy '%s': no more memory when trying to allocate the management task\n", |
4382 | 0 | curproxy->id); |
4383 | 0 | cfgerr++; |
4384 | 0 | } |
4385 | 0 | } |
4386 | | |
4387 | | /* |
4388 | | * We have just initialized the main proxies list |
4389 | | * we must also configure the log-forward proxies list |
4390 | | */ |
4391 | 0 | if (init_proxies_list == proxies_list) { |
4392 | 0 | init_proxies_list = cfg_log_forward; |
4393 | | /* check if list is not null to avoid infinite loop */ |
4394 | 0 | if (init_proxies_list) |
4395 | 0 | goto init_proxies_list_stage2; |
4396 | 0 | } |
4397 | | |
4398 | 0 | if (init_proxies_list == cfg_log_forward) { |
4399 | 0 | init_proxies_list = sink_proxies_list; |
4400 | | /* check if list is not null to avoid infinite loop */ |
4401 | 0 | if (init_proxies_list) |
4402 | 0 | goto init_proxies_list_stage2; |
4403 | 0 | } |
4404 | | |
4405 | | /* |
4406 | | * Recount currently required checks. |
4407 | | */ |
4408 | | |
4409 | 0 | for (curproxy=proxies_list; curproxy; curproxy=curproxy->next) { |
4410 | 0 | int optnum; |
4411 | |
|
4412 | 0 | for (optnum = 0; cfg_opts[optnum].name; optnum++) |
4413 | 0 | if (curproxy->options & cfg_opts[optnum].val) |
4414 | 0 | global.last_checks |= cfg_opts[optnum].checks; |
4415 | |
|
4416 | 0 | for (optnum = 0; cfg_opts2[optnum].name; optnum++) |
4417 | 0 | if (curproxy->options2 & cfg_opts2[optnum].val) |
4418 | 0 | global.last_checks |= cfg_opts2[optnum].checks; |
4419 | 0 | } |
4420 | |
|
4421 | 0 | if (cfg_peers) { |
4422 | 0 | struct peers *curpeers = cfg_peers, **last; |
4423 | 0 | struct peer *p, *pb; |
4424 | | |
4425 | | /* Remove all peers sections which don't have a valid listener, |
4426 | | * which are not used by any table, or which are bound to more |
4427 | | * than one process. |
4428 | | */ |
4429 | 0 | last = &cfg_peers; |
4430 | 0 | while (*last) { |
4431 | 0 | struct peer *peer; |
4432 | 0 | struct stktable *t; |
4433 | 0 | curpeers = *last; |
4434 | |
|
4435 | 0 | if (curpeers->disabled) { |
4436 | | /* the "disabled" keyword was present */ |
4437 | 0 | if (curpeers->peers_fe) |
4438 | 0 | stop_proxy(curpeers->peers_fe); |
4439 | 0 | curpeers->peers_fe = NULL; |
4440 | 0 | } |
4441 | 0 | else if (!curpeers->peers_fe || !curpeers->peers_fe->id) { |
4442 | 0 | ha_warning("Removing incomplete section 'peers %s' (no peer named '%s').\n", |
4443 | 0 | curpeers->id, localpeer); |
4444 | 0 | if (curpeers->peers_fe) |
4445 | 0 | stop_proxy(curpeers->peers_fe); |
4446 | 0 | curpeers->peers_fe = NULL; |
4447 | 0 | } |
4448 | 0 | else { |
4449 | | /* Initializes the transport layer of the server part of all the peers belonging to |
4450 | | * <curpeers> section if required. |
4451 | | * Note that ->srv is used by the local peer of a new process to connect to the local peer |
4452 | | * of an old process. |
4453 | | */ |
4454 | 0 | curpeers->peers_fe->flags |= PR_FL_READY; |
4455 | 0 | p = curpeers->remote; |
4456 | 0 | while (p) { |
4457 | 0 | struct peer *other_peer; |
4458 | |
|
4459 | 0 | for (other_peer = curpeers->remote; other_peer && other_peer != p; other_peer = other_peer->next) { |
4460 | 0 | if (strcmp(other_peer->id, p->id) == 0) { |
4461 | 0 | ha_alert("Peer section '%s' [%s:%d]: another peer named '%s' was already defined at line %s:%d, please use distinct names.\n", |
4462 | 0 | curpeers->peers_fe->id, |
4463 | 0 | p->conf.file, p->conf.line, |
4464 | 0 | other_peer->id, other_peer->conf.file, other_peer->conf.line); |
4465 | 0 | cfgerr++; |
4466 | 0 | break; |
4467 | 0 | } |
4468 | 0 | } |
4469 | |
|
4470 | 0 | if (p->srv) { |
4471 | 0 | if (p->srv->use_ssl == 1 && xprt_get(XPRT_SSL) && xprt_get(XPRT_SSL)->prepare_srv) |
4472 | 0 | cfgerr += xprt_get(XPRT_SSL)->prepare_srv(p->srv); |
4473 | 0 | } |
4474 | 0 | p = p->next; |
4475 | 0 | } |
4476 | | /* Configure the SSL bindings of the local peer if required. */ |
4477 | 0 | if (!LIST_ISEMPTY(&curpeers->peers_fe->conf.bind)) { |
4478 | 0 | struct list *l; |
4479 | 0 | struct bind_conf *bind_conf; |
4480 | 0 | int ret; |
4481 | |
|
4482 | 0 | l = &curpeers->peers_fe->conf.bind; |
4483 | 0 | bind_conf = LIST_ELEM(l->n, typeof(bind_conf), by_fe); |
4484 | |
|
4485 | 0 | if (curpeers->local->srv) { |
4486 | 0 | if (curpeers->local->srv->use_ssl == 1 && !(bind_conf->options & BC_O_USE_SSL)) { |
4487 | 0 | ha_warning("Peers section '%s': local peer have a non-SSL listener and a SSL server configured at line %s:%d.\n", |
4488 | 0 | curpeers->peers_fe->id, curpeers->local->conf.file, curpeers->local->conf.line); |
4489 | 0 | } |
4490 | 0 | else if (curpeers->local->srv->use_ssl != 1 && (bind_conf->options & BC_O_USE_SSL)) { |
4491 | 0 | ha_warning("Peers section '%s': local peer have a SSL listener and a non-SSL server configured at line %s:%d.\n", |
4492 | 0 | curpeers->peers_fe->id, curpeers->local->conf.file, curpeers->local->conf.line); |
4493 | 0 | } |
4494 | 0 | } |
4495 | | |
4496 | | /* finish the bind setup */ |
4497 | 0 | ret = bind_complete_thread_setup(bind_conf, &err_code); |
4498 | 0 | if (ret != 0) { |
4499 | 0 | cfgerr += ret; |
4500 | 0 | if (err_code & ERR_FATAL) |
4501 | 0 | goto out; |
4502 | 0 | } |
4503 | | |
4504 | 0 | if (bind_conf->xprt->prepare_bind_conf && |
4505 | 0 | bind_conf->xprt->prepare_bind_conf(bind_conf) < 0) |
4506 | 0 | cfgerr++; |
4507 | 0 | } |
4508 | 0 | if (!peers_init_sync(curpeers) || !peers_alloc_dcache(curpeers)) { |
4509 | 0 | ha_alert("Peers section '%s': out of memory, giving up on peers.\n", |
4510 | 0 | curpeers->id); |
4511 | 0 | cfgerr++; |
4512 | 0 | break; |
4513 | 0 | } |
4514 | 0 | last = &curpeers->next; |
4515 | | |
4516 | | /* Ignore the peer shard greater than the number of peer shard for this section. |
4517 | | * Also ignore the peer shard of the local peer. |
4518 | | */ |
4519 | 0 | for (peer = curpeers->remote; peer; peer = peer->next) { |
4520 | 0 | if (peer == curpeers->local) { |
4521 | 0 | if (peer->srv->shard) { |
4522 | 0 | ha_warning("Peers section '%s': shard ignored for '%s' local peer\n", |
4523 | 0 | curpeers->id, peer->id); |
4524 | 0 | peer->srv->shard = 0; |
4525 | 0 | } |
4526 | 0 | } |
4527 | 0 | else if (peer->srv->shard > curpeers->nb_shards) { |
4528 | 0 | ha_warning("Peers section '%s': shard ignored for '%s' local peer because " |
4529 | 0 | "%d shard value is greater than the section number of shards (%d)\n", |
4530 | 0 | curpeers->id, peer->id, peer->srv->shard, curpeers->nb_shards); |
4531 | 0 | peer->srv->shard = 0; |
4532 | 0 | } |
4533 | 0 | } |
4534 | |
|
4535 | 0 | continue; |
4536 | 0 | } |
4537 | | |
4538 | | /* clean what has been detected above */ |
4539 | 0 | p = curpeers->remote; |
4540 | 0 | while (p) { |
4541 | 0 | pb = p->next; |
4542 | 0 | free(p->id); |
4543 | 0 | free(p); |
4544 | 0 | p = pb; |
4545 | 0 | } |
4546 | | |
4547 | | /* Destroy and unlink this curpeers section. |
4548 | | * Note: curpeers is backed up into *last. |
4549 | | */ |
4550 | 0 | free(curpeers->id); |
4551 | 0 | curpeers = curpeers->next; |
4552 | | /* Reset any refereance to this peers section in the list of stick-tables */ |
4553 | 0 | for (t = stktables_list; t; t = t->next) { |
4554 | 0 | if (t->peers.p && t->peers.p == *last) |
4555 | 0 | t->peers.p = NULL; |
4556 | 0 | } |
4557 | 0 | free(*last); |
4558 | 0 | *last = curpeers; |
4559 | 0 | } |
4560 | 0 | } |
4561 | | |
4562 | 0 | for (t = stktables_list; t; t = t->next) { |
4563 | 0 | if (t->proxy) |
4564 | 0 | continue; |
4565 | 0 | err = NULL; |
4566 | 0 | if (!stktable_init(t, &err)) { |
4567 | 0 | ha_alert("Parsing [%s:%d]: failed to initialize '%s' stick-table: %s.\n", t->conf.file, t->conf.line, t->id, err); |
4568 | 0 | ha_free(&err); |
4569 | 0 | cfgerr++; |
4570 | 0 | } |
4571 | 0 | } |
4572 | | |
4573 | | /* initialize stick-tables on backend capable proxies. This must not |
4574 | | * be done earlier because the data size may be discovered while parsing |
4575 | | * other proxies. |
4576 | | */ |
4577 | 0 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
4578 | 0 | if ((curproxy->flags & PR_FL_DISABLED) || !curproxy->table) |
4579 | 0 | continue; |
4580 | | |
4581 | 0 | err = NULL; |
4582 | 0 | if (!stktable_init(curproxy->table, &err)) { |
4583 | 0 | ha_alert("Proxy '%s': failed to initialize stick-table: %s.\n", curproxy->id, err); |
4584 | 0 | ha_free(&err); |
4585 | 0 | cfgerr++; |
4586 | 0 | } |
4587 | 0 | } |
4588 | |
|
4589 | 0 | if (mailers) { |
4590 | 0 | struct mailers *curmailers = mailers, **last; |
4591 | 0 | struct mailer *m, *mb; |
4592 | | |
4593 | | /* Remove all mailers sections which don't have a valid listener. |
4594 | | * This can happen when a mailers section is never referenced. |
4595 | | */ |
4596 | 0 | last = &mailers; |
4597 | 0 | while (*last) { |
4598 | 0 | curmailers = *last; |
4599 | 0 | if (curmailers->users) { |
4600 | 0 | last = &curmailers->next; |
4601 | 0 | continue; |
4602 | 0 | } |
4603 | | |
4604 | 0 | ha_warning("Removing incomplete section 'mailers %s'.\n", |
4605 | 0 | curmailers->id); |
4606 | |
|
4607 | 0 | m = curmailers->mailer_list; |
4608 | 0 | while (m) { |
4609 | 0 | mb = m->next; |
4610 | 0 | free(m->id); |
4611 | 0 | free(m); |
4612 | 0 | m = mb; |
4613 | 0 | } |
4614 | | |
4615 | | /* Destroy and unlink this curmailers section. |
4616 | | * Note: curmailers is backed up into *last. |
4617 | | */ |
4618 | 0 | free(curmailers->id); |
4619 | 0 | curmailers = curmailers->next; |
4620 | 0 | free(*last); |
4621 | 0 | *last = curmailers; |
4622 | 0 | } |
4623 | 0 | } |
4624 | | |
4625 | | /* Update server_state_file_name to backend name if backend is supposed to use |
4626 | | * a server-state file locally defined and none has been provided */ |
4627 | 0 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
4628 | 0 | if (curproxy->load_server_state_from_file == PR_SRV_STATE_FILE_LOCAL && |
4629 | 0 | curproxy->server_state_file_name == NULL) |
4630 | 0 | curproxy->server_state_file_name = strdup(curproxy->id); |
4631 | 0 | } |
4632 | |
|
4633 | 0 | list_for_each_entry(curr_resolvers, &sec_resolvers, list) { |
4634 | 0 | if (LIST_ISEMPTY(&curr_resolvers->nameservers)) { |
4635 | 0 | ha_warning("resolvers '%s' [%s:%d] has no nameservers configured!\n", |
4636 | 0 | curr_resolvers->id, curr_resolvers->conf.file, |
4637 | 0 | curr_resolvers->conf.line); |
4638 | 0 | err_code |= ERR_WARN; |
4639 | 0 | } |
4640 | 0 | } |
4641 | |
|
4642 | 0 | list_for_each_entry(postparser, &postparsers, list) { |
4643 | 0 | if (postparser->func) |
4644 | 0 | cfgerr += postparser->func(); |
4645 | 0 | } |
4646 | |
|
4647 | 0 | if (experimental_directives_allowed && |
4648 | 0 | !(get_tainted() & TAINTED_CONFIG_EXP_KW_DECLARED)) { |
4649 | 0 | ha_warning("Option 'expose-experimental-directives' is set in the global section but is " |
4650 | 0 | "no longer used. It is strongly recommended to remove it in order to avoid " |
4651 | 0 | "using an experimental directive by accident in the future.\n"); |
4652 | 0 | err_code |= ERR_WARN; |
4653 | 0 | } |
4654 | |
|
4655 | 0 | if (cfgerr > 0) |
4656 | 0 | err_code |= ERR_ALERT | ERR_FATAL; |
4657 | 0 | out: |
4658 | 0 | return err_code; |
4659 | 0 | } |
4660 | | |
4661 | | /* |
4662 | | * Registers the CFG keyword list <kwl> as a list of valid keywords for next |
4663 | | * parsing sessions. |
4664 | | */ |
4665 | | void cfg_register_keywords(struct cfg_kw_list *kwl) |
4666 | 0 | { |
4667 | 0 | LIST_APPEND(&cfg_keywords.list, &kwl->list); |
4668 | 0 | } |
4669 | | |
4670 | | /* |
4671 | | * Unregisters the CFG keyword list <kwl> from the list of valid keywords. |
4672 | | */ |
4673 | | void cfg_unregister_keywords(struct cfg_kw_list *kwl) |
4674 | 0 | { |
4675 | 0 | LIST_DELETE(&kwl->list); |
4676 | 0 | LIST_INIT(&kwl->list); |
4677 | 0 | } |
4678 | | |
4679 | | /* this function register new section in the haproxy configuration file. |
4680 | | * <section_name> is the name of this new section and <section_parser> |
4681 | | * is the called parser. If two section declaration have the same name, |
4682 | | * only the first declared is used. |
4683 | | */ |
4684 | | int cfg_register_section(char *section_name, |
4685 | | int (*section_parser)(const char *, int, char **, int), |
4686 | | int (*post_section_parser)()) |
4687 | 0 | { |
4688 | 0 | struct cfg_section *cs; |
4689 | |
|
4690 | 0 | if (section_parser) { |
4691 | | /* only checks if we register a section parser, not a post section callback */ |
4692 | 0 | list_for_each_entry(cs, §ions, list) { |
4693 | 0 | if (strcmp(cs->section_name, section_name) == 0 && cs->section_parser) { |
4694 | 0 | ha_alert("register section '%s': already registered.\n", section_name); |
4695 | 0 | return 0; |
4696 | 0 | } |
4697 | 0 | } |
4698 | 0 | } |
4699 | | |
4700 | 0 | cs = calloc(1, sizeof(*cs)); |
4701 | 0 | if (!cs) { |
4702 | 0 | ha_alert("register section '%s': out of memory.\n", section_name); |
4703 | 0 | return 0; |
4704 | 0 | } |
4705 | | |
4706 | 0 | cs->section_name = section_name; |
4707 | 0 | cs->section_parser = section_parser; |
4708 | 0 | cs->post_section_parser = post_section_parser; |
4709 | |
|
4710 | 0 | LIST_APPEND(§ions, &cs->list); |
4711 | |
|
4712 | 0 | return 1; |
4713 | 0 | } |
4714 | | |
4715 | | /* this function register a new function which will be called once the haproxy |
4716 | | * configuration file has been parsed. It's useful to check dependencies |
4717 | | * between sections or to resolve items once everything is parsed. |
4718 | | */ |
4719 | | int cfg_register_postparser(char *name, int (*func)()) |
4720 | 0 | { |
4721 | 0 | struct cfg_postparser *cp; |
4722 | |
|
4723 | 0 | cp = calloc(1, sizeof(*cp)); |
4724 | 0 | if (!cp) { |
4725 | 0 | ha_alert("register postparser '%s': out of memory.\n", name); |
4726 | 0 | return 0; |
4727 | 0 | } |
4728 | 0 | cp->name = name; |
4729 | 0 | cp->func = func; |
4730 | |
|
4731 | 0 | LIST_APPEND(&postparsers, &cp->list); |
4732 | |
|
4733 | 0 | return 1; |
4734 | 0 | } |
4735 | | |
4736 | | /* |
4737 | | * free all config section entries |
4738 | | */ |
4739 | | void cfg_unregister_sections(void) |
4740 | 0 | { |
4741 | 0 | struct cfg_section *cs, *ics; |
4742 | |
|
4743 | 0 | list_for_each_entry_safe(cs, ics, §ions, list) { |
4744 | 0 | LIST_DELETE(&cs->list); |
4745 | 0 | free(cs); |
4746 | 0 | } |
4747 | 0 | } |
4748 | | |
4749 | | void cfg_backup_sections(struct list *backup_sections) |
4750 | 0 | { |
4751 | 0 | struct cfg_section *cs, *ics; |
4752 | |
|
4753 | 0 | list_for_each_entry_safe(cs, ics, §ions, list) { |
4754 | 0 | LIST_DELETE(&cs->list); |
4755 | 0 | LIST_APPEND(backup_sections, &cs->list); |
4756 | 0 | } |
4757 | 0 | } |
4758 | | |
4759 | | void cfg_restore_sections(struct list *backup_sections) |
4760 | 0 | { |
4761 | 0 | struct cfg_section *cs, *ics; |
4762 | |
|
4763 | 0 | list_for_each_entry_safe(cs, ics, backup_sections, list) { |
4764 | 0 | LIST_DELETE(&cs->list); |
4765 | 0 | LIST_APPEND(§ions, &cs->list); |
4766 | 0 | } |
4767 | 0 | } |
4768 | | |
4769 | | /* dumps all registered keywords by section on stdout */ |
4770 | | void cfg_dump_registered_keywords() |
4771 | 0 | { |
4772 | | /* CFG_GLOBAL, CFG_LISTEN, CFG_USERLIST, CFG_PEERS, CFG_CRTLIST, CFG_CRTSTORE, CFG_TRACES, CFG_ACME */ |
4773 | 0 | const char* sect_names[] = { "", "global", "listen", "userlist", "peers", "crt-list", "crt-store", "traces", "acme", 0 }; |
4774 | 0 | int section; |
4775 | 0 | int index; |
4776 | |
|
4777 | 0 | for (section = 1; sect_names[section]; section++) { |
4778 | 0 | struct cfg_kw_list *kwl; |
4779 | 0 | const struct cfg_keyword *kwp, *kwn; |
4780 | |
|
4781 | 0 | printf("%s\n", sect_names[section]); |
4782 | |
|
4783 | 0 | for (kwn = kwp = NULL;; kwp = kwn) { |
4784 | 0 | list_for_each_entry(kwl, &cfg_keywords.list, list) { |
4785 | 0 | for (index = 0; kwl->kw[index].kw != NULL; index++) |
4786 | 0 | if (kwl->kw[index].section == section && |
4787 | 0 | strordered(kwp ? kwp->kw : NULL, kwl->kw[index].kw, kwn != kwp ? kwn->kw : NULL)) |
4788 | 0 | kwn = &kwl->kw[index]; |
4789 | 0 | } |
4790 | 0 | if (kwn == kwp) |
4791 | 0 | break; |
4792 | 0 | printf("\t%s\n", kwn->kw); |
4793 | 0 | } |
4794 | |
|
4795 | 0 | if (section == CFG_LISTEN) { |
4796 | | /* there are plenty of other keywords there */ |
4797 | 0 | extern struct list tcp_req_conn_keywords, tcp_req_sess_keywords, |
4798 | 0 | tcp_req_cont_keywords, tcp_res_cont_keywords; |
4799 | 0 | extern struct bind_kw_list bind_keywords; |
4800 | 0 | extern struct srv_kw_list srv_keywords; |
4801 | 0 | struct bind_kw_list *bkwl; |
4802 | 0 | struct srv_kw_list *skwl; |
4803 | 0 | const struct bind_kw *bkwp, *bkwn; |
4804 | 0 | const struct srv_kw *skwp, *skwn; |
4805 | 0 | const struct cfg_opt *coptp, *coptn; |
4806 | | |
4807 | | /* display the non-ssl keywords */ |
4808 | 0 | for (bkwn = bkwp = NULL;; bkwp = bkwn) { |
4809 | 0 | list_for_each_entry(bkwl, &bind_keywords.list, list) { |
4810 | 0 | if (strcmp(bkwl->scope, "SSL") == 0) /* skip SSL keywords */ |
4811 | 0 | continue; |
4812 | 0 | for (index = 0; bkwl->kw[index].kw != NULL; index++) { |
4813 | 0 | if (strordered(bkwp ? bkwp->kw : NULL, |
4814 | 0 | bkwl->kw[index].kw, |
4815 | 0 | bkwn != bkwp ? bkwn->kw : NULL)) |
4816 | 0 | bkwn = &bkwl->kw[index]; |
4817 | 0 | } |
4818 | 0 | } |
4819 | 0 | if (bkwn == bkwp) |
4820 | 0 | break; |
4821 | | |
4822 | 0 | if (!bkwn->skip) |
4823 | 0 | printf("\tbind <addr> %s\n", bkwn->kw); |
4824 | 0 | else |
4825 | 0 | printf("\tbind <addr> %s +%d\n", bkwn->kw, bkwn->skip); |
4826 | 0 | } |
4827 | | #if defined(USE_OPENSSL) |
4828 | | /* displays the "ssl" keywords */ |
4829 | | for (bkwn = bkwp = NULL;; bkwp = bkwn) { |
4830 | | list_for_each_entry(bkwl, &bind_keywords.list, list) { |
4831 | | if (strcmp(bkwl->scope, "SSL") != 0) /* skip non-SSL keywords */ |
4832 | | continue; |
4833 | | for (index = 0; bkwl->kw[index].kw != NULL; index++) { |
4834 | | if (strordered(bkwp ? bkwp->kw : NULL, |
4835 | | bkwl->kw[index].kw, |
4836 | | bkwn != bkwp ? bkwn->kw : NULL)) |
4837 | | bkwn = &bkwl->kw[index]; |
4838 | | } |
4839 | | } |
4840 | | if (bkwn == bkwp) |
4841 | | break; |
4842 | | |
4843 | | if (strcmp(bkwn->kw, "ssl") == 0) /* skip "bind <addr> ssl ssl" */ |
4844 | | continue; |
4845 | | |
4846 | | if (!bkwn->skip) |
4847 | | printf("\tbind <addr> ssl %s\n", bkwn->kw); |
4848 | | else |
4849 | | printf("\tbind <addr> ssl %s +%d\n", bkwn->kw, bkwn->skip); |
4850 | | } |
4851 | | #endif |
4852 | 0 | for (skwn = skwp = NULL;; skwp = skwn) { |
4853 | 0 | list_for_each_entry(skwl, &srv_keywords.list, list) { |
4854 | 0 | for (index = 0; skwl->kw[index].kw != NULL; index++) |
4855 | 0 | if (strordered(skwp ? skwp->kw : NULL, |
4856 | 0 | skwl->kw[index].kw, |
4857 | 0 | skwn != skwp ? skwn->kw : NULL)) |
4858 | 0 | skwn = &skwl->kw[index]; |
4859 | 0 | } |
4860 | 0 | if (skwn == skwp) |
4861 | 0 | break; |
4862 | | |
4863 | 0 | if (!skwn->skip) |
4864 | 0 | printf("\tserver <name> <addr> %s\n", skwn->kw); |
4865 | 0 | else |
4866 | 0 | printf("\tserver <name> <addr> %s +%d\n", skwn->kw, skwn->skip); |
4867 | 0 | } |
4868 | |
|
4869 | 0 | for (coptn = coptp = NULL;; coptp = coptn) { |
4870 | 0 | for (index = 0; cfg_opts[index].name; index++) |
4871 | 0 | if (strordered(coptp ? coptp->name : NULL, |
4872 | 0 | cfg_opts[index].name, |
4873 | 0 | coptn != coptp ? coptn->name : NULL)) |
4874 | 0 | coptn = &cfg_opts[index]; |
4875 | |
|
4876 | 0 | for (index = 0; cfg_opts2[index].name; index++) |
4877 | 0 | if (strordered(coptp ? coptp->name : NULL, |
4878 | 0 | cfg_opts2[index].name, |
4879 | 0 | coptn != coptp ? coptn->name : NULL)) |
4880 | 0 | coptn = &cfg_opts2[index]; |
4881 | 0 | if (coptn == coptp) |
4882 | 0 | break; |
4883 | | |
4884 | 0 | printf("\toption %s [ ", coptn->name); |
4885 | 0 | if (coptn->cap & PR_CAP_FE) |
4886 | 0 | printf("FE "); |
4887 | 0 | if (coptn->cap & PR_CAP_BE) |
4888 | 0 | printf("BE "); |
4889 | 0 | if (coptn->mode == PR_MODE_HTTP) |
4890 | 0 | printf("HTTP "); |
4891 | 0 | printf("]\n"); |
4892 | 0 | } |
4893 | |
|
4894 | 0 | dump_act_rules(&tcp_req_conn_keywords, "\ttcp-request connection "); |
4895 | 0 | dump_act_rules(&tcp_req_sess_keywords, "\ttcp-request session "); |
4896 | 0 | dump_act_rules(&tcp_req_cont_keywords, "\ttcp-request content "); |
4897 | 0 | dump_act_rules(&tcp_res_cont_keywords, "\ttcp-response content "); |
4898 | 0 | dump_act_rules(&http_req_keywords.list, "\thttp-request "); |
4899 | 0 | dump_act_rules(&http_res_keywords.list, "\thttp-response "); |
4900 | 0 | dump_act_rules(&http_after_res_keywords.list, "\thttp-after-response "); |
4901 | 0 | } |
4902 | 0 | if (section == CFG_PEERS) { |
4903 | 0 | struct peers_kw_list *pkwl; |
4904 | 0 | const struct peers_keyword *pkwp, *pkwn; |
4905 | 0 | for (pkwn = pkwp = NULL;; pkwp = pkwn) { |
4906 | 0 | list_for_each_entry(pkwl, &peers_keywords.list, list) { |
4907 | 0 | for (index = 0; pkwl->kw[index].kw != NULL; index++) { |
4908 | 0 | if (strordered(pkwp ? pkwp->kw : NULL, |
4909 | 0 | pkwl->kw[index].kw, |
4910 | 0 | pkwn != pkwp ? pkwn->kw : NULL)) |
4911 | 0 | pkwn = &pkwl->kw[index]; |
4912 | 0 | } |
4913 | 0 | } |
4914 | 0 | if (pkwn == pkwp) |
4915 | 0 | break; |
4916 | 0 | printf("\t%s\n", pkwn->kw); |
4917 | 0 | } |
4918 | 0 | } |
4919 | 0 | if (section == CFG_CRTLIST) { |
4920 | | /* displays the keyword available for the crt-lists */ |
4921 | 0 | extern struct ssl_crtlist_kw ssl_crtlist_kws[] __maybe_unused; |
4922 | 0 | const struct ssl_crtlist_kw *sbkwp __maybe_unused, *sbkwn __maybe_unused; |
4923 | |
|
4924 | | #if defined(USE_OPENSSL) |
4925 | | for (sbkwn = sbkwp = NULL;; sbkwp = sbkwn) { |
4926 | | for (index = 0; ssl_crtlist_kws[index].kw != NULL; index++) { |
4927 | | if (strordered(sbkwp ? sbkwp->kw : NULL, |
4928 | | ssl_crtlist_kws[index].kw, |
4929 | | sbkwn != sbkwp ? sbkwn->kw : NULL)) |
4930 | | sbkwn = &ssl_crtlist_kws[index]; |
4931 | | } |
4932 | | if (sbkwn == sbkwp) |
4933 | | break; |
4934 | | if (!sbkwn->skip) |
4935 | | printf("\t%s\n", sbkwn->kw); |
4936 | | else |
4937 | | printf("\t%s +%d\n", sbkwn->kw, sbkwn->skip); |
4938 | | } |
4939 | | #endif |
4940 | |
|
4941 | 0 | } |
4942 | 0 | } |
4943 | 0 | } |
4944 | | |
4945 | | /* these are the config sections handled by default */ |
4946 | | REGISTER_CONFIG_SECTION("listen", cfg_parse_listen, NULL); |
4947 | | REGISTER_CONFIG_SECTION("frontend", cfg_parse_listen, NULL); |
4948 | | REGISTER_CONFIG_SECTION("backend", cfg_parse_listen, NULL); |
4949 | | REGISTER_CONFIG_SECTION("defaults", cfg_parse_listen, NULL); |
4950 | | REGISTER_CONFIG_SECTION("global", cfg_parse_global, NULL); |
4951 | | REGISTER_CONFIG_SECTION("userlist", cfg_parse_users, NULL); |
4952 | | REGISTER_CONFIG_SECTION("peers", cfg_parse_peers, NULL); |
4953 | | REGISTER_CONFIG_SECTION("mailers", cfg_parse_mailers, NULL); |
4954 | | REGISTER_CONFIG_SECTION("namespace_list", cfg_parse_netns, NULL); |
4955 | | REGISTER_CONFIG_SECTION("traces", cfg_parse_traces, NULL); |
4956 | | |
4957 | | static struct cfg_kw_list cfg_kws = {{ },{ |
4958 | | { CFG_GLOBAL, "default-path", cfg_parse_global_def_path }, |
4959 | | { /* END */ } |
4960 | | }}; |
4961 | | |
4962 | | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |
4963 | | |
4964 | | /* |
4965 | | * Local variables: |
4966 | | * c-indent-level: 8 |
4967 | | * c-basic-offset: 8 |
4968 | | * End: |
4969 | | */ |