mirror of
https://github.com/nginx/nginx.git
synced 2024-12-15 05:09:06 +08:00
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
This commit is contained in:
parent
72d4e5d793
commit
5b201ac31f
@ -529,13 +529,9 @@ ngx_int_t
|
|||||||
ngx_parse_addr_port(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text,
|
ngx_parse_addr_port(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
u_char *p, *last;
|
u_char *p, *last;
|
||||||
size_t plen;
|
size_t plen;
|
||||||
ngx_int_t rc, port;
|
ngx_int_t rc, port;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rc = ngx_parse_addr(pool, addr, text, len);
|
rc = ngx_parse_addr(pool, addr, text, len);
|
||||||
|
|
||||||
@ -585,20 +581,7 @@ ngx_parse_addr_port(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (addr->sockaddr->sa_family) {
|
ngx_inet_set_port(addr->sockaddr, port);
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = (struct sockaddr_in6 *) addr->sockaddr;
|
|
||||||
sin6->sin6_port = htons((in_port_t) port);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default: /* AF_INET */
|
|
||||||
sin = (struct sockaddr_in *) addr->sockaddr;
|
|
||||||
sin->sin_port = htons((in_port_t) port);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
@ -1356,3 +1339,61 @@ ngx_cmp_sockaddr(struct sockaddr *sa1, socklen_t slen1,
|
|||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
in_port_t
|
||||||
|
ngx_inet_get_port(struct sockaddr *sa)
|
||||||
|
{
|
||||||
|
struct sockaddr_in *sin;
|
||||||
|
#if (NGX_HAVE_INET6)
|
||||||
|
struct sockaddr_in6 *sin6;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch (sa->sa_family) {
|
||||||
|
|
||||||
|
#if (NGX_HAVE_INET6)
|
||||||
|
case AF_INET6:
|
||||||
|
sin6 = (struct sockaddr_in6 *) sa;
|
||||||
|
return ntohs(sin6->sin6_port);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (NGX_HAVE_UNIX_DOMAIN)
|
||||||
|
case AF_UNIX:
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
default: /* AF_INET */
|
||||||
|
sin = (struct sockaddr_in *) sa;
|
||||||
|
return ntohs(sin->sin_port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ngx_inet_set_port(struct sockaddr *sa, in_port_t port)
|
||||||
|
{
|
||||||
|
struct sockaddr_in *sin;
|
||||||
|
#if (NGX_HAVE_INET6)
|
||||||
|
struct sockaddr_in6 *sin6;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch (sa->sa_family) {
|
||||||
|
|
||||||
|
#if (NGX_HAVE_INET6)
|
||||||
|
case AF_INET6:
|
||||||
|
sin6 = (struct sockaddr_in6 *) sa;
|
||||||
|
sin6->sin6_port = htons(port);
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (NGX_HAVE_UNIX_DOMAIN)
|
||||||
|
case AF_UNIX:
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
default: /* AF_INET */
|
||||||
|
sin = (struct sockaddr_in *) sa;
|
||||||
|
sin->sin_port = htons(port);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -121,6 +121,8 @@ ngx_int_t ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u);
|
|||||||
ngx_int_t ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u);
|
ngx_int_t ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u);
|
||||||
ngx_int_t ngx_cmp_sockaddr(struct sockaddr *sa1, socklen_t slen1,
|
ngx_int_t ngx_cmp_sockaddr(struct sockaddr *sa1, socklen_t slen1,
|
||||||
struct sockaddr *sa2, socklen_t slen2, ngx_uint_t cmp_port);
|
struct sockaddr *sa2, socklen_t slen2, ngx_uint_t cmp_port);
|
||||||
|
in_port_t ngx_inet_get_port(struct sockaddr *sa);
|
||||||
|
void ngx_inet_set_port(struct sockaddr *sa, in_port_t port);
|
||||||
|
|
||||||
|
|
||||||
#endif /* _NGX_INET_H_INCLUDED_ */
|
#endif /* _NGX_INET_H_INCLUDED_ */
|
||||||
|
@ -141,19 +141,11 @@ ngx_proxy_protocol_write(ngx_connection_t *c, u_char *buf, u_char *last)
|
|||||||
|
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
buf = ngx_cpymem(buf, "PROXY TCP4 ", sizeof("PROXY TCP4 ") - 1);
|
buf = ngx_cpymem(buf, "PROXY TCP4 ", sizeof("PROXY TCP4 ") - 1);
|
||||||
|
|
||||||
port = ntohs(((struct sockaddr_in *) c->sockaddr)->sin_port);
|
|
||||||
lport = ntohs(((struct sockaddr_in *) c->local_sockaddr)->sin_port);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
#if (NGX_HAVE_INET6)
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
buf = ngx_cpymem(buf, "PROXY TCP6 ", sizeof("PROXY TCP6 ") - 1);
|
buf = ngx_cpymem(buf, "PROXY TCP6 ", sizeof("PROXY TCP6 ") - 1);
|
||||||
|
|
||||||
port = ntohs(((struct sockaddr_in6 *) c->sockaddr)->sin6_port);
|
|
||||||
lport = ntohs(((struct sockaddr_in6 *) c->local_sockaddr)->sin6_port);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -169,5 +161,8 @@ ngx_proxy_protocol_write(ngx_connection_t *c, u_char *buf, u_char *last)
|
|||||||
buf += ngx_sock_ntop(c->local_sockaddr, c->local_socklen, buf, last - buf,
|
buf += ngx_sock_ntop(c->local_sockaddr, c->local_socklen, buf, last - buf,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
port = ngx_inet_get_port(c->sockaddr);
|
||||||
|
lport = ngx_inet_get_port(c->local_sockaddr);
|
||||||
|
|
||||||
return ngx_slprintf(buf, last, " %ui %ui" CRLF, port, lport);
|
return ngx_slprintf(buf, last, " %ui %ui" CRLF, port, lport);
|
||||||
}
|
}
|
||||||
|
@ -2996,12 +2996,8 @@ ngx_resolver_srv_names_handler(ngx_resolver_ctx_t *cctx)
|
|||||||
ngx_addr_t *addrs;
|
ngx_addr_t *addrs;
|
||||||
ngx_resolver_t *r;
|
ngx_resolver_t *r;
|
||||||
ngx_sockaddr_t *sockaddr;
|
ngx_sockaddr_t *sockaddr;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
ngx_resolver_ctx_t *ctx;
|
ngx_resolver_ctx_t *ctx;
|
||||||
ngx_resolver_srv_name_t *srv;
|
ngx_resolver_srv_name_t *srv;
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
r = cctx->resolver;
|
r = cctx->resolver;
|
||||||
ctx = cctx->data;
|
ctx = cctx->data;
|
||||||
@ -3045,17 +3041,7 @@ ngx_resolver_srv_names_handler(ngx_resolver_ctx_t *cctx)
|
|||||||
ngx_memcpy(&sockaddr[i], cctx->addrs[i].sockaddr,
|
ngx_memcpy(&sockaddr[i], cctx->addrs[i].sockaddr,
|
||||||
addrs[i].socklen);
|
addrs[i].socklen);
|
||||||
|
|
||||||
switch (addrs[i].sockaddr->sa_family) {
|
ngx_inet_set_port(addrs[i].sockaddr, srv->port);
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = (struct sockaddr_in6 *) addrs[i].sockaddr;
|
|
||||||
sin6->sin6_port = htons(srv->port);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default: /* AF_INET */
|
|
||||||
sin = (struct sockaddr_in *) addrs[i].sockaddr;
|
|
||||||
sin->sin_port = htons(srv->port);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
srv->addrs = addrs;
|
srv->addrs = addrs;
|
||||||
|
@ -920,7 +920,6 @@ ngx_ssl_ocsp_resolve_handler(ngx_resolver_ctx_t *resolve)
|
|||||||
|
|
||||||
u_char *p;
|
u_char *p;
|
||||||
size_t len;
|
size_t len;
|
||||||
in_port_t port;
|
|
||||||
socklen_t socklen;
|
socklen_t socklen;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
struct sockaddr *sockaddr;
|
struct sockaddr *sockaddr;
|
||||||
@ -962,8 +961,6 @@ ngx_ssl_ocsp_resolve_handler(ngx_resolver_ctx_t *resolve)
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
port = htons(ctx->port);
|
|
||||||
|
|
||||||
for (i = 0; i < resolve->naddrs; i++) {
|
for (i = 0; i < resolve->naddrs; i++) {
|
||||||
|
|
||||||
socklen = resolve->addrs[i].socklen;
|
socklen = resolve->addrs[i].socklen;
|
||||||
@ -974,16 +971,7 @@ ngx_ssl_ocsp_resolve_handler(ngx_resolver_ctx_t *resolve)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngx_memcpy(sockaddr, resolve->addrs[i].sockaddr, socklen);
|
ngx_memcpy(sockaddr, resolve->addrs[i].sockaddr, socklen);
|
||||||
|
ngx_inet_set_port(sockaddr, ctx->port);
|
||||||
switch (sockaddr->sa_family) {
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
((struct sockaddr_in6 *) sockaddr)->sin6_port = port;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default: /* AF_INET */
|
|
||||||
((struct sockaddr_in *) sockaddr)->sin_port = port;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->addrs[i].sockaddr = sockaddr;
|
ctx->addrs[i].sockaddr = sockaddr;
|
||||||
ctx->addrs[i].socklen = socklen;
|
ctx->addrs[i].socklen = socklen;
|
||||||
|
@ -138,10 +138,6 @@ ngx_http_realip_handler(ngx_http_request_t *r)
|
|||||||
ngx_list_part_t *part;
|
ngx_list_part_t *part;
|
||||||
ngx_table_elt_t *header;
|
ngx_table_elt_t *header;
|
||||||
ngx_connection_t *c;
|
ngx_connection_t *c;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
ngx_http_realip_ctx_t *ctx;
|
ngx_http_realip_ctx_t *ctx;
|
||||||
ngx_http_realip_loc_conf_t *rlcf;
|
ngx_http_realip_loc_conf_t *rlcf;
|
||||||
|
|
||||||
@ -242,21 +238,7 @@ found:
|
|||||||
!= NGX_DECLINED)
|
!= NGX_DECLINED)
|
||||||
{
|
{
|
||||||
if (rlcf->type == NGX_HTTP_REALIP_PROXY) {
|
if (rlcf->type == NGX_HTTP_REALIP_PROXY) {
|
||||||
|
ngx_inet_set_port(addr.sockaddr, c->proxy_protocol_port);
|
||||||
switch (addr.sockaddr->sa_family) {
|
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = (struct sockaddr_in6 *) addr.sockaddr;
|
|
||||||
sin6->sin6_port = htons(c->proxy_protocol_port);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default: /* AF_INET */
|
|
||||||
sin = (struct sockaddr_in *) addr.sockaddr;
|
|
||||||
sin->sin_port = htons(c->proxy_protocol_port);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ngx_http_realip_set_addr(r, &addr);
|
return ngx_http_realip_set_addr(r, &addr);
|
||||||
@ -578,24 +560,7 @@ ngx_http_realip_remote_port_variable(ngx_http_request_t *r,
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (sa->sa_family) {
|
port = ngx_inet_get_port(sa);
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
port = ntohs(((struct sockaddr_in6 *) sa)->sin6_port);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (NGX_HAVE_UNIX_DOMAIN)
|
|
||||||
case AF_UNIX:
|
|
||||||
port = 0;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default: /* AF_INET */
|
|
||||||
port = ntohs(((struct sockaddr_in *) sa)->sin_port);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (port > 0 && port < 65536) {
|
if (port > 0 && port < 65536) {
|
||||||
v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
|
v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
|
||||||
|
@ -1144,12 +1144,8 @@ ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
|
|||||||
in_port_t p;
|
in_port_t p;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
struct sockaddr *sa;
|
struct sockaddr *sa;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
ngx_http_conf_port_t *port;
|
ngx_http_conf_port_t *port;
|
||||||
ngx_http_core_main_conf_t *cmcf;
|
ngx_http_core_main_conf_t *cmcf;
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
||||||
|
|
||||||
@ -1162,27 +1158,7 @@ ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
sa = &lsopt->sockaddr.sockaddr;
|
sa = &lsopt->sockaddr.sockaddr;
|
||||||
|
p = ngx_inet_get_port(sa);
|
||||||
switch (sa->sa_family) {
|
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = &lsopt->sockaddr.sockaddr_in6;
|
|
||||||
p = sin6->sin6_port;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (NGX_HAVE_UNIX_DOMAIN)
|
|
||||||
case AF_UNIX:
|
|
||||||
p = 0;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default: /* AF_INET */
|
|
||||||
sin = &lsopt->sockaddr.sockaddr_in;
|
|
||||||
p = sin->sin_port;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
port = cmcf->ports->elts;
|
port = cmcf->ports->elts;
|
||||||
for (i = 0; i < cmcf->ports->nelts; i++) {
|
for (i = 0; i < cmcf->ports->nelts; i++) {
|
||||||
|
@ -161,10 +161,6 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||||||
ngx_connection_t *c;
|
ngx_connection_t *c;
|
||||||
ngx_http_core_loc_conf_t *clcf;
|
ngx_http_core_loc_conf_t *clcf;
|
||||||
ngx_http_core_srv_conf_t *cscf;
|
ngx_http_core_srv_conf_t *cscf;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
u_char addr[NGX_SOCKADDR_STRLEN];
|
u_char addr[NGX_SOCKADDR_STRLEN];
|
||||||
|
|
||||||
if (r->header_sent) {
|
if (r->header_sent) {
|
||||||
@ -333,24 +329,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (c->local_sockaddr->sa_family) {
|
port = ngx_inet_get_port(c->local_sockaddr);
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
|
|
||||||
port = ntohs(sin6->sin6_port);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#if (NGX_HAVE_UNIX_DOMAIN)
|
|
||||||
case AF_UNIX:
|
|
||||||
port = 0;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default: /* AF_INET */
|
|
||||||
sin = (struct sockaddr_in *) c->local_sockaddr;
|
|
||||||
port = ntohs(sin->sin_port);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
len += sizeof("Location: https://") - 1
|
len += sizeof("Location: https://") - 1
|
||||||
+ host.len
|
+ host.len
|
||||||
|
@ -354,16 +354,7 @@ ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngx_memcpy(sockaddr, ur->addrs[i].sockaddr, socklen);
|
ngx_memcpy(sockaddr, ur->addrs[i].sockaddr, socklen);
|
||||||
|
ngx_inet_set_port(sockaddr, ur->port);
|
||||||
switch (sockaddr->sa_family) {
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
((struct sockaddr_in6 *) sockaddr)->sin6_port = htons(ur->port);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default: /* AF_INET */
|
|
||||||
((struct sockaddr_in *) sockaddr)->sin_port = htons(ur->port);
|
|
||||||
}
|
|
||||||
|
|
||||||
p = ngx_pnalloc(r->pool, NGX_SOCKADDR_STRLEN);
|
p = ngx_pnalloc(r->pool, NGX_SOCKADDR_STRLEN);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
|
@ -1201,11 +1201,7 @@ static ngx_int_t
|
|||||||
ngx_http_variable_remote_port(ngx_http_request_t *r,
|
ngx_http_variable_remote_port(ngx_http_request_t *r,
|
||||||
ngx_http_variable_value_t *v, uintptr_t data)
|
ngx_http_variable_value_t *v, uintptr_t data)
|
||||||
{
|
{
|
||||||
ngx_uint_t port;
|
ngx_uint_t port;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
v->len = 0;
|
v->len = 0;
|
||||||
v->valid = 1;
|
v->valid = 1;
|
||||||
@ -1217,26 +1213,7 @@ ngx_http_variable_remote_port(ngx_http_request_t *r,
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (r->connection->sockaddr->sa_family) {
|
port = ngx_inet_get_port(r->connection->sockaddr);
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = (struct sockaddr_in6 *) r->connection->sockaddr;
|
|
||||||
port = ntohs(sin6->sin6_port);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (NGX_HAVE_UNIX_DOMAIN)
|
|
||||||
case AF_UNIX:
|
|
||||||
port = 0;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default: /* AF_INET */
|
|
||||||
sin = (struct sockaddr_in *) r->connection->sockaddr;
|
|
||||||
port = ntohs(sin->sin_port);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (port > 0 && port < 65536) {
|
if (port > 0 && port < 65536) {
|
||||||
v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
|
v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
|
||||||
@ -1321,11 +1298,7 @@ static ngx_int_t
|
|||||||
ngx_http_variable_server_port(ngx_http_request_t *r,
|
ngx_http_variable_server_port(ngx_http_request_t *r,
|
||||||
ngx_http_variable_value_t *v, uintptr_t data)
|
ngx_http_variable_value_t *v, uintptr_t data)
|
||||||
{
|
{
|
||||||
ngx_uint_t port;
|
ngx_uint_t port;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
v->len = 0;
|
v->len = 0;
|
||||||
v->valid = 1;
|
v->valid = 1;
|
||||||
@ -1341,26 +1314,7 @@ ngx_http_variable_server_port(ngx_http_request_t *r,
|
|||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (r->connection->local_sockaddr->sa_family) {
|
port = ngx_inet_get_port(r->connection->local_sockaddr);
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr;
|
|
||||||
port = ntohs(sin6->sin6_port);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (NGX_HAVE_UNIX_DOMAIN)
|
|
||||||
case AF_UNIX:
|
|
||||||
port = 0;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default: /* AF_INET */
|
|
||||||
sin = (struct sockaddr_in *) r->connection->local_sockaddr;
|
|
||||||
port = ntohs(sin->sin_port);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (port > 0 && port < 65536) {
|
if (port > 0 && port < 65536) {
|
||||||
v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
|
v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
|
||||||
|
@ -137,10 +137,6 @@ ngx_http_v2_header_filter(ngx_http_request_t *r)
|
|||||||
ngx_http_v2_out_frame_t *frame;
|
ngx_http_v2_out_frame_t *frame;
|
||||||
ngx_http_core_loc_conf_t *clcf;
|
ngx_http_core_loc_conf_t *clcf;
|
||||||
ngx_http_core_srv_conf_t *cscf;
|
ngx_http_core_srv_conf_t *cscf;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
u_char addr[NGX_SOCKADDR_STRLEN];
|
u_char addr[NGX_SOCKADDR_STRLEN];
|
||||||
|
|
||||||
static const u_char nginx[5] = "\x84\xaa\x63\x55\xe7";
|
static const u_char nginx[5] = "\x84\xaa\x63\x55\xe7";
|
||||||
@ -280,24 +276,7 @@ ngx_http_v2_header_filter(ngx_http_request_t *r)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (fc->local_sockaddr->sa_family) {
|
port = ngx_inet_get_port(fc->local_sockaddr);
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = (struct sockaddr_in6 *) fc->local_sockaddr;
|
|
||||||
port = ntohs(sin6->sin6_port);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
#if (NGX_HAVE_UNIX_DOMAIN)
|
|
||||||
case AF_UNIX:
|
|
||||||
port = 0;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
default: /* AF_INET */
|
|
||||||
sin = (struct sockaddr_in *) fc->local_sockaddr;
|
|
||||||
port = ntohs(sin->sin_port);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
location.len = sizeof("https://") - 1 + host.len
|
location.len = sizeof("https://") - 1 + host.len
|
||||||
+ r->headers_out.location->value.len;
|
+ r->headers_out.location->value.len;
|
||||||
|
@ -228,35 +228,11 @@ ngx_mail_add_ports(ngx_conf_t *cf, ngx_array_t *ports,
|
|||||||
in_port_t p;
|
in_port_t p;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
struct sockaddr *sa;
|
struct sockaddr *sa;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
ngx_mail_conf_port_t *port;
|
ngx_mail_conf_port_t *port;
|
||||||
ngx_mail_conf_addr_t *addr;
|
ngx_mail_conf_addr_t *addr;
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sa = &listen->sockaddr.sockaddr;
|
sa = &listen->sockaddr.sockaddr;
|
||||||
|
p = ngx_inet_get_port(sa);
|
||||||
switch (sa->sa_family) {
|
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = &listen->sockaddr.sockaddr_in6;
|
|
||||||
p = sin6->sin6_port;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (NGX_HAVE_UNIX_DOMAIN)
|
|
||||||
case AF_UNIX:
|
|
||||||
p = 0;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default: /* AF_INET */
|
|
||||||
sin = &listen->sockaddr.sockaddr_in;
|
|
||||||
p = sin->sin_port;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
port = ports->elts;
|
port = ports->elts;
|
||||||
for (i = 0; i < ports->nelts; i++) {
|
for (i = 0; i < ports->nelts; i++) {
|
||||||
|
@ -462,15 +462,11 @@ static void
|
|||||||
ngx_mail_auth_http_process_headers(ngx_mail_session_t *s,
|
ngx_mail_auth_http_process_headers(ngx_mail_session_t *s,
|
||||||
ngx_mail_auth_http_ctx_t *ctx)
|
ngx_mail_auth_http_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
u_char *p;
|
u_char *p;
|
||||||
time_t timer;
|
time_t timer;
|
||||||
size_t len, size;
|
size_t len, size;
|
||||||
ngx_int_t rc, port, n;
|
ngx_int_t rc, port, n;
|
||||||
ngx_addr_t *peer;
|
ngx_addr_t *peer;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ngx_log_debug0(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
|
ngx_log_debug0(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
|
||||||
"mail auth http process headers");
|
"mail auth http process headers");
|
||||||
@ -813,20 +809,7 @@ ngx_mail_auth_http_process_headers(ngx_mail_session_t *s,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (peer->sockaddr->sa_family) {
|
ngx_inet_set_port(peer->sockaddr, port);
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = (struct sockaddr_in6 *) peer->sockaddr;
|
|
||||||
sin6->sin6_port = htons((in_port_t) port);
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default: /* AF_INET */
|
|
||||||
sin = (struct sockaddr_in *) peer->sockaddr;
|
|
||||||
sin->sin_port = htons((in_port_t) port);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
len = ctx->addr.len + 1 + ctx->port.len;
|
len = ctx->addr.len + 1 + ctx->port.len;
|
||||||
|
|
||||||
|
@ -243,35 +243,11 @@ ngx_stream_add_ports(ngx_conf_t *cf, ngx_array_t *ports,
|
|||||||
in_port_t p;
|
in_port_t p;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
struct sockaddr *sa;
|
struct sockaddr *sa;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
ngx_stream_conf_port_t *port;
|
ngx_stream_conf_port_t *port;
|
||||||
ngx_stream_conf_addr_t *addr;
|
ngx_stream_conf_addr_t *addr;
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sa = &listen->sockaddr.sockaddr;
|
sa = &listen->sockaddr.sockaddr;
|
||||||
|
p = ngx_inet_get_port(sa);
|
||||||
switch (sa->sa_family) {
|
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = &listen->sockaddr.sockaddr_in6;
|
|
||||||
p = sin6->sin6_port;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (NGX_HAVE_UNIX_DOMAIN)
|
|
||||||
case AF_UNIX:
|
|
||||||
p = 0;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default: /* AF_INET */
|
|
||||||
sin = &listen->sockaddr.sockaddr_in;
|
|
||||||
p = sin->sin_port;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
port = ports->elts;
|
port = ports->elts;
|
||||||
for (i = 0; i < ports->nelts; i++) {
|
for (i = 0; i < ports->nelts; i++) {
|
||||||
|
@ -446,12 +446,8 @@ static ngx_int_t
|
|||||||
ngx_stream_proxy_set_local(ngx_stream_session_t *s, ngx_stream_upstream_t *u,
|
ngx_stream_proxy_set_local(ngx_stream_session_t *s, ngx_stream_upstream_t *u,
|
||||||
ngx_stream_upstream_local_t *local)
|
ngx_stream_upstream_local_t *local)
|
||||||
{
|
{
|
||||||
ngx_addr_t *addr;
|
ngx_addr_t *addr;
|
||||||
ngx_connection_t *c;
|
ngx_connection_t *c;
|
||||||
struct sockaddr_in *sin;
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (local == NULL) {
|
if (local == NULL) {
|
||||||
u->peer.local = NULL;
|
u->peer.local = NULL;
|
||||||
@ -484,21 +480,7 @@ ngx_stream_proxy_set_local(ngx_stream_session_t *s, ngx_stream_upstream_t *u,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngx_memcpy(addr->sockaddr, c->sockaddr, c->socklen);
|
ngx_memcpy(addr->sockaddr, c->sockaddr, c->socklen);
|
||||||
|
ngx_inet_set_port(addr->sockaddr, 0);
|
||||||
switch (addr->sockaddr->sa_family) {
|
|
||||||
|
|
||||||
case AF_INET:
|
|
||||||
sin = (struct sockaddr_in *) addr->sockaddr;
|
|
||||||
sin->sin_port = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
#if (NGX_HAVE_INET6)
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = (struct sockaddr_in6 *) addr->sockaddr;
|
|
||||||
sin6->sin6_port = 0;
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
addr->name = c->addr_text;
|
addr->name = c->addr_text;
|
||||||
u->peer.local = addr;
|
u->peer.local = addr;
|
||||||
|
Loading…
Reference in New Issue
Block a user