diff options
| author | Ruslan Ermilov <ru@nginx.com> | 2012-04-29 22:02:18 +0000 |
|---|---|---|
| committer | Ruslan Ermilov <ru@nginx.com> | 2012-04-29 22:02:18 +0000 |
| commit | 700364f62dedba8f1b0b1ad965bf7d6425b02201 (patch) | |
| tree | b25c21b174f13de08976603473e078126f014575 /src | |
| parent | a0025f2d81fb4e8974534cee130233f9cd8f7929 (diff) | |
| download | nginx-700364f62dedba8f1b0b1ad965bf7d6425b02201.tar.gz nginx-700364f62dedba8f1b0b1ad965bf7d6425b02201.tar.bz2 | |
debug_connection: added the IPv6 and UNIX-domain socket support.
Diffstat (limited to 'src')
| -rw-r--r-- | src/event/ngx_event.c | 39 | ||||
| -rw-r--r-- | src/event/ngx_event.h | 6 | ||||
| -rw-r--r-- | src/event/ngx_event_accept.c | 53 |
3 files changed, 64 insertions, 34 deletions
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c index a0a9d743b..c584dd87d 100644 --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -1064,38 +1064,34 @@ ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_int_t rc; ngx_str_t *value; - ngx_event_debug_t *dc; struct hostent *h; - ngx_cidr_t cidr; + ngx_cidr_t *cidr; value = cf->args->elts; - dc = ngx_array_push(&ecf->debug_connection); - if (dc == NULL) { + cidr = ngx_array_push(&ecf->debug_connection); + if (cidr == NULL) { return NGX_CONF_ERROR; } - rc = ngx_ptocidr(&value[1], &cidr); +#if (NGX_HAVE_UNIX_DOMAIN) + + if (ngx_strcmp(value[1].data, "unix:") == 0) { + cidr->family = AF_UNIX; + return NGX_CONF_OK; + } + +#endif + + rc = ngx_ptocidr(&value[1], cidr); if (rc == NGX_DONE) { ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "low address bits of %V are meaningless", &value[1]); - rc = NGX_OK; + return NGX_CONF_OK; } if (rc == NGX_OK) { - - /* AF_INET only */ - - if (cidr.family != AF_INET) { - ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, - "\"debug_connection\" supports IPv4 only"); - return NGX_CONF_ERROR; - } - - dc->mask = cidr.u.in.mask; - dc->addr = cidr.u.in.addr; - return NGX_CONF_OK; } @@ -1107,8 +1103,9 @@ ngx_event_debug_connection(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_ERROR; } - dc->mask = 0xffffffff; - dc->addr = *(in_addr_t *)(h->h_addr_list[0]); + cidr->family = AF_INET; + cidr->u.in.mask = 0xffffffff; + cidr->u.in.addr = *(in_addr_t *)(h->h_addr_list[0]); #else @@ -1142,7 +1139,7 @@ ngx_event_core_create_conf(ngx_cycle_t *cycle) #if (NGX_DEBUG) if (ngx_array_init(&ecf->debug_connection, cycle->pool, 4, - sizeof(ngx_event_debug_t)) == NGX_ERROR) + sizeof(ngx_cidr_t)) == NGX_ERROR) { return NULL; } diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index 8cc87ebff..2096da234 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -222,12 +222,6 @@ struct ngx_event_aio_s { typedef struct { - in_addr_t mask; - in_addr_t addr; -} ngx_event_debug_t; - - -typedef struct { ngx_int_t (*add)(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags); ngx_int_t (*del)(ngx_event_t *ev, ngx_int_t event, ngx_uint_t flags); diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c index a45afeb1f..23cb85b14 100644 --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -252,17 +252,56 @@ ngx_event_accept(ngx_event_t *ev) #if (NGX_DEBUG) { - in_addr_t i; - ngx_event_debug_t *dc; - struct sockaddr_in *sin; + struct sockaddr_in *sin; + ngx_cidr_t *cidr; + ngx_uint_t i; +#if (NGX_HAVE_INET6) + struct sockaddr_in6 *sin6; + ngx_uint_t n; +#endif - sin = (struct sockaddr_in *) sa; - dc = ecf->debug_connection.elts; + cidr = ecf->debug_connection.elts; for (i = 0; i < ecf->debug_connection.nelts; i++) { - if ((sin->sin_addr.s_addr & dc[i].mask) == dc[i].addr) { - log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL; + if (cidr[i].family != c->sockaddr->sa_family) { + goto next; + } + + switch (cidr[i].family) { + +#if (NGX_HAVE_INET6) + case AF_INET6: + sin6 = (struct sockaddr_in6 *) c->sockaddr; + for (n = 0; n < 16; n++) { + if ((sin6->sin6_addr.s6_addr[n] + & cidr[i].u.in6.mask.s6_addr[n]) + != cidr[i].u.in6.addr.s6_addr[n]) + { + goto next; + } + } + break; +#endif + +#if (NGX_HAVE_UNIX_DOMAIN) + case AF_UNIX: + break; +#endif + + default: /* AF_INET */ + sin = (struct sockaddr_in *) c->sockaddr; + if ((sin->sin_addr.s_addr & cidr[i].u.in.mask) + != cidr[i].u.in.addr) + { + goto next; + } break; } + + log->log_level = NGX_LOG_DEBUG_CONNECTION|NGX_LOG_DEBUG_ALL; + break; + + next: + continue; } } |
