diff options
author | Roman Arutyunyan <arut@nginx.com> | 2019-11-19 11:30:41 +0300 |
---|---|---|
committer | Roman Arutyunyan <arut@nginx.com> | 2019-11-19 11:30:41 +0300 |
commit | b48c8718bf9b135368c8c9eb969db5dce6e0ed35 (patch) | |
tree | 4766a2d6bf354b40e09cf1e29da2e8383727ebf7 /src/stream/ngx_stream_limit_conn_module.c | |
parent | 271b12c71172b77ba6db6f5c8ab8ee67f0918fa3 (diff) | |
download | nginx-b48c8718bf9b135368c8c9eb969db5dce6e0ed35.tar.gz nginx-b48c8718bf9b135368c8c9eb969db5dce6e0ed35.zip |
Limit conn: limit_conn_dry_run directive.
A new directive limit_conn_dry_run allows enabling the dry run mode. In this
mode connections are not rejected, but reject status is logged as usual.
Diffstat (limited to 'src/stream/ngx_stream_limit_conn_module.c')
-rw-r--r-- | src/stream/ngx_stream_limit_conn_module.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/stream/ngx_stream_limit_conn_module.c b/src/stream/ngx_stream_limit_conn_module.c index b64a426c6..ebeaecf3e 100644 --- a/src/stream/ngx_stream_limit_conn_module.c +++ b/src/stream/ngx_stream_limit_conn_module.c @@ -39,6 +39,7 @@ typedef struct { typedef struct { ngx_array_t limits; ngx_uint_t log_level; + ngx_flag_t dry_run; } ngx_stream_limit_conn_conf_t; @@ -89,6 +90,13 @@ static ngx_command_t ngx_stream_limit_conn_commands[] = { offsetof(ngx_stream_limit_conn_conf_t, log_level), &ngx_stream_limit_conn_log_levels }, + { ngx_string("limit_conn_dry_run"), + NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_STREAM_SRV_CONF_OFFSET, + offsetof(ngx_stream_limit_conn_conf_t, dry_run), + NULL }, + ngx_null_command }; @@ -178,6 +186,11 @@ ngx_stream_limit_conn_handler(ngx_stream_session_t *s) if (node == NULL) { ngx_shmtx_unlock(&shpool->mutex); ngx_stream_limit_conn_cleanup_all(s->connection->pool); + + if (lccf->dry_run) { + return NGX_DECLINED; + } + return NGX_STREAM_SERVICE_UNAVAILABLE; } @@ -199,10 +212,16 @@ ngx_stream_limit_conn_handler(ngx_stream_session_t *s) ngx_shmtx_unlock(&shpool->mutex); ngx_log_error(lccf->log_level, s->connection->log, 0, - "limiting connections by zone \"%V\"", + "limiting connections%s by zone \"%V\"", + lccf->dry_run ? ", dry run," : "", &limits[i].shm_zone->shm.name); ngx_stream_limit_conn_cleanup_all(s->connection->pool); + + if (lccf->dry_run) { + return NGX_DECLINED; + } + return NGX_STREAM_SERVICE_UNAVAILABLE; } @@ -444,6 +463,7 @@ ngx_stream_limit_conn_create_conf(ngx_conf_t *cf) */ conf->log_level = NGX_CONF_UNSET_UINT; + conf->dry_run = NGX_CONF_UNSET; return conf; } @@ -461,6 +481,8 @@ ngx_stream_limit_conn_merge_conf(ngx_conf_t *cf, void *parent, void *child) ngx_conf_merge_uint_value(conf->log_level, prev->log_level, NGX_LOG_ERR); + ngx_conf_merge_value(conf->dry_run, prev->dry_run, 0); + return NGX_CONF_OK; } |