summaryrefslogtreecommitdiff
path: root/usr.sbin/bind/lib
diff options
context:
space:
mode:
authorJakob Schlyter <jakob@cvs.openbsd.org>2008-07-09 20:10:31 +0000
committerJakob Schlyter <jakob@cvs.openbsd.org>2008-07-09 20:10:31 +0000
commit1b50c0de4d07f1b3456bd5d1e482bae2bada3706 (patch)
treee57ae265cc6dea8c4a60abf3682393bd53968c3b /usr.sbin/bind/lib
parentbdf54ee976e77c7c85dc7102c4152a416caa9709 (diff)
let the kernel choose the random port. code from djm@. ok markus@.
Diffstat (limited to 'usr.sbin/bind/lib')
-rw-r--r--usr.sbin/bind/lib/dns/dispatch.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/usr.sbin/bind/lib/dns/dispatch.c b/usr.sbin/bind/lib/dns/dispatch.c
index 0272a93b3a7..99d5b93af2b 100644
--- a/usr.sbin/bind/lib/dns/dispatch.c
+++ b/usr.sbin/bind/lib/dns/dispatch.c
@@ -1910,6 +1910,7 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
localaddr_bound = *localaddr;
getsocket:
if ((attributes & DNS_DISPATCHATTR_RANDOMPORT) != 0) {
+#if 0
in_port_t prt;
/* XXX: should the range be configurable? */
@@ -1927,6 +1928,26 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
goto getsocket;
}
localport = prt;
+#else
+ isc_sockaddr_t localaddr_listen;
+
+ isc_sockaddr_setport(&localaddr_bound, 0);
+ result = create_socket(sockmgr, &localaddr_bound, &sock);
+ if (result == ISC_R_ADDRINUSE) {
+ if (++k == 1024)
+ attributes &= ~DNS_DISPATCHATTR_RANDOMPORT;
+ goto getsocket;
+ }
+ result = isc_socket_getsockname(sock, &localaddr_listen);
+ if (result != ISC_R_SUCCESS ||
+ blacklisted(mgr, NULL, &localaddr_listen)) {
+ isc_socket_detach(&sock);
+ if (++k == 1024)
+ attributes &= ~DNS_DISPATCHATTR_RANDOMPORT;
+ goto getsocket;
+ }
+ localport = isc_sockaddr_getport(&localaddr_listen);
+#endif
} else
result = create_socket(sockmgr, localaddr, &sock);
if (result != ISC_R_SUCCESS)