comparison src/event/ngx_event_connect.c @ 6592:2c7b488a61fb

Set IP_BIND_ADDRESS_NO_PORT socket option for upstream sockets.
author Andrei Belov <defan@nginx.com>
date Mon, 20 Jun 2016 10:41:17 +0300
parents 1d0e03db9f8e
children e778fe9a4463
comparison
equal deleted inserted replaced
6591:04d8d1f85649 6592:2c7b488a61fb
85 goto failed; 85 goto failed;
86 } 86 }
87 } 87 }
88 #endif 88 #endif
89 89
90 #if (NGX_HAVE_IP_BIND_ADDRESS_NO_PORT)
91
92 if (pc->sockaddr->sa_family != AF_UNIX) {
93 static int bind_address_no_port = 1;
94
95 if (bind_address_no_port) {
96 if (setsockopt(s, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT,
97 (const void *) &bind_address_no_port,
98 sizeof(int)) == -1)
99 {
100 err = ngx_socket_errno;
101
102 if (err != NGX_EOPNOTSUPP && err != NGX_ENOPROTOOPT) {
103 ngx_log_error(NGX_LOG_ALERT, pc->log, err,
104 "setsockopt(IP_BIND_ADDRESS_NO_PORT) "
105 "failed, ignored");
106
107 } else {
108 bind_address_no_port = 0;
109 }
110 }
111 }
112 }
113
114 #endif
115
90 if (bind(s, pc->local->sockaddr, pc->local->socklen) == -1) { 116 if (bind(s, pc->local->sockaddr, pc->local->socklen) == -1) {
91 ngx_log_error(NGX_LOG_CRIT, pc->log, ngx_socket_errno, 117 ngx_log_error(NGX_LOG_CRIT, pc->log, ngx_socket_errno,
92 "bind(%V) failed", &pc->local->name); 118 "bind(%V) failed", &pc->local->name);
93 119
94 goto failed; 120 goto failed;