Mercurial > hg > nginx
annotate src/http/modules/ngx_http_limit_zone_module.c @ 4270:3544987fef85
Limit zone: rbtree lookup moved to a separate function.
No functional changes.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Thu, 10 Nov 2011 15:51:55 +0000 |
parents | 23d567eabc5d |
children | b86cceba426a |
rev | line source |
---|---|
980 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 #include <ngx_http.h> | |
10 | |
11 | |
12 typedef struct { | |
981 | 13 u_char color; |
14 u_char len; | |
980 | 15 u_short conn; |
16 u_char data[1]; | |
17 } ngx_http_limit_zone_node_t; | |
18 | |
19 | |
20 typedef struct { | |
21 ngx_shm_zone_t *shm_zone; | |
22 ngx_rbtree_node_t *node; | |
23 } ngx_http_limit_zone_cleanup_t; | |
24 | |
25 | |
26 typedef struct { | |
987 | 27 ngx_rbtree_t *rbtree; |
28 ngx_int_t index; | |
29 ngx_str_t var; | |
30 } ngx_http_limit_zone_ctx_t; | |
31 | |
32 | |
33 typedef struct { | |
980 | 34 ngx_shm_zone_t *shm_zone; |
35 ngx_uint_t conn; | |
3186 | 36 ngx_uint_t log_level; |
980 | 37 } ngx_http_limit_zone_conf_t; |
38 | |
39 | |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
40 static ngx_rbtree_node_t *ngx_http_limit_zone_lookup(ngx_rbtree_t *rbtree, |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
41 ngx_http_variable_value_t *vv, uint32_t hash); |
980 | 42 static void ngx_http_limit_zone_cleanup(void *data); |
43 | |
44 static void *ngx_http_limit_zone_create_conf(ngx_conf_t *cf); | |
45 static char *ngx_http_limit_zone_merge_conf(ngx_conf_t *cf, void *parent, | |
46 void *child); | |
47 static char *ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, | |
48 void *conf); | |
49 static char *ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, | |
50 void *conf); | |
51 static ngx_int_t ngx_http_limit_zone_init(ngx_conf_t *cf); | |
52 | |
53 | |
3186 | 54 static ngx_conf_enum_t ngx_http_limit_conn_log_levels[] = { |
55 { ngx_string("info"), NGX_LOG_INFO }, | |
56 { ngx_string("notice"), NGX_LOG_NOTICE }, | |
57 { ngx_string("warn"), NGX_LOG_WARN }, | |
58 { ngx_string("error"), NGX_LOG_ERR }, | |
59 { ngx_null_string, 0 } | |
60 }; | |
61 | |
62 | |
980 | 63 static ngx_command_t ngx_http_limit_zone_commands[] = { |
64 | |
65 { ngx_string("limit_zone"), | |
987 | 66 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE3, |
980 | 67 ngx_http_limit_zone, |
68 0, | |
69 0, | |
70 NULL }, | |
71 | |
72 { ngx_string("limit_conn"), | |
987 | 73 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, |
980 | 74 ngx_http_limit_conn, |
75 NGX_HTTP_LOC_CONF_OFFSET, | |
76 0, | |
77 NULL }, | |
78 | |
3186 | 79 { ngx_string("limit_conn_log_level"), |
80 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
81 ngx_conf_set_enum_slot, | |
82 NGX_HTTP_LOC_CONF_OFFSET, | |
83 offsetof(ngx_http_limit_zone_conf_t, log_level), | |
84 &ngx_http_limit_conn_log_levels }, | |
85 | |
980 | 86 ngx_null_command |
87 }; | |
88 | |
89 | |
90 static ngx_http_module_t ngx_http_limit_zone_module_ctx = { | |
91 NULL, /* preconfiguration */ | |
92 ngx_http_limit_zone_init, /* postconfiguration */ | |
93 | |
94 NULL, /* create main configuration */ | |
95 NULL, /* init main configuration */ | |
96 | |
97 NULL, /* create server configuration */ | |
98 NULL, /* merge server configuration */ | |
99 | |
100 ngx_http_limit_zone_create_conf, /* create location configration */ | |
101 ngx_http_limit_zone_merge_conf /* merge location configration */ | |
102 }; | |
103 | |
104 | |
105 ngx_module_t ngx_http_limit_zone_module = { | |
106 NGX_MODULE_V1, | |
107 &ngx_http_limit_zone_module_ctx, /* module context */ | |
108 ngx_http_limit_zone_commands, /* module directives */ | |
109 NGX_HTTP_MODULE, /* module type */ | |
110 NULL, /* init master */ | |
111 NULL, /* init module */ | |
112 NULL, /* init process */ | |
113 NULL, /* init thread */ | |
114 NULL, /* exit thread */ | |
115 NULL, /* exit process */ | |
116 NULL, /* exit master */ | |
117 NGX_MODULE_V1_PADDING | |
118 }; | |
119 | |
120 | |
121 static ngx_int_t | |
122 ngx_http_limit_zone_handler(ngx_http_request_t *r) | |
123 { | |
124 size_t len, n; | |
125 uint32_t hash; | |
126 ngx_slab_pool_t *shpool; | |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
127 ngx_rbtree_node_t *node; |
980 | 128 ngx_pool_cleanup_t *cln; |
129 ngx_http_variable_value_t *vv; | |
987 | 130 ngx_http_limit_zone_ctx_t *ctx; |
980 | 131 ngx_http_limit_zone_node_t *lz; |
132 ngx_http_limit_zone_conf_t *lzcf; | |
133 ngx_http_limit_zone_cleanup_t *lzcln; | |
134 | |
997
5900ec20604a
do not count connection for subrequest
Igor Sysoev <igor@sysoev.ru>
parents:
993
diff
changeset
|
135 if (r->main->limit_zone_set) { |
984
dd128232e6ba
count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents:
981
diff
changeset
|
136 return NGX_DECLINED; |
dd128232e6ba
count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents:
981
diff
changeset
|
137 } |
dd128232e6ba
count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents:
981
diff
changeset
|
138 |
980 | 139 lzcf = ngx_http_get_module_loc_conf(r, ngx_http_limit_zone_module); |
140 | |
141 if (lzcf->shm_zone == NULL) { | |
142 return NGX_DECLINED; | |
143 } | |
144 | |
987 | 145 ctx = lzcf->shm_zone->data; |
146 | |
147 vv = ngx_http_get_indexed_variable(r, ctx->index); | |
980 | 148 |
149 if (vv == NULL || vv->not_found) { | |
150 return NGX_DECLINED; | |
151 } | |
152 | |
1011
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
153 len = vv->len; |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
154 |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
155 if (len == 0) { |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
156 return NGX_DECLINED; |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
157 } |
984
dd128232e6ba
count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents:
981
diff
changeset
|
158 |
1011
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
159 if (len > 255) { |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
160 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
161 "the value of the \"%V\" variable " |
1406
03341711f9a2
use %v for ngx_variable_value_t in ngx_sprintf(),
Igor Sysoev <igor@sysoev.ru>
parents:
1036
diff
changeset
|
162 "is more than 255 bytes: \"%v\"", |
1011
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
163 &ctx->var, vv); |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
164 return NGX_DECLINED; |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
165 } |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
166 |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
167 r->main->limit_zone_set = 1; |
980 | 168 |
169 hash = ngx_crc32_short(vv->data, len); | |
170 | |
171 cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_limit_zone_cleanup_t)); | |
172 if (cln == NULL) { | |
173 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
174 } | |
175 | |
176 shpool = (ngx_slab_pool_t *) lzcf->shm_zone->shm.addr; | |
177 | |
178 ngx_shmtx_lock(&shpool->mutex); | |
179 | |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
180 node = ngx_http_limit_zone_lookup(ctx->rbtree, vv, hash); |
980 | 181 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
182 if (node == NULL) { |
980 | 183 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
184 n = offsetof(ngx_rbtree_node_t, color) |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
185 + offsetof(ngx_http_limit_zone_node_t, data) |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
186 + len; |
980 | 187 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
188 node = ngx_slab_alloc_locked(shpool, n); |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
189 if (node == NULL) { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
190 ngx_shmtx_unlock(&shpool->mutex); |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
191 return NGX_HTTP_SERVICE_UNAVAILABLE; |
980 | 192 } |
193 | |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
194 lz = (ngx_http_limit_zone_node_t *) &node->color; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
195 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
196 node->key = hash; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
197 lz->len = (u_char) len; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
198 lz->conn = 1; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
199 ngx_memcpy(lz->data, vv->data, len); |
980 | 200 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
201 ngx_rbtree_insert(ctx->rbtree, node); |
2373 | 202 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
203 } else { |
1012
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
204 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
205 lz = (ngx_http_limit_zone_node_t *) &node->color; |
1012
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
206 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
207 if ((ngx_uint_t) lz->conn >= lzcf->conn) { |
1012
11ffb8e4753f
stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents:
1011
diff
changeset
|
208 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
209 ngx_shmtx_unlock(&shpool->mutex); |
980 | 210 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
211 ngx_log_error(lzcf->log_level, r->connection->log, 0, |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
212 "limiting connections by zone \"%V\"", |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
213 &lzcf->shm_zone->shm.name); |
980 | 214 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
215 return NGX_HTTP_SERVICE_UNAVAILABLE; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
216 } |
980 | 217 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
218 lz->conn++; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
219 } |
980 | 220 |
221 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
222 "limit zone: %08XD %d", node->key, lz->conn); | |
223 | |
224 ngx_shmtx_unlock(&shpool->mutex); | |
225 | |
226 cln->handler = ngx_http_limit_zone_cleanup; | |
227 lzcln = cln->data; | |
228 | |
229 lzcln->shm_zone = lzcf->shm_zone; | |
230 lzcln->node = node; | |
231 | |
232 return NGX_DECLINED; | |
233 } | |
234 | |
235 | |
236 static void | |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
237 ngx_http_limit_zone_rbtree_insert_value(ngx_rbtree_node_t *temp, |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
238 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
|
239 { |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
240 ngx_rbtree_node_t **p; |
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
241 ngx_http_limit_zone_node_t *lzn, *lznt; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
242 |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
243 for ( ;; ) { |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
244 |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
245 if (node->key < temp->key) { |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
246 |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
247 p = &temp->left; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
248 |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
249 } else if (node->key > temp->key) { |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
250 |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
251 p = &temp->right; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
252 |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
253 } else { /* node->key == temp->key */ |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
254 |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
255 lzn = (ngx_http_limit_zone_node_t *) &node->color; |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
256 lznt = (ngx_http_limit_zone_node_t *) &temp->color; |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
257 |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
258 p = (ngx_memn2cmp(lzn->data, lznt->data, lzn->len, lznt->len) < 0) |
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
259 ? &temp->left : &temp->right; |
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
260 } |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
261 |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
262 if (*p == sentinel) { |
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
263 break; |
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
264 } |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
265 |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
266 temp = *p; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
267 } |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
268 |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
269 *p = node; |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
270 node->parent = temp; |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
271 node->left = sentinel; |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
272 node->right = sentinel; |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
273 ngx_rbt_red(node); |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
274 } |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
275 |
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
276 |
4270
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
277 static ngx_rbtree_node_t * |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
278 ngx_http_limit_zone_lookup(ngx_rbtree_t *rbtree, ngx_http_variable_value_t *vv, |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
279 uint32_t hash) |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
280 { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
281 ngx_int_t rc; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
282 ngx_rbtree_node_t *node, *sentinel; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
283 ngx_http_limit_zone_node_t *lzn; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
284 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
285 node = rbtree->root; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
286 sentinel = rbtree->sentinel; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
287 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
288 while (node != sentinel) { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
289 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
290 if (hash < node->key) { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
291 node = node->left; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
292 continue; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
293 } |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
294 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
295 if (hash > node->key) { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
296 node = node->right; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
297 continue; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
298 } |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
299 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
300 /* hash == node->key */ |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
301 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
302 do { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
303 lzn = (ngx_http_limit_zone_node_t *) &node->color; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
304 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
305 rc = ngx_memn2cmp(vv->data, lzn->data, |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
306 (size_t) vv->len, (size_t) lzn->len); |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
307 if (rc == 0) { |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
308 return node; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
309 } |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
310 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
311 node = (rc < 0) ? node->left : node->right; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
312 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
313 } while (node != sentinel && hash == node->key); |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
314 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
315 break; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
316 } |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
317 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
318 return NULL; |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
319 } |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
320 |
3544987fef85
Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents:
3186
diff
changeset
|
321 |
1026
38be15c1379a
fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents:
1012
diff
changeset
|
322 static void |
980 | 323 ngx_http_limit_zone_cleanup(void *data) |
324 { | |
325 ngx_http_limit_zone_cleanup_t *lzcln = data; | |
326 | |
327 ngx_slab_pool_t *shpool; | |
328 ngx_rbtree_node_t *node; | |
987 | 329 ngx_http_limit_zone_ctx_t *ctx; |
980 | 330 ngx_http_limit_zone_node_t *lz; |
331 | |
987 | 332 ctx = lzcln->shm_zone->data; |
980 | 333 shpool = (ngx_slab_pool_t *) lzcln->shm_zone->shm.addr; |
334 node = lzcln->node; | |
981 | 335 lz = (ngx_http_limit_zone_node_t *) &node->color; |
980 | 336 |
337 ngx_shmtx_lock(&shpool->mutex); | |
338 | |
339 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, lzcln->shm_zone->shm.log, 0, | |
340 "limit zone cleanup: %08XD %d", node->key, lz->conn); | |
341 | |
342 lz->conn--; | |
343 | |
344 if (lz->conn == 0) { | |
987 | 345 ngx_rbtree_delete(ctx->rbtree, node); |
980 | 346 ngx_slab_free_locked(shpool, node); |
347 } | |
348 | |
349 ngx_shmtx_unlock(&shpool->mutex); | |
350 } | |
351 | |
352 | |
353 static ngx_int_t | |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
354 ngx_http_limit_zone_init_zone(ngx_shm_zone_t *shm_zone, void *data) |
980 | 355 { |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
356 ngx_http_limit_zone_ctx_t *octx = data; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
357 |
2611
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
358 size_t len; |
987 | 359 ngx_slab_pool_t *shpool; |
360 ngx_rbtree_node_t *sentinel; | |
361 ngx_http_limit_zone_ctx_t *ctx; | |
980 | 362 |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
363 ctx = shm_zone->data; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
364 |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
365 if (octx) { |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
366 if (ngx_strcmp(ctx->var.data, octx->var.data) != 0) { |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
367 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0, |
1001 | 368 "limit_zone \"%V\" uses the \"%V\" variable " |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
369 "while previously it used the \"%V\" variable", |
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
|
370 &shm_zone->shm.name, &ctx->var, &octx->var); |
993
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
371 return NGX_ERROR; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
372 } |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
373 |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
374 ctx->rbtree = octx->rbtree; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
375 |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
376 return NGX_OK; |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
377 } |
1b9a4d92173f
pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents:
987
diff
changeset
|
378 |
980 | 379 shpool = (ngx_slab_pool_t *) shm_zone->shm.addr; |
380 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
381 if (shm_zone->shm.exists) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
382 ctx->rbtree = shpool->data; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
383 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
384 return NGX_OK; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
385 } |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
386 |
987 | 387 ctx->rbtree = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_t)); |
388 if (ctx->rbtree == NULL) { | |
980 | 389 return NGX_ERROR; |
390 } | |
391 | |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
392 shpool->data = ctx->rbtree; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
393 |
980 | 394 sentinel = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_node_t)); |
395 if (sentinel == NULL) { | |
396 return NGX_ERROR; | |
397 } | |
398 | |
1743
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
399 ngx_rbtree_init(ctx->rbtree, sentinel, |
4fc402c3ec73
optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents:
1406
diff
changeset
|
400 ngx_http_limit_zone_rbtree_insert_value); |
980 | 401 |
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
|
402 len = sizeof(" in limit_zone \"\"") + shm_zone->shm.name.len; |
2611
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
403 |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
404 shpool->log_ctx = ngx_slab_alloc(shpool, len); |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
405 if (shpool->log_ctx == NULL) { |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
406 return NGX_ERROR; |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
407 } |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
408 |
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
|
409 ngx_sprintf(shpool->log_ctx, " in limit_zone \"%V\"%Z", |
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
|
410 &shm_zone->shm.name); |
2611
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2373
diff
changeset
|
411 |
980 | 412 return NGX_OK; |
413 } | |
414 | |
415 | |
416 static void * | |
417 ngx_http_limit_zone_create_conf(ngx_conf_t *cf) | |
418 { | |
419 ngx_http_limit_zone_conf_t *conf; | |
420 | |
421 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_zone_conf_t)); | |
422 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
|
423 return NULL; |
980 | 424 } |
425 | |
426 /* | |
427 * set by ngx_pcalloc(): | |
428 * | |
429 * conf->shm_zone = NULL; | |
430 * conf->conn = 0; | |
431 */ | |
432 | |
3186 | 433 conf->log_level = NGX_CONF_UNSET_UINT; |
434 | |
980 | 435 return conf; |
436 } | |
437 | |
438 | |
439 static char * | |
440 ngx_http_limit_zone_merge_conf(ngx_conf_t *cf, void *parent, void *child) | |
441 { | |
442 ngx_http_limit_zone_conf_t *prev = parent; | |
443 ngx_http_limit_zone_conf_t *conf = child; | |
444 | |
445 if (conf->shm_zone == NULL) { | |
446 *conf = *prev; | |
447 } | |
448 | |
3186 | 449 ngx_conf_merge_uint_value(conf->log_level, prev->log_level, NGX_LOG_ERR); |
450 | |
980 | 451 return NGX_CONF_OK; |
452 } | |
453 | |
454 | |
455 static char * | |
456 ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
457 { | |
987 | 458 ssize_t n; |
459 ngx_str_t *value; | |
460 ngx_shm_zone_t *shm_zone; | |
461 ngx_http_limit_zone_ctx_t *ctx; | |
980 | 462 |
463 value = cf->args->elts; | |
464 | |
987 | 465 if (value[2].data[0] != '$') { |
466 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
467 "invalid variable name \"%V\"", &value[2]); | |
468 return NGX_CONF_ERROR; | |
469 } | |
470 | |
471 value[2].len--; | |
472 value[2].data++; | |
473 | |
474 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_zone_ctx_t)); | |
475 if (ctx == NULL) { | |
476 return NGX_CONF_ERROR; | |
477 } | |
478 | |
479 ctx->index = ngx_http_get_variable_index(cf, &value[2]); | |
480 if (ctx->index == NGX_ERROR) { | |
481 return NGX_CONF_ERROR; | |
482 } | |
483 | |
484 ctx->var = value[2]; | |
485 | |
486 n = ngx_parse_size(&value[3]); | |
980 | 487 |
488 if (n == NGX_ERROR) { | |
489 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
987 | 490 "invalid size of limit_zone \"%V\"", &value[3]); |
980 | 491 return NGX_CONF_ERROR; |
492 } | |
493 | |
494 if (n < (ngx_int_t) (8 * ngx_pagesize)) { | |
495 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
496 "limit_zone \"%V\" is too small", &value[1]); | |
497 return NGX_CONF_ERROR; | |
498 } | |
499 | |
500 | |
501 shm_zone = ngx_shared_memory_add(cf, &value[1], n, | |
502 &ngx_http_limit_zone_module); | |
503 if (shm_zone == NULL) { | |
504 return NGX_CONF_ERROR; | |
505 } | |
506 | |
987 | 507 if (shm_zone->data) { |
508 ctx = shm_zone->data; | |
509 | |
510 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
511 "limit_zone \"%V\" is already bound to variable \"%V\"", | |
512 &value[1], &ctx->var); | |
513 return NGX_CONF_ERROR; | |
514 } | |
515 | |
980 | 516 shm_zone->init = ngx_http_limit_zone_init_zone; |
987 | 517 shm_zone->data = ctx; |
980 | 518 |
519 return NGX_CONF_OK; | |
520 } | |
521 | |
522 | |
523 static char * | |
524 ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
525 { | |
526 ngx_http_limit_zone_conf_t *lzcf = conf; | |
527 | |
528 ngx_int_t n; | |
529 ngx_str_t *value; | |
530 | |
2372 | 531 if (lzcf->shm_zone) { |
532 return "is duplicate"; | |
533 } | |
534 | |
980 | 535 value = cf->args->elts; |
536 | |
987 | 537 lzcf->shm_zone = ngx_shared_memory_add(cf, &value[1], 0, |
538 &ngx_http_limit_zone_module); | |
539 if (lzcf->shm_zone == NULL) { | |
980 | 540 return NGX_CONF_ERROR; |
541 } | |
542 | |
987 | 543 n = ngx_atoi(value[2].data, value[2].len); |
544 if (n <= 0) { | |
980 | 545 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
987 | 546 "invalid number of connections \"%V\"", &value[2]); |
980 | 547 return NGX_CONF_ERROR; |
548 } | |
549 | |
1011
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
550 if (n > 65535) { |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
551 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
552 "connection limit must be less 65536"); |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
553 return NGX_CONF_ERROR; |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
554 } |
19118c44303f
test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents:
1002
diff
changeset
|
555 |
980 | 556 lzcf->conn = n; |
557 | |
558 return NGX_CONF_OK; | |
559 } | |
560 | |
561 | |
562 static ngx_int_t | |
563 ngx_http_limit_zone_init(ngx_conf_t *cf) | |
564 { | |
565 ngx_http_handler_pt *h; | |
566 ngx_http_core_main_conf_t *cmcf; | |
567 | |
568 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
569 | |
570 h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers); | |
571 if (h == NULL) { | |
572 return NGX_ERROR; | |
573 } | |
574 | |
575 *h = ngx_http_limit_zone_handler; | |
576 | |
577 return NGX_OK; | |
578 } |