49 static void ngx_http_limit_conn_cleanup(
void *data);
52 static void *ngx_http_limit_conn_create_conf(
ngx_conf_t *cf);
53 static char *ngx_http_limit_conn_merge_conf(
ngx_conf_t *cf,
void *parent,
87 ngx_http_limit_conn_zone,
111 &ngx_http_limit_conn_log_levels },
118 &ngx_http_limit_conn_status_bounds },
126 ngx_http_limit_conn_init,
134 ngx_http_limit_conn_create_conf,
135 ngx_http_limit_conn_merge_conf
141 &ngx_http_limit_conn_module_ctx,
142 ngx_http_limit_conn_commands,
195 "the value of the \"%V\" variable "
196 "is more than 255 bytes: \"%v\"",
203 hash = ngx_crc32_short(vv->
data, len);
209 node = ngx_http_limit_conn_lookup(ctx->
rbtree, vv, hash);
221 ngx_http_limit_conn_cleanup_all(r->
pool);
228 lc->
len = (u_char) len;
243 "limiting connections by zone \"%V\"",
246 ngx_http_limit_conn_cleanup_all(r->
pool);
254 "limit conn: %08XD %d", node->
key, lc->
conn);
264 cln->
handler = ngx_http_limit_conn_cleanup;
284 if (node->
key < temp->
key) {
288 }
else if (node->
key > temp->
key) {
301 if (*p == sentinel) {
310 node->
left = sentinel;
311 node->
right = sentinel;
327 while (node != sentinel) {
329 if (hash < node->key) {
334 if (hash > node->
key) {
344 (
size_t) vv->
len, (size_t) lcn->
len);
349 node = (rc < 0) ? node->
left : node->
right;
357 ngx_http_limit_conn_cleanup(
void *data)
374 "limit conn cleanup: %08XD %d", node->
key, lc->
conn);
388 ngx_http_limit_conn_cleanup_all(
ngx_pool_t *pool)
394 while (cln && cln->
handler == ngx_http_limit_conn_cleanup) {
395 ngx_http_limit_conn_cleanup(cln->
data);
404 ngx_http_limit_conn_init_zone(
ngx_shm_zone_t *shm_zone,
void *data)
413 ctx = shm_zone->
data;
418 "limit_conn_zone \"%V\" uses the \"%V\" variable "
419 "while previously it used the \"%V\" variable",
438 if (ctx->
rbtree == NULL) {
445 if (sentinel == NULL) {
450 ngx_http_limit_conn_rbtree_insert_value);
452 len =
sizeof(
" in limit_conn_zone \"\"") + shm_zone->
shm.
name.
len;
467 ngx_http_limit_conn_create_conf(
ngx_conf_t *cf)
490 ngx_http_limit_conn_merge_conf(
ngx_conf_t *cf,
void *parent,
void *child)
533 "invalid zone size \"%V\"", &value[i]);
546 "invalid zone size \"%V\"", &value[i]);
552 "zone \"%V\" is too small", &value[i]);
559 if (value[i].data[0] ==
'$') {
580 "invalid parameter \"%V\"", &value[i]);
586 "\"%V\" must have \"zone\" parameter",
593 "no variable is defined for %V \"%V\"",
599 &ngx_http_limit_conn_module);
600 if (shm_zone == NULL) {
604 if (shm_zone->
data) {
605 ctx = shm_zone->
data;
608 "%V \"%V\" is already bound to variable \"%V\"",
613 shm_zone->
init = ngx_http_limit_conn_init_zone;
614 shm_zone->
data = ctx;
632 if (value[2].data[0] !=
'$') {
634 "invalid variable name \"%V\"", &value[2]);
657 "invalid size of limit_zone \"%V\"", &value[3]);
663 "limit_zone \"%V\" is too small", &value[1]);
669 &ngx_http_limit_conn_module);
670 if (shm_zone == NULL) {
674 if (shm_zone->
data) {
675 ctx = shm_zone->
data;
678 "limit_zone \"%V\" is already bound to variable \"%V\"",
679 &value[1], &ctx->
var);
683 shm_zone->
init = ngx_http_limit_conn_init_zone;
684 shm_zone->
data = ctx;
704 &ngx_http_limit_conn_module);
705 if (shm_zone == NULL) {
711 if (limits == NULL) {
712 if (ngx_array_init(&lccf->
limits, cf->
pool, 1,
721 if (shm_zone == limits[i].shm_zone) {
722 return "is duplicate";
726 n =
ngx_atoi(value[2].data, value[2].len);
729 "invalid number of connections \"%V\"", &value[2]);
735 "connection limit must be less 65536");
764 *h = ngx_http_limit_conn_handler;