Merge of r4968, r4969, r4977, r4980, r4981, r4990: geo fixes.
*) Geo: improved ngx_http_geo_block() code readability. *) Geo: fixed the "ranges" without ranges case. The following configuration returned an empty value for $geo: geo $geo { ranges; default default; } *) Fixed return type of internal function that allocates radix tree nodes. *) There's no need to normalize address returned by ngx_ptocidr(). *) Geo: ensure that default entry is always present. If 0.0.0.0/32 entry was present and there was no explicit "default", we failed to add an empty string as a default value. *) Trailing whitespace fix.
This commit is contained in:
parent
f2d783ed9e
commit
a618295c0e
|
@ -9,7 +9,7 @@
|
|||
#include <ngx_core.h>
|
||||
|
||||
|
||||
static void *ngx_radix_alloc(ngx_radix_tree_t *tree);
|
||||
static ngx_radix_node_t *ngx_radix_alloc(ngx_radix_tree_t *tree);
|
||||
|
||||
|
||||
ngx_radix_tree_t *
|
||||
|
@ -263,13 +263,13 @@ ngx_radix32tree_find(ngx_radix_tree_t *tree, uint32_t key)
|
|||
}
|
||||
|
||||
|
||||
static void *
|
||||
static ngx_radix_node_t *
|
||||
ngx_radix_alloc(ngx_radix_tree_t *tree)
|
||||
{
|
||||
char *p;
|
||||
ngx_radix_node_t *p;
|
||||
|
||||
if (tree->free) {
|
||||
p = (char *) tree->free;
|
||||
p = tree->free;
|
||||
tree->free = tree->free->right;
|
||||
return p;
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ ngx_radix_alloc(ngx_radix_tree_t *tree)
|
|||
tree->size = ngx_pagesize;
|
||||
}
|
||||
|
||||
p = tree->start;
|
||||
p = (ngx_radix_node_t *) tree->start;
|
||||
tree->start += sizeof(ngx_radix_node_t);
|
||||
tree->size -= sizeof(ngx_radix_node_t);
|
||||
|
||||
|
|
|
@ -189,19 +189,22 @@ ngx_http_geo_range_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
|||
|
||||
*v = *ctx->u.high.default_value;
|
||||
|
||||
addr = ngx_http_geo_addr(r, ctx);
|
||||
if (ctx->u.high.low) {
|
||||
addr = ngx_http_geo_addr(r, ctx);
|
||||
|
||||
range = ctx->u.high.low[addr >> 16];
|
||||
range = ctx->u.high.low[addr >> 16];
|
||||
|
||||
if (range) {
|
||||
n = addr & 0xffff;
|
||||
do {
|
||||
if (n >= (ngx_uint_t) range->start && n <= (ngx_uint_t) range->end)
|
||||
{
|
||||
*v = *range->value;
|
||||
break;
|
||||
}
|
||||
} while ((++range)->value);
|
||||
if (range) {
|
||||
n = addr & 0xffff;
|
||||
do {
|
||||
if (n >= (ngx_uint_t) range->start
|
||||
&& n <= (ngx_uint_t) range->end)
|
||||
{
|
||||
*v = *range->value;
|
||||
break;
|
||||
}
|
||||
} while ((++range)->value);
|
||||
}
|
||||
}
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
|
@ -303,7 +306,6 @@ static char *
|
|||
ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
||||
{
|
||||
char *rv;
|
||||
void **p;
|
||||
size_t len;
|
||||
ngx_str_t *value, name;
|
||||
ngx_uint_t i;
|
||||
|
@ -392,9 +394,9 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||
geo->proxies = ctx.proxies;
|
||||
geo->proxy_recursive = ctx.proxy_recursive;
|
||||
|
||||
if (ctx.high.low) {
|
||||
if (ctx.ranges) {
|
||||
|
||||
if (!ctx.binary_include) {
|
||||
if (ctx.high.low && !ctx.binary_include) {
|
||||
for (i = 0; i < 0x10000; i++) {
|
||||
a = (ngx_array_t *) ctx.high.low[i];
|
||||
|
||||
|
@ -409,8 +411,8 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
p = (void **) ngx_cpymem(ctx.high.low[i], a->elts, len);
|
||||
*p = NULL;
|
||||
ngx_memcpy(ctx.high.low[i], a->elts, len);
|
||||
ctx.high.low[i][a->nelts].value = NULL;
|
||||
ctx.data_size += len + sizeof(void *);
|
||||
}
|
||||
|
||||
|
@ -451,16 +453,14 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||
ngx_destroy_pool(ctx.temp_pool);
|
||||
ngx_destroy_pool(pool);
|
||||
|
||||
if (ngx_radix32tree_find(ctx.tree, 0) != NGX_RADIX_NO_VALUE) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (ngx_radix32tree_insert(ctx.tree, 0, 0,
|
||||
(uintptr_t) &ngx_http_variable_null_value)
|
||||
== NGX_ERROR)
|
||||
{
|
||||
return NGX_CONF_ERROR;
|
||||
}
|
||||
|
||||
/* NGX_BUSY is okay (default was set explicitly) */
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
@ -996,7 +996,7 @@ ngx_http_geo_cidr(ngx_conf_t *cf, ngx_http_geo_conf_ctx_t *ctx,
|
|||
/* rc == NGX_BUSY */
|
||||
|
||||
old = (ngx_http_variable_value_t *)
|
||||
ngx_radix32tree_find(ctx->tree, cidr.u.in.addr & cidr.u.in.mask);
|
||||
ngx_radix32tree_find(ctx->tree, cidr.u.in.addr);
|
||||
|
||||
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
||||
"duplicate network \"%V\", value: \"%v\", old value: \"%v\"",
|
||||
|
|
Loading…
Reference in New Issue