annotate src/http/modules/ngx_http_limit_conn_module.c @ 4412:d620f497c50f

Copyright updated.
author Maxim Konovalov <maxim@nginx.com>
date Wed, 18 Jan 2012 15:07:43 +0000
parents 7697412a0921
children 2d4ff8bd5649
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: 4380
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 {
981
6fe76f377a62 fix key length and alignment
Igor Sysoev <igor@sysoev.ru>
parents: 980
diff changeset
14 u_char color;
6fe76f377a62 fix key length and alignment
Igor Sysoev <igor@sysoev.ru>
parents: 980
diff changeset
15 u_char len;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16 u_short conn;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 u_char data[1];
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
18 } ngx_http_limit_conn_node_t;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21 typedef struct {
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 ngx_shm_zone_t *shm_zone;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 ngx_rbtree_node_t *node;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
24 } ngx_http_limit_conn_cleanup_t;
980
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
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27 typedef struct {
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
28 ngx_rbtree_t *rbtree;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
29 ngx_int_t index;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
30 ngx_str_t var;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
31 } ngx_http_limit_conn_ctx_t;
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
32
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
33
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
34 typedef struct {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35 ngx_shm_zone_t *shm_zone;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36 ngx_uint_t conn;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
37 } ngx_http_limit_conn_limit_t;
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
38
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
39
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
40 typedef struct {
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
41 ngx_array_t limits;
3186
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
42 ngx_uint_t log_level;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
43 } ngx_http_limit_conn_conf_t;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
46 static ngx_rbtree_node_t *ngx_http_limit_conn_lookup(ngx_rbtree_t *rbtree,
4270
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
47 ngx_http_variable_value_t *vv, uint32_t hash);
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
48 static void ngx_http_limit_conn_cleanup(void *data);
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
49 static ngx_inline void ngx_http_limit_conn_cleanup_all(ngx_pool_t *pool);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
51 static void *ngx_http_limit_conn_create_conf(ngx_conf_t *cf);
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
52 static char *ngx_http_limit_conn_merge_conf(ngx_conf_t *cf, void *parent,
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53 void *child);
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
54 static char *ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
55 void *conf);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56 static char *ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd,
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57 void *conf);
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 static char *ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd,
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 void *conf);
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
60 static ngx_int_t ngx_http_limit_conn_init(ngx_conf_t *cf);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
63 static ngx_conf_deprecated_t ngx_conf_deprecated_limit_zone = {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
64 ngx_conf_deprecated, "limit_zone", "limit_conn_zone"
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
65 };
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
66
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
67
3186
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
68 static ngx_conf_enum_t ngx_http_limit_conn_log_levels[] = {
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
69 { ngx_string("info"), NGX_LOG_INFO },
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
70 { ngx_string("notice"), NGX_LOG_NOTICE },
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
71 { ngx_string("warn"), NGX_LOG_WARN },
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
72 { ngx_string("error"), NGX_LOG_ERR },
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
73 { ngx_null_string, 0 }
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
74 };
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
75
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
76
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
77 static ngx_command_t ngx_http_limit_conn_commands[] = {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
79 { ngx_string("limit_conn_zone"),
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
80 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE2,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
81 ngx_http_limit_conn_zone,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
82 0,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
83 0,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
84 NULL },
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
85
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 { ngx_string("limit_zone"),
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
87 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE3,
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 ngx_http_limit_zone,
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 0,
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 0,
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 NULL },
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 { ngx_string("limit_conn"),
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
94 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 ngx_http_limit_conn,
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 NGX_HTTP_LOC_CONF_OFFSET,
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
3186
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
100 { ngx_string("limit_conn_log_level"),
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
101 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
102 ngx_conf_set_enum_slot,
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
103 NGX_HTTP_LOC_CONF_OFFSET,
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
104 offsetof(ngx_http_limit_conn_conf_t, log_level),
3186
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
105 &ngx_http_limit_conn_log_levels },
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
106
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107 ngx_null_command
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 };
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
111 static ngx_http_module_t ngx_http_limit_conn_module_ctx = {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112 NULL, /* preconfiguration */
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
113 ngx_http_limit_conn_init, /* postconfiguration */
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115 NULL, /* create main configuration */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 NULL, /* init main configuration */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118 NULL, /* create server configuration */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 NULL, /* merge server configuration */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
121 ngx_http_limit_conn_create_conf, /* create location configration */
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
122 ngx_http_limit_conn_merge_conf /* merge location configration */
980
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
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
126 ngx_module_t ngx_http_limit_conn_module = {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 NGX_MODULE_V1,
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
128 &ngx_http_limit_conn_module_ctx, /* module context */
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
129 ngx_http_limit_conn_commands, /* module directives */
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130 NGX_HTTP_MODULE, /* module type */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131 NULL, /* init master */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 NULL, /* init module */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 NULL, /* init process */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 NULL, /* init thread */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 NULL, /* exit thread */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136 NULL, /* exit process */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137 NULL, /* exit master */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 NGX_MODULE_V1_PADDING
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139 };
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 static ngx_int_t
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
143 ngx_http_limit_conn_handler(ngx_http_request_t *r)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144 {
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 size_t len, n;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 uint32_t hash;
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
147 ngx_uint_t i;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148 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
149 ngx_rbtree_node_t *node;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 ngx_pool_cleanup_t *cln;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151 ngx_http_variable_value_t *vv;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
152 ngx_http_limit_conn_ctx_t *ctx;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
153 ngx_http_limit_conn_node_t *lc;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
154 ngx_http_limit_conn_conf_t *lccf;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
155 ngx_http_limit_conn_limit_t *limits;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
156 ngx_http_limit_conn_cleanup_t *lccln;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
158 if (r->main->limit_conn_set) {
984
dd128232e6ba count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents: 981
diff changeset
159 return NGX_DECLINED;
dd128232e6ba count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents: 981
diff changeset
160 }
dd128232e6ba count connection once per request
Igor Sysoev <igor@sysoev.ru>
parents: 981
diff changeset
161
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
162 r->main->limit_conn_set = 1;
1011
19118c44303f test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents: 1002
diff changeset
163
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
164 lccf = ngx_http_get_module_loc_conf(r, ngx_http_limit_conn_module);
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
165 limits = lccf->limits.elts;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
167 for (i = 0; i < lccf->limits.nelts; i++) {
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
168 ctx = limits[i].shm_zone->data;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
169
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
170 vv = ngx_http_get_indexed_variable(r, ctx->index);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
172 if (vv == NULL || vv->not_found) {
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
173 continue;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
174 }
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
176 len = vv->len;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
178 if (len == 0) {
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
179 continue;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
180 }
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
182 if (len > 255) {
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
183 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
184 "the value of the \"%V\" variable "
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
185 "is more than 255 bytes: \"%v\"",
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
186 &ctx->var, vv);
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
187 continue;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
190 hash = ngx_crc32_short(vv->data, len);
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
191
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
192 shpool = (ngx_slab_pool_t *) limits[i].shm_zone->shm.addr;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
193
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
194 ngx_shmtx_lock(&shpool->mutex);
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
195
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
196 node = ngx_http_limit_conn_lookup(ctx->rbtree, vv, hash);
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
197
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
198 if (node == NULL) {
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
199
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
200 n = offsetof(ngx_rbtree_node_t, color)
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
201 + offsetof(ngx_http_limit_conn_node_t, data)
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
202 + len;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
203
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
204 node = ngx_slab_alloc_locked(shpool, n);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
206 if (node == NULL) {
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
207 ngx_shmtx_unlock(&shpool->mutex);
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
208 ngx_http_limit_conn_cleanup_all(r->pool);
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
209 return NGX_HTTP_SERVICE_UNAVAILABLE;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
210 }
2373
f4603d71f532 log 503 error reason
Igor Sysoev <igor@sysoev.ru>
parents: 2372
diff changeset
211
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
212 lc = (ngx_http_limit_conn_node_t *) &node->color;
1012
11ffb8e4753f stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents: 1011
diff changeset
213
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
214 node->key = hash;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
215 lc->len = (u_char) len;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
216 lc->conn = 1;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
217 ngx_memcpy(lc->data, vv->data, len);
1012
11ffb8e4753f stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents: 1011
diff changeset
218
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
219 ngx_rbtree_insert(ctx->rbtree, node);
1012
11ffb8e4753f stop rbtree search early if equal hash was found
Igor Sysoev <igor@sysoev.ru>
parents: 1011
diff changeset
220
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
221 } else {
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
222
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
223 lc = (ngx_http_limit_conn_node_t *) &node->color;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
225 if ((ngx_uint_t) lc->conn >= limits[i].conn) {
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
226
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
227 ngx_shmtx_unlock(&shpool->mutex);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
229 ngx_log_error(lccf->log_level, r->connection->log, 0,
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
230 "limiting connections by zone \"%V\"",
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
231 &limits[i].shm_zone->shm.name);
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
232
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
233 ngx_http_limit_conn_cleanup_all(r->pool);
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
234 return NGX_HTTP_SERVICE_UNAVAILABLE;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
235 }
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
236
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
237 lc->conn++;
4270
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
238 }
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
240 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
241 "limit zone: %08XD %d", node->key, lc->conn);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
243 ngx_shmtx_unlock(&shpool->mutex);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
245 cln = ngx_pool_cleanup_add(r->pool,
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
246 sizeof(ngx_http_limit_conn_cleanup_t));
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
247 if (cln == NULL) {
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
248 return NGX_HTTP_INTERNAL_SERVER_ERROR;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
249 }
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
250
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
251 cln->handler = ngx_http_limit_conn_cleanup;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
252 lccln = cln->data;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
253
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
254 lccln->shm_zone = limits[i].shm_zone;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
255 lccln->node = node;
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
256 }
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
257
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
258 return NGX_DECLINED;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
259 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
260
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
261
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
262 static void
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
263 ngx_http_limit_conn_rbtree_insert_value(ngx_rbtree_node_t *temp,
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
264 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
265 {
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
266 ngx_rbtree_node_t **p;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
267 ngx_http_limit_conn_node_t *lcn, *lcnt;
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
268
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
269 for ( ;; ) {
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
270
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
271 if (node->key < temp->key) {
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
272
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
273 p = &temp->left;
1026
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 } else if (node->key > temp->key) {
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
276
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
277 p = &temp->right;
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
278
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
279 } else { /* node->key == temp->key */
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
280
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
281 lcn = (ngx_http_limit_conn_node_t *) &node->color;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
282 lcnt = (ngx_http_limit_conn_node_t *) &temp->color;
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
283
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
284 p = (ngx_memn2cmp(lcn->data, lcnt->data, lcn->len, lcnt->len) < 0)
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
285 ? &temp->left : &temp->right;
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
286 }
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
287
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
288 if (*p == sentinel) {
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
289 break;
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
290 }
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
291
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
292 temp = *p;
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
293 }
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
294
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
295 *p = node;
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
296 node->parent = temp;
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
297 node->left = sentinel;
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
298 node->right = sentinel;
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
299 ngx_rbt_red(node);
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
300 }
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
301
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
302
4270
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
303 static ngx_rbtree_node_t *
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
304 ngx_http_limit_conn_lookup(ngx_rbtree_t *rbtree, ngx_http_variable_value_t *vv,
4270
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
305 uint32_t hash)
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
306 {
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
307 ngx_int_t rc;
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
308 ngx_rbtree_node_t *node, *sentinel;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
309 ngx_http_limit_conn_node_t *lcn;
4270
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 = rbtree->root;
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
312 sentinel = rbtree->sentinel;
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
313
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
314 while (node != sentinel) {
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
315
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
316 if (hash < node->key) {
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
317 node = node->left;
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
318 continue;
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 if (hash > node->key) {
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
322 node = node->right;
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
323 continue;
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
324 }
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
325
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
326 /* hash == node->key */
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
327
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
328 do {
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
329 lcn = (ngx_http_limit_conn_node_t *) &node->color;
4270
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
330
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
331 rc = ngx_memn2cmp(vv->data, lcn->data,
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
332 (size_t) vv->len, (size_t) lcn->len);
4270
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
333 if (rc == 0) {
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
334 return node;
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
335 }
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
336
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
337 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
338
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
339 } 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
340
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
341 break;
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
342 }
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
343
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
344 return NULL;
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
345 }
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
346
3544987fef85 Limit zone: rbtree lookup moved to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 3186
diff changeset
347
1026
38be15c1379a fix duplicate rbtree keys case
Igor Sysoev <igor@sysoev.ru>
parents: 1012
diff changeset
348 static void
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
349 ngx_http_limit_conn_cleanup(void *data)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
350 {
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
351 ngx_http_limit_conn_cleanup_t *lccln = data;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
352
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
353 ngx_slab_pool_t *shpool;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
354 ngx_rbtree_node_t *node;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
355 ngx_http_limit_conn_ctx_t *ctx;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
356 ngx_http_limit_conn_node_t *lc;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
357
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
358 ctx = lccln->shm_zone->data;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
359 shpool = (ngx_slab_pool_t *) lccln->shm_zone->shm.addr;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
360 node = lccln->node;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
361 lc = (ngx_http_limit_conn_node_t *) &node->color;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
362
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
363 ngx_shmtx_lock(&shpool->mutex);
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
364
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
365 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, lccln->shm_zone->shm.log, 0,
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
366 "limit zone cleanup: %08XD %d", node->key, lc->conn);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
367
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
368 lc->conn--;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
369
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
370 if (lc->conn == 0) {
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
371 ngx_rbtree_delete(ctx->rbtree, node);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
372 ngx_slab_free_locked(shpool, node);
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
373 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
374
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
375 ngx_shmtx_unlock(&shpool->mutex);
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
376 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
377
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
378
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
379 static ngx_inline void
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
380 ngx_http_limit_conn_cleanup_all(ngx_pool_t *pool)
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
381 {
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
382 ngx_pool_cleanup_t *cln;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
383
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
384 cln = pool->cleanup;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
385
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
386 while (cln && cln->handler == ngx_http_limit_conn_cleanup) {
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
387 ngx_http_limit_conn_cleanup(cln->data);
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
388 cln = cln->next;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
389 }
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
390
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
391 pool->cleanup = cln;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
392 }
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
393
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
394
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
395 static ngx_int_t
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
396 ngx_http_limit_conn_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
397 {
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
398 ngx_http_limit_conn_ctx_t *octx = data;
993
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
399
2611
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2373
diff changeset
400 size_t len;
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
401 ngx_slab_pool_t *shpool;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
402 ngx_rbtree_node_t *sentinel;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
403 ngx_http_limit_conn_ctx_t *ctx;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
404
993
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
405 ctx = shm_zone->data;
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
406
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
407 if (octx) {
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
408 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
409 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0,
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
410 "limit_conn_zone \"%V\" uses the \"%V\" variable "
993
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
411 "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
412 &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
413 return NGX_ERROR;
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
414 }
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
415
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
416 ctx->rbtree = octx->rbtree;
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
417
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
418 return NGX_OK;
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
419 }
1b9a4d92173f pass the inherited shm_zone data
Igor Sysoev <igor@sysoev.ru>
parents: 987
diff changeset
420
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
421 shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
422
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
423 if (shm_zone->shm.exists) {
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
424 ctx->rbtree = shpool->data;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
425
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
426 return NGX_OK;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
427 }
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
428
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
429 ctx->rbtree = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_t));
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
430 if (ctx->rbtree == NULL) {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
431 return NGX_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
432 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
433
2720
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
434 shpool->data = ctx->rbtree;
b3b8c66bd520 support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents: 2716
diff changeset
435
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
436 sentinel = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_node_t));
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
437 if (sentinel == NULL) {
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
438 return NGX_ERROR;
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
1743
4fc402c3ec73 optimize rbtree initialization and insert
Igor Sysoev <igor@sysoev.ru>
parents: 1406
diff changeset
441 ngx_rbtree_init(ctx->rbtree, sentinel,
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
442 ngx_http_limit_conn_rbtree_insert_value);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
443
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
444 len = sizeof(" in limit_conn_zone \"\"") + shm_zone->shm.name.len;
2611
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2373
diff changeset
445
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2373
diff changeset
446 shpool->log_ctx = ngx_slab_alloc(shpool, len);
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2373
diff changeset
447 if (shpool->log_ctx == NULL) {
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2373
diff changeset
448 return NGX_ERROR;
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2373
diff changeset
449 }
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2373
diff changeset
450
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
451 ngx_sprintf(shpool->log_ctx, " in limit_conn_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
452 &shm_zone->shm.name);
2611
2bce3f6416c6 improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents: 2373
diff changeset
453
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
454 return NGX_OK;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
455 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
456
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
457
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
458 static void *
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
459 ngx_http_limit_conn_create_conf(ngx_conf_t *cf)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
460 {
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
461 ngx_http_limit_conn_conf_t *conf;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
462
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
463 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_conn_conf_t));
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
464 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
465 return NULL;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
466 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
467
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
468 /*
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
469 * set by ngx_pcalloc():
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
470 *
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
471 * conf->limits.elts = NULL;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
472 */
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
473
3186
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
474 conf->log_level = NGX_CONF_UNSET_UINT;
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
475
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
476 return conf;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
477 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
478
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
479
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
480 static char *
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
481 ngx_http_limit_conn_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
482 {
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
483 ngx_http_limit_conn_conf_t *prev = parent;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
484 ngx_http_limit_conn_conf_t *conf = child;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
485
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
486 if (conf->limits.elts == NULL) {
4380
7697412a0921 Fixed limit_conn_log_level/limit_req_log_level inheritance.
Valentin Bartenev <vbart@nginx.com>
parents: 4280
diff changeset
487 conf->limits = prev->limits;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
488 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
489
3186
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
490 ngx_conf_merge_uint_value(conf->log_level, prev->log_level, NGX_LOG_ERR);
23d567eabc5d limit_conn_log_level
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
491
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
492 return NGX_CONF_OK;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
493 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
494
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
495
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
496 static char *
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
497 ngx_http_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
498 {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
499 u_char *p;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
500 ssize_t size;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
501 ngx_str_t *value, name, s;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
502 ngx_uint_t i;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
503 ngx_shm_zone_t *shm_zone;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
504 ngx_http_limit_conn_ctx_t *ctx;
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
505
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
506 value = cf->args->elts;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
507
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
508 ctx = NULL;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
509 size = 0;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
510 name.len = 0;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
511
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
512 for (i = 1; i < cf->args->nelts; i++) {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
513
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
514 if (ngx_strncmp(value[i].data, "zone=", 5) == 0) {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
515
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
516 name.data = value[i].data + 5;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
517
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
518 p = (u_char *) ngx_strchr(name.data, ':');
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
519
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
520 if (p == NULL) {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
521 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
522 "invalid zone size \"%V\"", &value[i]);
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
523 return NGX_CONF_ERROR;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
524 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
525
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
526 name.len = p - name.data;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
527
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
528 s.data = p + 1;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
529 s.len = value[i].data + value[i].len - s.data;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
530
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
531 size = ngx_parse_size(&s);
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
532
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
533 if (size == NGX_ERROR) {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
534 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
535 "invalid zone size \"%V\"", &value[i]);
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
536 return NGX_CONF_ERROR;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
537 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
538
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
539 if (size < (ssize_t) (8 * ngx_pagesize)) {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
540 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
541 "zone \"%V\" is too small", &value[i]);
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
542 return NGX_CONF_ERROR;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
543 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
544
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
545 continue;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
546 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
547
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
548 if (value[i].data[0] == '$') {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
549
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
550 value[i].len--;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
551 value[i].data++;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
552
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
553 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_conn_ctx_t));
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
554 if (ctx == NULL) {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
555 return NGX_CONF_ERROR;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
556 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
557
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
558 ctx->index = ngx_http_get_variable_index(cf, &value[i]);
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
559 if (ctx->index == NGX_ERROR) {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
560 return NGX_CONF_ERROR;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
561 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
562
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
563 ctx->var = value[i];
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
564
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
565 continue;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
566 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
567
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
568 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
569 "invalid parameter \"%V\"", &value[i]);
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
570 return NGX_CONF_ERROR;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
571 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
572
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
573 if (name.len == 0) {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
574 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
575 "\"%V\" must have \"zone\" parameter",
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
576 &cmd->name);
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
577 return NGX_CONF_ERROR;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
578 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
579
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
580 if (ctx == NULL) {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
581 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
582 "no variable is defined for %V \"%V\"",
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
583 &cmd->name, &name);
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
584 return NGX_CONF_ERROR;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
585 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
586
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
587 shm_zone = ngx_shared_memory_add(cf, &name, size,
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
588 &ngx_http_limit_conn_module);
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
589 if (shm_zone == NULL) {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
590 return NGX_CONF_ERROR;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
591 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
592
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
593 if (shm_zone->data) {
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
594 ctx = shm_zone->data;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
595
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
596 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
597 "%V \"%V\" is already bound to variable \"%V\"",
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
598 &cmd->name, &name, &ctx->var);
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
599 return NGX_CONF_ERROR;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
600 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
601
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
602 shm_zone->init = ngx_http_limit_conn_init_zone;
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
603 shm_zone->data = ctx;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
604
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
605 return NGX_CONF_OK;
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
606 }
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
607
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
608
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
609 static char *
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
610 ngx_http_limit_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
611 {
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
612 ssize_t n;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
613 ngx_str_t *value;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
614 ngx_shm_zone_t *shm_zone;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
615 ngx_http_limit_conn_ctx_t *ctx;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
616
4272
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
617 ngx_conf_deprecated(cf, &ngx_conf_deprecated_limit_zone, NULL);
260d591cb6a3 Limit zone: added the "limit_conn_zone" directive.
Valentin Bartenev <vbart@nginx.com>
parents: 4271
diff changeset
618
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
619 value = cf->args->elts;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
620
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
621 if (value[2].data[0] != '$') {
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
622 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
623 "invalid variable name \"%V\"", &value[2]);
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
624 return NGX_CONF_ERROR;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
625 }
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
626
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
627 value[2].len--;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
628 value[2].data++;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
629
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
630 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_limit_conn_ctx_t));
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
631 if (ctx == NULL) {
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
632 return NGX_CONF_ERROR;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
633 }
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
634
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
635 ctx->index = ngx_http_get_variable_index(cf, &value[2]);
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
636 if (ctx->index == NGX_ERROR) {
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
637 return NGX_CONF_ERROR;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
638 }
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
639
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
640 ctx->var = value[2];
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
641
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
642 n = ngx_parse_size(&value[3]);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
643
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
644 if (n == NGX_ERROR) {
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
645 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
646 "invalid size of limit_zone \"%V\"", &value[3]);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
647 return NGX_CONF_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
648 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
649
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
650 if (n < (ngx_int_t) (8 * ngx_pagesize)) {
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
651 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
652 "limit_zone \"%V\" is too small", &value[1]);
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
653 return NGX_CONF_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
654 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
655
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
656
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
657 shm_zone = ngx_shared_memory_add(cf, &value[1], n,
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
658 &ngx_http_limit_conn_module);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
659 if (shm_zone == NULL) {
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
660 return NGX_CONF_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
661 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
662
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
663 if (shm_zone->data) {
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
664 ctx = shm_zone->data;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
665
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
666 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
667 "limit_zone \"%V\" is already bound to variable \"%V\"",
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
668 &value[1], &ctx->var);
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
669 return NGX_CONF_ERROR;
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
670 }
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
671
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
672 shm_zone->init = ngx_http_limit_conn_init_zone;
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
673 shm_zone->data = ctx;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
674
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
675 return NGX_CONF_OK;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
676 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
677
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
678
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
679 static char *
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
680 ngx_http_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
681 {
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
682 ngx_shm_zone_t *shm_zone;
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
683 ngx_http_limit_conn_conf_t *lccf = conf;
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
684 ngx_http_limit_conn_limit_t *limit, *limits;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
685
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
686 ngx_str_t *value;
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
687 ngx_int_t n;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
688 ngx_uint_t i;
2372
7148efbdd798 test duplicate limit_conn
Igor Sysoev <igor@sysoev.ru>
parents: 1743
diff changeset
689
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
690 value = cf->args->elts;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
691
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
692 shm_zone = ngx_shared_memory_add(cf, &value[1], 0,
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
693 &ngx_http_limit_conn_module);
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
694 if (shm_zone == NULL) {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
695 return NGX_CONF_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
696 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
697
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
698 limits = lccf->limits.elts;
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
699
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
700 if (limits == NULL) {
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
701 if (ngx_array_init(&lccf->limits, cf->pool, 1,
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
702 sizeof(ngx_http_limit_conn_limit_t))
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
703 != NGX_OK)
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
704 {
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
705 return NGX_CONF_ERROR;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
706 }
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
707 }
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
708
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
709 for (i = 0; i < lccf->limits.nelts; i++) {
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
710 if (shm_zone == limits[i].shm_zone) {
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
711 return "is duplicate";
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
712 }
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
713 }
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
714
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
715 n = ngx_atoi(value[2].data, value[2].len);
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
716 if (n <= 0) {
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
717 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
987
14e68f471d02 new syntax
Igor Sysoev <igor@sysoev.ru>
parents: 984
diff changeset
718 "invalid number of connections \"%V\"", &value[2]);
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
719 return NGX_CONF_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
720 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
721
1011
19118c44303f test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents: 1002
diff changeset
722 if (n > 65535) {
19118c44303f test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents: 1002
diff changeset
723 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
724 "connection limit must be less 65536");
19118c44303f test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents: 1002
diff changeset
725 return NGX_CONF_ERROR;
19118c44303f test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents: 1002
diff changeset
726 }
19118c44303f test length of variable and number of connections
Igor Sysoev <igor@sysoev.ru>
parents: 1002
diff changeset
727
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
728 limit = ngx_array_push(&lccf->limits);
4271
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
729 limit->conn = n;
b86cceba426a Limit zone: support for multiple "limit_conn" limits.
Valentin Bartenev <vbart@nginx.com>
parents: 4270
diff changeset
730 limit->shm_zone = shm_zone;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
731
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
732 return NGX_CONF_OK;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
733 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
734
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
735
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
736 static ngx_int_t
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
737 ngx_http_limit_conn_init(ngx_conf_t *cf)
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
738 {
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
739 ngx_http_handler_pt *h;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
740 ngx_http_core_main_conf_t *cmcf;
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 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
743
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
744 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
745 if (h == NULL) {
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
746 return NGX_ERROR;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
747 }
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
748
4280
91874133fb27 Renamed ngx_http_limit_zone_module to ngx_http_limit_conn_module.
Valentin Bartenev <vbart@nginx.com>
parents: 4272
diff changeset
749 *h = ngx_http_limit_conn_handler;
980
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
750
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
751 return NGX_OK;
7cb910b4a58a ngx_http_limit_zone_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
752 }