#include <ngx_core.h>
+#if (NGX_HAVE_INET6)
+static size_t ngx_inet6_ntop(u_char *p, u_char *text, size_t len);
+#endif
static ngx_int_t ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u);
static ngx_int_t ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u);
+static ngx_int_t ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u);
-/* AF_INET only */
-
in_addr_t
ngx_inet_addr(u_char *text, size_t len)
{
}
-/* AF_INET only */
-
size_t
-ngx_sock_ntop(struct sockaddr *sa, u_char *text, size_t len)
+ngx_sock_ntop(struct sockaddr *sa, u_char *text, size_t len, ngx_uint_t port)
{
- u_char *p;
- struct sockaddr_in *sin;
+ u_char *p;
+ struct sockaddr_in *sin;
+#if (NGX_HAVE_INET6)
+ size_t n;
+ struct sockaddr_in6 *sin6;
+#endif
+
+ switch (sa->sa_family) {
- if (sa->sa_family == AF_INET) {
+ case AF_INET:
sin = (struct sockaddr_in *) sa;
p = (u_char *) &sin->sin_addr;
- return ngx_snprintf(text, len, "%ud.%ud.%ud.%ud",
- p[0], p[1], p[2], p[3])
- - text;
- }
+ if (port) {
+ p = ngx_snprintf(text, len, "%ud.%ud.%ud.%ud:%d",
+ p[0], p[1], p[2], p[3], ntohs(sin->sin_port));
+ } else {
+ p = ngx_snprintf(text, len, "%ud.%ud.%ud.%ud",
+ p[0], p[1], p[2], p[3]);
+ }
+
+ return (p - text);
+
+#if (NGX_HAVE_INET6)
+
+ case AF_INET6:
+
+ sin6 = (struct sockaddr_in6 *) sa;
+
+ n = 0;
+
+ if (port) {
+ text[n++] = '[';
+ }
- return 0;
+ n = ngx_inet6_ntop((u_char *) &sin6->sin6_addr, &text[n], len);
+
+ if (port) {
+ n = ngx_sprintf(&text[1 + n], "]:%d",
+ ntohs(sin6->sin6_port)) - text;
+ }
+
+ return n;
+#endif
+
+ default:
+ return 0;
+ }
}
{
u_char *p;
- if (family == AF_INET) {
+ switch (family) {
+
+ case AF_INET:
- p = (u_char *) addr;
+ p = addr;
return ngx_snprintf(text, len, "%ud.%ud.%ud.%ud",
p[0], p[1], p[2], p[3])
- text;
+
+#if (NGX_HAVE_INET6)
+
+ case AF_INET6:
+ return ngx_inet6_ntop(addr, text, len);
+
+#endif
+
+ default:
+ return 0;
+ }
+}
+
+
+#if (NGX_HAVE_INET6)
+
+static size_t
+ngx_inet6_ntop(u_char *p, u_char *text, size_t len)
+{
+ u_char *dst;
+ size_t max, n;
+ ngx_uint_t i, zero, last;
+
+ if (len < NGX_INET6_ADDRSTRLEN) {
+ return 0;
+ }
+
+ zero = (ngx_uint_t) -1;
+ last = (ngx_uint_t) -1;
+ max = 1;
+ n = 0;
+
+ for (i = 0; i < 16; i += 2) {
+
+ if (p[i] || p[i + 1]) {
+
+ if (max < n) {
+ zero = last;
+ max = n;
+ }
+
+ n = 0;
+ continue;
+ }
+
+ if (n++ == 0) {
+ last = i;
+ }
}
- return 0;
+ if (max < n) {
+ zero = last;
+ max = n;
+ }
+
+ dst = text;
+ n = 16;
+
+ if (zero == 0) {
+
+ if ((max == 5 && p[10] == 0xff && p[11] == 0xff)
+ || (max == 6)
+ || (max == 7 && p[14] != 0 && p[15] != 1))
+ {
+ n = 12;
+ }
+
+ *dst++ = ':';
+ }
+
+ for (i = 0; i < n; i += 2) {
+
+ if (i == zero) {
+ *dst++ = ':';
+ i += (max - 1) * 2;
+ continue;
+ }
+
+ dst = ngx_sprintf(dst, "%uxi", p[i] * 256 + p[i + 1]);
+
+ if (i < 14) {
+ *dst++ = ':';
+ }
+ }
+
+ if (n == 12) {
+ dst = ngx_sprintf(dst, "%ud.%ud.%ud.%ud", p[12], p[13], p[14], p[15]);
+ }
+
+ return dst - text;
}
+#endif
+
/* AF_INET only */
return NGX_ERROR;
}
+ if (p[0] == '[') {
+ return ngx_parse_inet6_url(pool, u);
+ }
+
return ngx_parse_inet_url(pool, u);
}
u->host.len = len++;
u->host.data = path;
- u->family = AF_UNIX;
if (len > sizeof(saun->sun_path)) {
u->err = "too long path in the unix domain socket";
return NGX_ERROR;
}
+ u->socklen = sizeof(struct sockaddr_un);
+ saun = (struct sockaddr_un *) &u->sockaddr;
+ saun->sun_family = AF_UNIX;
+ (void) ngx_cpystrn((u_char *) saun->sun_path, path, len);
+
u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t));
if (u->addrs == NULL) {
return NGX_ERROR;
return NGX_ERROR;
}
+ u->family = AF_UNIX;
u->naddrs = 1;
saun->sun_family = AF_UNIX;
static ngx_int_t
ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u)
{
- u_char *p, *host, *port, *last, *uri, *args;
- size_t len;
- ngx_int_t n;
- struct hostent *h;
+ u_char *p, *host, *port, *last, *uri, *args;
+ size_t len;
+ ngx_int_t n;
+ struct hostent *h;
+ struct sockaddr_in *sin;
+
+ u->socklen = sizeof(struct sockaddr_in);
+ sin = (struct sockaddr_in *) &u->sockaddr;
+ sin->sin_family = AF_INET;
u->family = AF_INET;
}
u->port = (in_port_t) n;
+ sin->sin_port = htons((in_port_t) n);
u->port_text.len = len;
u->port_text.data = port;
}
u->port = (in_port_t) n;
+ sin->sin_port = htons((in_port_t) n);
u->port_text.len = last - host;
u->port_text.data = host;
+ u->wildcard = 1;
+
return NGX_OK;
}
}
(void) ngx_cpystrn(p, host, len);
u->addr.in_addr = inet_addr((const char *) p);
+ sin->sin_addr.s_addr = inet_addr((const char *) p);
- if (u->addr.in_addr == INADDR_NONE) {
+ if (sin->sin_addr.s_addr == INADDR_NONE) {
h = gethostbyname((const char *) p);
if (h == NULL || h->h_addr_list[0] == NULL) {
}
u->addr.in_addr = *(in_addr_t *) (h->h_addr_list[0]);
+ sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[0]);
+ }
+
+ if (sin->sin_addr.s_addr == INADDR_ANY) {
+ u->wildcard = 1;
}
ngx_free(p);
} else {
u->addr.in_addr = INADDR_ANY;
+ sin->sin_addr.s_addr = INADDR_ANY;
+ u->wildcard = 1;
}
if (u->no_port) {
u->port = u->default_port;
+ sin->sin_port = htons(u->default_port);
}
if (u->listen) {
}
+static ngx_int_t
+ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u)
+{
+#if (NGX_HAVE_INET6)
+ int rc;
+ u_char *p, *host, *port, *last, *uri;
+ size_t len;
+ ngx_int_t n;
+ struct sockaddr_in6 *sin6;
+
+ u->socklen = sizeof(struct sockaddr_in6);
+ sin6 = (struct sockaddr_in6 *) &u->sockaddr;
+ sin6->sin6_family = AF_INET6;
+
+ host = u->url.data + 1;
+
+ last = u->url.data + u->url.len;
+
+ p = ngx_strlchr(host, last, ']');
+
+ if (p == NULL) {
+ u->err = "invalid host";
+ return NGX_ERROR;
+ }
+
+ if (last - p) {
+
+ port = p + 1;
+
+ uri = ngx_strlchr(port, last, '/');
+
+ if (uri) {
+ if (u->listen || !u->uri_part) {
+ u->err = "invalid host";
+ return NGX_ERROR;
+ }
+
+ u->uri.len = last - uri;
+ u->uri.data = uri;
+ }
+
+ if (*port == ':') {
+ port++;
+
+ len = last - port;
+
+ if (len == 0) {
+ u->err = "invalid port";
+ return NGX_ERROR;
+ }
+
+ n = ngx_atoi(port, len);
+
+ if (n < 1 || n > 65536) {
+ u->err = "invalid port";
+ return NGX_ERROR;
+ }
+
+ u->port = (in_port_t) n;
+ sin6->sin6_port = htons((in_port_t) n);
+
+ u->port_text.len = len;
+ u->port_text.data = port;
+
+ } else {
+ u->no_port = 1;
+ }
+ }
+
+ len = p - host;
+
+ if (len == 0) {
+ u->err = "no host";
+ return NGX_ERROR;
+ }
+
+ u->host.len = len++;
+ u->host.data = host;
+
+ p = ngx_alloc(len, pool->log);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ (void) ngx_cpystrn(p, host, len);
+
+ rc = inet_pton(AF_INET6, (const char *) p, &sin6->sin6_addr);
+
+ ngx_free(p);
+
+ if (rc == 0) {
+ u->err = "invalid IPv6 address";
+ return NGX_ERROR;
+ }
+
+ if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
+ u->wildcard = 1;
+ }
+
+ u->family = AF_INET6;
+
+ if (u->no_resolve) {
+ return NGX_OK;
+ }
+
+ if (u->no_port) {
+ u->port = u->default_port;
+ sin6->sin6_port = htons(u->default_port);
+ }
+
+ return NGX_OK;
+
+#else
+
+ u->err = "the INET6 sockets are not supported on this platform";
+
+ return NGX_ERROR;
+
+#endif
+}
+
+
ngx_int_t
ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u)
{
u_char *p, *host;
size_t len;
+ in_port_t port;
in_addr_t in_addr;
ngx_uint_t i;
struct hostent *h;
/* AF_INET only */
+ sin = (struct sockaddr_in *) &u->sockaddr;
+ port = sin->sin_port;
+
in_addr = inet_addr((char *) host);
if (in_addr == INADDR_NONE) {
}
sin->sin_family = AF_INET;
- sin->sin_port = htons(u->port);
+ sin->sin_port = port;
sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]);
u->addrs[i].sockaddr = (struct sockaddr *) sin;
u->addrs[i].socklen = sizeof(struct sockaddr_in);
- len = NGX_INET_ADDRSTRLEN + sizeof(":65536") - 1;
+ len = NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1;
p = ngx_pnalloc(pool, len);
if (p == NULL) {
return NGX_ERROR;
}
- len = ngx_sock_ntop((struct sockaddr *) sin, p, len);
+ len = ngx_sock_ntop((struct sockaddr *) sin, p, len, 1);
- u->addrs[i].name.len = ngx_sprintf(&p[len], ":%d", u->port) - p;
+ u->addrs[i].name.len = len;
u->addrs[i].name.data = p;
}
u->naddrs = 1;
sin->sin_family = AF_INET;
- sin->sin_port = htons(u->port);
+ sin->sin_port = port;
sin->sin_addr.s_addr = in_addr;
u->addrs[0].sockaddr = (struct sockaddr *) sin;
u->addrs[0].socklen = sizeof(struct sockaddr_in);
- p = ngx_pnalloc(pool, u->host.len + sizeof(":65536") - 1);
+ p = ngx_pnalloc(pool, u->host.len + sizeof(":65535") - 1);
if (p == NULL) {
return NGX_ERROR;
}
- u->addrs[0].name.len = ngx_sprintf(p, "%V:%d", &u->host, u->port) - p;
+ u->addrs[0].name.len = ngx_sprintf(p, "%V:%d",
+ &u->host, ntohs(port)) - p;
u->addrs[0].name.data = p;
}
static ngx_int_t ngx_http_init_server_lists(ngx_conf_t *cf,
ngx_array_t *servers, ngx_array_t *in_ports);
+static ngx_int_t ngx_http_add_ports(ngx_conf_t *cf,
+ ngx_http_core_srv_conf_t *cscf, ngx_array_t *ports,
+ ngx_http_listen_t *listen);
+static ngx_int_t ngx_http_add_addresses(ngx_conf_t *cf,
+ ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port,
+ ngx_http_listen_t *listen);
static ngx_int_t ngx_http_add_address(ngx_conf_t *cf,
- ngx_http_core_srv_conf_t *cscf, ngx_http_conf_in_port_t *in_port,
+ ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port,
ngx_http_listen_t *listen);
static ngx_int_t ngx_http_add_names(ngx_conf_t *cf,
- ngx_http_core_srv_conf_t *cscf, ngx_http_conf_in_addr_t *in_addr);
+ ngx_http_core_srv_conf_t *cscf, ngx_http_conf_addr_t *addr);
static char *ngx_http_merge_locations(ngx_conf_t *cf,
ngx_queue_t *locations, void **loc_conf, ngx_http_module_t *module,
size_t prefix);
static ngx_int_t ngx_http_optimize_servers(ngx_conf_t *cf,
- ngx_http_core_main_conf_t *cmcf, ngx_array_t *in_ports);
-static ngx_int_t ngx_http_cmp_conf_in_addrs(const void *one, const void *two);
+ ngx_http_core_main_conf_t *cmcf, ngx_array_t *ports);
+static ngx_int_t ngx_http_server_names(ngx_conf_t *cf,
+ ngx_http_core_main_conf_t *cmcf, ngx_http_conf_addr_t *addr);
+static ngx_int_t ngx_http_cmp_conf_addrs(const void *one, const void *two);
static int ngx_libc_cdecl ngx_http_cmp_dns_wildcards(const void *one,
const void *two);
static ngx_int_t ngx_http_init_listening(ngx_conf_t *cf,
- ngx_http_conf_in_port_t *in_port);
+ ngx_http_conf_port_t *port);
+static ngx_listening_t *ngx_http_add_listening(ngx_conf_t *cf,
+ ngx_http_conf_addr_t *addr);
+static ngx_int_t ngx_http_add_addrs(ngx_conf_t *cf, ngx_http_port_t *hport,
+ ngx_http_conf_addr_t *addr);
+#if (NGX_HAVE_INET6)
+static ngx_int_t ngx_http_add_addrs6(ngx_conf_t *cf, ngx_http_port_t *hport,
+ ngx_http_conf_addr_t *addr);
+#endif
ngx_uint_t ngx_http_max_module;
* to find quickly the server core module configuration at run-time
*/
- /* AF_INET only */
-
if (ngx_http_init_server_lists(cf, &cmcf->servers, &in_ports) != NGX_OK) {
return NGX_CONF_ERROR;
}
/* optimize the lists of ports, addresses and server names */
- /* AF_INET only */
-
if (ngx_http_optimize_servers(cf, cmcf, &in_ports) != NGX_OK) {
return NGX_CONF_ERROR;
}
static ngx_int_t
ngx_http_init_server_lists(ngx_conf_t *cf, ngx_array_t *servers,
- ngx_array_t *in_ports)
+ ngx_array_t *ports)
{
- ngx_uint_t s, l, p, a;
+ ngx_uint_t s, i;
ngx_http_listen_t *listen;
- ngx_http_conf_in_port_t *in_port;
- ngx_http_conf_in_addr_t *in_addr;
ngx_http_core_srv_conf_t **cscfp;
- if (ngx_array_init(in_ports, cf->temp_pool, 2,
- sizeof(ngx_http_conf_in_port_t))
+ if (ngx_array_init(ports, cf->temp_pool, 2, sizeof(ngx_http_conf_port_t))
!= NGX_OK)
{
return NGX_ERROR;
/* "listen" directives */
listen = cscfp[s]->listen.elts;
- for (l = 0; l < cscfp[s]->listen.nelts; l++) {
+ for (i = 0; i < cscfp[s]->listen.nelts; i++) {
- /* AF_INET only */
+ if (ngx_http_add_ports(cf, cscfp[s], ports, &listen[i]) != NGX_OK) {
+ return NGX_ERROR;
+ }
+ }
+ }
- in_port = in_ports->elts;
- for (p = 0; p < in_ports->nelts; p++) {
+ return NGX_OK;
+}
- if (listen[l].port != in_port[p].port) {
- continue;
- }
- /* the port is already in the port list */
+static ngx_int_t
+ngx_http_add_ports(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
+ ngx_array_t *ports, ngx_http_listen_t *listen)
+{
+ in_port_t p;
+ ngx_uint_t i;
+ struct sockaddr *sa;
+ struct sockaddr_in *sin;
+ ngx_http_conf_port_t *port;
+#if (NGX_HAVE_INET6)
+ struct sockaddr_in6 *sin6;
+#endif
- in_addr = in_port[p].addrs.elts;
- for (a = 0; a < in_port[p].addrs.nelts; a++) {
+ sa = (struct sockaddr *) &listen->sockaddr;
- if (listen[l].addr != in_addr[a].addr) {
- continue;
- }
+ switch (sa->sa_family) {
- /* the address is already in the address list */
+#if (NGX_HAVE_INET6)
+ case AF_INET6:
+ sin6 = (struct sockaddr_in6 *) sa;
+ p = sin6->sin6_port;
+ break;
+#endif
- if (ngx_http_add_names(cf, cscfp[s], &in_addr[a]) != NGX_OK)
- {
- return NGX_ERROR;
- }
+ default: /* AF_INET */
+ sin = (struct sockaddr_in *) sa;
+ p = sin->sin_port;
+ break;
+ }
+
+ port = ports->elts;
+ for (i = 0; i < ports->nelts; i++) {
- /*
- * check the duplicate "default" server
- * for this address:port
- */
+ if (p != port[i].port || sa->sa_family != port[i].family) {
+ continue;
+ }
- if (listen[l].conf.default_server) {
+ /* a port is already in the in_port list */
- if (in_addr[a].default_server) {
- ngx_log_error(NGX_LOG_ERR, cf->log, 0,
- "the duplicate default server in %s:%ui",
- listen[l].file_name, listen[l].line);
+ return ngx_http_add_addresses(cf, cscf, &port[i], listen);
+ }
- return NGX_ERROR;
- }
+ /* add a port to the in_port list */
- in_addr[a].core_srv_conf = cscfp[s];
- in_addr[a].default_server = 1;
-#if (NGX_HTTP_SSL)
- in_addr[a].ssl = listen[l].conf.ssl;
+ port = ngx_array_push(ports);
+ if (port == NULL) {
+ return NGX_ERROR;
+ }
+
+ port->family = sa->sa_family;
+ port->port = p;
+ port->addrs.elts = NULL;
+
+ return ngx_http_add_address(cf, cscf, port, listen);
+}
+
+
+static ngx_int_t
+ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
+ ngx_http_conf_port_t *port, ngx_http_listen_t *listen)
+{
+ u_char *p;
+ size_t len, off;
+ ngx_uint_t i;
+ struct sockaddr *sa;
+ ngx_http_conf_addr_t *addr;
+
+ /*
+ * we can not compare whole sockaddr struct's as kernel
+ * may fill some fields in inherited sockaddr struct's
+ */
+
+ sa = (struct sockaddr *) &listen->sockaddr;
+
+ switch (sa->sa_family) {
+
+#if (NGX_HAVE_INET6)
+ case AF_INET6:
+ off = offsetof(struct sockaddr_in6, sin6_addr);
+ len = 16;
+ break;
#endif
- in_addr[a].listen_conf = &listen[l].conf;
- }
- goto found;
- }
+ default: /* AF_INET */
+ off = offsetof(struct sockaddr_in, sin_addr);
+ len = 4;
+ break;
+ }
- /*
- * add the address to the addresses list that
- * bound to this port
- */
+ p = listen->sockaddr + off;
- if (ngx_http_add_address(cf, cscfp[s], &in_port[p], &listen[l])
- != NGX_OK)
- {
- return NGX_ERROR;
- }
+ addr = port->addrs.elts;
- goto found;
- }
+ for (i = 0; i < port->addrs.nelts; i++) {
- /* add the port to the in_port list */
+ if (ngx_memcmp(p, (u_char *) addr[i].sockaddr + off, len) != 0) {
+ continue;
+ }
- in_port = ngx_array_push(in_ports);
- if (in_port == NULL) {
- return NGX_ERROR;
- }
+ /* the address is already in the address list */
- in_port->port = listen[l].port;
- in_port->addrs.elts = NULL;
+ if (ngx_http_add_names(cf, cscf, &addr[i]) != NGX_OK) {
+ return NGX_ERROR;
+ }
+
+ /* check the duplicate "default" server for this address:port */
+
+ if (listen->conf.default_server) {
+
+ if (addr[i].default_server) {
+ ngx_log_error(NGX_LOG_ERR, cf->log, 0,
+ "the duplicate default server in %s:%ui",
+ listen->file_name, listen->line);
- if (ngx_http_add_address(cf, cscfp[s], in_port, &listen[l])
- != NGX_OK)
- {
return NGX_ERROR;
}
- found:
-
- continue;
+ addr[i].core_srv_conf = cscf;
+ addr[i].default_server = 1;
+#if (NGX_HTTP_SSL)
+ addr[i].ssl = listen->conf.ssl;
+#endif
+ addr[i].listen_conf = &listen->conf;
}
+
+ return NGX_OK;
}
- return NGX_OK;
+ /* add the address to the addresses list that bound to this port */
+
+ return ngx_http_add_address(cf, cscf, port, listen);
}
static ngx_int_t
ngx_http_add_address(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
- ngx_http_conf_in_port_t *in_port, ngx_http_listen_t *listen)
+ ngx_http_conf_port_t *port, ngx_http_listen_t *listen)
{
- ngx_http_conf_in_addr_t *in_addr;
+ ngx_http_conf_addr_t *addr;
- if (in_port->addrs.elts == NULL) {
- if (ngx_array_init(&in_port->addrs, cf->temp_pool, 4,
- sizeof(ngx_http_conf_in_addr_t))
+ if (port->addrs.elts == NULL) {
+ if (ngx_array_init(&port->addrs, cf->temp_pool, 4,
+ sizeof(ngx_http_conf_addr_t))
!= NGX_OK)
{
return NGX_ERROR;
}
}
- in_addr = ngx_array_push(&in_port->addrs);
- if (in_addr == NULL) {
+ addr = ngx_array_push(&port->addrs);
+ if (addr == NULL) {
return NGX_ERROR;
}
- in_addr->addr = listen->addr;
- in_addr->hash.buckets = NULL;
- in_addr->hash.size = 0;
- in_addr->wc_head = NULL;
- in_addr->wc_tail = NULL;
- in_addr->names.elts = NULL;
+ addr->sockaddr = (struct sockaddr *) &listen->sockaddr;
+ addr->socklen = listen->socklen;
+ addr->hash.buckets = NULL;
+ addr->hash.size = 0;
+ addr->wc_head = NULL;
+ addr->wc_tail = NULL;
+ addr->names.elts = NULL;
#if (NGX_PCRE)
- in_addr->nregex = 0;
- in_addr->regex = NULL;
+ addr->nregex = 0;
+ addr->regex = NULL;
#endif
- in_addr->core_srv_conf = cscf;
- in_addr->default_server = listen->conf.default_server;
- in_addr->bind = listen->conf.bind;
+ addr->core_srv_conf = cscf;
+ addr->default_server = listen->conf.default_server;
+ addr->bind = listen->conf.bind;
+ addr->wildcard = listen->conf.wildcard;
#if (NGX_HTTP_SSL)
- in_addr->ssl = listen->conf.ssl;
+ addr->ssl = listen->conf.ssl;
#endif
- in_addr->listen_conf = &listen->conf;
+ addr->listen_conf = &listen->conf;
- return ngx_http_add_names(cf, cscf, in_addr);
+ return ngx_http_add_names(cf, cscf, addr);
}
/*
* add the server names and the server core module
- * configurations to the address:port (in_addr)
+ * configurations to the address:port
*/
static ngx_int_t
ngx_http_add_names(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
- ngx_http_conf_in_addr_t *in_addr)
+ ngx_http_conf_addr_t *addr)
{
ngx_uint_t i;
ngx_http_server_name_t *server_names, *name;
- if (in_addr->names.elts == NULL) {
- if (ngx_array_init(&in_addr->names, cf->temp_pool, 4,
+ if (addr->names.elts == NULL) {
+ if (ngx_array_init(&addr->names, cf->temp_pool, 4,
sizeof(ngx_http_server_name_t))
!= NGX_OK)
{
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
"name: %V", &server_names[i].name);
- name = ngx_array_push(&in_addr->names);
+ name = ngx_array_push(&addr->names);
if (name == NULL) {
return NGX_ERROR;
}
static ngx_int_t
ngx_http_optimize_servers(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf,
- ngx_array_t *in_ports)
+ ngx_array_t *ports)
{
- ngx_int_t rc;
- ngx_uint_t s, p, a;
- ngx_hash_init_t hash;
- ngx_http_server_name_t *name;
- ngx_hash_keys_arrays_t ha;
- ngx_http_conf_in_port_t *in_port;
- ngx_http_conf_in_addr_t *in_addr;
-#if (NGX_PCRE)
- ngx_uint_t regex, i;
-#endif
+ ngx_uint_t s, p, a;
+ ngx_http_conf_port_t *port;
+ ngx_http_conf_addr_t *addr;
+ ngx_http_server_name_t *name;
- in_port = in_ports->elts;
- for (p = 0; p < in_ports->nelts; p++) {
+ port = ports->elts;
+ for (p = 0; p < ports->nelts; p++) {
- ngx_sort(in_port[p].addrs.elts, (size_t) in_port[p].addrs.nelts,
- sizeof(ngx_http_conf_in_addr_t), ngx_http_cmp_conf_in_addrs);
+ ngx_sort(port[p].addrs.elts, (size_t) port[p].addrs.nelts,
+ sizeof(ngx_http_conf_addr_t), ngx_http_cmp_conf_addrs);
/*
- * check whether all name-based servers have
- * the same configuraiton as the default server
+ * check whether all name-based servers have the same
+ * configuraiton as a default server for given address:port
*/
- in_addr = in_port[p].addrs.elts;
- for (a = 0; a < in_port[p].addrs.nelts; a++) {
+ addr = port[p].addrs.elts;
+ for (a = 0; a < port[p].addrs.nelts; a++) {
- name = in_addr[a].names.elts;
- for (s = 0; s < in_addr[a].names.nelts; s++) {
+ name = addr[a].names.elts;
+ for (s = 0; s < addr[a].names.nelts; s++) {
- if (in_addr[a].core_srv_conf != name[s].core_srv_conf) {
- goto virtual_names;
+ if (addr[a].core_srv_conf == name[s].core_srv_conf) {
+ continue;
}
+
+ if (ngx_http_server_names(cf, cmcf, &addr[a]) != NGX_OK) {
+ return NGX_ERROR;
+ }
+
+ break;
}
+ }
- /*
- * if all name-based servers have the same configuration
- * as the default server, then we do not need to check
- * them at run-time at all
- */
+ if (ngx_http_init_listening(cf, &port[p]) != NGX_OK) {
+ return NGX_ERROR;
+ }
+ }
- in_addr[a].names.nelts = 0;
+ return NGX_OK;
+}
- continue;
- virtual_names:
+static ngx_int_t
+ngx_http_server_names(ngx_conf_t *cf, ngx_http_core_main_conf_t *cmcf,
+ ngx_http_conf_addr_t *addr)
+{
+ ngx_int_t rc;
+ ngx_uint_t s;
+ ngx_hash_init_t hash;
+ ngx_http_server_name_t *name;
+ ngx_hash_keys_arrays_t ha;
+#if (NGX_PCRE)
+ ngx_uint_t regex, i;
- ngx_memzero(&ha, sizeof(ngx_hash_keys_arrays_t));
+ regex = 0;
+#endif
- ha.temp_pool = ngx_create_pool(16384, cf->log);
- if (ha.temp_pool == NULL) {
- return NGX_ERROR;
- }
+ ngx_memzero(&ha, sizeof(ngx_hash_keys_arrays_t));
- ha.pool = cf->pool;
+ ha.temp_pool = ngx_create_pool(16384, cf->log);
+ if (ha.temp_pool == NULL) {
+ return NGX_ERROR;
+ }
- if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) {
- goto failed;
- }
+ ha.pool = cf->pool;
-#if (NGX_PCRE)
- regex = 0;
-#endif
+ if (ngx_hash_keys_array_init(&ha, NGX_HASH_LARGE) != NGX_OK) {
+ goto failed;
+ }
- name = in_addr[a].names.elts;
+ name = addr->names.elts;
- for (s = 0; s < in_addr[a].names.nelts; s++) {
+ for (s = 0; s < addr->names.nelts; s++) {
#if (NGX_PCRE)
- if (name[s].regex) {
- regex++;
- continue;
- }
+ if (name[s].regex) {
+ regex++;
+ continue;
+ }
#endif
- rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf,
- NGX_HASH_WILDCARD_KEY);
+ rc = ngx_hash_add_key(&ha, &name[s].name, name[s].core_srv_conf,
+ NGX_HASH_WILDCARD_KEY);
- if (rc == NGX_ERROR) {
- return NGX_ERROR;
- }
+ if (rc == NGX_ERROR) {
+ return NGX_ERROR;
+ }
- if (rc == NGX_DECLINED) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "invalid server name or wildcard \"%V\" on %s",
- &name[s].name, in_addr[a].listen_conf->addr);
- return NGX_ERROR;
- }
+ if (rc == NGX_DECLINED) {
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+ "invalid server name or wildcard \"%V\" on %s",
+ &name[s].name, addr->listen_conf->addr);
+ return NGX_ERROR;
+ }
- if (rc == NGX_BUSY) {
- ngx_log_error(NGX_LOG_WARN, cf->log, 0,
- "conflicting server name \"%V\" on %s, ignored",
- &name[s].name, in_addr[a].listen_conf->addr);
- }
- }
+ if (rc == NGX_BUSY) {
+ ngx_log_error(NGX_LOG_WARN, cf->log, 0,
+ "conflicting server name \"%V\" on %s, ignored",
+ &name[s].name, addr->listen_conf->addr);
+ }
+ }
- hash.key = ngx_hash_key_lc;
- hash.max_size = cmcf->server_names_hash_max_size;
- hash.bucket_size = cmcf->server_names_hash_bucket_size;
- hash.name = "server_names_hash";
- hash.pool = cf->pool;
+ hash.key = ngx_hash_key_lc;
+ hash.max_size = cmcf->server_names_hash_max_size;
+ hash.bucket_size = cmcf->server_names_hash_bucket_size;
+ hash.name = "server_names_hash";
+ hash.pool = cf->pool;
- if (ha.keys.nelts) {
- hash.hash = &in_addr[a].hash;
- hash.temp_pool = NULL;
+ if (ha.keys.nelts) {
+ hash.hash = &addr->hash;
+ hash.temp_pool = NULL;
- if (ngx_hash_init(&hash, ha.keys.elts, ha.keys.nelts) != NGX_OK)
- {
- goto failed;
- }
- }
+ if (ngx_hash_init(&hash, ha.keys.elts, ha.keys.nelts) != NGX_OK) {
+ goto failed;
+ }
+ }
- if (ha.dns_wc_head.nelts) {
+ if (ha.dns_wc_head.nelts) {
- ngx_qsort(ha.dns_wc_head.elts,
- (size_t) ha.dns_wc_head.nelts,
- sizeof(ngx_hash_key_t),
- ngx_http_cmp_dns_wildcards);
+ ngx_qsort(ha.dns_wc_head.elts, (size_t) ha.dns_wc_head.nelts,
+ sizeof(ngx_hash_key_t), ngx_http_cmp_dns_wildcards);
- hash.hash = NULL;
- hash.temp_pool = ha.temp_pool;
+ hash.hash = NULL;
+ hash.temp_pool = ha.temp_pool;
- if (ngx_hash_wildcard_init(&hash, ha.dns_wc_head.elts,
- ha.dns_wc_head.nelts)
- != NGX_OK)
- {
- goto failed;
- }
+ if (ngx_hash_wildcard_init(&hash, ha.dns_wc_head.elts,
+ ha.dns_wc_head.nelts)
+ != NGX_OK)
+ {
+ goto failed;
+ }
- in_addr[a].wc_head = (ngx_hash_wildcard_t *) hash.hash;
- }
+ addr->wc_head = (ngx_hash_wildcard_t *) hash.hash;
+ }
- if (ha.dns_wc_tail.nelts) {
+ if (ha.dns_wc_tail.nelts) {
- ngx_qsort(ha.dns_wc_tail.elts,
- (size_t) ha.dns_wc_tail.nelts,
- sizeof(ngx_hash_key_t),
- ngx_http_cmp_dns_wildcards);
+ ngx_qsort(ha.dns_wc_tail.elts, (size_t) ha.dns_wc_tail.nelts,
+ sizeof(ngx_hash_key_t), ngx_http_cmp_dns_wildcards);
- hash.hash = NULL;
- hash.temp_pool = ha.temp_pool;
+ hash.hash = NULL;
+ hash.temp_pool = ha.temp_pool;
- if (ngx_hash_wildcard_init(&hash, ha.dns_wc_tail.elts,
- ha.dns_wc_tail.nelts)
- != NGX_OK)
- {
- goto failed;
- }
+ if (ngx_hash_wildcard_init(&hash, ha.dns_wc_tail.elts,
+ ha.dns_wc_tail.nelts)
+ != NGX_OK)
+ {
+ goto failed;
+ }
- in_addr[a].wc_tail = (ngx_hash_wildcard_t *) hash.hash;
- }
+ addr->wc_tail = (ngx_hash_wildcard_t *) hash.hash;
+ }
- ngx_destroy_pool(ha.temp_pool);
+ ngx_destroy_pool(ha.temp_pool);
#if (NGX_PCRE)
- if (regex == 0) {
- continue;
- }
-
- in_addr[a].nregex = regex;
- in_addr[a].regex = ngx_palloc(cf->pool,
- regex * sizeof(ngx_http_server_name_t));
-
- if (in_addr[a].regex == NULL) {
- return NGX_ERROR;
- }
+ if (regex == 0) {
+ return NGX_OK;
+ }
- for (i = 0, s = 0; s < in_addr[a].names.nelts; s++) {
- if (name[s].regex) {
- in_addr[a].regex[i++] = name[s];
- }
- }
-#endif
- }
+ addr->nregex = regex;
+ addr->regex = ngx_palloc(cf->pool, regex * sizeof(ngx_http_server_name_t));
+ if (addr->regex == NULL) {
+ return NGX_ERROR;
+ }
- if (ngx_http_init_listening(cf, &in_port[p]) != NGX_OK) {
- return NGX_ERROR;
+ for (i = 0, s = 0; s < addr->names.nelts; s++) {
+ if (name[s].regex) {
+ addr->regex[i++] = name[s];
}
}
+#endif
+
return NGX_OK;
failed:
static ngx_int_t
-ngx_http_cmp_conf_in_addrs(const void *one, const void *two)
+ngx_http_cmp_conf_addrs(const void *one, const void *two)
{
- ngx_http_conf_in_addr_t *first, *second;
+ ngx_http_conf_addr_t *first, *second;
- first = (ngx_http_conf_in_addr_t *) one;
- second = (ngx_http_conf_in_addr_t *) two;
+ first = (ngx_http_conf_addr_t *) one;
+ second = (ngx_http_conf_addr_t *) two;
- if (first->addr == INADDR_ANY) {
- /* the INADDR_ANY must be the last resort, shift it to the end */
+ if (first->wildcard) {
+ /* a wildcard address must be the last resort, shift it to the end */
return 1;
}
static ngx_int_t
-ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_in_port_t *in_port)
+ngx_http_init_listening(ngx_conf_t *cf, ngx_http_conf_port_t *port)
{
- ngx_uint_t i, a, last, bind_all, done;
+ ngx_uint_t i, a, last, bind_wildcard;
ngx_listening_t *ls;
- ngx_http_in_port_t *hip;
- ngx_http_conf_in_addr_t *in_addr;
- ngx_http_virtual_names_t *vn;
- ngx_http_core_loc_conf_t *clcf;
- ngx_http_core_srv_conf_t *cscf;
+ ngx_http_port_t *hport;
+ ngx_http_conf_addr_t *addr;
- in_addr = in_port->addrs.elts;
- last = in_port->addrs.nelts;
+ addr = port->addrs.elts;
+ last = port->addrs.nelts;
/*
- * if there is a binding to a "*:port" then we need to bind()
- * to the "*:port" only and ignore other bindings
+ * If there is a binding to an "*:port" then we need to bind() to
+ * the "*:port" only and ignore other implicit bindings. The bindings
+ * have been already sorted: explicit bindings are on the start, then
+ * implicit bindings go, and wildcard binding is in the end.
*/
- if (in_addr[last - 1].addr == INADDR_ANY) {
- in_addr[last - 1].bind = 1;
- bind_all = 0;
+ if (addr[last - 1].wildcard) {
+ addr[last - 1].bind = 1;
+ bind_wildcard = 1;
} else {
- bind_all = 1;
+ bind_wildcard = 0;
}
a = 0;
while (a < last) {
- if (!bind_all && !in_addr[a].bind) {
+ if (bind_wildcard && !addr[a].bind) {
a++;
continue;
}
- ls = ngx_listening_inet_stream_socket(cf, in_addr[a].addr,
- in_port->port);
+ ls = ngx_http_add_listening(cf, &addr[a]);
if (ls == NULL) {
return NGX_ERROR;
}
- ls->addr_ntop = 1;
+ hport = ngx_pcalloc(cf->pool, sizeof(ngx_http_port_t));
+ if (hport == NULL) {
+ return NGX_ERROR;
+ }
- ls->handler = ngx_http_init_connection;
+ ls->servers = hport;
- cscf = in_addr[a].core_srv_conf;
- ls->pool_size = cscf->connection_pool_size;
- ls->post_accept_timeout = cscf->client_header_timeout;
+ hport->port = ntohs(port->port);
- clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];
+ for (i = ls->addr_text.len - 1; i; i--) {
- ls->log = *clcf->err_log;
- ls->log.data = &ls->addr_text;
- ls->log.handler = ngx_accept_log_error;
+ if (ls->addr_text.data[i] == ':') {
+ hport->port_text.len = ls->addr_text.len - i;
+ hport->port_text.data = &ls->addr_text.data[i];
+ break;
+ }
+ }
-#if (NGX_WIN32)
- {
- ngx_iocp_conf_t *iocpcf;
+ if (a == last - 1) {
+ hport->naddrs = last;
- iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module);
- if (iocpcf->acceptex_read) {
- ls->post_accept_buffer_size = cscf->client_header_buffer_size;
+ } else {
+ hport->naddrs = 1;
+ a = 0;
}
+
+ switch (ls->sockaddr->sa_family) {
+
+#if (NGX_HAVE_INET6)
+ case AF_INET6:
+ if (ngx_http_add_addrs6(cf, hport, addr) != NGX_OK) {
+ return NGX_ERROR;
+ }
+ break;
+#endif
+ default: /* AF_INET */
+ if (ngx_http_add_addrs(cf, hport, addr) != NGX_OK) {
+ return NGX_ERROR;
+ }
+ break;
}
+
+ addr++;
+ last--;
+ }
+
+ return NGX_OK;
+}
+
+
+static ngx_listening_t *
+ngx_http_add_listening(ngx_conf_t *cf, ngx_http_conf_addr_t *addr)
+{
+ ngx_listening_t *ls;
+ struct sockaddr *sa;
+ ngx_http_core_loc_conf_t *clcf;
+ ngx_http_core_srv_conf_t *cscf;
+ u_char text[NGX_SOCKADDR_STRLEN];
+
+ ls = ngx_array_push(&cf->cycle->listening);
+ if (ls == NULL) {
+ return NULL;
+ }
+
+ ngx_memzero(ls, sizeof(ngx_listening_t));
+
+ sa = ngx_palloc(cf->pool, addr->socklen);
+ if (sa == NULL) {
+ return NULL;
+ }
+
+ ngx_memcpy(sa, addr->sockaddr, addr->socklen);
+
+ ls->sockaddr = sa;
+ ls->socklen = addr->socklen;
+
+ ls->addr_text.len = ngx_sock_ntop(sa, text, NGX_SOCKADDR_STRLEN, 1);
+
+ ls->addr_text.data = ngx_pnalloc(cf->pool, ls->addr_text.len);
+ if (ls->addr_text.data == NULL) {
+ return NULL;
+ }
+
+ ngx_memcpy(ls->addr_text.data, text, ls->addr_text.len);
+
+ ls->fd = (ngx_socket_t) -1;
+ ls->type = SOCK_STREAM;
+
+ switch (ls->sockaddr->sa_family) {
+#if (NGX_HAVE_INET6)
+ case AF_INET6:
+ ls->addr_text_max_len = NGX_INET6_ADDRSTRLEN;
+ break;
#endif
+ case AF_INET:
+ ls->addr_text_max_len = NGX_INET_ADDRSTRLEN;
+ break;
+ default:
+ ls->addr_text_max_len = NGX_SOCKADDR_STRLEN;
+ break;
+ }
+
+ ls->addr_ntop = 1;
+
+ ls->handler = ngx_http_init_connection;
- ls->backlog = in_addr[a].listen_conf->backlog;
- ls->rcvbuf = in_addr[a].listen_conf->rcvbuf;
- ls->sndbuf = in_addr[a].listen_conf->sndbuf;
+ cscf = addr->core_srv_conf;
+ ls->pool_size = cscf->connection_pool_size;
+ ls->post_accept_timeout = cscf->client_header_timeout;
+
+ clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];
+
+ ls->log = *clcf->err_log;
+ ls->log.data = &ls->addr_text;
+ ls->log.handler = ngx_accept_log_error;
+
+#if (NGX_WIN32)
+ {
+ ngx_iocp_conf_t *iocpcf;
+
+ iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module);
+ if (iocpcf->acceptex_read) {
+ ls->post_accept_buffer_size = cscf->client_header_buffer_size;
+ }
+ }
+#endif
+
+ ls->backlog = addr->listen_conf->backlog;
+ ls->rcvbuf = addr->listen_conf->rcvbuf;
+ ls->sndbuf = addr->listen_conf->sndbuf;
#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
- ls->accept_filter = in_addr[a].listen_conf->accept_filter;
+ ls->accept_filter = addr->listen_conf->accept_filter;
#endif
#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
- ls->deferred_accept = in_addr[a].listen_conf->deferred_accept;
+ ls->deferred_accept = addr->listen_conf->deferred_accept;
#endif
- hip = ngx_palloc(cf->pool, sizeof(ngx_http_in_port_t));
- if (hip == NULL) {
- return NGX_ERROR;
- }
+ return ls;
+}
- hip->port = in_port->port;
- hip->port_text.data = ngx_pnalloc(cf->pool, 7);
- if (hip->port_text.data == NULL) {
- return NGX_ERROR;
- }
+static ngx_int_t
+ngx_http_add_addrs(ngx_conf_t *cf, ngx_http_port_t *hport,
+ ngx_http_conf_addr_t *addr)
+{
+ ngx_uint_t i;
+ ngx_http_in_addr_t *addrs;
+ struct sockaddr_in *sin;
+ ngx_http_virtual_names_t *vn;
- ls->servers = hip;
+ hport->addrs = ngx_pcalloc(cf->pool,
+ hport->naddrs * sizeof(ngx_http_in_addr_t));
+ if (hport->addrs == NULL) {
+ return NGX_ERROR;
+ }
- hip->port_text.len = ngx_sprintf(hip->port_text.data, ":%d", hip->port)
- - hip->port_text.data;
+ addrs = hport->addrs;
- in_addr = in_port->addrs.elts;
+ for (i = 0; i < hport->naddrs; i++) {
- if (in_addr[a].bind && in_addr[a].addr != INADDR_ANY) {
- hip->naddrs = 1;
- done = 0;
+ sin = (struct sockaddr_in *) addr[i].sockaddr;
+ addrs[i].addr = sin->sin_addr.s_addr;
+ addrs[i].conf.core_srv_conf = addr[i].core_srv_conf;
+#if (NGX_HTTP_SSL)
+ addrs[i].conf.ssl = addr[i].ssl;
+#endif
- } else if (in_port->addrs.nelts > 1
- && in_addr[last - 1].addr == INADDR_ANY)
+ if (addr[i].hash.buckets == NULL
+ && (addr[i].wc_head == NULL
+ || addr[i].wc_head->hash.buckets == NULL)
+ && (addr[i].wc_head == NULL
+ || addr[i].wc_head->hash.buckets == NULL))
{
- hip->naddrs = last;
- done = 1;
-
- } else {
- hip->naddrs = 1;
- done = 0;
+ continue;
}
- hip->addrs = ngx_pcalloc(cf->pool,
- hip->naddrs * sizeof(ngx_http_in_addr_t));
- if (hip->addrs == NULL) {
+ vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));
+ if (vn == NULL) {
return NGX_ERROR;
}
- for (i = 0; i < hip->naddrs; i++) {
- hip->addrs[i].addr = in_addr[i].addr;
- hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf;
+ addrs[i].conf.virtual_names = vn;
-#if (NGX_HTTP_SSL)
- hip->addrs[i].ssl = in_addr[i].ssl;
+ vn->names.hash = addr[i].hash;
+ vn->names.wc_head = addr[i].wc_head;
+ vn->names.wc_tail = addr[i].wc_tail;
+#if (NGX_PCRE)
+ vn->nregex = addr[i].nregex;
+ vn->regex = addr[i].regex;
#endif
+ }
- if (in_addr[i].hash.buckets == NULL
- && (in_addr[i].wc_head == NULL
- || in_addr[i].wc_head->hash.buckets == NULL)
- && (in_addr[i].wc_head == NULL
- || in_addr[i].wc_head->hash.buckets == NULL))
- {
- continue;
- }
+ return NGX_OK;
+}
- vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));
- if (vn == NULL) {
- return NGX_ERROR;
- }
- hip->addrs[i].virtual_names = vn;
- vn->names.hash = in_addr[i].hash;
- vn->names.wc_head = in_addr[i].wc_head;
- vn->names.wc_tail = in_addr[i].wc_tail;
-#if (NGX_PCRE)
- vn->nregex = in_addr[i].nregex;
- vn->regex = in_addr[i].regex;
+#if (NGX_HAVE_INET6)
+
+static ngx_int_t
+ngx_http_add_addrs6(ngx_conf_t *cf, ngx_http_port_t *hport,
+ ngx_http_conf_addr_t *addr)
+{
+ ngx_uint_t i;
+ ngx_http_in6_addr_t *addrs6;
+ struct sockaddr_in6 *sin6;
+ ngx_http_virtual_names_t *vn;
+
+ hport->addrs = ngx_pcalloc(cf->pool,
+ hport->naddrs * sizeof(ngx_http_in6_addr_t));
+ if (hport->addrs == NULL) {
+ return NGX_ERROR;
+ }
+
+ addrs6 = hport->addrs;
+
+ for (i = 0; i < hport->naddrs; i++) {
+
+ sin6 = (struct sockaddr_in6 *) addr[i].sockaddr;
+ addrs6[i].addr6 = sin6->sin6_addr;
+ addrs6[i].conf.core_srv_conf = addr[i].core_srv_conf;
+#if (NGX_HTTP_SSL)
+ addrs6[i].conf.ssl = addr[i].ssl;
#endif
+
+ if (addr[i].hash.buckets == NULL
+ && (addr[i].wc_head == NULL
+ || addr[i].wc_head->hash.buckets == NULL)
+ && (addr[i].wc_head == NULL
+ || addr[i].wc_head->hash.buckets == NULL))
+ {
+ continue;
}
- if (done) {
- return NGX_OK;
+ vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));
+ if (vn == NULL) {
+ return NGX_ERROR;
}
- in_addr++;
- in_port->addrs.elts = in_addr;
- last--;
+ addrs6[i].conf.virtual_names = vn;
- a = 0;
+ vn->names.hash = addr[i].hash;
+ vn->names.wc_head = addr[i].wc_head;
+ vn->names.wc_tail = addr[i].wc_tail;
+#if (NGX_PCRE)
+ vn->nregex = addr[i].nregex;
+ vn->regex = addr[i].regex;
+#endif
}
return NGX_OK;
}
+#endif
+
char *
ngx_http_types_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)