[Patch] Make resolver port configurable

Sirsiwal, Umesh usirsiwal at verivue.com
Mon Feb 14 23:53:47 MSK 2011


Igor,
Thanks for the feedback. Here is update patch. This does not need a second parameter. Just allows host:port based configuration.

-Umesh
diff -rupN tmp/nginx-0.8.54/src/http/ngx_http_core_module.c nginx-0.8.54/src/http/ngx_http_core_module.c
--- tmp/nginx-0.8.54/src/http/ngx_http_core_module.c    2010-12-14 10:38:42.000000000 +0000
+++ nginx-0.8.54/src/http/ngx_http_core_module.c        2011-02-14 20:42:39.000000000 +0000
@@ -4342,7 +4342,10 @@ ngx_http_core_resolver(ngx_conf_t *cf, n

     ngx_url_t   u;
     ngx_str_t  *value;
-
+    u_char *port, *last;
+    ngx_int_t n;
+    ngx_int_t len;
+
     if (clcf->resolver) {
         return "is duplicate";
     }
@@ -4352,7 +4355,27 @@ ngx_http_core_resolver(ngx_conf_t *cf, n
     ngx_memzero(&u, sizeof(ngx_url_t));

     u.host = value[1];
-    u.port = 53;
+    last = u.host.data + u.host.len;
+    port = ngx_strlchr(u.host.data, last, ':');
+    if(port != NULL){
+      port ++;
+      len = last - port;
+      u.host.len -= len + 1;
+
+      if (len == 0) {
+       ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid port %s", port);
+       return NGX_CONF_ERROR;
+      }
+      n = ngx_atoi(port, len);
+
+      if (n < 1 || n > 65536) {
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid port %s", port);
+
+       return NGX_CONF_ERROR;
+      }
+
+      u.port = (in_port_t) n;
+    }else
+      u.port = 53;

     if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);

> -----Original Message-----
> From: Igor Sysoev [mailto:igor at sysoev.ru]
> Sent: Friday, February 11, 2011 2:50 AM
> To: nginx-devel at nginx.org
> Subject: Re: [Patch] Make resolver port configurable
> 
> On Thu, Feb 10, 2011 at 10:19:39PM -0500, Sirsiwal, Umesh wrote:
> > This path extends existing resolver command to optionally take a
> second parameter. The second parameter can be used to override default
> port 53.
> 
> Thank you for the patch, but a port should be set as "host:port",
> but not as second parameter.
> 
> 
> --
> Igor Sysoev
> http://sysoev.ru/en/
> 
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://nginx.org/mailman/listinfo/nginx-devel



More information about the nginx-devel mailing list