From 1e71b3927c8b9fe3085b62eb9cf6f5749ca21db0 Mon Sep 17 00:00:00 2001 From: Moses DeWitt-Monroy Date: Tue, 18 Nov 2025 16:02:16 -0600 Subject: [PATCH 1/5] feat(stream/proxy): add PROXY protocol v2 support for TCP upstreams - Implemented ngx_proxy_protocol_v2_write() to generate PROXYv2 headers - Supports both IPv4 and IPv6 addresses and ports - Added configuration directive `proxy_protocol_version 2` to enable v2 - Updated stream module to send PROXYv2 header to upstreams - Tested with netcat and Python decoder to verify header correctness --- compile_commands.json | 4320 ++++++++++++++++++++++++++ src/core/ngx_proxy_protocol.c | 83 + src/core/ngx_proxy_protocol.h | 30 +- src/stream/ngx_stream_proxy_module.c | 4098 ++++++++++++------------ 4 files changed, 6365 insertions(+), 2166 deletions(-) create mode 100644 compile_commands.json diff --git a/compile_commands.json b/compile_commands.json new file mode 100644 index 000000000..c615d3126 --- /dev/null +++ b/compile_commands.json @@ -0,0 +1,4320 @@ +[ + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_output_chain.o", + "src/core/ngx_output_chain.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_output_chain.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_output_chain.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_list.o", + "src/core/ngx_list.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_list.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_list.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_array.o", + "src/core/ngx_array.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_array.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_array.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/nginx.o", + "src/core/nginx.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/nginx.c", + "output": "/home/moses/projects/nginx/objs/src/core/nginx.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_palloc.o", + "src/core/ngx_palloc.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_palloc.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_palloc.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_buf.o", + "src/core/ngx_buf.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_buf.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_buf.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_string.o", + "src/core/ngx_string.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_string.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_string.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_hash.o", + "src/core/ngx_hash.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_hash.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_hash.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_log.o", + "src/core/ngx_log.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_log.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_log.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_parse_time.o", + "src/core/ngx_parse_time.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_parse_time.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_parse_time.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_queue.o", + "src/core/ngx_queue.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_queue.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_queue.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_parse.o", + "src/core/ngx_parse.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_parse.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_parse.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_inet.o", + "src/core/ngx_inet.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_inet.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_inet.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_crc32.o", + "src/core/ngx_crc32.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_crc32.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_crc32.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_file.o", + "src/core/ngx_file.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_file.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_file.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_murmurhash.o", + "src/core/ngx_murmurhash.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_murmurhash.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_murmurhash.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_slab.o", + "src/core/ngx_slab.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_slab.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_slab.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_rbtree.o", + "src/core/ngx_rbtree.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_rbtree.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_rbtree.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_radix_tree.o", + "src/core/ngx_radix_tree.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_radix_tree.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_radix_tree.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_md5.o", + "src/core/ngx_md5.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_md5.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_md5.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_times.o", + "src/core/ngx_times.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_times.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_times.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_sha1.o", + "src/core/ngx_sha1.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_sha1.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_sha1.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_shmtx.o", + "src/core/ngx_shmtx.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_shmtx.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_shmtx.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_connection.o", + "src/core/ngx_connection.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_connection.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_connection.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_cycle.o", + "src/core/ngx_cycle.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_cycle.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_cycle.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_rwlock.o", + "src/core/ngx_rwlock.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_rwlock.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_rwlock.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_spinlock.o", + "src/core/ngx_spinlock.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_spinlock.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_spinlock.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_cpuinfo.o", + "src/core/ngx_cpuinfo.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_cpuinfo.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_cpuinfo.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_resolver.o", + "src/core/ngx_resolver.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_resolver.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_resolver.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_conf_file.o", + "src/core/ngx_conf_file.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_conf_file.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_conf_file.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_module.o", + "src/core/ngx_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_module.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_open_file_cache.o", + "src/core/ngx_open_file_cache.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_open_file_cache.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_open_file_cache.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_crypt.o", + "src/core/ngx_crypt.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_crypt.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_crypt.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_syslog.o", + "src/core/ngx_syslog.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_syslog.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_syslog.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_proxy_protocol.o", + "src/core/ngx_proxy_protocol.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_proxy_protocol.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_proxy_protocol.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/event/ngx_event.o", + "src/event/ngx_event.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/event/ngx_event.c", + "output": "/home/moses/projects/nginx/objs/src/event/ngx_event.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/event/ngx_event_timer.o", + "src/event/ngx_event_timer.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/event/ngx_event_timer.c", + "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_timer.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/event/ngx_event_posted.o", + "src/event/ngx_event_posted.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/event/ngx_event_posted.c", + "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_posted.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/event/ngx_event_accept.o", + "src/event/ngx_event_accept.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/event/ngx_event_accept.c", + "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_accept.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/event/ngx_event_udp.o", + "src/event/ngx_event_udp.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/event/ngx_event_udp.c", + "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_udp.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/event/ngx_event_connect.o", + "src/event/ngx_event_connect.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/event/ngx_event_connect.c", + "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_connect.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/event/ngx_event_pipe.o", + "src/event/ngx_event_pipe.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/event/ngx_event_pipe.c", + "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_pipe.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_time.o", + "src/os/unix/ngx_time.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_time.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_time.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_errno.o", + "src/os/unix/ngx_errno.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_errno.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_errno.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_alloc.o", + "src/os/unix/ngx_alloc.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_alloc.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_alloc.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_files.o", + "src/os/unix/ngx_files.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_files.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_files.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_socket.o", + "src/os/unix/ngx_socket.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_socket.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_socket.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_recv.o", + "src/os/unix/ngx_recv.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_recv.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_recv.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_readv_chain.o", + "src/os/unix/ngx_readv_chain.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_readv_chain.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_readv_chain.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_udp_recv.o", + "src/os/unix/ngx_udp_recv.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_udp_recv.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_udp_recv.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_send.o", + "src/os/unix/ngx_send.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_send.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_send.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_writev_chain.o", + "src/os/unix/ngx_writev_chain.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_writev_chain.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_writev_chain.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_udp_send.o", + "src/os/unix/ngx_udp_send.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_udp_send.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_udp_send.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_udp_sendmsg_chain.o", + "src/os/unix/ngx_udp_sendmsg_chain.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_udp_sendmsg_chain.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_udp_sendmsg_chain.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_shmem.o", + "src/os/unix/ngx_shmem.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_shmem.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_shmem.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_channel.o", + "src/os/unix/ngx_channel.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_channel.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_channel.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_process.o", + "src/os/unix/ngx_process.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_process.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_process.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_daemon.o", + "src/os/unix/ngx_daemon.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_daemon.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_daemon.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_setaffinity.o", + "src/os/unix/ngx_setaffinity.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_setaffinity.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_setaffinity.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_setproctitle.o", + "src/os/unix/ngx_setproctitle.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_setproctitle.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_setproctitle.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_posix_init.o", + "src/os/unix/ngx_posix_init.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_posix_init.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_posix_init.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_user.o", + "src/os/unix/ngx_user.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_user.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_user.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_dlopen.o", + "src/os/unix/ngx_dlopen.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_dlopen.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_dlopen.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_process_cycle.o", + "src/os/unix/ngx_process_cycle.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_process_cycle.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_process_cycle.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_linux_init.o", + "src/os/unix/ngx_linux_init.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_linux_init.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_linux_init.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/event/modules/ngx_epoll_module.o", + "src/event/modules/ngx_epoll_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/event/modules/ngx_epoll_module.c", + "output": "/home/moses/projects/nginx/objs/src/event/modules/ngx_epoll_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/os/unix/ngx_linux_sendfile_chain.o", + "src/os/unix/ngx_linux_sendfile_chain.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/os/unix/ngx_linux_sendfile_chain.c", + "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_linux_sendfile_chain.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_bpf.o", + "src/core/ngx_bpf.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_bpf.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_bpf.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/src/core/ngx_regex.o", + "src/core/ngx_regex.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/core/ngx_regex.c", + "output": "/home/moses/projects/nginx/objs/src/core/ngx_regex.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http.o", + "src/http/ngx_http.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_special_response.o", + "src/http/ngx_http_special_response.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_special_response.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_special_response.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_core_module.o", + "src/http/ngx_http_core_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_core_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_core_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_request.o", + "src/http/ngx_http_request.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_request.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_request.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_parse.o", + "src/http/ngx_http_parse.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_parse.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_parse.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_log_module.o", + "src/http/modules/ngx_http_log_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_log_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_log_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_request_body.o", + "src/http/ngx_http_request_body.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_request_body.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_request_body.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_variables.o", + "src/http/ngx_http_variables.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_variables.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_variables.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_script.o", + "src/http/ngx_http_script.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_script.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_script.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_upstream.o", + "src/http/ngx_http_upstream.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_upstream.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_upstream.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_upstream_round_robin.o", + "src/http/ngx_http_upstream_round_robin.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_upstream_round_robin.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_upstream_round_robin.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_file_cache.o", + "src/http/ngx_http_file_cache.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_file_cache.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_file_cache.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_write_filter_module.o", + "src/http/ngx_http_write_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_write_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_write_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_header_filter_module.o", + "src/http/ngx_http_header_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_header_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_header_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_chunked_filter_module.o", + "src/http/modules/ngx_http_chunked_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_chunked_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_chunked_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_range_filter_module.o", + "src/http/modules/ngx_http_range_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_range_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_range_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_gzip_filter_module.o", + "src/http/modules/ngx_http_gzip_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_gzip_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_gzip_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_postpone_filter_module.o", + "src/http/ngx_http_postpone_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_postpone_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_postpone_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_ssi_filter_module.o", + "src/http/modules/ngx_http_ssi_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_ssi_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_ssi_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_charset_filter_module.o", + "src/http/modules/ngx_http_charset_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_charset_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_charset_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_userid_filter_module.o", + "src/http/modules/ngx_http_userid_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_userid_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_userid_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/ngx_http_copy_filter_module.o", + "src/http/ngx_http_copy_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/ngx_http_copy_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_copy_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_headers_filter_module.o", + "src/http/modules/ngx_http_headers_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_headers_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_headers_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_not_modified_filter_module.o", + "src/http/modules/ngx_http_not_modified_filter_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_not_modified_filter_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_not_modified_filter_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_autoindex_module.o", + "src/http/modules/ngx_http_autoindex_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_autoindex_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_autoindex_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_static_module.o", + "src/http/modules/ngx_http_static_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_static_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_static_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_mirror_module.o", + "src/http/modules/ngx_http_mirror_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_mirror_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_mirror_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_index_module.o", + "src/http/modules/ngx_http_index_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_index_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_index_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_try_files_module.o", + "src/http/modules/ngx_http_try_files_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_try_files_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_try_files_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_auth_basic_module.o", + "src/http/modules/ngx_http_auth_basic_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_auth_basic_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_auth_basic_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_access_module.o", + "src/http/modules/ngx_http_access_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_access_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_access_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_limit_conn_module.o", + "src/http/modules/ngx_http_limit_conn_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_limit_conn_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_limit_conn_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_limit_req_module.o", + "src/http/modules/ngx_http_limit_req_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_limit_req_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_limit_req_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_map_module.o", + "src/http/modules/ngx_http_map_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_map_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_map_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_geo_module.o", + "src/http/modules/ngx_http_geo_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_geo_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_geo_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_split_clients_module.o", + "src/http/modules/ngx_http_split_clients_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_split_clients_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_split_clients_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_referer_module.o", + "src/http/modules/ngx_http_referer_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_referer_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_referer_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_rewrite_module.o", + "src/http/modules/ngx_http_rewrite_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_rewrite_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_rewrite_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_proxy_module.o", + "src/http/modules/ngx_http_proxy_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_proxy_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_proxy_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_fastcgi_module.o", + "src/http/modules/ngx_http_fastcgi_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_fastcgi_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_fastcgi_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_uwsgi_module.o", + "src/http/modules/ngx_http_uwsgi_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_uwsgi_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_uwsgi_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_scgi_module.o", + "src/http/modules/ngx_http_scgi_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_scgi_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_scgi_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_memcached_module.o", + "src/http/modules/ngx_http_memcached_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_memcached_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_memcached_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_empty_gif_module.o", + "src/http/modules/ngx_http_empty_gif_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_empty_gif_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_empty_gif_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_upstream_ip_hash_module.o", + "src/http/modules/ngx_http_upstream_ip_hash_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_ip_hash_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_browser_module.o", + "src/http/modules/ngx_http_browser_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_browser_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_browser_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_upstream_hash_module.o", + "src/http/modules/ngx_http_upstream_hash_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_hash_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_hash_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_upstream_least_conn_module.o", + "src/http/modules/ngx_http_upstream_least_conn_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_least_conn_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_upstream_random_module.o", + "src/http/modules/ngx_http_upstream_random_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_random_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_random_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_upstream_keepalive_module.o", + "src/http/modules/ngx_http_upstream_keepalive_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_keepalive_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-I", + "src/http", + "-I", + "src/http/modules", + "-o", + "objs/src/http/modules/ngx_http_upstream_zone_module.o", + "src/http/modules/ngx_http_upstream_zone_module.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_zone_module.c", + "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_zone_module.o" + }, + { + "arguments": [ + "/usr/bin/cc", + "-c", + "-pipe", + "-O", + "-W", + "-Wall", + "-Wpointer-arith", + "-Wno-unused-parameter", + "-Werror", + "-g", + "-g3", + "-O0", + "-I", + "src/core", + "-I", + "src/event", + "-I", + "src/event/modules", + "-I", + "src/event/quic", + "-I", + "src/os/unix", + "-I", + "objs", + "-o", + "objs/ngx_modules.o", + "objs/ngx_modules.c" + ], + "directory": "/home/moses/projects/nginx", + "file": "/home/moses/projects/nginx/objs/ngx_modules.c", + "output": "/home/moses/projects/nginx/objs/ngx_modules.o" + } +] diff --git a/src/core/ngx_proxy_protocol.c b/src/core/ngx_proxy_protocol.c index 49888b986..96e8542db 100644 --- a/src/core/ngx_proxy_protocol.c +++ b/src/core/ngx_proxy_protocol.c @@ -5,13 +5,20 @@ */ +#include #include #include +#include +#include +#include +#include +#include #define NGX_PROXY_PROTOCOL_AF_INET 1 #define NGX_PROXY_PROTOCOL_AF_INET6 2 +#define NGX_PROXY_PROTOCOL_V2_SIG "\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A" #define ngx_proxy_protocol_parse_uint16(p) \ ( ((uint16_t) (p)[0] << 8) \ @@ -321,6 +328,82 @@ ngx_proxy_protocol_write(ngx_connection_t *c, u_char *buf, u_char *last) return ngx_slprintf(buf, last, " %ui %ui" CRLF, port, lport); } +u_char * +ngx_proxy_protocol_v2_write(ngx_connection_t *c, u_char *buf, u_char *last) { + u_char *buf_ptr = buf; + ngx_uint_t port, lport; + + if (last-buf < NGX_PROXY_PROTOCOL_V2_MAX_HEADER) { + ngx_log_error(NGX_LOG_ALERT, c->log, 0, "the buffer is to small for proxy protocol v2"); + return NULL; + } + + buf_ptr = ngx_cpymem(buf_ptr, NGX_PROXY_PROTOCOL_V2_SIG, 12); + + *buf_ptr++ = 0x21; + + port = ngx_inet_get_port(c->sockaddr); + lport = ngx_inet_get_port(c->local_sockaddr); + + switch (c->sockaddr->sa_family) { + case AF_INET: { + *buf_ptr++ = 0x11; + + *buf_ptr++ = 0x00; + *buf_ptr++ = 0x0C; + + struct sockaddr_in *sin; + sin = (struct sockaddr_in *) c->sockaddr; + + struct sockaddr_in *lsin; + lsin = (struct sockaddr_in *) c->local_sockaddr; + + buf_ptr = ngx_cpymem(buf_ptr, &sin->sin_addr.s_addr, 4); + buf_ptr = ngx_cpymem(buf_ptr, &lsin->sin_addr.s_addr, 4); + + *buf_ptr++ = (u_char) (port >> 8); + *buf_ptr++ = (u_char) port; + + *buf_ptr++ = (u_char) (lport >> 8); + *buf_ptr++ = (u_char) lport; + + break; + } +#if (NGX_HAVE_INET6) + case AF_INET6: { + *buf_ptr++ = 0x21; + + *buf_ptr++ = 0x00; + *buf_ptr++ = 0x24; + + struct sockaddr_in6 *sin6; + sin6 = (struct sockaddr_in6 *) c->sockaddr; + + struct sockaddr_in6 *lsin6; + lsin6 = (struct sockaddr_in6 *) c->local_sockaddr; + + buf_ptr = ngx_cpymem(buf_ptr, &sin6->sin6_addr, 16); + buf_ptr = ngx_cpymem(buf_ptr, &lsin6->sin6_addr, 16); + + *buf_ptr++ = (u_char)(port >> 8); + *buf_ptr++ = (u_char) port; + + *buf_ptr++ = (u_char)(lport >> 8); + *buf_ptr++ = (u_char) lport; + break; + } +#endif + default: { + *buf_ptr++ = 0x00; + *buf_ptr++ = 0x00; + *buf_ptr++ = 0x00; + break; + } + } + + return buf_ptr; +} + static u_char * ngx_proxy_protocol_v2_read(ngx_connection_t *c, u_char *buf, u_char *last) diff --git a/src/core/ngx_proxy_protocol.h b/src/core/ngx_proxy_protocol.h index d1749f57b..38e7c9f63 100644 --- a/src/core/ngx_proxy_protocol.h +++ b/src/core/ngx_proxy_protocol.h @@ -4,34 +4,30 @@ * Copyright (C) Nginx, Inc. */ - #ifndef _NGX_PROXY_PROTOCOL_H_INCLUDED_ #define _NGX_PROXY_PROTOCOL_H_INCLUDED_ - #include #include - -#define NGX_PROXY_PROTOCOL_V1_MAX_HEADER 107 -#define NGX_PROXY_PROTOCOL_MAX_HEADER 4096 - +#define NGX_PROXY_PROTOCOL_V1_MAX_HEADER 107 +#define NGX_PROXY_PROTOCOL_V2_MAX_HEADER 64 +#define NGX_PROXY_PROTOCOL_MAX_HEADER 4096 struct ngx_proxy_protocol_s { - ngx_str_t src_addr; - ngx_str_t dst_addr; - in_port_t src_port; - in_port_t dst_port; - ngx_str_t tlvs; + ngx_str_t src_addr; + ngx_str_t dst_addr; + in_port_t src_port; + in_port_t dst_port; + ngx_str_t tlvs; }; - -u_char *ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, - u_char *last); +u_char *ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last); u_char *ngx_proxy_protocol_write(ngx_connection_t *c, u_char *buf, - u_char *last); + u_char *last); +u_char *ngx_proxy_protocol_v2_write(ngx_connection_t *c, u_char *buf, + u_char *last); ngx_int_t ngx_proxy_protocol_get_tlv(ngx_connection_t *c, ngx_str_t *name, - ngx_str_t *value); - + ngx_str_t *value); #endif /* _NGX_PROXY_PROTOCOL_H_INCLUDED_ */ diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c index 300bdf681..33e9127ac 100644 --- a/src/stream/ngx_stream_proxy_module.c +++ b/src/stream/ngx_stream_proxy_module.c @@ -4,2680 +4,2480 @@ * Copyright (C) Nginx, Inc. */ - +#include "ngx_proxy_protocol.h" #include #include #include - typedef struct { - ngx_addr_t *addr; - ngx_stream_complex_value_t *value; + ngx_addr_t *addr; + ngx_stream_complex_value_t *value; #if (NGX_HAVE_TRANSPARENT_PROXY) - ngx_uint_t transparent; /* unsigned transparent:1; */ + ngx_uint_t transparent; /* unsigned transparent:1; */ #endif } ngx_stream_upstream_local_t; - typedef struct { - ngx_msec_t connect_timeout; - ngx_msec_t timeout; - ngx_msec_t next_upstream_timeout; - size_t buffer_size; - ngx_stream_complex_value_t *upload_rate; - ngx_stream_complex_value_t *download_rate; - ngx_uint_t requests; - ngx_uint_t responses; - ngx_uint_t next_upstream_tries; - ngx_flag_t next_upstream; - ngx_flag_t proxy_protocol; - ngx_flag_t half_close; - ngx_stream_upstream_local_t *local; - ngx_flag_t socket_keepalive; + ngx_msec_t connect_timeout; + ngx_msec_t timeout; + ngx_msec_t next_upstream_timeout; + size_t buffer_size; + ngx_stream_complex_value_t *upload_rate; + ngx_stream_complex_value_t *download_rate; + ngx_uint_t requests; + ngx_uint_t responses; + ngx_uint_t next_upstream_tries; + ngx_flag_t next_upstream; + ngx_flag_t proxy_protocol; + ngx_uint_t protocol_version; + ngx_flag_t half_close; + ngx_stream_upstream_local_t *local; + ngx_flag_t socket_keepalive; #if (NGX_STREAM_SSL) - ngx_flag_t ssl_enable; - ngx_flag_t ssl_session_reuse; - ngx_uint_t ssl_protocols; - ngx_str_t ssl_ciphers; - ngx_stream_complex_value_t *ssl_name; - ngx_flag_t ssl_server_name; + ngx_flag_t ssl_enable; + ngx_flag_t ssl_session_reuse; + ngx_uint_t ssl_protocols; + ngx_str_t ssl_ciphers; + ngx_stream_complex_value_t *ssl_name; + ngx_flag_t ssl_server_name; - ngx_flag_t ssl_verify; - ngx_uint_t ssl_verify_depth; - ngx_str_t ssl_trusted_certificate; - ngx_str_t ssl_crl; - ngx_stream_complex_value_t *ssl_certificate; - ngx_stream_complex_value_t *ssl_certificate_key; - ngx_ssl_cache_t *ssl_certificate_cache; - ngx_array_t *ssl_passwords; - ngx_array_t *ssl_conf_commands; + ngx_flag_t ssl_verify; + ngx_uint_t ssl_verify_depth; + ngx_str_t ssl_trusted_certificate; + ngx_str_t ssl_crl; + ngx_stream_complex_value_t *ssl_certificate; + ngx_stream_complex_value_t *ssl_certificate_key; + ngx_ssl_cache_t *ssl_certificate_cache; + ngx_array_t *ssl_passwords; + ngx_array_t *ssl_conf_commands; - ngx_ssl_t *ssl; + ngx_ssl_t *ssl; #endif - ngx_stream_upstream_srv_conf_t *upstream; - ngx_stream_complex_value_t *upstream_value; + ngx_stream_upstream_srv_conf_t *upstream; + ngx_stream_complex_value_t *upstream_value; } ngx_stream_proxy_srv_conf_t; - static void ngx_stream_proxy_handler(ngx_stream_session_t *s); static ngx_int_t ngx_stream_proxy_eval(ngx_stream_session_t *s, - ngx_stream_proxy_srv_conf_t *pscf); + ngx_stream_proxy_srv_conf_t *pscf); static ngx_int_t ngx_stream_proxy_set_local(ngx_stream_session_t *s, - ngx_stream_upstream_t *u, ngx_stream_upstream_local_t *local); + ngx_stream_upstream_t *u, + ngx_stream_upstream_local_t *local); static void ngx_stream_proxy_connect(ngx_stream_session_t *s); static void ngx_stream_proxy_init_upstream(ngx_stream_session_t *s); static void ngx_stream_proxy_resolve_handler(ngx_resolver_ctx_t *ctx); static void ngx_stream_proxy_upstream_handler(ngx_event_t *ev); static void ngx_stream_proxy_downstream_handler(ngx_event_t *ev); static void ngx_stream_proxy_process_connection(ngx_event_t *ev, - ngx_uint_t from_upstream); + ngx_uint_t from_upstream); static void ngx_stream_proxy_connect_handler(ngx_event_t *ev); static ngx_int_t ngx_stream_proxy_test_connect(ngx_connection_t *c); static void ngx_stream_proxy_process(ngx_stream_session_t *s, - ngx_uint_t from_upstream, ngx_uint_t do_write); + ngx_uint_t from_upstream, + ngx_uint_t do_write); static ngx_int_t ngx_stream_proxy_test_finalize(ngx_stream_session_t *s, - ngx_uint_t from_upstream); + ngx_uint_t from_upstream); static void ngx_stream_proxy_next_upstream(ngx_stream_session_t *s); static void ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc); static u_char *ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf, - size_t len); + size_t len); static void *ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf); static char *ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, - void *child); + void *child); static char *ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); #if (NGX_STREAM_SSL) static ngx_int_t ngx_stream_proxy_send_proxy_protocol(ngx_stream_session_t *s); static char *ngx_stream_proxy_ssl_certificate_cache(ngx_conf_t *cf, - ngx_command_t *cmd, void *conf); + ngx_command_t *cmd, + void *conf); static char *ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf, - ngx_command_t *cmd, void *conf); + ngx_command_t *cmd, void *conf); static char *ngx_stream_proxy_ssl_conf_command_check(ngx_conf_t *cf, void *post, - void *data); + void *data); static void ngx_stream_proxy_ssl_init_connection(ngx_stream_session_t *s); static void ngx_stream_proxy_ssl_handshake(ngx_connection_t *pc); static void ngx_stream_proxy_ssl_save_session(ngx_connection_t *c); static ngx_int_t ngx_stream_proxy_ssl_name(ngx_stream_session_t *s); static ngx_int_t ngx_stream_proxy_ssl_certificate(ngx_stream_session_t *s); static ngx_int_t ngx_stream_proxy_merge_ssl(ngx_conf_t *cf, - ngx_stream_proxy_srv_conf_t *conf, ngx_stream_proxy_srv_conf_t *prev); -static ngx_int_t ngx_stream_proxy_merge_ssl_passwords(ngx_conf_t *cf, - ngx_stream_proxy_srv_conf_t *conf, ngx_stream_proxy_srv_conf_t *prev); + ngx_stream_proxy_srv_conf_t *conf, + ngx_stream_proxy_srv_conf_t *prev); +static ngx_int_t +ngx_stream_proxy_merge_ssl_passwords(ngx_conf_t *cf, + ngx_stream_proxy_srv_conf_t *conf, + ngx_stream_proxy_srv_conf_t *prev); static ngx_int_t ngx_stream_proxy_set_ssl(ngx_conf_t *cf, - ngx_stream_proxy_srv_conf_t *pscf); + ngx_stream_proxy_srv_conf_t *pscf); +static ngx_conf_bitmask_t ngx_stream_proxy_ssl_protocols[] = { + {ngx_string("SSLv2"), NGX_SSL_SSLv2}, + {ngx_string("SSLv3"), NGX_SSL_SSLv3}, + {ngx_string("TLSv1"), NGX_SSL_TLSv1}, + {ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1}, + {ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2}, + {ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3}, + {ngx_null_string, 0}}; -static ngx_conf_bitmask_t ngx_stream_proxy_ssl_protocols[] = { - { ngx_string("SSLv2"), NGX_SSL_SSLv2 }, - { ngx_string("SSLv3"), NGX_SSL_SSLv3 }, - { ngx_string("TLSv1"), NGX_SSL_TLSv1 }, - { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 }, - { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 }, - { ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3 }, - { ngx_null_string, 0 } -}; - -static ngx_conf_post_t ngx_stream_proxy_ssl_conf_command_post = - { ngx_stream_proxy_ssl_conf_command_check }; +static ngx_conf_post_t ngx_stream_proxy_ssl_conf_command_post = { + ngx_stream_proxy_ssl_conf_command_check}; #endif +static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_downstream_buffer = { + ngx_conf_deprecated, "proxy_downstream_buffer", "proxy_buffer_size"}; -static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_downstream_buffer = { - ngx_conf_deprecated, "proxy_downstream_buffer", "proxy_buffer_size" -}; +static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_upstream_buffer = { + ngx_conf_deprecated, "proxy_upstream_buffer", "proxy_buffer_size"}; -static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_upstream_buffer = { - ngx_conf_deprecated, "proxy_upstream_buffer", "proxy_buffer_size" -}; +static ngx_command_t ngx_stream_proxy_commands[] = { + {ngx_string("proxy_pass"), NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_stream_proxy_pass, NGX_STREAM_SRV_CONF_OFFSET, 0, NULL}, -static ngx_command_t ngx_stream_proxy_commands[] = { + {ngx_string("proxy_bind"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE12, + ngx_stream_proxy_bind, NGX_STREAM_SRV_CONF_OFFSET, 0, NULL}, - { ngx_string("proxy_pass"), - NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_stream_proxy_pass, - NGX_STREAM_SRV_CONF_OFFSET, - 0, - NULL }, + {ngx_string("proxy_socket_keepalive"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, + ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, socket_keepalive), NULL}, - { ngx_string("proxy_bind"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE12, - ngx_stream_proxy_bind, - NGX_STREAM_SRV_CONF_OFFSET, - 0, - NULL }, + {ngx_string("proxy_connect_timeout"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_msec_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, connect_timeout), NULL}, - { ngx_string("proxy_socket_keepalive"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, socket_keepalive), - NULL }, + {ngx_string("proxy_timeout"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_msec_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, timeout), NULL}, - { ngx_string("proxy_connect_timeout"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_msec_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, connect_timeout), - NULL }, + {ngx_string("proxy_buffer_size"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_size_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), NULL}, - { ngx_string("proxy_timeout"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_msec_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, timeout), - NULL }, + {ngx_string("proxy_downstream_buffer"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_size_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), + &ngx_conf_deprecated_proxy_downstream_buffer}, - { ngx_string("proxy_buffer_size"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_size_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), - NULL }, + {ngx_string("proxy_upstream_buffer"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_size_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), + &ngx_conf_deprecated_proxy_upstream_buffer}, - { ngx_string("proxy_downstream_buffer"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_size_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), - &ngx_conf_deprecated_proxy_downstream_buffer }, + {ngx_string("proxy_upload_rate"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_stream_set_complex_value_size_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, upload_rate), NULL}, - { ngx_string("proxy_upstream_buffer"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_size_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), - &ngx_conf_deprecated_proxy_upstream_buffer }, + {ngx_string("proxy_download_rate"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_stream_set_complex_value_size_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, download_rate), NULL}, - { ngx_string("proxy_upload_rate"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_stream_set_complex_value_size_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, upload_rate), - NULL }, + {ngx_string("proxy_requests"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_num_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, requests), NULL}, - { ngx_string("proxy_download_rate"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_stream_set_complex_value_size_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, download_rate), - NULL }, + {ngx_string("proxy_responses"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_num_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, responses), NULL}, - { ngx_string("proxy_requests"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_num_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, requests), - NULL }, + {ngx_string("proxy_next_upstream"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, + ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, next_upstream), NULL}, - { ngx_string("proxy_responses"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_num_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, responses), - NULL }, + {ngx_string("proxy_next_upstream_tries"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_num_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_tries), NULL}, - { ngx_string("proxy_next_upstream"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, next_upstream), - NULL }, + {ngx_string("proxy_next_upstream_timeout"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_msec_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_timeout), NULL}, - { ngx_string("proxy_next_upstream_tries"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_num_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_tries), - NULL }, + {ngx_string("proxy_protocol"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, + ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, proxy_protocol), NULL}, - { ngx_string("proxy_next_upstream_timeout"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_msec_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_timeout), - NULL }, + {ngx_string("proxy_protocol_version"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_num_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, protocol_version), NULL}, - { ngx_string("proxy_protocol"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, proxy_protocol), - NULL }, - - { ngx_string("proxy_half_close"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, half_close), - NULL }, + {ngx_string("proxy_half_close"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, + ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, half_close), NULL}, #if (NGX_STREAM_SSL) - { ngx_string("proxy_ssl"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_enable), - NULL }, + {ngx_string("proxy_ssl"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, + ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_enable), NULL}, - { ngx_string("proxy_ssl_session_reuse"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_session_reuse), - NULL }, + {ngx_string("proxy_ssl_session_reuse"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, + ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_session_reuse), NULL}, - { ngx_string("proxy_ssl_protocols"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE, - ngx_conf_set_bitmask_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_protocols), - &ngx_stream_proxy_ssl_protocols }, + {ngx_string("proxy_ssl_protocols"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_1MORE, + ngx_conf_set_bitmask_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_protocols), + &ngx_stream_proxy_ssl_protocols}, - { ngx_string("proxy_ssl_ciphers"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_str_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_ciphers), - NULL }, + {ngx_string("proxy_ssl_ciphers"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_str_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_ciphers), NULL}, - { ngx_string("proxy_ssl_name"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_stream_set_complex_value_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_name), - NULL }, + {ngx_string("proxy_ssl_name"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_stream_set_complex_value_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_name), NULL}, - { ngx_string("proxy_ssl_server_name"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_server_name), - NULL }, + {ngx_string("proxy_ssl_server_name"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, + ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_server_name), NULL}, - { ngx_string("proxy_ssl_verify"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, - ngx_conf_set_flag_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify), - NULL }, + {ngx_string("proxy_ssl_verify"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, + ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify), NULL}, - { ngx_string("proxy_ssl_verify_depth"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_num_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify_depth), - NULL }, + {ngx_string("proxy_ssl_verify_depth"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_num_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify_depth), NULL}, - { ngx_string("proxy_ssl_trusted_certificate"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_str_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_trusted_certificate), - NULL }, + {ngx_string("proxy_ssl_trusted_certificate"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_str_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_trusted_certificate), NULL}, - { ngx_string("proxy_ssl_crl"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_conf_set_str_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_crl), - NULL }, + {ngx_string("proxy_ssl_crl"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_str_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_crl), NULL}, - { ngx_string("proxy_ssl_certificate"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_stream_set_complex_value_zero_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate), - NULL }, + {ngx_string("proxy_ssl_certificate"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_stream_set_complex_value_zero_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate), NULL}, - { ngx_string("proxy_ssl_certificate_key"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_stream_set_complex_value_zero_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate_key), - NULL }, + {ngx_string("proxy_ssl_certificate_key"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_stream_set_complex_value_zero_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate_key), NULL}, - { ngx_string("proxy_ssl_certificate_cache"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE123, - ngx_stream_proxy_ssl_certificate_cache, - NGX_STREAM_SRV_CONF_OFFSET, - 0, - NULL }, + {ngx_string("proxy_ssl_certificate_cache"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE123, + ngx_stream_proxy_ssl_certificate_cache, NGX_STREAM_SRV_CONF_OFFSET, 0, + NULL}, - { ngx_string("proxy_ssl_password_file"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, - ngx_stream_proxy_ssl_password_file, - NGX_STREAM_SRV_CONF_OFFSET, - 0, - NULL }, + {ngx_string("proxy_ssl_password_file"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_stream_proxy_ssl_password_file, NGX_STREAM_SRV_CONF_OFFSET, 0, NULL}, - { ngx_string("proxy_ssl_conf_command"), - NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE2, - ngx_conf_set_keyval_slot, - NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_conf_commands), - &ngx_stream_proxy_ssl_conf_command_post }, + {ngx_string("proxy_ssl_conf_command"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE2, + ngx_conf_set_keyval_slot, NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_conf_commands), + &ngx_stream_proxy_ssl_conf_command_post}, #endif - ngx_null_command + ngx_null_command}; + +static ngx_stream_module_t ngx_stream_proxy_module_ctx = { + NULL, /* preconfiguration */ + NULL, /* postconfiguration */ + + NULL, /* create main configuration */ + NULL, /* init main configuration */ + + ngx_stream_proxy_create_srv_conf, /* create server configuration */ + ngx_stream_proxy_merge_srv_conf /* merge server configuration */ }; - -static ngx_stream_module_t ngx_stream_proxy_module_ctx = { - NULL, /* preconfiguration */ - NULL, /* postconfiguration */ - - NULL, /* create main configuration */ - NULL, /* init main configuration */ - - ngx_stream_proxy_create_srv_conf, /* create server configuration */ - ngx_stream_proxy_merge_srv_conf /* merge server configuration */ -}; - - -ngx_module_t ngx_stream_proxy_module = { +ngx_module_t ngx_stream_proxy_module = { NGX_MODULE_V1, - &ngx_stream_proxy_module_ctx, /* module context */ - ngx_stream_proxy_commands, /* module directives */ - NGX_STREAM_MODULE, /* module type */ - NULL, /* init master */ - NULL, /* init module */ - NULL, /* init process */ - NULL, /* init thread */ - NULL, /* exit thread */ - NULL, /* exit process */ - NULL, /* exit master */ - NGX_MODULE_V1_PADDING -}; + &ngx_stream_proxy_module_ctx, /* module context */ + ngx_stream_proxy_commands, /* module directives */ + NGX_STREAM_MODULE, /* module type */ + NULL, /* init master */ + NULL, /* init module */ + NULL, /* init process */ + NULL, /* init thread */ + NULL, /* exit thread */ + NULL, /* exit process */ + NULL, /* exit master */ + NGX_MODULE_V1_PADDING}; +static void ngx_stream_proxy_handler(ngx_stream_session_t *s) { + u_char *p; + ngx_str_t *host; + ngx_uint_t i; + ngx_connection_t *c; + ngx_resolver_ctx_t *ctx, temp; + ngx_stream_upstream_t *u; + ngx_stream_core_srv_conf_t *cscf; + ngx_stream_proxy_srv_conf_t *pscf; + ngx_stream_upstream_srv_conf_t *uscf, **uscfp; + ngx_stream_upstream_main_conf_t *umcf; -static void -ngx_stream_proxy_handler(ngx_stream_session_t *s) -{ - u_char *p; - ngx_str_t *host; - ngx_uint_t i; - ngx_connection_t *c; - ngx_resolver_ctx_t *ctx, temp; - ngx_stream_upstream_t *u; - ngx_stream_core_srv_conf_t *cscf; - ngx_stream_proxy_srv_conf_t *pscf; - ngx_stream_upstream_srv_conf_t *uscf, **uscfp; - ngx_stream_upstream_main_conf_t *umcf; + c = s->connection; - c = s->connection; + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connection handler"); - ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, - "proxy connection handler"); + u = ngx_pcalloc(c->pool, sizeof(ngx_stream_upstream_t)); + if (u == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } - u = ngx_pcalloc(c->pool, sizeof(ngx_stream_upstream_t)); - if (u == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; + s->upstream = u; + + s->log_handler = ngx_stream_proxy_log_error; + + u->requests = 1; + + u->peer.log = c->log; + u->peer.log_error = NGX_ERROR_ERR; + + if (ngx_stream_proxy_set_local(s, u, pscf->local) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + if (pscf->socket_keepalive) { + u->peer.so_keepalive = 1; + } + + u->peer.type = c->type; + u->start_sec = ngx_time(); + + c->write->handler = ngx_stream_proxy_downstream_handler; + c->read->handler = ngx_stream_proxy_downstream_handler; + + s->upstream_states = + ngx_array_create(c->pool, 1, sizeof(ngx_stream_upstream_state_t)); + if (s->upstream_states == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + p = ngx_pnalloc(c->pool, pscf->buffer_size); + if (p == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + u->downstream_buf.start = p; + u->downstream_buf.end = p + pscf->buffer_size; + u->downstream_buf.pos = p; + u->downstream_buf.last = p; + + if (c->read->ready) { + ngx_post_event(c->read, &ngx_posted_events); + } + + if (pscf->upstream_value) { + if (ngx_stream_proxy_eval(s, pscf) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; } + } - s->upstream = u; + if (u->resolved == NULL) { - s->log_handler = ngx_stream_proxy_log_error; + uscf = pscf->upstream; - u->requests = 1; - - u->peer.log = c->log; - u->peer.log_error = NGX_ERROR_ERR; - - if (ngx_stream_proxy_set_local(s, u, pscf->local) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - if (pscf->socket_keepalive) { - u->peer.so_keepalive = 1; - } - - u->peer.type = c->type; - u->start_sec = ngx_time(); - - c->write->handler = ngx_stream_proxy_downstream_handler; - c->read->handler = ngx_stream_proxy_downstream_handler; - - s->upstream_states = ngx_array_create(c->pool, 1, - sizeof(ngx_stream_upstream_state_t)); - if (s->upstream_states == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - p = ngx_pnalloc(c->pool, pscf->buffer_size); - if (p == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - u->downstream_buf.start = p; - u->downstream_buf.end = p + pscf->buffer_size; - u->downstream_buf.pos = p; - u->downstream_buf.last = p; - - if (c->read->ready) { - ngx_post_event(c->read, &ngx_posted_events); - } - - if (pscf->upstream_value) { - if (ngx_stream_proxy_eval(s, pscf) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - } - - if (u->resolved == NULL) { - - uscf = pscf->upstream; - - } else { + } else { #if (NGX_STREAM_SSL) - u->ssl_name = u->resolved->host; + u->ssl_name = u->resolved->host; #endif - host = &u->resolved->host; + host = &u->resolved->host; - umcf = ngx_stream_get_module_main_conf(s, ngx_stream_upstream_module); + umcf = ngx_stream_get_module_main_conf(s, ngx_stream_upstream_module); - uscfp = umcf->upstreams.elts; + uscfp = umcf->upstreams.elts; - for (i = 0; i < umcf->upstreams.nelts; i++) { + for (i = 0; i < umcf->upstreams.nelts; i++) { - uscf = uscfp[i]; + uscf = uscfp[i]; - if (uscf->host.len == host->len - && ((uscf->port == 0 && u->resolved->no_port) - || uscf->port == u->resolved->port) - && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) - { - goto found; - } - } - - if (u->resolved->sockaddr) { - - if (u->resolved->port == 0 - && u->resolved->sockaddr->sa_family != AF_UNIX) - { - ngx_log_error(NGX_LOG_ERR, c->log, 0, - "no port in upstream \"%V\"", host); - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - if (ngx_stream_upstream_create_round_robin_peer(s, u->resolved) - != NGX_OK) - { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - ngx_stream_proxy_connect(s); - - return; - } - - if (u->resolved->port == 0) { - ngx_log_error(NGX_LOG_ERR, c->log, 0, - "no port in upstream \"%V\"", host); - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - temp.name = *host; - - cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); - - ctx = ngx_resolve_start(cscf->resolver, &temp); - if (ctx == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - if (ctx == NGX_NO_RESOLVER) { - ngx_log_error(NGX_LOG_ERR, c->log, 0, - "no resolver defined to resolve %V", host); - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - ctx->name = *host; - ctx->handler = ngx_stream_proxy_resolve_handler; - ctx->data = s; - ctx->timeout = cscf->resolver_timeout; - - u->resolved->ctx = ctx; - - if (ngx_resolve_name(ctx) != NGX_OK) { - u->resolved->ctx = NULL; - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - return; + if (uscf->host.len == host->len && + ((uscf->port == 0 && u->resolved->no_port) || + uscf->port == u->resolved->port) && + ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) { + goto found; + } } -found: + if (u->resolved->sockaddr) { - if (uscf == NULL) { - ngx_log_error(NGX_LOG_ALERT, c->log, 0, "no upstream configuration"); + if (u->resolved->port == 0 && + u->resolved->sockaddr->sa_family != AF_UNIX) { + ngx_log_error(NGX_LOG_ERR, c->log, 0, "no port in upstream \"%V\"", + host); ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); return; - } + } - u->upstream = uscf; - -#if (NGX_STREAM_SSL) - u->ssl_name = uscf->host; -#endif - - if (uscf->peer.init(s, uscf) != NGX_OK) { + if (ngx_stream_upstream_create_round_robin_peer(s, u->resolved) != + NGX_OK) { ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); return; + } + + ngx_stream_proxy_connect(s); + + return; } - u->peer.start_time = ngx_current_msec; - - if (pscf->next_upstream_tries - && u->peer.tries > pscf->next_upstream_tries) - { - u->peer.tries = pscf->next_upstream_tries; + if (u->resolved->port == 0) { + ngx_log_error(NGX_LOG_ERR, c->log, 0, "no port in upstream \"%V\"", host); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; } - ngx_stream_proxy_connect(s); -} - - -static ngx_int_t -ngx_stream_proxy_eval(ngx_stream_session_t *s, - ngx_stream_proxy_srv_conf_t *pscf) -{ - ngx_str_t host; - ngx_url_t url; - ngx_stream_upstream_t *u; - - if (ngx_stream_complex_value(s, pscf->upstream_value, &host) != NGX_OK) { - return NGX_ERROR; - } - - ngx_memzero(&url, sizeof(ngx_url_t)); - - url.url = host; - url.no_resolve = 1; - - if (ngx_parse_url(s->connection->pool, &url) != NGX_OK) { - if (url.err) { - ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, - "%s in upstream \"%V\"", url.err, &url.url); - } - - return NGX_ERROR; - } - - u = s->upstream; - - u->resolved = ngx_pcalloc(s->connection->pool, - sizeof(ngx_stream_upstream_resolved_t)); - if (u->resolved == NULL) { - return NGX_ERROR; - } - - if (url.addrs) { - u->resolved->sockaddr = url.addrs[0].sockaddr; - u->resolved->socklen = url.addrs[0].socklen; - u->resolved->name = url.addrs[0].name; - u->resolved->naddrs = 1; - } - - u->resolved->host = url.host; - u->resolved->port = url.port; - u->resolved->no_port = url.no_port; - - return NGX_OK; -} - - -static ngx_int_t -ngx_stream_proxy_set_local(ngx_stream_session_t *s, ngx_stream_upstream_t *u, - ngx_stream_upstream_local_t *local) -{ - ngx_int_t rc; - ngx_str_t val; - ngx_addr_t *addr; - - if (local == NULL) { - u->peer.local = NULL; - return NGX_OK; - } - -#if (NGX_HAVE_TRANSPARENT_PROXY) - u->peer.transparent = local->transparent; -#endif - - if (local->value == NULL) { - u->peer.local = local->addr; - return NGX_OK; - } - - if (ngx_stream_complex_value(s, local->value, &val) != NGX_OK) { - return NGX_ERROR; - } - - if (val.len == 0) { - u->peer.local = NULL; - return NGX_OK; - } - - addr = ngx_palloc(s->connection->pool, sizeof(ngx_addr_t)); - if (addr == NULL) { - return NGX_ERROR; - } - - rc = ngx_parse_addr_port(s->connection->pool, addr, val.data, val.len); - if (rc == NGX_ERROR) { - return NGX_ERROR; - } - - if (rc != NGX_OK) { - ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, - "invalid local address \"%V\"", &val); - u->peer.local = NULL; - return NGX_OK; - } - - addr->name = val; - u->peer.local = addr; - - return NGX_OK; -} - - -static void -ngx_stream_proxy_connect(ngx_stream_session_t *s) -{ - ngx_int_t rc; - ngx_connection_t *c, *pc; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - - c = s->connection; - - c->log->action = "connecting to upstream"; - - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - - u = s->upstream; - - u->connected = 0; - u->proxy_protocol = pscf->proxy_protocol; - - if (u->state) { - u->state->response_time = ngx_current_msec - u->start_time; - } - - u->state = ngx_array_push(s->upstream_states); - if (u->state == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t)); - - u->start_time = ngx_current_msec; - - u->state->connect_time = (ngx_msec_t) -1; - u->state->first_byte_time = (ngx_msec_t) -1; - u->state->response_time = (ngx_msec_t) -1; - - rc = ngx_event_connect_peer(&u->peer); - - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc); - - if (rc == NGX_ERROR) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - u->state->peer = u->peer.name; - -#if (NGX_STREAM_UPSTREAM_ZONE) - if (u->upstream && u->upstream->shm_zone - && (u->upstream->flags & NGX_STREAM_UPSTREAM_MODIFY)) - { - u->state->peer = ngx_palloc(s->connection->pool, - sizeof(ngx_str_t) + u->peer.name->len); - if (u->state->peer == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - u->state->peer->len = u->peer.name->len; - u->state->peer->data = (u_char *) (u->state->peer + 1); - ngx_memcpy(u->state->peer->data, u->peer.name->data, u->peer.name->len); - - u->peer.name = u->state->peer; - } -#endif - - if (rc == NGX_BUSY) { - ngx_log_error(NGX_LOG_ERR, c->log, 0, "no live upstreams"); - ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); - return; - } - - if (rc == NGX_DECLINED) { - ngx_stream_proxy_next_upstream(s); - return; - } - - /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */ - - pc = u->peer.connection; - - pc->data = s; - pc->log = c->log; - pc->pool = c->pool; - pc->read->log = c->log; - pc->write->log = c->log; - - if (rc != NGX_AGAIN) { - ngx_stream_proxy_init_upstream(s); - return; - } - - pc->read->handler = ngx_stream_proxy_connect_handler; - pc->write->handler = ngx_stream_proxy_connect_handler; - - ngx_add_timer(pc->write, pscf->connect_timeout); -} - - -static void -ngx_stream_proxy_init_upstream(ngx_stream_session_t *s) -{ - u_char *p; - ngx_chain_t *cl; - ngx_connection_t *c, *pc; - ngx_log_handler_pt handler; - ngx_stream_upstream_t *u; - ngx_stream_core_srv_conf_t *cscf; - ngx_stream_proxy_srv_conf_t *pscf; - - u = s->upstream; - pc = u->peer.connection; + temp.name = *host; cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); - if (pc->type == SOCK_STREAM - && cscf->tcp_nodelay - && ngx_tcp_nodelay(pc) != NGX_OK) - { - ngx_stream_proxy_next_upstream(s); - return; + ctx = ngx_resolve_start(cscf->resolver, &temp); + if (ctx == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; } - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + if (ctx == NGX_NO_RESOLVER) { + ngx_log_error(NGX_LOG_ERR, c->log, 0, "no resolver defined to resolve %V", + host); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + ctx->name = *host; + ctx->handler = ngx_stream_proxy_resolve_handler; + ctx->data = s; + ctx->timeout = cscf->resolver_timeout; + + u->resolved->ctx = ctx; + + if (ngx_resolve_name(ctx) != NGX_OK) { + u->resolved->ctx = NULL; + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + return; + } + +found: + + if (uscf == NULL) { + ngx_log_error(NGX_LOG_ALERT, c->log, 0, "no upstream configuration"); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + u->upstream = uscf; #if (NGX_STREAM_SSL) - - if (pc->type == SOCK_STREAM && pscf->ssl_enable) { - - if (u->proxy_protocol) { - if (ngx_stream_proxy_send_proxy_protocol(s) != NGX_OK) { - return; - } - - u->proxy_protocol = 0; - } - - if (pc->ssl == NULL) { - ngx_stream_proxy_ssl_init_connection(s); - return; - } - } - + u->ssl_name = uscf->host; #endif - c = s->connection; + if (uscf->peer.init(s, uscf) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } - if (c->log->log_level >= NGX_LOG_INFO) { - ngx_str_t str; - u_char addr[NGX_SOCKADDR_STRLEN]; + u->peer.start_time = ngx_current_msec; - str.len = NGX_SOCKADDR_STRLEN; - str.data = addr; + if (pscf->next_upstream_tries && u->peer.tries > pscf->next_upstream_tries) { + u->peer.tries = pscf->next_upstream_tries; + } - if (ngx_connection_local_sockaddr(pc, &str, 1) == NGX_OK) { - handler = c->log->handler; - c->log->handler = NULL; - - ngx_log_error(NGX_LOG_INFO, c->log, 0, - "%sproxy %V connected to %V", - pc->type == SOCK_DGRAM ? "udp " : "", - &str, u->peer.name); - - c->log->handler = handler; - } - } - - u->state->connect_time = ngx_current_msec - u->start_time; - - if (u->peer.notify) { - u->peer.notify(&u->peer, u->peer.data, - NGX_STREAM_UPSTREAM_NOTIFY_CONNECT); - } - - if (u->upstream_buf.start == NULL) { - p = ngx_pnalloc(c->pool, pscf->buffer_size); - if (p == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - u->upstream_buf.start = p; - u->upstream_buf.end = p + pscf->buffer_size; - u->upstream_buf.pos = p; - u->upstream_buf.last = p; - } - - if (c->buffer && c->buffer->pos <= c->buffer->last) { - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream proxy add preread buffer: %uz", - c->buffer->last - c->buffer->pos); - - cl = ngx_chain_get_free_buf(c->pool, &u->free); - if (cl == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - *cl->buf = *c->buffer; - - cl->buf->tag = (ngx_buf_tag_t) &ngx_stream_proxy_module; - cl->buf->temporary = (cl->buf->pos == cl->buf->last) ? 0 : 1; - cl->buf->flush = 1; - - cl->next = u->upstream_out; - u->upstream_out = cl; - } - - if (u->proxy_protocol) { - ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream proxy add PROXY protocol header"); - - cl = ngx_chain_get_free_buf(c->pool, &u->free); - if (cl == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - p = ngx_pnalloc(c->pool, NGX_PROXY_PROTOCOL_V1_MAX_HEADER); - if (p == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - cl->buf->pos = p; - - p = ngx_proxy_protocol_write(c, p, - p + NGX_PROXY_PROTOCOL_V1_MAX_HEADER); - if (p == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - cl->buf->last = p; - cl->buf->temporary = 1; - cl->buf->flush = 0; - cl->buf->last_buf = 0; - cl->buf->tag = (ngx_buf_tag_t) &ngx_stream_proxy_module; - - cl->next = u->upstream_out; - u->upstream_out = cl; - - u->proxy_protocol = 0; - } - - u->upload_rate = ngx_stream_complex_value_size(s, pscf->upload_rate, 0); - u->download_rate = ngx_stream_complex_value_size(s, pscf->download_rate, 0); - - u->connected = 1; - - pc->read->handler = ngx_stream_proxy_upstream_handler; - pc->write->handler = ngx_stream_proxy_upstream_handler; - - if (pc->read->ready) { - ngx_post_event(pc->read, &ngx_posted_events); - } - - ngx_stream_proxy_process(s, 0, 1); + ngx_stream_proxy_connect(s); } +static ngx_int_t ngx_stream_proxy_eval(ngx_stream_session_t *s, + ngx_stream_proxy_srv_conf_t *pscf) { + ngx_str_t host; + ngx_url_t url; + ngx_stream_upstream_t *u; -#if (NGX_STREAM_SSL) + if (ngx_stream_complex_value(s, pscf->upstream_value, &host) != NGX_OK) { + return NGX_ERROR; + } + + ngx_memzero(&url, sizeof(ngx_url_t)); + + url.url = host; + url.no_resolve = 1; + + if (ngx_parse_url(s->connection->pool, &url) != NGX_OK) { + if (url.err) { + ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, "%s in upstream \"%V\"", + url.err, &url.url); + } + + return NGX_ERROR; + } + + u = s->upstream; + + u->resolved = + ngx_pcalloc(s->connection->pool, sizeof(ngx_stream_upstream_resolved_t)); + if (u->resolved == NULL) { + return NGX_ERROR; + } + + if (url.addrs) { + u->resolved->sockaddr = url.addrs[0].sockaddr; + u->resolved->socklen = url.addrs[0].socklen; + u->resolved->name = url.addrs[0].name; + u->resolved->naddrs = 1; + } + + u->resolved->host = url.host; + u->resolved->port = url.port; + u->resolved->no_port = url.no_port; + + return NGX_OK; +} static ngx_int_t -ngx_stream_proxy_send_proxy_protocol(ngx_stream_session_t *s) -{ - u_char *p; - ssize_t n, size; - ngx_connection_t *c, *pc; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - u_char buf[NGX_PROXY_PROTOCOL_V1_MAX_HEADER]; +ngx_stream_proxy_set_local(ngx_stream_session_t *s, ngx_stream_upstream_t *u, + ngx_stream_upstream_local_t *local) { + ngx_int_t rc; + ngx_str_t val; + ngx_addr_t *addr; - c = s->connection; + if (local == NULL) { + u->peer.local = NULL; + return NGX_OK; + } +#if (NGX_HAVE_TRANSPARENT_PROXY) + u->peer.transparent = local->transparent; +#endif + + if (local->value == NULL) { + u->peer.local = local->addr; + return NGX_OK; + } + + if (ngx_stream_complex_value(s, local->value, &val) != NGX_OK) { + return NGX_ERROR; + } + + if (val.len == 0) { + u->peer.local = NULL; + return NGX_OK; + } + + addr = ngx_palloc(s->connection->pool, sizeof(ngx_addr_t)); + if (addr == NULL) { + return NGX_ERROR; + } + + rc = ngx_parse_addr_port(s->connection->pool, addr, val.data, val.len); + if (rc == NGX_ERROR) { + return NGX_ERROR; + } + + if (rc != NGX_OK) { + ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, + "invalid local address \"%V\"", &val); + u->peer.local = NULL; + return NGX_OK; + } + + addr->name = val; + u->peer.local = addr; + + return NGX_OK; +} + +static void ngx_stream_proxy_connect(ngx_stream_session_t *s) { + ngx_int_t rc; + ngx_connection_t *c, *pc; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; + + c = s->connection; + + c->log->action = "connecting to upstream"; + + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + + u = s->upstream; + + u->connected = 0; + u->proxy_protocol = pscf->proxy_protocol; + + if (u->state) { + u->state->response_time = ngx_current_msec - u->start_time; + } + + u->state = ngx_array_push(s->upstream_states); + if (u->state == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t)); + + u->start_time = ngx_current_msec; + + u->state->connect_time = (ngx_msec_t)-1; + u->state->first_byte_time = (ngx_msec_t)-1; + u->state->response_time = (ngx_msec_t)-1; + + rc = ngx_event_connect_peer(&u->peer); + + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc); + + if (rc == NGX_ERROR) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + u->state->peer = u->peer.name; + +#if (NGX_STREAM_UPSTREAM_ZONE) + if (u->upstream && u->upstream->shm_zone && + (u->upstream->flags & NGX_STREAM_UPSTREAM_MODIFY)) { + u->state->peer = + ngx_palloc(s->connection->pool, sizeof(ngx_str_t) + u->peer.name->len); + if (u->state->peer == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + u->state->peer->len = u->peer.name->len; + u->state->peer->data = (u_char *)(u->state->peer + 1); + ngx_memcpy(u->state->peer->data, u->peer.name->data, u->peer.name->len); + + u->peer.name = u->state->peer; + } +#endif + + if (rc == NGX_BUSY) { + ngx_log_error(NGX_LOG_ERR, c->log, 0, "no live upstreams"); + ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); + return; + } + + if (rc == NGX_DECLINED) { + ngx_stream_proxy_next_upstream(s); + return; + } + + /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */ + + pc = u->peer.connection; + + pc->data = s; + pc->log = c->log; + pc->pool = c->pool; + pc->read->log = c->log; + pc->write->log = c->log; + + if (rc != NGX_AGAIN) { + ngx_stream_proxy_init_upstream(s); + return; + } + + pc->read->handler = ngx_stream_proxy_connect_handler; + pc->write->handler = ngx_stream_proxy_connect_handler; + + ngx_add_timer(pc->write, pscf->connect_timeout); +} + +static void ngx_stream_proxy_init_upstream(ngx_stream_session_t *s) { + u_char *p; + ngx_chain_t *cl; + ngx_connection_t *c, *pc; + ngx_log_handler_pt handler; + ngx_stream_upstream_t *u; + ngx_stream_core_srv_conf_t *cscf; + ngx_stream_proxy_srv_conf_t *pscf; + + u = s->upstream; + pc = u->peer.connection; + + cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); + + if (pc->type == SOCK_STREAM && cscf->tcp_nodelay && + ngx_tcp_nodelay(pc) != NGX_OK) { + ngx_stream_proxy_next_upstream(s); + return; + } + + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + +#if (NGX_STREAM_SSL) + + if (pc->type == SOCK_STREAM && pscf->ssl_enable) { + + if (u->proxy_protocol) { + if (ngx_stream_proxy_send_proxy_protocol(s) != NGX_OK) { + return; + } + + u->proxy_protocol = 0; + } + + if (pc->ssl == NULL) { + ngx_stream_proxy_ssl_init_connection(s); + return; + } + } + +#endif + + c = s->connection; + + if (c->log->log_level >= NGX_LOG_INFO) { + ngx_str_t str; + u_char addr[NGX_SOCKADDR_STRLEN]; + + str.len = NGX_SOCKADDR_STRLEN; + str.data = addr; + + if (ngx_connection_local_sockaddr(pc, &str, 1) == NGX_OK) { + handler = c->log->handler; + c->log->handler = NULL; + + ngx_log_error(NGX_LOG_INFO, c->log, 0, "%sproxy %V connected to %V", + pc->type == SOCK_DGRAM ? "udp " : "", &str, u->peer.name); + + c->log->handler = handler; + } + } + + u->state->connect_time = ngx_current_msec - u->start_time; + + if (u->peer.notify) { + u->peer.notify(&u->peer, u->peer.data, NGX_STREAM_UPSTREAM_NOTIFY_CONNECT); + } + + if (u->upstream_buf.start == NULL) { + p = ngx_pnalloc(c->pool, pscf->buffer_size); + if (p == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + u->upstream_buf.start = p; + u->upstream_buf.end = p + pscf->buffer_size; + u->upstream_buf.pos = p; + u->upstream_buf.last = p; + } + + if (c->buffer && c->buffer->pos <= c->buffer->last) { + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, + "stream proxy add preread buffer: %uz", + c->buffer->last - c->buffer->pos); + + cl = ngx_chain_get_free_buf(c->pool, &u->free); + if (cl == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + *cl->buf = *c->buffer; + + cl->buf->tag = (ngx_buf_tag_t)&ngx_stream_proxy_module; + cl->buf->temporary = (cl->buf->pos == cl->buf->last) ? 0 : 1; + cl->buf->flush = 1; + + cl->next = u->upstream_out; + u->upstream_out = cl; + } + + if (u->proxy_protocol) { ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream proxy send PROXY protocol header"); + "stream proxy add PROXY protocol header"); + cl = ngx_chain_get_free_buf(c->pool, &u->free); + if (cl == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + if (pscf->protocol_version == 2) { + p = ngx_pnalloc(c->pool, NGX_PROXY_PROTOCOL_V2_MAX_HEADER); + } else { + p = ngx_pnalloc(c->pool, NGX_PROXY_PROTOCOL_V1_MAX_HEADER); + } + if (p == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + cl->buf->pos = p; + + if (pscf->protocol_version == 2) { + p = ngx_proxy_protocol_v2_write(c, p, + p + NGX_PROXY_PROTOCOL_V2_MAX_HEADER); + } else { + p = ngx_proxy_protocol_write(c, p, p + NGX_PROXY_PROTOCOL_V1_MAX_HEADER); + } + if (p == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + cl->buf->last = p; + cl->buf->temporary = 1; + cl->buf->flush = 0; + cl->buf->last_buf = 0; + cl->buf->tag = (ngx_buf_tag_t)&ngx_stream_proxy_module; + + cl->next = u->upstream_out; + u->upstream_out = cl; + + u->proxy_protocol = 0; + } + + u->upload_rate = ngx_stream_complex_value_size(s, pscf->upload_rate, 0); + u->download_rate = ngx_stream_complex_value_size(s, pscf->download_rate, 0); + + u->connected = 1; + + pc->read->handler = ngx_stream_proxy_upstream_handler; + pc->write->handler = ngx_stream_proxy_upstream_handler; + + if (pc->read->ready) { + ngx_post_event(pc->read, &ngx_posted_events); + } + + ngx_stream_proxy_process(s, 0, 1); +} + +#if (NGX_STREAM_SSL) + +static ngx_int_t ngx_stream_proxy_send_proxy_protocol(ngx_stream_session_t *s) { + u_char *p; + ssize_t n, size; + ngx_connection_t *c, *pc; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; + u_char buf[NGX_PROXY_PROTOCOL_V1_MAX_HEADER]; + + c = s->connection; + + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, + "stream proxy send PROXY protocol header"); + + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + + if (pscf->protocol_version == 2) { + p = ngx_proxy_protocol_v2_write(c, buf, + buf + NGX_PROXY_PROTOCOL_V2_MAX_HEADER); + } else { p = ngx_proxy_protocol_write(c, buf, buf + NGX_PROXY_PROTOCOL_V1_MAX_HEADER); - if (p == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return NGX_ERROR; + } + if (p == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return NGX_ERROR; + } + + u = s->upstream; + + pc = u->peer.connection; + + size = p - buf; + + n = pc->send(pc, buf, size); + + if (n == NGX_AGAIN) { + if (ngx_handle_write_event(pc->write, 0) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return NGX_ERROR; } - u = s->upstream; + ngx_add_timer(pc->write, pscf->timeout); - pc = u->peer.connection; + pc->write->handler = ngx_stream_proxy_connect_handler; - size = p - buf; + return NGX_AGAIN; + } - n = pc->send(pc, buf, size); + if (n == NGX_ERROR) { + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + return NGX_ERROR; + } - if (n == NGX_AGAIN) { - if (ngx_handle_write_event(pc->write, 0) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return NGX_ERROR; - } + if (n != size) { - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + /* + * PROXY protocol specification: + * The sender must always ensure that the header + * is sent at once, so that the transport layer + * maintains atomicity along the path to the receiver. + */ - ngx_add_timer(pc->write, pscf->timeout); + ngx_log_error(NGX_LOG_ERR, c->log, 0, + "could not send PROXY protocol header at once"); - pc->write->handler = ngx_stream_proxy_connect_handler; + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return NGX_AGAIN; - } + return NGX_ERROR; + } - if (n == NGX_ERROR) { - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - return NGX_ERROR; - } - - if (n != size) { - - /* - * PROXY protocol specification: - * The sender must always ensure that the header - * is sent at once, so that the transport layer - * maintains atomicity along the path to the receiver. - */ - - ngx_log_error(NGX_LOG_ERR, c->log, 0, - "could not send PROXY protocol header at once"); - - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - - return NGX_ERROR; - } - - return NGX_OK; + return NGX_OK; } +static char *ngx_stream_proxy_ssl_certificate_cache(ngx_conf_t *cf, + ngx_command_t *cmd, + void *conf) { + ngx_stream_proxy_srv_conf_t *pscf = conf; -static char * -ngx_stream_proxy_ssl_certificate_cache(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) -{ - ngx_stream_proxy_srv_conf_t *pscf = conf; + time_t inactive, valid; + ngx_str_t *value, s; + ngx_int_t max; + ngx_uint_t i; - time_t inactive, valid; - ngx_str_t *value, s; - ngx_int_t max; - ngx_uint_t i; + if (pscf->ssl_certificate_cache != NGX_CONF_UNSET_PTR) { + return "is duplicate"; + } - if (pscf->ssl_certificate_cache != NGX_CONF_UNSET_PTR) { - return "is duplicate"; + value = cf->args->elts; + + max = 0; + inactive = 10; + valid = 60; + + for (i = 1; i < cf->args->nelts; i++) { + + if (ngx_strncmp(value[i].data, "max=", 4) == 0) { + + max = ngx_atoi(value[i].data + 4, value[i].len - 4); + if (max <= 0) { + goto failed; + } + + continue; } - value = cf->args->elts; + if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { - max = 0; - inactive = 10; - valid = 60; + s.len = value[i].len - 9; + s.data = value[i].data + 9; - for (i = 1; i < cf->args->nelts; i++) { + inactive = ngx_parse_time(&s, 1); + if (inactive == (time_t)NGX_ERROR) { + goto failed; + } - if (ngx_strncmp(value[i].data, "max=", 4) == 0) { - - max = ngx_atoi(value[i].data + 4, value[i].len - 4); - if (max <= 0) { - goto failed; - } - - continue; - } - - if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { - - s.len = value[i].len - 9; - s.data = value[i].data + 9; - - inactive = ngx_parse_time(&s, 1); - if (inactive == (time_t) NGX_ERROR) { - goto failed; - } - - continue; - } - - if (ngx_strncmp(value[i].data, "valid=", 6) == 0) { - - s.len = value[i].len - 6; - s.data = value[i].data + 6; - - valid = ngx_parse_time(&s, 1); - if (valid == (time_t) NGX_ERROR) { - goto failed; - } - - continue; - } - - if (ngx_strcmp(value[i].data, "off") == 0) { - - pscf->ssl_certificate_cache = NULL; - - continue; - } - - failed: - - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid parameter \"%V\"", &value[i]); - return NGX_CONF_ERROR; + continue; } - if (pscf->ssl_certificate_cache == NULL) { - return NGX_CONF_OK; + if (ngx_strncmp(value[i].data, "valid=", 6) == 0) { + + s.len = value[i].len - 6; + s.data = value[i].data + 6; + + valid = ngx_parse_time(&s, 1); + if (valid == (time_t)NGX_ERROR) { + goto failed; + } + + continue; } - if (max == 0) { - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "\"proxy_ssl_certificate_cache\" must have " - "the \"max\" parameter"); - return NGX_CONF_ERROR; + if (ngx_strcmp(value[i].data, "off") == 0) { + + pscf->ssl_certificate_cache = NULL; + + continue; } - pscf->ssl_certificate_cache = ngx_ssl_cache_init(cf->pool, max, valid, - inactive); - if (pscf->ssl_certificate_cache == NULL) { - return NGX_CONF_ERROR; - } + failed: + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%V\"", + &value[i]); + return NGX_CONF_ERROR; + } + + if (pscf->ssl_certificate_cache == NULL) { return NGX_CONF_OK; + } + + if (max == 0) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "\"proxy_ssl_certificate_cache\" must have " + "the \"max\" parameter"); + return NGX_CONF_ERROR; + } + + pscf->ssl_certificate_cache = + ngx_ssl_cache_init(cf->pool, max, valid, inactive); + if (pscf->ssl_certificate_cache == NULL) { + return NGX_CONF_ERROR; + } + + return NGX_CONF_OK; } +static char *ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf, + ngx_command_t *cmd, + void *conf) { + ngx_stream_proxy_srv_conf_t *pscf = conf; -static char * -ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) -{ - ngx_stream_proxy_srv_conf_t *pscf = conf; + ngx_str_t *value; - ngx_str_t *value; + if (pscf->ssl_passwords != NGX_CONF_UNSET_PTR) { + return "is duplicate"; + } - if (pscf->ssl_passwords != NGX_CONF_UNSET_PTR) { - return "is duplicate"; - } + value = cf->args->elts; - value = cf->args->elts; + pscf->ssl_passwords = ngx_ssl_read_password_file(cf, &value[1]); - pscf->ssl_passwords = ngx_ssl_read_password_file(cf, &value[1]); + if (pscf->ssl_passwords == NULL) { + return NGX_CONF_ERROR; + } - if (pscf->ssl_passwords == NULL) { - return NGX_CONF_ERROR; - } - - return NGX_CONF_OK; + return NGX_CONF_OK; } - -static char * -ngx_stream_proxy_ssl_conf_command_check(ngx_conf_t *cf, void *post, void *data) -{ +static char *ngx_stream_proxy_ssl_conf_command_check(ngx_conf_t *cf, void *post, + void *data) { #ifndef SSL_CONF_FLAG_FILE - return "is not supported on this platform"; + return "is not supported on this platform"; #else - return NGX_CONF_OK; + return NGX_CONF_OK; #endif } +static void ngx_stream_proxy_ssl_init_connection(ngx_stream_session_t *s) { + ngx_int_t rc; + ngx_connection_t *pc; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; -static void -ngx_stream_proxy_ssl_init_connection(ngx_stream_session_t *s) -{ - ngx_int_t rc; - ngx_connection_t *pc; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; + u = s->upstream; - u = s->upstream; + pc = u->peer.connection; - pc = u->peer.connection; + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + if (ngx_ssl_create_connection(pscf->ssl, pc, + NGX_SSL_BUFFER | NGX_SSL_CLIENT) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } - if (ngx_ssl_create_connection(pscf->ssl, pc, NGX_SSL_BUFFER|NGX_SSL_CLIENT) - != NGX_OK) - { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; + if (pscf->ssl_server_name || pscf->ssl_verify) { + if (ngx_stream_proxy_ssl_name(s) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + } + + if (pscf->ssl_certificate && pscf->ssl_certificate->value.len && + (pscf->ssl_certificate->lengths || pscf->ssl_certificate_key->lengths)) { + if (ngx_stream_proxy_ssl_certificate(s) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + } + + if (pscf->ssl_session_reuse) { + pc->ssl->save_session = ngx_stream_proxy_ssl_save_session; + + if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + } + + s->connection->log->action = "SSL handshaking to upstream"; + + rc = ngx_ssl_handshake(pc); + + if (rc == NGX_AGAIN) { + + if (!pc->write->timer_set) { + ngx_add_timer(pc->write, pscf->connect_timeout); } - if (pscf->ssl_server_name || pscf->ssl_verify) { - if (ngx_stream_proxy_ssl_name(s) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - } + pc->ssl->handler = ngx_stream_proxy_ssl_handshake; + return; + } - if (pscf->ssl_certificate - && pscf->ssl_certificate->value.len - && (pscf->ssl_certificate->lengths - || pscf->ssl_certificate_key->lengths)) - { - if (ngx_stream_proxy_ssl_certificate(s) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - } - - if (pscf->ssl_session_reuse) { - pc->ssl->save_session = ngx_stream_proxy_ssl_save_session; - - if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - } - - s->connection->log->action = "SSL handshaking to upstream"; - - rc = ngx_ssl_handshake(pc); - - if (rc == NGX_AGAIN) { - - if (!pc->write->timer_set) { - ngx_add_timer(pc->write, pscf->connect_timeout); - } - - pc->ssl->handler = ngx_stream_proxy_ssl_handshake; - return; - } - - ngx_stream_proxy_ssl_handshake(pc); + ngx_stream_proxy_ssl_handshake(pc); } +static void ngx_stream_proxy_ssl_handshake(ngx_connection_t *pc) { + long rc; + ngx_stream_session_t *s; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; -static void -ngx_stream_proxy_ssl_handshake(ngx_connection_t *pc) -{ - long rc; - ngx_stream_session_t *s; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; + s = pc->data; - s = pc->data; + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + if (pc->ssl->handshaked) { - if (pc->ssl->handshaked) { + if (pscf->ssl_verify) { + rc = SSL_get_verify_result(pc->ssl->connection); - if (pscf->ssl_verify) { - rc = SSL_get_verify_result(pc->ssl->connection); + if (rc != X509_V_OK) { + ngx_log_error(NGX_LOG_ERR, pc->log, 0, + "upstream SSL certificate verify error: (%l:%s)", rc, + X509_verify_cert_error_string(rc)); + goto failed; + } - if (rc != X509_V_OK) { - ngx_log_error(NGX_LOG_ERR, pc->log, 0, - "upstream SSL certificate verify error: (%l:%s)", - rc, X509_verify_cert_error_string(rc)); - goto failed; - } + u = s->upstream; - u = s->upstream; - - if (ngx_ssl_check_host(pc, &u->ssl_name) != NGX_OK) { - ngx_log_error(NGX_LOG_ERR, pc->log, 0, - "upstream SSL certificate does not match \"%V\"", - &u->ssl_name); - goto failed; - } - } - - if (pc->write->timer_set) { - ngx_del_timer(pc->write); - } - - ngx_stream_proxy_init_upstream(s); - - return; + if (ngx_ssl_check_host(pc, &u->ssl_name) != NGX_OK) { + ngx_log_error(NGX_LOG_ERR, pc->log, 0, + "upstream SSL certificate does not match \"%V\"", + &u->ssl_name); + goto failed; + } } + if (pc->write->timer_set) { + ngx_del_timer(pc->write); + } + + ngx_stream_proxy_init_upstream(s); + + return; + } + failed: - ngx_stream_proxy_next_upstream(s); + ngx_stream_proxy_next_upstream(s); } +static void ngx_stream_proxy_ssl_save_session(ngx_connection_t *c) { + ngx_stream_session_t *s; + ngx_stream_upstream_t *u; -static void -ngx_stream_proxy_ssl_save_session(ngx_connection_t *c) -{ - ngx_stream_session_t *s; - ngx_stream_upstream_t *u; + s = c->data; + u = s->upstream; - s = c->data; - u = s->upstream; - - u->peer.save_session(&u->peer, u->peer.data); + u->peer.save_session(&u->peer, u->peer.data); } +static ngx_int_t ngx_stream_proxy_ssl_name(ngx_stream_session_t *s) { + u_char *p, *last; + ngx_str_t name; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; -static ngx_int_t -ngx_stream_proxy_ssl_name(ngx_stream_session_t *s) -{ - u_char *p, *last; - ngx_str_t name; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + u = s->upstream; - u = s->upstream; - - if (pscf->ssl_name) { - if (ngx_stream_complex_value(s, pscf->ssl_name, &name) != NGX_OK) { - return NGX_ERROR; - } - - } else { - name = u->ssl_name; + if (pscf->ssl_name) { + if (ngx_stream_complex_value(s, pscf->ssl_name, &name) != NGX_OK) { + return NGX_ERROR; } - if (name.len == 0) { - goto done; + } else { + name = u->ssl_name; + } + + if (name.len == 0) { + goto done; + } + + /* + * ssl name here may contain port, strip it for compatibility + * with the http module + */ + + p = name.data; + last = name.data + name.len; + + if (*p == '[') { + p = ngx_strlchr(p, last, ']'); + + if (p == NULL) { + p = name.data; } + } - /* - * ssl name here may contain port, strip it for compatibility - * with the http module - */ + p = ngx_strlchr(p, last, ':'); - p = name.data; - last = name.data + name.len; + if (p != NULL) { + name.len = p - name.data; + } - if (*p == '[') { - p = ngx_strlchr(p, last, ']'); - - if (p == NULL) { - p = name.data; - } - } - - p = ngx_strlchr(p, last, ':'); - - if (p != NULL) { - name.len = p - name.data; - } - - if (!pscf->ssl_server_name) { - goto done; - } + if (!pscf->ssl_server_name) { + goto done; + } #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME - /* as per RFC 6066, literal IPv4 and IPv6 addresses are not permitted */ + /* as per RFC 6066, literal IPv4 and IPv6 addresses are not permitted */ - if (name.len == 0 || *name.data == '[') { - goto done; - } + if (name.len == 0 || *name.data == '[') { + goto done; + } - if (ngx_inet_addr(name.data, name.len) != INADDR_NONE) { - goto done; - } + if (ngx_inet_addr(name.data, name.len) != INADDR_NONE) { + goto done; + } - /* - * SSL_set_tlsext_host_name() needs a null-terminated string, - * hence we explicitly null-terminate name here - */ + /* + * SSL_set_tlsext_host_name() needs a null-terminated string, + * hence we explicitly null-terminate name here + */ - p = ngx_pnalloc(s->connection->pool, name.len + 1); - if (p == NULL) { - return NGX_ERROR; - } + p = ngx_pnalloc(s->connection->pool, name.len + 1); + if (p == NULL) { + return NGX_ERROR; + } - (void) ngx_cpystrn(p, name.data, name.len + 1); + (void)ngx_cpystrn(p, name.data, name.len + 1); - name.data = p; + name.data = p; - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "upstream SSL server name: \"%s\"", name.data); + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "upstream SSL server name: \"%s\"", name.data); - if (SSL_set_tlsext_host_name(u->peer.connection->ssl->connection, - (char *) name.data) - == 0) - { - ngx_ssl_error(NGX_LOG_ERR, s->connection->log, 0, - "SSL_set_tlsext_host_name(\"%s\") failed", name.data); - return NGX_ERROR; - } + if (SSL_set_tlsext_host_name(u->peer.connection->ssl->connection, + (char *)name.data) == 0) { + ngx_ssl_error(NGX_LOG_ERR, s->connection->log, 0, + "SSL_set_tlsext_host_name(\"%s\") failed", name.data); + return NGX_ERROR; + } #endif done: - u->ssl_name = name; + u->ssl_name = name; - return NGX_OK; + return NGX_OK; } +static ngx_int_t ngx_stream_proxy_ssl_certificate(ngx_stream_session_t *s) { + ngx_str_t cert, key; + ngx_connection_t *c; + ngx_stream_proxy_srv_conf_t *pscf; -static ngx_int_t -ngx_stream_proxy_ssl_certificate(ngx_stream_session_t *s) -{ - ngx_str_t cert, key; - ngx_connection_t *c; - ngx_stream_proxy_srv_conf_t *pscf; + c = s->upstream->peer.connection; - c = s->upstream->peer.connection; + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + if (ngx_stream_complex_value(s, pscf->ssl_certificate, &cert) != NGX_OK) { + return NGX_ERROR; + } - if (ngx_stream_complex_value(s, pscf->ssl_certificate, &cert) - != NGX_OK) - { - return NGX_ERROR; - } - - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream upstream ssl cert: \"%s\"", cert.data); - - if (*cert.data == '\0') { - return NGX_OK; - } - - if (ngx_stream_complex_value(s, pscf->ssl_certificate_key, &key) - != NGX_OK) - { - return NGX_ERROR; - } - - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream upstream ssl key: \"%s\"", key.data); - - if (ngx_ssl_connection_certificate(c, c->pool, &cert, &key, - pscf->ssl_certificate_cache, - pscf->ssl_passwords) - != NGX_OK) - { - return NGX_ERROR; - } + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, + "stream upstream ssl cert: \"%s\"", cert.data); + if (*cert.data == '\0') { return NGX_OK; + } + + if (ngx_stream_complex_value(s, pscf->ssl_certificate_key, &key) != NGX_OK) { + return NGX_ERROR; + } + + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, + "stream upstream ssl key: \"%s\"", key.data); + + if (ngx_ssl_connection_certificate(c, c->pool, &cert, &key, + pscf->ssl_certificate_cache, + pscf->ssl_passwords) != NGX_OK) { + return NGX_ERROR; + } + + return NGX_OK; } #endif - -static void -ngx_stream_proxy_downstream_handler(ngx_event_t *ev) -{ - ngx_stream_proxy_process_connection(ev, ev->write); +static void ngx_stream_proxy_downstream_handler(ngx_event_t *ev) { + ngx_stream_proxy_process_connection(ev, ev->write); } +static void ngx_stream_proxy_resolve_handler(ngx_resolver_ctx_t *ctx) { + ngx_stream_session_t *s; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; + ngx_stream_upstream_resolved_t *ur; -static void -ngx_stream_proxy_resolve_handler(ngx_resolver_ctx_t *ctx) -{ - ngx_stream_session_t *s; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - ngx_stream_upstream_resolved_t *ur; + s = ctx->data; - s = ctx->data; + u = s->upstream; + ur = u->resolved; - u = s->upstream; - ur = u->resolved; + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "stream upstream resolve"); - ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "stream upstream resolve"); + if (ctx->state) { + ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, + "%V could not be resolved (%i: %s)", &ctx->name, ctx->state, + ngx_resolver_strerror(ctx->state)); - if (ctx->state) { - ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, - "%V could not be resolved (%i: %s)", - &ctx->name, ctx->state, - ngx_resolver_strerror(ctx->state)); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - ur->naddrs = ctx->naddrs; - ur->addrs = ctx->addrs; + ur->naddrs = ctx->naddrs; + ur->addrs = ctx->addrs; #if (NGX_DEBUG) - { - u_char text[NGX_SOCKADDR_STRLEN]; - ngx_str_t addr; - ngx_uint_t i; + { + u_char text[NGX_SOCKADDR_STRLEN]; + ngx_str_t addr; + ngx_uint_t i; addr.data = text; for (i = 0; i < ctx->naddrs; i++) { - addr.len = ngx_sock_ntop(ur->addrs[i].sockaddr, ur->addrs[i].socklen, - text, NGX_SOCKADDR_STRLEN, 0); + addr.len = ngx_sock_ntop(ur->addrs[i].sockaddr, ur->addrs[i].socklen, + text, NGX_SOCKADDR_STRLEN, 0); - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "name was resolved to %V", &addr); - } + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "name was resolved to %V", &addr); } + } #endif - if (ngx_stream_upstream_create_round_robin_peer(s, ur) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } + if (ngx_stream_upstream_create_round_robin_peer(s, ur) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } - ngx_resolve_name_done(ctx); - ur->ctx = NULL; + ngx_resolve_name_done(ctx); + ur->ctx = NULL; - u->peer.start_time = ngx_current_msec; + u->peer.start_time = ngx_current_msec; - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - if (pscf->next_upstream_tries - && u->peer.tries > pscf->next_upstream_tries) - { - u->peer.tries = pscf->next_upstream_tries; - } + if (pscf->next_upstream_tries && u->peer.tries > pscf->next_upstream_tries) { + u->peer.tries = pscf->next_upstream_tries; + } - ngx_stream_proxy_connect(s); + ngx_stream_proxy_connect(s); } - -static void -ngx_stream_proxy_upstream_handler(ngx_event_t *ev) -{ - ngx_stream_proxy_process_connection(ev, !ev->write); +static void ngx_stream_proxy_upstream_handler(ngx_event_t *ev) { + ngx_stream_proxy_process_connection(ev, !ev->write); } +static void ngx_stream_proxy_process_connection(ngx_event_t *ev, + ngx_uint_t from_upstream) { + ngx_connection_t *c, *pc; + ngx_log_handler_pt handler; + ngx_stream_session_t *s; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; -static void -ngx_stream_proxy_process_connection(ngx_event_t *ev, ngx_uint_t from_upstream) -{ - ngx_connection_t *c, *pc; - ngx_log_handler_pt handler; - ngx_stream_session_t *s; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; + c = ev->data; + s = c->data; + u = s->upstream; - c = ev->data; - s = c->data; - u = s->upstream; + if (c->close) { + ngx_log_error(NGX_LOG_INFO, c->log, 0, "shutdown timeout"); + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + return; + } - if (c->close) { - ngx_log_error(NGX_LOG_INFO, c->log, 0, "shutdown timeout"); - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - return; - } + c = s->connection; + pc = u->peer.connection; - c = s->connection; - pc = u->peer.connection; + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + if (ev->timedout) { + ev->timedout = 0; - if (ev->timedout) { - ev->timedout = 0; - - if (ev->delayed) { - ev->delayed = 0; - - if (!ev->ready) { - if (ngx_handle_read_event(ev, 0) != NGX_OK) { - ngx_stream_proxy_finalize(s, - NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - if (u->connected && !c->read->delayed && !pc->read->delayed) { - ngx_add_timer(c->write, pscf->timeout); - } - - return; - } - - } else { - if (s->connection->type == SOCK_DGRAM) { - - if (pscf->responses == NGX_MAX_INT32_VALUE - || (u->responses >= pscf->responses * u->requests)) - { - - /* - * successfully terminate timed out UDP session - * if expected number of responses was received - */ - - handler = c->log->handler; - c->log->handler = NULL; - - ngx_log_error(NGX_LOG_INFO, c->log, 0, - "udp timed out" - ", packets from/to client:%ui/%ui" - ", bytes from/to client:%O/%O" - ", bytes from/to upstream:%O/%O", - u->requests, u->responses, - s->received, c->sent, u->received, - pc ? pc->sent : 0); - - c->log->handler = handler; - - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - return; - } - - ngx_connection_error(pc, NGX_ETIMEDOUT, "upstream timed out"); - - pc->read->error = 1; - - ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); - - return; - } - - ngx_connection_error(c, NGX_ETIMEDOUT, "connection timed out"); - - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - - return; - } - - } else if (ev->delayed) { - - ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream connection delayed"); + if (ev->delayed) { + ev->delayed = 0; + if (!ev->ready) { if (ngx_handle_read_event(ev, 0) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + if (u->connected && !c->read->delayed && !pc->read->delayed) { + ngx_add_timer(c->write, pscf->timeout); } return; - } + } + + } else { + if (s->connection->type == SOCK_DGRAM) { + + if (pscf->responses == NGX_MAX_INT32_VALUE || + (u->responses >= pscf->responses * u->requests)) { + + /* + * successfully terminate timed out UDP session + * if expected number of responses was received + */ + + handler = c->log->handler; + c->log->handler = NULL; + + ngx_log_error(NGX_LOG_INFO, c->log, 0, + "udp timed out" + ", packets from/to client:%ui/%ui" + ", bytes from/to client:%O/%O" + ", bytes from/to upstream:%O/%O", + u->requests, u->responses, s->received, c->sent, + u->received, pc ? pc->sent : 0); + + c->log->handler = handler; + + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + return; + } + + ngx_connection_error(pc, NGX_ETIMEDOUT, "upstream timed out"); + + pc->read->error = 1; + + ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); - if (from_upstream && !u->connected) { return; + } + + ngx_connection_error(c, NGX_ETIMEDOUT, "connection timed out"); + + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + + return; } - ngx_stream_proxy_process(s, from_upstream, ev->write); -} - - -static void -ngx_stream_proxy_connect_handler(ngx_event_t *ev) -{ - ngx_connection_t *c; - ngx_stream_session_t *s; - - c = ev->data; - s = c->data; - - if (ev->timedout) { - ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT, "upstream timed out"); - ngx_stream_proxy_next_upstream(s); - return; - } - - ngx_del_timer(c->write); + } else if (ev->delayed) { ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream proxy connect upstream"); + "stream connection delayed"); - if (ngx_stream_proxy_test_connect(c) != NGX_OK) { - ngx_stream_proxy_next_upstream(s); - return; + if (ngx_handle_read_event(ev, 0) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); } - ngx_stream_proxy_init_upstream(s); + return; + } + + if (from_upstream && !u->connected) { + return; + } + + ngx_stream_proxy_process(s, from_upstream, ev->write); } +static void ngx_stream_proxy_connect_handler(ngx_event_t *ev) { + ngx_connection_t *c; + ngx_stream_session_t *s; -static ngx_int_t -ngx_stream_proxy_test_connect(ngx_connection_t *c) -{ - int err; - socklen_t len; + c = ev->data; + s = c->data; + + if (ev->timedout) { + ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT, "upstream timed out"); + ngx_stream_proxy_next_upstream(s); + return; + } + + ngx_del_timer(c->write); + + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, + "stream proxy connect upstream"); + + if (ngx_stream_proxy_test_connect(c) != NGX_OK) { + ngx_stream_proxy_next_upstream(s); + return; + } + + ngx_stream_proxy_init_upstream(s); +} + +static ngx_int_t ngx_stream_proxy_test_connect(ngx_connection_t *c) { + int err; + socklen_t len; #if (NGX_HAVE_KQUEUE) - if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { - err = c->write->kq_errno ? c->write->kq_errno : c->read->kq_errno; + if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { + err = c->write->kq_errno ? c->write->kq_errno : c->read->kq_errno; - if (err) { - (void) ngx_connection_error(c, err, - "kevent() reported that connect() failed"); - return NGX_ERROR; - } - - } else -#endif - { - err = 0; - len = sizeof(int); - - /* - * BSDs and Linux return 0 and set a pending error in err - * Solaris returns -1 and sets errno - */ - - if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) - == -1) - { - err = ngx_socket_errno; - } - - if (err) { - (void) ngx_connection_error(c, err, "connect() failed"); - return NGX_ERROR; - } + if (err) { + (void)ngx_connection_error(c, err, + "kevent() reported that connect() failed"); + return NGX_ERROR; } - return NGX_OK; + } else +#endif + { + err = 0; + len = sizeof(int); + + /* + * BSDs and Linux return 0 and set a pending error in err + * Solaris returns -1 and sets errno + */ + + if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *)&err, &len) == -1) { + err = ngx_socket_errno; + } + + if (err) { + (void)ngx_connection_error(c, err, "connect() failed"); + return NGX_ERROR; + } + } + + return NGX_OK; } +static void ngx_stream_proxy_process(ngx_stream_session_t *s, + ngx_uint_t from_upstream, + ngx_uint_t do_write) { + char *recv_action, *send_action; + off_t *received, limit; + size_t size, limit_rate; + ssize_t n; + ngx_buf_t *b; + ngx_int_t rc; + ngx_uint_t flags, *packets; + ngx_msec_t delay; + ngx_chain_t *cl, **ll, **out, **busy; + ngx_connection_t *c, *pc, *src, *dst; + ngx_log_handler_pt handler; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; -static void -ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream, - ngx_uint_t do_write) -{ - char *recv_action, *send_action; - off_t *received, limit; - size_t size, limit_rate; - ssize_t n; - ngx_buf_t *b; - ngx_int_t rc; - ngx_uint_t flags, *packets; - ngx_msec_t delay; - ngx_chain_t *cl, **ll, **out, **busy; - ngx_connection_t *c, *pc, *src, *dst; - ngx_log_handler_pt handler; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; + u = s->upstream; - u = s->upstream; + c = s->connection; + pc = u->connected ? u->peer.connection : NULL; - c = s->connection; - pc = u->connected ? u->peer.connection : NULL; + if (c->type == SOCK_DGRAM && (ngx_terminate || ngx_exiting)) { - if (c->type == SOCK_DGRAM && (ngx_terminate || ngx_exiting)) { + /* socket is already closed on worker shutdown */ - /* socket is already closed on worker shutdown */ + handler = c->log->handler; + c->log->handler = NULL; - handler = c->log->handler; - c->log->handler = NULL; + ngx_log_error(NGX_LOG_INFO, c->log, 0, "disconnected on shutdown"); - ngx_log_error(NGX_LOG_INFO, c->log, 0, "disconnected on shutdown"); + c->log->handler = handler; - c->log->handler = handler; + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + return; + } - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - return; - } + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + if (from_upstream) { + src = pc; + dst = c; + b = &u->upstream_buf; + limit_rate = u->download_rate; + received = &u->received; + packets = &u->responses; + out = &u->downstream_out; + busy = &u->downstream_busy; + recv_action = "proxying and reading from upstream"; + send_action = "proxying and sending to client"; - if (from_upstream) { - src = pc; - dst = c; - b = &u->upstream_buf; - limit_rate = u->download_rate; - received = &u->received; - packets = &u->responses; - out = &u->downstream_out; - busy = &u->downstream_busy; - recv_action = "proxying and reading from upstream"; - send_action = "proxying and sending to client"; + } else { + src = c; + dst = pc; + b = &u->downstream_buf; + limit_rate = u->upload_rate; + received = &s->received; + packets = &u->requests; + out = &u->upstream_out; + busy = &u->upstream_busy; + recv_action = "proxying and reading from client"; + send_action = "proxying and sending to upstream"; + } - } else { - src = c; - dst = pc; - b = &u->downstream_buf; - limit_rate = u->upload_rate; - received = &s->received; - packets = &u->requests; - out = &u->upstream_out; - busy = &u->upstream_busy; - recv_action = "proxying and reading from client"; - send_action = "proxying and sending to upstream"; - } + for (;;) { - for ( ;; ) { + if (do_write && dst) { - if (do_write && dst) { + if (*out || *busy || dst->buffered) { + c->log->action = send_action; - if (*out || *busy || dst->buffered) { - c->log->action = send_action; + rc = ngx_stream_top_filter(s, *out, from_upstream); - rc = ngx_stream_top_filter(s, *out, from_upstream); - - if (rc == NGX_ERROR) { - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - return; - } - - ngx_chain_update_chains(c->pool, &u->free, busy, out, - (ngx_buf_tag_t) &ngx_stream_proxy_module); - - if (*busy == NULL) { - b->pos = b->start; - b->last = b->start; - } - } + if (rc == NGX_ERROR) { + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + return; } - size = b->end - b->last; + ngx_chain_update_chains(c->pool, &u->free, busy, out, + (ngx_buf_tag_t)&ngx_stream_proxy_module); - if (size && src->read->ready && !src->read->delayed) { + if (*busy == NULL) { + b->pos = b->start; + b->last = b->start; + } + } + } - if (limit_rate) { - limit = (off_t) limit_rate * (ngx_time() - u->start_sec + 1) - - *received; + size = b->end - b->last; - if (limit <= 0) { - src->read->delayed = 1; - delay = (ngx_msec_t) (- limit * 1000 / limit_rate + 1); - ngx_add_timer(src->read, delay); - break; - } + if (size && src->read->ready && !src->read->delayed) { - if (c->type == SOCK_STREAM && (off_t) size > limit) { - size = (size_t) limit; - } - } + if (limit_rate) { + limit = (off_t)limit_rate * (ngx_time() - u->start_sec + 1) - *received; - c->log->action = recv_action; - - n = src->recv(src, b->last, size); - - if (n == NGX_AGAIN) { - break; - } - - if (n == NGX_ERROR) { - src->read->eof = 1; - n = 0; - } - - if (n >= 0) { - if (limit_rate) { - delay = (ngx_msec_t) (n * 1000 / limit_rate); - - if (delay > 0) { - src->read->delayed = 1; - ngx_add_timer(src->read, delay); - } - } - - if (from_upstream) { - if (u->state->first_byte_time == (ngx_msec_t) -1) { - u->state->first_byte_time = ngx_current_msec - - u->start_time; - } - } - - for (ll = out; *ll; ll = &(*ll)->next) { /* void */ } - - cl = ngx_chain_get_free_buf(c->pool, &u->free); - if (cl == NULL) { - ngx_stream_proxy_finalize(s, - NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - *ll = cl; - - cl->buf->pos = b->last; - cl->buf->last = b->last + n; - cl->buf->tag = (ngx_buf_tag_t) &ngx_stream_proxy_module; - - cl->buf->temporary = (n ? 1 : 0); - cl->buf->last_buf = src->read->eof; - cl->buf->flush = !src->read->eof; - - (*packets)++; - *received += n; - b->last += n; - do_write = 1; - - continue; - } + if (limit <= 0) { + src->read->delayed = 1; + delay = (ngx_msec_t)(-limit * 1000 / limit_rate + 1); + ngx_add_timer(src->read, delay); + break; } + if (c->type == SOCK_STREAM && (off_t)size > limit) { + size = (size_t)limit; + } + } + + c->log->action = recv_action; + + n = src->recv(src, b->last, size); + + if (n == NGX_AGAIN) { break; + } + + if (n == NGX_ERROR) { + src->read->eof = 1; + n = 0; + } + + if (n >= 0) { + if (limit_rate) { + delay = (ngx_msec_t)(n * 1000 / limit_rate); + + if (delay > 0) { + src->read->delayed = 1; + ngx_add_timer(src->read, delay); + } + } + + if (from_upstream) { + if (u->state->first_byte_time == (ngx_msec_t)-1) { + u->state->first_byte_time = ngx_current_msec - u->start_time; + } + } + + for (ll = out; *ll; ll = &(*ll)->next) { /* void */ + } + + cl = ngx_chain_get_free_buf(c->pool, &u->free); + if (cl == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + *ll = cl; + + cl->buf->pos = b->last; + cl->buf->last = b->last + n; + cl->buf->tag = (ngx_buf_tag_t)&ngx_stream_proxy_module; + + cl->buf->temporary = (n ? 1 : 0); + cl->buf->last_buf = src->read->eof; + cl->buf->flush = !src->read->eof; + + (*packets)++; + *received += n; + b->last += n; + do_write = 1; + + continue; + } } - c->log->action = "proxying connection"; + break; + } - if (ngx_stream_proxy_test_finalize(s, from_upstream) == NGX_OK) { - return; - } + c->log->action = "proxying connection"; - flags = src->read->eof ? NGX_CLOSE_EVENT : 0; + if (ngx_stream_proxy_test_finalize(s, from_upstream) == NGX_OK) { + return; + } + + flags = src->read->eof ? NGX_CLOSE_EVENT : 0; + + if (ngx_handle_read_event(src->read, flags) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + if (dst) { + + if (dst->type == SOCK_STREAM && pscf->half_close && src->read->eof && + !u->half_closed && !dst->buffered) { + if (ngx_shutdown_socket(dst->fd, NGX_WRITE_SHUTDOWN) == -1) { + ngx_connection_error(c, ngx_socket_errno, + ngx_shutdown_socket_n " failed"); - if (ngx_handle_read_event(src->read, flags) != NGX_OK) { ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); return; + } + + u->half_closed = 1; + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "stream proxy %s socket shutdown", + from_upstream ? "client" : "upstream"); } - if (dst) { - - if (dst->type == SOCK_STREAM && pscf->half_close - && src->read->eof && !u->half_closed && !dst->buffered) - { - if (ngx_shutdown_socket(dst->fd, NGX_WRITE_SHUTDOWN) == -1) { - ngx_connection_error(c, ngx_socket_errno, - ngx_shutdown_socket_n " failed"); - - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - u->half_closed = 1; - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "stream proxy %s socket shutdown", - from_upstream ? "client" : "upstream"); - } - - if (ngx_handle_write_event(dst->write, 0) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - if (!c->read->delayed && !pc->read->delayed) { - ngx_add_timer(c->write, pscf->timeout); - - } else if (c->write->timer_set) { - ngx_del_timer(c->write); - } + if (ngx_handle_write_event(dst->write, 0) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; } + + if (!c->read->delayed && !pc->read->delayed) { + ngx_add_timer(c->write, pscf->timeout); + + } else if (c->write->timer_set) { + ngx_del_timer(c->write); + } + } } +static ngx_int_t ngx_stream_proxy_test_finalize(ngx_stream_session_t *s, + ngx_uint_t from_upstream) { + ngx_connection_t *c, *pc; + ngx_log_handler_pt handler; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; -static ngx_int_t -ngx_stream_proxy_test_finalize(ngx_stream_session_t *s, - ngx_uint_t from_upstream) -{ - ngx_connection_t *c, *pc; - ngx_log_handler_pt handler; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + c = s->connection; + u = s->upstream; + pc = u->connected ? u->peer.connection : NULL; - c = s->connection; - u = s->upstream; - pc = u->connected ? u->peer.connection : NULL; + if (c->type == SOCK_DGRAM) { - if (c->type == SOCK_DGRAM) { - - if (pscf->requests && u->requests < pscf->requests) { - return NGX_DECLINED; - } - - if (pscf->requests) { - ngx_delete_udp_connection(c); - } - - if (pscf->responses == NGX_MAX_INT32_VALUE - || u->responses < pscf->responses * u->requests) - { - return NGX_DECLINED; - } - - if (pc == NULL || c->buffered || pc->buffered) { - return NGX_DECLINED; - } - - handler = c->log->handler; - c->log->handler = NULL; - - ngx_log_error(NGX_LOG_INFO, c->log, 0, - "udp done" - ", packets from/to client:%ui/%ui" - ", bytes from/to client:%O/%O" - ", bytes from/to upstream:%O/%O", - u->requests, u->responses, - s->received, c->sent, u->received, pc ? pc->sent : 0); - - c->log->handler = handler; - - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - - return NGX_OK; + if (pscf->requests && u->requests < pscf->requests) { + return NGX_DECLINED; } - /* c->type == SOCK_STREAM */ - - if (pc == NULL - || (!c->read->eof && !pc->read->eof) - || (!c->read->eof && c->buffered) - || (!pc->read->eof && pc->buffered)) - { - return NGX_DECLINED; + if (pscf->requests) { + ngx_delete_udp_connection(c); } - if (pscf->half_close) { - /* avoid closing live connections until both read ends get EOF */ - if (!(c->read->eof && pc->read->eof && !c->buffered && !pc->buffered)) { - return NGX_DECLINED; - } + if (pscf->responses == NGX_MAX_INT32_VALUE || + u->responses < pscf->responses * u->requests) { + return NGX_DECLINED; + } + + if (pc == NULL || c->buffered || pc->buffered) { + return NGX_DECLINED; } handler = c->log->handler; c->log->handler = NULL; ngx_log_error(NGX_LOG_INFO, c->log, 0, - "%s disconnected" + "udp done" + ", packets from/to client:%ui/%ui" ", bytes from/to client:%O/%O" ", bytes from/to upstream:%O/%O", - from_upstream ? "upstream" : "client", - s->received, c->sent, u->received, pc ? pc->sent : 0); + u->requests, u->responses, s->received, c->sent, u->received, + pc ? pc->sent : 0); c->log->handler = handler; ngx_stream_proxy_finalize(s, NGX_STREAM_OK); return NGX_OK; + } + + /* c->type == SOCK_STREAM */ + + if (pc == NULL || (!c->read->eof && !pc->read->eof) || + (!c->read->eof && c->buffered) || (!pc->read->eof && pc->buffered)) { + return NGX_DECLINED; + } + + if (pscf->half_close) { + /* avoid closing live connections until both read ends get EOF */ + if (!(c->read->eof && pc->read->eof && !c->buffered && !pc->buffered)) { + return NGX_DECLINED; + } + } + + handler = c->log->handler; + c->log->handler = NULL; + + ngx_log_error(NGX_LOG_INFO, c->log, 0, + "%s disconnected" + ", bytes from/to client:%O/%O" + ", bytes from/to upstream:%O/%O", + from_upstream ? "upstream" : "client", s->received, c->sent, + u->received, pc ? pc->sent : 0); + + c->log->handler = handler; + + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + + return NGX_OK; } +static void ngx_stream_proxy_next_upstream(ngx_stream_session_t *s) { + ngx_msec_t timeout; + ngx_connection_t *pc; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; -static void -ngx_stream_proxy_next_upstream(ngx_stream_session_t *s) -{ - ngx_msec_t timeout; - ngx_connection_t *pc; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "stream proxy next upstream"); - ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "stream proxy next upstream"); + u = s->upstream; + pc = u->peer.connection; - u = s->upstream; - pc = u->peer.connection; + if (pc && pc->buffered) { + ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, + "buffered data on next upstream"); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } - if (pc && pc->buffered) { - ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, - "buffered data on next upstream"); - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } + if (s->connection->type == SOCK_DGRAM) { + u->upstream_out = NULL; + } - if (s->connection->type == SOCK_DGRAM) { - u->upstream_out = NULL; - } + if (u->peer.sockaddr) { + u->peer.free(&u->peer, u->peer.data, NGX_PEER_FAILED); + u->peer.sockaddr = NULL; + } - if (u->peer.sockaddr) { - u->peer.free(&u->peer, u->peer.data, NGX_PEER_FAILED); - u->peer.sockaddr = NULL; - } + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + timeout = pscf->next_upstream_timeout; - timeout = pscf->next_upstream_timeout; - - if (u->peer.tries == 0 - || !pscf->next_upstream - || (timeout && ngx_current_msec - u->peer.start_time >= timeout)) - { - ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); - return; - } - - if (pc) { - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "close proxy upstream connection: %d", pc->fd); - -#if (NGX_STREAM_SSL) - if (pc->ssl) { - pc->ssl->no_wait_shutdown = 1; - pc->ssl->no_send_shutdown = 1; - - (void) ngx_ssl_shutdown(pc); - } -#endif - - u->state->bytes_received = u->received; - u->state->bytes_sent = pc->sent; - - ngx_close_connection(pc); - u->peer.connection = NULL; - } - - ngx_stream_proxy_connect(s); -} - - -static void -ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc) -{ - ngx_uint_t state; - ngx_connection_t *pc; - ngx_stream_upstream_t *u; + if (u->peer.tries == 0 || !pscf->next_upstream || + (timeout && ngx_current_msec - u->peer.start_time >= timeout)) { + ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); + return; + } + if (pc) { ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "finalize stream proxy: %i", rc); + "close proxy upstream connection: %d", pc->fd); - u = s->upstream; +#if (NGX_STREAM_SSL) + if (pc->ssl) { + pc->ssl->no_wait_shutdown = 1; + pc->ssl->no_send_shutdown = 1; - if (u == NULL) { - goto noupstream; + (void)ngx_ssl_shutdown(pc); } +#endif - if (u->resolved && u->resolved->ctx) { - ngx_resolve_name_done(u->resolved->ctx); - u->resolved->ctx = NULL; - } + u->state->bytes_received = u->received; + u->state->bytes_sent = pc->sent; - pc = u->peer.connection; + ngx_close_connection(pc); + u->peer.connection = NULL; + } - if (u->state) { - if (u->state->response_time == (ngx_msec_t) -1) { - u->state->response_time = ngx_current_msec - u->start_time; - } + ngx_stream_proxy_connect(s); +} - if (pc) { - u->state->bytes_received = u->received; - u->state->bytes_sent = pc->sent; - } - } +static void ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc) { + ngx_uint_t state; + ngx_connection_t *pc; + ngx_stream_upstream_t *u; - if (u->peer.free && u->peer.sockaddr) { - state = 0; + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "finalize stream proxy: %i", rc); - if (pc && pc->type == SOCK_DGRAM - && (pc->read->error || pc->write->error)) - { - state = NGX_PEER_FAILED; - } + u = s->upstream; - u->peer.free(&u->peer, u->peer.data, state); - u->peer.sockaddr = NULL; + if (u == NULL) { + goto noupstream; + } + + if (u->resolved && u->resolved->ctx) { + ngx_resolve_name_done(u->resolved->ctx); + u->resolved->ctx = NULL; + } + + pc = u->peer.connection; + + if (u->state) { + if (u->state->response_time == (ngx_msec_t)-1) { + u->state->response_time = ngx_current_msec - u->start_time; } if (pc) { - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "close stream proxy upstream connection: %d", pc->fd); + u->state->bytes_received = u->received; + u->state->bytes_sent = pc->sent; + } + } + + if (u->peer.free && u->peer.sockaddr) { + state = 0; + + if (pc && pc->type == SOCK_DGRAM && (pc->read->error || pc->write->error)) { + state = NGX_PEER_FAILED; + } + + u->peer.free(&u->peer, u->peer.data, state); + u->peer.sockaddr = NULL; + } + + if (pc) { + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "close stream proxy upstream connection: %d", pc->fd); #if (NGX_STREAM_SSL) - if (pc->ssl) { - pc->ssl->no_wait_shutdown = 1; - (void) ngx_ssl_shutdown(pc); - } + if (pc->ssl) { + pc->ssl->no_wait_shutdown = 1; + (void)ngx_ssl_shutdown(pc); + } #endif - ngx_close_connection(pc); - u->peer.connection = NULL; - } + ngx_close_connection(pc); + u->peer.connection = NULL; + } noupstream: - ngx_stream_finalize_session(s, rc); + ngx_stream_finalize_session(s, rc); } +static u_char *ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf, + size_t len) { + u_char *p; + ngx_connection_t *pc; + ngx_stream_session_t *s; + ngx_stream_upstream_t *u; -static u_char * -ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len) -{ - u_char *p; - ngx_connection_t *pc; - ngx_stream_session_t *s; - ngx_stream_upstream_t *u; + s = log->data; - s = log->data; + u = s->upstream; - u = s->upstream; + p = buf; - p = buf; + if (u->peer.name) { + p = ngx_snprintf(p, len, ", upstream: \"%V\"", u->peer.name); + len -= p - buf; + } - if (u->peer.name) { - p = ngx_snprintf(p, len, ", upstream: \"%V\"", u->peer.name); - len -= p - buf; - } + pc = u->peer.connection; - pc = u->peer.connection; + p = ngx_snprintf(p, len, + ", bytes from/to client:%O/%O" + ", bytes from/to upstream:%O/%O", + s->received, s->connection->sent, u->received, + pc ? pc->sent : 0); - p = ngx_snprintf(p, len, - ", bytes from/to client:%O/%O" - ", bytes from/to upstream:%O/%O", - s->received, s->connection->sent, - u->received, pc ? pc->sent : 0); - - return p; + return p; } +static void *ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf) { + ngx_stream_proxy_srv_conf_t *conf; -static void * -ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf) -{ - ngx_stream_proxy_srv_conf_t *conf; + conf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_proxy_srv_conf_t)); + if (conf == NULL) { + return NULL; + } - conf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_proxy_srv_conf_t)); - if (conf == NULL) { - return NULL; - } + /* + * set by ngx_pcalloc(): + * + * conf->ssl_protocols = 0; + * conf->ssl_ciphers = { 0, NULL }; + * conf->ssl_trusted_certificate = { 0, NULL }; + * conf->ssl_crl = { 0, NULL }; + * + * conf->ssl = NULL; + * conf->upstream = NULL; + * conf->upstream_value = NULL; + */ - /* - * set by ngx_pcalloc(): - * - * conf->ssl_protocols = 0; - * conf->ssl_ciphers = { 0, NULL }; - * conf->ssl_trusted_certificate = { 0, NULL }; - * conf->ssl_crl = { 0, NULL }; - * - * conf->ssl = NULL; - * conf->upstream = NULL; - * conf->upstream_value = NULL; - */ - - conf->connect_timeout = NGX_CONF_UNSET_MSEC; - conf->timeout = NGX_CONF_UNSET_MSEC; - conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC; - conf->buffer_size = NGX_CONF_UNSET_SIZE; - conf->upload_rate = NGX_CONF_UNSET_PTR; - conf->download_rate = NGX_CONF_UNSET_PTR; - conf->requests = NGX_CONF_UNSET_UINT; - conf->responses = NGX_CONF_UNSET_UINT; - conf->next_upstream_tries = NGX_CONF_UNSET_UINT; - conf->next_upstream = NGX_CONF_UNSET; - conf->proxy_protocol = NGX_CONF_UNSET; - conf->local = NGX_CONF_UNSET_PTR; - conf->socket_keepalive = NGX_CONF_UNSET; - conf->half_close = NGX_CONF_UNSET; + conf->connect_timeout = NGX_CONF_UNSET_MSEC; + conf->timeout = NGX_CONF_UNSET_MSEC; + conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC; + conf->buffer_size = NGX_CONF_UNSET_SIZE; + conf->upload_rate = NGX_CONF_UNSET_PTR; + conf->download_rate = NGX_CONF_UNSET_PTR; + conf->requests = NGX_CONF_UNSET_UINT; + conf->responses = NGX_CONF_UNSET_UINT; + conf->next_upstream_tries = NGX_CONF_UNSET_UINT; + conf->next_upstream = NGX_CONF_UNSET; + conf->proxy_protocol = NGX_CONF_UNSET; + conf->protocol_version = NGX_CONF_UNSET_UINT; + conf->local = NGX_CONF_UNSET_PTR; + conf->socket_keepalive = NGX_CONF_UNSET; + conf->half_close = NGX_CONF_UNSET; #if (NGX_STREAM_SSL) - conf->ssl_enable = NGX_CONF_UNSET; - conf->ssl_session_reuse = NGX_CONF_UNSET; - conf->ssl_name = NGX_CONF_UNSET_PTR; - conf->ssl_server_name = NGX_CONF_UNSET; - conf->ssl_verify = NGX_CONF_UNSET; - conf->ssl_verify_depth = NGX_CONF_UNSET_UINT; - conf->ssl_certificate = NGX_CONF_UNSET_PTR; - conf->ssl_certificate_key = NGX_CONF_UNSET_PTR; - conf->ssl_certificate_cache = NGX_CONF_UNSET_PTR; - conf->ssl_passwords = NGX_CONF_UNSET_PTR; - conf->ssl_conf_commands = NGX_CONF_UNSET_PTR; + conf->ssl_enable = NGX_CONF_UNSET; + conf->ssl_session_reuse = NGX_CONF_UNSET; + conf->ssl_name = NGX_CONF_UNSET_PTR; + conf->ssl_server_name = NGX_CONF_UNSET; + conf->ssl_verify = NGX_CONF_UNSET; + conf->ssl_verify_depth = NGX_CONF_UNSET_UINT; + conf->ssl_certificate = NGX_CONF_UNSET_PTR; + conf->ssl_certificate_key = NGX_CONF_UNSET_PTR; + conf->ssl_certificate_cache = NGX_CONF_UNSET_PTR; + conf->ssl_passwords = NGX_CONF_UNSET_PTR; + conf->ssl_conf_commands = NGX_CONF_UNSET_PTR; #endif - return conf; + return conf; } +static char *ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, + void *child) { + ngx_stream_proxy_srv_conf_t *prev = parent; + ngx_stream_proxy_srv_conf_t *conf = child; -static char * -ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) -{ - ngx_stream_proxy_srv_conf_t *prev = parent; - ngx_stream_proxy_srv_conf_t *conf = child; + ngx_conf_merge_msec_value(conf->connect_timeout, prev->connect_timeout, + 60000); - ngx_conf_merge_msec_value(conf->connect_timeout, - prev->connect_timeout, 60000); + ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 10 * 60000); - ngx_conf_merge_msec_value(conf->timeout, - prev->timeout, 10 * 60000); + ngx_conf_merge_msec_value(conf->next_upstream_timeout, + prev->next_upstream_timeout, 0); - ngx_conf_merge_msec_value(conf->next_upstream_timeout, - prev->next_upstream_timeout, 0); + ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, 16384); - ngx_conf_merge_size_value(conf->buffer_size, - prev->buffer_size, 16384); + ngx_conf_merge_ptr_value(conf->upload_rate, prev->upload_rate, NULL); - ngx_conf_merge_ptr_value(conf->upload_rate, prev->upload_rate, NULL); + ngx_conf_merge_ptr_value(conf->download_rate, prev->download_rate, NULL); - ngx_conf_merge_ptr_value(conf->download_rate, prev->download_rate, NULL); + ngx_conf_merge_uint_value(conf->requests, prev->requests, 0); - ngx_conf_merge_uint_value(conf->requests, - prev->requests, 0); + ngx_conf_merge_uint_value(conf->responses, prev->responses, + NGX_MAX_INT32_VALUE); - ngx_conf_merge_uint_value(conf->responses, - prev->responses, NGX_MAX_INT32_VALUE); + ngx_conf_merge_uint_value(conf->next_upstream_tries, + prev->next_upstream_tries, 0); - ngx_conf_merge_uint_value(conf->next_upstream_tries, - prev->next_upstream_tries, 0); + ngx_conf_merge_value(conf->next_upstream, prev->next_upstream, 1); - ngx_conf_merge_value(conf->next_upstream, prev->next_upstream, 1); + ngx_conf_merge_value(conf->proxy_protocol, prev->proxy_protocol, 0); - ngx_conf_merge_value(conf->proxy_protocol, prev->proxy_protocol, 0); + ngx_conf_merge_ptr_value(conf->local, prev->local, NULL); - ngx_conf_merge_ptr_value(conf->local, prev->local, NULL); + ngx_conf_merge_value(conf->socket_keepalive, prev->socket_keepalive, 0); - ngx_conf_merge_value(conf->socket_keepalive, - prev->socket_keepalive, 0); - - ngx_conf_merge_value(conf->half_close, prev->half_close, 0); + ngx_conf_merge_value(conf->half_close, prev->half_close, 0); #if (NGX_STREAM_SSL) - if (ngx_stream_proxy_merge_ssl(cf, conf, prev) != NGX_OK) { - return NGX_CONF_ERROR; - } + if (ngx_stream_proxy_merge_ssl(cf, conf, prev) != NGX_OK) { + return NGX_CONF_ERROR; + } - ngx_conf_merge_value(conf->ssl_enable, prev->ssl_enable, 0); + ngx_conf_merge_value(conf->ssl_enable, prev->ssl_enable, 0); - ngx_conf_merge_value(conf->ssl_session_reuse, - prev->ssl_session_reuse, 1); + ngx_conf_merge_value(conf->ssl_session_reuse, prev->ssl_session_reuse, 1); - ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols, - (NGX_CONF_BITMASK_SET|NGX_SSL_DEFAULT_PROTOCOLS)); + ngx_conf_merge_bitmask_value( + conf->ssl_protocols, prev->ssl_protocols, + (NGX_CONF_BITMASK_SET | NGX_SSL_DEFAULT_PROTOCOLS)); - ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers, "DEFAULT"); + ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers, "DEFAULT"); - ngx_conf_merge_ptr_value(conf->ssl_name, prev->ssl_name, NULL); + ngx_conf_merge_ptr_value(conf->ssl_name, prev->ssl_name, NULL); - ngx_conf_merge_value(conf->ssl_server_name, prev->ssl_server_name, 0); + ngx_conf_merge_value(conf->ssl_server_name, prev->ssl_server_name, 0); - ngx_conf_merge_value(conf->ssl_verify, prev->ssl_verify, 0); + ngx_conf_merge_value(conf->ssl_verify, prev->ssl_verify, 0); - ngx_conf_merge_uint_value(conf->ssl_verify_depth, - prev->ssl_verify_depth, 1); + ngx_conf_merge_uint_value(conf->ssl_verify_depth, prev->ssl_verify_depth, 1); - ngx_conf_merge_str_value(conf->ssl_trusted_certificate, - prev->ssl_trusted_certificate, ""); + ngx_conf_merge_str_value(conf->ssl_trusted_certificate, + prev->ssl_trusted_certificate, ""); - ngx_conf_merge_str_value(conf->ssl_crl, prev->ssl_crl, ""); + ngx_conf_merge_str_value(conf->ssl_crl, prev->ssl_crl, ""); - ngx_conf_merge_ptr_value(conf->ssl_certificate, - prev->ssl_certificate, NULL); + ngx_conf_merge_ptr_value(conf->ssl_certificate, prev->ssl_certificate, NULL); - ngx_conf_merge_ptr_value(conf->ssl_certificate_key, - prev->ssl_certificate_key, NULL); + ngx_conf_merge_ptr_value(conf->ssl_certificate_key, prev->ssl_certificate_key, + NULL); - ngx_conf_merge_ptr_value(conf->ssl_certificate_cache, - prev->ssl_certificate_cache, NULL); + ngx_conf_merge_ptr_value(conf->ssl_certificate_cache, + prev->ssl_certificate_cache, NULL); - if (ngx_stream_proxy_merge_ssl_passwords(cf, conf, prev) != NGX_OK) { - return NGX_CONF_ERROR; - } + if (ngx_stream_proxy_merge_ssl_passwords(cf, conf, prev) != NGX_OK) { + return NGX_CONF_ERROR; + } - ngx_conf_merge_ptr_value(conf->ssl_conf_commands, - prev->ssl_conf_commands, NULL); + ngx_conf_merge_ptr_value(conf->ssl_conf_commands, prev->ssl_conf_commands, + NULL); - if (conf->ssl_enable && ngx_stream_proxy_set_ssl(cf, conf) != NGX_OK) { - return NGX_CONF_ERROR; - } + if (conf->ssl_enable && ngx_stream_proxy_set_ssl(cf, conf) != NGX_OK) { + return NGX_CONF_ERROR; + } #endif - return NGX_CONF_OK; + return NGX_CONF_OK; } - #if (NGX_STREAM_SSL) -static ngx_int_t -ngx_stream_proxy_merge_ssl(ngx_conf_t *cf, ngx_stream_proxy_srv_conf_t *conf, - ngx_stream_proxy_srv_conf_t *prev) -{ - ngx_uint_t preserve; +static ngx_int_t ngx_stream_proxy_merge_ssl(ngx_conf_t *cf, + ngx_stream_proxy_srv_conf_t *conf, + ngx_stream_proxy_srv_conf_t *prev) { + ngx_uint_t preserve; - if (conf->ssl_protocols == 0 - && conf->ssl_ciphers.data == NULL - && conf->ssl_certificate == NGX_CONF_UNSET_PTR - && conf->ssl_certificate_key == NGX_CONF_UNSET_PTR - && conf->ssl_passwords == NGX_CONF_UNSET_PTR - && conf->ssl_verify == NGX_CONF_UNSET - && conf->ssl_verify_depth == NGX_CONF_UNSET_UINT - && conf->ssl_trusted_certificate.data == NULL - && conf->ssl_crl.data == NULL - && conf->ssl_session_reuse == NGX_CONF_UNSET - && conf->ssl_conf_commands == NGX_CONF_UNSET_PTR) - { - if (prev->ssl) { - conf->ssl = prev->ssl; - return NGX_OK; - } - - preserve = 1; - - } else { - preserve = 0; + if (conf->ssl_protocols == 0 && conf->ssl_ciphers.data == NULL && + conf->ssl_certificate == NGX_CONF_UNSET_PTR && + conf->ssl_certificate_key == NGX_CONF_UNSET_PTR && + conf->ssl_passwords == NGX_CONF_UNSET_PTR && + conf->ssl_verify == NGX_CONF_UNSET && + conf->ssl_verify_depth == NGX_CONF_UNSET_UINT && + conf->ssl_trusted_certificate.data == NULL && + conf->ssl_crl.data == NULL && conf->ssl_session_reuse == NGX_CONF_UNSET && + conf->ssl_conf_commands == NGX_CONF_UNSET_PTR) { + if (prev->ssl) { + conf->ssl = prev->ssl; + return NGX_OK; } - conf->ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t)); - if (conf->ssl == NULL) { - return NGX_ERROR; - } + preserve = 1; - conf->ssl->log = cf->log; + } else { + preserve = 0; + } - /* - * special handling to preserve conf->ssl - * in the "stream" section to inherit it to all servers - */ + conf->ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t)); + if (conf->ssl == NULL) { + return NGX_ERROR; + } - if (preserve) { - prev->ssl = conf->ssl; - } + conf->ssl->log = cf->log; - return NGX_OK; + /* + * special handling to preserve conf->ssl + * in the "stream" section to inherit it to all servers + */ + + if (preserve) { + prev->ssl = conf->ssl; + } + + return NGX_OK; } - static ngx_int_t ngx_stream_proxy_merge_ssl_passwords(ngx_conf_t *cf, - ngx_stream_proxy_srv_conf_t *conf, ngx_stream_proxy_srv_conf_t *prev) -{ - ngx_uint_t preserve; + ngx_stream_proxy_srv_conf_t *conf, + ngx_stream_proxy_srv_conf_t *prev) { + ngx_uint_t preserve; - ngx_conf_merge_ptr_value(conf->ssl_passwords, prev->ssl_passwords, NULL); + ngx_conf_merge_ptr_value(conf->ssl_passwords, prev->ssl_passwords, NULL); - if (conf->ssl_certificate == NULL - || conf->ssl_certificate->value.len == 0 - || conf->ssl_certificate_key == NULL) - { - return NGX_OK; - } + if (conf->ssl_certificate == NULL || conf->ssl_certificate->value.len == 0 || + conf->ssl_certificate_key == NULL) { + return NGX_OK; + } - if (conf->ssl_certificate->lengths == NULL - && conf->ssl_certificate_key->lengths == NULL) - { - if (conf->ssl_passwords && conf->ssl_passwords->pool == NULL) { - /* un-preserve empty password list */ - conf->ssl_passwords = NULL; - } - - return NGX_OK; - } - - if (conf->ssl_passwords && conf->ssl_passwords->pool != cf->temp_pool) { - /* already preserved */ - return NGX_OK; - } - - preserve = (conf->ssl_passwords == prev->ssl_passwords) ? 1 : 0; - - conf->ssl_passwords = ngx_ssl_preserve_passwords(cf, conf->ssl_passwords); - if (conf->ssl_passwords == NULL) { - return NGX_ERROR; - } - - /* - * special handling to keep a preserved ssl_passwords copy - * in the previous configuration to inherit it to all children - */ - - if (preserve) { - prev->ssl_passwords = conf->ssl_passwords; + if (conf->ssl_certificate->lengths == NULL && + conf->ssl_certificate_key->lengths == NULL) { + if (conf->ssl_passwords && conf->ssl_passwords->pool == NULL) { + /* un-preserve empty password list */ + conf->ssl_passwords = NULL; } return NGX_OK; + } + + if (conf->ssl_passwords && conf->ssl_passwords->pool != cf->temp_pool) { + /* already preserved */ + return NGX_OK; + } + + preserve = (conf->ssl_passwords == prev->ssl_passwords) ? 1 : 0; + + conf->ssl_passwords = ngx_ssl_preserve_passwords(cf, conf->ssl_passwords); + if (conf->ssl_passwords == NULL) { + return NGX_ERROR; + } + + /* + * special handling to keep a preserved ssl_passwords copy + * in the previous configuration to inherit it to all children + */ + + if (preserve) { + prev->ssl_passwords = conf->ssl_passwords; + } + + return NGX_OK; } +static ngx_int_t ngx_stream_proxy_set_ssl(ngx_conf_t *cf, + ngx_stream_proxy_srv_conf_t *pscf) { + ngx_pool_cleanup_t *cln; -static ngx_int_t -ngx_stream_proxy_set_ssl(ngx_conf_t *cf, ngx_stream_proxy_srv_conf_t *pscf) -{ - ngx_pool_cleanup_t *cln; - - if (pscf->ssl->ctx) { - return NGX_OK; - } - - if (ngx_ssl_create(pscf->ssl, pscf->ssl_protocols, NULL) != NGX_OK) { - return NGX_ERROR; - } - - cln = ngx_pool_cleanup_add(cf->pool, 0); - if (cln == NULL) { - ngx_ssl_cleanup_ctx(pscf->ssl); - return NGX_ERROR; - } - - cln->handler = ngx_ssl_cleanup_ctx; - cln->data = pscf->ssl; - - if (ngx_ssl_ciphers(cf, pscf->ssl, &pscf->ssl_ciphers, 0) != NGX_OK) { - return NGX_ERROR; - } - - if (pscf->ssl_certificate - && pscf->ssl_certificate->value.len) - { - if (pscf->ssl_certificate_key == NULL) { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - "no \"proxy_ssl_certificate_key\" is defined " - "for certificate \"%V\"", - &pscf->ssl_certificate->value); - return NGX_ERROR; - } - - if (pscf->ssl_certificate->lengths == NULL - && pscf->ssl_certificate_key->lengths == NULL) - { - if (ngx_ssl_certificate(cf, pscf->ssl, - &pscf->ssl_certificate->value, - &pscf->ssl_certificate_key->value, - pscf->ssl_passwords) - != NGX_OK) - { - return NGX_ERROR; - } - } - } - - if (pscf->ssl_verify) { - if (pscf->ssl_trusted_certificate.len == 0) { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - "no proxy_ssl_trusted_certificate for proxy_ssl_verify"); - return NGX_ERROR; - } - - if (ngx_ssl_trusted_certificate(cf, pscf->ssl, - &pscf->ssl_trusted_certificate, - pscf->ssl_verify_depth) - != NGX_OK) - { - return NGX_ERROR; - } - - if (ngx_ssl_crl(cf, pscf->ssl, &pscf->ssl_crl) != NGX_OK) { - return NGX_ERROR; - } - } - - if (ngx_ssl_client_session_cache(cf, pscf->ssl, pscf->ssl_session_reuse) - != NGX_OK) - { - return NGX_ERROR; - } - - if (ngx_ssl_conf_commands(cf, pscf->ssl, pscf->ssl_conf_commands) - != NGX_OK) - { - return NGX_ERROR; - } - + if (pscf->ssl->ctx) { return NGX_OK; + } + + if (ngx_ssl_create(pscf->ssl, pscf->ssl_protocols, NULL) != NGX_OK) { + return NGX_ERROR; + } + + cln = ngx_pool_cleanup_add(cf->pool, 0); + if (cln == NULL) { + ngx_ssl_cleanup_ctx(pscf->ssl); + return NGX_ERROR; + } + + cln->handler = ngx_ssl_cleanup_ctx; + cln->data = pscf->ssl; + + if (ngx_ssl_ciphers(cf, pscf->ssl, &pscf->ssl_ciphers, 0) != NGX_OK) { + return NGX_ERROR; + } + + if (pscf->ssl_certificate && pscf->ssl_certificate->value.len) { + if (pscf->ssl_certificate_key == NULL) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "no \"proxy_ssl_certificate_key\" is defined " + "for certificate \"%V\"", + &pscf->ssl_certificate->value); + return NGX_ERROR; + } + + if (pscf->ssl_certificate->lengths == NULL && + pscf->ssl_certificate_key->lengths == NULL) { + if (ngx_ssl_certificate(cf, pscf->ssl, &pscf->ssl_certificate->value, + &pscf->ssl_certificate_key->value, + pscf->ssl_passwords) != NGX_OK) { + return NGX_ERROR; + } + } + } + + if (pscf->ssl_verify) { + if (pscf->ssl_trusted_certificate.len == 0) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "no proxy_ssl_trusted_certificate for proxy_ssl_verify"); + return NGX_ERROR; + } + + if (ngx_ssl_trusted_certificate(cf, pscf->ssl, + &pscf->ssl_trusted_certificate, + pscf->ssl_verify_depth) != NGX_OK) { + return NGX_ERROR; + } + + if (ngx_ssl_crl(cf, pscf->ssl, &pscf->ssl_crl) != NGX_OK) { + return NGX_ERROR; + } + } + + if (ngx_ssl_client_session_cache(cf, pscf->ssl, pscf->ssl_session_reuse) != + NGX_OK) { + return NGX_ERROR; + } + + if (ngx_ssl_conf_commands(cf, pscf->ssl, pscf->ssl_conf_commands) != NGX_OK) { + return NGX_ERROR; + } + + return NGX_OK; } #endif +static char *ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf) { + ngx_stream_proxy_srv_conf_t *pscf = conf; -static char * -ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) -{ - ngx_stream_proxy_srv_conf_t *pscf = conf; + ngx_url_t u; + ngx_str_t *value, *url; + ngx_stream_complex_value_t cv; + ngx_stream_core_srv_conf_t *cscf; + ngx_stream_compile_complex_value_t ccv; - ngx_url_t u; - ngx_str_t *value, *url; - ngx_stream_complex_value_t cv; - ngx_stream_core_srv_conf_t *cscf; - ngx_stream_compile_complex_value_t ccv; + if (pscf->upstream || pscf->upstream_value) { + return "is duplicate"; + } - if (pscf->upstream || pscf->upstream_value) { - return "is duplicate"; + cscf = ngx_stream_conf_get_module_srv_conf(cf, ngx_stream_core_module); + + cscf->handler = ngx_stream_proxy_handler; + + value = cf->args->elts; + + url = &value[1]; + + ngx_memzero(&ccv, sizeof(ngx_stream_compile_complex_value_t)); + + ccv.cf = cf; + ccv.value = url; + ccv.complex_value = &cv; + + if (ngx_stream_compile_complex_value(&ccv) != NGX_OK) { + return NGX_CONF_ERROR; + } + + if (cv.lengths) { + pscf->upstream_value = + ngx_palloc(cf->pool, sizeof(ngx_stream_complex_value_t)); + if (pscf->upstream_value == NULL) { + return NGX_CONF_ERROR; } - cscf = ngx_stream_conf_get_module_srv_conf(cf, ngx_stream_core_module); - - cscf->handler = ngx_stream_proxy_handler; - - value = cf->args->elts; - - url = &value[1]; - - ngx_memzero(&ccv, sizeof(ngx_stream_compile_complex_value_t)); - - ccv.cf = cf; - ccv.value = url; - ccv.complex_value = &cv; - - if (ngx_stream_compile_complex_value(&ccv) != NGX_OK) { - return NGX_CONF_ERROR; - } - - if (cv.lengths) { - pscf->upstream_value = ngx_palloc(cf->pool, - sizeof(ngx_stream_complex_value_t)); - if (pscf->upstream_value == NULL) { - return NGX_CONF_ERROR; - } - - *pscf->upstream_value = cv; - - return NGX_CONF_OK; - } - - ngx_memzero(&u, sizeof(ngx_url_t)); - - u.url = *url; - u.no_resolve = 1; - - pscf->upstream = ngx_stream_upstream_add(cf, &u, 0); - if (pscf->upstream == NULL) { - return NGX_CONF_ERROR; - } + *pscf->upstream_value = cv; return NGX_CONF_OK; + } + + ngx_memzero(&u, sizeof(ngx_url_t)); + + u.url = *url; + u.no_resolve = 1; + + pscf->upstream = ngx_stream_upstream_add(cf, &u, 0); + if (pscf->upstream == NULL) { + return NGX_CONF_ERROR; + } + + return NGX_CONF_OK; } +static char *ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf) { + ngx_stream_proxy_srv_conf_t *pscf = conf; -static char * -ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) -{ - ngx_stream_proxy_srv_conf_t *pscf = conf; + ngx_int_t rc; + ngx_str_t *value; + ngx_stream_complex_value_t cv; + ngx_stream_upstream_local_t *local; + ngx_stream_compile_complex_value_t ccv; - ngx_int_t rc; - ngx_str_t *value; - ngx_stream_complex_value_t cv; - ngx_stream_upstream_local_t *local; - ngx_stream_compile_complex_value_t ccv; + if (pscf->local != NGX_CONF_UNSET_PTR) { + return "is duplicate"; + } - if (pscf->local != NGX_CONF_UNSET_PTR) { - return "is duplicate"; + value = cf->args->elts; + + if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "off") == 0) { + pscf->local = NULL; + return NGX_CONF_OK; + } + + ngx_memzero(&ccv, sizeof(ngx_stream_compile_complex_value_t)); + + ccv.cf = cf; + ccv.value = &value[1]; + ccv.complex_value = &cv; + + if (ngx_stream_compile_complex_value(&ccv) != NGX_OK) { + return NGX_CONF_ERROR; + } + + local = ngx_pcalloc(cf->pool, sizeof(ngx_stream_upstream_local_t)); + if (local == NULL) { + return NGX_CONF_ERROR; + } + + pscf->local = local; + + if (cv.lengths) { + local->value = ngx_palloc(cf->pool, sizeof(ngx_stream_complex_value_t)); + if (local->value == NULL) { + return NGX_CONF_ERROR; } - value = cf->args->elts; + *local->value = cv; - if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "off") == 0) { - pscf->local = NULL; - return NGX_CONF_OK; + } else { + local->addr = ngx_palloc(cf->pool, sizeof(ngx_addr_t)); + if (local->addr == NULL) { + return NGX_CONF_ERROR; } - ngx_memzero(&ccv, sizeof(ngx_stream_compile_complex_value_t)); + rc = + ngx_parse_addr_port(cf->pool, local->addr, value[1].data, value[1].len); - ccv.cf = cf; - ccv.value = &value[1]; - ccv.complex_value = &cv; + switch (rc) { + case NGX_OK: + local->addr->name = value[1]; + break; - if (ngx_stream_compile_complex_value(&ccv) != NGX_OK) { - return NGX_CONF_ERROR; + case NGX_DECLINED: + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid address \"%V\"", + &value[1]); + /* fall through */ + + default: + return NGX_CONF_ERROR; } + } - local = ngx_pcalloc(cf->pool, sizeof(ngx_stream_upstream_local_t)); - if (local == NULL) { - return NGX_CONF_ERROR; - } - - pscf->local = local; - - if (cv.lengths) { - local->value = ngx_palloc(cf->pool, sizeof(ngx_stream_complex_value_t)); - if (local->value == NULL) { - return NGX_CONF_ERROR; - } - - *local->value = cv; - - } else { - local->addr = ngx_palloc(cf->pool, sizeof(ngx_addr_t)); - if (local->addr == NULL) { - return NGX_CONF_ERROR; - } - - rc = ngx_parse_addr_port(cf->pool, local->addr, value[1].data, - value[1].len); - - switch (rc) { - case NGX_OK: - local->addr->name = value[1]; - break; - - case NGX_DECLINED: - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid address \"%V\"", &value[1]); - /* fall through */ - - default: - return NGX_CONF_ERROR; - } - } - - if (cf->args->nelts > 2) { - if (ngx_strcmp(value[2].data, "transparent") == 0) { + if (cf->args->nelts > 2) { + if (ngx_strcmp(value[2].data, "transparent") == 0) { #if (NGX_HAVE_TRANSPARENT_PROXY) - ngx_core_conf_t *ccf; + ngx_core_conf_t *ccf; - ccf = (ngx_core_conf_t *) ngx_get_conf(cf->cycle->conf_ctx, - ngx_core_module); + ccf = + (ngx_core_conf_t *)ngx_get_conf(cf->cycle->conf_ctx, ngx_core_module); - ccf->transparent = 1; - local->transparent = 1; + ccf->transparent = 1; + local->transparent = 1; #else - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "transparent proxying is not supported " - "on this platform, ignored"); + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "transparent proxying is not supported " + "on this platform, ignored"); #endif - } else { - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "invalid parameter \"%V\"", &value[2]); - return NGX_CONF_ERROR; - } + } else { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%V\"", + &value[2]); + return NGX_CONF_ERROR; } + } - return NGX_CONF_OK; + return NGX_CONF_OK; } From d436cae655a5e62d67707e842e8f6610bf86f3af Mon Sep 17 00:00:00 2001 From: Moses DeWitt-Monroy Date: Wed, 19 Nov 2025 11:08:41 -0600 Subject: [PATCH 2/5] fix(stream/proxy): fixed bugs with the ip6 and fixed typeos. --- src/core/ngx_proxy_protocol.c | 17 ++++------------- src/stream/ngx_stream_proxy_module.c | 2 ++ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/core/ngx_proxy_protocol.c b/src/core/ngx_proxy_protocol.c index 96e8542db..21b0eb55a 100644 --- a/src/core/ngx_proxy_protocol.c +++ b/src/core/ngx_proxy_protocol.c @@ -4,15 +4,8 @@ * Copyright (C) Nginx, Inc. */ - -#include #include #include -#include -#include -#include -#include -#include #define NGX_PROXY_PROTOCOL_AF_INET 1 @@ -333,13 +326,12 @@ ngx_proxy_protocol_v2_write(ngx_connection_t *c, u_char *buf, u_char *last) { u_char *buf_ptr = buf; ngx_uint_t port, lport; - if (last-buf < NGX_PROXY_PROTOCOL_V2_MAX_HEADER) { - ngx_log_error(NGX_LOG_ALERT, c->log, 0, "the buffer is to small for proxy protocol v2"); + if (last - buf < NGX_PROXY_PROTOCOL_V2_MAX_HEADER) { + ngx_log_error(NGX_LOG_ALERT, c->log, 0, "the buffer is too small for proxy protocol v2"); return NULL; } buf_ptr = ngx_cpymem(buf_ptr, NGX_PROXY_PROTOCOL_V2_SIG, 12); - *buf_ptr++ = 0x21; port = ngx_inet_get_port(c->sockaddr); @@ -371,8 +363,6 @@ ngx_proxy_protocol_v2_write(ngx_connection_t *c, u_char *buf, u_char *last) { } #if (NGX_HAVE_INET6) case AF_INET6: { - *buf_ptr++ = 0x21; - *buf_ptr++ = 0x00; *buf_ptr++ = 0x24; @@ -397,7 +387,8 @@ ngx_proxy_protocol_v2_write(ngx_connection_t *c, u_char *buf, u_char *last) { *buf_ptr++ = 0x00; *buf_ptr++ = 0x00; *buf_ptr++ = 0x00; - break; + ngx_log_error(NGX_LOG_ALERT, c->log, 0, "unsupported address family"); + return NULL; } } diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c index 33e9127ac..a7724c9e9 100644 --- a/src/stream/ngx_stream_proxy_module.c +++ b/src/stream/ngx_stream_proxy_module.c @@ -2102,6 +2102,8 @@ static char *ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, ngx_conf_merge_value(conf->proxy_protocol, prev->proxy_protocol, 0); + ngx_conf_merge_uint_value(conf->protocol_version, prev->protocol_version, 1); + ngx_conf_merge_ptr_value(conf->local, prev->local, NULL); ngx_conf_merge_value(conf->socket_keepalive, prev->socket_keepalive, 0); From 136e99a1b5569be491f0ca04eae561a776cc6159 Mon Sep 17 00:00:00 2001 From: mdewitt11 <129132141+mdewitt11@users.noreply.github.com> Date: Mon, 24 Nov 2025 14:54:17 -0600 Subject: [PATCH 3/5] Delete compile_commands.json i forgot to clean up this file --- compile_commands.json | 4320 ----------------------------------------- 1 file changed, 4320 deletions(-) delete mode 100644 compile_commands.json diff --git a/compile_commands.json b/compile_commands.json deleted file mode 100644 index c615d3126..000000000 --- a/compile_commands.json +++ /dev/null @@ -1,4320 +0,0 @@ -[ - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_output_chain.o", - "src/core/ngx_output_chain.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_output_chain.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_output_chain.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_list.o", - "src/core/ngx_list.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_list.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_list.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_array.o", - "src/core/ngx_array.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_array.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_array.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/nginx.o", - "src/core/nginx.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/nginx.c", - "output": "/home/moses/projects/nginx/objs/src/core/nginx.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_palloc.o", - "src/core/ngx_palloc.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_palloc.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_palloc.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_buf.o", - "src/core/ngx_buf.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_buf.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_buf.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_string.o", - "src/core/ngx_string.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_string.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_string.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_hash.o", - "src/core/ngx_hash.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_hash.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_hash.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_log.o", - "src/core/ngx_log.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_log.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_log.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_parse_time.o", - "src/core/ngx_parse_time.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_parse_time.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_parse_time.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_queue.o", - "src/core/ngx_queue.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_queue.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_queue.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_parse.o", - "src/core/ngx_parse.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_parse.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_parse.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_inet.o", - "src/core/ngx_inet.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_inet.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_inet.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_crc32.o", - "src/core/ngx_crc32.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_crc32.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_crc32.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_file.o", - "src/core/ngx_file.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_file.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_file.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_murmurhash.o", - "src/core/ngx_murmurhash.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_murmurhash.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_murmurhash.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_slab.o", - "src/core/ngx_slab.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_slab.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_slab.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_rbtree.o", - "src/core/ngx_rbtree.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_rbtree.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_rbtree.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_radix_tree.o", - "src/core/ngx_radix_tree.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_radix_tree.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_radix_tree.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_md5.o", - "src/core/ngx_md5.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_md5.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_md5.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_times.o", - "src/core/ngx_times.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_times.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_times.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_sha1.o", - "src/core/ngx_sha1.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_sha1.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_sha1.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_shmtx.o", - "src/core/ngx_shmtx.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_shmtx.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_shmtx.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_connection.o", - "src/core/ngx_connection.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_connection.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_connection.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_cycle.o", - "src/core/ngx_cycle.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_cycle.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_cycle.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_rwlock.o", - "src/core/ngx_rwlock.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_rwlock.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_rwlock.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_spinlock.o", - "src/core/ngx_spinlock.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_spinlock.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_spinlock.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_cpuinfo.o", - "src/core/ngx_cpuinfo.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_cpuinfo.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_cpuinfo.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_resolver.o", - "src/core/ngx_resolver.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_resolver.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_resolver.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_conf_file.o", - "src/core/ngx_conf_file.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_conf_file.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_conf_file.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_module.o", - "src/core/ngx_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_module.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_open_file_cache.o", - "src/core/ngx_open_file_cache.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_open_file_cache.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_open_file_cache.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_crypt.o", - "src/core/ngx_crypt.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_crypt.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_crypt.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_syslog.o", - "src/core/ngx_syslog.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_syslog.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_syslog.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_proxy_protocol.o", - "src/core/ngx_proxy_protocol.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_proxy_protocol.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_proxy_protocol.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/event/ngx_event.o", - "src/event/ngx_event.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/event/ngx_event.c", - "output": "/home/moses/projects/nginx/objs/src/event/ngx_event.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/event/ngx_event_timer.o", - "src/event/ngx_event_timer.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/event/ngx_event_timer.c", - "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_timer.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/event/ngx_event_posted.o", - "src/event/ngx_event_posted.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/event/ngx_event_posted.c", - "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_posted.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/event/ngx_event_accept.o", - "src/event/ngx_event_accept.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/event/ngx_event_accept.c", - "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_accept.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/event/ngx_event_udp.o", - "src/event/ngx_event_udp.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/event/ngx_event_udp.c", - "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_udp.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/event/ngx_event_connect.o", - "src/event/ngx_event_connect.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/event/ngx_event_connect.c", - "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_connect.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/event/ngx_event_pipe.o", - "src/event/ngx_event_pipe.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/event/ngx_event_pipe.c", - "output": "/home/moses/projects/nginx/objs/src/event/ngx_event_pipe.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_time.o", - "src/os/unix/ngx_time.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_time.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_time.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_errno.o", - "src/os/unix/ngx_errno.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_errno.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_errno.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_alloc.o", - "src/os/unix/ngx_alloc.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_alloc.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_alloc.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_files.o", - "src/os/unix/ngx_files.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_files.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_files.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_socket.o", - "src/os/unix/ngx_socket.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_socket.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_socket.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_recv.o", - "src/os/unix/ngx_recv.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_recv.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_recv.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_readv_chain.o", - "src/os/unix/ngx_readv_chain.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_readv_chain.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_readv_chain.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_udp_recv.o", - "src/os/unix/ngx_udp_recv.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_udp_recv.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_udp_recv.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_send.o", - "src/os/unix/ngx_send.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_send.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_send.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_writev_chain.o", - "src/os/unix/ngx_writev_chain.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_writev_chain.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_writev_chain.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_udp_send.o", - "src/os/unix/ngx_udp_send.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_udp_send.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_udp_send.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_udp_sendmsg_chain.o", - "src/os/unix/ngx_udp_sendmsg_chain.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_udp_sendmsg_chain.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_udp_sendmsg_chain.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_shmem.o", - "src/os/unix/ngx_shmem.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_shmem.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_shmem.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_channel.o", - "src/os/unix/ngx_channel.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_channel.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_channel.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_process.o", - "src/os/unix/ngx_process.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_process.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_process.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_daemon.o", - "src/os/unix/ngx_daemon.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_daemon.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_daemon.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_setaffinity.o", - "src/os/unix/ngx_setaffinity.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_setaffinity.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_setaffinity.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_setproctitle.o", - "src/os/unix/ngx_setproctitle.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_setproctitle.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_setproctitle.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_posix_init.o", - "src/os/unix/ngx_posix_init.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_posix_init.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_posix_init.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_user.o", - "src/os/unix/ngx_user.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_user.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_user.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_dlopen.o", - "src/os/unix/ngx_dlopen.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_dlopen.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_dlopen.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_process_cycle.o", - "src/os/unix/ngx_process_cycle.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_process_cycle.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_process_cycle.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_linux_init.o", - "src/os/unix/ngx_linux_init.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_linux_init.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_linux_init.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/event/modules/ngx_epoll_module.o", - "src/event/modules/ngx_epoll_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/event/modules/ngx_epoll_module.c", - "output": "/home/moses/projects/nginx/objs/src/event/modules/ngx_epoll_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/os/unix/ngx_linux_sendfile_chain.o", - "src/os/unix/ngx_linux_sendfile_chain.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/os/unix/ngx_linux_sendfile_chain.c", - "output": "/home/moses/projects/nginx/objs/src/os/unix/ngx_linux_sendfile_chain.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_bpf.o", - "src/core/ngx_bpf.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_bpf.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_bpf.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/src/core/ngx_regex.o", - "src/core/ngx_regex.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/core/ngx_regex.c", - "output": "/home/moses/projects/nginx/objs/src/core/ngx_regex.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http.o", - "src/http/ngx_http.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_special_response.o", - "src/http/ngx_http_special_response.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_special_response.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_special_response.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_core_module.o", - "src/http/ngx_http_core_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_core_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_core_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_request.o", - "src/http/ngx_http_request.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_request.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_request.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_parse.o", - "src/http/ngx_http_parse.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_parse.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_parse.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_log_module.o", - "src/http/modules/ngx_http_log_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_log_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_log_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_request_body.o", - "src/http/ngx_http_request_body.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_request_body.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_request_body.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_variables.o", - "src/http/ngx_http_variables.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_variables.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_variables.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_script.o", - "src/http/ngx_http_script.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_script.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_script.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_upstream.o", - "src/http/ngx_http_upstream.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_upstream.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_upstream.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_upstream_round_robin.o", - "src/http/ngx_http_upstream_round_robin.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_upstream_round_robin.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_upstream_round_robin.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_file_cache.o", - "src/http/ngx_http_file_cache.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_file_cache.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_file_cache.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_write_filter_module.o", - "src/http/ngx_http_write_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_write_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_write_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_header_filter_module.o", - "src/http/ngx_http_header_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_header_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_header_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_chunked_filter_module.o", - "src/http/modules/ngx_http_chunked_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_chunked_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_chunked_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_range_filter_module.o", - "src/http/modules/ngx_http_range_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_range_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_range_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_gzip_filter_module.o", - "src/http/modules/ngx_http_gzip_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_gzip_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_gzip_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_postpone_filter_module.o", - "src/http/ngx_http_postpone_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_postpone_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_postpone_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_ssi_filter_module.o", - "src/http/modules/ngx_http_ssi_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_ssi_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_ssi_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_charset_filter_module.o", - "src/http/modules/ngx_http_charset_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_charset_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_charset_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_userid_filter_module.o", - "src/http/modules/ngx_http_userid_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_userid_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_userid_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/ngx_http_copy_filter_module.o", - "src/http/ngx_http_copy_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/ngx_http_copy_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/ngx_http_copy_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_headers_filter_module.o", - "src/http/modules/ngx_http_headers_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_headers_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_headers_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_not_modified_filter_module.o", - "src/http/modules/ngx_http_not_modified_filter_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_not_modified_filter_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_not_modified_filter_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_autoindex_module.o", - "src/http/modules/ngx_http_autoindex_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_autoindex_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_autoindex_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_static_module.o", - "src/http/modules/ngx_http_static_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_static_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_static_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_mirror_module.o", - "src/http/modules/ngx_http_mirror_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_mirror_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_mirror_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_index_module.o", - "src/http/modules/ngx_http_index_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_index_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_index_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_try_files_module.o", - "src/http/modules/ngx_http_try_files_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_try_files_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_try_files_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_auth_basic_module.o", - "src/http/modules/ngx_http_auth_basic_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_auth_basic_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_auth_basic_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_access_module.o", - "src/http/modules/ngx_http_access_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_access_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_access_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_limit_conn_module.o", - "src/http/modules/ngx_http_limit_conn_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_limit_conn_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_limit_conn_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_limit_req_module.o", - "src/http/modules/ngx_http_limit_req_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_limit_req_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_limit_req_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_map_module.o", - "src/http/modules/ngx_http_map_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_map_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_map_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_geo_module.o", - "src/http/modules/ngx_http_geo_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_geo_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_geo_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_split_clients_module.o", - "src/http/modules/ngx_http_split_clients_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_split_clients_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_split_clients_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_referer_module.o", - "src/http/modules/ngx_http_referer_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_referer_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_referer_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_rewrite_module.o", - "src/http/modules/ngx_http_rewrite_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_rewrite_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_rewrite_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_proxy_module.o", - "src/http/modules/ngx_http_proxy_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_proxy_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_proxy_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_fastcgi_module.o", - "src/http/modules/ngx_http_fastcgi_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_fastcgi_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_fastcgi_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_uwsgi_module.o", - "src/http/modules/ngx_http_uwsgi_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_uwsgi_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_uwsgi_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_scgi_module.o", - "src/http/modules/ngx_http_scgi_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_scgi_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_scgi_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_memcached_module.o", - "src/http/modules/ngx_http_memcached_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_memcached_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_memcached_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_empty_gif_module.o", - "src/http/modules/ngx_http_empty_gif_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_empty_gif_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_empty_gif_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_upstream_ip_hash_module.o", - "src/http/modules/ngx_http_upstream_ip_hash_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_ip_hash_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_browser_module.o", - "src/http/modules/ngx_http_browser_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_browser_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_browser_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_upstream_hash_module.o", - "src/http/modules/ngx_http_upstream_hash_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_hash_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_hash_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_upstream_least_conn_module.o", - "src/http/modules/ngx_http_upstream_least_conn_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_least_conn_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_upstream_random_module.o", - "src/http/modules/ngx_http_upstream_random_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_random_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_random_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_upstream_keepalive_module.o", - "src/http/modules/ngx_http_upstream_keepalive_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_keepalive_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-I", - "src/http", - "-I", - "src/http/modules", - "-o", - "objs/src/http/modules/ngx_http_upstream_zone_module.o", - "src/http/modules/ngx_http_upstream_zone_module.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/src/http/modules/ngx_http_upstream_zone_module.c", - "output": "/home/moses/projects/nginx/objs/src/http/modules/ngx_http_upstream_zone_module.o" - }, - { - "arguments": [ - "/usr/bin/cc", - "-c", - "-pipe", - "-O", - "-W", - "-Wall", - "-Wpointer-arith", - "-Wno-unused-parameter", - "-Werror", - "-g", - "-g3", - "-O0", - "-I", - "src/core", - "-I", - "src/event", - "-I", - "src/event/modules", - "-I", - "src/event/quic", - "-I", - "src/os/unix", - "-I", - "objs", - "-o", - "objs/ngx_modules.o", - "objs/ngx_modules.c" - ], - "directory": "/home/moses/projects/nginx", - "file": "/home/moses/projects/nginx/objs/ngx_modules.c", - "output": "/home/moses/projects/nginx/objs/ngx_modules.o" - } -] From 3146f796eaa228e9249253b62ac57cae68e8e1dc Mon Sep 17 00:00:00 2001 From: Moses DeWitt-Monroy Date: Fri, 30 Jan 2026 13:29:43 -0600 Subject: [PATCH 4/5] reformat: reset the format of the edited code --- src/stream/ngx_stream_proxy_module.c | 4340 ++++++++++++++------------ temp/logs/error.log | 36 + temp/logs/nginx.pid | 1 + temp/nginx.conf | 22 + 4 files changed, 2340 insertions(+), 2059 deletions(-) create mode 100644 temp/logs/error.log create mode 100644 temp/logs/nginx.pid create mode 100644 temp/nginx.conf diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c index a7724c9e9..ec04c9fdb 100644 --- a/src/stream/ngx_stream_proxy_module.c +++ b/src/stream/ngx_stream_proxy_module.c @@ -4,2482 +4,2704 @@ * Copyright (C) Nginx, Inc. */ -#include "ngx_proxy_protocol.h" + #include #include #include + typedef struct { - ngx_addr_t *addr; - ngx_stream_complex_value_t *value; + ngx_addr_t *addr; + ngx_stream_complex_value_t *value; #if (NGX_HAVE_TRANSPARENT_PROXY) - ngx_uint_t transparent; /* unsigned transparent:1; */ + ngx_uint_t transparent; /* unsigned transparent:1; */ #endif } ngx_stream_upstream_local_t; + typedef struct { - ngx_msec_t connect_timeout; - ngx_msec_t timeout; - ngx_msec_t next_upstream_timeout; - size_t buffer_size; - ngx_stream_complex_value_t *upload_rate; - ngx_stream_complex_value_t *download_rate; - ngx_uint_t requests; - ngx_uint_t responses; - ngx_uint_t next_upstream_tries; - ngx_flag_t next_upstream; - ngx_flag_t proxy_protocol; - ngx_uint_t protocol_version; - ngx_flag_t half_close; - ngx_stream_upstream_local_t *local; - ngx_flag_t socket_keepalive; + ngx_msec_t connect_timeout; + ngx_msec_t timeout; + ngx_msec_t next_upstream_timeout; + size_t buffer_size; + ngx_stream_complex_value_t *upload_rate; + ngx_stream_complex_value_t *download_rate; + ngx_uint_t requests; + ngx_uint_t responses; + ngx_uint_t next_upstream_tries; + ngx_flag_t next_upstream; + ngx_flag_t proxy_protocol; + ngx_flag_t protocol_version; + ngx_flag_t half_close; + ngx_stream_upstream_local_t *local; + ngx_flag_t socket_keepalive; #if (NGX_STREAM_SSL) - ngx_flag_t ssl_enable; - ngx_flag_t ssl_session_reuse; - ngx_uint_t ssl_protocols; - ngx_str_t ssl_ciphers; - ngx_stream_complex_value_t *ssl_name; - ngx_flag_t ssl_server_name; + ngx_flag_t ssl_enable; + ngx_flag_t ssl_session_reuse; + ngx_uint_t ssl_protocols; + ngx_str_t ssl_ciphers; + ngx_stream_complex_value_t *ssl_name; + ngx_flag_t ssl_server_name; - ngx_flag_t ssl_verify; - ngx_uint_t ssl_verify_depth; - ngx_str_t ssl_trusted_certificate; - ngx_str_t ssl_crl; - ngx_stream_complex_value_t *ssl_certificate; - ngx_stream_complex_value_t *ssl_certificate_key; - ngx_ssl_cache_t *ssl_certificate_cache; - ngx_array_t *ssl_passwords; - ngx_array_t *ssl_conf_commands; + ngx_flag_t ssl_verify; + ngx_uint_t ssl_verify_depth; + ngx_str_t ssl_trusted_certificate; + ngx_str_t ssl_crl; + ngx_stream_complex_value_t *ssl_certificate; + ngx_stream_complex_value_t *ssl_certificate_key; + ngx_ssl_cache_t *ssl_certificate_cache; + ngx_array_t *ssl_passwords; + ngx_array_t *ssl_conf_commands; - ngx_ssl_t *ssl; + ngx_ssl_t *ssl; #endif - ngx_stream_upstream_srv_conf_t *upstream; - ngx_stream_complex_value_t *upstream_value; + ngx_stream_upstream_srv_conf_t *upstream; + ngx_stream_complex_value_t *upstream_value; } ngx_stream_proxy_srv_conf_t; + static void ngx_stream_proxy_handler(ngx_stream_session_t *s); static ngx_int_t ngx_stream_proxy_eval(ngx_stream_session_t *s, - ngx_stream_proxy_srv_conf_t *pscf); + ngx_stream_proxy_srv_conf_t *pscf); static ngx_int_t ngx_stream_proxy_set_local(ngx_stream_session_t *s, - ngx_stream_upstream_t *u, - ngx_stream_upstream_local_t *local); + ngx_stream_upstream_t *u, ngx_stream_upstream_local_t *local); static void ngx_stream_proxy_connect(ngx_stream_session_t *s); static void ngx_stream_proxy_init_upstream(ngx_stream_session_t *s); static void ngx_stream_proxy_resolve_handler(ngx_resolver_ctx_t *ctx); static void ngx_stream_proxy_upstream_handler(ngx_event_t *ev); static void ngx_stream_proxy_downstream_handler(ngx_event_t *ev); static void ngx_stream_proxy_process_connection(ngx_event_t *ev, - ngx_uint_t from_upstream); + ngx_uint_t from_upstream); static void ngx_stream_proxy_connect_handler(ngx_event_t *ev); static ngx_int_t ngx_stream_proxy_test_connect(ngx_connection_t *c); static void ngx_stream_proxy_process(ngx_stream_session_t *s, - ngx_uint_t from_upstream, - ngx_uint_t do_write); + ngx_uint_t from_upstream, ngx_uint_t do_write); static ngx_int_t ngx_stream_proxy_test_finalize(ngx_stream_session_t *s, - ngx_uint_t from_upstream); + ngx_uint_t from_upstream); static void ngx_stream_proxy_next_upstream(ngx_stream_session_t *s); static void ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc); static u_char *ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf, - size_t len); + size_t len); static void *ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf); static char *ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, - void *child); + void *child); static char *ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); static char *ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf); + void *conf); #if (NGX_STREAM_SSL) static ngx_int_t ngx_stream_proxy_send_proxy_protocol(ngx_stream_session_t *s); static char *ngx_stream_proxy_ssl_certificate_cache(ngx_conf_t *cf, - ngx_command_t *cmd, - void *conf); + ngx_command_t *cmd, void *conf); static char *ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf, - ngx_command_t *cmd, void *conf); + ngx_command_t *cmd, void *conf); static char *ngx_stream_proxy_ssl_conf_command_check(ngx_conf_t *cf, void *post, - void *data); + void *data); static void ngx_stream_proxy_ssl_init_connection(ngx_stream_session_t *s); static void ngx_stream_proxy_ssl_handshake(ngx_connection_t *pc); static void ngx_stream_proxy_ssl_save_session(ngx_connection_t *c); static ngx_int_t ngx_stream_proxy_ssl_name(ngx_stream_session_t *s); static ngx_int_t ngx_stream_proxy_ssl_certificate(ngx_stream_session_t *s); static ngx_int_t ngx_stream_proxy_merge_ssl(ngx_conf_t *cf, - ngx_stream_proxy_srv_conf_t *conf, - ngx_stream_proxy_srv_conf_t *prev); -static ngx_int_t -ngx_stream_proxy_merge_ssl_passwords(ngx_conf_t *cf, - ngx_stream_proxy_srv_conf_t *conf, - ngx_stream_proxy_srv_conf_t *prev); + ngx_stream_proxy_srv_conf_t *conf, ngx_stream_proxy_srv_conf_t *prev); +static ngx_int_t ngx_stream_proxy_merge_ssl_passwords(ngx_conf_t *cf, + ngx_stream_proxy_srv_conf_t *conf, ngx_stream_proxy_srv_conf_t *prev); static ngx_int_t ngx_stream_proxy_set_ssl(ngx_conf_t *cf, - ngx_stream_proxy_srv_conf_t *pscf); + ngx_stream_proxy_srv_conf_t *pscf); -static ngx_conf_bitmask_t ngx_stream_proxy_ssl_protocols[] = { - {ngx_string("SSLv2"), NGX_SSL_SSLv2}, - {ngx_string("SSLv3"), NGX_SSL_SSLv3}, - {ngx_string("TLSv1"), NGX_SSL_TLSv1}, - {ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1}, - {ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2}, - {ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3}, - {ngx_null_string, 0}}; -static ngx_conf_post_t ngx_stream_proxy_ssl_conf_command_post = { - ngx_stream_proxy_ssl_conf_command_check}; - -#endif - -static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_downstream_buffer = { - ngx_conf_deprecated, "proxy_downstream_buffer", "proxy_buffer_size"}; - -static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_upstream_buffer = { - ngx_conf_deprecated, "proxy_upstream_buffer", "proxy_buffer_size"}; - -static ngx_command_t ngx_stream_proxy_commands[] = { - - {ngx_string("proxy_pass"), NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_stream_proxy_pass, NGX_STREAM_SRV_CONF_OFFSET, 0, NULL}, - - {ngx_string("proxy_bind"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE12, - ngx_stream_proxy_bind, NGX_STREAM_SRV_CONF_OFFSET, 0, NULL}, - - {ngx_string("proxy_socket_keepalive"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, - ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, socket_keepalive), NULL}, - - {ngx_string("proxy_connect_timeout"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_msec_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, connect_timeout), NULL}, - - {ngx_string("proxy_timeout"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_msec_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, timeout), NULL}, - - {ngx_string("proxy_buffer_size"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_size_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), NULL}, - - {ngx_string("proxy_downstream_buffer"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_size_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), - &ngx_conf_deprecated_proxy_downstream_buffer}, - - {ngx_string("proxy_upstream_buffer"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_size_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), - &ngx_conf_deprecated_proxy_upstream_buffer}, - - {ngx_string("proxy_upload_rate"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_stream_set_complex_value_size_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, upload_rate), NULL}, - - {ngx_string("proxy_download_rate"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_stream_set_complex_value_size_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, download_rate), NULL}, - - {ngx_string("proxy_requests"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_num_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, requests), NULL}, - - {ngx_string("proxy_responses"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_num_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, responses), NULL}, - - {ngx_string("proxy_next_upstream"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, - ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, next_upstream), NULL}, - - {ngx_string("proxy_next_upstream_tries"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_num_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_tries), NULL}, - - {ngx_string("proxy_next_upstream_timeout"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_msec_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_timeout), NULL}, - - {ngx_string("proxy_protocol"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, - ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, proxy_protocol), NULL}, - - {ngx_string("proxy_protocol_version"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_num_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, protocol_version), NULL}, - - {ngx_string("proxy_half_close"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, - ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, half_close), NULL}, - -#if (NGX_STREAM_SSL) - - {ngx_string("proxy_ssl"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, - ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_enable), NULL}, - - {ngx_string("proxy_ssl_session_reuse"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, - ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_session_reuse), NULL}, - - {ngx_string("proxy_ssl_protocols"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_1MORE, - ngx_conf_set_bitmask_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_protocols), - &ngx_stream_proxy_ssl_protocols}, - - {ngx_string("proxy_ssl_ciphers"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_str_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_ciphers), NULL}, - - {ngx_string("proxy_ssl_name"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_stream_set_complex_value_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_name), NULL}, - - {ngx_string("proxy_ssl_server_name"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, - ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_server_name), NULL}, - - {ngx_string("proxy_ssl_verify"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_FLAG, - ngx_conf_set_flag_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify), NULL}, - - {ngx_string("proxy_ssl_verify_depth"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_num_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify_depth), NULL}, - - {ngx_string("proxy_ssl_trusted_certificate"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_str_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_trusted_certificate), NULL}, - - {ngx_string("proxy_ssl_crl"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_conf_set_str_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_crl), NULL}, - - {ngx_string("proxy_ssl_certificate"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_stream_set_complex_value_zero_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate), NULL}, - - {ngx_string("proxy_ssl_certificate_key"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_stream_set_complex_value_zero_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate_key), NULL}, - - {ngx_string("proxy_ssl_certificate_cache"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE123, - ngx_stream_proxy_ssl_certificate_cache, NGX_STREAM_SRV_CONF_OFFSET, 0, - NULL}, - - {ngx_string("proxy_ssl_password_file"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, - ngx_stream_proxy_ssl_password_file, NGX_STREAM_SRV_CONF_OFFSET, 0, NULL}, - - {ngx_string("proxy_ssl_conf_command"), - NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE2, - ngx_conf_set_keyval_slot, NGX_STREAM_SRV_CONF_OFFSET, - offsetof(ngx_stream_proxy_srv_conf_t, ssl_conf_commands), - &ngx_stream_proxy_ssl_conf_command_post}, - -#endif - - ngx_null_command}; - -static ngx_stream_module_t ngx_stream_proxy_module_ctx = { - NULL, /* preconfiguration */ - NULL, /* postconfiguration */ - - NULL, /* create main configuration */ - NULL, /* init main configuration */ - - ngx_stream_proxy_create_srv_conf, /* create server configuration */ - ngx_stream_proxy_merge_srv_conf /* merge server configuration */ +static ngx_conf_bitmask_t ngx_stream_proxy_ssl_protocols[] = { + { ngx_string("SSLv2"), NGX_SSL_SSLv2 }, + { ngx_string("SSLv3"), NGX_SSL_SSLv3 }, + { ngx_string("TLSv1"), NGX_SSL_TLSv1 }, + { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 }, + { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 }, + { ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3 }, + { ngx_null_string, 0 } }; -ngx_module_t ngx_stream_proxy_module = { - NGX_MODULE_V1, - &ngx_stream_proxy_module_ctx, /* module context */ - ngx_stream_proxy_commands, /* module directives */ - NGX_STREAM_MODULE, /* module type */ - NULL, /* init master */ - NULL, /* init module */ - NULL, /* init process */ - NULL, /* init thread */ - NULL, /* exit thread */ - NULL, /* exit process */ - NULL, /* exit master */ - NGX_MODULE_V1_PADDING}; +static ngx_conf_post_t ngx_stream_proxy_ssl_conf_command_post = + { ngx_stream_proxy_ssl_conf_command_check }; -static void ngx_stream_proxy_handler(ngx_stream_session_t *s) { - u_char *p; - ngx_str_t *host; - ngx_uint_t i; - ngx_connection_t *c; - ngx_resolver_ctx_t *ctx, temp; - ngx_stream_upstream_t *u; - ngx_stream_core_srv_conf_t *cscf; - ngx_stream_proxy_srv_conf_t *pscf; - ngx_stream_upstream_srv_conf_t *uscf, **uscfp; - ngx_stream_upstream_main_conf_t *umcf; - - c = s->connection; - - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - - ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connection handler"); - - u = ngx_pcalloc(c->pool, sizeof(ngx_stream_upstream_t)); - if (u == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - s->upstream = u; - - s->log_handler = ngx_stream_proxy_log_error; - - u->requests = 1; - - u->peer.log = c->log; - u->peer.log_error = NGX_ERROR_ERR; - - if (ngx_stream_proxy_set_local(s, u, pscf->local) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - if (pscf->socket_keepalive) { - u->peer.so_keepalive = 1; - } - - u->peer.type = c->type; - u->start_sec = ngx_time(); - - c->write->handler = ngx_stream_proxy_downstream_handler; - c->read->handler = ngx_stream_proxy_downstream_handler; - - s->upstream_states = - ngx_array_create(c->pool, 1, sizeof(ngx_stream_upstream_state_t)); - if (s->upstream_states == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - p = ngx_pnalloc(c->pool, pscf->buffer_size); - if (p == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - u->downstream_buf.start = p; - u->downstream_buf.end = p + pscf->buffer_size; - u->downstream_buf.pos = p; - u->downstream_buf.last = p; - - if (c->read->ready) { - ngx_post_event(c->read, &ngx_posted_events); - } - - if (pscf->upstream_value) { - if (ngx_stream_proxy_eval(s, pscf) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - } - - if (u->resolved == NULL) { - - uscf = pscf->upstream; - - } else { - -#if (NGX_STREAM_SSL) - u->ssl_name = u->resolved->host; #endif - host = &u->resolved->host; - umcf = ngx_stream_get_module_main_conf(s, ngx_stream_upstream_module); +static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_downstream_buffer = { + ngx_conf_deprecated, "proxy_downstream_buffer", "proxy_buffer_size" +}; - uscfp = umcf->upstreams.elts; +static ngx_conf_deprecated_t ngx_conf_deprecated_proxy_upstream_buffer = { + ngx_conf_deprecated, "proxy_upstream_buffer", "proxy_buffer_size" +}; - for (i = 0; i < umcf->upstreams.nelts; i++) { - uscf = uscfp[i]; +static ngx_command_t ngx_stream_proxy_commands[] = { - if (uscf->host.len == host->len && - ((uscf->port == 0 && u->resolved->no_port) || - uscf->port == u->resolved->port) && - ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) { - goto found; - } - } + { ngx_string("proxy_pass"), + NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_stream_proxy_pass, + NGX_STREAM_SRV_CONF_OFFSET, + 0, + NULL }, - if (u->resolved->sockaddr) { + { ngx_string("proxy_bind"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE12, + ngx_stream_proxy_bind, + NGX_STREAM_SRV_CONF_OFFSET, + 0, + NULL }, - if (u->resolved->port == 0 && - u->resolved->sockaddr->sa_family != AF_UNIX) { - ngx_log_error(NGX_LOG_ERR, c->log, 0, "no port in upstream \"%V\"", - host); + { ngx_string("proxy_socket_keepalive"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, socket_keepalive), + NULL }, + + { ngx_string("proxy_connect_timeout"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_msec_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, connect_timeout), + NULL }, + + { ngx_string("proxy_timeout"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_msec_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, timeout), + NULL }, + + { ngx_string("proxy_buffer_size"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_size_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), + NULL }, + + { ngx_string("proxy_downstream_buffer"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_size_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), + &ngx_conf_deprecated_proxy_downstream_buffer }, + + { ngx_string("proxy_upstream_buffer"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_size_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, buffer_size), + &ngx_conf_deprecated_proxy_upstream_buffer }, + + { ngx_string("proxy_upload_rate"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_stream_set_complex_value_size_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, upload_rate), + NULL }, + + { ngx_string("proxy_download_rate"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_stream_set_complex_value_size_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, download_rate), + NULL }, + + { ngx_string("proxy_requests"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, requests), + NULL }, + + { ngx_string("proxy_responses"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, responses), + NULL }, + + { ngx_string("proxy_next_upstream"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, next_upstream), + NULL }, + + { ngx_string("proxy_next_upstream_tries"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_tries), + NULL }, + + { ngx_string("proxy_next_upstream_timeout"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_msec_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, next_upstream_timeout), + NULL }, + + { ngx_string("proxy_protocol"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, proxy_protocol), + NULL }, + + { ngx_string("proxy_protocol_version"), + NGX_STREAM_MAIN_CONF | NGX_STREAM_SRV_CONF | NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, protocol_version), + NULL}, + + { ngx_string("proxy_half_close"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, half_close), + NULL }, + +#if (NGX_STREAM_SSL) + + { ngx_string("proxy_ssl"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_enable), + NULL }, + + { ngx_string("proxy_ssl_session_reuse"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_session_reuse), + NULL }, + + { ngx_string("proxy_ssl_protocols"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE, + ngx_conf_set_bitmask_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_protocols), + &ngx_stream_proxy_ssl_protocols }, + + { ngx_string("proxy_ssl_ciphers"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_str_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_ciphers), + NULL }, + + { ngx_string("proxy_ssl_name"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_stream_set_complex_value_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_name), + NULL }, + + { ngx_string("proxy_ssl_server_name"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_server_name), + NULL }, + + { ngx_string("proxy_ssl_verify"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify), + NULL }, + + { ngx_string("proxy_ssl_verify_depth"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_verify_depth), + NULL }, + + { ngx_string("proxy_ssl_trusted_certificate"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_str_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_trusted_certificate), + NULL }, + + { ngx_string("proxy_ssl_crl"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_conf_set_str_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_crl), + NULL }, + + { ngx_string("proxy_ssl_certificate"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_stream_set_complex_value_zero_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate), + NULL }, + + { ngx_string("proxy_ssl_certificate_key"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_stream_set_complex_value_zero_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_certificate_key), + NULL }, + + { ngx_string("proxy_ssl_certificate_cache"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE123, + ngx_stream_proxy_ssl_certificate_cache, + NGX_STREAM_SRV_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("proxy_ssl_password_file"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, + ngx_stream_proxy_ssl_password_file, + NGX_STREAM_SRV_CONF_OFFSET, + 0, + NULL }, + + { ngx_string("proxy_ssl_conf_command"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE2, + ngx_conf_set_keyval_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_proxy_srv_conf_t, ssl_conf_commands), + &ngx_stream_proxy_ssl_conf_command_post }, + +#endif + + ngx_null_command +}; + + +static ngx_stream_module_t ngx_stream_proxy_module_ctx = { + NULL, /* preconfiguration */ + NULL, /* postconfiguration */ + + NULL, /* create main configuration */ + NULL, /* init main configuration */ + + ngx_stream_proxy_create_srv_conf, /* create server configuration */ + ngx_stream_proxy_merge_srv_conf /* merge server configuration */ +}; + + +ngx_module_t ngx_stream_proxy_module = { + NGX_MODULE_V1, + &ngx_stream_proxy_module_ctx, /* module context */ + ngx_stream_proxy_commands, /* module directives */ + NGX_STREAM_MODULE, /* module type */ + NULL, /* init master */ + NULL, /* init module */ + NULL, /* init process */ + NULL, /* init thread */ + NULL, /* exit thread */ + NULL, /* exit process */ + NULL, /* exit master */ + NGX_MODULE_V1_PADDING +}; + + +static void +ngx_stream_proxy_handler(ngx_stream_session_t *s) +{ + u_char *p; + ngx_str_t *host; + ngx_uint_t i; + ngx_connection_t *c; + ngx_resolver_ctx_t *ctx, temp; + ngx_stream_upstream_t *u; + ngx_stream_core_srv_conf_t *cscf; + ngx_stream_proxy_srv_conf_t *pscf; + ngx_stream_upstream_srv_conf_t *uscf, **uscfp; + ngx_stream_upstream_main_conf_t *umcf; + + c = s->connection; + + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, + "proxy connection handler"); + + u = ngx_pcalloc(c->pool, sizeof(ngx_stream_upstream_t)); + if (u == NULL) { ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); return; - } + } - if (ngx_stream_upstream_create_round_robin_peer(s, u->resolved) != - NGX_OK) { + s->upstream = u; + + s->log_handler = ngx_stream_proxy_log_error; + + u->requests = 1; + + u->peer.log = c->log; + u->peer.log_error = NGX_ERROR_ERR; + + if (ngx_stream_proxy_set_local(s, u, pscf->local) != NGX_OK) { ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); return; - } - - ngx_stream_proxy_connect(s); - - return; } - if (u->resolved->port == 0) { - ngx_log_error(NGX_LOG_ERR, c->log, 0, "no port in upstream \"%V\"", host); - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; + if (pscf->socket_keepalive) { + u->peer.so_keepalive = 1; } - temp.name = *host; + u->peer.type = c->type; + u->start_sec = ngx_time(); - cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); + c->write->handler = ngx_stream_proxy_downstream_handler; + c->read->handler = ngx_stream_proxy_downstream_handler; - ctx = ngx_resolve_start(cscf->resolver, &temp); - if (ctx == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; + s->upstream_states = ngx_array_create(c->pool, 1, + sizeof(ngx_stream_upstream_state_t)); + if (s->upstream_states == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; } - if (ctx == NGX_NO_RESOLVER) { - ngx_log_error(NGX_LOG_ERR, c->log, 0, "no resolver defined to resolve %V", - host); - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; + p = ngx_pnalloc(c->pool, pscf->buffer_size); + if (p == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; } - ctx->name = *host; - ctx->handler = ngx_stream_proxy_resolve_handler; - ctx->data = s; - ctx->timeout = cscf->resolver_timeout; + u->downstream_buf.start = p; + u->downstream_buf.end = p + pscf->buffer_size; + u->downstream_buf.pos = p; + u->downstream_buf.last = p; - u->resolved->ctx = ctx; - - if (ngx_resolve_name(ctx) != NGX_OK) { - u->resolved->ctx = NULL; - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; + if (c->read->ready) { + ngx_post_event(c->read, &ngx_posted_events); } - return; - } + if (pscf->upstream_value) { + if (ngx_stream_proxy_eval(s, pscf) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + } + + if (u->resolved == NULL) { + + uscf = pscf->upstream; + + } else { + +#if (NGX_STREAM_SSL) + u->ssl_name = u->resolved->host; +#endif + + host = &u->resolved->host; + + umcf = ngx_stream_get_module_main_conf(s, ngx_stream_upstream_module); + + uscfp = umcf->upstreams.elts; + + for (i = 0; i < umcf->upstreams.nelts; i++) { + + uscf = uscfp[i]; + + if (uscf->host.len == host->len + && ((uscf->port == 0 && u->resolved->no_port) + || uscf->port == u->resolved->port) + && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0) + { + goto found; + } + } + + if (u->resolved->sockaddr) { + + if (u->resolved->port == 0 + && u->resolved->sockaddr->sa_family != AF_UNIX) + { + ngx_log_error(NGX_LOG_ERR, c->log, 0, + "no port in upstream \"%V\"", host); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + if (ngx_stream_upstream_create_round_robin_peer(s, u->resolved) + != NGX_OK) + { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + ngx_stream_proxy_connect(s); + + return; + } + + if (u->resolved->port == 0) { + ngx_log_error(NGX_LOG_ERR, c->log, 0, + "no port in upstream \"%V\"", host); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + temp.name = *host; + + cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); + + ctx = ngx_resolve_start(cscf->resolver, &temp); + if (ctx == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + if (ctx == NGX_NO_RESOLVER) { + ngx_log_error(NGX_LOG_ERR, c->log, 0, + "no resolver defined to resolve %V", host); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + ctx->name = *host; + ctx->handler = ngx_stream_proxy_resolve_handler; + ctx->data = s; + ctx->timeout = cscf->resolver_timeout; + + u->resolved->ctx = ctx; + + if (ngx_resolve_name(ctx) != NGX_OK) { + u->resolved->ctx = NULL; + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + return; + } found: - if (uscf == NULL) { - ngx_log_error(NGX_LOG_ALERT, c->log, 0, "no upstream configuration"); - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - u->upstream = uscf; - -#if (NGX_STREAM_SSL) - u->ssl_name = uscf->host; -#endif - - if (uscf->peer.init(s, uscf) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - u->peer.start_time = ngx_current_msec; - - if (pscf->next_upstream_tries && u->peer.tries > pscf->next_upstream_tries) { - u->peer.tries = pscf->next_upstream_tries; - } - - ngx_stream_proxy_connect(s); -} - -static ngx_int_t ngx_stream_proxy_eval(ngx_stream_session_t *s, - ngx_stream_proxy_srv_conf_t *pscf) { - ngx_str_t host; - ngx_url_t url; - ngx_stream_upstream_t *u; - - if (ngx_stream_complex_value(s, pscf->upstream_value, &host) != NGX_OK) { - return NGX_ERROR; - } - - ngx_memzero(&url, sizeof(ngx_url_t)); - - url.url = host; - url.no_resolve = 1; - - if (ngx_parse_url(s->connection->pool, &url) != NGX_OK) { - if (url.err) { - ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, "%s in upstream \"%V\"", - url.err, &url.url); + if (uscf == NULL) { + ngx_log_error(NGX_LOG_ALERT, c->log, 0, "no upstream configuration"); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; } - return NGX_ERROR; - } + u->upstream = uscf; - u = s->upstream; +#if (NGX_STREAM_SSL) + u->ssl_name = uscf->host; +#endif - u->resolved = - ngx_pcalloc(s->connection->pool, sizeof(ngx_stream_upstream_resolved_t)); - if (u->resolved == NULL) { - return NGX_ERROR; - } + if (uscf->peer.init(s, uscf) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } - if (url.addrs) { - u->resolved->sockaddr = url.addrs[0].sockaddr; - u->resolved->socklen = url.addrs[0].socklen; - u->resolved->name = url.addrs[0].name; - u->resolved->naddrs = 1; - } + u->peer.start_time = ngx_current_msec; - u->resolved->host = url.host; - u->resolved->port = url.port; - u->resolved->no_port = url.no_port; + if (pscf->next_upstream_tries + && u->peer.tries > pscf->next_upstream_tries) + { + u->peer.tries = pscf->next_upstream_tries; + } - return NGX_OK; + ngx_stream_proxy_connect(s); } + +static ngx_int_t +ngx_stream_proxy_eval(ngx_stream_session_t *s, + ngx_stream_proxy_srv_conf_t *pscf) +{ + ngx_str_t host; + ngx_url_t url; + ngx_stream_upstream_t *u; + + if (ngx_stream_complex_value(s, pscf->upstream_value, &host) != NGX_OK) { + return NGX_ERROR; + } + + ngx_memzero(&url, sizeof(ngx_url_t)); + + url.url = host; + url.no_resolve = 1; + + if (ngx_parse_url(s->connection->pool, &url) != NGX_OK) { + if (url.err) { + ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, + "%s in upstream \"%V\"", url.err, &url.url); + } + + return NGX_ERROR; + } + + u = s->upstream; + + u->resolved = ngx_pcalloc(s->connection->pool, + sizeof(ngx_stream_upstream_resolved_t)); + if (u->resolved == NULL) { + return NGX_ERROR; + } + + if (url.addrs) { + u->resolved->sockaddr = url.addrs[0].sockaddr; + u->resolved->socklen = url.addrs[0].socklen; + u->resolved->name = url.addrs[0].name; + u->resolved->naddrs = 1; + } + + u->resolved->host = url.host; + u->resolved->port = url.port; + u->resolved->no_port = url.no_port; + + return NGX_OK; +} + + static ngx_int_t ngx_stream_proxy_set_local(ngx_stream_session_t *s, ngx_stream_upstream_t *u, - ngx_stream_upstream_local_t *local) { - ngx_int_t rc; - ngx_str_t val; - ngx_addr_t *addr; + ngx_stream_upstream_local_t *local) +{ + ngx_int_t rc; + ngx_str_t val; + ngx_addr_t *addr; - if (local == NULL) { - u->peer.local = NULL; - return NGX_OK; - } + if (local == NULL) { + u->peer.local = NULL; + return NGX_OK; + } #if (NGX_HAVE_TRANSPARENT_PROXY) - u->peer.transparent = local->transparent; + u->peer.transparent = local->transparent; #endif - if (local->value == NULL) { - u->peer.local = local->addr; + if (local->value == NULL) { + u->peer.local = local->addr; + return NGX_OK; + } + + if (ngx_stream_complex_value(s, local->value, &val) != NGX_OK) { + return NGX_ERROR; + } + + if (val.len == 0) { + u->peer.local = NULL; + return NGX_OK; + } + + addr = ngx_palloc(s->connection->pool, sizeof(ngx_addr_t)); + if (addr == NULL) { + return NGX_ERROR; + } + + rc = ngx_parse_addr_port(s->connection->pool, addr, val.data, val.len); + if (rc == NGX_ERROR) { + return NGX_ERROR; + } + + if (rc != NGX_OK) { + ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, + "invalid local address \"%V\"", &val); + u->peer.local = NULL; + return NGX_OK; + } + + addr->name = val; + u->peer.local = addr; + return NGX_OK; - } - - if (ngx_stream_complex_value(s, local->value, &val) != NGX_OK) { - return NGX_ERROR; - } - - if (val.len == 0) { - u->peer.local = NULL; - return NGX_OK; - } - - addr = ngx_palloc(s->connection->pool, sizeof(ngx_addr_t)); - if (addr == NULL) { - return NGX_ERROR; - } - - rc = ngx_parse_addr_port(s->connection->pool, addr, val.data, val.len); - if (rc == NGX_ERROR) { - return NGX_ERROR; - } - - if (rc != NGX_OK) { - ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, - "invalid local address \"%V\"", &val); - u->peer.local = NULL; - return NGX_OK; - } - - addr->name = val; - u->peer.local = addr; - - return NGX_OK; } -static void ngx_stream_proxy_connect(ngx_stream_session_t *s) { - ngx_int_t rc; - ngx_connection_t *c, *pc; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - c = s->connection; +static void +ngx_stream_proxy_connect(ngx_stream_session_t *s) +{ + ngx_int_t rc; + ngx_connection_t *c, *pc; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; - c->log->action = "connecting to upstream"; + c = s->connection; - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + c->log->action = "connecting to upstream"; - u = s->upstream; + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - u->connected = 0; - u->proxy_protocol = pscf->proxy_protocol; + u = s->upstream; - if (u->state) { - u->state->response_time = ngx_current_msec - u->start_time; - } + u->connected = 0; + u->proxy_protocol = pscf->proxy_protocol; - u->state = ngx_array_push(s->upstream_states); - if (u->state == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } + if (u->state) { + u->state->response_time = ngx_current_msec - u->start_time; + } - ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t)); + u->state = ngx_array_push(s->upstream_states); + if (u->state == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } - u->start_time = ngx_current_msec; + ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t)); - u->state->connect_time = (ngx_msec_t)-1; - u->state->first_byte_time = (ngx_msec_t)-1; - u->state->response_time = (ngx_msec_t)-1; + u->start_time = ngx_current_msec; - rc = ngx_event_connect_peer(&u->peer); + u->state->connect_time = (ngx_msec_t) -1; + u->state->first_byte_time = (ngx_msec_t) -1; + u->state->response_time = (ngx_msec_t) -1; - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc); + rc = ngx_event_connect_peer(&u->peer); - if (rc == NGX_ERROR) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc); - u->state->peer = u->peer.name; + if (rc == NGX_ERROR) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + u->state->peer = u->peer.name; #if (NGX_STREAM_UPSTREAM_ZONE) - if (u->upstream && u->upstream->shm_zone && - (u->upstream->flags & NGX_STREAM_UPSTREAM_MODIFY)) { - u->state->peer = - ngx_palloc(s->connection->pool, sizeof(ngx_str_t) + u->peer.name->len); - if (u->state->peer == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; + if (u->upstream && u->upstream->shm_zone + && (u->upstream->flags & NGX_STREAM_UPSTREAM_MODIFY)) + { + u->state->peer = ngx_palloc(s->connection->pool, + sizeof(ngx_str_t) + u->peer.name->len); + if (u->state->peer == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + u->state->peer->len = u->peer.name->len; + u->state->peer->data = (u_char *) (u->state->peer + 1); + ngx_memcpy(u->state->peer->data, u->peer.name->data, u->peer.name->len); + + u->peer.name = u->state->peer; } - - u->state->peer->len = u->peer.name->len; - u->state->peer->data = (u_char *)(u->state->peer + 1); - ngx_memcpy(u->state->peer->data, u->peer.name->data, u->peer.name->len); - - u->peer.name = u->state->peer; - } #endif - if (rc == NGX_BUSY) { - ngx_log_error(NGX_LOG_ERR, c->log, 0, "no live upstreams"); - ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); - return; - } - - if (rc == NGX_DECLINED) { - ngx_stream_proxy_next_upstream(s); - return; - } - - /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */ - - pc = u->peer.connection; - - pc->data = s; - pc->log = c->log; - pc->pool = c->pool; - pc->read->log = c->log; - pc->write->log = c->log; - - if (rc != NGX_AGAIN) { - ngx_stream_proxy_init_upstream(s); - return; - } - - pc->read->handler = ngx_stream_proxy_connect_handler; - pc->write->handler = ngx_stream_proxy_connect_handler; - - ngx_add_timer(pc->write, pscf->connect_timeout); -} - -static void ngx_stream_proxy_init_upstream(ngx_stream_session_t *s) { - u_char *p; - ngx_chain_t *cl; - ngx_connection_t *c, *pc; - ngx_log_handler_pt handler; - ngx_stream_upstream_t *u; - ngx_stream_core_srv_conf_t *cscf; - ngx_stream_proxy_srv_conf_t *pscf; - - u = s->upstream; - pc = u->peer.connection; - - cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); - - if (pc->type == SOCK_STREAM && cscf->tcp_nodelay && - ngx_tcp_nodelay(pc) != NGX_OK) { - ngx_stream_proxy_next_upstream(s); - return; - } - - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - -#if (NGX_STREAM_SSL) - - if (pc->type == SOCK_STREAM && pscf->ssl_enable) { - - if (u->proxy_protocol) { - if (ngx_stream_proxy_send_proxy_protocol(s) != NGX_OK) { + if (rc == NGX_BUSY) { + ngx_log_error(NGX_LOG_ERR, c->log, 0, "no live upstreams"); + ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); return; - } - - u->proxy_protocol = 0; } - if (pc->ssl == NULL) { - ngx_stream_proxy_ssl_init_connection(s); - return; - } - } - -#endif - - c = s->connection; - - if (c->log->log_level >= NGX_LOG_INFO) { - ngx_str_t str; - u_char addr[NGX_SOCKADDR_STRLEN]; - - str.len = NGX_SOCKADDR_STRLEN; - str.data = addr; - - if (ngx_connection_local_sockaddr(pc, &str, 1) == NGX_OK) { - handler = c->log->handler; - c->log->handler = NULL; - - ngx_log_error(NGX_LOG_INFO, c->log, 0, "%sproxy %V connected to %V", - pc->type == SOCK_DGRAM ? "udp " : "", &str, u->peer.name); - - c->log->handler = handler; - } - } - - u->state->connect_time = ngx_current_msec - u->start_time; - - if (u->peer.notify) { - u->peer.notify(&u->peer, u->peer.data, NGX_STREAM_UPSTREAM_NOTIFY_CONNECT); - } - - if (u->upstream_buf.start == NULL) { - p = ngx_pnalloc(c->pool, pscf->buffer_size); - if (p == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; + if (rc == NGX_DECLINED) { + ngx_stream_proxy_next_upstream(s); + return; } - u->upstream_buf.start = p; - u->upstream_buf.end = p + pscf->buffer_size; - u->upstream_buf.pos = p; - u->upstream_buf.last = p; - } + /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */ - if (c->buffer && c->buffer->pos <= c->buffer->last) { - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream proxy add preread buffer: %uz", - c->buffer->last - c->buffer->pos); + pc = u->peer.connection; - cl = ngx_chain_get_free_buf(c->pool, &u->free); - if (cl == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; + pc->data = s; + pc->log = c->log; + pc->pool = c->pool; + pc->read->log = c->log; + pc->write->log = c->log; + + if (rc != NGX_AGAIN) { + ngx_stream_proxy_init_upstream(s); + return; } - *cl->buf = *c->buffer; - - cl->buf->tag = (ngx_buf_tag_t)&ngx_stream_proxy_module; - cl->buf->temporary = (cl->buf->pos == cl->buf->last) ? 0 : 1; - cl->buf->flush = 1; - - cl->next = u->upstream_out; - u->upstream_out = cl; - } - - if (u->proxy_protocol) { - ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream proxy add PROXY protocol header"); - - cl = ngx_chain_get_free_buf(c->pool, &u->free); - if (cl == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - if (pscf->protocol_version == 2) { - p = ngx_pnalloc(c->pool, NGX_PROXY_PROTOCOL_V2_MAX_HEADER); - } else { - p = ngx_pnalloc(c->pool, NGX_PROXY_PROTOCOL_V1_MAX_HEADER); - } - if (p == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - cl->buf->pos = p; - - if (pscf->protocol_version == 2) { - p = ngx_proxy_protocol_v2_write(c, p, - p + NGX_PROXY_PROTOCOL_V2_MAX_HEADER); - } else { - p = ngx_proxy_protocol_write(c, p, p + NGX_PROXY_PROTOCOL_V1_MAX_HEADER); - } - if (p == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - cl->buf->last = p; - cl->buf->temporary = 1; - cl->buf->flush = 0; - cl->buf->last_buf = 0; - cl->buf->tag = (ngx_buf_tag_t)&ngx_stream_proxy_module; - - cl->next = u->upstream_out; - u->upstream_out = cl; - - u->proxy_protocol = 0; - } - - u->upload_rate = ngx_stream_complex_value_size(s, pscf->upload_rate, 0); - u->download_rate = ngx_stream_complex_value_size(s, pscf->download_rate, 0); - - u->connected = 1; - - pc->read->handler = ngx_stream_proxy_upstream_handler; - pc->write->handler = ngx_stream_proxy_upstream_handler; - - if (pc->read->ready) { - ngx_post_event(pc->read, &ngx_posted_events); - } - - ngx_stream_proxy_process(s, 0, 1); -} - -#if (NGX_STREAM_SSL) - -static ngx_int_t ngx_stream_proxy_send_proxy_protocol(ngx_stream_session_t *s) { - u_char *p; - ssize_t n, size; - ngx_connection_t *c, *pc; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - u_char buf[NGX_PROXY_PROTOCOL_V1_MAX_HEADER]; - - c = s->connection; - - ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream proxy send PROXY protocol header"); - - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - - if (pscf->protocol_version == 2) { - p = ngx_proxy_protocol_v2_write(c, buf, - buf + NGX_PROXY_PROTOCOL_V2_MAX_HEADER); - } else { - p = ngx_proxy_protocol_write(c, buf, - buf + NGX_PROXY_PROTOCOL_V1_MAX_HEADER); - } - if (p == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return NGX_ERROR; - } - - u = s->upstream; - - pc = u->peer.connection; - - size = p - buf; - - n = pc->send(pc, buf, size); - - if (n == NGX_AGAIN) { - if (ngx_handle_write_event(pc->write, 0) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return NGX_ERROR; - } - - ngx_add_timer(pc->write, pscf->timeout); - + pc->read->handler = ngx_stream_proxy_connect_handler; pc->write->handler = ngx_stream_proxy_connect_handler; - return NGX_AGAIN; - } - - if (n == NGX_ERROR) { - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - return NGX_ERROR; - } - - if (n != size) { - - /* - * PROXY protocol specification: - * The sender must always ensure that the header - * is sent at once, so that the transport layer - * maintains atomicity along the path to the receiver. - */ - - ngx_log_error(NGX_LOG_ERR, c->log, 0, - "could not send PROXY protocol header at once"); - - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - - return NGX_ERROR; - } - - return NGX_OK; + ngx_add_timer(pc->write, pscf->connect_timeout); } -static char *ngx_stream_proxy_ssl_certificate_cache(ngx_conf_t *cf, - ngx_command_t *cmd, - void *conf) { - ngx_stream_proxy_srv_conf_t *pscf = conf; - time_t inactive, valid; - ngx_str_t *value, s; - ngx_int_t max; - ngx_uint_t i; +static void +ngx_stream_proxy_init_upstream(ngx_stream_session_t *s) +{ + u_char *p; + ngx_chain_t *cl; + ngx_connection_t *c, *pc; + ngx_log_handler_pt handler; + ngx_stream_upstream_t *u; + ngx_stream_core_srv_conf_t *cscf; + ngx_stream_proxy_srv_conf_t *pscf; - if (pscf->ssl_certificate_cache != NGX_CONF_UNSET_PTR) { - return "is duplicate"; - } + u = s->upstream; + pc = u->peer.connection; - value = cf->args->elts; + cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); - max = 0; - inactive = 10; - valid = 60; - - for (i = 1; i < cf->args->nelts; i++) { - - if (ngx_strncmp(value[i].data, "max=", 4) == 0) { - - max = ngx_atoi(value[i].data + 4, value[i].len - 4); - if (max <= 0) { - goto failed; - } - - continue; + if (pc->type == SOCK_STREAM + && cscf->tcp_nodelay + && ngx_tcp_nodelay(pc) != NGX_OK) + { + ngx_stream_proxy_next_upstream(s); + return; } - if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - s.len = value[i].len - 9; - s.data = value[i].data + 9; +#if (NGX_STREAM_SSL) - inactive = ngx_parse_time(&s, 1); - if (inactive == (time_t)NGX_ERROR) { - goto failed; - } + if (pc->type == SOCK_STREAM && pscf->ssl_enable) { - continue; + if (u->proxy_protocol) { + if (ngx_stream_proxy_send_proxy_protocol(s) != NGX_OK) { + return; + } + + u->proxy_protocol = 0; + } + + if (pc->ssl == NULL) { + ngx_stream_proxy_ssl_init_connection(s); + return; + } } - if (ngx_strncmp(value[i].data, "valid=", 6) == 0) { +#endif - s.len = value[i].len - 6; - s.data = value[i].data + 6; + c = s->connection; - valid = ngx_parse_time(&s, 1); - if (valid == (time_t)NGX_ERROR) { - goto failed; - } + if (c->log->log_level >= NGX_LOG_INFO) { + ngx_str_t str; + u_char addr[NGX_SOCKADDR_STRLEN]; - continue; + str.len = NGX_SOCKADDR_STRLEN; + str.data = addr; + + if (ngx_connection_local_sockaddr(pc, &str, 1) == NGX_OK) { + handler = c->log->handler; + c->log->handler = NULL; + + ngx_log_error(NGX_LOG_INFO, c->log, 0, + "%sproxy %V connected to %V", + pc->type == SOCK_DGRAM ? "udp " : "", + &str, u->peer.name); + + c->log->handler = handler; + } } - if (ngx_strcmp(value[i].data, "off") == 0) { + u->state->connect_time = ngx_current_msec - u->start_time; - pscf->ssl_certificate_cache = NULL; - - continue; + if (u->peer.notify) { + u->peer.notify(&u->peer, u->peer.data, + NGX_STREAM_UPSTREAM_NOTIFY_CONNECT); } - failed: + if (u->upstream_buf.start == NULL) { + p = ngx_pnalloc(c->pool, pscf->buffer_size); + if (p == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%V\"", - &value[i]); - return NGX_CONF_ERROR; - } + u->upstream_buf.start = p; + u->upstream_buf.end = p + pscf->buffer_size; + u->upstream_buf.pos = p; + u->upstream_buf.last = p; + } + + if (c->buffer && c->buffer->pos <= c->buffer->last) { + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, + "stream proxy add preread buffer: %uz", + c->buffer->last - c->buffer->pos); + + cl = ngx_chain_get_free_buf(c->pool, &u->free); + if (cl == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + *cl->buf = *c->buffer; + + cl->buf->tag = (ngx_buf_tag_t) &ngx_stream_proxy_module; + cl->buf->temporary = (cl->buf->pos == cl->buf->last) ? 0 : 1; + cl->buf->flush = 1; + + cl->next = u->upstream_out; + u->upstream_out = cl; + } + + if (u->proxy_protocol) { + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, + "stream proxy add PROXY protocol header"); + + cl = ngx_chain_get_free_buf(c->pool, &u->free); + if (cl == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + if (pscf->proxy_protocol == 2){ + p = ngx_pnalloc(c->pool, NGX_PROXY_PROTOCOL_V2_MAX_HEADER); + } else{ + p = ngx_pnalloc(c->pool, NGX_PROXY_PROTOCOL_V1_MAX_HEADER); + } + if (p == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + cl->buf->pos = p; + + if (pscf->protocol_version == 2) { + p = ngx_proxy_protocol_v2_write(c, p, + p + NGX_PROXY_PROTOCOL_V2_MAX_HEADER); + } else { + p = ngx_proxy_protocol_write(c, p, + p + NGX_PROXY_PROTOCOL_V1_MAX_HEADER); + } + if (p == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + cl->buf->last = p; + cl->buf->temporary = 1; + cl->buf->flush = 0; + cl->buf->last_buf = 0; + cl->buf->tag = (ngx_buf_tag_t) &ngx_stream_proxy_module; + + cl->next = u->upstream_out; + u->upstream_out = cl; + + u->proxy_protocol = 0; + } + + u->upload_rate = ngx_stream_complex_value_size(s, pscf->upload_rate, 0); + u->download_rate = ngx_stream_complex_value_size(s, pscf->download_rate, 0); + + u->connected = 1; + + pc->read->handler = ngx_stream_proxy_upstream_handler; + pc->write->handler = ngx_stream_proxy_upstream_handler; + + if (pc->read->ready) { + ngx_post_event(pc->read, &ngx_posted_events); + } + + ngx_stream_proxy_process(s, 0, 1); +} + +#if (NGX_STREAM_SSL) + +static ngx_int_t +ngx_stream_proxy_send_proxy_protocol(ngx_stream_session_t *s) +{ + u_char *p; + ssize_t n, size; + ngx_connection_t *c, *pc; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; + u_char buf[NGX_PROXY_PROTOCOL_V1_MAX_HEADER]; + + c = s->connection; + + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, + "stream proxy send PROXY protocol header"); + + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + + if (pscf->protocol_version == 2) { + p = ngx_proxy_protocol_v2_write(c, buf, + buf + NGX_PROXY_PROTOCOL_V2_MAX_HEADER); + } else { + p = ngx_proxy_protocol_write(c, buf, + buf + NGX_PROXY_PROTOCOL_V1_MAX_HEADER); + + if (p == NULL) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return NGX_ERROR; + } + + u = s->upstream; + + pc = u->peer.connection; + + size = p - buf; + + n = pc->send(pc, buf, size); + + if (n == NGX_AGAIN) { + if (ngx_handle_write_event(pc->write, 0) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return NGX_ERROR; + } + + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + + ngx_add_timer(pc->write, pscf->timeout); + + pc->write->handler = ngx_stream_proxy_connect_handler; + + return NGX_AGAIN; + } + + if (n == NGX_ERROR) { + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + return NGX_ERROR; + } + + if (n != size) { + + /* + * PROXY protocol specification: + * The sender must always ensure that the header + * is sent at once, so that the transport layer + * maintains atomicity along the path to the receiver. + */ + + ngx_log_error(NGX_LOG_ERR, c->log, 0, + "could not send PROXY protocol header at once"); + + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + + return NGX_ERROR; + } + + return NGX_OK; +} + + +static char * +ngx_stream_proxy_ssl_certificate_cache(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf) +{ + ngx_stream_proxy_srv_conf_t *pscf = conf; + + time_t inactive, valid; + ngx_str_t *value, s; + ngx_int_t max; + ngx_uint_t i; + + if (pscf->ssl_certificate_cache != NGX_CONF_UNSET_PTR) { + return "is duplicate"; + } + + value = cf->args->elts; + + max = 0; + inactive = 10; + valid = 60; + + for (i = 1; i < cf->args->nelts; i++) { + + if (ngx_strncmp(value[i].data, "max=", 4) == 0) { + + max = ngx_atoi(value[i].data + 4, value[i].len - 4); + if (max <= 0) { + goto failed; + } + + continue; + } + + if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { + + s.len = value[i].len - 9; + s.data = value[i].data + 9; + + inactive = ngx_parse_time(&s, 1); + if (inactive == (time_t) NGX_ERROR) { + goto failed; + } + + continue; + } + + if (ngx_strncmp(value[i].data, "valid=", 6) == 0) { + + s.len = value[i].len - 6; + s.data = value[i].data + 6; + + valid = ngx_parse_time(&s, 1); + if (valid == (time_t) NGX_ERROR) { + goto failed; + } + + continue; + } + + if (ngx_strcmp(value[i].data, "off") == 0) { + + pscf->ssl_certificate_cache = NULL; + + continue; + } + + failed: + + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid parameter \"%V\"", &value[i]); + return NGX_CONF_ERROR; + } + + if (pscf->ssl_certificate_cache == NULL) { + return NGX_CONF_OK; + } + + if (max == 0) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "\"proxy_ssl_certificate_cache\" must have " + "the \"max\" parameter"); + return NGX_CONF_ERROR; + } + + pscf->ssl_certificate_cache = ngx_ssl_cache_init(cf->pool, max, valid, + inactive); + if (pscf->ssl_certificate_cache == NULL) { + return NGX_CONF_ERROR; + } - if (pscf->ssl_certificate_cache == NULL) { return NGX_CONF_OK; - } - - if (max == 0) { - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "\"proxy_ssl_certificate_cache\" must have " - "the \"max\" parameter"); - return NGX_CONF_ERROR; - } - - pscf->ssl_certificate_cache = - ngx_ssl_cache_init(cf->pool, max, valid, inactive); - if (pscf->ssl_certificate_cache == NULL) { - return NGX_CONF_ERROR; - } - - return NGX_CONF_OK; } -static char *ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf, - ngx_command_t *cmd, - void *conf) { - ngx_stream_proxy_srv_conf_t *pscf = conf; - ngx_str_t *value; +static char * +ngx_stream_proxy_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf) +{ + ngx_stream_proxy_srv_conf_t *pscf = conf; - if (pscf->ssl_passwords != NGX_CONF_UNSET_PTR) { - return "is duplicate"; - } + ngx_str_t *value; - value = cf->args->elts; + if (pscf->ssl_passwords != NGX_CONF_UNSET_PTR) { + return "is duplicate"; + } - pscf->ssl_passwords = ngx_ssl_read_password_file(cf, &value[1]); + value = cf->args->elts; - if (pscf->ssl_passwords == NULL) { - return NGX_CONF_ERROR; - } + pscf->ssl_passwords = ngx_ssl_read_password_file(cf, &value[1]); - return NGX_CONF_OK; + if (pscf->ssl_passwords == NULL) { + return NGX_CONF_ERROR; + } + + return NGX_CONF_OK; } -static char *ngx_stream_proxy_ssl_conf_command_check(ngx_conf_t *cf, void *post, - void *data) { + +static char * +ngx_stream_proxy_ssl_conf_command_check(ngx_conf_t *cf, void *post, void *data) +{ #ifndef SSL_CONF_FLAG_FILE - return "is not supported on this platform"; + return "is not supported on this platform"; #else - return NGX_CONF_OK; + return NGX_CONF_OK; #endif } -static void ngx_stream_proxy_ssl_init_connection(ngx_stream_session_t *s) { - ngx_int_t rc; - ngx_connection_t *pc; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - u = s->upstream; +static void +ngx_stream_proxy_ssl_init_connection(ngx_stream_session_t *s) +{ + ngx_int_t rc; + ngx_connection_t *pc; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; - pc = u->peer.connection; + u = s->upstream; - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + pc = u->peer.connection; - if (ngx_ssl_create_connection(pscf->ssl, pc, - NGX_SSL_BUFFER | NGX_SSL_CLIENT) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - if (pscf->ssl_server_name || pscf->ssl_verify) { - if (ngx_stream_proxy_ssl_name(s) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - } - - if (pscf->ssl_certificate && pscf->ssl_certificate->value.len && - (pscf->ssl_certificate->lengths || pscf->ssl_certificate_key->lengths)) { - if (ngx_stream_proxy_ssl_certificate(s) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - } - - if (pscf->ssl_session_reuse) { - pc->ssl->save_session = ngx_stream_proxy_ssl_save_session; - - if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - } - - s->connection->log->action = "SSL handshaking to upstream"; - - rc = ngx_ssl_handshake(pc); - - if (rc == NGX_AGAIN) { - - if (!pc->write->timer_set) { - ngx_add_timer(pc->write, pscf->connect_timeout); + if (ngx_ssl_create_connection(pscf->ssl, pc, NGX_SSL_BUFFER|NGX_SSL_CLIENT) + != NGX_OK) + { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; } - pc->ssl->handler = ngx_stream_proxy_ssl_handshake; - return; - } + if (pscf->ssl_server_name || pscf->ssl_verify) { + if (ngx_stream_proxy_ssl_name(s) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + } - ngx_stream_proxy_ssl_handshake(pc); + if (pscf->ssl_certificate + && pscf->ssl_certificate->value.len + && (pscf->ssl_certificate->lengths + || pscf->ssl_certificate_key->lengths)) + { + if (ngx_stream_proxy_ssl_certificate(s) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + } + + if (pscf->ssl_session_reuse) { + pc->ssl->save_session = ngx_stream_proxy_ssl_save_session; + + if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + } + + s->connection->log->action = "SSL handshaking to upstream"; + + rc = ngx_ssl_handshake(pc); + + if (rc == NGX_AGAIN) { + + if (!pc->write->timer_set) { + ngx_add_timer(pc->write, pscf->connect_timeout); + } + + pc->ssl->handler = ngx_stream_proxy_ssl_handshake; + return; + } + + ngx_stream_proxy_ssl_handshake(pc); } -static void ngx_stream_proxy_ssl_handshake(ngx_connection_t *pc) { - long rc; - ngx_stream_session_t *s; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - s = pc->data; +static void +ngx_stream_proxy_ssl_handshake(ngx_connection_t *pc) +{ + long rc; + ngx_stream_session_t *s; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + s = pc->data; - if (pc->ssl->handshaked) { + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - if (pscf->ssl_verify) { - rc = SSL_get_verify_result(pc->ssl->connection); + if (pc->ssl->handshaked) { - if (rc != X509_V_OK) { - ngx_log_error(NGX_LOG_ERR, pc->log, 0, - "upstream SSL certificate verify error: (%l:%s)", rc, - X509_verify_cert_error_string(rc)); - goto failed; - } + if (pscf->ssl_verify) { + rc = SSL_get_verify_result(pc->ssl->connection); - u = s->upstream; + if (rc != X509_V_OK) { + ngx_log_error(NGX_LOG_ERR, pc->log, 0, + "upstream SSL certificate verify error: (%l:%s)", + rc, X509_verify_cert_error_string(rc)); + goto failed; + } - if (ngx_ssl_check_host(pc, &u->ssl_name) != NGX_OK) { - ngx_log_error(NGX_LOG_ERR, pc->log, 0, - "upstream SSL certificate does not match \"%V\"", - &u->ssl_name); - goto failed; - } + u = s->upstream; + + if (ngx_ssl_check_host(pc, &u->ssl_name) != NGX_OK) { + ngx_log_error(NGX_LOG_ERR, pc->log, 0, + "upstream SSL certificate does not match \"%V\"", + &u->ssl_name); + goto failed; + } + } + + if (pc->write->timer_set) { + ngx_del_timer(pc->write); + } + + ngx_stream_proxy_init_upstream(s); + + return; } - if (pc->write->timer_set) { - ngx_del_timer(pc->write); - } - - ngx_stream_proxy_init_upstream(s); - - return; - } - failed: - ngx_stream_proxy_next_upstream(s); + ngx_stream_proxy_next_upstream(s); } -static void ngx_stream_proxy_ssl_save_session(ngx_connection_t *c) { - ngx_stream_session_t *s; - ngx_stream_upstream_t *u; - s = c->data; - u = s->upstream; +static void +ngx_stream_proxy_ssl_save_session(ngx_connection_t *c) +{ + ngx_stream_session_t *s; + ngx_stream_upstream_t *u; - u->peer.save_session(&u->peer, u->peer.data); + s = c->data; + u = s->upstream; + + u->peer.save_session(&u->peer, u->peer.data); } -static ngx_int_t ngx_stream_proxy_ssl_name(ngx_stream_session_t *s) { - u_char *p, *last; - ngx_str_t name; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); +static ngx_int_t +ngx_stream_proxy_ssl_name(ngx_stream_session_t *s) +{ + u_char *p, *last; + ngx_str_t name; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; - u = s->upstream; + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - if (pscf->ssl_name) { - if (ngx_stream_complex_value(s, pscf->ssl_name, &name) != NGX_OK) { - return NGX_ERROR; + u = s->upstream; + + if (pscf->ssl_name) { + if (ngx_stream_complex_value(s, pscf->ssl_name, &name) != NGX_OK) { + return NGX_ERROR; + } + + } else { + name = u->ssl_name; } - } else { - name = u->ssl_name; - } - - if (name.len == 0) { - goto done; - } - - /* - * ssl name here may contain port, strip it for compatibility - * with the http module - */ - - p = name.data; - last = name.data + name.len; - - if (*p == '[') { - p = ngx_strlchr(p, last, ']'); - - if (p == NULL) { - p = name.data; + if (name.len == 0) { + goto done; } - } - p = ngx_strlchr(p, last, ':'); + /* + * ssl name here may contain port, strip it for compatibility + * with the http module + */ - if (p != NULL) { - name.len = p - name.data; - } + p = name.data; + last = name.data + name.len; - if (!pscf->ssl_server_name) { - goto done; - } + if (*p == '[') { + p = ngx_strlchr(p, last, ']'); + + if (p == NULL) { + p = name.data; + } + } + + p = ngx_strlchr(p, last, ':'); + + if (p != NULL) { + name.len = p - name.data; + } + + if (!pscf->ssl_server_name) { + goto done; + } #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME - /* as per RFC 6066, literal IPv4 and IPv6 addresses are not permitted */ + /* as per RFC 6066, literal IPv4 and IPv6 addresses are not permitted */ - if (name.len == 0 || *name.data == '[') { - goto done; - } + if (name.len == 0 || *name.data == '[') { + goto done; + } - if (ngx_inet_addr(name.data, name.len) != INADDR_NONE) { - goto done; - } + if (ngx_inet_addr(name.data, name.len) != INADDR_NONE) { + goto done; + } - /* - * SSL_set_tlsext_host_name() needs a null-terminated string, - * hence we explicitly null-terminate name here - */ + /* + * SSL_set_tlsext_host_name() needs a null-terminated string, + * hence we explicitly null-terminate name here + */ - p = ngx_pnalloc(s->connection->pool, name.len + 1); - if (p == NULL) { - return NGX_ERROR; - } + p = ngx_pnalloc(s->connection->pool, name.len + 1); + if (p == NULL) { + return NGX_ERROR; + } - (void)ngx_cpystrn(p, name.data, name.len + 1); + (void) ngx_cpystrn(p, name.data, name.len + 1); - name.data = p; + name.data = p; - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "upstream SSL server name: \"%s\"", name.data); + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "upstream SSL server name: \"%s\"", name.data); - if (SSL_set_tlsext_host_name(u->peer.connection->ssl->connection, - (char *)name.data) == 0) { - ngx_ssl_error(NGX_LOG_ERR, s->connection->log, 0, - "SSL_set_tlsext_host_name(\"%s\") failed", name.data); - return NGX_ERROR; - } + if (SSL_set_tlsext_host_name(u->peer.connection->ssl->connection, + (char *) name.data) + == 0) + { + ngx_ssl_error(NGX_LOG_ERR, s->connection->log, 0, + "SSL_set_tlsext_host_name(\"%s\") failed", name.data); + return NGX_ERROR; + } #endif done: - u->ssl_name = name; + u->ssl_name = name; - return NGX_OK; + return NGX_OK; } -static ngx_int_t ngx_stream_proxy_ssl_certificate(ngx_stream_session_t *s) { - ngx_str_t cert, key; - ngx_connection_t *c; - ngx_stream_proxy_srv_conf_t *pscf; - c = s->upstream->peer.connection; +static ngx_int_t +ngx_stream_proxy_ssl_certificate(ngx_stream_session_t *s) +{ + ngx_str_t cert, key; + ngx_connection_t *c; + ngx_stream_proxy_srv_conf_t *pscf; - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + c = s->upstream->peer.connection; - if (ngx_stream_complex_value(s, pscf->ssl_certificate, &cert) != NGX_OK) { - return NGX_ERROR; - } + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream upstream ssl cert: \"%s\"", cert.data); + if (ngx_stream_complex_value(s, pscf->ssl_certificate, &cert) + != NGX_OK) + { + return NGX_ERROR; + } + + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, + "stream upstream ssl cert: \"%s\"", cert.data); + + if (*cert.data == '\0') { + return NGX_OK; + } + + if (ngx_stream_complex_value(s, pscf->ssl_certificate_key, &key) + != NGX_OK) + { + return NGX_ERROR; + } + + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, + "stream upstream ssl key: \"%s\"", key.data); + + if (ngx_ssl_connection_certificate(c, c->pool, &cert, &key, + pscf->ssl_certificate_cache, + pscf->ssl_passwords) + != NGX_OK) + { + return NGX_ERROR; + } - if (*cert.data == '\0') { return NGX_OK; - } - - if (ngx_stream_complex_value(s, pscf->ssl_certificate_key, &key) != NGX_OK) { - return NGX_ERROR; - } - - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream upstream ssl key: \"%s\"", key.data); - - if (ngx_ssl_connection_certificate(c, c->pool, &cert, &key, - pscf->ssl_certificate_cache, - pscf->ssl_passwords) != NGX_OK) { - return NGX_ERROR; - } - - return NGX_OK; } #endif -static void ngx_stream_proxy_downstream_handler(ngx_event_t *ev) { - ngx_stream_proxy_process_connection(ev, ev->write); + +static void +ngx_stream_proxy_downstream_handler(ngx_event_t *ev) +{ + ngx_stream_proxy_process_connection(ev, ev->write); } -static void ngx_stream_proxy_resolve_handler(ngx_resolver_ctx_t *ctx) { - ngx_stream_session_t *s; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - ngx_stream_upstream_resolved_t *ur; - s = ctx->data; +static void +ngx_stream_proxy_resolve_handler(ngx_resolver_ctx_t *ctx) +{ + ngx_stream_session_t *s; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; + ngx_stream_upstream_resolved_t *ur; - u = s->upstream; - ur = u->resolved; + s = ctx->data; - ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "stream upstream resolve"); + u = s->upstream; + ur = u->resolved; - if (ctx->state) { - ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, - "%V could not be resolved (%i: %s)", &ctx->name, ctx->state, - ngx_resolver_strerror(ctx->state)); + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "stream upstream resolve"); - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } + if (ctx->state) { + ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, + "%V could not be resolved (%i: %s)", + &ctx->name, ctx->state, + ngx_resolver_strerror(ctx->state)); - ur->naddrs = ctx->naddrs; - ur->addrs = ctx->addrs; + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + ur->naddrs = ctx->naddrs; + ur->addrs = ctx->addrs; #if (NGX_DEBUG) - { - u_char text[NGX_SOCKADDR_STRLEN]; - ngx_str_t addr; - ngx_uint_t i; + { + u_char text[NGX_SOCKADDR_STRLEN]; + ngx_str_t addr; + ngx_uint_t i; addr.data = text; for (i = 0; i < ctx->naddrs; i++) { - addr.len = ngx_sock_ntop(ur->addrs[i].sockaddr, ur->addrs[i].socklen, - text, NGX_SOCKADDR_STRLEN, 0); + addr.len = ngx_sock_ntop(ur->addrs[i].sockaddr, ur->addrs[i].socklen, + text, NGX_SOCKADDR_STRLEN, 0); - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "name was resolved to %V", &addr); + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "name was resolved to %V", &addr); + } } - } #endif - if (ngx_stream_upstream_create_round_robin_peer(s, ur) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - ngx_resolve_name_done(ctx); - ur->ctx = NULL; - - u->peer.start_time = ngx_current_msec; - - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - - if (pscf->next_upstream_tries && u->peer.tries > pscf->next_upstream_tries) { - u->peer.tries = pscf->next_upstream_tries; - } - - ngx_stream_proxy_connect(s); -} - -static void ngx_stream_proxy_upstream_handler(ngx_event_t *ev) { - ngx_stream_proxy_process_connection(ev, !ev->write); -} - -static void ngx_stream_proxy_process_connection(ngx_event_t *ev, - ngx_uint_t from_upstream) { - ngx_connection_t *c, *pc; - ngx_log_handler_pt handler; - ngx_stream_session_t *s; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - - c = ev->data; - s = c->data; - u = s->upstream; - - if (c->close) { - ngx_log_error(NGX_LOG_INFO, c->log, 0, "shutdown timeout"); - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - return; - } - - c = s->connection; - pc = u->peer.connection; - - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - - if (ev->timedout) { - ev->timedout = 0; - - if (ev->delayed) { - ev->delayed = 0; - - if (!ev->ready) { - if (ngx_handle_read_event(ev, 0) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - if (u->connected && !c->read->delayed && !pc->read->delayed) { - ngx_add_timer(c->write, pscf->timeout); - } - + if (ngx_stream_upstream_create_round_robin_peer(s, ur) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); return; - } - - } else { - if (s->connection->type == SOCK_DGRAM) { - - if (pscf->responses == NGX_MAX_INT32_VALUE || - (u->responses >= pscf->responses * u->requests)) { - - /* - * successfully terminate timed out UDP session - * if expected number of responses was received - */ - - handler = c->log->handler; - c->log->handler = NULL; - - ngx_log_error(NGX_LOG_INFO, c->log, 0, - "udp timed out" - ", packets from/to client:%ui/%ui" - ", bytes from/to client:%O/%O" - ", bytes from/to upstream:%O/%O", - u->requests, u->responses, s->received, c->sent, - u->received, pc ? pc->sent : 0); - - c->log->handler = handler; - - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - return; - } - - ngx_connection_error(pc, NGX_ETIMEDOUT, "upstream timed out"); - - pc->read->error = 1; - - ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); - - return; - } - - ngx_connection_error(c, NGX_ETIMEDOUT, "connection timed out"); - - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - - return; } - } else if (ev->delayed) { + ngx_resolve_name_done(ctx); + ur->ctx = NULL; + + u->peer.start_time = ngx_current_msec; + + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + + if (pscf->next_upstream_tries + && u->peer.tries > pscf->next_upstream_tries) + { + u->peer.tries = pscf->next_upstream_tries; + } + + ngx_stream_proxy_connect(s); +} + + +static void +ngx_stream_proxy_upstream_handler(ngx_event_t *ev) +{ + ngx_stream_proxy_process_connection(ev, !ev->write); +} + + +static void +ngx_stream_proxy_process_connection(ngx_event_t *ev, ngx_uint_t from_upstream) +{ + ngx_connection_t *c, *pc; + ngx_log_handler_pt handler; + ngx_stream_session_t *s; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; + + c = ev->data; + s = c->data; + u = s->upstream; + + if (c->close) { + ngx_log_error(NGX_LOG_INFO, c->log, 0, "shutdown timeout"); + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + return; + } + + c = s->connection; + pc = u->peer.connection; + + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); + + if (ev->timedout) { + ev->timedout = 0; + + if (ev->delayed) { + ev->delayed = 0; + + if (!ev->ready) { + if (ngx_handle_read_event(ev, 0) != NGX_OK) { + ngx_stream_proxy_finalize(s, + NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + if (u->connected && !c->read->delayed && !pc->read->delayed) { + ngx_add_timer(c->write, pscf->timeout); + } + + return; + } + + } else { + if (s->connection->type == SOCK_DGRAM) { + + if (pscf->responses == NGX_MAX_INT32_VALUE + || (u->responses >= pscf->responses * u->requests)) + { + + /* + * successfully terminate timed out UDP session + * if expected number of responses was received + */ + + handler = c->log->handler; + c->log->handler = NULL; + + ngx_log_error(NGX_LOG_INFO, c->log, 0, + "udp timed out" + ", packets from/to client:%ui/%ui" + ", bytes from/to client:%O/%O" + ", bytes from/to upstream:%O/%O", + u->requests, u->responses, + s->received, c->sent, u->received, + pc ? pc->sent : 0); + + c->log->handler = handler; + + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + return; + } + + ngx_connection_error(pc, NGX_ETIMEDOUT, "upstream timed out"); + + pc->read->error = 1; + + ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); + + return; + } + + ngx_connection_error(c, NGX_ETIMEDOUT, "connection timed out"); + + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + + return; + } + + } else if (ev->delayed) { + + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, + "stream connection delayed"); + + if (ngx_handle_read_event(ev, 0) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + } + + return; + } + + if (from_upstream && !u->connected) { + return; + } + + ngx_stream_proxy_process(s, from_upstream, ev->write); +} + + +static void +ngx_stream_proxy_connect_handler(ngx_event_t *ev) +{ + ngx_connection_t *c; + ngx_stream_session_t *s; + + c = ev->data; + s = c->data; + + if (ev->timedout) { + ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT, "upstream timed out"); + ngx_stream_proxy_next_upstream(s); + return; + } + + ngx_del_timer(c->write); ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream connection delayed"); + "stream proxy connect upstream"); - if (ngx_handle_read_event(ev, 0) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + if (ngx_stream_proxy_test_connect(c) != NGX_OK) { + ngx_stream_proxy_next_upstream(s); + return; } - return; - } - - if (from_upstream && !u->connected) { - return; - } - - ngx_stream_proxy_process(s, from_upstream, ev->write); + ngx_stream_proxy_init_upstream(s); } -static void ngx_stream_proxy_connect_handler(ngx_event_t *ev) { - ngx_connection_t *c; - ngx_stream_session_t *s; - c = ev->data; - s = c->data; - - if (ev->timedout) { - ngx_log_error(NGX_LOG_ERR, c->log, NGX_ETIMEDOUT, "upstream timed out"); - ngx_stream_proxy_next_upstream(s); - return; - } - - ngx_del_timer(c->write); - - ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, - "stream proxy connect upstream"); - - if (ngx_stream_proxy_test_connect(c) != NGX_OK) { - ngx_stream_proxy_next_upstream(s); - return; - } - - ngx_stream_proxy_init_upstream(s); -} - -static ngx_int_t ngx_stream_proxy_test_connect(ngx_connection_t *c) { - int err; - socklen_t len; +static ngx_int_t +ngx_stream_proxy_test_connect(ngx_connection_t *c) +{ + int err; + socklen_t len; #if (NGX_HAVE_KQUEUE) - if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { - err = c->write->kq_errno ? c->write->kq_errno : c->read->kq_errno; + if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { + err = c->write->kq_errno ? c->write->kq_errno : c->read->kq_errno; - if (err) { - (void)ngx_connection_error(c, err, - "kevent() reported that connect() failed"); - return NGX_ERROR; - } + if (err) { + (void) ngx_connection_error(c, err, + "kevent() reported that connect() failed"); + return NGX_ERROR; + } - } else + } else #endif - { - err = 0; - len = sizeof(int); + { + err = 0; + len = sizeof(int); - /* - * BSDs and Linux return 0 and set a pending error in err - * Solaris returns -1 and sets errno - */ + /* + * BSDs and Linux return 0 and set a pending error in err + * Solaris returns -1 and sets errno + */ - if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *)&err, &len) == -1) { - err = ngx_socket_errno; + if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len) + == -1) + { + err = ngx_socket_errno; + } + + if (err) { + (void) ngx_connection_error(c, err, "connect() failed"); + return NGX_ERROR; + } } - if (err) { - (void)ngx_connection_error(c, err, "connect() failed"); - return NGX_ERROR; - } - } - - return NGX_OK; + return NGX_OK; } -static void ngx_stream_proxy_process(ngx_stream_session_t *s, - ngx_uint_t from_upstream, - ngx_uint_t do_write) { - char *recv_action, *send_action; - off_t *received, limit; - size_t size, limit_rate; - ssize_t n; - ngx_buf_t *b; - ngx_int_t rc; - ngx_uint_t flags, *packets; - ngx_msec_t delay; - ngx_chain_t *cl, **ll, **out, **busy; - ngx_connection_t *c, *pc, *src, *dst; - ngx_log_handler_pt handler; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - u = s->upstream; +static void +ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream, + ngx_uint_t do_write) +{ + char *recv_action, *send_action; + off_t *received, limit; + size_t size, limit_rate; + ssize_t n; + ngx_buf_t *b; + ngx_int_t rc; + ngx_uint_t flags, *packets; + ngx_msec_t delay; + ngx_chain_t *cl, **ll, **out, **busy; + ngx_connection_t *c, *pc, *src, *dst; + ngx_log_handler_pt handler; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; - c = s->connection; - pc = u->connected ? u->peer.connection : NULL; + u = s->upstream; - if (c->type == SOCK_DGRAM && (ngx_terminate || ngx_exiting)) { + c = s->connection; + pc = u->connected ? u->peer.connection : NULL; - /* socket is already closed on worker shutdown */ + if (c->type == SOCK_DGRAM && (ngx_terminate || ngx_exiting)) { - handler = c->log->handler; - c->log->handler = NULL; + /* socket is already closed on worker shutdown */ - ngx_log_error(NGX_LOG_INFO, c->log, 0, "disconnected on shutdown"); + handler = c->log->handler; + c->log->handler = NULL; - c->log->handler = handler; + ngx_log_error(NGX_LOG_INFO, c->log, 0, "disconnected on shutdown"); - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - return; - } + c->log->handler = handler; - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - - if (from_upstream) { - src = pc; - dst = c; - b = &u->upstream_buf; - limit_rate = u->download_rate; - received = &u->received; - packets = &u->responses; - out = &u->downstream_out; - busy = &u->downstream_busy; - recv_action = "proxying and reading from upstream"; - send_action = "proxying and sending to client"; - - } else { - src = c; - dst = pc; - b = &u->downstream_buf; - limit_rate = u->upload_rate; - received = &s->received; - packets = &u->requests; - out = &u->upstream_out; - busy = &u->upstream_busy; - recv_action = "proxying and reading from client"; - send_action = "proxying and sending to upstream"; - } - - for (;;) { - - if (do_write && dst) { - - if (*out || *busy || dst->buffered) { - c->log->action = send_action; - - rc = ngx_stream_top_filter(s, *out, from_upstream); - - if (rc == NGX_ERROR) { - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - return; - } - - ngx_chain_update_chains(c->pool, &u->free, busy, out, - (ngx_buf_tag_t)&ngx_stream_proxy_module); - - if (*busy == NULL) { - b->pos = b->start; - b->last = b->start; - } - } + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + return; } - size = b->end - b->last; + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - if (size && src->read->ready && !src->read->delayed) { + if (from_upstream) { + src = pc; + dst = c; + b = &u->upstream_buf; + limit_rate = u->download_rate; + received = &u->received; + packets = &u->responses; + out = &u->downstream_out; + busy = &u->downstream_busy; + recv_action = "proxying and reading from upstream"; + send_action = "proxying and sending to client"; - if (limit_rate) { - limit = (off_t)limit_rate * (ngx_time() - u->start_sec + 1) - *received; + } else { + src = c; + dst = pc; + b = &u->downstream_buf; + limit_rate = u->upload_rate; + received = &s->received; + packets = &u->requests; + out = &u->upstream_out; + busy = &u->upstream_busy; + recv_action = "proxying and reading from client"; + send_action = "proxying and sending to upstream"; + } - if (limit <= 0) { - src->read->delayed = 1; - delay = (ngx_msec_t)(-limit * 1000 / limit_rate + 1); - ngx_add_timer(src->read, delay); - break; + for ( ;; ) { + + if (do_write && dst) { + + if (*out || *busy || dst->buffered) { + c->log->action = send_action; + + rc = ngx_stream_top_filter(s, *out, from_upstream); + + if (rc == NGX_ERROR) { + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + return; + } + + ngx_chain_update_chains(c->pool, &u->free, busy, out, + (ngx_buf_tag_t) &ngx_stream_proxy_module); + + if (*busy == NULL) { + b->pos = b->start; + b->last = b->start; + } + } } - if (c->type == SOCK_STREAM && (off_t)size > limit) { - size = (size_t)limit; + size = b->end - b->last; + + if (size && src->read->ready && !src->read->delayed) { + + if (limit_rate) { + limit = (off_t) limit_rate * (ngx_time() - u->start_sec + 1) + - *received; + + if (limit <= 0) { + src->read->delayed = 1; + delay = (ngx_msec_t) (- limit * 1000 / limit_rate + 1); + ngx_add_timer(src->read, delay); + break; + } + + if (c->type == SOCK_STREAM && (off_t) size > limit) { + size = (size_t) limit; + } + } + + c->log->action = recv_action; + + n = src->recv(src, b->last, size); + + if (n == NGX_AGAIN) { + break; + } + + if (n == NGX_ERROR) { + src->read->eof = 1; + n = 0; + } + + if (n >= 0) { + if (limit_rate) { + delay = (ngx_msec_t) (n * 1000 / limit_rate); + + if (delay > 0) { + src->read->delayed = 1; + ngx_add_timer(src->read, delay); + } + } + + if (from_upstream) { + if (u->state->first_byte_time == (ngx_msec_t) -1) { + u->state->first_byte_time = ngx_current_msec + - u->start_time; + } + } + + for (ll = out; *ll; ll = &(*ll)->next) { /* void */ } + + cl = ngx_chain_get_free_buf(c->pool, &u->free); + if (cl == NULL) { + ngx_stream_proxy_finalize(s, + NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + *ll = cl; + + cl->buf->pos = b->last; + cl->buf->last = b->last + n; + cl->buf->tag = (ngx_buf_tag_t) &ngx_stream_proxy_module; + + cl->buf->temporary = (n ? 1 : 0); + cl->buf->last_buf = src->read->eof; + cl->buf->flush = !src->read->eof; + + (*packets)++; + *received += n; + b->last += n; + do_write = 1; + + continue; + } } - } - c->log->action = recv_action; - - n = src->recv(src, b->last, size); - - if (n == NGX_AGAIN) { break; - } - - if (n == NGX_ERROR) { - src->read->eof = 1; - n = 0; - } - - if (n >= 0) { - if (limit_rate) { - delay = (ngx_msec_t)(n * 1000 / limit_rate); - - if (delay > 0) { - src->read->delayed = 1; - ngx_add_timer(src->read, delay); - } - } - - if (from_upstream) { - if (u->state->first_byte_time == (ngx_msec_t)-1) { - u->state->first_byte_time = ngx_current_msec - u->start_time; - } - } - - for (ll = out; *ll; ll = &(*ll)->next) { /* void */ - } - - cl = ngx_chain_get_free_buf(c->pool, &u->free); - if (cl == NULL) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - *ll = cl; - - cl->buf->pos = b->last; - cl->buf->last = b->last + n; - cl->buf->tag = (ngx_buf_tag_t)&ngx_stream_proxy_module; - - cl->buf->temporary = (n ? 1 : 0); - cl->buf->last_buf = src->read->eof; - cl->buf->flush = !src->read->eof; - - (*packets)++; - *received += n; - b->last += n; - do_write = 1; - - continue; - } } - break; - } + c->log->action = "proxying connection"; - c->log->action = "proxying connection"; + if (ngx_stream_proxy_test_finalize(s, from_upstream) == NGX_OK) { + return; + } - if (ngx_stream_proxy_test_finalize(s, from_upstream) == NGX_OK) { - return; - } - - flags = src->read->eof ? NGX_CLOSE_EVENT : 0; - - if (ngx_handle_read_event(src->read, flags) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } - - if (dst) { - - if (dst->type == SOCK_STREAM && pscf->half_close && src->read->eof && - !u->half_closed && !dst->buffered) { - if (ngx_shutdown_socket(dst->fd, NGX_WRITE_SHUTDOWN) == -1) { - ngx_connection_error(c, ngx_socket_errno, - ngx_shutdown_socket_n " failed"); + flags = src->read->eof ? NGX_CLOSE_EVENT : 0; + if (ngx_handle_read_event(src->read, flags) != NGX_OK) { ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); return; - } - - u->half_closed = 1; - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "stream proxy %s socket shutdown", - from_upstream ? "client" : "upstream"); } - if (ngx_handle_write_event(dst->write, 0) != NGX_OK) { - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } + if (dst) { - if (!c->read->delayed && !pc->read->delayed) { - ngx_add_timer(c->write, pscf->timeout); + if (dst->type == SOCK_STREAM && pscf->half_close + && src->read->eof && !u->half_closed && !dst->buffered) + { + if (ngx_shutdown_socket(dst->fd, NGX_WRITE_SHUTDOWN) == -1) { + ngx_connection_error(c, ngx_socket_errno, + ngx_shutdown_socket_n " failed"); - } else if (c->write->timer_set) { - ngx_del_timer(c->write); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + u->half_closed = 1; + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "stream proxy %s socket shutdown", + from_upstream ? "client" : "upstream"); + } + + if (ngx_handle_write_event(dst->write, 0) != NGX_OK) { + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; + } + + if (!c->read->delayed && !pc->read->delayed) { + ngx_add_timer(c->write, pscf->timeout); + + } else if (c->write->timer_set) { + ngx_del_timer(c->write); + } } - } } -static ngx_int_t ngx_stream_proxy_test_finalize(ngx_stream_session_t *s, - ngx_uint_t from_upstream) { - ngx_connection_t *c, *pc; - ngx_log_handler_pt handler; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); +static ngx_int_t +ngx_stream_proxy_test_finalize(ngx_stream_session_t *s, + ngx_uint_t from_upstream) +{ + ngx_connection_t *c, *pc; + ngx_log_handler_pt handler; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; - c = s->connection; - u = s->upstream; - pc = u->connected ? u->peer.connection : NULL; + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - if (c->type == SOCK_DGRAM) { + c = s->connection; + u = s->upstream; + pc = u->connected ? u->peer.connection : NULL; - if (pscf->requests && u->requests < pscf->requests) { - return NGX_DECLINED; + if (c->type == SOCK_DGRAM) { + + if (pscf->requests && u->requests < pscf->requests) { + return NGX_DECLINED; + } + + if (pscf->requests) { + ngx_delete_udp_connection(c); + } + + if (pscf->responses == NGX_MAX_INT32_VALUE + || u->responses < pscf->responses * u->requests) + { + return NGX_DECLINED; + } + + if (pc == NULL || c->buffered || pc->buffered) { + return NGX_DECLINED; + } + + handler = c->log->handler; + c->log->handler = NULL; + + ngx_log_error(NGX_LOG_INFO, c->log, 0, + "udp done" + ", packets from/to client:%ui/%ui" + ", bytes from/to client:%O/%O" + ", bytes from/to upstream:%O/%O", + u->requests, u->responses, + s->received, c->sent, u->received, pc ? pc->sent : 0); + + c->log->handler = handler; + + ngx_stream_proxy_finalize(s, NGX_STREAM_OK); + + return NGX_OK; } - if (pscf->requests) { - ngx_delete_udp_connection(c); + /* c->type == SOCK_STREAM */ + + if (pc == NULL + || (!c->read->eof && !pc->read->eof) + || (!c->read->eof && c->buffered) + || (!pc->read->eof && pc->buffered)) + { + return NGX_DECLINED; } - if (pscf->responses == NGX_MAX_INT32_VALUE || - u->responses < pscf->responses * u->requests) { - return NGX_DECLINED; - } - - if (pc == NULL || c->buffered || pc->buffered) { - return NGX_DECLINED; + if (pscf->half_close) { + /* avoid closing live connections until both read ends get EOF */ + if (!(c->read->eof && pc->read->eof && !c->buffered && !pc->buffered)) { + return NGX_DECLINED; + } } handler = c->log->handler; c->log->handler = NULL; ngx_log_error(NGX_LOG_INFO, c->log, 0, - "udp done" - ", packets from/to client:%ui/%ui" + "%s disconnected" ", bytes from/to client:%O/%O" ", bytes from/to upstream:%O/%O", - u->requests, u->responses, s->received, c->sent, u->received, - pc ? pc->sent : 0); + from_upstream ? "upstream" : "client", + s->received, c->sent, u->received, pc ? pc->sent : 0); c->log->handler = handler; ngx_stream_proxy_finalize(s, NGX_STREAM_OK); return NGX_OK; - } - - /* c->type == SOCK_STREAM */ - - if (pc == NULL || (!c->read->eof && !pc->read->eof) || - (!c->read->eof && c->buffered) || (!pc->read->eof && pc->buffered)) { - return NGX_DECLINED; - } - - if (pscf->half_close) { - /* avoid closing live connections until both read ends get EOF */ - if (!(c->read->eof && pc->read->eof && !c->buffered && !pc->buffered)) { - return NGX_DECLINED; - } - } - - handler = c->log->handler; - c->log->handler = NULL; - - ngx_log_error(NGX_LOG_INFO, c->log, 0, - "%s disconnected" - ", bytes from/to client:%O/%O" - ", bytes from/to upstream:%O/%O", - from_upstream ? "upstream" : "client", s->received, c->sent, - u->received, pc ? pc->sent : 0); - - c->log->handler = handler; - - ngx_stream_proxy_finalize(s, NGX_STREAM_OK); - - return NGX_OK; } -static void ngx_stream_proxy_next_upstream(ngx_stream_session_t *s) { - ngx_msec_t timeout; - ngx_connection_t *pc; - ngx_stream_upstream_t *u; - ngx_stream_proxy_srv_conf_t *pscf; - ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "stream proxy next upstream"); +static void +ngx_stream_proxy_next_upstream(ngx_stream_session_t *s) +{ + ngx_msec_t timeout; + ngx_connection_t *pc; + ngx_stream_upstream_t *u; + ngx_stream_proxy_srv_conf_t *pscf; - u = s->upstream; - pc = u->peer.connection; + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "stream proxy next upstream"); - if (pc && pc->buffered) { - ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, - "buffered data on next upstream"); - ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); - return; - } + u = s->upstream; + pc = u->peer.connection; - if (s->connection->type == SOCK_DGRAM) { - u->upstream_out = NULL; - } - - if (u->peer.sockaddr) { - u->peer.free(&u->peer, u->peer.data, NGX_PEER_FAILED); - u->peer.sockaddr = NULL; - } - - pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); - - timeout = pscf->next_upstream_timeout; - - if (u->peer.tries == 0 || !pscf->next_upstream || - (timeout && ngx_current_msec - u->peer.start_time >= timeout)) { - ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); - return; - } - - if (pc) { - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "close proxy upstream connection: %d", pc->fd); - -#if (NGX_STREAM_SSL) - if (pc->ssl) { - pc->ssl->no_wait_shutdown = 1; - pc->ssl->no_send_shutdown = 1; - - (void)ngx_ssl_shutdown(pc); + if (pc && pc->buffered) { + ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, + "buffered data on next upstream"); + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); + return; } -#endif - u->state->bytes_received = u->received; - u->state->bytes_sent = pc->sent; + if (s->connection->type == SOCK_DGRAM) { + u->upstream_out = NULL; + } - ngx_close_connection(pc); - u->peer.connection = NULL; - } + if (u->peer.sockaddr) { + u->peer.free(&u->peer, u->peer.data, NGX_PEER_FAILED); + u->peer.sockaddr = NULL; + } - ngx_stream_proxy_connect(s); -} + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); -static void ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc) { - ngx_uint_t state; - ngx_connection_t *pc; - ngx_stream_upstream_t *u; + timeout = pscf->next_upstream_timeout; - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "finalize stream proxy: %i", rc); - - u = s->upstream; - - if (u == NULL) { - goto noupstream; - } - - if (u->resolved && u->resolved->ctx) { - ngx_resolve_name_done(u->resolved->ctx); - u->resolved->ctx = NULL; - } - - pc = u->peer.connection; - - if (u->state) { - if (u->state->response_time == (ngx_msec_t)-1) { - u->state->response_time = ngx_current_msec - u->start_time; + if (u->peer.tries == 0 + || !pscf->next_upstream + || (timeout && ngx_current_msec - u->peer.start_time >= timeout)) + { + ngx_stream_proxy_finalize(s, NGX_STREAM_BAD_GATEWAY); + return; } if (pc) { - u->state->bytes_received = u->received; - u->state->bytes_sent = pc->sent; - } - } - - if (u->peer.free && u->peer.sockaddr) { - state = 0; - - if (pc && pc->type == SOCK_DGRAM && (pc->read->error || pc->write->error)) { - state = NGX_PEER_FAILED; - } - - u->peer.free(&u->peer, u->peer.data, state); - u->peer.sockaddr = NULL; - } - - if (pc) { - ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, - "close stream proxy upstream connection: %d", pc->fd); + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "close proxy upstream connection: %d", pc->fd); #if (NGX_STREAM_SSL) - if (pc->ssl) { - pc->ssl->no_wait_shutdown = 1; - (void)ngx_ssl_shutdown(pc); - } + if (pc->ssl) { + pc->ssl->no_wait_shutdown = 1; + pc->ssl->no_send_shutdown = 1; + + (void) ngx_ssl_shutdown(pc); + } #endif - ngx_close_connection(pc); - u->peer.connection = NULL; - } + u->state->bytes_received = u->received; + u->state->bytes_sent = pc->sent; + + ngx_close_connection(pc); + u->peer.connection = NULL; + } + + ngx_stream_proxy_connect(s); +} + + +static void +ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc) +{ + ngx_uint_t state; + ngx_connection_t *pc; + ngx_stream_upstream_t *u; + + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "finalize stream proxy: %i", rc); + + u = s->upstream; + + if (u == NULL) { + goto noupstream; + } + + if (u->resolved && u->resolved->ctx) { + ngx_resolve_name_done(u->resolved->ctx); + u->resolved->ctx = NULL; + } + + pc = u->peer.connection; + + if (u->state) { + if (u->state->response_time == (ngx_msec_t) -1) { + u->state->response_time = ngx_current_msec - u->start_time; + } + + if (pc) { + u->state->bytes_received = u->received; + u->state->bytes_sent = pc->sent; + } + } + + if (u->peer.free && u->peer.sockaddr) { + state = 0; + + if (pc && pc->type == SOCK_DGRAM + && (pc->read->error || pc->write->error)) + { + state = NGX_PEER_FAILED; + } + + u->peer.free(&u->peer, u->peer.data, state); + u->peer.sockaddr = NULL; + } + + if (pc) { + ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, + "close stream proxy upstream connection: %d", pc->fd); + +#if (NGX_STREAM_SSL) + if (pc->ssl) { + pc->ssl->no_wait_shutdown = 1; + (void) ngx_ssl_shutdown(pc); + } +#endif + + ngx_close_connection(pc); + u->peer.connection = NULL; + } noupstream: - ngx_stream_finalize_session(s, rc); + ngx_stream_finalize_session(s, rc); } -static u_char *ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf, - size_t len) { - u_char *p; - ngx_connection_t *pc; - ngx_stream_session_t *s; - ngx_stream_upstream_t *u; - s = log->data; +static u_char * +ngx_stream_proxy_log_error(ngx_log_t *log, u_char *buf, size_t len) +{ + u_char *p; + ngx_connection_t *pc; + ngx_stream_session_t *s; + ngx_stream_upstream_t *u; - u = s->upstream; + s = log->data; - p = buf; + u = s->upstream; - if (u->peer.name) { - p = ngx_snprintf(p, len, ", upstream: \"%V\"", u->peer.name); - len -= p - buf; - } + p = buf; - pc = u->peer.connection; - - p = ngx_snprintf(p, len, - ", bytes from/to client:%O/%O" - ", bytes from/to upstream:%O/%O", - s->received, s->connection->sent, u->received, - pc ? pc->sent : 0); - - return p; -} - -static void *ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf) { - ngx_stream_proxy_srv_conf_t *conf; - - conf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_proxy_srv_conf_t)); - if (conf == NULL) { - return NULL; - } - - /* - * set by ngx_pcalloc(): - * - * conf->ssl_protocols = 0; - * conf->ssl_ciphers = { 0, NULL }; - * conf->ssl_trusted_certificate = { 0, NULL }; - * conf->ssl_crl = { 0, NULL }; - * - * conf->ssl = NULL; - * conf->upstream = NULL; - * conf->upstream_value = NULL; - */ - - conf->connect_timeout = NGX_CONF_UNSET_MSEC; - conf->timeout = NGX_CONF_UNSET_MSEC; - conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC; - conf->buffer_size = NGX_CONF_UNSET_SIZE; - conf->upload_rate = NGX_CONF_UNSET_PTR; - conf->download_rate = NGX_CONF_UNSET_PTR; - conf->requests = NGX_CONF_UNSET_UINT; - conf->responses = NGX_CONF_UNSET_UINT; - conf->next_upstream_tries = NGX_CONF_UNSET_UINT; - conf->next_upstream = NGX_CONF_UNSET; - conf->proxy_protocol = NGX_CONF_UNSET; - conf->protocol_version = NGX_CONF_UNSET_UINT; - conf->local = NGX_CONF_UNSET_PTR; - conf->socket_keepalive = NGX_CONF_UNSET; - conf->half_close = NGX_CONF_UNSET; - -#if (NGX_STREAM_SSL) - conf->ssl_enable = NGX_CONF_UNSET; - conf->ssl_session_reuse = NGX_CONF_UNSET; - conf->ssl_name = NGX_CONF_UNSET_PTR; - conf->ssl_server_name = NGX_CONF_UNSET; - conf->ssl_verify = NGX_CONF_UNSET; - conf->ssl_verify_depth = NGX_CONF_UNSET_UINT; - conf->ssl_certificate = NGX_CONF_UNSET_PTR; - conf->ssl_certificate_key = NGX_CONF_UNSET_PTR; - conf->ssl_certificate_cache = NGX_CONF_UNSET_PTR; - conf->ssl_passwords = NGX_CONF_UNSET_PTR; - conf->ssl_conf_commands = NGX_CONF_UNSET_PTR; -#endif - - return conf; -} - -static char *ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, - void *child) { - ngx_stream_proxy_srv_conf_t *prev = parent; - ngx_stream_proxy_srv_conf_t *conf = child; - - ngx_conf_merge_msec_value(conf->connect_timeout, prev->connect_timeout, - 60000); - - ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 10 * 60000); - - ngx_conf_merge_msec_value(conf->next_upstream_timeout, - prev->next_upstream_timeout, 0); - - ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, 16384); - - ngx_conf_merge_ptr_value(conf->upload_rate, prev->upload_rate, NULL); - - ngx_conf_merge_ptr_value(conf->download_rate, prev->download_rate, NULL); - - ngx_conf_merge_uint_value(conf->requests, prev->requests, 0); - - ngx_conf_merge_uint_value(conf->responses, prev->responses, - NGX_MAX_INT32_VALUE); - - ngx_conf_merge_uint_value(conf->next_upstream_tries, - prev->next_upstream_tries, 0); - - ngx_conf_merge_value(conf->next_upstream, prev->next_upstream, 1); - - ngx_conf_merge_value(conf->proxy_protocol, prev->proxy_protocol, 0); - - ngx_conf_merge_uint_value(conf->protocol_version, prev->protocol_version, 1); - - ngx_conf_merge_ptr_value(conf->local, prev->local, NULL); - - ngx_conf_merge_value(conf->socket_keepalive, prev->socket_keepalive, 0); - - ngx_conf_merge_value(conf->half_close, prev->half_close, 0); - -#if (NGX_STREAM_SSL) - - if (ngx_stream_proxy_merge_ssl(cf, conf, prev) != NGX_OK) { - return NGX_CONF_ERROR; - } - - ngx_conf_merge_value(conf->ssl_enable, prev->ssl_enable, 0); - - ngx_conf_merge_value(conf->ssl_session_reuse, prev->ssl_session_reuse, 1); - - ngx_conf_merge_bitmask_value( - conf->ssl_protocols, prev->ssl_protocols, - (NGX_CONF_BITMASK_SET | NGX_SSL_DEFAULT_PROTOCOLS)); - - ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers, "DEFAULT"); - - ngx_conf_merge_ptr_value(conf->ssl_name, prev->ssl_name, NULL); - - ngx_conf_merge_value(conf->ssl_server_name, prev->ssl_server_name, 0); - - ngx_conf_merge_value(conf->ssl_verify, prev->ssl_verify, 0); - - ngx_conf_merge_uint_value(conf->ssl_verify_depth, prev->ssl_verify_depth, 1); - - ngx_conf_merge_str_value(conf->ssl_trusted_certificate, - prev->ssl_trusted_certificate, ""); - - ngx_conf_merge_str_value(conf->ssl_crl, prev->ssl_crl, ""); - - ngx_conf_merge_ptr_value(conf->ssl_certificate, prev->ssl_certificate, NULL); - - ngx_conf_merge_ptr_value(conf->ssl_certificate_key, prev->ssl_certificate_key, - NULL); - - ngx_conf_merge_ptr_value(conf->ssl_certificate_cache, - prev->ssl_certificate_cache, NULL); - - if (ngx_stream_proxy_merge_ssl_passwords(cf, conf, prev) != NGX_OK) { - return NGX_CONF_ERROR; - } - - ngx_conf_merge_ptr_value(conf->ssl_conf_commands, prev->ssl_conf_commands, - NULL); - - if (conf->ssl_enable && ngx_stream_proxy_set_ssl(cf, conf) != NGX_OK) { - return NGX_CONF_ERROR; - } - -#endif - - return NGX_CONF_OK; -} - -#if (NGX_STREAM_SSL) - -static ngx_int_t ngx_stream_proxy_merge_ssl(ngx_conf_t *cf, - ngx_stream_proxy_srv_conf_t *conf, - ngx_stream_proxy_srv_conf_t *prev) { - ngx_uint_t preserve; - - if (conf->ssl_protocols == 0 && conf->ssl_ciphers.data == NULL && - conf->ssl_certificate == NGX_CONF_UNSET_PTR && - conf->ssl_certificate_key == NGX_CONF_UNSET_PTR && - conf->ssl_passwords == NGX_CONF_UNSET_PTR && - conf->ssl_verify == NGX_CONF_UNSET && - conf->ssl_verify_depth == NGX_CONF_UNSET_UINT && - conf->ssl_trusted_certificate.data == NULL && - conf->ssl_crl.data == NULL && conf->ssl_session_reuse == NGX_CONF_UNSET && - conf->ssl_conf_commands == NGX_CONF_UNSET_PTR) { - if (prev->ssl) { - conf->ssl = prev->ssl; - return NGX_OK; + if (u->peer.name) { + p = ngx_snprintf(p, len, ", upstream: \"%V\"", u->peer.name); + len -= p - buf; } - preserve = 1; + pc = u->peer.connection; - } else { - preserve = 0; - } + p = ngx_snprintf(p, len, + ", bytes from/to client:%O/%O" + ", bytes from/to upstream:%O/%O", + s->received, s->connection->sent, + u->received, pc ? pc->sent : 0); - conf->ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t)); - if (conf->ssl == NULL) { - return NGX_ERROR; - } - - conf->ssl->log = cf->log; - - /* - * special handling to preserve conf->ssl - * in the "stream" section to inherit it to all servers - */ - - if (preserve) { - prev->ssl = conf->ssl; - } - - return NGX_OK; + return p; } + +static void * +ngx_stream_proxy_create_srv_conf(ngx_conf_t *cf) +{ + ngx_stream_proxy_srv_conf_t *conf; + + conf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_proxy_srv_conf_t)); + if (conf == NULL) { + return NULL; + } + + /* + * set by ngx_pcalloc(): + * + * conf->ssl_protocols = 0; + * conf->ssl_ciphers = { 0, NULL }; + * conf->ssl_trusted_certificate = { 0, NULL }; + * conf->ssl_crl = { 0, NULL }; + * + * conf->ssl = NULL; + * conf->upstream = NULL; + * conf->upstream_value = NULL; + */ + + conf->connect_timeout = NGX_CONF_UNSET_MSEC; + conf->timeout = NGX_CONF_UNSET_MSEC; + conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC; + conf->buffer_size = NGX_CONF_UNSET_SIZE; + conf->upload_rate = NGX_CONF_UNSET_PTR; + conf->download_rate = NGX_CONF_UNSET_PTR; + conf->requests = NGX_CONF_UNSET_UINT; + conf->responses = NGX_CONF_UNSET_UINT; + conf->next_upstream_tries = NGX_CONF_UNSET_UINT; + conf->next_upstream = NGX_CONF_UNSET; + conf->proxy_protocol = NGX_CONF_UNSET; + conf->protocol_version = NGX_CONF_UNSET_UINT; + conf->local = NGX_CONF_UNSET_PTR; + conf->socket_keepalive = NGX_CONF_UNSET; + conf->half_close = NGX_CONF_UNSET; + +#if (NGX_STREAM_SSL) + conf->ssl_enable = NGX_CONF_UNSET; + conf->ssl_session_reuse = NGX_CONF_UNSET; + conf->ssl_name = NGX_CONF_UNSET_PTR; + conf->ssl_server_name = NGX_CONF_UNSET; + conf->ssl_verify = NGX_CONF_UNSET; + conf->ssl_verify_depth = NGX_CONF_UNSET_UINT; + conf->ssl_certificate = NGX_CONF_UNSET_PTR; + conf->ssl_certificate_key = NGX_CONF_UNSET_PTR; + conf->ssl_certificate_cache = NGX_CONF_UNSET_PTR; + conf->ssl_passwords = NGX_CONF_UNSET_PTR; + conf->ssl_conf_commands = NGX_CONF_UNSET_PTR; +#endif + + return conf; +} + + +static char * +ngx_stream_proxy_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) +{ + ngx_stream_proxy_srv_conf_t *prev = parent; + ngx_stream_proxy_srv_conf_t *conf = child; + + ngx_conf_merge_msec_value(conf->connect_timeout, + prev->connect_timeout, 60000); + + ngx_conf_merge_msec_value(conf->timeout, + prev->timeout, 10 * 60000); + + ngx_conf_merge_msec_value(conf->next_upstream_timeout, + prev->next_upstream_timeout, 0); + + ngx_conf_merge_size_value(conf->buffer_size, + prev->buffer_size, 16384); + + ngx_conf_merge_ptr_value(conf->upload_rate, prev->upload_rate, NULL); + + ngx_conf_merge_ptr_value(conf->download_rate, prev->download_rate, NULL); + + ngx_conf_merge_uint_value(conf->requests, + prev->requests, 0); + + ngx_conf_merge_uint_value(conf->responses, + prev->responses, NGX_MAX_INT32_VALUE); + + ngx_conf_merge_uint_value(conf->next_upstream_tries, + prev->next_upstream_tries, 0); + + ngx_conf_merge_value(conf->next_upstream, prev->next_upstream, 1); + + ngx_conf_merge_value(conf->proxy_protocol, prev->proxy_protocol, 0); + + ngx_conf_merge_ptr_value(conf->local, prev->local, NULL); + + ngx_conf_merge_value(conf->socket_keepalive, + prev->socket_keepalive, 0); + + ngx_conf_merge_value(conf->half_close, prev->half_close, 0); + +#if (NGX_STREAM_SSL) + + if (ngx_stream_proxy_merge_ssl(cf, conf, prev) != NGX_OK) { + return NGX_CONF_ERROR; + } + + ngx_conf_merge_value(conf->ssl_enable, prev->ssl_enable, 0); + + ngx_conf_merge_value(conf->ssl_session_reuse, + prev->ssl_session_reuse, 1); + + ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols, + (NGX_CONF_BITMASK_SET|NGX_SSL_DEFAULT_PROTOCOLS)); + + ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers, "DEFAULT"); + + ngx_conf_merge_ptr_value(conf->ssl_name, prev->ssl_name, NULL); + + ngx_conf_merge_value(conf->ssl_server_name, prev->ssl_server_name, 0); + + ngx_conf_merge_value(conf->ssl_verify, prev->ssl_verify, 0); + + ngx_conf_merge_uint_value(conf->ssl_verify_depth, + prev->ssl_verify_depth, 1); + + ngx_conf_merge_str_value(conf->ssl_trusted_certificate, + prev->ssl_trusted_certificate, ""); + + ngx_conf_merge_str_value(conf->ssl_crl, prev->ssl_crl, ""); + + ngx_conf_merge_ptr_value(conf->ssl_certificate, + prev->ssl_certificate, NULL); + + ngx_conf_merge_ptr_value(conf->ssl_certificate_key, + prev->ssl_certificate_key, NULL); + + ngx_conf_merge_ptr_value(conf->ssl_certificate_cache, + prev->ssl_certificate_cache, NULL); + + if (ngx_stream_proxy_merge_ssl_passwords(cf, conf, prev) != NGX_OK) { + return NGX_CONF_ERROR; + } + + ngx_conf_merge_ptr_value(conf->ssl_conf_commands, + prev->ssl_conf_commands, NULL); + + if (conf->ssl_enable && ngx_stream_proxy_set_ssl(cf, conf) != NGX_OK) { + return NGX_CONF_ERROR; + } + +#endif + + return NGX_CONF_OK; +} + + +#if (NGX_STREAM_SSL) + +static ngx_int_t +ngx_stream_proxy_merge_ssl(ngx_conf_t *cf, ngx_stream_proxy_srv_conf_t *conf, + ngx_stream_proxy_srv_conf_t *prev) +{ + ngx_uint_t preserve; + + if (conf->ssl_protocols == 0 + && conf->ssl_ciphers.data == NULL + && conf->ssl_certificate == NGX_CONF_UNSET_PTR + && conf->ssl_certificate_key == NGX_CONF_UNSET_PTR + && conf->ssl_passwords == NGX_CONF_UNSET_PTR + && conf->ssl_verify == NGX_CONF_UNSET + && conf->ssl_verify_depth == NGX_CONF_UNSET_UINT + && conf->ssl_trusted_certificate.data == NULL + && conf->ssl_crl.data == NULL + && conf->ssl_session_reuse == NGX_CONF_UNSET + && conf->ssl_conf_commands == NGX_CONF_UNSET_PTR) + { + if (prev->ssl) { + conf->ssl = prev->ssl; + return NGX_OK; + } + + preserve = 1; + + } else { + preserve = 0; + } + + conf->ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t)); + if (conf->ssl == NULL) { + return NGX_ERROR; + } + + conf->ssl->log = cf->log; + + /* + * special handling to preserve conf->ssl + * in the "stream" section to inherit it to all servers + */ + + if (preserve) { + prev->ssl = conf->ssl; + } + + return NGX_OK; +} + + static ngx_int_t ngx_stream_proxy_merge_ssl_passwords(ngx_conf_t *cf, - ngx_stream_proxy_srv_conf_t *conf, - ngx_stream_proxy_srv_conf_t *prev) { - ngx_uint_t preserve; + ngx_stream_proxy_srv_conf_t *conf, ngx_stream_proxy_srv_conf_t *prev) +{ + ngx_uint_t preserve; - ngx_conf_merge_ptr_value(conf->ssl_passwords, prev->ssl_passwords, NULL); + ngx_conf_merge_ptr_value(conf->ssl_passwords, prev->ssl_passwords, NULL); - if (conf->ssl_certificate == NULL || conf->ssl_certificate->value.len == 0 || - conf->ssl_certificate_key == NULL) { - return NGX_OK; - } - - if (conf->ssl_certificate->lengths == NULL && - conf->ssl_certificate_key->lengths == NULL) { - if (conf->ssl_passwords && conf->ssl_passwords->pool == NULL) { - /* un-preserve empty password list */ - conf->ssl_passwords = NULL; + if (conf->ssl_certificate == NULL + || conf->ssl_certificate->value.len == 0 + || conf->ssl_certificate_key == NULL) + { + return NGX_OK; } - return NGX_OK; - } + if (conf->ssl_certificate->lengths == NULL + && conf->ssl_certificate_key->lengths == NULL) + { + if (conf->ssl_passwords && conf->ssl_passwords->pool == NULL) { + /* un-preserve empty password list */ + conf->ssl_passwords = NULL; + } - if (conf->ssl_passwords && conf->ssl_passwords->pool != cf->temp_pool) { - /* already preserved */ - return NGX_OK; - } - - preserve = (conf->ssl_passwords == prev->ssl_passwords) ? 1 : 0; - - conf->ssl_passwords = ngx_ssl_preserve_passwords(cf, conf->ssl_passwords); - if (conf->ssl_passwords == NULL) { - return NGX_ERROR; - } - - /* - * special handling to keep a preserved ssl_passwords copy - * in the previous configuration to inherit it to all children - */ - - if (preserve) { - prev->ssl_passwords = conf->ssl_passwords; - } - - return NGX_OK; -} - -static ngx_int_t ngx_stream_proxy_set_ssl(ngx_conf_t *cf, - ngx_stream_proxy_srv_conf_t *pscf) { - ngx_pool_cleanup_t *cln; - - if (pscf->ssl->ctx) { - return NGX_OK; - } - - if (ngx_ssl_create(pscf->ssl, pscf->ssl_protocols, NULL) != NGX_OK) { - return NGX_ERROR; - } - - cln = ngx_pool_cleanup_add(cf->pool, 0); - if (cln == NULL) { - ngx_ssl_cleanup_ctx(pscf->ssl); - return NGX_ERROR; - } - - cln->handler = ngx_ssl_cleanup_ctx; - cln->data = pscf->ssl; - - if (ngx_ssl_ciphers(cf, pscf->ssl, &pscf->ssl_ciphers, 0) != NGX_OK) { - return NGX_ERROR; - } - - if (pscf->ssl_certificate && pscf->ssl_certificate->value.len) { - if (pscf->ssl_certificate_key == NULL) { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - "no \"proxy_ssl_certificate_key\" is defined " - "for certificate \"%V\"", - &pscf->ssl_certificate->value); - return NGX_ERROR; + return NGX_OK; } - if (pscf->ssl_certificate->lengths == NULL && - pscf->ssl_certificate_key->lengths == NULL) { - if (ngx_ssl_certificate(cf, pscf->ssl, &pscf->ssl_certificate->value, - &pscf->ssl_certificate_key->value, - pscf->ssl_passwords) != NGX_OK) { + if (conf->ssl_passwords && conf->ssl_passwords->pool != cf->temp_pool) { + /* already preserved */ + return NGX_OK; + } + + preserve = (conf->ssl_passwords == prev->ssl_passwords) ? 1 : 0; + + conf->ssl_passwords = ngx_ssl_preserve_passwords(cf, conf->ssl_passwords); + if (conf->ssl_passwords == NULL) { return NGX_ERROR; - } - } - } - - if (pscf->ssl_verify) { - if (pscf->ssl_trusted_certificate.len == 0) { - ngx_log_error(NGX_LOG_EMERG, cf->log, 0, - "no proxy_ssl_trusted_certificate for proxy_ssl_verify"); - return NGX_ERROR; } - if (ngx_ssl_trusted_certificate(cf, pscf->ssl, - &pscf->ssl_trusted_certificate, - pscf->ssl_verify_depth) != NGX_OK) { - return NGX_ERROR; + /* + * special handling to keep a preserved ssl_passwords copy + * in the previous configuration to inherit it to all children + */ + + if (preserve) { + prev->ssl_passwords = conf->ssl_passwords; } - if (ngx_ssl_crl(cf, pscf->ssl, &pscf->ssl_crl) != NGX_OK) { - return NGX_ERROR; + return NGX_OK; +} + + +static ngx_int_t +ngx_stream_proxy_set_ssl(ngx_conf_t *cf, ngx_stream_proxy_srv_conf_t *pscf) +{ + ngx_pool_cleanup_t *cln; + + if (pscf->ssl->ctx) { + return NGX_OK; } - } - if (ngx_ssl_client_session_cache(cf, pscf->ssl, pscf->ssl_session_reuse) != - NGX_OK) { - return NGX_ERROR; - } + if (ngx_ssl_create(pscf->ssl, pscf->ssl_protocols, NULL) != NGX_OK) { + return NGX_ERROR; + } - if (ngx_ssl_conf_commands(cf, pscf->ssl, pscf->ssl_conf_commands) != NGX_OK) { - return NGX_ERROR; - } + cln = ngx_pool_cleanup_add(cf->pool, 0); + if (cln == NULL) { + ngx_ssl_cleanup_ctx(pscf->ssl); + return NGX_ERROR; + } - return NGX_OK; + cln->handler = ngx_ssl_cleanup_ctx; + cln->data = pscf->ssl; + + if (ngx_ssl_ciphers(cf, pscf->ssl, &pscf->ssl_ciphers, 0) != NGX_OK) { + return NGX_ERROR; + } + + if (pscf->ssl_certificate + && pscf->ssl_certificate->value.len) + { + if (pscf->ssl_certificate_key == NULL) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "no \"proxy_ssl_certificate_key\" is defined " + "for certificate \"%V\"", + &pscf->ssl_certificate->value); + return NGX_ERROR; + } + + if (pscf->ssl_certificate->lengths == NULL + && pscf->ssl_certificate_key->lengths == NULL) + { + if (ngx_ssl_certificate(cf, pscf->ssl, + &pscf->ssl_certificate->value, + &pscf->ssl_certificate_key->value, + pscf->ssl_passwords) + != NGX_OK) + { + return NGX_ERROR; + } + } + } + + if (pscf->ssl_verify) { + if (pscf->ssl_trusted_certificate.len == 0) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "no proxy_ssl_trusted_certificate for proxy_ssl_verify"); + return NGX_ERROR; + } + + if (ngx_ssl_trusted_certificate(cf, pscf->ssl, + &pscf->ssl_trusted_certificate, + pscf->ssl_verify_depth) + != NGX_OK) + { + return NGX_ERROR; + } + + if (ngx_ssl_crl(cf, pscf->ssl, &pscf->ssl_crl) != NGX_OK) { + return NGX_ERROR; + } + } + + if (ngx_ssl_client_session_cache(cf, pscf->ssl, pscf->ssl_session_reuse) + != NGX_OK) + { + return NGX_ERROR; + } + + if (ngx_ssl_conf_commands(cf, pscf->ssl, pscf->ssl_conf_commands) + != NGX_OK) + { + return NGX_ERROR; + } + + return NGX_OK; } #endif -static char *ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) { - ngx_stream_proxy_srv_conf_t *pscf = conf; - ngx_url_t u; - ngx_str_t *value, *url; - ngx_stream_complex_value_t cv; - ngx_stream_core_srv_conf_t *cscf; - ngx_stream_compile_complex_value_t ccv; +static char * +ngx_stream_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_stream_proxy_srv_conf_t *pscf = conf; - if (pscf->upstream || pscf->upstream_value) { - return "is duplicate"; - } + ngx_url_t u; + ngx_str_t *value, *url; + ngx_stream_complex_value_t cv; + ngx_stream_core_srv_conf_t *cscf; + ngx_stream_compile_complex_value_t ccv; - cscf = ngx_stream_conf_get_module_srv_conf(cf, ngx_stream_core_module); - - cscf->handler = ngx_stream_proxy_handler; - - value = cf->args->elts; - - url = &value[1]; - - ngx_memzero(&ccv, sizeof(ngx_stream_compile_complex_value_t)); - - ccv.cf = cf; - ccv.value = url; - ccv.complex_value = &cv; - - if (ngx_stream_compile_complex_value(&ccv) != NGX_OK) { - return NGX_CONF_ERROR; - } - - if (cv.lengths) { - pscf->upstream_value = - ngx_palloc(cf->pool, sizeof(ngx_stream_complex_value_t)); - if (pscf->upstream_value == NULL) { - return NGX_CONF_ERROR; + if (pscf->upstream || pscf->upstream_value) { + return "is duplicate"; } - *pscf->upstream_value = cv; + cscf = ngx_stream_conf_get_module_srv_conf(cf, ngx_stream_core_module); + + cscf->handler = ngx_stream_proxy_handler; + + value = cf->args->elts; + + url = &value[1]; + + ngx_memzero(&ccv, sizeof(ngx_stream_compile_complex_value_t)); + + ccv.cf = cf; + ccv.value = url; + ccv.complex_value = &cv; + + if (ngx_stream_compile_complex_value(&ccv) != NGX_OK) { + return NGX_CONF_ERROR; + } + + if (cv.lengths) { + pscf->upstream_value = ngx_palloc(cf->pool, + sizeof(ngx_stream_complex_value_t)); + if (pscf->upstream_value == NULL) { + return NGX_CONF_ERROR; + } + + *pscf->upstream_value = cv; + + return NGX_CONF_OK; + } + + ngx_memzero(&u, sizeof(ngx_url_t)); + + u.url = *url; + u.no_resolve = 1; + + pscf->upstream = ngx_stream_upstream_add(cf, &u, 0); + if (pscf->upstream == NULL) { + return NGX_CONF_ERROR; + } return NGX_CONF_OK; - } - - ngx_memzero(&u, sizeof(ngx_url_t)); - - u.url = *url; - u.no_resolve = 1; - - pscf->upstream = ngx_stream_upstream_add(cf, &u, 0); - if (pscf->upstream == NULL) { - return NGX_CONF_ERROR; - } - - return NGX_CONF_OK; } -static char *ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, - void *conf) { - ngx_stream_proxy_srv_conf_t *pscf = conf; - ngx_int_t rc; - ngx_str_t *value; - ngx_stream_complex_value_t cv; - ngx_stream_upstream_local_t *local; - ngx_stream_compile_complex_value_t ccv; +static char * +ngx_stream_proxy_bind(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_stream_proxy_srv_conf_t *pscf = conf; - if (pscf->local != NGX_CONF_UNSET_PTR) { - return "is duplicate"; - } + ngx_int_t rc; + ngx_str_t *value; + ngx_stream_complex_value_t cv; + ngx_stream_upstream_local_t *local; + ngx_stream_compile_complex_value_t ccv; - value = cf->args->elts; - - if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "off") == 0) { - pscf->local = NULL; - return NGX_CONF_OK; - } - - ngx_memzero(&ccv, sizeof(ngx_stream_compile_complex_value_t)); - - ccv.cf = cf; - ccv.value = &value[1]; - ccv.complex_value = &cv; - - if (ngx_stream_compile_complex_value(&ccv) != NGX_OK) { - return NGX_CONF_ERROR; - } - - local = ngx_pcalloc(cf->pool, sizeof(ngx_stream_upstream_local_t)); - if (local == NULL) { - return NGX_CONF_ERROR; - } - - pscf->local = local; - - if (cv.lengths) { - local->value = ngx_palloc(cf->pool, sizeof(ngx_stream_complex_value_t)); - if (local->value == NULL) { - return NGX_CONF_ERROR; + if (pscf->local != NGX_CONF_UNSET_PTR) { + return "is duplicate"; } - *local->value = cv; + value = cf->args->elts; - } else { - local->addr = ngx_palloc(cf->pool, sizeof(ngx_addr_t)); - if (local->addr == NULL) { - return NGX_CONF_ERROR; + if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "off") == 0) { + pscf->local = NULL; + return NGX_CONF_OK; } - rc = - ngx_parse_addr_port(cf->pool, local->addr, value[1].data, value[1].len); + ngx_memzero(&ccv, sizeof(ngx_stream_compile_complex_value_t)); - switch (rc) { - case NGX_OK: - local->addr->name = value[1]; - break; + ccv.cf = cf; + ccv.value = &value[1]; + ccv.complex_value = &cv; - case NGX_DECLINED: - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid address \"%V\"", - &value[1]); - /* fall through */ - - default: - return NGX_CONF_ERROR; + if (ngx_stream_compile_complex_value(&ccv) != NGX_OK) { + return NGX_CONF_ERROR; } - } - if (cf->args->nelts > 2) { - if (ngx_strcmp(value[2].data, "transparent") == 0) { -#if (NGX_HAVE_TRANSPARENT_PROXY) - ngx_core_conf_t *ccf; + local = ngx_pcalloc(cf->pool, sizeof(ngx_stream_upstream_local_t)); + if (local == NULL) { + return NGX_CONF_ERROR; + } - ccf = - (ngx_core_conf_t *)ngx_get_conf(cf->cycle->conf_ctx, ngx_core_module); + pscf->local = local; + + if (cv.lengths) { + local->value = ngx_palloc(cf->pool, sizeof(ngx_stream_complex_value_t)); + if (local->value == NULL) { + return NGX_CONF_ERROR; + } + + *local->value = cv; - ccf->transparent = 1; - local->transparent = 1; -#else - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "transparent proxying is not supported " - "on this platform, ignored"); -#endif } else { - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%V\"", - &value[2]); - return NGX_CONF_ERROR; - } - } + local->addr = ngx_palloc(cf->pool, sizeof(ngx_addr_t)); + if (local->addr == NULL) { + return NGX_CONF_ERROR; + } - return NGX_CONF_OK; + rc = ngx_parse_addr_port(cf->pool, local->addr, value[1].data, + value[1].len); + + switch (rc) { + case NGX_OK: + local->addr->name = value[1]; + break; + + case NGX_DECLINED: + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid address \"%V\"", &value[1]); + /* fall through */ + + default: + return NGX_CONF_ERROR; + } + } + + if (cf->args->nelts > 2) { + if (ngx_strcmp(value[2].data, "transparent") == 0) { +#if (NGX_HAVE_TRANSPARENT_PROXY) + ngx_core_conf_t *ccf; + + ccf = (ngx_core_conf_t *) ngx_get_conf(cf->cycle->conf_ctx, + ngx_core_module); + + ccf->transparent = 1; + local->transparent = 1; +#else + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "transparent proxying is not supported " + "on this platform, ignored"); +#endif + } else { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid parameter \"%V\"", &value[2]); + return NGX_CONF_ERROR; + } + } + + return NGX_CONF_OK; } diff --git a/temp/logs/error.log b/temp/logs/error.log new file mode 100644 index 000000000..1acc37783 --- /dev/null +++ b/temp/logs/error.log @@ -0,0 +1,36 @@ +2026/01/30 12:50:19 [emerg] 25009#0: open() "temp/temp/nginx.conf" failed (2: No such file or directory) +2026/01/30 12:50:55 [emerg] 26393#0: unknown directive "stream" in temp/nginx.conf:9 +2026/01/30 13:12:51 [emerg] 35184#0: log format is not specified in temp/nginx.conf:24 +2026/01/30 13:14:12 [error] 35959#0: *1 broken header: "J" while reading PROXY protocol, client: 127.0.0.1, server: 0.0.0.0:9000 +2026/01/30 13:14:33 [error] 35959#0: *2 broken header: "hello" while reading PROXY protocol, client: 127.0.0.1, server: 0.0.0.0:9000 +2026/01/30 13:14:46 [error] 35959#0: *3 broken header: "" while reading PROXY protocol, client: 127.0.0.1, server: 0.0.0.0:9000 +2026/01/30 13:16:23 [error] 35959#0: *4 broken header: "j" while reading PROXY protocol, client: 127.0.0.1, server: 0.0.0.0:9000 +2026/01/30 13:18:56 [error] 39917#0: *1 broken header: "m" while reading PROXY protocol, client: 127.0.0.1, server: 0.0.0.0:9000 +2026/01/30 13:20:24 [notice] 41462#0: using the "epoll" event method +2026/01/30 13:20:24 [notice] 41462#0: nginx/1.29.5 +2026/01/30 13:20:24 [notice] 41462#0: built by gcc 15.2.1 20251112 (GCC) +2026/01/30 13:20:24 [notice] 41462#0: OS: Linux 6.18.2-2-cachyos +2026/01/30 13:20:24 [notice] 41462#0: getrlimit(RLIMIT_NOFILE): 2048:2097152 +2026/01/30 13:20:24 [notice] 41463#0: start worker processes +2026/01/30 13:20:24 [notice] 41463#0: start worker process 41464 +2026/01/30 13:21:44 [info] 41464#0: *1 client 127.0.0.1:58974 connected to 0.0.0.0:9000 +2026/01/30 13:21:44 [info] 41464#0: *1 proxy 127.0.0.1:56302 connected to 127.0.0.1:9999 +2026/01/30 13:22:13 [info] 41464#0: *1 client disconnected, bytes from/to client:0/0, bytes from/to upstream:0/43 +2026/01/30 13:24:44 [notice] 41464#0: signal 15 (SIGTERM) received from 43075, exiting +2026/01/30 13:24:44 [notice] 41463#0: signal 15 (SIGTERM) received from 43075, exiting +2026/01/30 13:24:44 [info] 41464#0: epoll_wait() failed (4: Interrupted system call) +2026/01/30 13:24:44 [notice] 41464#0: exiting +2026/01/30 13:24:44 [notice] 41464#0: exit +2026/01/30 13:24:44 [notice] 41463#0: signal 17 (SIGCHLD) received from 41464 +2026/01/30 13:24:44 [notice] 41463#0: worker process 41464 exited with code 0 +2026/01/30 13:24:44 [notice] 41463#0: exit +2026/01/30 13:24:51 [notice] 43218#0: using the "epoll" event method +2026/01/30 13:24:51 [notice] 43218#0: nginx/1.29.5 +2026/01/30 13:24:51 [notice] 43218#0: built by gcc 15.2.1 20251112 (GCC) +2026/01/30 13:24:51 [notice] 43218#0: OS: Linux 6.18.2-2-cachyos +2026/01/30 13:24:51 [notice] 43218#0: getrlimit(RLIMIT_NOFILE): 2048:2097152 +2026/01/30 13:24:51 [notice] 43219#0: start worker processes +2026/01/30 13:24:51 [notice] 43219#0: start worker process 43220 +2026/01/30 13:25:10 [info] 43220#0: *1 client 127.0.0.1:41902 connected to 0.0.0.0:9000 +2026/01/30 13:25:10 [info] 43220#0: *1 proxy 127.0.0.1:59436 connected to 127.0.0.1:9999 +2026/01/30 13:26:17 [info] 43220#0: *1 client disconnected, bytes from/to client:35/26, bytes from/to upstream:26/63 diff --git a/temp/logs/nginx.pid b/temp/logs/nginx.pid new file mode 100644 index 000000000..c1ed2dc39 --- /dev/null +++ b/temp/logs/nginx.pid @@ -0,0 +1 @@ +43219 diff --git a/temp/nginx.conf b/temp/nginx.conf new file mode 100644 index 000000000..165921380 --- /dev/null +++ b/temp/nginx.conf @@ -0,0 +1,22 @@ +worker_processes 1; + +error_log logs/error.log debug; +pid logs/nginx.pid; + +events { + worker_connections 1024; +} + +stream { + server { + # NORMAL listener (no proxy_protocol) + listen 9000; + + # Tell Nginx to SEND PROXYv2 to the upstream: + proxy_protocol on; + proxy_protocol_version 2; + + proxy_pass 127.0.0.1:9999; + } +} + From 6d9c24d29156a87d1d0bd7bcfa59666e15732f13 Mon Sep 17 00:00:00 2001 From: mdewitt11 <129132141+mdewitt11@users.noreply.github.com> Date: Fri, 30 Jan 2026 14:57:48 -0600 Subject: [PATCH 5/5] Delete temp directory --- temp/logs/error.log | 36 ------------------------------------ temp/logs/nginx.pid | 1 - temp/nginx.conf | 22 ---------------------- 3 files changed, 59 deletions(-) delete mode 100644 temp/logs/error.log delete mode 100644 temp/logs/nginx.pid delete mode 100644 temp/nginx.conf diff --git a/temp/logs/error.log b/temp/logs/error.log deleted file mode 100644 index 1acc37783..000000000 --- a/temp/logs/error.log +++ /dev/null @@ -1,36 +0,0 @@ -2026/01/30 12:50:19 [emerg] 25009#0: open() "temp/temp/nginx.conf" failed (2: No such file or directory) -2026/01/30 12:50:55 [emerg] 26393#0: unknown directive "stream" in temp/nginx.conf:9 -2026/01/30 13:12:51 [emerg] 35184#0: log format is not specified in temp/nginx.conf:24 -2026/01/30 13:14:12 [error] 35959#0: *1 broken header: "J" while reading PROXY protocol, client: 127.0.0.1, server: 0.0.0.0:9000 -2026/01/30 13:14:33 [error] 35959#0: *2 broken header: "hello" while reading PROXY protocol, client: 127.0.0.1, server: 0.0.0.0:9000 -2026/01/30 13:14:46 [error] 35959#0: *3 broken header: "" while reading PROXY protocol, client: 127.0.0.1, server: 0.0.0.0:9000 -2026/01/30 13:16:23 [error] 35959#0: *4 broken header: "j" while reading PROXY protocol, client: 127.0.0.1, server: 0.0.0.0:9000 -2026/01/30 13:18:56 [error] 39917#0: *1 broken header: "m" while reading PROXY protocol, client: 127.0.0.1, server: 0.0.0.0:9000 -2026/01/30 13:20:24 [notice] 41462#0: using the "epoll" event method -2026/01/30 13:20:24 [notice] 41462#0: nginx/1.29.5 -2026/01/30 13:20:24 [notice] 41462#0: built by gcc 15.2.1 20251112 (GCC) -2026/01/30 13:20:24 [notice] 41462#0: OS: Linux 6.18.2-2-cachyos -2026/01/30 13:20:24 [notice] 41462#0: getrlimit(RLIMIT_NOFILE): 2048:2097152 -2026/01/30 13:20:24 [notice] 41463#0: start worker processes -2026/01/30 13:20:24 [notice] 41463#0: start worker process 41464 -2026/01/30 13:21:44 [info] 41464#0: *1 client 127.0.0.1:58974 connected to 0.0.0.0:9000 -2026/01/30 13:21:44 [info] 41464#0: *1 proxy 127.0.0.1:56302 connected to 127.0.0.1:9999 -2026/01/30 13:22:13 [info] 41464#0: *1 client disconnected, bytes from/to client:0/0, bytes from/to upstream:0/43 -2026/01/30 13:24:44 [notice] 41464#0: signal 15 (SIGTERM) received from 43075, exiting -2026/01/30 13:24:44 [notice] 41463#0: signal 15 (SIGTERM) received from 43075, exiting -2026/01/30 13:24:44 [info] 41464#0: epoll_wait() failed (4: Interrupted system call) -2026/01/30 13:24:44 [notice] 41464#0: exiting -2026/01/30 13:24:44 [notice] 41464#0: exit -2026/01/30 13:24:44 [notice] 41463#0: signal 17 (SIGCHLD) received from 41464 -2026/01/30 13:24:44 [notice] 41463#0: worker process 41464 exited with code 0 -2026/01/30 13:24:44 [notice] 41463#0: exit -2026/01/30 13:24:51 [notice] 43218#0: using the "epoll" event method -2026/01/30 13:24:51 [notice] 43218#0: nginx/1.29.5 -2026/01/30 13:24:51 [notice] 43218#0: built by gcc 15.2.1 20251112 (GCC) -2026/01/30 13:24:51 [notice] 43218#0: OS: Linux 6.18.2-2-cachyos -2026/01/30 13:24:51 [notice] 43218#0: getrlimit(RLIMIT_NOFILE): 2048:2097152 -2026/01/30 13:24:51 [notice] 43219#0: start worker processes -2026/01/30 13:24:51 [notice] 43219#0: start worker process 43220 -2026/01/30 13:25:10 [info] 43220#0: *1 client 127.0.0.1:41902 connected to 0.0.0.0:9000 -2026/01/30 13:25:10 [info] 43220#0: *1 proxy 127.0.0.1:59436 connected to 127.0.0.1:9999 -2026/01/30 13:26:17 [info] 43220#0: *1 client disconnected, bytes from/to client:35/26, bytes from/to upstream:26/63 diff --git a/temp/logs/nginx.pid b/temp/logs/nginx.pid deleted file mode 100644 index c1ed2dc39..000000000 --- a/temp/logs/nginx.pid +++ /dev/null @@ -1 +0,0 @@ -43219 diff --git a/temp/nginx.conf b/temp/nginx.conf deleted file mode 100644 index 165921380..000000000 --- a/temp/nginx.conf +++ /dev/null @@ -1,22 +0,0 @@ -worker_processes 1; - -error_log logs/error.log debug; -pid logs/nginx.pid; - -events { - worker_connections 1024; -} - -stream { - server { - # NORMAL listener (no proxy_protocol) - listen 9000; - - # Tell Nginx to SEND PROXYv2 to the upstream: - proxy_protocol on; - proxy_protocol_version 2; - - proxy_pass 127.0.0.1:9999; - } -} -