Welcome! Log In Create A New Profile

Advanced

Re: [PATCH] Add ipv4=off option in resolver like ipv6=off (ticket #1330)

Roman Arutyunyan
June 28, 2022 08:12AM
On Wed, Jun 15, 2022 at 02:27:27PM +0400, Sergey Kandaurov wrote:
>
> > On 23 Feb 2022, at 08:09, Ruslan Ermilov <ru@nginx.com> wrote:
> >
> > On Wed, Feb 16, 2022 at 03:30:55PM +0300, Ruslan Ermilov wrote:
> >> Hi Lukas,
> >>
> >> On Wed, Jan 19, 2022 at 07:47:44PM +0100, Lukas Lihotzki via nginx-devel wrote:
> >>> # HG changeset patch
> >>> # User Lukas Lihotzki <lukas@lihotzki.de>
> >>> # Date 1642618053 -3600
> >>> # Wed Jan 19 19:47:33 2022 +0100
> >>> # Node ID e9f06dc2d6a4a1aa61c15009b84ceedcaf5983b2
> >>> # Parent aeab41dfd2606dd36cabbf01f1472726e27e8aea
> >>> Add ipv4=off option in resolver like ipv6=off (ticket #1330).
> >>>
> >>> IPv6-only hosts (ticket #1330) and upstreams with IPv6 bind address
> >>> (ticket #1535) need to disable resolving to IPv4 addresses.
> >>>
> >>> Ticket #1330 mentions ipv4=off is the proper fix.
> >>
> >> There's a number of problems in your patch. Please try this
> >> one instead:
> >>
> >> # HG changeset patch
> >> # User Ruslan Ermilov <ru@nginx.com>
> >> # Date 1644873563 -10800
> >> # Tue Feb 15 00:19:23 2022 +0300
> >> # Node ID 5d2cb60a78dd32a10a0010ccff39974fd7605867
> >> # Parent 1add55d236522616ce34ffaa4dc697a76d3d41a4
> >> The "ipv4=" parameter of the "resolver" directive (ticket #2196).
> >>
> >> When set to "off", only IPv6 addresses will be resolved, and no
> >> A queries are ever sent.
> >>
> >> 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
> >> @@ -157,6 +157,8 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_
> >> cln->handler = ngx_resolver_cleanup;
> >> cln->data = r;
> >>
> >> + r->ipv4 = 1;
> >> +
> >> ngx_rbtree_init(&r->name_rbtree, &r->name_sentinel,
> >> ngx_resolver_rbtree_insert_value);
> >>
> >> @@ -225,6 +227,23 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_
> >> }
> >>
> >> #if (NGX_HAVE_INET6)
> >> + if (ngx_strncmp(names[i].data, "ipv4=", 5) == 0) {
> >> +
> >> + if (ngx_strcmp(&names[i].data[5], "on") == 0) {
> >> + r->ipv4 = 1;
> >> +
> >> + } else if (ngx_strcmp(&names[i].data[5], "off") == 0) {
> >> + r->ipv4 = 0;
> >> +
> >> + } else {
> >> + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
> >> + "invalid parameter: %V", &names[i]);
> >> + return NULL;
> >> + }
> >> +
> >> + continue;
> >> + }
> >> +
> >> if (ngx_strncmp(names[i].data, "ipv6=", 5) == 0) {
> >>
> >> if (ngx_strcmp(&names[i].data[5], "on") == 0) {
> >
> > Addon to the patch:
> >
> > 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
> > @@ -229,10 +229,12 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_
> > #if (NGX_HAVE_INET6)
> > if (ngx_strncmp(names[i].data, "ipv4=", 5) == 0) {
> >
> > - if (ngx_strcmp(&names[i].data[5], "on") == 0) {
> > + if (ngx_strcasecmp(&names[i].data[5], (u_char *) "on") == 0) {
> > r->ipv4 = 1;
> >
> > - } else if (ngx_strcmp(&names[i].data[5], "off") == 0) {
> > + } else if (ngx_strcasecmp(&names[i].data[5], (u_char *) "off")
> > + == 0)
> > + {
> > r->ipv4 = 0;
> >
> > } else {
> > @@ -246,10 +248,12 @@ ngx_resolver_create(ngx_conf_t *cf, ngx_
> >
> > if (ngx_strncmp(names[i].data, "ipv6=", 5) == 0) {
> >
> > - if (ngx_strcmp(&names[i].data[5], "on") == 0) {
> > + if (ngx_strcasecmp(&names[i].data[5], (u_char *) "on") == 0) {
> > r->ipv6 = 1;
> >
> > - } else if (ngx_strcmp(&names[i].data[5], "off") == 0) {
> > + } else if (ngx_strcasecmp(&names[i].data[5], (u_char *) "off")
> > + == 0)
> > + {
> > r->ipv6 = 0;
> >
> > } else {
> >
>
> I don't see the reasons to make the parameter value case-insensitive.
> Existing parameters in ngx_http_core_module.c take it case-sensitive.
> Otherwise, looks good to me.

I agree. Although ngx_conf_set_flag_slot() treats its argument as
case-insensitive, "listen" directive handler provides a number of
case-sensitive examples.

--
Roman Arutyunyan
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[PATCH] Add ipv4=off option in resolver like ipv6=off (ticket #1330)

Lukas Lihotzki via nginx-devel 1064 January 19, 2022 01:50PM

Re: [PATCH] Add ipv4=off option in resolver like ipv6=off (ticket #1330)

ru@nginx.com 474 February 16, 2022 07:32AM

Re: [PATCH] Add ipv4=off option in resolver like ipv6=off (ticket #1330)

ru@nginx.com 371 February 22, 2022 11:10PM

Re: [PATCH] Add ipv4=off option in resolver like ipv6=off (ticket #1330)

Lukas Lihotzki via nginx-devel 212 May 28, 2022 12:30PM

Re: [PATCH] Add ipv4=off option in resolver like ipv6=off (ticket #1330)

Sergey Kandaurov 236 June 15, 2022 06:28AM

Re: [PATCH] Add ipv4=off option in resolver like ipv6=off (ticket #1330)

Roman Arutyunyan 173 June 28, 2022 08:12AM

Re: [PATCH] The "sort=" parameter of the "resolver" directive

Sergey Kandaurov 187 June 16, 2022 11:18AM

Re: [PATCH] The "sort=" parameter of the "resolver" directive

Roman Arutyunyan 168 June 28, 2022 08:26AM

Re: [PATCH] The "sort=" parameter of the "resolver" directive

Sergey Kandaurov 179 June 28, 2022 12:02PM

Re: [PATCH] The "sort=" parameter of the "resolver" directive

Maxim Dounin 185 June 28, 2022 08:52PM

Re: [PATCH] The "sort=" parameter of the "resolver" directive

Sergey Kandaurov 214 June 30, 2022 12:18PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 304
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready