Commit 9de0f9b0 authored by Mark Andrews's avatar Mark Andrews

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

                        [RT #18336]
parent 2dbc961b
2396. [bug] Don't set SO_REUSEADDR for randomized ports.
[RT #18336]
2395. [port] Avoid warning and no effect from "files unlimited"
on Linux when running as root. [RT #18335]
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dighost.c,v 1.309 2008/04/03 02:01:08 marka Exp $ */
/* $Id: dighost.c,v 1.310 2008/07/22 03:43:03 marka Exp $ */
/*! \file
* \note
......@@ -2236,14 +2236,14 @@ send_tcp_connect(dig_query_t *query) {
sockcount++;
debug("sockcount=%d", sockcount);
if (specified_source)
result = isc_socket_bind(query->sock, &bind_address);
result = isc_socket_bind(query->sock, &bind_address, 1);
else {
if ((isc_sockaddr_pf(&query->sockaddr) == AF_INET) &&
have_ipv4)
isc_sockaddr_any(&bind_any);
else
isc_sockaddr_any6(&bind_any);
result = isc_socket_bind(query->sock, &bind_any);
result = isc_socket_bind(query->sock, &bind_any, 0);
}
check_result(result, "isc_socket_bind");
bringup_timer(query, TCP_TIMEOUT);
......@@ -2290,11 +2290,12 @@ send_udp(dig_query_t *query) {
sockcount++;
debug("sockcount=%d", sockcount);
if (specified_source) {
result = isc_socket_bind(query->sock, &bind_address);
result = isc_socket_bind(query->sock,
&bind_address, 1);
} else {
isc_sockaddr_anyofpf(&bind_any,
isc_sockaddr_pf(&query->sockaddr));
result = isc_socket_bind(query->sock, &bind_any);
result = isc_socket_bind(query->sock, &bind_any, 0);
}
check_result(result, "isc_socket_bind");
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: controlconf.c,v 1.58 2008/01/18 23:46:57 tbox Exp $ */
/* $Id: controlconf.c,v 1.59 2008/07/22 03:43:04 marka Exp $ */
/*! \file */
......@@ -1150,7 +1150,7 @@ add_listener(ns_controls_t *cp, controllistener_t **listenerp,
if (result == ISC_R_SUCCESS)
result = isc_socket_bind(listener->sock,
&listener->address);
&listener->address, 1);
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.90 2007/09/12 01:09:07 each Exp $ */
/* $Id: interfacemgr.c,v 1.91 2008/07/22 03:43:04 marka Exp $ */
/*! \file */
......@@ -308,7 +308,7 @@ 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);
result = isc_socket_bind(ifp->tcpsocket, &ifp->addr, 1);
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.55 2007/06/19 23:46:59 tbox Exp $ */
/* $Id: lwresd.c,v 1.56 2008/07/22 03:43:04 marka Exp $ */
/*! \file
* \brief
......@@ -576,7 +576,7 @@ listener_bind(ns_lwreslistener_t *listener, isc_sockaddr_t *address) {
return (result);
}
result = isc_socket_bind(sock, &listener->address);
result = isc_socket_bind(sock, &listener->address, 1);
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.11 2008/07/17 23:43:26 jinmei Exp $ */
/* $Id: statschannel.c,v 1.12 2008/07/22 03:43:04 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);
result = isc_socket_bind(sock, addr, 1);
if (result != ISC_R_SUCCESS)
goto cleanup;
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rndc.c,v 1.118 2007/06/18 23:47:25 tbox Exp $ */
/* $Id: rndc.c,v 1.119 2008/07/22 03:43:04 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));
DO("bind socket", isc_socket_bind(sock, &local4, 1));
break;
case AF_INET6:
DO("bind socket", isc_socket_bind(sock, &local6));
DO("bind socket", isc_socket_bind(sock, &local6, 1));
break;
default:
break;
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: sig0_test.c,v 1.15 2007/06/19 23:46:59 tbox Exp $ */
/* $Id: sig0_test.c,v 1.16 2008/07/22 03:43:04 marka Exp $ */
#include <config.h>
......@@ -189,7 +189,7 @@ buildquery(void) {
isc_buffer_usedregion(&qbuffer, &r);
isc_sockaddr_any(&sa);
result = isc_socket_bind(s, &sa);
result = isc_socket_bind(s, &sa, 0);
CHECK("isc_socket_bind", result);
result = isc_socket_sendto(s, &r, task1, senddone, NULL, &address,
NULL);
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: sock_test.c,v 1.52 2007/06/19 23:46:59 tbox Exp $ */
/* $Id: sock_test.c,v 1.53 2008/07/22 03:43:04 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);
result = isc_socket_bind(so1, &sockaddr, 1);
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.147 2008/07/18 23:47:01 tbox Exp $ */
/* $Id: dispatch.c,v 1.148 2008/07/22 03:43:04 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,
isc_socket_t **sockp);
int reuseaddr, isc_socket_t **sockp);
static isc_boolean_t portavailable(dns_dispatchmgr_t *mgr, isc_socket_t *sock,
isc_sockaddr_t *sockaddrp);
......@@ -747,7 +747,7 @@ get_dispsocket(dns_dispatch_t *disp, isc_sockaddr_t *dest,
continue;
}
result = open_socket(sockmgr, &localaddr, &sock);
result = open_socket(sockmgr, &localaddr, 0, &sock);
if (result == ISC_R_SUCCESS || result != ISC_R_ADDRINUSE)
break;
}
......@@ -1586,7 +1586,7 @@ destroy_mgr(dns_dispatchmgr_t **mgrp) {
}
static isc_result_t
open_socket(isc_socketmgr_t *mgr, isc_sockaddr_t *local,
open_socket(isc_socketmgr_t *mgr, isc_sockaddr_t *local, int reuseaddr,
isc_socket_t **sockp)
{
isc_socket_t *sock;
......@@ -1608,7 +1608,7 @@ open_socket(isc_socketmgr_t *mgr, isc_sockaddr_t *local,
#ifndef ISC_ALLOW_MAPPED
isc_socket_ipv6only(sock, ISC_TRUE);
#endif
result = isc_socket_bind(sock, local);
result = isc_socket_bind(sock, local, reuseaddr);
if (result != ISC_R_SUCCESS) {
if (*sockp == NULL)
isc_socket_detach(&sock);
......@@ -2535,7 +2535,8 @@ get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp,
DISP_ARC4CTX(disp),
nports)];
isc_sockaddr_setport(&localaddr_bound, prt);
result = open_socket(sockmgr, &localaddr_bound, &sock);
result = open_socket(sockmgr, &localaddr_bound,
0, &sock);
if (result == ISC_R_SUCCESS ||
result != ISC_R_ADDRINUSE) {
disp->localport = prt;
......@@ -2554,7 +2555,7 @@ get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp,
i = 0;
for (j = 0; j < maxtry; j++) {
result = open_socket(sockmgr, localaddr, &sock);
result = open_socket(sockmgr, localaddr, 0, &sock);
if (result != ISC_R_SUCCESS)
goto end;
else if (!anyport)
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: request.c,v 1.81 2008/06/23 23:47:11 tbox Exp $ */
/* $Id: request.c,v 1.82 2008/07/22 03:43:04 marka Exp $ */
/*! \file */
......@@ -528,11 +528,11 @@ create_tcp_dispatch(dns_requestmgr_t *requestmgr, isc_sockaddr_t *srcaddr,
if (srcaddr == NULL) {
isc_sockaddr_anyofpf(&bind_any,
isc_sockaddr_pf(destaddr));
result = isc_socket_bind(socket, &bind_any);
result = isc_socket_bind(socket, &bind_any, 0);
} else {
src = *srcaddr;
isc_sockaddr_setport(&src, 0);
result = isc_socket_bind(socket, &src);
result = isc_socket_bind(socket, &src, 0);
}
if (result != ISC_R_SUCCESS)
goto cleanup;
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: resolver.c,v 1.373 2008/06/23 19:41:19 jinmei Exp $ */
/* $Id: resolver.c,v 1.374 2008/07/22 03:43:04 marka Exp $ */
/*! \file */
......@@ -1201,7 +1201,7 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
goto cleanup_query;
#ifndef BROKEN_TCP_BIND_BEFORE_CONNECT
result = isc_socket_bind(query->tcpsocket, &addr);
result = isc_socket_bind(query->tcpsocket, &addr, 0);
if (result != ISC_R_SUCCESS)
goto cleanup_socket;
#endif
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: xfrin.c,v 1.157 2007/12/02 23:55:01 marka Exp $ */
/* $Id: xfrin.c,v 1.158 2008/07/22 03:43:04 marka Exp $ */
/*! \file */
......@@ -873,7 +873,7 @@ 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));
CHECK(isc_socket_bind(xfr->socket, &xfr->sourceaddr, 1));
#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.78 2008/07/11 23:05:46 jinmei Exp $ */
/* $Id: socket.h,v 1.79 2008/07/22 03:43:04 marka Exp $ */
#ifndef ISC_SOCKET_H
#define ISC_SOCKET_H 1
......@@ -406,7 +406,7 @@ isc_socket_close(isc_socket_t *sock);
*/
isc_result_t
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *addressp);
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *addressp, int reuseaddr);
/*%<
* Bind 'socket' to '*addressp'.
*
......@@ -416,6 +416,8 @@ isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *addressp);
*
* \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.289 2008/07/18 03:45:55 marka Exp $ */
/* $Id: socket.c,v 1.290 2008/07/22 03:43:04 marka Exp $ */
/*! \file */
......@@ -4170,7 +4170,7 @@ 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) {
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr, int reuseaddr) {
char strbuf[ISC_STRERRORSIZE];
int on = 1;
......@@ -4189,7 +4189,8 @@ isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr) {
if (sock->pf == AF_UNIX)
goto bind_socket;
#endif
if (isc_sockaddr_getport(sockaddr) != (in_port_t)0 &&
if (reuseaddr &&
isc_sockaddr_getport(sockaddr) != (in_port_t)0 &&
setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on,
sizeof(on)) < 0) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: socket.c,v 1.58 2008/07/11 23:05:46 jinmei Exp $ */
/* $Id: socket.c,v 1.59 2008/07/22 03:43:04 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,7 @@ 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) {
isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr, int reuseaddr) {
int bind_errno;
char strbuf[ISC_STRERRORSIZE];
int on = 1;
......@@ -3324,7 +3324,8 @@ isc_socket_bind(isc_socket_t *sock, isc_sockaddr_t *sockaddr) {
/*
* Only set SO_REUSEADDR when we want a specific port.
*/
if (isc_sockaddr_getport(sockaddr) != (in_port_t)0 &&
if (reuseaddr &&
isc_sockaddr_getport(sockaddr) != (in_port_t)0 &&
setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on,
sizeof(on)) < 0) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
......
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