diff options
author | Andrei Belov <defan@nginx.com> | 2016-06-20 10:41:17 +0300 |
---|---|---|
committer | Andrei Belov <defan@nginx.com> | 2016-06-20 10:41:17 +0300 |
commit | 72d4e5d7930a07a8753640061bbe9210c6a1f890 (patch) | |
tree | 5e084ad0920e1d6ce5ebed9c1c4f00fb0b6143f5 /src | |
parent | 4f578bfcab740fcfbbb8824822803ad9b3f176cc (diff) | |
download | nginx-72d4e5d7930a07a8753640061bbe9210c6a1f890.tar.gz nginx-72d4e5d7930a07a8753640061bbe9210c6a1f890.zip |
Set IP_BIND_ADDRESS_NO_PORT socket option for upstream sockets.
Diffstat (limited to 'src')
-rw-r--r-- | src/event/ngx_event_connect.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c index 5de991e07..9a8f4d931 100644 --- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -87,6 +87,32 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc) } #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); |