Commit 240e53b1 authored by Mark Andrews's avatar Mark Andrews

2396. [bug] Don't set SO_REUSEADDR for randomized ports.

                        [RT #18336]
part 2
parent 5df5127a
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dighost.c,v 1.310 2008/07/22 03:43:03 marka Exp $ */
/* $Id: dighost.c,v 1.311 2008/07/23 23:27:54 marka Exp $ */
/*! \file
* \note
......@@ -2236,7 +2236,8 @@ send_tcp_connect(dig_query_t *query) {
sockcount++;
debug("sockcount=%d", sockcount);
if (specified_source)
result = isc_socket_bind(query->sock, &bind_address, 1);
result = isc_socket_bind(query->sock, &bind_address,
ISC_SOCKET_REUSEADDRESS);
else {
if ((isc_sockaddr_pf(&query->sockaddr) == AF_INET) &&
have_ipv4)
......@@ -2290,8 +2291,8 @@ send_udp(dig_query_t *query) {
sockcount++;
debug("sockcount=%d", sockcount);
if (specified_source) {
result = isc_socket_bind(query->sock,
&bind_address, 1);
result = isc_socket_bind(query->sock, &bind_address,
ISC_SOCKET_REUSEADDRESS);
} else {
isc_sockaddr_anyofpf(&bind_any,
isc_sockaddr_pf(&query->sockaddr));
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: controlconf.c,v 1.59 2008/07/22 03:43:04 marka Exp $ */
/* $Id: controlconf.c,v 1.60 2008/07/23 23:27:54 marka Exp $ */
/*! \file */
......@@ -1149,8 +1149,8 @@ add_listener(ns_controls_t *cp, controllistener_t **listenerp,
isc_socket_setname(listener->sock, "control", NULL);
if (result == ISC_R_SUCCESS)
result = isc_socket_bind(listener->sock,
&listener->address, 1);
result = isc_socket_bind(listener->sock, &listener->address,
ISC_SOCKET_REUSEADDRESS);
if (result == ISC_R_SUCCESS && type == isc_sockettype_unix) {
listener->perm = cfg_obj_asuint32(cfg_tuple_get(control,
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: interfacemgr.c,v 1.92 2008/07/22 23:47:04 tbox Exp $ */
/* $Id: interfacemgr.c,v 1.93 2008/07/23 23:27:54 marka Exp $ */
/*! \file */
......@@ -308,7 +308,8 @@ ns_interface_accepttcp(ns_interface_t *ifp) {
#ifndef ISC_ALLOW_MAPPED
isc_socket_ipv6only(ifp->tcpsocket, ISC_TRUE);
#endif
result = isc_socket_bind(ifp->tcpsocket, &ifp->addr, 1);
result = isc_socket_bind(ifp->tcpsocket, &ifp->addr,
ISC_SOCKET_REUSEADDRESS);
if (result != ISC_R_SUCCESS) {
isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
"binding TCP socket: %s",
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: lwresd.c,v 1.57 2008/07/22 23:47:04 tbox Exp $ */
/* $Id: lwresd.c,v 1.58 2008/07/23 23:27:54 marka Exp $ */
/*! \file
* \brief
......@@ -576,7 +576,8 @@ listener_bind(ns_lwreslistener_t *listener, isc_sockaddr_t *address) {
return (result);
}
result = isc_socket_bind(sock, &listener->address, 1);
result = isc_socket_bind(sock, &listener->address,
ISC_SOCKET_REUSEADDRESS);
if (result != ISC_R_SUCCESS) {
char socktext[ISC_SOCKADDR_FORMATSIZE];
isc_sockaddr_format(&listener->address, socktext,
......
......@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: statschannel.c,v 1.12 2008/07/22 03:43:04 marka Exp $ */
/* $Id: statschannel.c,v 1.13 2008/07/23 23:27:54 marka Exp $ */
/*! \file */
......@@ -919,7 +919,7 @@ add_listener(ns_server_t *server, ns_statschannel_t **listenerp,
isc_socket_ipv6only(sock, ISC_TRUE);
#endif
result = isc_socket_bind(sock, addr, 1);
result = isc_socket_bind(sock, addr, ISC_SOCKET_REUSEADDRESS);
if (result != ISC_R_SUCCESS)
goto cleanup;
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rndc.c,v 1.120 2008/07/22 23:47:04 tbox Exp $ */
/* $Id: rndc.c,v 1.121 2008/07/23 23:27:54 marka Exp $ */
/*! \file */
......@@ -400,10 +400,10 @@ rndc_startconnect(isc_sockaddr_t *addr, isc_task_t *task) {
DO("create socket", isc_socket_create(socketmgr, pf, type, &sock));
switch (isc_sockaddr_pf(addr)) {
case AF_INET:
DO("bind socket", isc_socket_bind(sock, &local4, 1));
DO("bind socket", isc_socket_bind(sock, &local4, 0));
break;
case AF_INET6:
DO("bind socket", isc_socket_bind(sock, &local6, 1));
DO("bind socket", isc_socket_bind(sock, &local6, 0));
break;
default:
break;
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: sock_test.c,v 1.54 2008/07/22 23:47:04 tbox Exp $ */
/* $Id: sock_test.c,v 1.55 2008/07/23 23:27:54 marka Exp $ */
#include <config.h>
......@@ -321,7 +321,7 @@ main(int argc, char *argv[]) {
}
RUNTIME_CHECK(isc_socket_create(socketmgr, pf, isc_sockettype_tcp,
&so1) == ISC_R_SUCCESS);
result = isc_socket_bind(so1, &sockaddr, 1);
result = isc_socket_bind(so1, &sockaddr, ISC_SOCKET_REUSEADDRESS);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_socket_listen(so1, 0) == ISC_R_SUCCESS);
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dispatch.c,v 1.148 2008/07/22 03:43:04 marka Exp $ */
/* $Id: dispatch.c,v 1.149 2008/07/23 23:27:54 marka Exp $ */
/*! \file */
......@@ -304,7 +304,7 @@ static isc_result_t qid_allocate(dns_dispatchmgr_t *mgr, unsigned int buckets,
isc_boolean_t needaddrtable);
static void qid_destroy(isc_mem_t *mctx, dns_qid_t **qidp);
static isc_result_t open_socket(isc_socketmgr_t *mgr, isc_sockaddr_t *local,
int reuseaddr, isc_socket_t **sockp);
unsigned int options, isc_socket_t **sockp);
static isc_boolean_t portavailable(dns_dispatchmgr_t *mgr, isc_socket_t *sock,
isc_sockaddr_t *sockaddrp);
......@@ -1586,8 +1586,8 @@ destroy_mgr(dns_dispatchmgr_t **mgrp) {
}
static isc_result_t
open_socket(isc_socketmgr_t *mgr, isc_sockaddr_t *local, int reuseaddr,
isc_socket_t **sockp)
open_socket(isc_socketmgr_t *mgr, isc_sockaddr_t *local,
unsigned int options, isc_socket_t **sockp)
{
isc_socket_t *sock;
isc_result_t result;
......@@ -1608,7 +1608,7 @@ open_socket(isc_socketmgr_t *mgr, isc_sockaddr_t *local, int reuseaddr,
#ifndef ISC_ALLOW_MAPPED
isc_socket_ipv6only(sock, ISC_TRUE);
#endif
result = isc_socket_bind(sock, local, reuseaddr);
result = isc_socket_bind(sock, local, options);
if (result != ISC_R_SUCCESS) {
if (*sockp == NULL)
isc_socket_detach(&sock);
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: xfrin.c,v 1.159 2008/07/22 23:47:04 tbox Exp $ */
/* $Id: xfrin.c,v 1.160 2008/07/23 23:27:54 marka Exp $ */
/*! \file */
......@@ -873,7 +873,8 @@ xfrin_start(dns_xfrin_ctx_t *xfr) {
&xfr->socket));
isc_socket_setname(xfr->socket, "xfrin", NULL);
#ifndef BROKEN_TCP_BIND_BEFORE_CONNECT
CHECK(isc_socket_bind(xfr->socket, &xfr->sourceaddr, 1));
CHECK(isc_socket_bind(xfr->socket, &xfr->sourceaddr,
ISC_SOCKET_REUSEADDRESS));
#endif
CHECK(isc_socket_connect(xfr->socket, &xfr->masteraddr, xfr->task,
xfrin_connect_done, xfr));
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: socket.h,v 1.79 2008/07/22 03:43:04 marka Exp $ */
/* $Id: socket.h,v 1.80 2008/07/23 23:27:54 marka Exp $ */
#ifndef ISC_SOCKET_H
#define ISC_SOCKET_H 1
......@@ -78,6 +78,12 @@ ISC_LANG_BEGINDECLS
*/
#define ISC_SOCKET_MAXSCATTERGATHER 8
/*%
* In isc_socket_bind() set socket option SO_REUSEADDR prior to calling
* bind() if a non zero port is specified (AF_INET and AF_INET6).
*/
#define ISC_SOCKET_REUSEADDRESS 0x01U
/***
*** Types
***/
......@@ -406,7 +412,8 @@ isc_socket_close(isc_socket_t *sock);
*/
isc_result_t
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *addressp, int reuseaddr);
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *addressp,
unsigned int options);
/*%<
* Bind 'socket' to '*addressp'.
*
......@@ -416,8 +423,6 @@ isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *addressp, int reuseaddr);
*
* \li 'addressp' points to a valid isc_sockaddr.
*
* \li 'reuseaddr' asks to set SO_REUSEADDR (if the port is not 0).
* Returns:
*
* \li ISC_R_SUCCESS
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: socket.c,v 1.290 2008/07/22 03:43:04 marka Exp $ */
/* $Id: socket.c,v 1.291 2008/07/23 23:27:54 marka Exp $ */
/*! \file */
......@@ -4170,7 +4170,8 @@ isc_socket_permunix(isc_sockaddr_t *sockaddr, isc_uint32_t perm,
}
isc_result_t
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr, int reuseaddr) {
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr,
unsigned int options) {
char strbuf[ISC_STRERRORSIZE];
int on = 1;
......@@ -4189,7 +4190,7 @@ isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr, int reuseaddr) {
if (sock->pf == AF_UNIX)
goto bind_socket;
#endif
if (reuseaddr &&
if ((options & ISC_SOCKET_REUSEADDRESS) != 0 &&
isc_sockaddr_getport(sockaddr) != (in_port_t)0 &&
setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on,
sizeof(on)) < 0) {
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: socket.c,v 1.59 2008/07/22 03:43:04 marka Exp $ */
/* $Id: socket.c,v 1.60 2008/07/23 23:27:54 marka Exp $ */
/* This code has been rewritten to take advantage of Windows Sockets
* I/O Completion Ports and Events. I/O Completion Ports is ONLY
......@@ -3308,7 +3308,8 @@ isc_socket_sendto2(isc_socket_t *sock, isc_region_t *region,
}
isc_result_t
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr, int reuseaddr) {
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr,
unsigned int options) {
int bind_errno;
char strbuf[ISC_STRERRORSIZE];
int on = 1;
......@@ -3324,7 +3325,7 @@ isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr, int reuseaddr) {
/*
* Only set SO_REUSEADDR when we want a specific port.
*/
if (reuseaddr &&
if ((options & ISC_SOCKET_REUSEADDRESS) != 0 &&
isc_sockaddr_getport(sockaddr) != (in_port_t)0 &&
setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on,
sizeof(on)) < 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment