Welcome! Log In Create A New Profile

Advanced

[nginx] Set IP_BIND_ADDRESS_NO_PORT socket option for upstream sockets.

Andrei Belov
June 20, 2016 03:50AM
details: http://hg.nginx.org/nginx/rev/2c7b488a61fb
branches:
changeset: 6592:2c7b488a61fb
user: Andrei Belov <defan@nginx.com>
date: Mon Jun 20 10:41:17 2016 +0300
description:
Set IP_BIND_ADDRESS_NO_PORT socket option for upstream sockets.

diffstat:

auto/unix | 13 +++++++++++++
src/event/ngx_event_connect.c | 26 ++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)

diffs (59 lines):

diff -r 04d8d1f85649 -r 2c7b488a61fb auto/unix
--- a/auto/unix Wed Jun 15 21:05:30 2016 +0100
+++ b/auto/unix Mon Jun 20 10:41:17 2016 +0300
@@ -341,6 +341,19 @@ ngx_feature_test="setsockopt(0, SOL_SOCK
. auto/feature


+# Linux IP_BIND_ADDRESS_NO_PORT
+
+ngx_feature="IP_BIND_ADDRESS_NO_PORT"
+ngx_feature_name="NGX_HAVE_IP_BIND_ADDRESS_NO_PORT"
+ngx_feature_run=no
+ngx_feature_incs="#include <sys/socket.h>
+ #include <netinet/in.h>"
+ngx_feature_path=
+ngx_feature_libs=
+ngx_feature_test="setsockopt(0, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT, NULL, 0)"
+. auto/feature
+
+
# Linux transparent proxying

ngx_feature="IP_TRANSPARENT"
diff -r 04d8d1f85649 -r 2c7b488a61fb src/event/ngx_event_connect.c
--- a/src/event/ngx_event_connect.c Wed Jun 15 21:05:30 2016 +0100
+++ b/src/event/ngx_event_connect.c Mon Jun 20 10:41:17 2016 +0300
@@ -87,6 +87,32 @@ ngx_event_connect_peer(ngx_peer_connecti
}
#endif

+#if (NGX_HAVE_IP_BIND_ADDRESS_NO_PORT)
+
+ if (pc->sockaddr->sa_family != AF_UNIX) {
+ static int bind_address_no_port = 1;
+
+ if (bind_address_no_port) {
+ if (setsockopt(s, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT,
+ (const void *) &bind_address_no_port,
+ sizeof(int)) == -1)
+ {
+ err = ngx_socket_errno;
+
+ if (err != NGX_EOPNOTSUPP && err != NGX_ENOPROTOOPT) {
+ ngx_log_error(NGX_LOG_ALERT, pc->log, err,
+ "setsockopt(IP_BIND_ADDRESS_NO_PORT) "
+ "failed, ignored");
+
+ } else {
+ bind_address_no_port = 0;
+ }
+ }
+ }
+ }
+
+#endif
+
if (bind(s, pc->local->sockaddr, pc->local->socklen) == -1) {
ngx_log_error(NGX_LOG_CRIT, pc->log, ngx_socket_errno,
"bind(%V) failed", &pc->local->name);

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Set IP_BIND_ADDRESS_NO_PORT socket option for upstream sockets.

Andrei Belov 2092 June 20, 2016 03:50AM

AW: [nginx] Set IP_BIND_ADDRESS_NO_PORT socket option for upstream sockets.

Lukas Tribus 393 July 05, 2016 06:38PM

AW: [nginx] Set IP_BIND_ADDRESS_NO_PORT socket option for upstream sockets.

Lukas Tribus 351 July 05, 2016 06:50PM

Re: [nginx] Set IP_BIND_ADDRESS_NO_PORT socket option for upstream sockets.

Andrei Belov 382 July 06, 2016 12:00AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 297
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready