annotate src/http/modules/ngx_http_limit_req_module.c @ 7281:bd6563e81cea

Limit req: improved handling of negative times. Negative times can appear since workers only update time on an event loop iteration start. If a worker was blocked for a long time during an event loop iteration, it is possible that another worker already updated the time stored in the node. As such, time since last update of the node (ms) will be negative. Previous code used ngx_abs(ms) in the calculations. That is, negative times were effectively treated as positive ones. As a result, it was not possible to maintain high request rates, where the same node can be updated multiple times from during an event loop iteration. In particular, this affected setups with many SSL handshakes, see http://mailman.nginx.org/pipermail/nginx/2018-May/056291.html. Fix is to only update the last update time stored in the node if the new time is larger than previously stored one. If a future time is stored in the node, we preserve this time as is. To prevent breaking things on platforms without monotonic time available if system time is updated backwards, a safety limit of 60 seconds is used. If the time stored in the node is more than 60 seconds in the future, we assume that the time was changed backwards and update lr->last to the current time.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 30 May 2018 15:40:34 +0300
parents 903fb1ddc07f
children bca4dad0d3cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4399
diff changeset
4 * Copyright (C) Nginx, Inc.
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_http.h>
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 typedef struct {
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
14 u_char color;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
15 u_char dummy;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
16 u_short len;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
17 ngx_queue_t queue;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
18 ngx_msec_t last;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
19 /* integer value, 1 corresponds to 0.001 r/s */
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
20 ngx_uint_t excess;
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
21 ngx_uint_t count;
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
22 u_char data[1];
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
23 } ngx_http_limit_req_node_t;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 typedef struct {
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
27 ngx_rbtree_t rbtree;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
28 ngx_rbtree_node_t sentinel;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
29 ngx_queue_t queue;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
30 } ngx_http_limit_req_shctx_t;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
31
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
32
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
33 typedef struct {
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
34 ngx_http_limit_req_shctx_t *sh;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
35 ngx_slab_pool_t *shpool;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
36 /* integer value, 1 corresponds to 0.001 r/s */
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
37 ngx_uint_t rate;
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
38 ngx_http_complex_value_t key;
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
39 ngx_http_limit_req_node_t *node;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
40 } ngx_http_limit_req_ctx_t;
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
41
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
42
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
43 typedef struct {
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
44 ngx_shm_zone_t *shm_zone;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
45 /* integer value, 1 corresponds to 0.001 r/s */
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
46 ngx_uint_t burst;
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
47 ngx_uint_t nodelay; /* unsigned nodelay:1 */
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
48 } ngx_http_limit_req_limit_t;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
49
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
50
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
51 typedef struct {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
52 ngx_array_t limits;
3185
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
53 ngx_uint_t limit_log_level;
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
54 ngx_uint_t delay_log_level;
5117
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
55 ngx_uint_t status_code;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
56 } ngx_http_limit_req_conf_t;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
59 static void ngx_http_limit_req_delay(ngx_http_request_t *r);
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
60 static ngx_int_t ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit,
5863
102f85699420 Limit req: reduced number of parameters in the lookup function.
Valentin Bartenev <vbart@nginx.com>
parents: 5862
diff changeset
61 ngx_uint_t hash, ngx_str_t *key, ngx_uint_t *ep, ngx_uint_t account);
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
62 static ngx_msec_t ngx_http_limit_req_account(ngx_http_limit_req_limit_t *limits,
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
63 ngx_uint_t n, ngx_uint_t *ep, ngx_http_limit_req_limit_t **limit);
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
64 static void ngx_http_limit_req_expire(ngx_http_limit_req_ctx_t *ctx,
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
65 ngx_uint_t n);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
67 static void *ngx_http_limit_req_create_conf(ngx_conf_t *cf);
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
68 static char *ngx_http_limit_req_merge_conf(ngx_conf_t *cf, void *parent,
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69 void *child);
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
70 static char *ngx_http_limit_req_zone(ngx_conf_t *cf, ngx_command_t *cmd,
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 void *conf);
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
72 static char *ngx_http_limit_req(ngx_conf_t *cf, ngx_command_t *cmd,
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 void *conf);
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
74 static ngx_int_t ngx_http_limit_req_init(ngx_conf_t *cf);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76
3185
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
77 static ngx_conf_enum_t ngx_http_limit_req_log_levels[] = {
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
78 { ngx_string("info"), NGX_LOG_INFO },
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
79 { ngx_string("notice"), NGX_LOG_NOTICE },
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
80 { ngx_string("warn"), NGX_LOG_WARN },
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
81 { ngx_string("error"), NGX_LOG_ERR },
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
82 { ngx_null_string, 0 }
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
83 };
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
84
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
85
5117
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
86 static ngx_conf_num_bounds_t ngx_http_limit_req_status_bounds = {
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
87 ngx_conf_check_num_bounds, 400, 599
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
88 };
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
89
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
90
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
91 static ngx_command_t ngx_http_limit_req_commands[] = {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
93 { ngx_string("limit_req_zone"),
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
94 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE3,
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
95 ngx_http_limit_req_zone,
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 0,
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97 0,
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 NULL },
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
100 { ngx_string("limit_req"),
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
101 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
102 ngx_http_limit_req,
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103 NGX_HTTP_LOC_CONF_OFFSET,
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104 0,
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105 NULL },
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106
3185
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
107 { ngx_string("limit_req_log_level"),
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
108 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
109 ngx_conf_set_enum_slot,
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
110 NGX_HTTP_LOC_CONF_OFFSET,
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
111 offsetof(ngx_http_limit_req_conf_t, limit_log_level),
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
112 &ngx_http_limit_req_log_levels },
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
113
5117
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
114 { ngx_string("limit_req_status"),
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
115 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
116 ngx_conf_set_num_slot,
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
117 NGX_HTTP_LOC_CONF_OFFSET,
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
118 offsetof(ngx_http_limit_req_conf_t, status_code),
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
119 &ngx_http_limit_req_status_bounds },
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
120
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121 ngx_null_command
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 };
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
125 static ngx_http_module_t ngx_http_limit_req_module_ctx = {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126 NULL, /* preconfiguration */
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
127 ngx_http_limit_req_init, /* postconfiguration */
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 NULL, /* create main configuration */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130 NULL, /* init main configuration */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 NULL, /* create server configuration */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 NULL, /* merge server configuration */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134
4499
778ef9c3fd2d Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents: 4497
diff changeset
135 ngx_http_limit_req_create_conf, /* create location configuration */
778ef9c3fd2d Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents: 4497
diff changeset
136 ngx_http_limit_req_merge_conf /* merge location configuration */
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137 };
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
140 ngx_module_t ngx_http_limit_req_module = {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141 NGX_MODULE_V1,
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
142 &ngx_http_limit_req_module_ctx, /* module context */
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
143 ngx_http_limit_req_commands, /* module directives */
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144 NGX_HTTP_MODULE, /* module type */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 NULL, /* init master */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 NULL, /* init module */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147 NULL, /* init process */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148 NULL, /* init thread */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 NULL, /* exit thread */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 NULL, /* exit process */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151 NULL, /* exit master */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 NGX_MODULE_V1_PADDING
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 };
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 static ngx_int_t
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
157 ngx_http_limit_req_handler(ngx_http_request_t *r)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 {
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
159 uint32_t hash;
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
160 ngx_str_t key;
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
161 ngx_int_t rc;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
162 ngx_uint_t n, excess;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
163 ngx_msec_t delay;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
164 ngx_http_limit_req_ctx_t *ctx;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
165 ngx_http_limit_req_conf_t *lrcf;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
166 ngx_http_limit_req_limit_t *limit, *limits;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
168 if (r->main->limit_req_set) {
984
dd128232e6ba count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents: 981
diff changeset
169 return NGX_DECLINED;
dd128232e6ba count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents: 981
diff changeset
170 }
dd128232e6ba count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents: 981
diff changeset
171
2374
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
172 lrcf = ngx_http_get_module_loc_conf(r, ngx_http_limit_req_module);
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
173 limits = lrcf->limits.elts;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
175 excess = 0;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
176
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
177 rc = NGX_DECLINED;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
178
4424
aacd7356c197 Limit req: unbreak compilation with MSVC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4420
diff changeset
179 #if (NGX_SUPPRESS_WARN)
aacd7356c197 Limit req: unbreak compilation with MSVC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4420
diff changeset
180 limit = NULL;
aacd7356c197 Limit req: unbreak compilation with MSVC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4420
diff changeset
181 #endif
aacd7356c197 Limit req: unbreak compilation with MSVC.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4420
diff changeset
182
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
183 for (n = 0; n < lrcf->limits.nelts; n++) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
184
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
185 limit = &limits[n];
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
186
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
187 ctx = limit->shm_zone->data;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
188
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
189 if (ngx_http_complex_value(r, &ctx->key, &key) != NGX_OK) {
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
190 return NGX_HTTP_INTERNAL_SERVER_ERROR;
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
191 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
192
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
193 if (key.len == 0) {
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
194 continue;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
195 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
196
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
197 if (key.len > 65535) {
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
198 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
199 "the value of the \"%V\" key "
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
200 "is more than 65535 bytes: \"%V\"",
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
201 &ctx->key.value, &key);
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
202 continue;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
203 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
204
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
205 hash = ngx_crc32_short(key.data, key.len);
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
206
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
207 ngx_shmtx_lock(&ctx->shpool->mutex);
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
208
5863
102f85699420 Limit req: reduced number of parameters in the lookup function.
Valentin Bartenev <vbart@nginx.com>
parents: 5862
diff changeset
209 rc = ngx_http_limit_req_lookup(limit, hash, &key, &excess,
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
210 (n == lrcf->limits.nelts - 1));
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
211
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
212 ngx_shmtx_unlock(&ctx->shpool->mutex);
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
213
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
214 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
215 "limit_req[%ui]: %i %ui.%03ui",
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
216 n, rc, excess / 1000, excess % 1000);
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
217
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
218 if (rc != NGX_AGAIN) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
219 break;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
220 }
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
223 if (rc == NGX_DECLINED) {
1011
19118c44303f test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents: 1002
diff changeset
224 return NGX_DECLINED;
19118c44303f test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents: 1002
diff changeset
225 }
19118c44303f test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents: 1002
diff changeset
226
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
227 r->main->limit_req_set = 1;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228
4418
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
229 if (rc == NGX_BUSY || rc == NGX_ERROR) {
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
230
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
231 if (rc == NGX_BUSY) {
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
232 ngx_log_error(lrcf->limit_log_level, r->connection->log, 0,
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
233 "limiting requests, excess: %ui.%03ui by zone \"%V\"",
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
234 excess / 1000, excess % 1000,
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
235 &limit->shm_zone->shm.name);
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
236 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
237
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
238 while (n--) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
239 ctx = limits[n].shm_zone->data;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
240
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
241 if (ctx->node == NULL) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
242 continue;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
243 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
244
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
245 ngx_shmtx_lock(&ctx->shpool->mutex);
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
246
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
247 ctx->node->count--;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
248
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
249 ngx_shmtx_unlock(&ctx->shpool->mutex);
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
250
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
251 ctx->node = NULL;
4418
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
252 }
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
253
5117
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
254 return lrcf->status_code;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
255 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
256
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
257 /* rc == NGX_AGAIN || rc == NGX_OK */
2300
159136c9808d *) correct leaky bucket implementation
Igor Sysoev <igor@sysoev.ru>
parents: 2294
diff changeset
258
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
259 if (rc == NGX_AGAIN) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
260 excess = 0;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
261 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
262
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
263 delay = ngx_http_limit_req_account(limits, n, &excess, &limit);
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
264
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
265 if (!delay) {
3780
d94d7104f598 change order of limit_req lookup result processing
Igor Sysoev <igor@sysoev.ru>
parents: 3779
diff changeset
266 return NGX_DECLINED;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
267 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
268
3780
d94d7104f598 change order of limit_req lookup result processing
Igor Sysoev <igor@sysoev.ru>
parents: 3779
diff changeset
269 ngx_log_error(lrcf->delay_log_level, r->connection->log, 0,
d94d7104f598 change order of limit_req lookup result processing
Igor Sysoev <igor@sysoev.ru>
parents: 3779
diff changeset
270 "delaying request, excess: %ui.%03ui, by zone \"%V\"",
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
271 excess / 1000, excess % 1000, &limit->shm_zone->shm.name);
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
272
3780
d94d7104f598 change order of limit_req lookup result processing
Igor Sysoev <igor@sysoev.ru>
parents: 3779
diff changeset
273 if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
d94d7104f598 change order of limit_req lookup result processing
Igor Sysoev <igor@sysoev.ru>
parents: 3779
diff changeset
274 return NGX_HTTP_INTERNAL_SERVER_ERROR;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
275 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
276
3780
d94d7104f598 change order of limit_req lookup result processing
Igor Sysoev <igor@sysoev.ru>
parents: 3779
diff changeset
277 r->read_event_handler = ngx_http_test_reading;
d94d7104f598 change order of limit_req lookup result processing
Igor Sysoev <igor@sysoev.ru>
parents: 3779
diff changeset
278 r->write_event_handler = ngx_http_limit_req_delay;
6959
7fcf209d40c8 Limit req: fixed delaying subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6653
diff changeset
279
7fcf209d40c8 Limit req: fixed delaying subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6653
diff changeset
280 r->connection->write->delayed = 1;
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
281 ngx_add_timer(r->connection->write, delay);
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
282
3780
d94d7104f598 change order of limit_req lookup result processing
Igor Sysoev <igor@sysoev.ru>
parents: 3779
diff changeset
283 return NGX_AGAIN;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
284 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
285
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
286
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
287 static void
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
288 ngx_http_limit_req_delay(ngx_http_request_t *r)
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
289 {
2972
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
290 ngx_event_t *wev;
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
291
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
292 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2973
70c8b2d28d1d style fix
Igor Sysoev <igor@sysoev.ru>
parents: 2972
diff changeset
293 "limit_req delay");
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
294
2972
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
295 wev = r->connection->write;
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
296
6961
903fb1ddc07f Moved handling of wev->delayed to the connection event handler.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6959
diff changeset
297 if (wev->delayed) {
2972
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
298
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
299 if (ngx_handle_write_event(wev, 0) != NGX_OK) {
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
300 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
301 }
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
302
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
303 return;
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
304 }
c5ad288f851d fix client write event handling in ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
305
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
306 if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
307 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
308 return;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
309 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
310
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
311 r->read_event_handler = ngx_http_block_reading;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
312 r->write_event_handler = ngx_http_core_run_phases;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
313
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
314 ngx_http_core_run_phases(r);
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
315 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
316
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
317
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
318 static void
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
319 ngx_http_limit_req_rbtree_insert_value(ngx_rbtree_node_t *temp,
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
320 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
321 {
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
322 ngx_rbtree_node_t **p;
2374
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
323 ngx_http_limit_req_node_t *lrn, *lrnt;
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
324
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
325 for ( ;; ) {
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
326
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
327 if (node->key < temp->key) {
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
328
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
329 p = &temp->left;
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
330
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
331 } else if (node->key > temp->key) {
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
332
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
333 p = &temp->right;
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
334
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
335 } else { /* node->key == temp->key */
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
336
2374
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
337 lrn = (ngx_http_limit_req_node_t *) &node->color;
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
338 lrnt = (ngx_http_limit_req_node_t *) &temp->color;
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
339
2374
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
340 p = (ngx_memn2cmp(lrn->data, lrnt->data, lrn->len, lrnt->len) < 0)
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
341 ? &temp->left : &temp->right;
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
342 }
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
343
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
344 if (*p == sentinel) {
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
345 break;
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
346 }
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
347
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
348 temp = *p;
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
349 }
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
350
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
351 *p = node;
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
352 node->parent = temp;
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
353 node->left = sentinel;
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
354 node->right = sentinel;
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
355 ngx_rbt_red(node);
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
356 }
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
357
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
358
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
359 static ngx_int_t
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
360 ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, ngx_uint_t hash,
5863
102f85699420 Limit req: reduced number of parameters in the lookup function.
Valentin Bartenev <vbart@nginx.com>
parents: 5862
diff changeset
361 ngx_str_t *key, ngx_uint_t *ep, ngx_uint_t account)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
362 {
4418
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
363 size_t size;
2313
b56a9ba4824d use integer instead of float
Igor Sysoev <igor@sysoev.ru>
parents: 2312
diff changeset
364 ngx_int_t rc, excess;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
365 ngx_msec_t now;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
366 ngx_msec_int_t ms;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
367 ngx_rbtree_node_t *node, *sentinel;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
368 ngx_http_limit_req_ctx_t *ctx;
2374
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
369 ngx_http_limit_req_node_t *lr;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
370
6653
7a6456398fc3 Simplified extraction of current time.
Ruslan Ermilov <ru@nginx.com>
parents: 6117
diff changeset
371 now = ngx_current_msec;
4418
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
372
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
373 ctx = limit->shm_zone->data;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
374
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
375 node = ctx->sh->rbtree.root;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
376 sentinel = ctx->sh->rbtree.sentinel;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
377
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
378 while (node != sentinel) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
379
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
380 if (hash < node->key) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
381 node = node->left;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
382 continue;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
383 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
384
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
385 if (hash > node->key) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
386 node = node->right;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
387 continue;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
388 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
389
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
390 /* hash == node->key */
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
391
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
392 lr = (ngx_http_limit_req_node_t *) &node->color;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
393
5863
102f85699420 Limit req: reduced number of parameters in the lookup function.
Valentin Bartenev <vbart@nginx.com>
parents: 5862
diff changeset
394 rc = ngx_memn2cmp(key->data, lr->data, key->len, (size_t) lr->len);
3191
30f841e2536d fix r3184
Igor Sysoev <igor@sysoev.ru>
parents: 3185
diff changeset
395
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
396 if (rc == 0) {
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
397 ngx_queue_remove(&lr->queue);
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
398 ngx_queue_insert_head(&ctx->sh->queue, &lr->queue);
3183
b87542338ac3 make limit_req to conform to the leaky bucket algorithm
Igor Sysoev <igor@sysoev.ru>
parents: 2973
diff changeset
399
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
400 ms = (ngx_msec_int_t) (now - lr->last);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
401
7281
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
402 if (ms < -60000) {
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
403 ms = 1;
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
404
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
405 } else if (ms < 0) {
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
406 ms = 0;
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
407 }
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
408
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
409 excess = lr->excess - ctx->rate * ms / 1000 + 1000;
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
410
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
411 if (excess < 0) {
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
412 excess = 0;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
413 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
414
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
415 *ep = excess;
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
416
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
417 if ((ngx_uint_t) excess > limit->burst) {
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
418 return NGX_BUSY;
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
419 }
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
420
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
421 if (account) {
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
422 lr->excess = excess;
7281
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
423
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
424 if (ms) {
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
425 lr->last = now;
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
426 }
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
427
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
428 return NGX_OK;
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
429 }
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
430
4497
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
431 lr->count++;
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
432
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
433 ctx->node = lr;
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
434
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
435 return NGX_AGAIN;
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
436 }
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
437
95ab6658654a Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4424
diff changeset
438 node = (rc < 0) ? node->left : node->right;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
439 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
440
3779
57aecfdcac3d an excess was logged as 0.000 if requests were limited without delay:
Igor Sysoev <igor@sysoev.ru>
parents: 3525
diff changeset
441 *ep = 0;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
442
4418
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
443 size = offsetof(ngx_rbtree_node_t, color)
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
444 + offsetof(ngx_http_limit_req_node_t, data)
5863
102f85699420 Limit req: reduced number of parameters in the lookup function.
Valentin Bartenev <vbart@nginx.com>
parents: 5862
diff changeset
445 + key->len;
4418
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
446
4419
7084faa7a4b4 Limit req: number of cleanup calls reduced.
Valentin Bartenev <vbart@nginx.com>
parents: 4418
diff changeset
447 ngx_http_limit_req_expire(ctx, 1);
7084faa7a4b4 Limit req: number of cleanup calls reduced.
Valentin Bartenev <vbart@nginx.com>
parents: 4418
diff changeset
448
4418
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
449 node = ngx_slab_alloc_locked(ctx->shpool, size);
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
450
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
451 if (node == NULL) {
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
452 ngx_http_limit_req_expire(ctx, 0);
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
453
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
454 node = ngx_slab_alloc_locked(ctx->shpool, size);
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
455 if (node == NULL) {
5634
5024d29354f1 Core: slab log_nomem flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5411
diff changeset
456 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
5024d29354f1 Core: slab log_nomem flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5411
diff changeset
457 "could not allocate node%s", ctx->shpool->log_ctx);
4418
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
458 return NGX_ERROR;
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
459 }
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
460 }
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
461
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
462 node->key = hash;
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
463
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
464 lr = (ngx_http_limit_req_node_t *) &node->color;
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
465
5863
102f85699420 Limit req: reduced number of parameters in the lookup function.
Valentin Bartenev <vbart@nginx.com>
parents: 5862
diff changeset
466 lr->len = (u_short) key->len;
4418
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
467 lr->excess = 0;
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
468
5863
102f85699420 Limit req: reduced number of parameters in the lookup function.
Valentin Bartenev <vbart@nginx.com>
parents: 5862
diff changeset
469 ngx_memcpy(lr->data, key->data, key->len);
4418
aac79fc948cc Limit req: allocation and initialization of a new node moved to the lookup
Valentin Bartenev <vbart@nginx.com>
parents: 4417
diff changeset
470
4832
949ea3d3cd1a Limit req: fix of rbtree node insertion on hash collisions.
Valentin Bartenev <vbart@nginx.com>
parents: 4811
diff changeset
471 ngx_rbtree_insert(&ctx->sh->rbtree, node);
949ea3d3cd1a Limit req: fix of rbtree node insertion on hash collisions.
Valentin Bartenev <vbart@nginx.com>
parents: 4811
diff changeset
472
949ea3d3cd1a Limit req: fix of rbtree node insertion on hash collisions.
Valentin Bartenev <vbart@nginx.com>
parents: 4811
diff changeset
473 ngx_queue_insert_head(&ctx->sh->queue, &lr->queue);
949ea3d3cd1a Limit req: fix of rbtree node insertion on hash collisions.
Valentin Bartenev <vbart@nginx.com>
parents: 4811
diff changeset
474
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
475 if (account) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
476 lr->last = now;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
477 lr->count = 0;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
478 return NGX_OK;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
479 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
480
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
481 lr->last = 0;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
482 lr->count = 1;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
483
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
484 ctx->node = lr;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
485
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
486 return NGX_AGAIN;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
487 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
488
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
489
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
490 static ngx_msec_t
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
491 ngx_http_limit_req_account(ngx_http_limit_req_limit_t *limits, ngx_uint_t n,
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
492 ngx_uint_t *ep, ngx_http_limit_req_limit_t **limit)
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
493 {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
494 ngx_int_t excess;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
495 ngx_msec_t now, delay, max_delay;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
496 ngx_msec_int_t ms;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
497 ngx_http_limit_req_ctx_t *ctx;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
498 ngx_http_limit_req_node_t *lr;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
499
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
500 excess = *ep;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
501
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
502 if (excess == 0 || (*limit)->nodelay) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
503 max_delay = 0;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
504
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
505 } else {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
506 ctx = (*limit)->shm_zone->data;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
507 max_delay = excess * 1000 / ctx->rate;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
508 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
509
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
510 while (n--) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
511 ctx = limits[n].shm_zone->data;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
512 lr = ctx->node;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
513
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
514 if (lr == NULL) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
515 continue;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
516 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
517
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
518 ngx_shmtx_lock(&ctx->shpool->mutex);
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
519
6653
7a6456398fc3 Simplified extraction of current time.
Ruslan Ermilov <ru@nginx.com>
parents: 6117
diff changeset
520 now = ngx_current_msec;
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
521 ms = (ngx_msec_int_t) (now - lr->last);
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
522
7281
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
523 if (ms < -60000) {
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
524 ms = 1;
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
525
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
526 } else if (ms < 0) {
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
527 ms = 0;
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
528 }
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
529
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
530 excess = lr->excess - ctx->rate * ms / 1000 + 1000;
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
531
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
532 if (excess < 0) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
533 excess = 0;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
534 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
535
7281
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
536 if (ms) {
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
537 lr->last = now;
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
538 }
bd6563e81cea Limit req: improved handling of negative times.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6961
diff changeset
539
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
540 lr->excess = excess;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
541 lr->count--;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
542
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
543 ngx_shmtx_unlock(&ctx->shpool->mutex);
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
544
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
545 ctx->node = NULL;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
546
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
547 if (limits[n].nodelay) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
548 continue;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
549 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
550
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
551 delay = excess * 1000 / ctx->rate;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
552
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
553 if (delay > max_delay) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
554 max_delay = delay;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
555 *ep = excess;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
556 *limit = &limits[n];
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
557 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
558 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
559
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
560 return max_delay;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
561 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
562
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
563
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
564 static void
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
565 ngx_http_limit_req_expire(ngx_http_limit_req_ctx_t *ctx, ngx_uint_t n)
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
566 {
2313
b56a9ba4824d use integer instead of float
Igor Sysoev <igor@sysoev.ru>
parents: 2312
diff changeset
567 ngx_int_t excess;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
568 ngx_msec_t now;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
569 ngx_queue_t *q;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
570 ngx_msec_int_t ms;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
571 ngx_rbtree_node_t *node;
2374
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
572 ngx_http_limit_req_node_t *lr;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
573
6653
7a6456398fc3 Simplified extraction of current time.
Ruslan Ermilov <ru@nginx.com>
parents: 6117
diff changeset
574 now = ngx_current_msec;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
575
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
576 /*
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
577 * n == 1 deletes one or two zero rate entries
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
578 * n == 0 deletes oldest entry by force
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
579 * and one or two zero rate entries
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
580 */
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
581
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
582 while (n < 3) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
583
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
584 if (ngx_queue_empty(&ctx->sh->queue)) {
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
585 return;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
586 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
587
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
588 q = ngx_queue_last(&ctx->sh->queue);
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
589
2374
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
590 lr = ngx_queue_data(q, ngx_http_limit_req_node_t, queue);
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
591
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
592 if (lr->count) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
593
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
594 /*
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
595 * There is not much sense in looking further,
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
596 * because we bump nodes on the lookup stage.
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
597 */
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
598
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
599 return;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
600 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
601
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
602 if (n++ != 0) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
603
2374
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
604 ms = (ngx_msec_int_t) (now - lr->last);
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
605 ms = ngx_abs(ms);
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
606
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
607 if (ms < 60000) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
608 return;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
609 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
610
2374
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
611 excess = lr->excess - ctx->rate * ms / 1000;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
612
2313
b56a9ba4824d use integer instead of float
Igor Sysoev <igor@sysoev.ru>
parents: 2312
diff changeset
613 if (excess > 0) {
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
614 return;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
615 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
616 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
617
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
618 ngx_queue_remove(q);
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
619
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
620 node = (ngx_rbtree_node_t *)
2374
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
621 ((u_char *) lr - offsetof(ngx_rbtree_node_t, color));
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
622
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
623 ngx_rbtree_delete(&ctx->sh->rbtree, node);
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
624
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
625 ngx_slab_free_locked(ctx->shpool, node);
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
626 }
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
627 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
628
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
629
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
630 static ngx_int_t
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
631 ngx_http_limit_req_init_zone(ngx_shm_zone_t *shm_zone, void *data)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
632 {
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
633 ngx_http_limit_req_ctx_t *octx = data;
993
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
634
2611
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2376
diff changeset
635 size_t len;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
636 ngx_http_limit_req_ctx_t *ctx;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
637
993
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
638 ctx = shm_zone->data;
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
639
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
640 if (octx) {
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
641 if (ctx->key.value.len != octx->key.value.len
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
642 || ngx_strncmp(ctx->key.value.data, octx->key.value.data,
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
643 ctx->key.value.len)
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
644 != 0)
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
645 {
993
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
646 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
647 "limit_req \"%V\" uses the \"%V\" key "
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
648 "while previously it used the \"%V\" key",
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
649 &shm_zone->shm.name, &ctx->key.value,
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
650 &octx->key.value);
993
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
651 return NGX_ERROR;
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
652 }
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
653
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
654 ctx->sh = octx->sh;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
655 ctx->shpool = octx->shpool;
993
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
656
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
657 return NGX_OK;
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
658 }
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
659
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
660 ctx->shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
661
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
662 if (shm_zone->shm.exists) {
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
663 ctx->sh = ctx->shpool->data;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
664
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
665 return NGX_OK;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
666 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
667
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
668 ctx->sh = ngx_slab_alloc(ctx->shpool, sizeof(ngx_http_limit_req_shctx_t));
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
669 if (ctx->sh == NULL) {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
670 return NGX_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
671 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
672
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
673 ctx->shpool->data = ctx->sh;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
674
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
675 ngx_rbtree_init(&ctx->sh->rbtree, &ctx->sh->sentinel,
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
676 ngx_http_limit_req_rbtree_insert_value);
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
677
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
678 ngx_queue_init(&ctx->sh->queue);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
679
2716
d5896f6608e8 move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2612
diff changeset
680 len = sizeof(" in limit_req zone \"\"") + shm_zone->shm.name.len;
2611
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2376
diff changeset
681
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2376
diff changeset
682 ctx->shpool->log_ctx = ngx_slab_alloc(ctx->shpool, len);
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2376
diff changeset
683 if (ctx->shpool->log_ctx == NULL) {
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2376
diff changeset
684 return NGX_ERROR;
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2376
diff changeset
685 }
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2376
diff changeset
686
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2376
diff changeset
687 ngx_sprintf(ctx->shpool->log_ctx, " in limit_req zone \"%V\"%Z",
2716
d5896f6608e8 move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2612
diff changeset
688 &shm_zone->shm.name);
2611
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2376
diff changeset
689
5634
5024d29354f1 Core: slab log_nomem flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5411
diff changeset
690 ctx->shpool->log_nomem = 0;
5024d29354f1 Core: slab log_nomem flag.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5411
diff changeset
691
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
692 return NGX_OK;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
693 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
694
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
695
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
696 static void *
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
697 ngx_http_limit_req_create_conf(ngx_conf_t *cf)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
698 {
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
699 ngx_http_limit_req_conf_t *conf;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
700
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
701 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_req_conf_t));
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
702 if (conf == NULL) {
2912
c7d57b539248 return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents: 2720
diff changeset
703 return NULL;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
704 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
705
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
706 /*
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
707 * set by ngx_pcalloc():
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
708 *
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
709 * conf->limits.elts = NULL;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
710 */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
711
3185
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
712 conf->limit_log_level = NGX_CONF_UNSET_UINT;
5117
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
713 conf->status_code = NGX_CONF_UNSET_UINT;
3185
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
714
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
715 return conf;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
716 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
717
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
718
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
719 static char *
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
720 ngx_http_limit_req_merge_conf(ngx_conf_t *cf, void *parent, void *child)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
721 {
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
722 ngx_http_limit_req_conf_t *prev = parent;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
723 ngx_http_limit_req_conf_t *conf = child;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
724
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
725 if (conf->limits.elts == NULL) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
726 conf->limits = prev->limits;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
727 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
728
3185
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
729 ngx_conf_merge_uint_value(conf->limit_log_level, prev->limit_log_level,
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
730 NGX_LOG_ERR);
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
731
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
732 conf->delay_log_level = (conf->limit_log_level == NGX_LOG_INFO) ?
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
733 NGX_LOG_INFO : conf->limit_log_level + 1;
30570a5b9bb0 limit_req_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 3183
diff changeset
734
5117
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
735 ngx_conf_merge_uint_value(conf->status_code, prev->status_code,
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
736 NGX_HTTP_SERVICE_UNAVAILABLE);
00e4459739ed The limit_req_status and limit_conn_status directives.
Maxim Dounin <mdounin@mdounin.ru>
parents: 4832
diff changeset
737
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
738 return NGX_CONF_OK;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
739 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
740
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
741
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
742 static char *
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
743 ngx_http_limit_req_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
744 {
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
745 u_char *p;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
746 size_t len;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
747 ssize_t size;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
748 ngx_str_t *value, name, s;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
749 ngx_int_t rate, scale;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
750 ngx_uint_t i;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
751 ngx_shm_zone_t *shm_zone;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
752 ngx_http_limit_req_ctx_t *ctx;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
753 ngx_http_compile_complex_value_t ccv;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
754
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
755 value = cf->args->elts;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
756
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
757 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_req_ctx_t));
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
758 if (ctx == NULL) {
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
759 return NGX_CONF_ERROR;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
760 }
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
761
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
762 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
763
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
764 ccv.cf = cf;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
765 ccv.value = &value[1];
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
766 ccv.complex_value = &ctx->key;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
767
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
768 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
769 return NGX_CONF_ERROR;
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
770 }
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
771
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
772 size = 0;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
773 rate = 1;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
774 scale = 1;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
775 name.len = 0;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
776
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
777 for (i = 2; i < cf->args->nelts; i++) {
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
778
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
779 if (ngx_strncmp(value[i].data, "zone=", 5) == 0) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
780
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
781 name.data = value[i].data + 5;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
782
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
783 p = (u_char *) ngx_strchr(name.data, ':');
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
784
4417
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
785 if (p == NULL) {
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
786 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
787 "invalid zone size \"%V\"", &value[i]);
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
788 return NGX_CONF_ERROR;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
789 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
790
4417
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
791 name.len = p - name.data;
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
792
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
793 s.data = p + 1;
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
794 s.len = value[i].data + value[i].len - s.data;
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
795
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
796 size = ngx_parse_size(&s);
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
797
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
798 if (size == NGX_ERROR) {
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
799 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
800 "invalid zone size \"%V\"", &value[i]);
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
801 return NGX_CONF_ERROR;
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
802 }
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
803
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
804 if (size < (ssize_t) (8 * ngx_pagesize)) {
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
805 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
806 "zone \"%V\" is too small", &value[i]);
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
807 return NGX_CONF_ERROR;
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
808 }
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
809
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
810 continue;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
811 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
812
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
813 if (ngx_strncmp(value[i].data, "rate=", 5) == 0) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
814
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
815 len = value[i].len;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
816 p = value[i].data + len - 3;
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
817
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
818 if (ngx_strncmp(p, "r/s", 3) == 0) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
819 scale = 1;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
820 len -= 3;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
821
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
822 } else if (ngx_strncmp(p, "r/m", 3) == 0) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
823 scale = 60;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
824 len -= 3;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
825 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
826
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
827 rate = ngx_atoi(value[i].data + 5, len - 5);
5166
fc595eeb6c54 Limit req: rate should be non-zero.
Valentin Bartenev <vbart@nginx.com>
parents: 5117
diff changeset
828 if (rate <= 0) {
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
829 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
830 "invalid rate \"%V\"", &value[i]);
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
831 return NGX_CONF_ERROR;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
832 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
833
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
834 continue;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
835 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
836
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
837 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
838 "invalid parameter \"%V\"", &value[i]);
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
839 return NGX_CONF_ERROR;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
840 }
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
841
4417
9e9d2e06f933 Limit req: improved error handling when parsing "zone" parameter of
Valentin Bartenev <vbart@nginx.com>
parents: 4416
diff changeset
842 if (name.len == 0) {
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
843 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
844 "\"%V\" must have \"zone\" parameter",
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
845 &cmd->name);
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
846 return NGX_CONF_ERROR;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
847 }
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
848
2313
b56a9ba4824d use integer instead of float
Igor Sysoev <igor@sysoev.ru>
parents: 2312
diff changeset
849 ctx->rate = rate * 1000 / scale;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
850
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
851 shm_zone = ngx_shared_memory_add(cf, &name, size,
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
852 &ngx_http_limit_req_module);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
853 if (shm_zone == NULL) {
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
854 return NGX_CONF_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
855 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
856
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
857 if (shm_zone->data) {
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
858 ctx = shm_zone->data;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
859
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
860 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
5862
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
861 "%V \"%V\" is already bound to key \"%V\"",
ecbb99aa0e12 Limit req: use complex value in limit_req_zone.
Valentin Bartenev <vbart@nginx.com>
parents: 5846
diff changeset
862 &cmd->name, &name, &ctx->key.value);
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
863 return NGX_CONF_ERROR;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
864 }
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
865
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
866 shm_zone->init = ngx_http_limit_req_init_zone;
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
867 shm_zone->data = ctx;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
868
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
869 return NGX_CONF_OK;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
870 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
871
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
872
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
873 static char *
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
874 ngx_http_limit_req(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
875 {
2374
7b11f9a1bfe1 rename "lz" to "lr" in variable names
Igor Sysoev <igor@sysoev.ru>
parents: 2313
diff changeset
876 ngx_http_limit_req_conf_t *lrcf = conf;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
877
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
878 ngx_int_t burst;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
879 ngx_str_t *value, s;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
880 ngx_uint_t i, nodelay;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
881 ngx_shm_zone_t *shm_zone;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
882 ngx_http_limit_req_limit_t *limit, *limits;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
883
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
884 value = cf->args->elts;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
885
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
886 shm_zone = NULL;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
887 burst = 0;
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
888 nodelay = 0;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
889
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
890 for (i = 1; i < cf->args->nelts; i++) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
891
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
892 if (ngx_strncmp(value[i].data, "zone=", 5) == 0) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
893
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
894 s.len = value[i].len - 5;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
895 s.data = value[i].data + 5;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
896
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
897 shm_zone = ngx_shared_memory_add(cf, &s, 0,
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
898 &ngx_http_limit_req_module);
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
899 if (shm_zone == NULL) {
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
900 return NGX_CONF_ERROR;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
901 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
902
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
903 continue;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
904 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
905
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
906 if (ngx_strncmp(value[i].data, "burst=", 6) == 0) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
907
2300
159136c9808d *) correct leaky bucket implementation
Igor Sysoev <igor@sysoev.ru>
parents: 2294
diff changeset
908 burst = ngx_atoi(value[i].data + 6, value[i].len - 6);
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
909 if (burst <= 0) {
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
910 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
911 "invalid burst rate \"%V\"", &value[i]);
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
912 return NGX_CONF_ERROR;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
913 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
914
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
915 continue;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
916 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
917
5411
5483d9e77b32 Limit req: fixed "nodelay" parsing.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5166
diff changeset
918 if (ngx_strcmp(value[i].data, "nodelay") == 0) {
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
919 nodelay = 1;
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
920 continue;
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
921 }
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
922
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
923 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
924 "invalid parameter \"%V\"", &value[i]);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
925 return NGX_CONF_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
926 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
927
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
928 if (shm_zone == NULL) {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
929 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
930 "\"%V\" must have \"zone\" parameter",
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
931 &cmd->name);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
932 return NGX_CONF_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
933 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
934
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
935 limits = lrcf->limits.elts;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
936
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
937 if (limits == NULL) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
938 if (ngx_array_init(&lrcf->limits, cf->pool, 1,
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
939 sizeof(ngx_http_limit_req_limit_t))
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
940 != NGX_OK)
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
941 {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
942 return NGX_CONF_ERROR;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
943 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
944 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
945
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
946 for (i = 0; i < lrcf->limits.nelts; i++) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
947 if (shm_zone == limits[i].shm_zone) {
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
948 return "is duplicate";
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
949 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
950 }
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
951
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
952 limit = ngx_array_push(&lrcf->limits);
4811
21d1e3bcb356 Added three missing checks for NULL after ngx_array_push() calls.
Valentin Bartenev <vbart@nginx.com>
parents: 4499
diff changeset
953 if (limit == NULL) {
21d1e3bcb356 Added three missing checks for NULL after ngx_array_push() calls.
Valentin Bartenev <vbart@nginx.com>
parents: 4499
diff changeset
954 return NGX_CONF_ERROR;
21d1e3bcb356 Added three missing checks for NULL after ngx_array_push() calls.
Valentin Bartenev <vbart@nginx.com>
parents: 4499
diff changeset
955 }
4420
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
956
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
957 limit->shm_zone = shm_zone;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
958 limit->burst = burst * 1000;
9ce48f9eb85b Limit req: support for multiple "limit_req" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4419
diff changeset
959 limit->nodelay = nodelay;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
960
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
961 return NGX_CONF_OK;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
962 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
963
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
964
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
965 static ngx_int_t
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
966 ngx_http_limit_req_init(ngx_conf_t *cf)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
967 {
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
968 ngx_http_handler_pt *h;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
969 ngx_http_core_main_conf_t *cmcf;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
970
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
971 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
972
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
973 h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers);
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
974 if (h == NULL) {
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
975 return NGX_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
976 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
977
2294
ce574b0ffeec ngx_http_limit_req_module
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
978 *h = ngx_http_limit_req_handler;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
979
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
980 return NGX_OK;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
981 }