nginxtra 1.8.1.12 → 1.10.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nginxtra +1 -1
  3. data/bin/nginxtra_rails +1 -1
  4. data/lib/nginxtra/version.rb +1 -1
  5. data/vendor/nginx/CHANGES +363 -25
  6. data/vendor/nginx/CHANGES.ru +365 -21
  7. data/vendor/nginx/LICENSE +2 -2
  8. data/vendor/nginx/auto/cc/conf +32 -0
  9. data/vendor/nginx/auto/cc/gcc +1 -1
  10. data/vendor/nginx/auto/cc/icc +2 -2
  11. data/vendor/nginx/auto/cc/msvc +29 -8
  12. data/vendor/nginx/auto/cc/name +2 -25
  13. data/vendor/nginx/auto/cc/sunc +3 -0
  14. data/vendor/nginx/auto/endianness +7 -2
  15. data/vendor/nginx/auto/install +60 -26
  16. data/vendor/nginx/auto/lib/conf +4 -4
  17. data/vendor/nginx/auto/lib/geoip/conf +6 -1
  18. data/vendor/nginx/auto/lib/libgd/conf +6 -1
  19. data/vendor/nginx/auto/lib/libxslt/conf +11 -2
  20. data/vendor/nginx/auto/lib/make +1 -1
  21. data/vendor/nginx/auto/lib/md5/conf +2 -2
  22. data/vendor/nginx/auto/lib/md5/make +2 -2
  23. data/vendor/nginx/auto/lib/openssl/conf +52 -3
  24. data/vendor/nginx/auto/lib/openssl/make +1 -1
  25. data/vendor/nginx/auto/lib/pcre/conf +2 -2
  26. data/vendor/nginx/auto/lib/pcre/make +2 -2
  27. data/vendor/nginx/auto/lib/perl/conf +6 -3
  28. data/vendor/nginx/auto/lib/perl/make +4 -1
  29. data/vendor/nginx/auto/lib/sha1/conf +2 -2
  30. data/vendor/nginx/auto/lib/sha1/make +2 -2
  31. data/vendor/nginx/auto/lib/zlib/conf +2 -2
  32. data/vendor/nginx/auto/lib/zlib/make +2 -2
  33. data/vendor/nginx/auto/make +281 -16
  34. data/vendor/nginx/auto/module +122 -0
  35. data/vendor/nginx/auto/modules +909 -178
  36. data/vendor/nginx/auto/options +81 -19
  37. data/vendor/nginx/auto/os/conf +9 -0
  38. data/vendor/nginx/auto/os/darwin +3 -0
  39. data/vendor/nginx/auto/os/freebsd +0 -20
  40. data/vendor/nginx/auto/os/linux +0 -12
  41. data/vendor/nginx/auto/os/win32 +5 -1
  42. data/vendor/nginx/auto/sources +11 -311
  43. data/vendor/nginx/auto/summary +1 -0
  44. data/vendor/nginx/auto/types/sizeof +5 -3
  45. data/vendor/nginx/auto/types/typedef +9 -4
  46. data/vendor/nginx/auto/types/uintptr_t +7 -2
  47. data/vendor/nginx/auto/unix +72 -12
  48. data/vendor/nginx/conf/fastcgi.conf +1 -0
  49. data/vendor/nginx/conf/fastcgi_params +1 -0
  50. data/vendor/nginx/conf/scgi_params +1 -0
  51. data/vendor/nginx/conf/uwsgi_params +1 -0
  52. data/vendor/nginx/configure +1 -1
  53. data/vendor/nginx/contrib/vim/syntax/nginx.vim +2 -2
  54. data/vendor/nginx/man/nginx.8 +6 -2
  55. data/vendor/nginx/src/core/nginx.c +281 -114
  56. data/vendor/nginx/src/core/nginx.h +2 -2
  57. data/vendor/nginx/src/core/ngx_conf_file.c +54 -13
  58. data/vendor/nginx/src/core/ngx_conf_file.h +8 -52
  59. data/vendor/nginx/src/core/ngx_config.h +0 -5
  60. data/vendor/nginx/src/core/ngx_connection.c +270 -37
  61. data/vendor/nginx/src/core/ngx_connection.h +35 -12
  62. data/vendor/nginx/src/core/ngx_core.h +4 -0
  63. data/vendor/nginx/src/core/ngx_crypt.c +2 -2
  64. data/vendor/nginx/src/core/ngx_cycle.c +72 -25
  65. data/vendor/nginx/src/core/ngx_cycle.h +28 -39
  66. data/vendor/nginx/src/core/ngx_file.c +14 -5
  67. data/vendor/nginx/src/core/ngx_file.h +2 -0
  68. data/vendor/nginx/src/core/ngx_hash.c +13 -1
  69. data/vendor/nginx/src/core/ngx_inet.c +20 -18
  70. data/vendor/nginx/src/core/ngx_log.c +12 -12
  71. data/vendor/nginx/src/core/ngx_log.h +13 -6
  72. data/vendor/nginx/src/core/ngx_module.c +360 -0
  73. data/vendor/nginx/src/core/ngx_module.h +307 -0
  74. data/vendor/nginx/src/core/ngx_open_file_cache.c +2 -2
  75. data/vendor/nginx/src/core/ngx_output_chain.c +8 -4
  76. data/vendor/nginx/src/core/ngx_palloc.c +42 -44
  77. data/vendor/nginx/src/{http/ngx_http_parse_time.c → core/ngx_parse_time.c} +2 -3
  78. data/vendor/nginx/src/core/ngx_parse_time.h +22 -0
  79. data/vendor/nginx/src/core/ngx_proxy_protocol.c +50 -1
  80. data/vendor/nginx/src/core/ngx_proxy_protocol.h +3 -1
  81. data/vendor/nginx/src/core/ngx_regex.c +1 -38
  82. data/vendor/nginx/src/core/ngx_resolver.c +1814 -320
  83. data/vendor/nginx/src/core/ngx_resolver.h +67 -10
  84. data/vendor/nginx/src/core/ngx_rwlock.c +120 -0
  85. data/vendor/nginx/src/core/ngx_rwlock.h +21 -0
  86. data/vendor/nginx/src/core/ngx_slab.c +6 -5
  87. data/vendor/nginx/src/core/ngx_string.c +1 -1
  88. data/vendor/nginx/src/core/ngx_syslog.c +11 -3
  89. data/vendor/nginx/src/core/ngx_syslog.h +2 -1
  90. data/vendor/nginx/src/core/ngx_thread_pool.c +4 -0
  91. data/vendor/nginx/src/core/ngx_times.c +2 -2
  92. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +3 -1
  93. data/vendor/nginx/src/event/modules/ngx_epoll_module.c +5 -2
  94. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +5 -5
  95. data/vendor/nginx/src/event/modules/ngx_kqueue_module.c +15 -8
  96. data/vendor/nginx/src/event/modules/ngx_poll_module.c +0 -10
  97. data/vendor/nginx/src/event/modules/ngx_select_module.c +0 -10
  98. data/vendor/nginx/src/event/ngx_event.c +60 -103
  99. data/vendor/nginx/src/event/ngx_event.h +22 -26
  100. data/vendor/nginx/src/event/ngx_event_accept.c +414 -88
  101. data/vendor/nginx/src/event/ngx_event_connect.c +27 -18
  102. data/vendor/nginx/src/event/ngx_event_connect.h +1 -0
  103. data/vendor/nginx/src/event/ngx_event_openssl.c +65 -25
  104. data/vendor/nginx/src/event/ngx_event_openssl.h +17 -0
  105. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +73 -7
  106. data/vendor/nginx/src/event/ngx_event_pipe.c +85 -27
  107. data/vendor/nginx/src/event/ngx_event_pipe.h +10 -0
  108. data/vendor/nginx/src/http/modules/ngx_http_auth_basic_module.c +1 -1
  109. data/vendor/nginx/src/http/modules/ngx_http_auth_request_module.c +2 -2
  110. data/vendor/nginx/src/http/modules/ngx_http_chunked_filter_module.c +2 -2
  111. data/vendor/nginx/src/http/modules/ngx_http_dav_module.c +6 -6
  112. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +17 -11
  113. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +2 -2
  114. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +9 -9
  115. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +2 -2
  116. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +2 -2
  117. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +0 -7
  118. data/vendor/nginx/src/http/modules/ngx_http_map_module.c +6 -6
  119. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +2 -1
  120. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +13 -13
  121. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +2 -2
  122. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +26 -21
  123. data/vendor/nginx/src/http/modules/ngx_http_random_index_module.c +1 -1
  124. data/vendor/nginx/src/http/modules/ngx_http_range_filter_module.c +26 -8
  125. data/vendor/nginx/src/http/modules/ngx_http_realip_module.c +73 -3
  126. data/vendor/nginx/src/http/modules/ngx_http_referer_module.c +1 -1
  127. data/vendor/nginx/src/http/modules/ngx_http_rewrite_module.c +6 -6
  128. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +5 -3
  129. data/vendor/nginx/src/http/modules/ngx_http_slice_filter_module.c +526 -0
  130. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +7 -7
  131. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +19 -16
  132. data/vendor/nginx/src/http/modules/ngx_http_static_module.c +1 -1
  133. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +1 -1
  134. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +373 -173
  135. data/vendor/nginx/src/http/modules/ngx_http_upstream_hash_module.c +72 -46
  136. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +18 -30
  137. data/vendor/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +50 -39
  138. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +38 -129
  139. data/vendor/nginx/src/http/modules/ngx_http_upstream_zone_module.c +246 -0
  140. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +6 -5
  141. data/vendor/nginx/src/http/modules/perl/nginx.xs +9 -9
  142. data/vendor/nginx/src/http/ngx_http.c +46 -43
  143. data/vendor/nginx/src/http/ngx_http.h +4 -9
  144. data/vendor/nginx/src/http/ngx_http_cache.h +4 -0
  145. data/vendor/nginx/src/http/ngx_http_copy_filter_module.c +13 -5
  146. data/vendor/nginx/src/http/ngx_http_core_module.c +92 -91
  147. data/vendor/nginx/src/http/ngx_http_core_module.h +12 -8
  148. data/vendor/nginx/src/http/ngx_http_file_cache.c +61 -10
  149. data/vendor/nginx/src/http/ngx_http_request.c +37 -50
  150. data/vendor/nginx/src/http/ngx_http_request.h +10 -15
  151. data/vendor/nginx/src/http/ngx_http_request_body.c +64 -88
  152. data/vendor/nginx/src/http/ngx_http_script.c +3 -3
  153. data/vendor/nginx/src/http/ngx_http_special_response.c +1 -4
  154. data/vendor/nginx/src/http/ngx_http_upstream.c +245 -109
  155. data/vendor/nginx/src/http/ngx_http_upstream.h +11 -5
  156. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +212 -65
  157. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +66 -5
  158. data/vendor/nginx/src/http/ngx_http_variables.c +28 -15
  159. data/vendor/nginx/src/http/ngx_http_write_filter_module.c +1 -1
  160. data/vendor/nginx/src/http/v2/ngx_http_v2.c +4349 -0
  161. data/vendor/nginx/src/http/v2/ngx_http_v2.h +337 -0
  162. data/vendor/nginx/src/http/v2/ngx_http_v2_filter_module.c +1391 -0
  163. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_decode.c +2714 -0
  164. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_encode.c +254 -0
  165. data/vendor/nginx/src/http/v2/ngx_http_v2_module.c +469 -0
  166. data/vendor/nginx/src/http/{ngx_http_spdy_module.h → v2/ngx_http_v2_module.h} +10 -9
  167. data/vendor/nginx/src/http/v2/ngx_http_v2_table.c +349 -0
  168. data/vendor/nginx/src/mail/ngx_mail.c +49 -82
  169. data/vendor/nginx/src/mail/ngx_mail.h +16 -23
  170. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +1 -1
  171. data/vendor/nginx/src/mail/ngx_mail_core_module.c +60 -34
  172. data/vendor/nginx/src/mail/ngx_mail_handler.c +17 -12
  173. data/vendor/nginx/src/mail/ngx_mail_proxy_module.c +1 -14
  174. data/vendor/nginx/src/mail/ngx_mail_smtp_handler.c +1 -1
  175. data/vendor/nginx/src/mail/ngx_mail_ssl_module.c +5 -5
  176. data/vendor/nginx/src/os/unix/ngx_atomic.h +10 -10
  177. data/vendor/nginx/src/os/unix/ngx_channel.h +4 -4
  178. data/vendor/nginx/src/os/unix/ngx_darwin_config.h +2 -0
  179. data/vendor/nginx/src/os/unix/ngx_darwin_init.c +1 -0
  180. data/vendor/nginx/src/os/unix/ngx_dlopen.c +28 -0
  181. data/vendor/nginx/src/os/unix/ngx_dlopen.h +31 -0
  182. data/vendor/nginx/src/os/unix/ngx_errno.h +1 -0
  183. data/vendor/nginx/src/os/unix/ngx_file_aio_read.c +1 -1
  184. data/vendor/nginx/src/os/unix/ngx_files.c +313 -80
  185. data/vendor/nginx/src/os/unix/ngx_files.h +5 -2
  186. data/vendor/nginx/src/os/unix/ngx_freebsd_config.h +3 -1
  187. data/vendor/nginx/src/os/unix/ngx_freebsd_init.c +1 -0
  188. data/vendor/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +13 -0
  189. data/vendor/nginx/src/os/unix/ngx_linux.h +0 -2
  190. data/vendor/nginx/src/os/unix/ngx_linux_aio_read.c +1 -1
  191. data/vendor/nginx/src/os/unix/ngx_linux_config.h +2 -6
  192. data/vendor/nginx/src/os/unix/ngx_linux_init.c +1 -33
  193. data/vendor/nginx/src/os/unix/ngx_linux_sendfile_chain.c +55 -12
  194. data/vendor/nginx/src/os/unix/ngx_os.h +3 -9
  195. data/vendor/nginx/src/os/unix/ngx_posix_config.h +14 -1
  196. data/vendor/nginx/src/os/unix/ngx_posix_init.c +2 -1
  197. data/vendor/nginx/src/os/unix/ngx_process.c +1 -1
  198. data/vendor/nginx/src/os/unix/ngx_process_cycle.c +25 -51
  199. data/vendor/nginx/src/os/unix/ngx_process_cycle.h +1 -0
  200. data/vendor/nginx/src/os/unix/ngx_readv_chain.c +24 -28
  201. data/vendor/nginx/src/os/unix/ngx_recv.c +30 -79
  202. data/vendor/nginx/src/os/unix/ngx_send.c +1 -1
  203. data/vendor/nginx/src/os/unix/ngx_setaffinity.c +14 -30
  204. data/vendor/nginx/src/os/unix/ngx_setaffinity.h +15 -1
  205. data/vendor/nginx/src/os/unix/ngx_solaris_config.h +2 -0
  206. data/vendor/nginx/src/os/unix/ngx_solaris_init.c +1 -0
  207. data/vendor/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +23 -0
  208. data/vendor/nginx/src/os/unix/ngx_sunpro_amd64.il +3 -3
  209. data/vendor/nginx/src/os/unix/ngx_sunpro_x86.il +3 -3
  210. data/vendor/nginx/src/os/unix/ngx_udp_recv.c +5 -48
  211. data/vendor/nginx/src/os/unix/ngx_udp_send.c +56 -0
  212. data/vendor/nginx/src/stream/ngx_stream.c +564 -0
  213. data/vendor/nginx/src/stream/ngx_stream.h +212 -0
  214. data/vendor/nginx/src/stream/ngx_stream_access_module.c +451 -0
  215. data/vendor/nginx/src/stream/ngx_stream_core_module.c +562 -0
  216. data/vendor/nginx/src/stream/ngx_stream_handler.c +344 -0
  217. data/vendor/nginx/src/stream/ngx_stream_limit_conn_module.c +632 -0
  218. data/vendor/nginx/src/stream/ngx_stream_proxy_module.c +1674 -0
  219. data/vendor/nginx/src/stream/ngx_stream_ssl_module.c +460 -0
  220. data/vendor/nginx/src/stream/ngx_stream_ssl_module.h +49 -0
  221. data/vendor/nginx/src/stream/ngx_stream_upstream.c +464 -0
  222. data/vendor/nginx/src/stream/ngx_stream_upstream.h +107 -0
  223. data/vendor/nginx/src/stream/ngx_stream_upstream_hash_module.c +656 -0
  224. data/vendor/nginx/src/stream/ngx_stream_upstream_least_conn_module.c +307 -0
  225. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.c +702 -0
  226. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.h +139 -0
  227. data/vendor/nginx/src/stream/ngx_stream_upstream_zone_module.c +242 -0
  228. metadata +39 -15
  229. data/vendor/nginx/src/event/modules/ngx_aio_module.c +0 -171
  230. data/vendor/nginx/src/event/modules/ngx_rtsig_module.c +0 -735
  231. data/vendor/nginx/src/http/ngx_http_spdy.c +0 -3701
  232. data/vendor/nginx/src/http/ngx_http_spdy.h +0 -261
  233. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +0 -1222
  234. data/vendor/nginx/src/http/ngx_http_spdy_module.c +0 -408
  235. data/vendor/nginx/src/os/unix/ngx_aio_read.c +0 -109
  236. data/vendor/nginx/src/os/unix/ngx_aio_read_chain.c +0 -78
  237. data/vendor/nginx/src/os/unix/ngx_aio_write.c +0 -109
  238. data/vendor/nginx/src/os/unix/ngx_aio_write_chain.c +0 -100
