[nginx] Geo: fixed handling of AF_UNIX client addresses (ticket #1684).

Maxim Dounin mdounin at mdounin.ru
Fri Dec 14 16:53:29 UTC 2018


details:   https://hg.nginx.org/nginx/rev/286ae954009d
branches:  
changeset: 7430:286ae954009d
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Fri Dec 14 18:11:06 2018 +0300
description:
Geo: fixed handling of AF_UNIX client addresses (ticket #1684).

Previously, AF_UNIX client addresses were handled as AF_INET, leading
to unexpected results.

diffstat:

 src/http/modules/ngx_http_geo_module.c |  13 +++++++++++++
 src/stream/ngx_stream_geo_module.c     |  13 +++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)

diffs (60 lines):

diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c
--- a/src/http/modules/ngx_http_geo_module.c
+++ b/src/http/modules/ngx_http_geo_module.c
@@ -215,6 +215,13 @@ ngx_http_geo_cidr_variable(ngx_http_requ
         break;
 #endif
 
+#if (NGX_HAVE_UNIX_DOMAIN)
+    case AF_UNIX:
+        vv = (ngx_http_variable_value_t *)
+                  ngx_radix32tree_find(ctx->u.trees.tree, INADDR_NONE);
+        break;
+#endif
+
     default: /* AF_INET */
         sin = (struct sockaddr_in *) addr.sockaddr;
         inaddr = ntohl(sin->sin_addr.s_addr);
@@ -277,6 +284,12 @@ ngx_http_geo_range_variable(ngx_http_req
             break;
 #endif
 
+#if (NGX_HAVE_UNIX_DOMAIN)
+        case AF_UNIX:
+            inaddr = INADDR_NONE;
+            break;
+#endif
+
         default: /* AF_INET */
             sin = (struct sockaddr_in *) addr.sockaddr;
             inaddr = ntohl(sin->sin_addr.s_addr);
diff --git a/src/stream/ngx_stream_geo_module.c b/src/stream/ngx_stream_geo_module.c
--- a/src/stream/ngx_stream_geo_module.c
+++ b/src/stream/ngx_stream_geo_module.c
@@ -206,6 +206,13 @@ ngx_stream_geo_cidr_variable(ngx_stream_
         break;
 #endif
 
+#if (NGX_HAVE_UNIX_DOMAIN)
+    case AF_UNIX:
+        vv = (ngx_stream_variable_value_t *)
+                  ngx_radix32tree_find(ctx->u.trees.tree, INADDR_NONE);
+        break;
+#endif
+
     default: /* AF_INET */
         sin = (struct sockaddr_in *) addr.sockaddr;
         inaddr = ntohl(sin->sin_addr.s_addr);
@@ -268,6 +275,12 @@ ngx_stream_geo_range_variable(ngx_stream
             break;
 #endif
 
+#if (NGX_HAVE_UNIX_DOMAIN)
+        case AF_UNIX:
+            inaddr = INADDR_NONE;
+            break;
+#endif
+
         default: /* AF_INET */
             sin = (struct sockaddr_in *) addr.sockaddr;
             inaddr = ntohl(sin->sin_addr.s_addr);


More information about the nginx-devel mailing list