Mercurial > hg > nginx-quic
annotate src/stream/ngx_stream.h @ 6557:6f8254ae61b8
Use ngx_cmp_sockaddr() where appropriate.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Fri, 20 May 2016 19:10:42 +0300 |
parents | 8f038068f4bc |
children | adf25b8d0431 |
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 | |
23 #include <ngx_stream_upstream.h> | |
24 #include <ngx_stream_upstream_round_robin.h> | |
25 | |
26 | |
27 typedef struct { | |
28 void **main_conf; | |
29 void **srv_conf; | |
30 } ngx_stream_conf_ctx_t; | |
31 | |
32 | |
33 typedef struct { | |
6170
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
34 union { |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
35 struct sockaddr sockaddr; |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
36 struct sockaddr_in sockaddr_in; |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
37 #if (NGX_HAVE_INET6) |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
38 struct sockaddr_in6 sockaddr_in6; |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
39 #endif |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
40 #if (NGX_HAVE_UNIX_DOMAIN) |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
41 struct sockaddr_un sockaddr_un; |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
42 #endif |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
43 } u; |
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
44 |
6115 | 45 socklen_t socklen; |
46 | |
47 /* server ctx */ | |
48 ngx_stream_conf_ctx_t *ctx; | |
49 | |
50 unsigned bind:1; | |
51 unsigned wildcard:1; | |
52 #if (NGX_STREAM_SSL) | |
53 unsigned ssl:1; | |
54 #endif | |
55 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | |
56 unsigned ipv6only:1; | |
57 #endif | |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
58 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
59 unsigned reuseport:1; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6129
diff
changeset
|
60 #endif |
6115 | 61 unsigned so_keepalive:2; |
62 #if (NGX_HAVE_KEEPALIVE_TUNABLE) | |
63 int tcp_keepidle; | |
64 int tcp_keepintvl; | |
65 int tcp_keepcnt; | |
66 #endif | |
6172 | 67 int backlog; |
6436 | 68 int type; |
6115 | 69 } ngx_stream_listen_t; |
70 | |
71 | |
72 typedef struct { | |
73 ngx_stream_conf_ctx_t *ctx; | |
74 ngx_str_t addr_text; | |
75 #if (NGX_STREAM_SSL) | |
76 ngx_uint_t ssl; /* unsigned ssl:1; */ | |
77 #endif | |
78 } ngx_stream_addr_conf_t; | |
79 | |
80 typedef struct { | |
81 in_addr_t addr; | |
82 ngx_stream_addr_conf_t conf; | |
83 } ngx_stream_in_addr_t; | |
84 | |
85 | |
86 #if (NGX_HAVE_INET6) | |
87 | |
88 typedef struct { | |
89 struct in6_addr addr6; | |
90 ngx_stream_addr_conf_t conf; | |
91 } ngx_stream_in6_addr_t; | |
92 | |
93 #endif | |
94 | |
95 | |
96 typedef struct { | |
97 /* ngx_stream_in_addr_t or ngx_stream_in6_addr_t */ | |
98 void *addrs; | |
99 ngx_uint_t naddrs; | |
100 } ngx_stream_port_t; | |
101 | |
102 | |
103 typedef struct { | |
104 int family; | |
6436 | 105 int type; |
6115 | 106 in_port_t port; |
107 ngx_array_t addrs; /* array of ngx_stream_conf_addr_t */ | |
108 } ngx_stream_conf_port_t; | |
109 | |
110 | |
111 typedef struct { | |
6170
c13091e6292c
Stream: embed ngx_stream_listen_t into ngx_stream_conf_addr_t.
Ruslan Ermilov <ru@nginx.com>
parents:
6169
diff
changeset
|
112 ngx_stream_listen_t opt; |
6115 | 113 } ngx_stream_conf_addr_t; |
114 | |
115 | |
6175 | 116 typedef ngx_int_t (*ngx_stream_access_pt)(ngx_stream_session_t *s); |
117 | |
118 | |
6115 | 119 typedef struct { |
120 ngx_array_t servers; /* ngx_stream_core_srv_conf_t */ | |
121 ngx_array_t listen; /* ngx_stream_listen_t */ | |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
6175
diff
changeset
|
122 ngx_stream_access_pt limit_conn_handler; |
6175 | 123 ngx_stream_access_pt access_handler; |
6115 | 124 } ngx_stream_core_main_conf_t; |
125 | |
126 | |
127 typedef void (*ngx_stream_handler_pt)(ngx_stream_session_t *s); | |
128 | |
129 | |
130 typedef struct { | |
131 ngx_stream_handler_pt handler; | |
132 ngx_stream_conf_ctx_t *ctx; | |
133 u_char *file_name; | |
134 ngx_int_t line; | |
135 ngx_log_t *error_log; | |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
136 ngx_flag_t tcp_nodelay; |
6115 | 137 } ngx_stream_core_srv_conf_t; |
138 | |
139 | |
140 struct ngx_stream_session_s { | |
141 uint32_t signature; /* "STRM" */ | |
142 | |
143 ngx_connection_t *connection; | |
144 | |
145 off_t received; | |
146 | |
147 ngx_log_handler_pt log_handler; | |
148 | |
149 void **ctx; | |
150 void **main_conf; | |
151 void **srv_conf; | |
152 | |
153 ngx_stream_upstream_t *upstream; | |
154 }; | |
155 | |
156 | |
157 typedef struct { | |
6174
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6172
diff
changeset
|
158 ngx_int_t (*postconfiguration)(ngx_conf_t *cf); |
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6172
diff
changeset
|
159 |
6115 | 160 void *(*create_main_conf)(ngx_conf_t *cf); |
161 char *(*init_main_conf)(ngx_conf_t *cf, void *conf); | |
162 | |
163 void *(*create_srv_conf)(ngx_conf_t *cf); | |
164 char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev, | |
165 void *conf); | |
166 } ngx_stream_module_t; | |
167 | |
168 | |
169 #define NGX_STREAM_MODULE 0x4d525453 /* "STRM" */ | |
170 | |
171 #define NGX_STREAM_MAIN_CONF 0x02000000 | |
172 #define NGX_STREAM_SRV_CONF 0x04000000 | |
173 #define NGX_STREAM_UPS_CONF 0x08000000 | |
174 | |
175 | |
176 #define NGX_STREAM_MAIN_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, main_conf) | |
177 #define NGX_STREAM_SRV_CONF_OFFSET offsetof(ngx_stream_conf_ctx_t, srv_conf) | |
178 | |
179 | |
180 #define ngx_stream_get_module_ctx(s, module) (s)->ctx[module.ctx_index] | |
181 #define ngx_stream_set_ctx(s, c, module) s->ctx[module.ctx_index] = c; | |
182 #define ngx_stream_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL; | |
183 | |
184 | |
185 #define ngx_stream_get_module_main_conf(s, module) \ | |
186 (s)->main_conf[module.ctx_index] | |
187 #define ngx_stream_get_module_srv_conf(s, module) \ | |
188 (s)->srv_conf[module.ctx_index] | |
189 | |
190 #define ngx_stream_conf_get_module_main_conf(cf, module) \ | |
191 ((ngx_stream_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index] | |
192 #define ngx_stream_conf_get_module_srv_conf(cf, module) \ | |
193 ((ngx_stream_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index] | |
194 | |
195 #define ngx_stream_cycle_get_module_main_conf(cycle, module) \ | |
196 (cycle->conf_ctx[ngx_stream_module.index] ? \ | |
197 ((ngx_stream_conf_ctx_t *) cycle->conf_ctx[ngx_stream_module.index]) \ | |
198 ->main_conf[module.ctx_index]: \ | |
199 NULL) | |
200 | |
201 | |
202 void ngx_stream_init_connection(ngx_connection_t *c); | |
203 void ngx_stream_close_connection(ngx_connection_t *c); | |
204 | |
205 | |
206 extern ngx_module_t ngx_stream_module; | |
207 extern ngx_uint_t ngx_stream_max_module; | |
208 extern ngx_module_t ngx_stream_core_module; | |
209 | |
210 | |
211 #endif /* _NGX_STREAM_H_INCLUDED_ */ |