[PATCH] Add ipv4=off option in resolver like ipv6=off (ticket #1330)
Roman Arutyunyan
arut at nginx.com
Tue Jun 28 12:10:11 UTC 2022
On Wed, Jun 15, 2022 at 02:27:27PM +0400, Sergey Kandaurov wrote:
>
> > On 23 Feb 2022, at 08:09, Ruslan Ermilov <ru at 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 at 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 at 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
More information about the nginx-devel
mailing list