Mercurial > hg > nginx
annotate src/stream/ngx_stream_handler.c @ 6680:7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Tue, 06 Sep 2016 21:28:16 +0300 |
parents | 40e8ce405859 |
children | db422604ceb0 |
rev | line source |
---|---|
6115 | 1 |
2 /* | |
3 * Copyright (C) Roman Arutyunyan | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_event.h> | |
11 #include <ngx_stream.h> | |
12 | |
13 | |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
14 static void ngx_stream_close_connection(ngx_connection_t *c); |
6115 | 15 static u_char *ngx_stream_log_error(ngx_log_t *log, u_char *buf, size_t len); |
6680
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
16 static void ngx_stream_proxy_protocol_handler(ngx_event_t *rev); |
6679
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
17 static void ngx_stream_init_session_handler(ngx_event_t *rev); |
6115 | 18 static void ngx_stream_init_session(ngx_connection_t *c); |
19 | |
20 #if (NGX_STREAM_SSL) | |
21 static void ngx_stream_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c); | |
22 static void ngx_stream_ssl_handshake_handler(ngx_connection_t *c); | |
23 #endif | |
24 | |
25 | |
26 void | |
27 ngx_stream_init_connection(ngx_connection_t *c) | |
28 { | |
6175 | 29 u_char text[NGX_SOCKADDR_STRLEN]; |
30 size_t len; | |
31 ngx_uint_t i; | |
6669
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
32 ngx_time_t *tp; |
6679
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
33 ngx_event_t *rev; |
6175 | 34 struct sockaddr *sa; |
35 ngx_stream_port_t *port; | |
36 struct sockaddr_in *sin; | |
37 ngx_stream_in_addr_t *addr; | |
38 ngx_stream_session_t *s; | |
39 ngx_stream_addr_conf_t *addr_conf; | |
6115 | 40 #if (NGX_HAVE_INET6) |
6175 | 41 struct sockaddr_in6 *sin6; |
42 ngx_stream_in6_addr_t *addr6; | |
6115 | 43 #endif |
6175 | 44 ngx_stream_core_srv_conf_t *cscf; |
45 ngx_stream_core_main_conf_t *cmcf; | |
6115 | 46 |
47 /* find the server configuration for the address:port */ | |
48 | |
49 port = c->listening->servers; | |
50 | |
51 if (port->naddrs > 1) { | |
52 | |
53 /* | |
54 * There are several addresses on this port and one of them | |
55 * is the "*:port" wildcard so getsockname() is needed to determine | |
56 * the server address. | |
57 * | |
6436 | 58 * AcceptEx() and recvmsg() already gave this address. |
6115 | 59 */ |
60 | |
61 if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) { | |
62 ngx_stream_close_connection(c); | |
63 return; | |
64 } | |
65 | |
66 sa = c->local_sockaddr; | |
67 | |
68 switch (sa->sa_family) { | |
69 | |
70 #if (NGX_HAVE_INET6) | |
71 case AF_INET6: | |
72 sin6 = (struct sockaddr_in6 *) sa; | |
73 | |
74 addr6 = port->addrs; | |
75 | |
76 /* the last address is "*" */ | |
77 | |
78 for (i = 0; i < port->naddrs - 1; i++) { | |
79 if (ngx_memcmp(&addr6[i].addr6, &sin6->sin6_addr, 16) == 0) { | |
80 break; | |
81 } | |
82 } | |
83 | |
84 addr_conf = &addr6[i].conf; | |
85 | |
86 break; | |
87 #endif | |
88 | |
89 default: /* AF_INET */ | |
90 sin = (struct sockaddr_in *) sa; | |
91 | |
92 addr = port->addrs; | |
93 | |
94 /* the last address is "*" */ | |
95 | |
96 for (i = 0; i < port->naddrs - 1; i++) { | |
97 if (addr[i].addr == sin->sin_addr.s_addr) { | |
98 break; | |
99 } | |
100 } | |
101 | |
102 addr_conf = &addr[i].conf; | |
103 | |
104 break; | |
105 } | |
106 | |
107 } else { | |
108 switch (c->local_sockaddr->sa_family) { | |
109 | |
110 #if (NGX_HAVE_INET6) | |
111 case AF_INET6: | |
112 addr6 = port->addrs; | |
113 addr_conf = &addr6[0].conf; | |
114 break; | |
115 #endif | |
116 | |
117 default: /* AF_INET */ | |
118 addr = port->addrs; | |
119 addr_conf = &addr[0].conf; | |
120 break; | |
121 } | |
122 } | |
123 | |
124 s = ngx_pcalloc(c->pool, sizeof(ngx_stream_session_t)); | |
125 if (s == NULL) { | |
126 ngx_stream_close_connection(c); | |
127 return; | |
128 } | |
129 | |
130 s->signature = NGX_STREAM_MODULE; | |
131 s->main_conf = addr_conf->ctx->main_conf; | |
132 s->srv_conf = addr_conf->ctx->srv_conf; | |
133 | |
6679
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
134 #if (NGX_STREAM_SSL) |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
135 s->ssl = addr_conf->ssl; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
136 #endif |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
137 |
6115 | 138 s->connection = c; |
139 c->data = s; | |
140 | |
141 cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); | |
142 | |
6129
187aa751ad62
Core: the ngx_set_connection_log() macro.
Vladimir Homutov <vl@nginx.com>
parents:
6115
diff
changeset
|
143 ngx_set_connection_log(c, cscf->error_log); |
6115 | 144 |
145 len = ngx_sock_ntop(c->sockaddr, c->socklen, text, NGX_SOCKADDR_STRLEN, 1); | |
146 | |
6461
a01e315b3a78
Stream: additional logging for UDP.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
147 ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%uA %sclient %*s connected to %V", |
a01e315b3a78
Stream: additional logging for UDP.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
148 c->number, c->type == SOCK_DGRAM ? "udp " : "", |
a01e315b3a78
Stream: additional logging for UDP.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
149 len, text, &addr_conf->addr_text); |
6115 | 150 |
151 c->log->connection = c->number; | |
152 c->log->handler = ngx_stream_log_error; | |
153 c->log->data = s; | |
154 c->log->action = "initializing connection"; | |
155 c->log_error = NGX_ERROR_INFO; | |
156 | |
6175 | 157 cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module); |
158 | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6461
diff
changeset
|
159 s->variables = ngx_pcalloc(s->connection->pool, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6461
diff
changeset
|
160 cmcf->variables.nelts |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6461
diff
changeset
|
161 * sizeof(ngx_stream_variable_value_t)); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6461
diff
changeset
|
162 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6461
diff
changeset
|
163 if (s->variables == NULL) { |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6461
diff
changeset
|
164 ngx_stream_close_connection(c); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6461
diff
changeset
|
165 return; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6461
diff
changeset
|
166 } |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6461
diff
changeset
|
167 |
6669
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
168 tp = ngx_timeofday(); |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
169 s->start_sec = tp->sec; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
170 s->start_msec = tp->msec; |
164a0824ce20
Stream: the $session_time variable.
Vladimir Homutov <vl@nginx.com>
parents:
6607
diff
changeset
|
171 |
6679
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
172 rev = c->read; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
173 rev->handler = ngx_stream_init_session_handler; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
174 |
6680
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
175 if (addr_conf->proxy_protocol) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
176 c->log->action = "reading PROXY protocol"; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
177 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
178 rev->handler = ngx_stream_proxy_protocol_handler; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
179 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
180 if (!rev->ready) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
181 ngx_add_timer(rev, cscf->proxy_protocol_timeout); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
182 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
183 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
184 ngx_stream_finalize_session(s, |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
185 NGX_STREAM_INTERNAL_SERVER_ERROR); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
186 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
187 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
188 return; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
189 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
190 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
191 |
6679
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
192 if (ngx_use_accept_mutex) { |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
193 ngx_post_event(rev, &ngx_posted_events); |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
194 return; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
195 } |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
196 |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
197 rev->handler(rev); |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
198 } |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
199 |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
200 |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
201 static void |
6680
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
202 ngx_stream_proxy_protocol_handler(ngx_event_t *rev) |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
203 { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
204 u_char *p, buf[NGX_PROXY_PROTOCOL_MAX_HEADER]; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
205 size_t size; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
206 ssize_t n; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
207 ngx_err_t err; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
208 ngx_connection_t *c; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
209 ngx_stream_session_t *s; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
210 ngx_stream_core_srv_conf_t *cscf; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
211 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
212 c = rev->data; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
213 s = c->data; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
214 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
215 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
216 "stream PROXY protocol handler"); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
217 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
218 if (rev->timedout) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
219 ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
220 ngx_stream_finalize_session(s, NGX_STREAM_OK); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
221 return; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
222 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
223 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
224 n = recv(c->fd, (char *) buf, sizeof(buf), MSG_PEEK); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
225 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
226 err = ngx_socket_errno; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
227 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
228 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "recv(): %z", n); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
229 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
230 if (n == -1) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
231 if (err == NGX_EAGAIN) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
232 rev->ready = 0; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
233 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
234 if (!rev->timer_set) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
235 cscf = ngx_stream_get_module_srv_conf(s, |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
236 ngx_stream_core_module); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
237 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
238 ngx_add_timer(rev, cscf->proxy_protocol_timeout); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
239 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
240 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
241 if (ngx_handle_read_event(rev, 0) != NGX_OK) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
242 ngx_stream_finalize_session(s, |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
243 NGX_STREAM_INTERNAL_SERVER_ERROR); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
244 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
245 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
246 return; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
247 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
248 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
249 ngx_connection_error(c, err, "recv() failed"); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
250 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
251 ngx_stream_finalize_session(s, NGX_STREAM_OK); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
252 return; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
253 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
254 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
255 if (rev->timer_set) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
256 ngx_del_timer(rev); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
257 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
258 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
259 p = ngx_proxy_protocol_read(c, buf, buf + n); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
260 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
261 if (p == NULL) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
262 ngx_stream_finalize_session(s, NGX_STREAM_BAD_REQUEST); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
263 return; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
264 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
265 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
266 size = p - buf; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
267 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
268 if (c->recv(c, buf, size) != (ssize_t) size) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
269 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
270 return; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
271 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
272 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
273 ngx_stream_init_session_handler(rev); |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
274 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
275 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
276 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6679
diff
changeset
|
277 static void |
6679
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
278 ngx_stream_init_session_handler(ngx_event_t *rev) |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
279 { |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
280 int tcp_nodelay; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
281 ngx_int_t rc; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
282 ngx_connection_t *c; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
283 ngx_stream_session_t *s; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
284 ngx_stream_core_srv_conf_t *cscf; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
285 ngx_stream_core_main_conf_t *cmcf; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
286 |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
287 c = rev->data; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
288 s = c->data; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
289 |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
290 c->log->action = "initializing session"; |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
291 |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
292 cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module); |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
293 |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
6175
diff
changeset
|
294 if (cmcf->limit_conn_handler) { |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
6175
diff
changeset
|
295 rc = cmcf->limit_conn_handler(s); |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
6175
diff
changeset
|
296 |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
297 if (rc == NGX_ERROR) { |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
298 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
299 return; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
300 } |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
301 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
302 if (rc == NGX_ABORT) { |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
303 ngx_stream_finalize_session(s, NGX_STREAM_SERVICE_UNAVAILABLE); |
6197
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
6175
diff
changeset
|
304 return; |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
6175
diff
changeset
|
305 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
6175
diff
changeset
|
306 } |
0dcef374b8bb
Stream: connection limiting module.
Vladimir Homutov <vl@nginx.com>
parents:
6175
diff
changeset
|
307 |
6175 | 308 if (cmcf->access_handler) { |
309 rc = cmcf->access_handler(s); | |
310 | |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
311 if (rc == NGX_ERROR) { |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
312 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
313 return; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
314 } |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
315 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
316 if (rc == NGX_ABORT) { |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
317 ngx_stream_finalize_session(s, NGX_STREAM_FORBIDDEN); |
6175 | 318 return; |
319 } | |
320 } | |
321 | |
6679
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
322 cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); |
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
323 |
6436 | 324 if (c->type == SOCK_STREAM |
325 && cscf->tcp_nodelay | |
326 && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) | |
327 { | |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
328 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, "tcp_nodelay"); |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
329 |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
330 tcp_nodelay = 1; |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
331 |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
332 if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY, |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
333 (const void *) &tcp_nodelay, sizeof(int)) == -1) |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
334 { |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
335 ngx_connection_error(c, ngx_socket_errno, |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
336 "setsockopt(TCP_NODELAY) failed"); |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
337 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
338 return; |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
339 } |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
340 |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
341 c->tcp_nodelay = NGX_TCP_NODELAY_SET; |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
342 } |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
343 |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6197
diff
changeset
|
344 |
6115 | 345 #if (NGX_STREAM_SSL) |
346 { | |
347 ngx_stream_ssl_conf_t *sslcf; | |
348 | |
349 sslcf = ngx_stream_get_module_srv_conf(s, ngx_stream_ssl_module); | |
350 | |
6679
40e8ce405859
Stream: postpone session initialization under accept mutex.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6678
diff
changeset
|
351 if (s->ssl) { |
6115 | 352 c->log->action = "SSL handshaking"; |
353 | |
354 if (sslcf->ssl.ctx == NULL) { | |
355 ngx_log_error(NGX_LOG_ERR, c->log, 0, | |
356 "no \"ssl_certificate\" is defined " | |
357 "in server listening on SSL port"); | |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
358 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); |
6115 | 359 return; |
360 } | |
361 | |
362 ngx_stream_ssl_init_connection(&sslcf->ssl, c); | |
363 return; | |
364 } | |
365 } | |
366 #endif | |
367 | |
368 ngx_stream_init_session(c); | |
369 } | |
370 | |
371 | |
372 static void | |
373 ngx_stream_init_session(ngx_connection_t *c) | |
374 { | |
375 ngx_stream_session_t *s; | |
376 ngx_stream_core_srv_conf_t *cscf; | |
377 | |
378 s = c->data; | |
379 c->log->action = "handling client connection"; | |
380 | |
381 cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); | |
382 | |
383 s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_stream_max_module); | |
384 if (s->ctx == NULL) { | |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
385 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); |
6115 | 386 return; |
387 } | |
388 | |
389 cscf->handler(s); | |
390 } | |
391 | |
392 | |
393 #if (NGX_STREAM_SSL) | |
394 | |
395 static void | |
396 ngx_stream_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c) | |
397 { | |
398 ngx_stream_session_t *s; | |
399 ngx_stream_ssl_conf_t *sslcf; | |
400 | |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
401 s = c->data; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
402 |
6115 | 403 if (ngx_ssl_create_connection(ssl, c, 0) == NGX_ERROR) { |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
404 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); |
6115 | 405 return; |
406 } | |
407 | |
408 if (ngx_ssl_handshake(c) == NGX_AGAIN) { | |
409 sslcf = ngx_stream_get_module_srv_conf(s, ngx_stream_ssl_module); | |
410 | |
411 ngx_add_timer(c->read, sslcf->handshake_timeout); | |
412 | |
413 c->ssl->handler = ngx_stream_ssl_handshake_handler; | |
414 | |
415 return; | |
416 } | |
417 | |
418 ngx_stream_ssl_handshake_handler(c); | |
419 } | |
420 | |
421 | |
422 static void | |
423 ngx_stream_ssl_handshake_handler(ngx_connection_t *c) | |
424 { | |
425 if (!c->ssl->handshaked) { | |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
426 ngx_stream_finalize_session(c->data, NGX_STREAM_INTERNAL_SERVER_ERROR); |
6115 | 427 return; |
428 } | |
429 | |
430 if (c->read->timer_set) { | |
431 ngx_del_timer(c->read); | |
432 } | |
433 | |
434 ngx_stream_init_session(c); | |
435 } | |
436 | |
437 #endif | |
438 | |
439 | |
440 void | |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
441 ngx_stream_finalize_session(ngx_stream_session_t *s, ngx_uint_t rc) |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
442 { |
6678 | 443 ngx_stream_core_main_conf_t *cmcf; |
444 | |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
445 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
446 "finalize stream session: %i", rc); |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
447 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
448 s->status = rc; |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
449 |
6678 | 450 cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module); |
451 | |
452 if (cmcf->access_log_handler) { | |
453 (void) cmcf->access_log_handler(s); | |
454 } | |
455 | |
6674
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
456 ngx_stream_close_connection(s->connection); |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
457 } |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
458 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
459 |
38143d1abdec
Stream: the $status variable.
Roman Arutyunyan <arut@nginx.com>
parents:
6669
diff
changeset
|
460 static void |
6115 | 461 ngx_stream_close_connection(ngx_connection_t *c) |
462 { | |
463 ngx_pool_t *pool; | |
464 | |
465 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, | |
466 "close stream connection: %d", c->fd); | |
467 | |
468 #if (NGX_STREAM_SSL) | |
469 | |
470 if (c->ssl) { | |
471 if (ngx_ssl_shutdown(c) == NGX_AGAIN) { | |
472 c->ssl->handler = ngx_stream_close_connection; | |
473 return; | |
474 } | |
475 } | |
476 | |
477 #endif | |
478 | |
479 #if (NGX_STAT_STUB) | |
480 (void) ngx_atomic_fetch_add(ngx_stat_active, -1); | |
481 #endif | |
482 | |
483 pool = c->pool; | |
484 | |
485 ngx_close_connection(c); | |
486 | |
487 ngx_destroy_pool(pool); | |
488 } | |
489 | |
490 | |
491 static u_char * | |
492 ngx_stream_log_error(ngx_log_t *log, u_char *buf, size_t len) | |
493 { | |
494 u_char *p; | |
495 ngx_stream_session_t *s; | |
496 | |
497 if (log->action) { | |
498 p = ngx_snprintf(buf, len, " while %s", log->action); | |
499 len -= p - buf; | |
500 buf = p; | |
501 } | |
502 | |
503 s = log->data; | |
504 | |
6461
a01e315b3a78
Stream: additional logging for UDP.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
505 p = ngx_snprintf(buf, len, ", %sclient: %V, server: %V", |
a01e315b3a78
Stream: additional logging for UDP.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
506 s->connection->type == SOCK_DGRAM ? "udp " : "", |
6115 | 507 &s->connection->addr_text, |
508 &s->connection->listening->addr_text); | |
6223
d1f94042c29c
Stream: fixed potential error log buffer overrun.
Vladimir Homutov <vl@nginx.com>
parents:
6221
diff
changeset
|
509 len -= p - buf; |
d1f94042c29c
Stream: fixed potential error log buffer overrun.
Vladimir Homutov <vl@nginx.com>
parents:
6221
diff
changeset
|
510 buf = p; |
6115 | 511 |
512 if (s->log_handler) { | |
6223
d1f94042c29c
Stream: fixed potential error log buffer overrun.
Vladimir Homutov <vl@nginx.com>
parents:
6221
diff
changeset
|
513 p = s->log_handler(log, buf, len); |
6115 | 514 } |
515 | |
516 return p; | |
517 } |