]> git.kaiwu.me - nginx.git/commitdiff
listen setfib=X
authorIgor Sysoev <igor@sysoev.ru>
Mon, 5 Jul 2010 13:49:16 +0000 (13:49 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 5 Jul 2010 13:49:16 +0000 (13:49 +0000)
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

index 3d490255f32b346c5b2d6a9da103e75fe8ca4699..ecd8e7fb4238d2643e9924afb5a80f7786b93780 100644 (file)
@@ -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
 
index 4a90b61203032d75042b182c587a84e9b7981cd0..c495edd52416d1ded45015798757163324c1319b 100644 (file)
@@ -74,6 +74,10 @@ ngx_create_listening(ngx_conf_t *cf, void *sockaddr, socklen_t socklen)
     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 *cycle)
             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_cycle_t *cycle)
             }
         }
 
+#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;
index 1810daca0fe171269fdfaa26d1af0d78f85a1a95..3837fd2551d17161082be35a30a83123b10699a7 100644 (file)
@@ -69,6 +69,9 @@ struct ngx_listening_s {
     char               *accept_filter;
 #endif
 #endif
+#if (NGX_HAVE_SETFIB)
+    int                 setfib;
+#endif
 
 };
 
index 84867887d2fd04428579b2156079600eeb4fda92..9f9294ce53135cb222659659347634ad094278bc 100644 (file)
@@ -1720,6 +1720,10 @@ ngx_http_add_listening(ngx_conf_t *cf, ngx_http_conf_addr_t *addr)
     ls->ipv6only = addr->opt.ipv6only;
 #endif
 
+#if (NGX_HAVE_SETFIB)
+    ls->setfib = addr->opt.setfib;
+#endif
+
     return ls;
 }
 
index 1654510be0581044952cbbae6db0555ff9653e2f..0296d00bf266985f3530084bcac5b858b9c8194a 100644 (file)
@@ -2992,6 +2992,9 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
         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_command_t *cmd, void *conf)
     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_command_t *cmd, void *conf)
             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;
index 2f49202c34f711148a60d97c3927418d4c36cadf..82c12084580891c3f0428709ed8f3fc709913427 100644 (file)
@@ -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;