comparison src/stream/ngx_stream_proxy_module.c @ 7393:4698cede59ff

Stream: proxy_requests directive. The directive allows to drop binding between a client and existing UDP stream session after receiving a specified number of packets. First packet from the same client address and port will start a new session. Old session continues to exist and will terminate at moment defined by configuration: either after receiving the expected number of responses, or after timeout, as specified by the "proxy_responses" and/or "proxy_timeout" directives. By default, proxy_requests is zero (disabled).
author Vladimir Homutov <vl@nginx.com>
date Mon, 12 Nov 2018 16:29:30 +0300
parents 04ff25798002
children 860d3907da1c
comparison
equal deleted inserted replaced
7392:04ff25798002 7393:4698cede59ff
24 ngx_msec_t timeout; 24 ngx_msec_t timeout;
25 ngx_msec_t next_upstream_timeout; 25 ngx_msec_t next_upstream_timeout;
26 size_t buffer_size; 26 size_t buffer_size;
27 size_t upload_rate; 27 size_t upload_rate;
28 size_t download_rate; 28 size_t download_rate;
29 ngx_uint_t requests;
29 ngx_uint_t responses; 30 ngx_uint_t responses;
30 ngx_uint_t next_upstream_tries; 31 ngx_uint_t next_upstream_tries;
31 ngx_flag_t next_upstream; 32 ngx_flag_t next_upstream;
32 ngx_flag_t proxy_protocol; 33 ngx_flag_t proxy_protocol;
33 ngx_stream_upstream_local_t *local; 34 ngx_stream_upstream_local_t *local;
193 ngx_conf_set_size_slot, 194 ngx_conf_set_size_slot,
194 NGX_STREAM_SRV_CONF_OFFSET, 195 NGX_STREAM_SRV_CONF_OFFSET,
195 offsetof(ngx_stream_proxy_srv_conf_t, download_rate), 196 offsetof(ngx_stream_proxy_srv_conf_t, download_rate),
196 NULL }, 197 NULL },
197 198
199 { ngx_string("proxy_requests"),
200 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
201 ngx_conf_set_num_slot,
202 NGX_STREAM_SRV_CONF_OFFSET,
203 offsetof(ngx_stream_proxy_srv_conf_t, requests),
204 NULL },
205
198 { ngx_string("proxy_responses"), 206 { ngx_string("proxy_responses"),
199 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, 207 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
200 ngx_conf_set_num_slot, 208 ngx_conf_set_num_slot,
201 NGX_STREAM_SRV_CONF_OFFSET, 209 NGX_STREAM_SRV_CONF_OFFSET,
202 offsetof(ngx_stream_proxy_srv_conf_t, responses), 210 offsetof(ngx_stream_proxy_srv_conf_t, responses),
1339 return; 1347 return;
1340 } 1348 }
1341 1349
1342 } else { 1350 } else {
1343 if (s->connection->type == SOCK_DGRAM) { 1351 if (s->connection->type == SOCK_DGRAM) {
1344 if (pscf->responses == NGX_MAX_INT32_VALUE) { 1352
1353 if (pscf->responses == NGX_MAX_INT32_VALUE
1354 || (u->responses >= pscf->responses * u->requests))
1355 {
1345 1356
1346 /* 1357 /*
1347 * successfully terminate timed out UDP session 1358 * successfully terminate timed out UDP session
1348 * with unspecified number of responses 1359 * if expected number of responses was received
1349 */ 1360 */
1350 1361
1351 handler = c->log->handler; 1362 handler = c->log->handler;
1352 c->log->handler = NULL; 1363 c->log->handler = NULL;
1353 1364
1689 c = s->connection; 1700 c = s->connection;
1690 u = s->upstream; 1701 u = s->upstream;
1691 pc = u->connected ? u->peer.connection : NULL; 1702 pc = u->connected ? u->peer.connection : NULL;
1692 1703
1693 if (c->type == SOCK_DGRAM) { 1704 if (c->type == SOCK_DGRAM) {
1705
1706 if (pscf->requests && u->requests < pscf->requests) {
1707 return NGX_DECLINED;
1708 }
1709
1710 if (pscf->requests) {
1711 ngx_delete_udp_connection(c);
1712 }
1694 1713
1695 if (pscf->responses == NGX_MAX_INT32_VALUE 1714 if (pscf->responses == NGX_MAX_INT32_VALUE
1696 || u->responses < pscf->responses * u->requests) 1715 || u->responses < pscf->responses * u->requests)
1697 { 1716 {
1698 return NGX_DECLINED; 1717 return NGX_DECLINED;
1941 conf->timeout = NGX_CONF_UNSET_MSEC; 1960 conf->timeout = NGX_CONF_UNSET_MSEC;
1942 conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC; 1961 conf->next_upstream_timeout = NGX_CONF_UNSET_MSEC;
1943 conf->buffer_size = NGX_CONF_UNSET_SIZE; 1962 conf->buffer_size = NGX_CONF_UNSET_SIZE;
1944 conf->upload_rate = NGX_CONF_UNSET_SIZE; 1963 conf->upload_rate = NGX_CONF_UNSET_SIZE;
1945 conf->download_rate = NGX_CONF_UNSET_SIZE; 1964 conf->download_rate = NGX_CONF_UNSET_SIZE;
1965 conf->requests = NGX_CONF_UNSET_UINT;
1946 conf->responses = NGX_CONF_UNSET_UINT; 1966 conf->responses = NGX_CONF_UNSET_UINT;
1947 conf->next_upstream_tries = NGX_CONF_UNSET_UINT; 1967 conf->next_upstream_tries = NGX_CONF_UNSET_UINT;
1948 conf->next_upstream = NGX_CONF_UNSET; 1968 conf->next_upstream = NGX_CONF_UNSET;
1949 conf->proxy_protocol = NGX_CONF_UNSET; 1969 conf->proxy_protocol = NGX_CONF_UNSET;
1950 conf->local = NGX_CONF_UNSET_PTR; 1970 conf->local = NGX_CONF_UNSET_PTR;
1984 ngx_conf_merge_size_value(conf->upload_rate, 2004 ngx_conf_merge_size_value(conf->upload_rate,
1985 prev->upload_rate, 0); 2005 prev->upload_rate, 0);
1986 2006
1987 ngx_conf_merge_size_value(conf->download_rate, 2007 ngx_conf_merge_size_value(conf->download_rate,
1988 prev->download_rate, 0); 2008 prev->download_rate, 0);
2009
2010 ngx_conf_merge_uint_value(conf->requests,
2011 prev->requests, 0);
1989 2012
1990 ngx_conf_merge_uint_value(conf->responses, 2013 ngx_conf_merge_uint_value(conf->responses,
1991 prev->responses, NGX_MAX_INT32_VALUE); 2014 prev->responses, NGX_MAX_INT32_VALUE);
1992 2015
1993 ngx_conf_merge_uint_value(conf->next_upstream_tries, 2016 ngx_conf_merge_uint_value(conf->next_upstream_tries,