[nginx] Stream: the "accept_filter" parameter of the "listen" directive.

Sergey Kandaurov pluknet at nginx.com
Fri Mar 22 11:17:20 UTC 2024


details:   https://hg.nginx.org/nginx/rev/c78790d3d061
branches:  
changeset: 9222:c78790d3d061
user:      Sergey Kandaurov <pluknet at nginx.com>
date:      Fri Mar 22 14:53:19 2024 +0400
description:
Stream: the "accept_filter" parameter of the "listen" directive.

The FreeBSD accept filters support.

diffstat:

 src/stream/ngx_stream.c             |   4 ++++
 src/stream/ngx_stream.h             |   4 ++++
 src/stream/ngx_stream_core_module.c |  20 ++++++++++++++++++++
 3 files changed, 28 insertions(+), 0 deletions(-)

diffs (65 lines):

diff -r bed832296f5d -r c78790d3d061 src/stream/ngx_stream.c
--- a/src/stream/ngx_stream.c	Fri Mar 22 14:53:19 2024 +0400
+++ b/src/stream/ngx_stream.c	Fri Mar 22 14:53:19 2024 +0400
@@ -1021,6 +1021,10 @@ ngx_stream_add_listening(ngx_conf_t *cf,
     ls->keepcnt = addr->opt.tcp_keepcnt;
 #endif
 
+#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
+    ls->accept_filter = addr->opt.accept_filter;
+#endif
+
 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
     ls->deferred_accept = addr->opt.deferred_accept;
 #endif
diff -r bed832296f5d -r c78790d3d061 src/stream/ngx_stream.h
--- a/src/stream/ngx_stream.h	Fri Mar 22 14:53:19 2024 +0400
+++ b/src/stream/ngx_stream.h	Fri Mar 22 14:53:19 2024 +0400
@@ -70,6 +70,10 @@ typedef struct {
     int                            tcp_keepintvl;
     int                            tcp_keepcnt;
 #endif
+
+#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
+    char                          *accept_filter;
+#endif
 } ngx_stream_listen_opt_t;
 
 
diff -r bed832296f5d -r c78790d3d061 src/stream/ngx_stream_core_module.c
--- a/src/stream/ngx_stream_core_module.c	Fri Mar 22 14:53:19 2024 +0400
+++ b/src/stream/ngx_stream_core_module.c	Fri Mar 22 14:53:19 2024 +0400
@@ -1015,6 +1015,20 @@ ngx_stream_core_listen(ngx_conf_t *cf, n
             continue;
         }
 
+        if (ngx_strncmp(value[i].data, "accept_filter=", 14) == 0) {
+#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
+            lsopt.accept_filter = (char *) &value[i].data[14];
+            lsopt.set = 1;
+            lsopt.bind = 1;
+#else
+            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                               "accept filters \"%V\" are not supported "
+                               "on this platform, ignored",
+                               &value[i]);
+#endif
+            continue;
+        }
+
         if (ngx_strcmp(value[i].data, "deferred") == 0) {
 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
             lsopt.deferred_accept = 1;
@@ -1186,6 +1200,12 @@ ngx_stream_core_listen(ngx_conf_t *cf, n
             return "\"backlog\" parameter is incompatible with \"udp\"";
         }
 
+#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
+        if (lsopt.accept_filter) {
+            return "\"accept_filter\" parameter is incompatible with \"udp\"";
+        }
+#endif
+
 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
         if (lsopt.deferred_accept) {
             return "\"deferred\" parameter is incompatible with \"udp\"";


More information about the nginx-devel mailing list