mirror of
https://github.com/nginx/nginx.git
synced 2024-12-03 04:39:00 +08:00
When "debug_connection" is configured with a domain name, only the first
resolved address was used. Now all addresses will be used.
This commit is contained in:
parent
a6c9e09476
commit
cfe194ef59
@ -1064,48 +1064,89 @@ ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|||||||
|
|
||||||
ngx_int_t rc;
|
ngx_int_t rc;
|
||||||
ngx_str_t *value;
|
ngx_str_t *value;
|
||||||
struct hostent *h;
|
ngx_url_t u;
|
||||||
ngx_cidr_t *cidr;
|
ngx_cidr_t c, *cidr;
|
||||||
|
ngx_uint_t i;
|
||||||
|
struct sockaddr_in *sin;
|
||||||
|
#if (NGX_HAVE_INET6)
|
||||||
|
struct sockaddr_in6 *sin6;
|
||||||
|
#endif
|
||||||
|
|
||||||
value = cf->args->elts;
|
value = cf->args->elts;
|
||||||
|
|
||||||
|
#if (NGX_HAVE_UNIX_DOMAIN)
|
||||||
|
|
||||||
|
if (ngx_strcmp(value[1].data, "unix:") == 0) {
|
||||||
cidr = ngx_array_push(&ecf->debug_connection);
|
cidr = ngx_array_push(&ecf->debug_connection);
|
||||||
if (cidr == NULL) {
|
if (cidr == NULL) {
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (NGX_HAVE_UNIX_DOMAIN)
|
|
||||||
|
|
||||||
if (ngx_strcmp(value[1].data, "unix:") == 0) {
|
|
||||||
cidr->family = AF_UNIX;
|
cidr->family = AF_UNIX;
|
||||||
return NGX_CONF_OK;
|
return NGX_CONF_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rc = ngx_ptocidr(&value[1], cidr);
|
rc = ngx_ptocidr(&value[1], &c);
|
||||||
|
|
||||||
|
if (rc != NGX_ERROR) {
|
||||||
if (rc == NGX_DONE) {
|
if (rc == NGX_DONE) {
|
||||||
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
|
||||||
"low address bits of %V are meaningless", &value[1]);
|
"low address bits of %V are meaningless",
|
||||||
return NGX_CONF_OK;
|
&value[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc == NGX_OK) {
|
cidr = ngx_array_push(&ecf->debug_connection);
|
||||||
return NGX_CONF_OK;
|
if (cidr == NULL) {
|
||||||
}
|
|
||||||
|
|
||||||
h = gethostbyname((char *) value[1].data);
|
|
||||||
|
|
||||||
if (h == NULL || h->h_addr_list[0] == NULL) {
|
|
||||||
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
||||||
"host \"%s\" not found", value[1].data);
|
|
||||||
return NGX_CONF_ERROR;
|
return NGX_CONF_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
cidr->family = AF_INET;
|
*cidr = c;
|
||||||
cidr->u.in.mask = 0xffffffff;
|
|
||||||
cidr->u.in.addr = *(in_addr_t *)(h->h_addr_list[0]);
|
return NGX_CONF_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_memzero(&u, sizeof(ngx_url_t));
|
||||||
|
u.host = value[1];
|
||||||
|
|
||||||
|
if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
|
||||||
|
if (u.err) {
|
||||||
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
||||||
|
"%s in debug_connection \"%V\"",
|
||||||
|
u.err, &u.host);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
cidr = ngx_array_push_n(&ecf->debug_connection, u.naddrs);
|
||||||
|
if (cidr == NULL) {
|
||||||
|
return NGX_CONF_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_memzero(cidr, u.naddrs * sizeof(ngx_cidr_t));
|
||||||
|
|
||||||
|
for (i = 0; i < u.naddrs; i++) {
|
||||||
|
cidr[i].family = u.addrs[i].sockaddr->sa_family;
|
||||||
|
|
||||||
|
switch (cidr[i].family) {
|
||||||
|
|
||||||
|
#if (NGX_HAVE_INET6)
|
||||||
|
case AF_INET6:
|
||||||
|
sin6 = (struct sockaddr_in6 *) u.addrs[i].sockaddr;
|
||||||
|
cidr[i].u.in6.addr = sin6->sin6_addr;
|
||||||
|
ngx_memset(cidr[i].u.in6.mask.s6_addr, 0xff, 16);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
default: /* AF_INET */
|
||||||
|
sin = (struct sockaddr_in *) u.addrs[i].sockaddr;
|
||||||
|
cidr[i].u.in.addr = sin->sin_addr.s_addr;
|
||||||
|
cidr[i].u.in.mask = 0xffffffff;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user