]> git.kaiwu.me - nginx.git/commitdiff
Stream: the "accept_filter" parameter of the "listen" directive.
authorSergey Kandaurov <pluknet@nginx.com>
Fri, 22 Mar 2024 10:53:19 +0000 (14:53 +0400)
committerSergey Kandaurov <pluknet@nginx.com>
Fri, 22 Mar 2024 10:53:19 +0000 (14:53 +0400)
The FreeBSD accept filters support.

src/stream/ngx_stream.c
src/stream/ngx_stream.h
src/stream/ngx_stream_core_module.c

index 9a918421311c04aea3bf6acc740229a4a3db9141..e0879d092568f5583d71b77a7e7c0bee39563c3a 100644 (file)
@@ -1021,6 +1021,10 @@ ngx_stream_add_listening(ngx_conf_t *cf, ngx_stream_conf_addr_t *addr)
     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
index 2221a14c943009207221f08c30305ebd5d51be35..888715888e1859bb21bc9d377e703f7c685c4d73 100644 (file)
@@ -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;
 
 
index 4bf0784d53acb624e636b2c86c7d33ebeadbcfdb..df08208a78f64faf9e8833b7d249195d45563b6a 100644 (file)
@@ -1015,6 +1015,20 @@ ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
             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, ngx_command_t *cmd, void *conf)
             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\"";