mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 13:38:26 +00:00
update stream sockets with bound address/port
when isc_nm_listenstreamdns() is called with a local port of 0, a random port is chosen. call uv_getsockname() to determine what the port is as soon as the socket is bound, and add a function isc_nmsocket_getaddr() to retrieve it, so that the caller can connect to the listening socket. this will be used in cases where the same process is acting as both client and server.
This commit is contained in:
parent
4ad95e0567
commit
fe7ed2ba24
@ -729,3 +729,9 @@ isc_nmhandle_set_tcp_nodelay(isc_nmhandle_t *handle, const bool value);
|
|||||||
*
|
*
|
||||||
* \li 'handle' is a valid netmgr handle object.
|
* \li 'handle' is a valid netmgr handle object.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
isc_sockaddr_t
|
||||||
|
isc_nmsocket_getaddr(isc_nmsocket_t *sock);
|
||||||
|
/*%<
|
||||||
|
* Return the local address of 'sock'.
|
||||||
|
*/
|
||||||
|
@ -2538,6 +2538,12 @@ isc_nmhandle_set_tcp_nodelay(isc_nmhandle_t *handle, const bool value) {
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isc_sockaddr_t
|
||||||
|
isc_nmsocket_getaddr(isc_nmsocket_t *sock) {
|
||||||
|
REQUIRE(VALID_NMSOCK(sock));
|
||||||
|
return (sock->iface);
|
||||||
|
}
|
||||||
|
|
||||||
#if ISC_NETMGR_TRACE
|
#if ISC_NETMGR_TRACE
|
||||||
/*
|
/*
|
||||||
* Dump all active sockets in netmgr. We output to stderr
|
* Dump all active sockets in netmgr. We output to stderr
|
||||||
|
@ -748,6 +748,11 @@ isc_nm_listenstreamdns(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface,
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* copy the actual port we're listening on into sock->iface */
|
||||||
|
if (isc_sockaddr_getport(iface) == 0) {
|
||||||
|
listener->iface = listener->outer->iface;
|
||||||
|
}
|
||||||
|
|
||||||
listener->result = result;
|
listener->result = result;
|
||||||
atomic_store(&listener->active, true);
|
atomic_store(&listener->active, true);
|
||||||
atomic_store(&listener->listening, true);
|
atomic_store(&listener->listening, true);
|
||||||
|
@ -353,6 +353,7 @@ start_tcp_child_job(void *arg) {
|
|||||||
int r, flags = 0;
|
int r, flags = 0;
|
||||||
isc_result_t result = ISC_R_UNSET;
|
isc_result_t result = ISC_R_UNSET;
|
||||||
isc_loop_t *loop = sock->worker->loop;
|
isc_loop_t *loop = sock->worker->loop;
|
||||||
|
struct sockaddr_storage ss;
|
||||||
|
|
||||||
(void)isc__nm_socket_min_mtu(sock->fd, sa_family);
|
(void)isc__nm_socket_min_mtu(sock->fd, sa_family);
|
||||||
(void)isc__nm_socket_tcp_maxseg(sock->fd, NM_MAXSEG);
|
(void)isc__nm_socket_tcp_maxseg(sock->fd, NM_MAXSEG);
|
||||||
@ -417,8 +418,25 @@ start_tcp_child_job(void *arg) {
|
|||||||
|
|
||||||
atomic_store(&sock->listening, true);
|
atomic_store(&sock->listening, true);
|
||||||
|
|
||||||
|
if (sock->tid == 0) {
|
||||||
|
r = uv_tcp_getsockname(&sock->uv_handle.tcp,
|
||||||
|
(struct sockaddr *)&ss,
|
||||||
|
&(int){ sizeof(ss) });
|
||||||
|
if (r != 0) {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = isc_sockaddr_fromsockaddr(&sock->parent->iface,
|
||||||
|
(struct sockaddr *)&ss);
|
||||||
|
if (result != ISC_R_SUCCESS) {
|
||||||
|
goto done_result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
result = isc_uverr2result(r);
|
result = isc_uverr2result(r);
|
||||||
|
|
||||||
|
done_result:
|
||||||
atomic_fetch_add(&sock->parent->rchildren, 1);
|
atomic_fetch_add(&sock->parent->rchildren, 1);
|
||||||
|
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
|
@ -937,6 +937,11 @@ isc_nm_listentls(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface,
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* copy the actual port we're listening on into sock->iface */
|
||||||
|
if (isc_sockaddr_getport(iface) == 0) {
|
||||||
|
tlssock->iface = tlssock->outer->iface;
|
||||||
|
}
|
||||||
|
|
||||||
/* wait for listen result */
|
/* wait for listen result */
|
||||||
isc__nmsocket_attach(tlssock->outer, &tsock);
|
isc__nmsocket_attach(tlssock->outer, &tsock);
|
||||||
tlssock->result = result;
|
tlssock->result = result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user