80
80
* return zero, it may write an error message into the <err> buffer, for at
81
81
* most <errlen> bytes, trailing zero included. The trailing '\n' must not
82
82
* be written. The function must be called with <args> pointing to the first
83
* word after "timeout", with <proxy> pointing to the proxy being parsed, and
83
* command line word, with <proxy> pointing to the proxy being parsed, and
84
84
* <defpx> to the default proxy or NULL. As a special case for compatibility
85
85
* with older configs, it also accepts "{cli|srv|con}timeout" in args[0].
87
int proxy_parse_timeout(const char **args, struct proxy *proxy,
88
struct proxy *defpx, char *err, int errlen)
87
static int proxy_parse_timeout(char **args, int section, struct proxy *proxy,
88
struct proxy *defpx, char *err, int errlen)
92
92
const char *res, *name;
93
struct timeval *tv = NULL;
94
struct timeval *td = NULL;
98
/* simply skip "timeout" but remain compatible with old form */
99
if (strcmp(args[0], "timeout") == 0)
98
103
if (!strcmp(args[0], "client") || !strcmp(args[0], "clitimeout")) {
146
151
res = parse_time_err(args[1], &timeout, TIME_UNIT_MS);
148
snprintf(err, errlen, "unexpected character '%c' in %s timeout", *err, name);
153
snprintf(err, errlen, "unexpected character '%c' in %s timeout", *res, name);
155
160
(cap & PR_CAP_BE) ? "backend" : "frontend");
158
else if (defpx && !__tv_iseq(tv, td)) {
163
else if (defpx && *tv != *td) {
159
164
snprintf(err, errlen, "overwriting %s timeout which was already specified", name);
164
__tv_from_ms(tv, timeout);
168
*tv = MS_TO_TICKS(timeout);
172
/* This function parses a "rate-limit" statement in a proxy section. It returns
173
* -1 if there is any error, 1 for a warning, otherwise zero. If it does not
174
* return zero, it may write an error message into the <err> buffer, for at
175
* most <errlen> bytes, trailing zero included. The trailing '\n' must not
176
* be written. The function must be called with <args> pointing to the first
177
* command line word, with <proxy> pointing to the proxy being parsed, and
178
* <defpx> to the default proxy or NULL.
180
static int proxy_parse_rate_limit(char **args, int section, struct proxy *proxy,
181
struct proxy *defpx, char *err, int errlen)
185
unsigned int *tv = NULL;
186
unsigned int *td = NULL;
191
/* simply skip "rate-limit" */
192
if (strcmp(args[0], "rate-limit") == 0)
196
if (!strcmp(args[0], "sessions")) {
198
tv = &proxy->fe_sps_lim;
199
td = &defpx->fe_sps_lim;
202
snprintf(err, errlen,
203
"%s '%s': must be 'sessions'",
204
"rate-limit", args[0]);
209
snprintf(err, errlen, "%s %s expects expects an integer value (in sessions/second)", "rate-limit", name);
213
val = strtoul(args[1], &res, 0);
215
snprintf(err, errlen, "%s %s: unexpected character '%c' in integer value '%s'", "rate-limit", name, *res, args[1]);
219
if (!(proxy->cap & cap)) {
220
snprintf(err, errlen, "%s %s will be ignored because %s '%s' has no %s capability",
221
"rate-limit", name, proxy_type_str(proxy), proxy->id,
222
(cap & PR_CAP_BE) ? "backend" : "frontend");
225
else if (defpx && *tv != *td) {
226
snprintf(err, errlen, "overwriting %s %s which was already specified", "rate-limit", name);
300
/* This function checks that the designated proxy has no http directives
301
* enabled. It will output a warning if there are, and will fix some of them.
302
* It returns the number of fatal errors encountered. This should be called
303
* at the end of the configuration parsing if the proxy is not in http mode.
304
* The <file> argument is used to construct the error message.
306
int proxy_cfg_ensure_no_http(struct proxy *curproxy, const char *file)
308
if (curproxy->cookie_name != NULL) {
309
Warning("parsing %s : cookie will be ignored for %s '%s' (needs 'mode http').\n",
310
file, proxy_type_str(curproxy), curproxy->id);
312
if (curproxy->rsp_exp != NULL) {
313
Warning("parsing %s : server regular expressions will be ignored for %s '%s' (needs 'mode http').\n",
314
file, proxy_type_str(curproxy), curproxy->id);
316
if (curproxy->req_exp != NULL) {
317
Warning("parsing %s : client regular expressions will be ignored for %s '%s' (needs 'mode http').\n",
318
file, proxy_type_str(curproxy), curproxy->id);
320
if (curproxy->monitor_uri != NULL) {
321
Warning("parsing %s : monitor-uri will be ignored for %s '%s' (needs 'mode http').\n",
322
file, proxy_type_str(curproxy), curproxy->id);
324
if (curproxy->lbprm.algo & BE_LB_PROP_L7) {
325
curproxy->lbprm.algo &= ~BE_LB_ALGO;
326
curproxy->lbprm.algo |= BE_LB_ALGO_RR;
327
Warning("parsing %s : Layer 7 hash not possible for %s '%s' (needs 'mode http'). Falling back to round robin.\n",
328
file, proxy_type_str(curproxy), curproxy->id);
238
334
* This function creates all proxy sockets. It should be done very early,
239
335
* typically before privileges are dropped. The sockets will be registered
301
397
* this function enables proxies when there are enough free sessions,
302
398
* or stops them when the table is full. It is designed to be called from the
303
* select_loop(). It returns the date of next expiration event during stop
304
* time, ETERNITY otherwise.
399
* select_loop(). It adjusts the date of next expiration event during stop
400
* time if appropriate.
306
void maintain_proxies(struct timeval *next)
402
void maintain_proxies(int *next)
309
405
struct listener *l;
314
410
/* if there are enough free sessions, we'll activate proxies */
315
411
if (actconn < global.maxconn) {
317
if (!p->maxconn || p->feconn < p->maxconn) {
318
if (p->state == PR_STIDLE) {
319
for (l = p->listen; l != NULL; l = l->next)
325
if (p->state == PR_STRUN) {
326
for (l = p->listen; l != NULL; l = l->next)
328
p->state = PR_STIDLE;
412
for (; p; p = p->next) {
413
/* check the various reasons we may find to block the frontend */
414
if (p->feconn >= p->maxconn)
418
(wait = next_event_delay(&p->fe_sess_per_sec, p->fe_sps_lim, 0))) {
419
/* we're blocking because a limit was reached on the number of
420
* requests/s on the frontend. We want to re-check ASAP, which
421
* means in 1 ms before estimated expiration date, because the
422
* timer will have settled down. Note that we may already be in
425
*next = tick_first(*next, tick_add(now_ms, wait));
429
/* OK we have no reason to block, so let's unblock if we were blocking */
430
if (p->state == PR_STIDLE) {
431
for (l = p->listen; l != NULL; l = l->next)
438
if (p->state == PR_STRUN) {
439
for (l = p->listen; l != NULL; l = l->next)
441
p->state = PR_STIDLE;
334
445
else { /* block all proxies */
348
459
if (p->state != PR_STSTOPPED) {
350
t = tv_ms_remain2(&now, &p->stop_time);
461
t = tick_remain(now_ms, p->stop_time);
352
463
Warning("Proxy %s stopped.\n", p->id);
353
464
send_log(p, LOG_WARNING, "Proxy %s stopped.\n", p->id);
380
tv_now(&now); /* else, the old time before select will be used */
491
tv_update_date(0,1); /* else, the old time before select will be used */
382
493
if (p->state != PR_STSTOPPED) {
383
494
Warning("Stopping %s %s in %d ms.\n", proxy_cap_str(p->cap), p->id, p->grace);
384
495
send_log(p, LOG_WARNING, "Stopping %s %s in %d ms.\n", proxy_cap_str(p->cap), p->id, p->grace);
385
tv_ms_add(&p->stop_time, &now, p->grace);
496
p->stop_time = tick_add(now_ms, p->grace);
484
595
struct listener *l;
487
tv_now(&now); /* else, the old time before select will be used */
598
tv_update_date(0,1); /* else, the old time before select will be used */
489
600
if (p->state == PR_STPAUSED) {
490
601
Warning("Enabling %s %s.\n", proxy_cap_str(p->cap), p->id);
634
static struct cfg_kw_list cfg_kws = {{ },{
635
{ CFG_LISTEN, "timeout", proxy_parse_timeout },
636
{ CFG_LISTEN, "clitimeout", proxy_parse_timeout },
637
{ CFG_LISTEN, "contimeout", proxy_parse_timeout },
638
{ CFG_LISTEN, "srvtimeout", proxy_parse_timeout },
639
{ CFG_LISTEN, "rate-limit", proxy_parse_rate_limit },
643
__attribute__((constructor))
644
static void __proxy_module_init(void)
646
cfg_register_keywords(&cfg_kws);
525
650
* Local variables: