From: jakob Date: Wed, 9 Jul 2008 20:10:30 +0000 (+0000) Subject: let the kernel choose the random port. code from djm@. ok markus@. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=458c8d3e8933b643baac55a04bf4c2f8441cefab;p=openbsd let the kernel choose the random port. code from djm@. ok markus@. --- 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)