1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| static char * ngx_http_geo_range(ngx_conf_t *cf, ngx_http_geo_conf_ctx_t *ctx, ngx_str_t *value) { u_char *p, *last; in_addr_t start, end; ngx_str_t *net; ngx_uint_t del;
if (ngx_strcmp(value[0].data, "default") == 0) {
if (ctx->high.default_value) { ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "duplicate default geo range value: \"%V\", old value: \"%v\"", &value[1], ctx->high.default_value); }
ctx->high.default_value = ngx_http_geo_value(cf, ctx, &value[1]); if (ctx->high.default_value == NULL) { return NGX_CONF_ERROR; }
return NGX_CONF_OK; }
if (ctx->binary_include) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "binary geo range base \"%s\" cannot be mixed with usual entries", ctx->include_name.data); return NGX_CONF_ERROR; }
if (ctx->high.low == NULL) { ctx->high.low = ngx_pcalloc(ctx->pool, 0x10000 * sizeof(ngx_http_geo_range_t *)); if (ctx->high.low == NULL) { return NGX_CONF_ERROR; } }
ctx->entries++; ctx->outside_entries = 1;
if (ngx_strcmp(value[0].data, "delete") == 0) { net = &value[1]; del = 1;
} else { net = &value[0]; del = 0; }
last = net->data + net->len;
p = ngx_strlchr(net->data, last, '-');
if (p == NULL) { goto invalid; }
start = ngx_inet_addr(net->data, p - net->data);
if (start == INADDR_NONE) { goto invalid; }
start = ntohl(start);
p++;
end = ngx_inet_addr(p, last - p);
if (end == INADDR_NONE) { goto invalid; }
end = ntohl(end);
if (start > end) { goto invalid; }
if (del) { if (ngx_http_geo_delete_range(cf, ctx, start, end)) { ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "no address range \"%V\" to delete", net); }
return NGX_CONF_OK; }
ctx->value = ngx_http_geo_value(cf, ctx, &value[1]);
if (ctx->value == NULL) { return NGX_CONF_ERROR; }
ctx->net = net;
return ngx_http_geo_add_range(cf, ctx, start, end);
invalid:
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid range \"%V\"", net);
return NGX_CONF_ERROR; }
|