Mercurial > hg > nginx
annotate src/stream/ngx_stream.h @ 6607:c70b7f4537e1
Stream: variables and script.
This is a port of corresponding http code with unrelated features excluded.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Mon, 04 Jul 2016 16:37:36 +0300 |
parents | 2f41d383c9c7 |
children | 070c31a482e6 |
rev | line source |
---|---|
6115 | 1 |
2 /* | |
3 * Copyright (C) Roman Arutyunyan | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #ifndef _NGX_STREAM_H_INCLUDED_ | |
9 #define _NGX_STREAM_H_INCLUDED_ | |
10 | |
11 | |
12 #include <ngx_config.h> | |
13 #include <ngx_core.h> | |
14 | |
15 #if (NGX_STREAM_SSL) | |
16 #include <ngx_stream_ssl_module.h> | |
17 #endif | |
18 | |
19 | |
20 typedef struct ngx_stream_session_s ngx_stream_session_t; | |
21 | |
22 | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
23 #include <ngx_stream_variables.h> |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
24 #include <ngx_stream_script.h> |
6115 | 25 #include <ngx_stream_upstream.h> |
26 #include <ngx_stream_upstream_round_robin.h> | |
27 | |
28 | |
29 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
30 void **main_conf; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
31 void **srv_conf; |
6115 | 32 } ngx_stream_conf_ctx_t; |
33 | |
34 | |
35 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
36 ngx_sockaddr_t sockaddr; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
37 socklen_t socklen; |
6115 | 38 |
39 /* server ctx */ | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
40 ngx_stream_conf_ctx_t *ctx; |
6115 | 41 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
42 unsigned bind:1; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
43 unsigned wildcard:1; |
6115 | 44 #if (NGX_STREAM_SSL) |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
45 unsigned ssl:1; |
6115 | 46 #endif |
47 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
48 unsigned ipv6only:1; |
6115 | 49 #endif |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
50 #if (NGX_HAVE_REUSEPORT) |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
51 unsigned reuseport:1; |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
52 #endif |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
53 unsigned so_keepalive:2; |
6115 | 54 #if (NGX_HAVE_KEEPALIVE_TUNABLE) |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
55 int tcp_keepidle; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
56 int tcp_keepintvl; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
57 int tcp_keepcnt; |
6115 | 58 #endif |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
59 int backlog; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
60 int type; |
6115 | 61 } ngx_stream_listen_t; |
62 | |
63 | |
64 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
65 ngx_stream_conf_ctx_t *ctx; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
66 ngx_str_t addr_text; |
6115 | 67 #if (NGX_STREAM_SSL) |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
68 ngx_uint_t ssl; /* unsigned ssl:1; */ |
6115 | 69 #endif |
70 } ngx_stream_addr_conf_t; | |
71 | |
72 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
73 in_addr_t addr; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
74 ngx_stream_addr_conf_t conf; |
6115 | 75 } ngx_stream_in_addr_t; |
76 | |
77 | |
78 #if (NGX_HAVE_INET6) | |
79 | |
80 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
81 struct in6_addr addr6; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
82 ngx_stream_addr_conf_t conf; |
6115 | 83 } ngx_stream_in6_addr_t; |
84 | |
85 #endif | |
86 | |
87 | |
88 typedef struct { | |
89 /* ngx_stream_in_addr_t or ngx_stream_in6_addr_t */ | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
90 void *addrs; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
91 ngx_uint_t naddrs; |
6115 | 92 } ngx_stream_port_t; |
93 | |
94 | |
95 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
96 int family; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
97 int type; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
98 in_port_t port; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
99 ngx_array_t addrs; /* array of ngx_stream_conf_addr_t */ |
6115 | 100 } ngx_stream_conf_port_t; |
101 | |
102 | |
103 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
104 ngx_stream_listen_t opt; |
6115 | 105 } ngx_stream_conf_addr_t; |
106 | |
107 | |
6175 | 108 typedef ngx_int_t (*ngx_stream_access_pt)(ngx_stream_session_t *s); |
109 | |
110 | |
6115 | 111 typedef struct { |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
112 ngx_array_t servers; /* ngx_stream_core_srv_conf_t */ |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
113 ngx_array_t listen; /* ngx_stream_listen_t */ |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
114 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
115 ngx_stream_access_pt limit_conn_handler; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
116 ngx_stream_access_pt access_handler; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
117 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
118 ngx_hash_t variables_hash; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
119 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
120 ngx_array_t variables; /* ngx_stream_variable_t */ |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
121 ngx_uint_t ncaptures; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
122 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
123 ngx_uint_t variables_hash_max_size; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
124 ngx_uint_t variables_hash_bucket_size; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
125 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
126 ngx_hash_keys_arrays_t *variables_keys; |
6115 | 127 } ngx_stream_core_main_conf_t; |
128 | |
129 | |
130 typedef void (*ngx_stream_handler_pt)(ngx_stream_session_t *s); | |
131 | |
132 | |
133 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
134 ngx_stream_handler_pt handler; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
135 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
136 ngx_stream_conf_ctx_t *ctx; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
137 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
138 u_char *file_name; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
139 ngx_int_t line; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
140 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
141 ngx_flag_t tcp_nodelay; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
142 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
143 ngx_log_t *error_log; |
6115 | 144 } ngx_stream_core_srv_conf_t; |
145 | |
146 | |
147 struct ngx_stream_session_s { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
148 uint32_t signature; /* "STRM" */ |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
149 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
150 ngx_connection_t *connection; |
6115 | 151 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
152 off_t received; |
6115 | 153 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
154 ngx_log_handler_pt log_handler; |
6115 | 155 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
156 void **ctx; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
157 void **main_conf; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
158 void **srv_conf; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
159 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
160 ngx_stream_upstream_t *upstream; |
6115 | 161 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
162 ngx_stream_variable_value_t *variables; |
6115 | 163 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
164 #if (NGX_PCRE) |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
165 ngx_uint_t ncaptures; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
166 int *captures; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
167 u_char *captures_data; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
168 #endif |
6115 | 169 }; |
170 | |
171 | |
172 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
173 ngx_int_t (*preconfiguration)(ngx_conf_t *cf); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
174 ngx_int_t (*postconfiguration)(ngx_conf_t *cf); |
6174
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6172
diff
changeset
|
175 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
176 void *(*create_main_conf)(ngx_conf_t *cf); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
177 char *(*init_main_conf)(ngx_conf_t *cf, void *conf); |
6115 | 178 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
179 void *(*create_srv_conf)(ngx_conf_t *cf); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
180 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
181 void *conf); |
6115 | 182 } ngx_stream_module_t; |
183 | |
184 | |
185 #define NGX_STREAM_MODULE 0x4d525453 /* "STRM" */ | |
186 | |
187 #define NGX_STREAM_MAIN_CONF 0x02000000 | |
188 #define NGX_STREAM_SRV_CONF 0x04000000 | |
189 #define NGX_STREAM_UPS_CONF 0x08000000 | |
190 | |
191 | |
192 #define NGX_STREAM_MAIN_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, main_conf) | |
193 #define NGX_STREAM_SRV_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, srv_conf) | |
194 | |
195 | |
196 #define ngx_stream_get_module_ctx(s, module) (s)->ctx[module.ctx_index] | |
197 #define ngx_stream_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; | |
198 #define ngx_stream_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; | |
199 | |
200 | |
201 #define ngx_stream_get_module_main_conf(s, module) \ | |
202 (s)->main_conf[module.ctx_index] | |
203 #define ngx_stream_get_module_srv_conf(s, module) \ | |
204 (s)->srv_conf[module.ctx_index] | |
205 | |
206 #define ngx_stream_conf_get_module_main_conf(cf, module) \ | |
207 ((ngx_stream_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] | |
208 #define ngx_stream_conf_get_module_srv_conf(cf, module) \ | |
209 ((ngx_stream_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] | |
210 | |
211 #define ngx_stream_cycle_get_module_main_conf(cycle, module) \ | |
212 (cycle->conf_ctx[ngx_stream_module.index] ? \ | |
213 ((ngx_stream_conf_ctx_t *) cycle->conf_ctx[ngx_stream_module.index]) \ | |
214 ->main_conf[module.ctx_index]: \ | |
215 NULL) | |
216 | |
217 | |
218 void ngx_stream_init_connection(ngx_connection_t *c); | |
219 void ngx_stream_close_connection(ngx_connection_t *c); | |
220 | |
221 | |
222 extern ngx_module_t ngx_stream_module; | |
223 extern ngx_uint_t ngx_stream_max_module; | |
224 extern ngx_module_t ngx_stream_core_module; | |
225 | |
226 | |
227 #endif /* _NGX_STREAM_H_INCLUDED_ */ |