@@ -0,0 +1,56 @@
1
+
2
+ /*
3
+ * Copyright (C) Igor Sysoev
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #include <ngx_config.h>
9
+ #include <ngx_core.h>
10
+ #include <ngx_event.h>
11
+
12
+
13
+ ssize_t
14
+ ngx_udp_unix_send(ngx_connection_t *c, u_char *buf, size_t size)
15
+ {
16
+ ssize_t n;
17
+ ngx_err_t err;
18
+ ngx_event_t *wev;
19
+
20
+ wev = c->write;
21
+
22
+ for ( ;; ) {
23
+ n = sendto(c->fd, buf, size, 0, c->sockaddr, c->socklen);
24
+
25
+ ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
26
+ "sendto: fd:%d %z of %uz to \"%V\"",
27
+ c->fd, n, size, &c->addr_text);
28
+
29
+ if (n >= 0) {
30
+ if ((size_t) n != size) {
31
+ wev->error = 1;
32
+ (void) ngx_connection_error(c, 0, "sendto() incomplete");
33
+ return NGX_ERROR;
34
+ }
35
+
36
+ c->sent += n;
37
+
38
+ return n;
39
+ }
40
+
41
+ err = ngx_socket_errno;
42
+
43
+ if (err == NGX_EAGAIN) {
44
+ wev->ready = 0;
45
+ ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, NGX_EAGAIN,
46
+ "sendto() not ready");
47
+ return NGX_AGAIN;
48
+ }
49
+
50
+ if (err != NGX_EINTR) {
51
+ wev->error = 1;
52
+ (void) ngx_connection_error(c, err, "sendto() failed");
53
+ return NGX_ERROR;
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,564 @@
1
+
2
+ /*
3
+ * Copyright (C) Roman Arutyunyan
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #include <ngx_config.h>
9
+ #include <ngx_core.h>
10
+ #include <ngx_event.h>
11
+ #include <ngx_stream.h>
12
+
13
+
14
+ static char *ngx_stream_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
15
+ static ngx_int_t ngx_stream_add_ports(ngx_conf_t *cf, ngx_array_t *ports,
16
+ ngx_stream_listen_t *listen);
17
+ static char *ngx_stream_optimize_servers(ngx_conf_t *cf, ngx_array_t *ports);
18
+ static ngx_int_t ngx_stream_add_addrs(ngx_conf_t *cf, ngx_stream_port_t *stport,
19
+ ngx_stream_conf_addr_t *addr);
20
+ #if (NGX_HAVE_INET6)
21
+ static ngx_int_t ngx_stream_add_addrs6(ngx_conf_t *cf,
22
+ ngx_stream_port_t *stport, ngx_stream_conf_addr_t *addr);
23
+ #endif
24
+ static ngx_int_t ngx_stream_cmp_conf_addrs(const void *one, const void *two);
25
+
26
+
27
+ ngx_uint_t ngx_stream_max_module;
28
+
29
+
30
+ static ngx_command_t ngx_stream_commands[] = {
31
+
32
+ { ngx_string("stream"),
33
+ NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
34
+ ngx_stream_block,
35
+ 0,
36
+ 0,
37
+ NULL },
38
+
39
+ ngx_null_command
40
+ };
41
+
42
+
43
+ static ngx_core_module_t ngx_stream_module_ctx = {
44
+ ngx_string("stream"),
45
+ NULL,
46
+ NULL
47
+ };
48
+
49
+
50
+ ngx_module_t ngx_stream_module = {
51
+ NGX_MODULE_V1,
52
+ &ngx_stream_module_ctx, /* module context */
53
+ ngx_stream_commands, /* module directives */
54
+ NGX_CORE_MODULE, /* module type */
55
+ NULL, /* init master */
56
+ NULL, /* init module */
57
+ NULL, /* init process */
58
+ NULL, /* init thread */
59
+ NULL, /* exit thread */
60
+ NULL, /* exit process */
61
+ NULL, /* exit master */
62
+ NGX_MODULE_V1_PADDING
63
+ };
64
+
65
+
66
+ static char *
67
+ ngx_stream_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
68
+ {
69
+ char *rv;
70
+ ngx_uint_t i, m, mi, s;
71
+ ngx_conf_t pcf;
72
+ ngx_array_t ports;
73
+ ngx_stream_listen_t *listen;
74
+ ngx_stream_module_t *module;
75
+ ngx_stream_conf_ctx_t *ctx;
76
+ ngx_stream_core_srv_conf_t **cscfp;
77
+ ngx_stream_core_main_conf_t *cmcf;
78
+
79
+ if (*(ngx_stream_conf_ctx_t **) conf) {
80
+ return "is duplicate";
81
+ }
82
+
83
+ /* the main stream context */
84
+
85
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_stream_conf_ctx_t));
86
+ if (ctx == NULL) {
87
+ return NGX_CONF_ERROR;
88
+ }
89
+
90
+ *(ngx_stream_conf_ctx_t **) conf = ctx;
91
+
92
+ /* count the number of the stream modules and set up their indices */
93
+
94
+ ngx_stream_max_module = ngx_count_modules(cf->cycle, NGX_STREAM_MODULE);
95
+
96
+
97
+ /* the stream main_conf context, it's the same in the all stream contexts */
98
+
99
+ ctx->main_conf = ngx_pcalloc(cf->pool,
100
+ sizeof(void *) * ngx_stream_max_module);
101
+ if (ctx->main_conf == NULL) {
102
+ return NGX_CONF_ERROR;
103
+ }
104
+
105
+
106
+ /*
107
+ * the stream null srv_conf context, it is used to merge
108
+ * the server{}s' srv_conf's
109
+ */
110
+
111
+ ctx->srv_conf = ngx_pcalloc(cf->pool,
112
+ sizeof(void *) * ngx_stream_max_module);
113
+ if (ctx->srv_conf == NULL) {
114
+ return NGX_CONF_ERROR;
115
+ }
116
+
117
+
118
+ /*
119
+ * create the main_conf's and the null srv_conf's of the all stream modules
120
+ */
121
+
122
+ for (m = 0; cf->cycle->modules[m]; m++) {
123
+ if (cf->cycle->modules[m]->type != NGX_STREAM_MODULE) {
124
+ continue;
125
+ }
126
+
127
+ module = cf->cycle->modules[m]->ctx;
128
+ mi = cf->cycle->modules[m]->ctx_index;
129
+
130
+ if (module->create_main_conf) {
131
+ ctx->main_conf[mi] = module->create_main_conf(cf);
132
+ if (ctx->main_conf[mi] == NULL) {
133
+ return NGX_CONF_ERROR;
134
+ }
135
+ }
136
+
137
+ if (module->create_srv_conf) {
138
+ ctx->srv_conf[mi] = module->create_srv_conf(cf);
139
+ if (ctx->srv_conf[mi] == NULL) {
140
+ return NGX_CONF_ERROR;
141
+ }
142
+ }
143
+ }
144
+
145
+
146
+ /* parse inside the stream{} block */
147
+
148
+ pcf = *cf;
149
+ cf->ctx = ctx;
150
+
151
+ cf->module_type = NGX_STREAM_MODULE;
152
+ cf->cmd_type = NGX_STREAM_MAIN_CONF;
153
+ rv = ngx_conf_parse(cf, NULL);
154
+
155
+ if (rv != NGX_CONF_OK) {
156
+ *cf = pcf;
157
+ return rv;
158
+ }
159
+
160
+
161
+ /* init stream{} main_conf's, merge the server{}s' srv_conf's */
162
+
163
+ cmcf = ctx->main_conf[ngx_stream_core_module.ctx_index];
164
+ cscfp = cmcf->servers.elts;
165
+
166
+ for (m = 0; cf->cycle->modules[m]; m++) {
167
+ if (cf->cycle->modules[m]->type != NGX_STREAM_MODULE) {
168
+ continue;
169
+ }
170
+
171
+ module = cf->cycle->modules[m]->ctx;
172
+ mi = cf->cycle->modules[m]->ctx_index;
173
+
174
+ /* init stream{} main_conf's */
175
+
176
+ cf->ctx = ctx;
177
+
178
+ if (module->init_main_conf) {
179
+ rv = module->init_main_conf(cf, ctx->main_conf[mi]);
180
+ if (rv != NGX_CONF_OK) {
181
+ *cf = pcf;
182
+ return rv;
183
+ }
184
+ }
185
+
186
+ for (s = 0; s < cmcf->servers.nelts; s++) {
187
+
188
+ /* merge the server{}s' srv_conf's */
189
+
190
+ cf->ctx = cscfp[s]->ctx;
191
+
192
+ if (module->merge_srv_conf) {
193
+ rv = module->merge_srv_conf(cf,
194
+ ctx->srv_conf[mi],
195
+ cscfp[s]->ctx->srv_conf[mi]);
196
+ if (rv != NGX_CONF_OK) {
197
+ *cf = pcf;
198
+ return rv;
199
+ }
200
+ }
201
+ }
202
+ }
203
+
204
+ for (m = 0; cf->cycle->modules[m]; m++) {
205
+ if (cf->cycle->modules[m]->type != NGX_STREAM_MODULE) {
206
+ continue;
207
+ }
208
+
209
+ module = cf->cycle->modules[m]->ctx;
210
+
211
+ if (module->postconfiguration) {
212
+ if (module->postconfiguration(cf) != NGX_OK) {
213
+ return NGX_CONF_ERROR;
214
+ }
215
+ }
216
+ }
217
+
218
+ *cf = pcf;
219
+
220
+
221
+ if (ngx_array_init(&ports, cf->temp_pool, 4, sizeof(ngx_stream_conf_port_t))
222
+ != NGX_OK)
223
+ {
224
+ return NGX_CONF_ERROR;
225
+ }
226
+
227
+ listen = cmcf->listen.elts;
228
+
229
+ for (i = 0; i < cmcf->listen.nelts; i++) {
230
+ if (ngx_stream_add_ports(cf, &ports, &listen[i]) != NGX_OK) {
231
+ return NGX_CONF_ERROR;
232
+ }
233
+ }
234
+
235
+ return ngx_stream_optimize_servers(cf, &ports);
236
+ }
237
+
238
+
239
+ static ngx_int_t
240
+ ngx_stream_add_ports(ngx_conf_t *cf, ngx_array_t *ports,
241
+ ngx_stream_listen_t *listen)
242
+ {
243
+ in_port_t p;
244
+ ngx_uint_t i;
245
+ struct sockaddr *sa;
246
+ struct sockaddr_in *sin;
247
+ ngx_stream_conf_port_t *port;
248
+ ngx_stream_conf_addr_t *addr;
249
+ #if (NGX_HAVE_INET6)
250
+ struct sockaddr_in6 *sin6;
251
+ #endif
252
+
253
+ sa = &listen->u.sockaddr;
254
+
255
+ switch (sa->sa_family) {
256
+
257
+ #if (NGX_HAVE_INET6)
258
+ case AF_INET6:
259
+ sin6 = &listen->u.sockaddr_in6;
260
+ p = sin6->sin6_port;
261
+ break;
262
+ #endif
263
+
264
+ #if (NGX_HAVE_UNIX_DOMAIN)
265
+ case AF_UNIX:
266
+ p = 0;
267
+ break;
268
+ #endif
269
+
270
+ default: /* AF_INET */
271
+ sin = &listen->u.sockaddr_in;
272
+ p = sin->sin_port;
273
+ break;
274
+ }
275
+
276
+ port = ports->elts;
277
+ for (i = 0; i < ports->nelts; i++) {
278
+
279
+ if (p == port[i].port
280
+ && listen->type == port[i].type
281
+ && sa->sa_family == port[i].family)
282
+ {
283
+ /* a port is already in the port list */
284
+
285
+ port = &port[i];
286
+ goto found;
287
+ }
288
+ }
289
+
290
+ /* add a port to the port list */
291
+
292
+ port = ngx_array_push(ports);
293
+ if (port == NULL) {
294
+ return NGX_ERROR;
295
+ }
296
+
297
+ port->family = sa->sa_family;
298
+ port->type = listen->type;
299
+ port->port = p;
300
+
301
+ if (ngx_array_init(&port->addrs, cf->temp_pool, 2,
302
+ sizeof(ngx_stream_conf_addr_t))
303
+ != NGX_OK)
304
+ {
305
+ return NGX_ERROR;
306
+ }
307
+
308
+ found:
309
+
310
+ addr = ngx_array_push(&port->addrs);
311
+ if (addr == NULL) {
312
+ return NGX_ERROR;
313
+ }
314
+
315
+ addr->opt = *listen;
316
+
317
+ return NGX_OK;
318
+ }
319
+
320
+
321
+ static char *
322
+ ngx_stream_optimize_servers(ngx_conf_t *cf, ngx_array_t *ports)
323
+ {
324
+ ngx_uint_t i, p, last, bind_wildcard;
325
+ ngx_listening_t *ls;
326
+ ngx_stream_port_t *stport;
327
+ ngx_stream_conf_port_t *port;
328
+ ngx_stream_conf_addr_t *addr;
329
+ ngx_stream_core_srv_conf_t *cscf;
330
+
331
+ port = ports->elts;
332
+ for (p = 0; p < ports->nelts; p++) {
333
+
334
+ ngx_sort(port[p].addrs.elts, (size_t) port[p].addrs.nelts,
335
+ sizeof(ngx_stream_conf_addr_t), ngx_stream_cmp_conf_addrs);
336
+
337
+ addr = port[p].addrs.elts;
338
+ last = port[p].addrs.nelts;
339
+
340
+ /*
341
+ * if there is the binding to the "*:port" then we need to bind()
342
+ * to the "*:port" only and ignore the other bindings
343
+ */
344
+
345
+ if (addr[last - 1].opt.wildcard) {
346
+ addr[last - 1].opt.bind = 1;
347
+ bind_wildcard = 1;
348
+
349
+ } else {
350
+ bind_wildcard = 0;
351
+ }
352
+
353
+ i = 0;
354
+
355
+ while (i < last) {
356
+
357
+ if (bind_wildcard && !addr[i].opt.bind) {
358
+ i++;
359
+ continue;
360
+ }
361
+
362
+ ls = ngx_create_listening(cf, &addr[i].opt.u.sockaddr,
363
+ addr[i].opt.socklen);
364
+ if (ls == NULL) {
365
+ return NGX_CONF_ERROR;
366
+ }
367
+
368
+ ls->addr_ntop = 1;
369
+ ls->handler = ngx_stream_init_connection;
370
+ ls->pool_size = 256;
371
+ ls->type = addr[i].opt.type;
372
+
373
+ cscf = addr->opt.ctx->srv_conf[ngx_stream_core_module.ctx_index];
374
+
375
+ ls->logp = cscf->error_log;
376
+ ls->log.data = &ls->addr_text;
377
+ ls->log.handler = ngx_accept_log_error;
378
+
379
+ ls->backlog = addr[i].opt.backlog;
380
+
381
+ ls->wildcard = addr[i].opt.wildcard;
382
+
383
+ ls->keepalive = addr[i].opt.so_keepalive;
384
+ #if (NGX_HAVE_KEEPALIVE_TUNABLE)
385
+ ls->keepidle = addr[i].opt.tcp_keepidle;
386
+ ls->keepintvl = addr[i].opt.tcp_keepintvl;
387
+ ls->keepcnt = addr[i].opt.tcp_keepcnt;
388
+ #endif
389
+
390
+ #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
391
+ ls->ipv6only = addr[i].opt.ipv6only;
392
+ #endif
393
+
394
+ #if (NGX_HAVE_REUSEPORT)
395
+ ls->reuseport = addr[i].opt.reuseport;
396
+ #endif
397
+
398
+ stport = ngx_palloc(cf->pool, sizeof(ngx_stream_port_t));
399
+ if (stport == NULL) {
400
+ return NGX_CONF_ERROR;
401
+ }
402
+
403
+ ls->servers = stport;
404
+
405
+ stport->naddrs = i + 1;
406
+
407
+ switch (ls->sockaddr->sa_family) {
408
+ #if (NGX_HAVE_INET6)
409
+ case AF_INET6:
410
+ if (ngx_stream_add_addrs6(cf, stport, addr) != NGX_OK) {
411
+ return NGX_CONF_ERROR;
412
+ }
413
+ break;
414
+ #endif
415
+ default: /* AF_INET */
416
+ if (ngx_stream_add_addrs(cf, stport, addr) != NGX_OK) {
417
+ return NGX_CONF_ERROR;
418
+ }
419
+ break;
420
+ }
421
+
422
+ if (ngx_clone_listening(cf, ls) != NGX_OK) {
423
+ return NGX_CONF_ERROR;
424
+ }
425
+
426
+ addr++;
427
+ last--;
428
+ }
429
+ }
430
+
431
+ return NGX_CONF_OK;
432
+ }
433
+
434
+
435
+ static ngx_int_t
436
+ ngx_stream_add_addrs(ngx_conf_t *cf, ngx_stream_port_t *stport,
437
+ ngx_stream_conf_addr_t *addr)
438
+ {
439
+ u_char *p;
440
+ size_t len;
441
+ ngx_uint_t i;
442
+ struct sockaddr_in *sin;
443
+ ngx_stream_in_addr_t *addrs;
444
+ u_char buf[NGX_SOCKADDR_STRLEN];
445
+
446
+ stport->addrs = ngx_pcalloc(cf->pool,
447
+ stport->naddrs * sizeof(ngx_stream_in_addr_t));
448
+ if (stport->addrs == NULL) {
449
+ return NGX_ERROR;
450
+ }
451
+
452
+ addrs = stport->addrs;
453
+
454
+ for (i = 0; i < stport->naddrs; i++) {
455
+
456
+ sin = &addr[i].opt.u.sockaddr_in;
457
+ addrs[i].addr = sin->sin_addr.s_addr;
458
+
459
+ addrs[i].conf.ctx = addr[i].opt.ctx;
460
+ #if (NGX_STREAM_SSL)
461
+ addrs[i].conf.ssl = addr[i].opt.ssl;
462
+ #endif
463
+
464
+ len = ngx_sock_ntop(&addr[i].opt.u.sockaddr, addr[i].opt.socklen, buf,
465
+ NGX_SOCKADDR_STRLEN, 1);
466
+
467
+ p = ngx_pnalloc(cf->pool, len);
468
+ if (p == NULL) {
469
+ return NGX_ERROR;
470
+ }
471
+
472
+ ngx_memcpy(p, buf, len);
473
+
474
+ addrs[i].conf.addr_text.len = len;
475
+ addrs[i].conf.addr_text.data = p;
476
+ }
477
+
478
+ return NGX_OK;
479
+ }
480
+
481
+
482
+ #if (NGX_HAVE_INET6)
483
+
484
+ static ngx_int_t
485
+ ngx_stream_add_addrs6(ngx_conf_t *cf, ngx_stream_port_t *stport,
486
+ ngx_stream_conf_addr_t *addr)
487
+ {
488
+ u_char *p;
489
+ size_t len;
490
+ ngx_uint_t i;
491
+ struct sockaddr_in6 *sin6;
492
+ ngx_stream_in6_addr_t *addrs6;
493
+ u_char buf[NGX_SOCKADDR_STRLEN];
494
+
495
+ stport->addrs = ngx_pcalloc(cf->pool,
496
+ stport->naddrs * sizeof(ngx_stream_in6_addr_t));
497
+ if (stport->addrs == NULL) {
498
+ return NGX_ERROR;
499
+ }
500
+
501
+ addrs6 = stport->addrs;
502
+
503
+ for (i = 0; i < stport->naddrs; i++) {
504
+
505
+ sin6 = &addr[i].opt.u.sockaddr_in6;
506
+ addrs6[i].addr6 = sin6->sin6_addr;
507
+
508
+ addrs6[i].conf.ctx = addr[i].opt.ctx;
509
+ #if (NGX_STREAM_SSL)
510
+ addrs6[i].conf.ssl = addr[i].opt.ssl;
511
+ #endif
512
+
513
+ len = ngx_sock_ntop(&addr[i].opt.u.sockaddr, addr[i].opt.socklen, buf,
514
+ NGX_SOCKADDR_STRLEN, 1);
515
+
516
+ p = ngx_pnalloc(cf->pool, len);
517
+ if (p == NULL) {
518
+ return NGX_ERROR;
519
+ }
520
+
521
+ ngx_memcpy(p, buf, len);
522
+
523
+ addrs6[i].conf.addr_text.len = len;
524
+ addrs6[i].conf.addr_text.data = p;
525
+ }
526
+
527
+ return NGX_OK;
528
+ }
529
+
530
+ #endif
531
+
532
+
533
+ static ngx_int_t
534
+ ngx_stream_cmp_conf_addrs(const void *one, const void *two)
535
+ {
536
+ ngx_stream_conf_addr_t *first, *second;
537
+
538
+ first = (ngx_stream_conf_addr_t *) one;
539
+ second = (ngx_stream_conf_addr_t *) two;
540
+
541
+ if (first->opt.wildcard) {
542
+ /* a wildcard must be the last resort, shift it to the end */
543
+ return 1;
544
+ }
545
+
546
+ if (second->opt.wildcard) {
547
+ /* a wildcard must be the last resort, shift it to the end */
548
+ return -1;
549
+ }
550
+
551
+ if (first->opt.bind && !second->opt.bind) {
552
+ /* shift explicit bind()ed addresses to the start */
553
+ return -1;
554
+ }
555
+
556
+ if (!first->opt.bind && second->opt.bind) {
557
+ /* shift explicit bind()ed addresses to the start */
558
+ return 1;
559
+ }
560
+
561
+ /* do not sort by default */
562
+
563
+ return 0;
564
+ }