Mercurial > hg > nginx-quic
annotate src/stream/ngx_stream_limit_conn_module.c @ 8722:02a9ad88e2df quic
QUIC: added missing frame initialization.
Currently, all used fields are initialized, but usage may change in future.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Mon, 06 Dec 2021 11:04:55 +0300 |
parents | b45f052483b8 |
children |
rev | line source |
---|---|
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
2 /* |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
4 * Copyright (C) Nginx, Inc. |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
5 */ |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
6 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
7 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
10 #include <ngx_stream.h> |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
11 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
12 |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
13 #define NGX_STREAM_LIMIT_CONN_PASSED 1 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
14 #define NGX_STREAM_LIMIT_CONN_REJECTED 2 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
15 #define NGX_STREAM_LIMIT_CONN_REJECTED_DRY_RUN 3 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
16 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
17 |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
18 typedef struct { |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
19 u_char color; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
20 u_char len; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
21 u_short conn; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
22 u_char data[1]; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
23 } ngx_stream_limit_conn_node_t; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
24 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
25 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
26 typedef struct { |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
27 ngx_shm_zone_t *shm_zone; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
28 ngx_rbtree_node_t *node; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
29 } ngx_stream_limit_conn_cleanup_t; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
30 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
31 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
32 typedef struct { |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
33 ngx_rbtree_t rbtree; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
34 ngx_rbtree_node_t sentinel; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
35 } ngx_stream_limit_conn_shctx_t; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
36 |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
37 |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
38 typedef struct { |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
39 ngx_stream_limit_conn_shctx_t *sh; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
40 ngx_slab_pool_t *shpool; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
41 ngx_stream_complex_value_t key; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
42 } ngx_stream_limit_conn_ctx_t; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
43 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
44 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
45 typedef struct { |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
46 ngx_shm_zone_t *shm_zone; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
47 ngx_uint_t conn; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
48 } ngx_stream_limit_conn_limit_t; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
49 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
50 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
51 typedef struct { |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
52 ngx_array_t limits; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
53 ngx_uint_t log_level; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
54 ngx_flag_t dry_run; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
55 } ngx_stream_limit_conn_conf_t; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
56 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
57 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
58 static ngx_rbtree_node_t *ngx_stream_limit_conn_lookup(ngx_rbtree_t *rbtree, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
59 ngx_str_t *key, uint32_t hash); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
60 static void ngx_stream_limit_conn_cleanup(void *data); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
61 static ngx_inline void ngx_stream_limit_conn_cleanup_all(ngx_pool_t *pool); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
62 |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
63 static ngx_int_t ngx_stream_limit_conn_status_variable(ngx_stream_session_t *s, |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
64 ngx_stream_variable_value_t *v, uintptr_t data); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
65 static void *ngx_stream_limit_conn_create_conf(ngx_conf_t *cf); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
66 static char *ngx_stream_limit_conn_merge_conf(ngx_conf_t *cf, void *parent, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
67 void *child); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
68 static char *ngx_stream_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
69 void *conf); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
70 static char *ngx_stream_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
71 void *conf); |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
72 static ngx_int_t ngx_stream_limit_conn_add_variables(ngx_conf_t *cf); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
73 static ngx_int_t ngx_stream_limit_conn_init(ngx_conf_t *cf); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
74 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
75 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
76 static ngx_conf_enum_t ngx_stream_limit_conn_log_levels[] = { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
77 { ngx_string("info"), NGX_LOG_INFO }, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
78 { ngx_string("notice"), NGX_LOG_NOTICE }, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
79 { ngx_string("warn"), NGX_LOG_WARN }, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
80 { ngx_string("error"), NGX_LOG_ERR }, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
81 { ngx_null_string, 0 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
82 }; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
83 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
84 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
85 static ngx_command_t ngx_stream_limit_conn_commands[] = { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
86 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
87 { ngx_string("limit_conn_zone"), |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
88 NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE2, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
89 ngx_stream_limit_conn_zone, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
90 0, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
91 0, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
92 NULL }, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
93 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
94 { ngx_string("limit_conn"), |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
95 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE2, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
96 ngx_stream_limit_conn, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
97 NGX_STREAM_SRV_CONF_OFFSET, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
98 0, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
99 NULL }, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
100 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
101 { ngx_string("limit_conn_log_level"), |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
102 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
103 ngx_conf_set_enum_slot, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
104 NGX_STREAM_SRV_CONF_OFFSET, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
105 offsetof(ngx_stream_limit_conn_conf_t, log_level), |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
106 &ngx_stream_limit_conn_log_levels }, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
107 |
7594
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
108 { ngx_string("limit_conn_dry_run"), |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
109 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
110 ngx_conf_set_flag_slot, |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
111 NGX_STREAM_SRV_CONF_OFFSET, |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
112 offsetof(ngx_stream_limit_conn_conf_t, dry_run), |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
113 NULL }, |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
114 |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
115 ngx_null_command |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
116 }; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
117 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
118 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
119 static ngx_stream_module_t ngx_stream_limit_conn_module_ctx = { |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
120 ngx_stream_limit_conn_add_variables, /* preconfiguration */ |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
121 ngx_stream_limit_conn_init, /* postconfiguration */ |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
122 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
123 NULL, /* create main configuration */ |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
124 NULL, /* init main configuration */ |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
125 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
126 ngx_stream_limit_conn_create_conf, /* create server configuration */ |
6629 | 127 ngx_stream_limit_conn_merge_conf /* merge server configuration */ |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
128 }; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
129 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
130 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
131 ngx_module_t ngx_stream_limit_conn_module = { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
132 NGX_MODULE_V1, |
6601 | 133 &ngx_stream_limit_conn_module_ctx, /* module context */ |
134 ngx_stream_limit_conn_commands, /* module directives */ | |
135 NGX_STREAM_MODULE, /* module type */ | |
136 NULL, /* init master */ | |
137 NULL, /* init module */ | |
138 NULL, /* init process */ | |
139 NULL, /* init thread */ | |
140 NULL, /* exit thread */ | |
141 NULL, /* exit process */ | |
142 NULL, /* exit master */ | |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
143 NGX_MODULE_V1_PADDING |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
144 }; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
145 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
146 |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
147 static ngx_stream_variable_t ngx_stream_limit_conn_vars[] = { |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
148 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
149 { ngx_string("limit_conn_status"), NULL, |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
150 ngx_stream_limit_conn_status_variable, 0, NGX_STREAM_VAR_NOCACHEABLE, 0 }, |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
151 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
152 ngx_stream_null_variable |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
153 }; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
154 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
155 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
156 static ngx_str_t ngx_stream_limit_conn_status[] = { |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
157 ngx_string("PASSED"), |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
158 ngx_string("REJECTED"), |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
159 ngx_string("REJECTED_DRY_RUN") |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
160 }; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
161 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
162 |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
163 static ngx_int_t |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
164 ngx_stream_limit_conn_handler(ngx_stream_session_t *s) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
165 { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
166 size_t n; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
167 uint32_t hash; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
168 ngx_str_t key; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
169 ngx_uint_t i; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
170 ngx_rbtree_node_t *node; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
171 ngx_pool_cleanup_t *cln; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
172 ngx_stream_limit_conn_ctx_t *ctx; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
173 ngx_stream_limit_conn_node_t *lc; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
174 ngx_stream_limit_conn_conf_t *lccf; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
175 ngx_stream_limit_conn_limit_t *limits; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
176 ngx_stream_limit_conn_cleanup_t *lccln; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
177 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
178 lccf = ngx_stream_get_module_srv_conf(s, ngx_stream_limit_conn_module); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
179 limits = lccf->limits.elts; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
180 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
181 for (i = 0; i < lccf->limits.nelts; i++) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
182 ctx = limits[i].shm_zone->data; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
183 |
6610
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
184 if (ngx_stream_complex_value(s, &ctx->key, &key) != NGX_OK) { |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
185 return NGX_ERROR; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
186 } |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
187 |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
188 if (key.len == 0) { |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
189 continue; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
190 } |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
191 |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
192 if (key.len > 255) { |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
193 ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
194 "the value of the \"%V\" key " |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
195 "is more than 255 bytes: \"%V\"", |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
196 &ctx->key.value, &key); |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
197 continue; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
198 } |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
199 |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
200 s->limit_conn_status = NGX_STREAM_LIMIT_CONN_PASSED; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
201 |
6610
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
202 hash = ngx_crc32_short(key.data, key.len); |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
203 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
204 ngx_shmtx_lock(&ctx->shpool->mutex); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
205 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
206 node = ngx_stream_limit_conn_lookup(&ctx->sh->rbtree, &key, hash); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
207 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
208 if (node == NULL) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
209 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
210 n = offsetof(ngx_rbtree_node_t, color) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
211 + offsetof(ngx_stream_limit_conn_node_t, data) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
212 + key.len; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
213 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
214 node = ngx_slab_alloc_locked(ctx->shpool, n); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
215 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
216 if (node == NULL) { |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
217 ngx_shmtx_unlock(&ctx->shpool->mutex); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
218 ngx_stream_limit_conn_cleanup_all(s->connection->pool); |
7594
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
219 |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
220 if (lccf->dry_run) { |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
221 s->limit_conn_status = |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
222 NGX_STREAM_LIMIT_CONN_REJECTED_DRY_RUN; |
7594
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
223 return NGX_DECLINED; |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
224 } |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
225 |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
226 s->limit_conn_status = NGX_STREAM_LIMIT_CONN_REJECTED; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
227 |
6693 | 228 return NGX_STREAM_SERVICE_UNAVAILABLE; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
229 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
230 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
231 lc = (ngx_stream_limit_conn_node_t *) &node->color; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
232 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
233 node->key = hash; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
234 lc->len = (u_char) key.len; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
235 lc->conn = 1; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
236 ngx_memcpy(lc->data, key.data, key.len); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
237 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
238 ngx_rbtree_insert(&ctx->sh->rbtree, node); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
239 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
240 } else { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
241 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
242 lc = (ngx_stream_limit_conn_node_t *) &node->color; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
243 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
244 if ((ngx_uint_t) lc->conn >= limits[i].conn) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
245 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
246 ngx_shmtx_unlock(&ctx->shpool->mutex); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
247 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
248 ngx_log_error(lccf->log_level, s->connection->log, 0, |
7594
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
249 "limiting connections%s by zone \"%V\"", |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
250 lccf->dry_run ? ", dry run," : "", |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
251 &limits[i].shm_zone->shm.name); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
252 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
253 ngx_stream_limit_conn_cleanup_all(s->connection->pool); |
7594
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
254 |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
255 if (lccf->dry_run) { |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
256 s->limit_conn_status = |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
257 NGX_STREAM_LIMIT_CONN_REJECTED_DRY_RUN; |
7594
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
258 return NGX_DECLINED; |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
259 } |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
260 |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
261 s->limit_conn_status = NGX_STREAM_LIMIT_CONN_REJECTED; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
262 |
6693 | 263 return NGX_STREAM_SERVICE_UNAVAILABLE; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
264 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
265 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
266 lc->conn++; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
267 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
268 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
269 ngx_log_debug2(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, |
6480 | 270 "limit conn: %08Xi %d", node->key, lc->conn); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
271 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
272 ngx_shmtx_unlock(&ctx->shpool->mutex); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
273 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
274 cln = ngx_pool_cleanup_add(s->connection->pool, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
275 sizeof(ngx_stream_limit_conn_cleanup_t)); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
276 if (cln == NULL) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
277 return NGX_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
278 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
279 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
280 cln->handler = ngx_stream_limit_conn_cleanup; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
281 lccln = cln->data; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
282 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
283 lccln->shm_zone = limits[i].shm_zone; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
284 lccln->node = node; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
285 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
286 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
287 return NGX_DECLINED; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
288 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
289 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
290 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
291 static void |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
292 ngx_stream_limit_conn_rbtree_insert_value(ngx_rbtree_node_t *temp, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
293 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
294 { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
295 ngx_rbtree_node_t **p; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
296 ngx_stream_limit_conn_node_t *lcn, *lcnt; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
297 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
298 for ( ;; ) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
299 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
300 if (node->key < temp->key) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
301 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
302 p = &temp->left; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
303 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
304 } else if (node->key > temp->key) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
305 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
306 p = &temp->right; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
307 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
308 } else { /* node->key == temp->key */ |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
309 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
310 lcn = (ngx_stream_limit_conn_node_t *) &node->color; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
311 lcnt = (ngx_stream_limit_conn_node_t *) &temp->color; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
312 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
313 p = (ngx_memn2cmp(lcn->data, lcnt->data, lcn->len, lcnt->len) < 0) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
314 ? &temp->left : &temp->right; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
315 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
316 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
317 if (*p == sentinel) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
318 break; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
319 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
320 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
321 temp = *p; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
322 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
323 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
324 *p = node; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
325 node->parent = temp; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
326 node->left = sentinel; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
327 node->right = sentinel; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
328 ngx_rbt_red(node); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
329 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
330 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
331 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
332 static ngx_rbtree_node_t * |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
333 ngx_stream_limit_conn_lookup(ngx_rbtree_t *rbtree, ngx_str_t *key, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
334 uint32_t hash) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
335 { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
336 ngx_int_t rc; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
337 ngx_rbtree_node_t *node, *sentinel; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
338 ngx_stream_limit_conn_node_t *lcn; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
339 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
340 node = rbtree->root; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
341 sentinel = rbtree->sentinel; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
342 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
343 while (node != sentinel) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
344 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
345 if (hash < node->key) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
346 node = node->left; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
347 continue; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
348 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
349 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
350 if (hash > node->key) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
351 node = node->right; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
352 continue; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
353 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
354 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
355 /* hash == node->key */ |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
356 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
357 lcn = (ngx_stream_limit_conn_node_t *) &node->color; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
358 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
359 rc = ngx_memn2cmp(key->data, lcn->data, key->len, (size_t) lcn->len); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
360 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
361 if (rc == 0) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
362 return node; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
363 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
364 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
365 node = (rc < 0) ? node->left : node->right; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
366 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
367 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
368 return NULL; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
369 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
370 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
371 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
372 static void |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
373 ngx_stream_limit_conn_cleanup(void *data) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
374 { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
375 ngx_stream_limit_conn_cleanup_t *lccln = data; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
376 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
377 ngx_rbtree_node_t *node; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
378 ngx_stream_limit_conn_ctx_t *ctx; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
379 ngx_stream_limit_conn_node_t *lc; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
380 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
381 ctx = lccln->shm_zone->data; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
382 node = lccln->node; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
383 lc = (ngx_stream_limit_conn_node_t *) &node->color; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
384 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
385 ngx_shmtx_lock(&ctx->shpool->mutex); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
386 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
387 ngx_log_debug2(NGX_LOG_DEBUG_STREAM, lccln->shm_zone->shm.log, 0, |
6480 | 388 "limit conn cleanup: %08Xi %d", node->key, lc->conn); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
389 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
390 lc->conn--; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
391 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
392 if (lc->conn == 0) { |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
393 ngx_rbtree_delete(&ctx->sh->rbtree, node); |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
394 ngx_slab_free_locked(ctx->shpool, node); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
395 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
396 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
397 ngx_shmtx_unlock(&ctx->shpool->mutex); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
398 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
399 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
400 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
401 static ngx_inline void |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
402 ngx_stream_limit_conn_cleanup_all(ngx_pool_t *pool) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
403 { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
404 ngx_pool_cleanup_t *cln; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
405 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
406 cln = pool->cleanup; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
407 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
408 while (cln && cln->handler == ngx_stream_limit_conn_cleanup) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
409 ngx_stream_limit_conn_cleanup(cln->data); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
410 cln = cln->next; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
411 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
412 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
413 pool->cleanup = cln; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
414 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
415 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
416 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
417 static ngx_int_t |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
418 ngx_stream_limit_conn_init_zone(ngx_shm_zone_t *shm_zone, void *data) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
419 { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
420 ngx_stream_limit_conn_ctx_t *octx = data; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
421 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
422 size_t len; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
423 ngx_stream_limit_conn_ctx_t *ctx; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
424 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
425 ctx = shm_zone->data; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
426 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
427 if (octx) { |
6610
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
428 if (ctx->key.value.len != octx->key.value.len |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
429 || ngx_strncmp(ctx->key.value.data, octx->key.value.data, |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
430 ctx->key.value.len) |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
431 != 0) |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
432 { |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
433 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0, |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
434 "limit_conn_zone \"%V\" uses the \"%V\" key " |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
435 "while previously it used the \"%V\" key", |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
436 &shm_zone->shm.name, &ctx->key.value, |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
437 &octx->key.value); |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
438 return NGX_ERROR; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
439 } |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
440 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
441 ctx->sh = octx->sh; |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
442 ctx->shpool = octx->shpool; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
443 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
444 return NGX_OK; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
445 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
446 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
447 ctx->shpool = (ngx_slab_pool_t *) shm_zone->shm.addr; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
448 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
449 if (shm_zone->shm.exists) { |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
450 ctx->sh = ctx->shpool->data; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
451 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
452 return NGX_OK; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
453 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
454 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
455 ctx->sh = ngx_slab_alloc(ctx->shpool, |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
456 sizeof(ngx_stream_limit_conn_shctx_t)); |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
457 if (ctx->sh == NULL) { |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
458 return NGX_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
459 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
460 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
461 ctx->shpool->data = ctx->sh; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
462 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
463 ngx_rbtree_init(&ctx->sh->rbtree, &ctx->sh->sentinel, |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
464 ngx_stream_limit_conn_rbtree_insert_value); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
465 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
466 len = sizeof(" in limit_conn_zone \"\"") + shm_zone->shm.name.len; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
467 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
468 ctx->shpool->log_ctx = ngx_slab_alloc(ctx->shpool, len); |
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
469 if (ctx->shpool->log_ctx == NULL) { |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
470 return NGX_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
471 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
472 |
7596
b45f052483b8
Limit conn: added shared context.
Roman Arutyunyan <arut@nginx.com>
parents:
7595
diff
changeset
|
473 ngx_sprintf(ctx->shpool->log_ctx, " in limit_conn_zone \"%V\"%Z", |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
474 &shm_zone->shm.name); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
475 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
476 return NGX_OK; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
477 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
478 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
479 |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
480 static ngx_int_t |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
481 ngx_stream_limit_conn_status_variable(ngx_stream_session_t *s, |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
482 ngx_stream_variable_value_t *v, uintptr_t data) |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
483 { |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
484 if (s->limit_conn_status == 0) { |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
485 v->not_found = 1; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
486 return NGX_OK; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
487 } |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
488 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
489 v->valid = 1; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
490 v->no_cacheable = 0; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
491 v->not_found = 0; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
492 v->len = ngx_stream_limit_conn_status[s->limit_conn_status - 1].len; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
493 v->data = ngx_stream_limit_conn_status[s->limit_conn_status - 1].data; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
494 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
495 return NGX_OK; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
496 } |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
497 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
498 |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
499 static void * |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
500 ngx_stream_limit_conn_create_conf(ngx_conf_t *cf) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
501 { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
502 ngx_stream_limit_conn_conf_t *conf; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
503 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
504 conf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_limit_conn_conf_t)); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
505 if (conf == NULL) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
506 return NULL; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
507 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
508 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
509 /* |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
510 * set by ngx_pcalloc(): |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
511 * |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
512 * conf->limits.elts = NULL; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
513 */ |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
514 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
515 conf->log_level = NGX_CONF_UNSET_UINT; |
7594
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
516 conf->dry_run = NGX_CONF_UNSET; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
517 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
518 return conf; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
519 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
520 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
521 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
522 static char * |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
523 ngx_stream_limit_conn_merge_conf(ngx_conf_t *cf, void *parent, void *child) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
524 { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
525 ngx_stream_limit_conn_conf_t *prev = parent; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
526 ngx_stream_limit_conn_conf_t *conf = child; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
527 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
528 if (conf->limits.elts == NULL) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
529 conf->limits = prev->limits; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
530 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
531 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
532 ngx_conf_merge_uint_value(conf->log_level, prev->log_level, NGX_LOG_ERR); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
533 |
7594
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
534 ngx_conf_merge_value(conf->dry_run, prev->dry_run, 0); |
359b0ea2b067
Limit conn: limit_conn_dry_run directive.
Roman Arutyunyan <arut@nginx.com>
parents:
6693
diff
changeset
|
535 |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
536 return NGX_CONF_OK; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
537 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
538 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
539 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
540 static char * |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
541 ngx_stream_limit_conn_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
542 { |
6610
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
543 u_char *p; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
544 ssize_t size; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
545 ngx_str_t *value, name, s; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
546 ngx_uint_t i; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
547 ngx_shm_zone_t *shm_zone; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
548 ngx_stream_limit_conn_ctx_t *ctx; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
549 ngx_stream_compile_complex_value_t ccv; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
550 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
551 value = cf->args->elts; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
552 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
553 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_stream_limit_conn_ctx_t)); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
554 if (ctx == NULL) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
555 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
556 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
557 |
6610
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
558 ngx_memzero(&ccv, sizeof(ngx_stream_compile_complex_value_t)); |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
559 |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
560 ccv.cf = cf; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
561 ccv.value = &value[1]; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
562 ccv.complex_value = &ctx->key; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
563 |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
564 if (ngx_stream_compile_complex_value(&ccv) != NGX_OK) { |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
565 return NGX_CONF_ERROR; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
566 } |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
567 |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
568 size = 0; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
569 name.len = 0; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
570 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
571 for (i = 2; i < cf->args->nelts; i++) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
572 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
573 if (ngx_strncmp(value[i].data, "zone=", 5) == 0) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
574 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
575 name.data = value[i].data + 5; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
576 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
577 p = (u_char *) ngx_strchr(name.data, ':'); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
578 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
579 if (p == NULL) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
580 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
581 "invalid zone size \"%V\"", &value[i]); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
582 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
583 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
584 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
585 name.len = p - name.data; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
586 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
587 s.data = p + 1; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
588 s.len = value[i].data + value[i].len - s.data; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
589 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
590 size = ngx_parse_size(&s); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
591 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
592 if (size == NGX_ERROR) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
593 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
594 "invalid zone size \"%V\"", &value[i]); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
595 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
596 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
597 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
598 if (size < (ssize_t) (8 * ngx_pagesize)) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
599 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
600 "zone \"%V\" is too small", &value[i]); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
601 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
602 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
603 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
604 continue; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
605 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
606 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
607 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
608 "invalid parameter \"%V\"", &value[i]); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
609 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
610 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
611 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
612 if (name.len == 0) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
613 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
614 "\"%V\" must have \"zone\" parameter", |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
615 &cmd->name); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
616 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
617 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
618 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
619 shm_zone = ngx_shared_memory_add(cf, &name, size, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
620 &ngx_stream_limit_conn_module); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
621 if (shm_zone == NULL) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
622 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
623 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
624 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
625 if (shm_zone->data) { |
6610
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
626 ctx = shm_zone->data; |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
627 |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
628 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
6610
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
629 "%V \"%V\" is already bound to key \"%V\"", |
d5b5866c06c4
Stream: got rid of pseudo variables.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
630 &cmd->name, &name, &ctx->key.value); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
631 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
632 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
633 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
634 shm_zone->init = ngx_stream_limit_conn_init_zone; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
635 shm_zone->data = ctx; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
636 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
637 return NGX_CONF_OK; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
638 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
639 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
640 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
641 static char * |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
642 ngx_stream_limit_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
643 { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
644 ngx_shm_zone_t *shm_zone; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
645 ngx_stream_limit_conn_conf_t *lccf = conf; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
646 ngx_stream_limit_conn_limit_t *limit, *limits; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
647 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
648 ngx_str_t *value; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
649 ngx_int_t n; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
650 ngx_uint_t i; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
651 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
652 value = cf->args->elts; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
653 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
654 shm_zone = ngx_shared_memory_add(cf, &value[1], 0, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
655 &ngx_stream_limit_conn_module); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
656 if (shm_zone == NULL) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
657 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
658 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
659 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
660 limits = lccf->limits.elts; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
661 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
662 if (limits == NULL) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
663 if (ngx_array_init(&lccf->limits, cf->pool, 1, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
664 sizeof(ngx_stream_limit_conn_limit_t)) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
665 != NGX_OK) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
666 { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
667 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
668 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
669 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
670 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
671 for (i = 0; i < lccf->limits.nelts; i++) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
672 if (shm_zone == limits[i].shm_zone) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
673 return "is duplicate"; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
674 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
675 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
676 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
677 n = ngx_atoi(value[2].data, value[2].len); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
678 if (n <= 0) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
679 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
680 "invalid number of connections \"%V\"", &value[2]); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
681 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
682 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
683 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
684 if (n > 65535) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
685 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
686 "connection limit must be less 65536"); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
687 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
688 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
689 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
690 limit = ngx_array_push(&lccf->limits); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
691 if (limit == NULL) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
692 return NGX_CONF_ERROR; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
693 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
694 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
695 limit->conn = n; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
696 limit->shm_zone = shm_zone; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
697 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
698 return NGX_CONF_OK; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
699 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
700 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
701 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
702 static ngx_int_t |
7595
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
703 ngx_stream_limit_conn_add_variables(ngx_conf_t *cf) |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
704 { |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
705 ngx_stream_variable_t *var, *v; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
706 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
707 for (v = ngx_stream_limit_conn_vars; v->name.len; v++) { |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
708 var = ngx_stream_add_variable(cf, &v->name, v->flags); |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
709 if (var == NULL) { |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
710 return NGX_ERROR; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
711 } |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
712 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
713 var->get_handler = v->get_handler; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
714 var->data = v->data; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
715 } |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
716 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
717 return NGX_OK; |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
718 } |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
719 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
720 |
9606d93aa586
Limit conn: $limit_conn_status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7594
diff
changeset
|
721 static ngx_int_t |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
722 ngx_stream_limit_conn_init(ngx_conf_t *cf) |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
723 { |
6693 | 724 ngx_stream_handler_pt *h; |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
725 ngx_stream_core_main_conf_t *cmcf; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
726 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
727 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
728 |
6693 | 729 h = ngx_array_push(&cmcf->phases[NGX_STREAM_PREACCESS_PHASE].handlers); |
730 if (h == NULL) { | |
731 return NGX_ERROR; | |
732 } | |
733 | |
734 *h = ngx_stream_limit_conn_handler; | |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
735 |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
736 return NGX_OK; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
737 } |