Mercurial > hg > nginx
annotate src/stream/ngx_stream.h @ 6678:0125b151c9a5
Stream: log module.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Mon, 05 Sep 2016 17:50:16 +0300 |
parents | ab9b4fd8c5b7 |
children | 40e8ce405859 |
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 | |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
29 #define NGX_STREAM_OK 200 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
30 #define NGX_STREAM_FORBIDDEN 403 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
31 #define NGX_STREAM_INTERNAL_SERVER_ERROR 500 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
32 #define NGX_STREAM_BAD_GATEWAY 502 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
33 #define NGX_STREAM_SERVICE_UNAVAILABLE 503 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
34 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
35 |
6115 | 36 typedef struct { |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
37 void **main_conf; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
38 void **srv_conf; |
6115 | 39 } ngx_stream_conf_ctx_t; |
40 | |
41 | |
42 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
43 ngx_sockaddr_t sockaddr; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
44 socklen_t socklen; |
6115 | 45 |
46 /* server ctx */ | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
47 ngx_stream_conf_ctx_t *ctx; |
6115 | 48 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
49 unsigned bind:1; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
50 unsigned wildcard:1; |
6115 | 51 #if (NGX_STREAM_SSL) |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
52 unsigned ssl:1; |
6115 | 53 #endif |
54 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
55 unsigned ipv6only:1; |
6115 | 56 #endif |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
57 #if (NGX_HAVE_REUSEPORT) |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
58 unsigned reuseport:1; |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
59 #endif |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
60 unsigned so_keepalive:2; |
6115 | 61 #if (NGX_HAVE_KEEPALIVE_TUNABLE) |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
62 int tcp_keepidle; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
63 int tcp_keepintvl; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
64 int tcp_keepcnt; |
6115 | 65 #endif |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
66 int backlog; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
67 int type; |
6115 | 68 } ngx_stream_listen_t; |
69 | |
70 | |
71 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
72 ngx_stream_conf_ctx_t *ctx; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
73 ngx_str_t addr_text; |
6115 | 74 #if (NGX_STREAM_SSL) |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
75 ngx_uint_t ssl; /* unsigned ssl:1; */ |
6115 | 76 #endif |
77 } ngx_stream_addr_conf_t; | |
78 | |
79 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
80 in_addr_t addr; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
81 ngx_stream_addr_conf_t conf; |
6115 | 82 } ngx_stream_in_addr_t; |
83 | |
84 | |
85 #if (NGX_HAVE_INET6) | |
86 | |
87 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
88 struct in6_addr addr6; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
89 ngx_stream_addr_conf_t conf; |
6115 | 90 } ngx_stream_in6_addr_t; |
91 | |
92 #endif | |
93 | |
94 | |
95 typedef struct { | |
96 /* 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
|
97 void *addrs; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
98 ngx_uint_t naddrs; |
6115 | 99 } ngx_stream_port_t; |
100 | |
101 | |
102 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
103 int family; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
104 int type; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
105 in_port_t port; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
106 ngx_array_t addrs; /* array of ngx_stream_conf_addr_t */ |
6115 | 107 } ngx_stream_conf_port_t; |
108 | |
109 | |
110 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
111 ngx_stream_listen_t opt; |
6115 | 112 } ngx_stream_conf_addr_t; |
113 | |
114 | |
6175 | 115 typedef ngx_int_t (*ngx_stream_access_pt)(ngx_stream_session_t *s); |
116 | |
117 | |
6115 | 118 typedef struct { |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
119 ngx_array_t servers; /* ngx_stream_core_srv_conf_t */ |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
120 ngx_array_t listen; /* ngx_stream_listen_t */ |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
121 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
122 ngx_stream_access_pt limit_conn_handler; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
123 ngx_stream_access_pt access_handler; |
6678 | 124 ngx_stream_access_pt access_log_handler; |
6607
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_t variables_hash; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
127 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
128 ngx_array_t variables; /* ngx_stream_variable_t */ |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
129 ngx_uint_t ncaptures; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
130 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
131 ngx_uint_t variables_hash_max_size; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
132 ngx_uint_t variables_hash_bucket_size; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
133 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
134 ngx_hash_keys_arrays_t *variables_keys; |
6115 | 135 } ngx_stream_core_main_conf_t; |
136 | |
137 | |
138 typedef void (*ngx_stream_handler_pt)(ngx_stream_session_t *s); | |
139 | |
140 | |
141 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
142 ngx_stream_handler_pt handler; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
143 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
144 ngx_stream_conf_ctx_t *ctx; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
145 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
146 u_char *file_name; |
6656
a2f57dfa65a9
Fixed wrong type of the "line" field.
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
147 ngx_uint_t line; |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
148 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
149 ngx_flag_t tcp_nodelay; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
150 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
151 ngx_log_t *error_log; |
6618 | 152 |
153 ngx_msec_t resolver_timeout; | |
154 ngx_resolver_t *resolver; | |
6657
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6656
diff
changeset
|
155 |
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6656
diff
changeset
|
156 ngx_uint_t listen; /* unsigned listen:1; */ |
6115 | 157 } ngx_stream_core_srv_conf_t; |
158 | |
159 | |
160 struct ngx_stream_session_s { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
161 uint32_t signature; /* "STRM" */ |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
162 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
163 ngx_connection_t *connection; |
6115 | 164 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
165 off_t received; |
6669
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6657
diff
changeset
|
166 time_t start_sec; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6657
diff
changeset
|
167 ngx_msec_t start_msec; |
6115 | 168 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
169 ngx_log_handler_pt log_handler; |
6115 | 170 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
171 void **ctx; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
172 void **main_conf; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
173 void **srv_conf; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
174 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
175 ngx_stream_upstream_t *upstream; |
6675
ab9b4fd8c5b7
Stream: the $upstream_addr variable.
Vladimir Homutov <vl@nginx.com>
parents:
6674
diff
changeset
|
176 ngx_array_t *upstream_states; |
ab9b4fd8c5b7
Stream: the $upstream_addr variable.
Vladimir Homutov <vl@nginx.com>
parents:
6674
diff
changeset
|
177 /* of ngx_stream_upstream_state_t */ |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
178 ngx_stream_variable_value_t *variables; |
6115 | 179 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
180 #if (NGX_PCRE) |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
181 ngx_uint_t ncaptures; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
182 int *captures; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
183 u_char *captures_data; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
184 #endif |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
185 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
186 ngx_uint_t status; |
6115 | 187 }; |
188 | |
189 | |
190 typedef struct { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
191 ngx_int_t (*preconfiguration)(ngx_conf_t *cf); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
192 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
|
193 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
194 void *(*create_main_conf)(ngx_conf_t *cf); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
195 char *(*init_main_conf)(ngx_conf_t *cf, void *conf); |
6115 | 196 |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
197 void *(*create_srv_conf)(ngx_conf_t *cf); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
198 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
199 void *conf); |
6115 | 200 } ngx_stream_module_t; |
201 | |
202 | |
203 #define NGX_STREAM_MODULE 0x4d525453 /* "STRM" */ | |
204 | |
205 #define NGX_STREAM_MAIN_CONF 0x02000000 | |
206 #define NGX_STREAM_SRV_CONF 0x04000000 | |
207 #define NGX_STREAM_UPS_CONF 0x08000000 | |
208 | |
209 | |
210 #define NGX_STREAM_MAIN_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, main_conf) | |
211 #define NGX_STREAM_SRV_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, srv_conf) | |
212 | |
213 | |
214 #define ngx_stream_get_module_ctx(s, module) (s)->ctx[module.ctx_index] | |
215 #define ngx_stream_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; | |
216 #define ngx_stream_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; | |
217 | |
218 | |
219 #define ngx_stream_get_module_main_conf(s, module) \ | |
220 (s)->main_conf[module.ctx_index] | |
221 #define ngx_stream_get_module_srv_conf(s, module) \ | |
222 (s)->srv_conf[module.ctx_index] | |
223 | |
224 #define ngx_stream_conf_get_module_main_conf(cf, module) \ | |
225 ((ngx_stream_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] | |
226 #define ngx_stream_conf_get_module_srv_conf(cf, module) \ | |
227 ((ngx_stream_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] | |
228 | |
229 #define ngx_stream_cycle_get_module_main_conf(cycle, module) \ | |
230 (cycle->conf_ctx[ngx_stream_module.index] ? \ | |
231 ((ngx_stream_conf_ctx_t *) cycle->conf_ctx[ngx_stream_module.index]) \ | |
232 ->main_conf[module.ctx_index]: \ | |
233 NULL) | |
234 | |
235 | |
236 void ngx_stream_init_connection(ngx_connection_t *c); | |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
237 void ngx_stream_finalize_session(ngx_stream_session_t *s, ngx_uint_t rc); |
6115 | 238 |
239 | |
240 extern ngx_module_t ngx_stream_module; | |
241 extern ngx_uint_t ngx_stream_max_module; | |
242 extern ngx_module_t ngx_stream_core_module; | |
243 | |
244 | |
245 #endif /* _NGX_STREAM_H_INCLUDED_ */ |