Welcome! Log In Create A New Profile

Advanced

Re: resolver: A vs AAAA

December 14, 2016 11:26AM
On Wed, Dec 14, 2016 at 06:05:48PM +0300, Dmitry Sivachenko wrote:
> Добрый день,
>
> Использую proxy_pass http://some.ip:80 (nginx 1.6.2)
>
> some.ip имеет как A-запись, так и AAAA-запись.
>
> На машине настроен приоритет IPv6 при резолвинге (ip6addrctl_policy="ipv6_prefer" для FreeBSD).
> Но nginx посылает запросы на IPv4-адрес, а не IPv6.
>
> Как правильно это исправить? (не хочется к конфиг прописывать ip-адрес).

Сейчас после резолвинга сначала отдаются IPv4-адреса, а затем IPv6-адреса.
Впоследствии, если результат резолвинга закэширован, адреса ротируются.

С таким патчем становится возможным контролировать приоритет IPv6 над
IPv4 в выдаче адресов.

# HG changeset patch
# User Ruslan Ermilov <ru@nginx.com>
# Date 1481732592 -10800
# Wed Dec 14 19:23:12 2016 +0300
# Node ID bfebe45e2dbb952a25655ead0c7a9a80a50b34e0
# Parent 7bb061c9e1dcc160d80b81c5b07ae5ff83ff221a
Resolver: allow controlling preference of IPv6 over IPv4.

diff --git a/src/core/ngx_resolver.c b/src/core/ngx_resolver.c
--- a/src/core/ngx_resolver.c
+++ b/src/core/ngx_resolver.c
@@ -233,6 +233,12 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_
} else if (ngx_strcmp(&names[i].data[5], "off") == 0) {
r->ipv6 = 0;

+ } else if (ngx_strcmp(&names[i].data[5], "primary") == 0) {
+ r->ipv6 = 2;
+
+ } else if (ngx_strcmp(&names[i].data[5], "backup") == 0) {
+ r->ipv6 = 3;
+
} else {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"invalid parameter: %V", &names[i]);
@@ -4177,6 +4183,16 @@ ngx_resolver_export(ngx_resolver_t *r, n
i = 0;
d = rotate ? ngx_random() % n : 0;

+#if (NGX_HAVE_INET6)
+ if (r->ipv6 == 2) {
+ /* prefer IPv6 */
+ d = rn->naddrs6;
+ } else if (r->ipv6 == 3) {
+ /* prefer IPv4 */
+ d = 0;
+ }
+#endif
+
if (rn->naddrs) {
j = rotate ? ngx_random() % rn->naddrs : 0;

diff --git a/src/core/ngx_resolver.h b/src/core/ngx_resolver.h
--- a/src/core/ngx_resolver.h
+++ b/src/core/ngx_resolver.h
@@ -176,7 +176,7 @@ struct ngx_resolver_s {
ngx_queue_t addr_expire_queue;

#if (NGX_HAVE_INET6)
- ngx_uint_t ipv6; /* unsigned ipv6:1; */
+ ngx_uint_t ipv6;
ngx_rbtree_t addr6_rbtree;
ngx_rbtree_node_t addr6_sentinel;
ngx_queue_t addr6_resend_queue;
_______________________________________________
nginx-ru mailing list
nginx-ru@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-ru
Subject Author Posted

resolver: A vs AAAA

Dmitry Sivachenko December 14, 2016 10:08AM

Re: resolver: A vs AAAA

ru@nginx.com December 14, 2016 11:26AM

Re: resolver: A vs AAAA

Maxim Dounin December 14, 2016 12:00PM

Re: resolver: A vs AAAA

Dmitry Sivachenko December 14, 2016 12:08PM

Re: resolver: A vs AAAA

Maxim Dounin December 14, 2016 12:52PM

Re: resolver: A vs AAAA

Dmitry Sivachenko December 14, 2016 01:40PM

Re: resolver: A vs AAAA

ru@nginx.com December 15, 2016 01:18AM

Re: resolver: A vs AAAA

Dmitry Sivachenko December 15, 2016 03:50AM

Re: resolver: A vs AAAA

Dmitry Morozovsky December 15, 2016 04:14AM

Re: resolver: A vs AAAA

Dmitry Morozovsky December 15, 2016 04:14AM

Re: resolver: A vs AAAA

Andrey Kopeyko December 15, 2016 05:28AM

Re: resolver: A vs AAAA

Dmitry Sivachenko December 14, 2016 01:50PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 95
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready