annotate src/stream/ngx_stream_proxy_module.c @ 6258:4b4aee40c508

Stream: delete proxy connection timer after SSL handshake. The timer remained active and could drop active SSL connection.
author Ruslan Ermilov <ru@nginx.com>
date Tue, 06 Oct 2015 08:57:09 +0300
parents 2a621245f4cf
children 4eb1b5c6d9c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
2 /*
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
3 * Copyright (C) Roman Arutyunyan
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
4 * Copyright (C) Nginx, Inc.
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
5 */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
6
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
7
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
8 #include <ngx_config.h>
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
9 #include <ngx_core.h>
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
10 #include <ngx_stream.h>
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
11
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
12
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
13 typedef void (*ngx_stream_proxy_handler_pt)(ngx_stream_session_t *s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
14
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
15
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
16 typedef struct {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
17 ngx_msec_t connect_timeout;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
18 ngx_msec_t timeout;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
19 ngx_msec_t next_upstream_timeout;
6215
8ee6a08ea3eb Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents: 6208
diff changeset
20 size_t buffer_size;
6208
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
21 size_t upload_rate;
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
22 size_t download_rate;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
23 ngx_uint_t next_upstream_tries;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
24 ngx_flag_t next_upstream;
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
25 ngx_flag_t proxy_protocol;
6183
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
26 ngx_addr_t *local;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
27
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
28 #if (NGX_STREAM_SSL)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
29 ngx_flag_t ssl_enable;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
30 ngx_flag_t ssl_session_reuse;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
31 ngx_uint_t ssl_protocols;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
32 ngx_str_t ssl_ciphers;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
33 ngx_str_t ssl_name;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
34 ngx_flag_t ssl_server_name;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
35
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
36 ngx_flag_t ssl_verify;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
37 ngx_uint_t ssl_verify_depth;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
38 ngx_str_t ssl_trusted_certificate;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
39 ngx_str_t ssl_crl;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
40 ngx_str_t ssl_certificate;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
41 ngx_str_t ssl_certificate_key;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
42 ngx_array_t *ssl_passwords;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
43
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
44 ngx_ssl_t *ssl;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
45 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
46
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
47 ngx_stream_upstream_srv_conf_t *upstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
48 } ngx_stream_proxy_srv_conf_t;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
49
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
50
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
51 static void ngx_stream_proxy_handler(ngx_stream_session_t *s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
52 static void ngx_stream_proxy_connect(ngx_stream_session_t *s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
53 static void ngx_stream_proxy_init_upstream(ngx_stream_session_t *s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
54 static void ngx_stream_proxy_upstream_handler(ngx_event_t *ev);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
55 static void ngx_stream_proxy_downstream_handler(ngx_event_t *ev);
6200
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
56 static void ngx_stream_proxy_process_connection(ngx_event_t *ev,
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
57 ngx_uint_t from_upstream);
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
58 static void ngx_stream_proxy_connect_handler(ngx_event_t *ev);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
59 static ngx_int_t ngx_stream_proxy_test_connect(ngx_connection_t *c);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
60 static ngx_int_t ngx_stream_proxy_process(ngx_stream_session_t *s,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
61 ngx_uint_t from_upstream, ngx_uint_t do_write);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
62 static void ngx_stream_proxy_next_upstream(ngx_stream_session_t *s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
63 static void ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_int_t rc);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
64 static u_char *ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
65 size_t len);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
66
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
67 static void *ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
68 static char *ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
69 void *child);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
70 static char *ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
71 void *conf);
6183
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
72 static char *ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd,
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
73 void *conf);
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
74 static ngx_int_t ngx_stream_proxy_send_proxy_protocol(ngx_stream_session_t *s);
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
75
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
76 #if (NGX_STREAM_SSL)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
77
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
78 static char *ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
79 ngx_command_t *cmd, void *conf);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
80 static void ngx_stream_proxy_ssl_init_connection(ngx_stream_session_t *s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
81 static void ngx_stream_proxy_ssl_handshake(ngx_connection_t *pc);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
82 static ngx_int_t ngx_stream_proxy_ssl_name(ngx_stream_session_t *s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
83 static ngx_int_t ngx_stream_proxy_set_ssl(ngx_conf_t *cf,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
84 ngx_stream_proxy_srv_conf_t *pscf);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
85
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
86
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
87 static ngx_conf_bitmask_t ngx_stream_proxy_ssl_protocols[] = {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
88 { ngx_string("SSLv2"), NGX_SSL_SSLv2 },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
89 { ngx_string("SSLv3"), NGX_SSL_SSLv3 },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
90 { ngx_string("TLSv1"), NGX_SSL_TLSv1 },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
91 { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
92 { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
93 { ngx_null_string, 0 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
94 };
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
95
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
96 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
97
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
98
6217
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
99 static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_downstream_buffer = {
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
100 ngx_conf_deprecated, "proxy_downstream_buffer", "proxy_buffer_size"
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
101 };
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
102
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
103 static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_upstream_buffer = {
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
104 ngx_conf_deprecated, "proxy_upstream_buffer", "proxy_buffer_size"
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
105 };
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
106
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
107
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
108 static ngx_command_t ngx_stream_proxy_commands[] = {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
109
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
110 { ngx_string("proxy_pass"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
111 NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
112 ngx_stream_proxy_pass,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
113 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
114 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
115 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
116
6183
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
117 { ngx_string("proxy_bind"),
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
118 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
119 ngx_stream_proxy_bind,
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
120 NGX_STREAM_SRV_CONF_OFFSET,
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
121 0,
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
122 NULL },
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
123
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
124 { ngx_string("proxy_connect_timeout"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
125 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
126 ngx_conf_set_msec_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
127 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
128 offsetof(ngx_stream_proxy_srv_conf_t, connect_timeout),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
129 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
130
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
131 { ngx_string("proxy_timeout"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
132 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
133 ngx_conf_set_msec_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
134 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
135 offsetof(ngx_stream_proxy_srv_conf_t, timeout),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
136 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
137
6215
8ee6a08ea3eb Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents: 6208
diff changeset
138 { ngx_string("proxy_buffer_size"),
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
139 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
140 ngx_conf_set_size_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
141 NGX_STREAM_SRV_CONF_OFFSET,
6215
8ee6a08ea3eb Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents: 6208
diff changeset
142 offsetof(ngx_stream_proxy_srv_conf_t, buffer_size),
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
143 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
144
6217
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
145 { ngx_string("proxy_downstream_buffer"),
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
146 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
147 ngx_conf_set_size_slot,
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
148 NGX_STREAM_SRV_CONF_OFFSET,
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
149 offsetof(ngx_stream_proxy_srv_conf_t, buffer_size),
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
150 &ngx_conf_deprecated_proxy_downstream_buffer },
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
151
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
152 { ngx_string("proxy_upstream_buffer"),
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
153 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
154 ngx_conf_set_size_slot,
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
155 NGX_STREAM_SRV_CONF_OFFSET,
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
156 offsetof(ngx_stream_proxy_srv_conf_t, buffer_size),
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
157 &ngx_conf_deprecated_proxy_upstream_buffer },
b544f8e0d921 Stream: deprecated proxy_downstream_buffer, proxy_upstream_buffer.
Roman Arutyunyan <arut@nginx.com>
parents: 6216
diff changeset
158
6208
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
159 { ngx_string("proxy_upload_rate"),
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
160 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
161 ngx_conf_set_size_slot,
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
162 NGX_STREAM_SRV_CONF_OFFSET,
6208
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
163 offsetof(ngx_stream_proxy_srv_conf_t, upload_rate),
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
164 NULL },
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
165
6208
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
166 { ngx_string("proxy_download_rate"),
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
167 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
168 ngx_conf_set_size_slot,
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
169 NGX_STREAM_SRV_CONF_OFFSET,
6208
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
170 offsetof(ngx_stream_proxy_srv_conf_t, download_rate),
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
171 NULL },
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
172
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
173 { ngx_string("proxy_next_upstream"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
174 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
175 ngx_conf_set_flag_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
176 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
177 offsetof(ngx_stream_proxy_srv_conf_t, next_upstream),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
178 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
179
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
180 { ngx_string("proxy_next_upstream_tries"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
181 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
182 ngx_conf_set_num_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
183 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
184 offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_tries),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
185 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
186
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
187 { ngx_string("proxy_next_upstream_timeout"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
188 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
189 ngx_conf_set_msec_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
190 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
191 offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_timeout),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
192 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
193
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
194 { ngx_string("proxy_protocol"),
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
195 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
196 ngx_conf_set_flag_slot,
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
197 NGX_STREAM_SRV_CONF_OFFSET,
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
198 offsetof(ngx_stream_proxy_srv_conf_t, proxy_protocol),
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
199 NULL },
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
200
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
201 #if (NGX_STREAM_SSL)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
202
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
203 { ngx_string("proxy_ssl"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
204 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
205 ngx_conf_set_flag_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
206 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
207 offsetof(ngx_stream_proxy_srv_conf_t, ssl_enable),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
208 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
209
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
210 { ngx_string("proxy_ssl_session_reuse"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
211 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
212 ngx_conf_set_flag_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
213 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
214 offsetof(ngx_stream_proxy_srv_conf_t, ssl_session_reuse),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
215 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
216
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
217 { ngx_string("proxy_ssl_protocols"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
218 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
219 ngx_conf_set_bitmask_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
220 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
221 offsetof(ngx_stream_proxy_srv_conf_t, ssl_protocols),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
222 &ngx_stream_proxy_ssl_protocols },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
223
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
224 { ngx_string("proxy_ssl_ciphers"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
225 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
226 ngx_conf_set_str_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
227 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
228 offsetof(ngx_stream_proxy_srv_conf_t, ssl_ciphers),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
229 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
230
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
231 { ngx_string("proxy_ssl_name"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
232 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
233 ngx_conf_set_str_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
234 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
235 offsetof(ngx_stream_proxy_srv_conf_t, ssl_name),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
236 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
237
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
238 { ngx_string("proxy_ssl_server_name"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
239 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
240 ngx_conf_set_flag_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
241 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
242 offsetof(ngx_stream_proxy_srv_conf_t, ssl_server_name),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
243 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
244
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
245 { ngx_string("proxy_ssl_verify"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
246 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
247 ngx_conf_set_flag_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
248 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
249 offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
250 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
251
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
252 { ngx_string("proxy_ssl_verify_depth"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
253 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
254 ngx_conf_set_num_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
255 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
256 offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify_depth),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
257 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
258
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
259 { ngx_string("proxy_ssl_trusted_certificate"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
260 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
261 ngx_conf_set_str_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
262 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
263 offsetof(ngx_stream_proxy_srv_conf_t, ssl_trusted_certificate),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
264 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
265
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
266 { ngx_string("proxy_ssl_crl"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
267 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
268 ngx_conf_set_str_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
269 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
270 offsetof(ngx_stream_proxy_srv_conf_t, ssl_crl),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
271 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
272
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
273 { ngx_string("proxy_ssl_certificate"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
274 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
275 ngx_conf_set_str_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
276 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
277 offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
278 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
279
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
280 { ngx_string("proxy_ssl_certificate_key"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
281 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
282 ngx_conf_set_str_slot,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
283 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
284 offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate_key),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
285 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
286
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
287 { ngx_string("proxy_ssl_password_file"),
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
288 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
289 ngx_stream_proxy_ssl_password_file,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
290 NGX_STREAM_SRV_CONF_OFFSET,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
291 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
292 NULL },
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
293
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
294 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
295
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
296 ngx_null_command
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
297 };
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
298
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
299
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
300 static ngx_stream_module_t ngx_stream_proxy_module_ctx = {
6174
68c106e6fa0a Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents: 6157
diff changeset
301 NULL, /* postconfiguration */
68c106e6fa0a Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents: 6157
diff changeset
302
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
303 NULL, /* create main configuration */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
304 NULL, /* init main configuration */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
305
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
306 ngx_stream_proxy_create_srv_conf, /* create server configuration */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
307 ngx_stream_proxy_merge_srv_conf /* merge server configuration */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
308 };
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
309
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
310
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
311 ngx_module_t ngx_stream_proxy_module = {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
312 NGX_MODULE_V1,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
313 &ngx_stream_proxy_module_ctx, /* module context */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
314 ngx_stream_proxy_commands, /* module directives */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
315 NGX_STREAM_MODULE, /* module type */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
316 NULL, /* init master */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
317 NULL, /* init module */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
318 NULL, /* init process */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
319 NULL, /* init thread */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
320 NULL, /* exit thread */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
321 NULL, /* exit process */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
322 NULL, /* exit master */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
323 NGX_MODULE_V1_PADDING
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
324 };
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
325
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
326
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
327 static void
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
328 ngx_stream_proxy_handler(ngx_stream_session_t *s)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
329 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
330 u_char *p;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
331 ngx_connection_t *c;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
332 ngx_stream_upstream_t *u;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
333 ngx_stream_proxy_srv_conf_t *pscf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
334 ngx_stream_upstream_srv_conf_t *uscf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
335
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
336 c = s->connection;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
337
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
338 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
339
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
340 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
341 "proxy connection handler");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
342
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
343 u = ngx_pcalloc(c->pool, sizeof(ngx_stream_upstream_t));
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
344 if (u == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
345 ngx_stream_proxy_finalize(s, NGX_ERROR);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
346 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
347 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
348
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
349 s->upstream = u;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
350
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
351 s->log_handler = ngx_stream_proxy_log_error;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
352
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
353 u->peer.log = c->log;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
354 u->peer.log_error = NGX_ERROR_ERR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
355
6183
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
356 u->peer.local = pscf->local;
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
357
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
358 uscf = pscf->upstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
359
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
360 if (uscf->peer.init(s, uscf) != NGX_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
361 ngx_stream_proxy_finalize(s, NGX_ERROR);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
362 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
363 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
364
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
365 u->peer.start_time = ngx_current_msec;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
366
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
367 if (pscf->next_upstream_tries
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
368 && u->peer.tries > pscf->next_upstream_tries)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
369 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
370 u->peer.tries = pscf->next_upstream_tries;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
371 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
372
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
373 u->proxy_protocol = pscf->proxy_protocol;
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
374 u->start_sec = ngx_time();
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
375
6215
8ee6a08ea3eb Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents: 6208
diff changeset
376 p = ngx_pnalloc(c->pool, pscf->buffer_size);
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
377 if (p == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
378 ngx_stream_proxy_finalize(s, NGX_ERROR);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
379 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
380 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
381
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
382 u->downstream_buf.start = p;
6215
8ee6a08ea3eb Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents: 6208
diff changeset
383 u->downstream_buf.end = p + pscf->buffer_size;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
384 u->downstream_buf.pos = p;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
385 u->downstream_buf.last = p;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
386
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
387 c->write->handler = ngx_stream_proxy_downstream_handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
388 c->read->handler = ngx_stream_proxy_downstream_handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
389
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
390 if (u->proxy_protocol
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
391 #if (NGX_STREAM_SSL)
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
392 && pscf->ssl == NULL
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
393 #endif
6216
Roman Arutyunyan <arut@nginx.com>
parents: 6215
diff changeset
394 && pscf->buffer_size >= NGX_PROXY_PROTOCOL_MAX_HEADER)
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
395 {
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
396 /* optimization for a typical case */
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
397
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
398 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0,
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
399 "stream proxy send PROXY protocol header");
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
400
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
401 p = ngx_proxy_protocol_write(c, u->downstream_buf.last,
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
402 u->downstream_buf.end);
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
403 if (p == NULL) {
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
404 ngx_stream_proxy_finalize(s, NGX_ERROR);
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
405 return;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
406 }
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
407
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
408 u->downstream_buf.last = p;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
409 u->proxy_protocol = 0;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
410 }
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
411
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
412 if (ngx_stream_proxy_process(s, 0, 0) != NGX_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
413 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
414 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
415
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
416 ngx_stream_proxy_connect(s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
417 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
418
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
419
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
420 static void
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
421 ngx_stream_proxy_connect(ngx_stream_session_t *s)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
422 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
423 ngx_int_t rc;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
424 ngx_connection_t *c, *pc;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
425 ngx_stream_upstream_t *u;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
426 ngx_stream_proxy_srv_conf_t *pscf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
427
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
428 c = s->connection;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
429
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
430 c->log->action = "connecting to upstream";
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
431
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
432 u = s->upstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
433
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
434 rc = ngx_event_connect_peer(&u->peer);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
435
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
436 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
437
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
438 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
439
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
440 if (rc == NGX_ERROR) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
441 ngx_stream_proxy_finalize(s, NGX_ERROR);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
442 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
443 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
444
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
445 if (rc == NGX_BUSY) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
446 ngx_log_error(NGX_LOG_ERR, c->log, 0, "no live upstreams");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
447 ngx_stream_proxy_finalize(s, NGX_DECLINED);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
448 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
449 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
450
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
451 if (rc == NGX_DECLINED) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
452 ngx_stream_proxy_next_upstream(s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
453 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
454 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
455
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
456 /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
457
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
458 pc = u->peer.connection;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
459
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
460 pc->data = s;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
461 pc->log = c->log;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
462 pc->pool = c->pool;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
463 pc->read->log = c->log;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
464 pc->write->log = c->log;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
465
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
466 if (rc != NGX_AGAIN) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
467 ngx_stream_proxy_init_upstream(s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
468 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
469 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
470
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
471 pc->read->handler = ngx_stream_proxy_connect_handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
472 pc->write->handler = ngx_stream_proxy_connect_handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
473
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
474 ngx_add_timer(pc->write, pscf->connect_timeout);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
475 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
476
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
477
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
478 static void
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
479 ngx_stream_proxy_init_upstream(ngx_stream_session_t *s)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
480 {
6222
Vladimir Homutov <vl@nginx.com>
parents: 6221
diff changeset
481 int tcp_nodelay;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
482 u_char *p;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
483 ngx_connection_t *c, *pc;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
484 ngx_log_handler_pt handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
485 ngx_stream_upstream_t *u;
6221
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
486 ngx_stream_core_srv_conf_t *cscf;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
487 ngx_stream_proxy_srv_conf_t *pscf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
488
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
489 u = s->upstream;
6221
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
490 pc = u->peer.connection;
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
491
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
492 cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module);
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
493
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
494 if (cscf->tcp_nodelay && pc->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
495 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, pc->log, 0, "tcp_nodelay");
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
496
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
497 tcp_nodelay = 1;
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
498
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
499 if (setsockopt(pc->fd, IPPROTO_TCP, TCP_NODELAY,
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
500 (const void *) &tcp_nodelay, sizeof(int)) == -1)
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
501 {
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
502 ngx_connection_error(pc, ngx_socket_errno,
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
503 "setsockopt(TCP_NODELAY) failed");
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
504 ngx_stream_proxy_next_upstream(s);
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
505 return;
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
506 }
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
507
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
508 pc->tcp_nodelay = NGX_TCP_NODELAY_SET;
7565e056fad6 Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6217
diff changeset
509 }
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
510
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
511 if (u->proxy_protocol) {
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
512 if (ngx_stream_proxy_send_proxy_protocol(s) != NGX_OK) {
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
513 return;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
514 }
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
515
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
516 u->proxy_protocol = 0;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
517 }
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
518
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
519 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module);
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
520
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
521 #if (NGX_STREAM_SSL)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
522 if (pscf->ssl && pc->ssl == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
523 ngx_stream_proxy_ssl_init_connection(s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
524 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
525 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
526 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
527
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
528 c = s->connection;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
529
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
530 if (c->log->log_level >= NGX_LOG_INFO) {
6230
2a621245f4cf Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6222
diff changeset
531 ngx_str_t str;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
532 u_char addr[NGX_SOCKADDR_STRLEN];
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
533
6230
2a621245f4cf Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6222
diff changeset
534 str.len = NGX_SOCKADDR_STRLEN;
2a621245f4cf Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6222
diff changeset
535 str.data = addr;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
536
6230
2a621245f4cf Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6222
diff changeset
537 if (ngx_connection_local_sockaddr(pc, &str, 1) == NGX_OK) {
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
538 handler = c->log->handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
539 c->log->handler = NULL;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
540
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
541 ngx_log_error(NGX_LOG_INFO, c->log, 0, "proxy %V connected to %V",
6230
2a621245f4cf Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6222
diff changeset
542 &str, u->peer.name);
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
543
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
544 c->log->handler = handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
545 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
546 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
547
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
548 c->log->action = "proxying connection";
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
549
6215
8ee6a08ea3eb Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents: 6208
diff changeset
550 p = ngx_pnalloc(c->pool, pscf->buffer_size);
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
551 if (p == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
552 ngx_stream_proxy_finalize(s, NGX_ERROR);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
553 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
554 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
555
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
556 u->upstream_buf.start = p;
6215
8ee6a08ea3eb Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents: 6208
diff changeset
557 u->upstream_buf.end = p + pscf->buffer_size;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
558 u->upstream_buf.pos = p;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
559 u->upstream_buf.last = p;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
560
6202
6345822f0abb Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents: 6201
diff changeset
561 u->connected = 1;
6345822f0abb Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents: 6201
diff changeset
562
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
563 pc->read->handler = ngx_stream_proxy_upstream_handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
564 pc->write->handler = ngx_stream_proxy_upstream_handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
565
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
566 if (ngx_stream_proxy_process(s, 1, 0) != NGX_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
567 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
568 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
569
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
570 ngx_stream_proxy_process(s, 0, 1);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
571 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
572
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
573
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
574 static ngx_int_t
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
575 ngx_stream_proxy_send_proxy_protocol(ngx_stream_session_t *s)
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
576 {
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
577 u_char *p;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
578 ssize_t n, size;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
579 ngx_connection_t *c, *pc;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
580 ngx_stream_upstream_t *u;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
581 ngx_stream_proxy_srv_conf_t *pscf;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
582 u_char buf[NGX_PROXY_PROTOCOL_MAX_HEADER];
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
583
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
584 c = s->connection;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
585
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
586 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0,
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
587 "stream proxy send PROXY protocol header");
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
588
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
589 p = ngx_proxy_protocol_write(c, buf, buf + NGX_PROXY_PROTOCOL_MAX_HEADER);
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
590 if (p == NULL) {
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
591 ngx_stream_proxy_finalize(s, NGX_ERROR);
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
592 return NGX_ERROR;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
593 }
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
594
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
595 u = s->upstream;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
596
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
597 pc = u->peer.connection;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
598
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
599 size = p - buf;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
600
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
601 n = pc->send(pc, buf, size);
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
602
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
603 if (n == NGX_AGAIN) {
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
604 if (ngx_handle_write_event(pc->write, 0) != NGX_OK) {
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
605 ngx_stream_proxy_finalize(s, NGX_ERROR);
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
606 return NGX_ERROR;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
607 }
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
608
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
609 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module);
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
610
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
611 ngx_add_timer(pc->write, pscf->timeout);
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
612
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
613 pc->write->handler = ngx_stream_proxy_connect_handler;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
614
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
615 return NGX_AGAIN;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
616 }
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
617
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
618 if (n == NGX_ERROR) {
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
619 ngx_stream_proxy_finalize(s, NGX_DECLINED);
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
620 return NGX_ERROR;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
621 }
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
622
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
623 if (n != size) {
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
624
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
625 /*
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
626 * PROXY protocol specification:
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
627 * The sender must always ensure that the header
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
628 * is sent at once, so that the transport layer
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
629 * maintains atomicity along the path to the receiver.
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
630 */
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
631
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
632 ngx_log_error(NGX_LOG_ERR, c->log, 0,
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
633 "could not send PROXY protocol header at once");
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
634
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
635 ngx_stream_proxy_finalize(s, NGX_DECLINED);
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
636
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
637 return NGX_ERROR;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
638 }
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
639
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
640 return NGX_OK;
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
641 }
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
642
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
643
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
644 #if (NGX_STREAM_SSL)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
645
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
646 static char *
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
647 ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
648 void *conf)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
649 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
650 ngx_stream_proxy_srv_conf_t *pscf = conf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
651
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
652 ngx_str_t *value;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
653
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
654 if (pscf->ssl_passwords != NGX_CONF_UNSET_PTR) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
655 return "is duplicate";
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
656 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
657
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
658 value = cf->args->elts;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
659
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
660 pscf->ssl_passwords = ngx_ssl_read_password_file(cf, &value[1]);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
661
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
662 if (pscf->ssl_passwords == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
663 return NGX_CONF_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
664 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
665
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
666 return NGX_CONF_OK;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
667 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
668
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
669
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
670 static void
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
671 ngx_stream_proxy_ssl_init_connection(ngx_stream_session_t *s)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
672 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
673 ngx_int_t rc;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
674 ngx_connection_t *pc;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
675 ngx_stream_upstream_t *u;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
676 ngx_stream_proxy_srv_conf_t *pscf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
677
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
678 u = s->upstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
679
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
680 pc = u->peer.connection;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
681
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
682 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
683
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
684 if (ngx_ssl_create_connection(pscf->ssl, pc, NGX_SSL_BUFFER|NGX_SSL_CLIENT)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
685 != NGX_OK)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
686 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
687 ngx_stream_proxy_finalize(s, NGX_ERROR);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
688 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
689 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
690
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
691 if (pscf->ssl_server_name || pscf->ssl_verify) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
692 if (ngx_stream_proxy_ssl_name(s) != NGX_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
693 ngx_stream_proxy_finalize(s, NGX_ERROR);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
694 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
695 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
696 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
697
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
698 if (pscf->ssl_session_reuse) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
699 if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
700 ngx_stream_proxy_finalize(s, NGX_ERROR);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
701 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
702 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
703 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
704
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
705 s->connection->log->action = "SSL handshaking to upstream";
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
706
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
707 rc = ngx_ssl_handshake(pc);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
708
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
709 if (rc == NGX_AGAIN) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
710
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
711 if (!pc->write->timer_set) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
712 ngx_add_timer(pc->write, pscf->connect_timeout);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
713 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
714
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
715 pc->ssl->handler = ngx_stream_proxy_ssl_handshake;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
716 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
717 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
718
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
719 ngx_stream_proxy_ssl_handshake(pc);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
720 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
721
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
722
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
723 static void
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
724 ngx_stream_proxy_ssl_handshake(ngx_connection_t *pc)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
725 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
726 long rc;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
727 ngx_stream_session_t *s;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
728 ngx_stream_upstream_t *u;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
729 ngx_stream_proxy_srv_conf_t *pscf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
730
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
731 s = pc->data;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
732
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
733 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
734
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
735 if (pc->ssl->handshaked) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
736
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
737 if (pscf->ssl_verify) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
738 rc = SSL_get_verify_result(pc->ssl->connection);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
739
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
740 if (rc != X509_V_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
741 ngx_log_error(NGX_LOG_ERR, pc->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
742 "upstream SSL certificate verify error: (%l:%s)",
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
743 rc, X509_verify_cert_error_string(rc));
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
744 goto failed;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
745 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
746
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
747 u = s->upstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
748
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
749 if (ngx_ssl_check_host(pc, &u->ssl_name) != NGX_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
750 ngx_log_error(NGX_LOG_ERR, pc->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
751 "upstream SSL certificate does not match \"%V\"",
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
752 &u->ssl_name);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
753 goto failed;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
754 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
755 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
756
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
757 if (pscf->ssl_session_reuse) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
758 u = s->upstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
759 u->peer.save_session(&u->peer, u->peer.data);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
760 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
761
6258
4b4aee40c508 Stream: delete proxy connection timer after SSL handshake.
Ruslan Ermilov <ru@nginx.com>
parents: 6230
diff changeset
762 if (pc->write->timer_set) {
4b4aee40c508 Stream: delete proxy connection timer after SSL handshake.
Ruslan Ermilov <ru@nginx.com>
parents: 6230
diff changeset
763 ngx_del_timer(pc->write);
4b4aee40c508 Stream: delete proxy connection timer after SSL handshake.
Ruslan Ermilov <ru@nginx.com>
parents: 6230
diff changeset
764 }
4b4aee40c508 Stream: delete proxy connection timer after SSL handshake.
Ruslan Ermilov <ru@nginx.com>
parents: 6230
diff changeset
765
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
766 ngx_stream_proxy_init_upstream(s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
767
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
768 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
769 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
770
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
771 failed:
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
772
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
773 ngx_stream_proxy_next_upstream(s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
774 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
775
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
776
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
777 static ngx_int_t
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
778 ngx_stream_proxy_ssl_name(ngx_stream_session_t *s)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
779 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
780 u_char *p, *last;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
781 ngx_str_t name;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
782 ngx_stream_upstream_t *u;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
783 ngx_stream_proxy_srv_conf_t *pscf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
784
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
785 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
786
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
787 u = s->upstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
788
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
789 name = pscf->ssl_name;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
790
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
791 if (name.len == 0) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
792 name = pscf->upstream->host;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
793 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
794
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
795 if (name.len == 0) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
796 goto done;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
797 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
798
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
799 /*
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
800 * ssl name here may contain port, strip it for compatibility
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
801 * with the http module
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
802 */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
803
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
804 p = name.data;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
805 last = name.data + name.len;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
806
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
807 if (*p == '[') {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
808 p = ngx_strlchr(p, last, ']');
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
809
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
810 if (p == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
811 p = name.data;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
812 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
813 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
814
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
815 p = ngx_strlchr(p, last, ':');
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
816
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
817 if (p != NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
818 name.len = p - name.data;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
819 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
820
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
821 if (!pscf->ssl_server_name) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
822 goto done;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
823 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
824
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
825 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
826
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
827 /* as per RFC 6066, literal IPv4 and IPv6 addresses are not permitted */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
828
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
829 if (name.len == 0 || *name.data == '[') {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
830 goto done;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
831 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
832
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
833 if (ngx_inet_addr(name.data, name.len) != INADDR_NONE) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
834 goto done;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
835 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
836
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
837 /*
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
838 * SSL_set_tlsext_host_name() needs a null-terminated string,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
839 * hence we explicitly null-terminate name here
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
840 */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
841
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
842 p = ngx_pnalloc(s->connection->pool, name.len + 1);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
843 if (p == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
844 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
845 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
846
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
847 (void) ngx_cpystrn(p, name.data, name.len + 1);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
848
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
849 name.data = p;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
850
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
851 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
852 "upstream SSL server name: \"%s\"", name.data);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
853
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
854 if (SSL_set_tlsext_host_name(u->peer.connection->ssl->connection, name.data)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
855 == 0)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
856 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
857 ngx_ssl_error(NGX_LOG_ERR, s->connection->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
858 "SSL_set_tlsext_host_name(\"%s\") failed", name.data);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
859 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
860 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
861
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
862 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
863
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
864 done:
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
865
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
866 u->ssl_name = name;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
867
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
868 return NGX_OK;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
869 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
870
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
871 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
872
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
873
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
874 static void
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
875 ngx_stream_proxy_downstream_handler(ngx_event_t *ev)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
876 {
6200
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
877 ngx_stream_proxy_process_connection(ev, ev->write);
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
878 }
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
879
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
880
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
881 static void
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
882 ngx_stream_proxy_upstream_handler(ngx_event_t *ev)
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
883 {
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
884 ngx_stream_proxy_process_connection(ev, !ev->write);
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
885 }
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
886
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
887
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
888 static void
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
889 ngx_stream_proxy_process_connection(ngx_event_t *ev, ngx_uint_t from_upstream)
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
890 {
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
891 ngx_connection_t *c, *pc;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
892 ngx_stream_session_t *s;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
893 ngx_stream_upstream_t *u;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
894 ngx_stream_proxy_srv_conf_t *pscf;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
895
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
896 c = ev->data;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
897 s = c->data;
6200
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
898 u = s->upstream;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
899
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
900 if (ev->timedout) {
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
901
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
902 if (ev->delayed) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
903
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
904 ev->timedout = 0;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
905 ev->delayed = 0;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
906
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
907 if (!ev->ready) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
908 if (ngx_handle_read_event(ev, 0) != NGX_OK) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
909 ngx_stream_proxy_finalize(s, NGX_ERROR);
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
910 return;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
911 }
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
912
6202
6345822f0abb Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents: 6201
diff changeset
913 if (u->connected) {
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
914 pc = u->peer.connection;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
915
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
916 if (!c->read->delayed && !pc->read->delayed) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
917 pscf = ngx_stream_get_module_srv_conf(s,
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
918 ngx_stream_proxy_module);
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
919 ngx_add_timer(c->write, pscf->timeout);
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
920 }
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
921 }
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
922
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
923 return;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
924 }
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
925
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
926 } else {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
927 ngx_connection_error(c, NGX_ETIMEDOUT, "connection timed out");
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
928 ngx_stream_proxy_finalize(s, NGX_DECLINED);
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
929 return;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
930 }
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
931
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
932 } else if (ev->delayed) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
933
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
934 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0,
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
935 "stream connection delayed");
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
936
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
937 if (ngx_handle_read_event(ev, 0) != NGX_OK) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
938 ngx_stream_proxy_finalize(s, NGX_ERROR);
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
939 }
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
940
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
941 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
942 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
943
6202
6345822f0abb Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents: 6201
diff changeset
944 if (from_upstream && !u->connected) {
6200
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
945 return;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
946 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
947
6200
abee77018d3a Stream: common handler for upstream and downstream.
Roman Arutyunyan <arut@nginx.com>
parents: 6184
diff changeset
948 ngx_stream_proxy_process(s, from_upstream, ev->write);
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
949 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
950
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
951
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
952 static void
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
953 ngx_stream_proxy_connect_handler(ngx_event_t *ev)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
954 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
955 ngx_connection_t *c;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
956 ngx_stream_session_t *s;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
957
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
958 c = ev->data;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
959 s = c->data;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
960
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
961 if (ev->timedout) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
962 ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT, "upstream timed out");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
963 ngx_stream_proxy_next_upstream(s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
964 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
965 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
966
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
967 ngx_del_timer(c->write);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
968
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
969 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
970 "stream proxy connect upstream");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
971
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
972 if (ngx_stream_proxy_test_connect(c) != NGX_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
973 ngx_stream_proxy_next_upstream(s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
974 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
975 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
976
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
977 ngx_stream_proxy_init_upstream(s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
978 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
979
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
980
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
981 static ngx_int_t
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
982 ngx_stream_proxy_test_connect(ngx_connection_t *c)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
983 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
984 int err;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
985 socklen_t len;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
986
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
987 #if (NGX_HAVE_KQUEUE)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
988
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
989 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
990 err = c->write->kq_errno ? c->write->kq_errno : c->read->kq_errno;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
991
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
992 if (err) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
993 (void) ngx_connection_error(c, err,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
994 "kevent() reported that connect() failed");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
995 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
996 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
997
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
998 } else
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
999 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1000 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1001 err = 0;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1002 len = sizeof(int);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1003
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1004 /*
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1005 * BSDs and Linux return 0 and set a pending error in err
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1006 * Solaris returns -1 and sets errno
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1007 */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1008
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1009 if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1010 == -1)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1011 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1012 err = ngx_socket_errno;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1013 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1014
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1015 if (err) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1016 (void) ngx_connection_error(c, err, "connect() failed");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1017 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1018 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1019 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1020
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1021 return NGX_OK;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1022 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1023
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1024
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1025 static ngx_int_t
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1026 ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1027 ngx_uint_t do_write)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1028 {
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1029 off_t *received, limit;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1030 size_t size, limit_rate;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1031 ssize_t n;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1032 ngx_buf_t *b;
6124
f1f222db290b Stream: prevent repeated event notifications after eof.
Roman Arutyunyan <arut@nginx.com>
parents: 6115
diff changeset
1033 ngx_uint_t flags;
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1034 ngx_msec_t delay;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1035 ngx_connection_t *c, *pc, *src, *dst;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1036 ngx_log_handler_pt handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1037 ngx_stream_upstream_t *u;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1038 ngx_stream_proxy_srv_conf_t *pscf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1039
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1040 u = s->upstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1041
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1042 c = s->connection;
6202
6345822f0abb Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents: 6201
diff changeset
1043 pc = u->connected ? u->peer.connection : NULL;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1044
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1045 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module);
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1046
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1047 if (from_upstream) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1048 src = pc;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1049 dst = c;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1050 b = &u->upstream_buf;
6208
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
1051 limit_rate = pscf->download_rate;
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1052 received = &u->received;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1053
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1054 } else {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1055 src = c;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1056 dst = pc;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1057 b = &u->downstream_buf;
6208
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
1058 limit_rate = pscf->upload_rate;
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1059 received = &s->received;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1060 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1061
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1062 for ( ;; ) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1063
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1064 if (do_write) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1065
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1066 size = b->last - b->pos;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1067
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1068 if (size && dst && dst->write->ready) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1069
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1070 n = dst->send(dst, b->pos, size);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1071
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1072 if (n == NGX_ERROR) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1073 ngx_stream_proxy_finalize(s, NGX_DECLINED);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1074 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1075 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1076
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1077 if (n > 0) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1078 b->pos += n;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1079
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1080 if (b->pos == b->last) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1081 b->pos = b->start;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1082 b->last = b->start;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1083 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1084 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1085 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1086 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1087
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1088 size = b->end - b->last;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1089
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1090 if (size && src->read->ready && !src->read->delayed) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1091
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1092 if (limit_rate) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1093 limit = (off_t) limit_rate * (ngx_time() - u->start_sec + 1)
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1094 - *received;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1095
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1096 if (limit <= 0) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1097 src->read->delayed = 1;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1098 delay = (ngx_msec_t) (- limit * 1000 / limit_rate + 1);
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1099 ngx_add_timer(src->read, delay);
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1100 break;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1101 }
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1102
6204
114d1f8cdcab Stream: fixed possible integer overflow in rate limiting.
Valentin Bartenev <vbart@nginx.com>
parents: 6203
diff changeset
1103 if ((off_t) size > limit) {
6203
fdfdcad62875 Stream: fixed MSVC compilation warning.
Roman Arutyunyan <arut@nginx.com>
parents: 6202
diff changeset
1104 size = (size_t) limit;
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1105 }
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1106 }
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1107
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1108 n = src->recv(src, b->last, size);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1109
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1110 if (n == NGX_AGAIN || n == 0) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1111 break;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1112 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1113
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1114 if (n > 0) {
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1115 if (limit_rate) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1116 delay = (ngx_msec_t) (n * 1000 / limit_rate);
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1117
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1118 if (delay > 0) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1119 src->read->delayed = 1;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1120 ngx_add_timer(src->read, delay);
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1121 }
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1122 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1123
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1124 *received += n;
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1125 b->last += n;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1126 do_write = 1;
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1127
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1128 continue;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1129 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1130
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1131 if (n == NGX_ERROR) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1132 src->read->eof = 1;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1133 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1134 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1135
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1136 break;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1137 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1138
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1139 if (src->read->eof && (b->pos == b->last || (dst && dst->read->eof))) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1140 handler = c->log->handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1141 c->log->handler = NULL;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1142
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1143 ngx_log_error(NGX_LOG_INFO, c->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1144 "%s disconnected"
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1145 ", bytes from/to client:%O/%O"
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1146 ", bytes from/to upstream:%O/%O",
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1147 from_upstream ? "upstream" : "client",
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1148 s->received, c->sent, u->received, pc ? pc->sent : 0);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1149
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1150 c->log->handler = handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1151
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1152 ngx_stream_proxy_finalize(s, NGX_OK);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1153 return NGX_DONE;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1154 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1155
6124
f1f222db290b Stream: prevent repeated event notifications after eof.
Roman Arutyunyan <arut@nginx.com>
parents: 6115
diff changeset
1156 flags = src->read->eof ? NGX_CLOSE_EVENT : 0;
f1f222db290b Stream: prevent repeated event notifications after eof.
Roman Arutyunyan <arut@nginx.com>
parents: 6115
diff changeset
1157
f1f222db290b Stream: prevent repeated event notifications after eof.
Roman Arutyunyan <arut@nginx.com>
parents: 6115
diff changeset
1158 if (ngx_handle_read_event(src->read, flags) != NGX_OK) {
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1159 ngx_stream_proxy_finalize(s, NGX_ERROR);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1160 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1161 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1162
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1163 if (dst) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1164 if (ngx_handle_write_event(dst->write, 0) != NGX_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1165 ngx_stream_proxy_finalize(s, NGX_ERROR);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1166 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1167 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1168
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1169 if (!c->read->delayed && !pc->read->delayed) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1170 ngx_add_timer(c->write, pscf->timeout);
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1171
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1172 } else if (c->write->timer_set) {
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1173 ngx_del_timer(c->write);
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1174 }
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1175 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1176
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1177 return NGX_OK;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1178 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1179
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1180
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1181 static void
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1182 ngx_stream_proxy_next_upstream(ngx_stream_session_t *s)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1183 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1184 ngx_msec_t timeout;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1185 ngx_connection_t *pc;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1186 ngx_stream_upstream_t *u;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1187 ngx_stream_proxy_srv_conf_t *pscf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1188
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1189 ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1190 "stream proxy next upstream");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1191
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1192 u = s->upstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1193
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1194 if (u->peer.sockaddr) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1195 u->peer.free(&u->peer, u->peer.data, NGX_PEER_FAILED);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1196 u->peer.sockaddr = NULL;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1197 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1198
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1199 pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1200
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1201 timeout = pscf->next_upstream_timeout;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1202
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1203 if (u->peer.tries == 0
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1204 || !pscf->next_upstream
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1205 || (timeout && ngx_current_msec - u->peer.start_time >= timeout))
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1206 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1207 ngx_stream_proxy_finalize(s, NGX_DECLINED);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1208 return;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1209 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1210
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1211 pc = u->peer.connection;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1212
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1213 if (pc) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1214 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1215 "close proxy upstream connection: %d", pc->fd);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1216
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1217 #if (NGX_STREAM_SSL)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1218 if (pc->ssl) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1219 pc->ssl->no_wait_shutdown = 1;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1220 pc->ssl->no_send_shutdown = 1;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1221
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1222 (void) ngx_ssl_shutdown(pc);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1223 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1224 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1225
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1226 ngx_close_connection(pc);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1227 u->peer.connection = NULL;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1228 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1229
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1230 ngx_stream_proxy_connect(s);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1231 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1232
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1233
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1234 static void
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1235 ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_int_t rc)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1236 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1237 ngx_connection_t *pc;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1238 ngx_stream_upstream_t *u;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1239
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1240 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1241 "finalize stream proxy: %i", rc);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1242
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1243 u = s->upstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1244
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1245 if (u == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1246 goto noupstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1247 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1248
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1249 if (u->peer.free && u->peer.sockaddr) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1250 u->peer.free(&u->peer, u->peer.data, 0);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1251 u->peer.sockaddr = NULL;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1252 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1253
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1254 pc = u->peer.connection;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1255
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1256 if (pc) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1257 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1258 "close stream proxy upstream connection: %d", pc->fd);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1259
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1260 #if (NGX_STREAM_SSL)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1261 if (pc->ssl) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1262 pc->ssl->no_wait_shutdown = 1;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1263 (void) ngx_ssl_shutdown(pc);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1264 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1265 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1266
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1267 ngx_close_connection(pc);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1268 u->peer.connection = NULL;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1269 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1270
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1271 noupstream:
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1272
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1273 ngx_stream_close_connection(s->connection);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1274 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1275
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1276
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1277 static u_char *
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1278 ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1279 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1280 u_char *p;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1281 ngx_connection_t *pc;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1282 ngx_stream_session_t *s;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1283 ngx_stream_upstream_t *u;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1284
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1285 s = log->data;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1286
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1287 u = s->upstream;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1288
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1289 p = buf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1290
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1291 if (u->peer.name) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1292 p = ngx_snprintf(p, len, ", upstream: \"%V\"", u->peer.name);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1293 len -= p - buf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1294 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1295
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1296 pc = u->peer.connection;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1297
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1298 p = ngx_snprintf(p, len,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1299 ", bytes from/to client:%O/%O"
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1300 ", bytes from/to upstream:%O/%O",
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1301 s->received, s->connection->sent,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1302 u->received, pc ? pc->sent : 0);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1303
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1304 return p;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1305 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1306
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1307
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1308 static void *
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1309 ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1310 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1311 ngx_stream_proxy_srv_conf_t *conf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1312
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1313 conf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_proxy_srv_conf_t));
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1314 if (conf == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1315 return NULL;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1316 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1317
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1318 /*
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1319 * set by ngx_pcalloc():
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1320 *
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1321 * conf->ssl_protocols = 0;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1322 * conf->ssl_ciphers = { 0, NULL };
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1323 * conf->ssl_name = { 0, NULL };
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1324 * conf->ssl_trusted_certificate = { 0, NULL };
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1325 * conf->ssl_crl = { 0, NULL };
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1326 * conf->ssl_certificate = { 0, NULL };
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1327 * conf->ssl_certificate_key = { 0, NULL };
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1328 *
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1329 * conf->ssl = NULL;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1330 * conf->upstream = NULL;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1331 */
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1332
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1333 conf->connect_timeout = NGX_CONF_UNSET_MSEC;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1334 conf->timeout = NGX_CONF_UNSET_MSEC;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1335 conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC;
6215
8ee6a08ea3eb Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents: 6208
diff changeset
1336 conf->buffer_size = NGX_CONF_UNSET_SIZE;
6208
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
1337 conf->upload_rate = NGX_CONF_UNSET_SIZE;
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
1338 conf->download_rate = NGX_CONF_UNSET_SIZE;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1339 conf->next_upstream_tries = NGX_CONF_UNSET_UINT;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1340 conf->next_upstream = NGX_CONF_UNSET;
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
1341 conf->proxy_protocol = NGX_CONF_UNSET;
6183
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1342 conf->local = NGX_CONF_UNSET_PTR;
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1343
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1344 #if (NGX_STREAM_SSL)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1345 conf->ssl_enable = NGX_CONF_UNSET;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1346 conf->ssl_session_reuse = NGX_CONF_UNSET;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1347 conf->ssl_server_name = NGX_CONF_UNSET;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1348 conf->ssl_verify = NGX_CONF_UNSET;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1349 conf->ssl_verify_depth = NGX_CONF_UNSET_UINT;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1350 conf->ssl_passwords = NGX_CONF_UNSET_PTR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1351 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1352
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1353 return conf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1354 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1355
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1356
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1357 static char *
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1358 ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1359 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1360 ngx_stream_proxy_srv_conf_t *prev = parent;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1361 ngx_stream_proxy_srv_conf_t *conf = child;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1362
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1363 ngx_conf_merge_msec_value(conf->connect_timeout,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1364 prev->connect_timeout, 60000);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1365
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1366 ngx_conf_merge_msec_value(conf->timeout,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1367 prev->timeout, 10 * 60000);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1368
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1369 ngx_conf_merge_msec_value(conf->next_upstream_timeout,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1370 prev->next_upstream_timeout, 0);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1371
6215
8ee6a08ea3eb Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents: 6208
diff changeset
1372 ngx_conf_merge_size_value(conf->buffer_size,
8ee6a08ea3eb Stream: added proxy_buffer_size to set the size of data buffers.
Roman Arutyunyan <arut@nginx.com>
parents: 6208
diff changeset
1373 prev->buffer_size, 16384);
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1374
6208
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
1375 ngx_conf_merge_size_value(conf->upload_rate,
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
1376 prev->upload_rate, 0);
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1377
6208
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
1378 ngx_conf_merge_size_value(conf->download_rate,
7a14a0d754ad Stream: renamed rate limiting directives.
Roman Arutyunyan <arut@nginx.com>
parents: 6204
diff changeset
1379 prev->download_rate, 0);
6201
24488e6db782 Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents: 6200
diff changeset
1380
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1381 ngx_conf_merge_uint_value(conf->next_upstream_tries,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1382 prev->next_upstream_tries, 0);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1383
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1384 ngx_conf_merge_value(conf->next_upstream, prev->next_upstream, 1);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1385
6184
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
1386 ngx_conf_merge_value(conf->proxy_protocol, prev->proxy_protocol, 0);
fa663739e115 Stream: client-side PROXY protocol.
Roman Arutyunyan <arut@nginx.com>
parents: 6183
diff changeset
1387
6183
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1388 ngx_conf_merge_ptr_value(conf->local, prev->local, NULL);
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1389
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1390 #if (NGX_STREAM_SSL)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1391
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1392 ngx_conf_merge_value(conf->ssl_enable, prev->ssl_enable, 0);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1393
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1394 ngx_conf_merge_value(conf->ssl_session_reuse,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1395 prev->ssl_session_reuse, 1);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1396
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1397 ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
6157
b2899e7d0ef8 Disabled SSLv3 by default (ticket #653).
Maxim Dounin <mdounin@mdounin.ru>
parents: 6124
diff changeset
1398 (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
b2899e7d0ef8 Disabled SSLv3 by default (ticket #653).
Maxim Dounin <mdounin@mdounin.ru>
parents: 6124
diff changeset
1399 |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
6115
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1400
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1401 ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers, "DEFAULT");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1402
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1403 ngx_conf_merge_str_value(conf->ssl_name, prev->ssl_name, "");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1404
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1405 ngx_conf_merge_value(conf->ssl_server_name, prev->ssl_server_name, 0);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1406
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1407 ngx_conf_merge_value(conf->ssl_verify, prev->ssl_verify, 0);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1408
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1409 ngx_conf_merge_uint_value(conf->ssl_verify_depth,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1410 prev->ssl_verify_depth, 1);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1411
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1412 ngx_conf_merge_str_value(conf->ssl_trusted_certificate,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1413 prev->ssl_trusted_certificate, "");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1414
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1415 ngx_conf_merge_str_value(conf->ssl_crl, prev->ssl_crl, "");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1416
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1417 ngx_conf_merge_str_value(conf->ssl_certificate,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1418 prev->ssl_certificate, "");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1419
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1420 ngx_conf_merge_str_value(conf->ssl_certificate_key,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1421 prev->ssl_certificate_key, "");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1422
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1423 ngx_conf_merge_ptr_value(conf->ssl_passwords, prev->ssl_passwords, NULL);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1424
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1425 if (conf->ssl_enable && ngx_stream_proxy_set_ssl(cf, conf) != NGX_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1426 return NGX_CONF_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1427 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1428
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1429 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1430
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1431 return NGX_CONF_OK;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1432 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1433
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1434
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1435 #if (NGX_STREAM_SSL)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1436
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1437 static ngx_int_t
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1438 ngx_stream_proxy_set_ssl(ngx_conf_t *cf, ngx_stream_proxy_srv_conf_t *pscf)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1439 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1440 ngx_pool_cleanup_t *cln;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1441
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1442 pscf->ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t));
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1443 if (pscf->ssl == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1444 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1445 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1446
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1447 pscf->ssl->log = cf->log;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1448
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1449 if (ngx_ssl_create(pscf->ssl, pscf->ssl_protocols, NULL) != NGX_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1450 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1451 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1452
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1453 cln = ngx_pool_cleanup_add(cf->pool, 0);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1454 if (cln == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1455 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1456 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1457
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1458 cln->handler = ngx_ssl_cleanup_ctx;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1459 cln->data = pscf->ssl;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1460
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1461 if (pscf->ssl_certificate.len) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1462
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1463 if (pscf->ssl_certificate_key.len == 0) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1464 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1465 "no \"proxy_ssl_certificate_key\" is defined "
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1466 "for certificate \"%V\"", &pscf->ssl_certificate);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1467 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1468 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1469
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1470 if (ngx_ssl_certificate(cf, pscf->ssl, &pscf->ssl_certificate,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1471 &pscf->ssl_certificate_key, pscf->ssl_passwords)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1472 != NGX_OK)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1473 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1474 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1475 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1476 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1477
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1478 if (SSL_CTX_set_cipher_list(pscf->ssl->ctx,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1479 (const char *) pscf->ssl_ciphers.data)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1480 == 0)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1481 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1482 ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1483 "SSL_CTX_set_cipher_list(\"%V\") failed",
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1484 &pscf->ssl_ciphers);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1485 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1486 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1487
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1488 if (pscf->ssl_verify) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1489 if (pscf->ssl_trusted_certificate.len == 0) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1490 ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1491 "no proxy_ssl_trusted_certificate for proxy_ssl_verify");
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1492 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1493 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1494
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1495 if (ngx_ssl_trusted_certificate(cf, pscf->ssl,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1496 &pscf->ssl_trusted_certificate,
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1497 pscf->ssl_verify_depth)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1498 != NGX_OK)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1499 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1500 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1501 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1502
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1503 if (ngx_ssl_crl(cf, pscf->ssl, &pscf->ssl_crl) != NGX_OK) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1504 return NGX_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1505 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1506 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1507
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1508 return NGX_OK;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1509 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1510
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1511 #endif
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1512
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1513
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1514 static char *
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1515 ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1516 {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1517 ngx_stream_proxy_srv_conf_t *pscf = conf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1518
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1519 ngx_url_t u;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1520 ngx_str_t *value, *url;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1521 ngx_stream_core_srv_conf_t *cscf;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1522
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1523 if (pscf->upstream) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1524 return "is duplicate";
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1525 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1526
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1527 cscf = ngx_stream_conf_get_module_srv_conf(cf, ngx_stream_core_module);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1528
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1529 cscf->handler = ngx_stream_proxy_handler;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1530
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1531 value = cf->args->elts;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1532
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1533 url = &value[1];
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1534
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1535 ngx_memzero(&u, sizeof(ngx_url_t));
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1536
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1537 u.url = *url;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1538 u.no_resolve = 1;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1539
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1540 pscf->upstream = ngx_stream_upstream_add(cf, &u, 0);
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1541 if (pscf->upstream == NULL) {
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1542 return NGX_CONF_ERROR;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1543 }
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1544
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1545 return NGX_CONF_OK;
61d7ae76647d Stream: port from NGINX+.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1546 }
6183
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1547
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1548
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1549 static char *
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1550 ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1551 {
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1552 ngx_stream_proxy_srv_conf_t *pscf = conf;
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1553
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1554 ngx_int_t rc;
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1555 ngx_str_t *value;
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1556
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1557 if (pscf->local != NGX_CONF_UNSET_PTR) {
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1558 return "is duplicate";
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1559 }
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1560
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1561 value = cf->args->elts;
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1562
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1563 if (ngx_strcmp(value[1].data, "off") == 0) {
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1564 pscf->local = NULL;
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1565 return NGX_CONF_OK;
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1566 }
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1567
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1568 pscf->local = ngx_palloc(cf->pool, sizeof(ngx_addr_t));
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1569 if (pscf->local == NULL) {
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1570 return NGX_CONF_ERROR;
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1571 }
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1572
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1573 rc = ngx_parse_addr(cf->pool, pscf->local, value[1].data, value[1].len);
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1574
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1575 switch (rc) {
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1576 case NGX_OK:
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1577 pscf->local->name = value[1];
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1578 return NGX_CONF_OK;
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1579
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1580 case NGX_DECLINED:
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1581 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1582 "invalid address \"%V\"", &value[1]);
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1583 /* fall through */
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1584
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1585 default:
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1586 return NGX_CONF_ERROR;
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1587 }
4dcffe43a7ea Stream: the "proxy_bind" directive.
Vladimir Homutov <vl@nginx.com>
parents: 6174
diff changeset
1588 }