listen setfib=X
diff --git a/auto/os/features b/auto/os/features index 3d49025..ecd8e7f 100644 --- a/auto/os/features +++ b/auto/os/features
@@ -295,6 +295,15 @@ 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
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 4a90b61..c495edd 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c
@@ -74,6 +74,10 @@ ls->rcvbuf = -1; ls->sndbuf = -1; +#if (NGX_HAVE_SETFIB) + ls->setfib = -1; +#endif + return ls; } @@ -179,6 +183,25 @@ 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 @@ } } +#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;
diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h index 1810dac..3837fd2 100644 --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h
@@ -69,6 +69,9 @@ char *accept_filter; #endif #endif +#if (NGX_HAVE_SETFIB) + int setfib; +#endif };
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index 8486788..9f9294c 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c
@@ -1720,6 +1720,10 @@ ls->ipv6only = addr->opt.ipv6only; #endif +#if (NGX_HAVE_SETFIB) + ls->setfib = addr->opt.setfib; +#endif + return ls; }
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 1654510..0296d00 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c
@@ -2992,6 +2992,9 @@ 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 @@ 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 @@ 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;
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index 2f49202..82c1208 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h
@@ -71,6 +71,9 @@ int backlog; int rcvbuf; int sndbuf; +#if (NGX_HAVE_SETFIB) + int setfib; +#endif #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) char *accept_filter;