[PATCH 6 of 6] Stream: the "setfib" parameter of the "listen" directive

Sergey Kandaurov pluknet at nginx.com
Fri Dec 15 15:37:49 UTC 2023


# HG changeset patch
# User Sergey Kandaurov <pluknet at nginx.com>
# Date 1702651328 -14400
#      Fri Dec 15 18:42:08 2023 +0400
# Node ID 219662ea1613ab68d4d5d4085394bba75993ae42
# Parent  9be627b7a3a35c00be13332f553e2d3b778877ae
Stream: the "setfib" parameter of the "listen" directive.

The FreeBSD SO_SETFIB support.

diff --git a/src/stream/ngx_stream.c b/src/stream/ngx_stream.c
--- a/src/stream/ngx_stream.c
+++ b/src/stream/ngx_stream.c
@@ -1033,6 +1033,10 @@ ngx_stream_add_listening(ngx_conf_t *cf,
     ls->ipv6only = addr->opt.ipv6only;
 #endif
 
+#if (NGX_HAVE_SETFIB)
+    ls->setfib = addr->opt.setfib;
+#endif
+
 #if (NGX_HAVE_TCP_FASTOPEN)
     ls->fastopen = addr->opt.fastopen;
 #endif
diff --git a/src/stream/ngx_stream.h b/src/stream/ngx_stream.h
--- a/src/stream/ngx_stream.h
+++ b/src/stream/ngx_stream.h
@@ -62,6 +62,9 @@ typedef struct {
     int                            rcvbuf;
     int                            sndbuf;
     int                            type;
+#if (NGX_HAVE_SETFIB)
+    int                            setfib;
+#endif
 #if (NGX_HAVE_TCP_FASTOPEN)
     int                            fastopen;
 #endif
diff --git a/src/stream/ngx_stream_core_module.c b/src/stream/ngx_stream_core_module.c
--- a/src/stream/ngx_stream_core_module.c
+++ b/src/stream/ngx_stream_core_module.c
@@ -892,6 +892,9 @@ ngx_stream_core_listen(ngx_conf_t *cf, n
     lsopt.type = SOCK_STREAM;
     lsopt.rcvbuf = -1;
     lsopt.sndbuf = -1;
+#if (NGX_HAVE_SETFIB)
+    lsopt.setfib = -1;
+#endif
 #if (NGX_HAVE_TCP_FASTOPEN)
     lsopt.fastopen = -1;
 #endif
@@ -921,6 +924,22 @@ ngx_stream_core_listen(ngx_conf_t *cf, n
             continue;
         }
 
+#if (NGX_HAVE_SETFIB)
+        if (ngx_strncmp(value[i].data, "setfib=", 7) == 0) {
+            lsopt.setfib = ngx_atoi(value[i].data + 7, value[i].len - 7);
+            lsopt.set = 1;
+            lsopt.bind = 1;
+
+            if (lsopt.setfib == NGX_ERROR) {
+                ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                                   "invalid setfib \"%V\"", &value[i]);
+                return NGX_CONF_ERROR;
+            }
+
+            continue;
+        }
+#endif
+
 #if (NGX_HAVE_TCP_FASTOPEN)
         if (ngx_strncmp(value[i].data, "fastopen=", 9) == 0) {
             lsopt.fastopen = ngx_atoi(value[i].data + 9, value[i].len - 9);


More information about the nginx-devel mailing list