|
| 1 | +diff -u -r -p -Naur nginx-1.25.3/src/stream/ngx_stream.h nginx-1.25.3-patched/src/stream/ngx_stream.h |
| 2 | +--- nginx-1.25.3/src/stream/ngx_stream.h 2021-11-04 21:27:55.288708527 +0800 |
| 3 | ++++ nginx-1.25.3-patched/src/stream/ngx_stream.h 2021-11-04 21:28:50.768035209 +0800 |
| 4 | +@@ -254,6 +254,15 @@ typedef struct { |
| 5 | + } ngx_stream_module_t; |
| 6 | + |
| 7 | + |
| 8 | ++typedef struct { |
| 9 | ++ ngx_msec_t connect_timeout; |
| 10 | ++ ngx_msec_t timeout; |
| 11 | ++} ngx_stream_proxy_ctx_t; |
| 12 | ++ |
| 13 | ++ |
| 14 | ++#define NGX_STREAM_HAVE_PROXY_TIMEOUT_FIELDS_PATCH 1 |
| 15 | ++ |
| 16 | ++ |
| 17 | + #define NGX_STREAM_MODULE 0x4d525453 /* "STRM" */ |
| 18 | + |
| 19 | + #define NGX_STREAM_MAIN_CONF 0x02000000 |
| 20 | +@@ -307,6 +316,7 @@ void ngx_stream_finalize_session(ngx_str |
| 21 | + extern ngx_module_t ngx_stream_module; |
| 22 | + extern ngx_uint_t ngx_stream_max_module; |
| 23 | + extern ngx_module_t ngx_stream_core_module; |
| 24 | ++extern ngx_module_t ngx_stream_proxy_module; |
| 25 | + |
| 26 | + |
| 27 | + typedef ngx_int_t (*ngx_stream_filter_pt)(ngx_stream_session_t *s, |
| 28 | +diff -u -r -p -Naur nginx-1.25.3/src/stream/ngx_stream_proxy_module.c nginx-1.25.3-patched/src/stream/ngx_stream_proxy_module.c |
| 29 | +--- nginx-1.25.3/src/stream/ngx_stream_proxy_module.c 2021-11-04 21:27:55.289708533 +0800 |
| 30 | ++++ nginx-1.25.3-patched/src/stream/ngx_stream_proxy_module.c 2021-11-04 21:37:03.578936990 +0800 |
| 31 | +@@ -400,6 +400,7 @@ ngx_stream_proxy_handler(ngx_stream_sess |
| 32 | + ngx_stream_proxy_srv_conf_t *pscf; |
| 33 | + ngx_stream_upstream_srv_conf_t *uscf, **uscfp; |
| 34 | + ngx_stream_upstream_main_conf_t *umcf; |
| 35 | ++ ngx_stream_proxy_ctx_t *pctx; |
| 36 | + |
| 37 | + c = s->connection; |
| 38 | + |
| 39 | +@@ -408,6 +409,17 @@ ngx_stream_proxy_handler(ngx_stream_sess |
| 40 | + ngx_log_debug0(NGX_LOG_DEBUG_STREAM, c->log, 0, |
| 41 | + "proxy connection handler"); |
| 42 | + |
| 43 | ++ pctx = ngx_palloc(c->pool, sizeof(ngx_stream_proxy_ctx_t)); |
| 44 | ++ if (pctx == NULL) { |
| 45 | ++ ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); |
| 46 | ++ return; |
| 47 | ++ } |
| 48 | ++ |
| 49 | ++ pctx->connect_timeout = pscf->connect_timeout; |
| 50 | ++ pctx->timeout = pscf->timeout; |
| 51 | ++ |
| 52 | ++ ngx_stream_set_ctx(s, pctx, ngx_stream_proxy_module); |
| 53 | ++ |
| 54 | + u = ngx_pcalloc(c->pool, sizeof(ngx_stream_upstream_t)); |
| 55 | + if (u == NULL) { |
| 56 | + ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); |
| 57 | +@@ -699,6 +711,7 @@ ngx_stream_proxy_connect(ngx_stream_sess |
| 58 | + ngx_connection_t *c, *pc; |
| 59 | + ngx_stream_upstream_t *u; |
| 60 | + ngx_stream_proxy_srv_conf_t *pscf; |
| 61 | ++ ngx_stream_proxy_ctx_t *ctx; |
| 62 | + |
| 63 | + c = s->connection; |
| 64 | + |
| 65 | +@@ -706,6 +719,8 @@ ngx_stream_proxy_connect(ngx_stream_sess |
| 66 | + |
| 67 | + pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); |
| 68 | + |
| 69 | ++ ctx = ngx_stream_get_module_ctx(s, ngx_stream_proxy_module); |
| 70 | ++ |
| 71 | + u = s->upstream; |
| 72 | + |
| 73 | + u->connected = 0; |
| 74 | +@@ -774,7 +789,7 @@ ngx_stream_proxy_connect(ngx_stream_sess |
| 75 | + pc->read->handler = ngx_stream_proxy_connect_handler; |
| 76 | + pc->write->handler = ngx_stream_proxy_connect_handler; |
| 77 | + |
| 78 | +- ngx_add_timer(pc->write, pscf->connect_timeout); |
| 79 | ++ ngx_add_timer(pc->write, ctx->connect_timeout); |
| 80 | + } |
| 81 | + |
| 82 | + |
| 83 | +@@ -957,12 +957,14 @@ ngx_stream_proxy_init_upstream(ngx_stream_session_t *s) |
| 84 | + static ngx_int_t |
| 85 | + ngx_stream_proxy_send_proxy_protocol(ngx_stream_session_t *s) |
| 86 | + { |
| 87 | +- u_char *p; |
| 88 | +- ssize_t n, size; |
| 89 | +- ngx_connection_t *c, *pc; |
| 90 | +- ngx_stream_upstream_t *u; |
| 91 | +- ngx_stream_proxy_srv_conf_t *pscf; |
| 92 | +- u_char buf[NGX_PROXY_PROTOCOL_V1_MAX_HEADER]; |
| 93 | ++ u_char *p; |
| 94 | ++ u_char buf[NGX_PROXY_PROTOCOL_V1_MAX_HEADER]; |
| 95 | ++ ssize_t n, size; |
| 96 | ++ ngx_connection_t *c, *pc; |
| 97 | ++ ngx_stream_upstream_t *u; |
| 98 | ++ ngx_stream_proxy_ctx_t *ctx; |
| 99 | ++ |
| 100 | ++ ctx = ngx_stream_get_module_ctx(s, ngx_stream_proxy_module); |
| 101 | + |
| 102 | + c = s->connection; |
| 103 | + |
| 104 | +@@ -976,9 +993,7 @@ ngx_stream_proxy_send_proxy_protocol(ngx |
| 105 | + return NGX_ERROR; |
| 106 | + } |
| 107 | + |
| 108 | +- pscf = ngx_stream_get_module_srv_conf(s, ngx_stream_proxy_module); |
| 109 | +- |
| 110 | +- ngx_add_timer(pc->write, pscf->timeout); |
| 111 | ++ ngx_add_timer(pc->write, ctx->timeout); |
| 112 | + |
| 113 | + pc->write->handler = ngx_stream_proxy_connect_handler; |
| 114 | + |
| 115 | +@@ -1053,6 +1068,9 @@ ngx_stream_proxy_ssl_init_connection(ngx |
| 116 | + ngx_connection_t *pc; |
| 117 | + ngx_stream_upstream_t *u; |
| 118 | + ngx_stream_proxy_srv_conf_t *pscf; |
| 119 | ++ ngx_stream_proxy_ctx_t *ctx; |
| 120 | ++ |
| 121 | ++ ctx = ngx_stream_get_module_ctx(s, ngx_stream_proxy_module); |
| 122 | + |
| 123 | + u = s->upstream; |
| 124 | + |
| 125 | +@@ -1099,7 +1117,7 @@ ngx_stream_proxy_ssl_init_connection(ngx |
| 126 | + if (rc == NGX_AGAIN) { |
| 127 | + |
| 128 | + if (!pc->write->timer_set) { |
| 129 | +- ngx_add_timer(pc->write, pscf->connect_timeout); |
| 130 | ++ ngx_add_timer(pc->write, ctx->connect_timeout); |
| 131 | + } |
| 132 | + |
| 133 | + pc->ssl->handler = ngx_stream_proxy_ssl_handshake; |
| 134 | +@@ -1408,6 +1426,7 @@ ngx_stream_proxy_process_connection(ngx_ |
| 135 | + ngx_stream_session_t *s; |
| 136 | + ngx_stream_upstream_t *u; |
| 137 | + ngx_stream_proxy_srv_conf_t *pscf; |
| 138 | ++ ngx_stream_proxy_ctx_t *ctx; |
| 139 | + |
| 140 | + c = ev->data; |
| 141 | + s = c->data; |
| 142 | +@@ -1419,6 +1438,8 @@ ngx_stream_proxy_process_connection(ngx_ |
| 143 | + return; |
| 144 | + } |
| 145 | + |
| 146 | ++ ctx = ngx_stream_get_module_ctx(s, ngx_stream_proxy_module); |
| 147 | ++ |
| 148 | + c = s->connection; |
| 149 | + pc = u->peer.connection; |
| 150 | + |
| 151 | +@@ -1438,7 +1459,7 @@ ngx_stream_proxy_process_connection(ngx_ |
| 152 | + } |
| 153 | + |
| 154 | + if (u->connected && !c->read->delayed && !pc->read->delayed) { |
| 155 | +- ngx_add_timer(c->write, pscf->timeout); |
| 156 | ++ ngx_add_timer(c->write, ctx->timeout); |
| 157 | + } |
| 158 | + |
| 159 | + return; |
| 160 | +@@ -1600,6 +1621,9 @@ ngx_stream_proxy_process(ngx_stream_sess |
| 161 | + ngx_log_handler_pt handler; |
| 162 | + ngx_stream_upstream_t *u; |
| 163 | + ngx_stream_proxy_srv_conf_t *pscf; |
| 164 | ++ ngx_stream_proxy_ctx_t *ctx; |
| 165 | ++ |
| 166 | ++ ctx = ngx_stream_get_module_ctx(s, ngx_stream_proxy_module); |
| 167 | + |
| 168 | + u = s->upstream; |
| 169 | + |
| 170 | +@@ -1807,7 +1831,7 @@ ngx_stream_proxy_process(ngx_stream_sess |
| 171 | + } |
| 172 | + |
| 173 | + if (!c->read->delayed && !pc->read->delayed) { |
| 174 | +- ngx_add_timer(c->write, pscf->timeout); |
| 175 | ++ ngx_add_timer(c->write, ctx->timeout); |
| 176 | + |
| 177 | + } else if (c->write->timer_set) { |
| 178 | + ngx_del_timer(c->write); |
0 commit comments