Mercurial > hg > nginx
annotate src/stream/ngx_stream_upstream.h @ 6785:d1d0dd69a419
Upstream: added the ngx_http_upstream_resolved_t.name field.
This fixes inconsistency in what is stored in the "host" field.
Normally it would contain the "host" part of the parsed URL
(e.g., proxy_pass with variables), but for the case of an
implicit upstream specified with literal address it contained
the text representation of the socket address (that is, host
including port for IP).
Now the "host" field always contains the "host" part of the URL,
while the text representation of the socket address is stored
in the newly added "name" field.
The ngx_http_upstream_create_round_robin_peer() function was
modified accordingly in a way to be compatible with the code
that does not know about the new "name" field.
The "stream" code was similarly modified except for not adding
compatibility in ngx_stream_upstream_create_round_robin_peer().
This change is also a prerequisite for the next change.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Mon, 31 Oct 2016 18:33:33 +0300 |
parents | f41c2530dd17 |
children | 54cf51c4f07a |
rev | line source |
---|---|
6115 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #ifndef _NGX_STREAM_UPSTREAM_H_INCLUDED_ | |
9 #define _NGX_STREAM_UPSTREAM_H_INCLUDED_ | |
10 | |
11 | |
12 #include <ngx_config.h> | |
13 #include <ngx_core.h> | |
14 #include <ngx_stream.h> | |
15 #include <ngx_event_connect.h> | |
16 | |
17 | |
18 #define NGX_STREAM_UPSTREAM_CREATE 0x0001 | |
19 #define NGX_STREAM_UPSTREAM_WEIGHT 0x0002 | |
20 #define NGX_STREAM_UPSTREAM_MAX_FAILS 0x0004 | |
21 #define NGX_STREAM_UPSTREAM_FAIL_TIMEOUT 0x0008 | |
22 #define NGX_STREAM_UPSTREAM_DOWN 0x0010 | |
23 #define NGX_STREAM_UPSTREAM_BACKUP 0x0020 | |
6705 | 24 #define NGX_STREAM_UPSTREAM_MAX_CONNS 0x0100 |
6115 | 25 |
26 | |
27 typedef struct { | |
28 ngx_array_t upstreams; | |
29 /* ngx_stream_upstream_srv_conf_t */ | |
30 } ngx_stream_upstream_main_conf_t; | |
31 | |
32 | |
33 typedef struct ngx_stream_upstream_srv_conf_s ngx_stream_upstream_srv_conf_t; | |
34 | |
35 | |
36 typedef ngx_int_t (*ngx_stream_upstream_init_pt)(ngx_conf_t *cf, | |
37 ngx_stream_upstream_srv_conf_t *us); | |
38 typedef ngx_int_t (*ngx_stream_upstream_init_peer_pt)(ngx_stream_session_t *s, | |
39 ngx_stream_upstream_srv_conf_t *us); | |
40 | |
41 | |
42 typedef struct { | |
43 ngx_stream_upstream_init_pt init_upstream; | |
44 ngx_stream_upstream_init_peer_pt init; | |
45 void *data; | |
46 } ngx_stream_upstream_peer_t; | |
47 | |
48 | |
49 typedef struct { | |
50 ngx_str_t name; | |
51 ngx_addr_t *addrs; | |
52 ngx_uint_t naddrs; | |
53 ngx_uint_t weight; | |
6705 | 54 ngx_uint_t max_conns; |
6115 | 55 ngx_uint_t max_fails; |
56 time_t fail_timeout; | |
6708
4080f94a996f
Modules compatibility: slow start fields.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6705
diff
changeset
|
57 ngx_msec_t slow_start; |
6115 | 58 |
59 unsigned down:1; | |
60 unsigned backup:1; | |
6715
d200a0fd00b7
Introduced the NGX_COMPAT macro.
Ruslan Ermilov <ru@nginx.com>
parents:
6708
diff
changeset
|
61 |
d200a0fd00b7
Introduced the NGX_COMPAT macro.
Ruslan Ermilov <ru@nginx.com>
parents:
6708
diff
changeset
|
62 NGX_COMPAT_BEGIN(4) |
d200a0fd00b7
Introduced the NGX_COMPAT macro.
Ruslan Ermilov <ru@nginx.com>
parents:
6708
diff
changeset
|
63 NGX_COMPAT_END |
6115 | 64 } ngx_stream_upstream_server_t; |
65 | |
66 | |
67 struct ngx_stream_upstream_srv_conf_s { | |
68 ngx_stream_upstream_peer_t peer; | |
69 void **srv_conf; | |
70 | |
71 ngx_array_t *servers; | |
72 /* ngx_stream_upstream_server_t */ | |
73 | |
74 ngx_uint_t flags; | |
75 ngx_str_t host; | |
76 u_char *file_name; | |
77 ngx_uint_t line; | |
78 in_port_t port; | |
79 ngx_uint_t no_port; /* unsigned no_port:1 */ | |
80 | |
81 #if (NGX_STREAM_UPSTREAM_ZONE) | |
82 ngx_shm_zone_t *shm_zone; | |
83 #endif | |
84 }; | |
85 | |
86 | |
87 typedef struct { | |
6677
c02290241cbe
Stream: upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
6676
diff
changeset
|
88 ngx_msec_t response_time; |
c02290241cbe
Stream: upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
6676
diff
changeset
|
89 ngx_msec_t connect_time; |
c02290241cbe
Stream: upstream response time variables.
Vladimir Homutov <vl@nginx.com>
parents:
6676
diff
changeset
|
90 ngx_msec_t first_byte_time; |
6676
df3a7c029dec
Stream: $upstream_bytes_sent and $upstream_bytes_received.
Vladimir Homutov <vl@nginx.com>
parents:
6675
diff
changeset
|
91 off_t bytes_sent; |
df3a7c029dec
Stream: $upstream_bytes_sent and $upstream_bytes_received.
Vladimir Homutov <vl@nginx.com>
parents:
6675
diff
changeset
|
92 off_t bytes_received; |
df3a7c029dec
Stream: $upstream_bytes_sent and $upstream_bytes_received.
Vladimir Homutov <vl@nginx.com>
parents:
6675
diff
changeset
|
93 |
6675
ab9b4fd8c5b7
Stream: the $upstream_addr variable.
Vladimir Homutov <vl@nginx.com>
parents:
6643
diff
changeset
|
94 ngx_str_t *peer; |
ab9b4fd8c5b7
Stream: the $upstream_addr variable.
Vladimir Homutov <vl@nginx.com>
parents:
6643
diff
changeset
|
95 } ngx_stream_upstream_state_t; |
ab9b4fd8c5b7
Stream: the $upstream_addr variable.
Vladimir Homutov <vl@nginx.com>
parents:
6643
diff
changeset
|
96 |
ab9b4fd8c5b7
Stream: the $upstream_addr variable.
Vladimir Homutov <vl@nginx.com>
parents:
6643
diff
changeset
|
97 |
ab9b4fd8c5b7
Stream: the $upstream_addr variable.
Vladimir Homutov <vl@nginx.com>
parents:
6643
diff
changeset
|
98 typedef struct { |
6643
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
99 ngx_str_t host; |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
100 in_port_t port; |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
101 ngx_uint_t no_port; /* unsigned no_port:1 */ |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
102 |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
103 ngx_uint_t naddrs; |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
104 ngx_resolver_addr_t *addrs; |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
105 |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
106 struct sockaddr *sockaddr; |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
107 socklen_t socklen; |
6785
d1d0dd69a419
Upstream: added the ngx_http_upstream_resolved_t.name field.
Ruslan Ermilov <ru@nginx.com>
parents:
6736
diff
changeset
|
108 ngx_str_t name; |
6643
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
109 |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
110 ngx_resolver_ctx_t *ctx; |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
111 } ngx_stream_upstream_resolved_t; |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
112 |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
113 |
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
114 typedef struct { |
6115 | 115 ngx_peer_connection_t peer; |
6692 | 116 |
6115 | 117 ngx_buf_t downstream_buf; |
118 ngx_buf_t upstream_buf; | |
6692 | 119 |
120 ngx_chain_t *free; | |
121 ngx_chain_t *upstream_out; | |
122 ngx_chain_t *upstream_busy; | |
123 ngx_chain_t *downstream_out; | |
124 ngx_chain_t *downstream_busy; | |
125 | |
6115 | 126 off_t received; |
6201
24488e6db782
Stream: upstream and downstream limit rates.
Roman Arutyunyan <arut@nginx.com>
parents:
6184
diff
changeset
|
127 time_t start_sec; |
6436 | 128 ngx_uint_t responses; |
6692 | 129 |
6115 | 130 ngx_str_t ssl_name; |
6692 | 131 |
6703
edcd9303a4d3
Upstream: introduced u->upstream.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6692
diff
changeset
|
132 ngx_stream_upstream_srv_conf_t *upstream; |
6643
9757cffc1e2f
Stream: variables in proxy_pass and proxy_ssl_name.
Vladimir Homutov <vl@nginx.com>
parents:
6436
diff
changeset
|
133 ngx_stream_upstream_resolved_t *resolved; |
6675
ab9b4fd8c5b7
Stream: the $upstream_addr variable.
Vladimir Homutov <vl@nginx.com>
parents:
6643
diff
changeset
|
134 ngx_stream_upstream_state_t *state; |
6202
6345822f0abb
Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents:
6201
diff
changeset
|
135 unsigned connected:1; |
6345822f0abb
Stream: upstream "connected" flag.
Roman Arutyunyan <arut@nginx.com>
parents:
6201
diff
changeset
|
136 unsigned proxy_protocol:1; |
6115 | 137 } ngx_stream_upstream_t; |
138 | |
139 | |
140 ngx_stream_upstream_srv_conf_t *ngx_stream_upstream_add(ngx_conf_t *cf, | |
141 ngx_url_t *u, ngx_uint_t flags); | |
142 | |
143 | |
144 #define ngx_stream_conf_upstream_srv_conf(uscf, module) \ | |
145 uscf->srv_conf[module.ctx_index] | |
146 | |
147 | |
148 extern ngx_module_t ngx_stream_upstream_module; | |
149 | |
150 | |
151 #endif /* _NGX_STREAM_UPSTREAM_H_INCLUDED_ */ |