changeset 3676:4430d110293e

listen setfib=X
author Igor Sysoev <igor@sysoev.ru>
date Mon, 05 Jul 2010 13:49:16 +0000
parents 08d7165b6be1
children 00ec8cd76fb8
files auto/os/features src/core/ngx_connection.c src/core/ngx_connection.h src/http/ngx_http.c src/http/ngx_http_core_module.c src/http/ngx_http_core_module.h
diffstat 6 files changed, 74 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/auto/os/features
+++ b/auto/os/features
@@ -295,6 +295,15 @@ if [ $ngx_found != yes ]; then
     fi
 fi
 
+ngx_feature="SO_SETFIB"
+ngx_feature_name="NGX_HAVE_SETFIB"
+ngx_feature_run=no
+ngx_feature_incs="#include <sys/socket.h>"
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="setsockopt(0, SOL_SOCKET, SO_SETFIB, NULL, 4)"
+. auto/feature
+
 
 if [ $NGX_FILE_AIO = YES ]; then
 
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -74,6 +74,10 @@ ngx_create_listening(ngx_conf_t *cf, voi
     ls->rcvbuf = -1;
     ls->sndbuf = -1;
 
+#if (NGX_HAVE_SETFIB)
+    ls->setfib = -1;
+#endif
+
     return ls;
 }
 
@@ -179,6 +183,25 @@ ngx_set_inherited_sockets(ngx_cycle_t *c
             ls[i].sndbuf = -1;
         }
 
+#if 0
+        /* SO_SETFIB is currently a set only option */
+
+#if (NGX_HAVE_SETFIB)
+
+        if (getsockopt(ls[i].setfib, SOL_SOCKET, SO_SETFIB,
+                       (void *) &ls[i].setfib, &olen)
+            == -1)
+        {
+            ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
+                          "getsockopt(SO_SETFIB) %V failed, ignored",
+                          &ls[i].addr_text);
+
+            ls[i].setfib = -1;
+        }
+
+#endif
+#endif
+
 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
 
         ngx_memzero(&af, sizeof(struct accept_filter_arg));
@@ -473,6 +496,19 @@ ngx_configure_listening_sockets(ngx_cycl
             }
         }
 
+#if (NGX_HAVE_SETFIB)
+        if (ls[i].setfib != -1) {
+            if (setsockopt(ls[i].fd, SOL_SOCKET, SO_SETFIB,
+                           (const void *) &ls[i].setfib, sizeof(int))
+                == -1)
+            {
+                ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
+                              "setsockopt(SO_SETFIB, %d) %V failed, ignored",
+                              ls[i].setfib, &ls[i].addr_text);
+            }
+        }
+#endif
+
 #if 0
         if (1) {
             int tcp_nodelay = 1;
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -69,6 +69,9 @@ struct ngx_listening_s {
     char               *accept_filter;
 #endif
 #endif
+#if (NGX_HAVE_SETFIB)
+    int                 setfib;
+#endif
 
 };
 
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -1720,6 +1720,10 @@ ngx_http_add_listening(ngx_conf_t *cf, n
     ls->ipv6only = addr->opt.ipv6only;
 #endif
 
+#if (NGX_HAVE_SETFIB)
+    ls->setfib = addr->opt.setfib;
+#endif
+
     return ls;
 }
 
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -2992,6 +2992,9 @@ ngx_http_core_merge_srv_conf(ngx_conf_t 
         lsopt.backlog = NGX_LISTEN_BACKLOG;
         lsopt.rcvbuf = -1;
         lsopt.sndbuf = -1;
+#if (NGX_HAVE_SETFIB)
+        lsopt.setfib = -1;
+#endif
         lsopt.wildcard = 1;
 
         (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr,
@@ -3410,6 +3413,9 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
     lsopt.backlog = NGX_LISTEN_BACKLOG;
     lsopt.rcvbuf = -1;
     lsopt.sndbuf = -1;
+#if (NGX_HAVE_SETFIB)
+    lsopt.setfib = -1;
+#endif
     lsopt.wildcard = u.wildcard;
 
     (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.addr,
@@ -3430,6 +3436,19 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
             continue;
         }
 
+#if (NGX_HAVE_SETFIB)
+        if (ngx_strncmp(value[n].data, "setfib=", 7) == 0) {
+            lsopt.setfib = ngx_atoi(value[n].data + 7, value[n].len - 7);
+
+            if (lsopt.setfib == NGX_ERROR || lsopt.setfib == 0) {
+                ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                                   "invalid setfib \"%V\"", &value[n]);
+                return NGX_CONF_ERROR;
+            }
+
+            continue;
+        }
+#endif
         if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
             lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
             lsopt.set = 1;
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -71,6 +71,9 @@ typedef struct {
     int                        backlog;
     int                        rcvbuf;
     int                        sndbuf;
+#if (NGX_HAVE_SETFIB)
+    int                        setfib;
+#endif
 
 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
     char                      *accept_filter;