From 7a2bafc239432a78d69bbc00058a9cddd05dab23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Vavru=C5=A1a?= <marek.vavrusa@nic.cz> Date: Mon, 27 Apr 2015 16:18:31 +0200 Subject: [PATCH] daemon/net: use REUSEADDR and IPV6ONLY for bound sockets this disables dual-stack and allows binding to both v4 and v4-in-v6 addresses separately --- daemon/io.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/daemon/io.c b/daemon/io.c index 5597c5a59..6f7e01187 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -70,13 +70,17 @@ void udp_recv(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, int udp_bind(struct endpoint *ep, struct sockaddr *addr) { uv_udp_t *handle = &ep->udp; - int ret = uv_udp_bind(handle, addr, 0); + unsigned flags = UV_UDP_REUSEADDR; + if (addr->sa_family == AF_INET6) { + flags |= UV_UDP_IPV6ONLY; + } + int ret = uv_udp_bind(handle, addr, flags); if (ret != 0) { return ret; } handle->data = NULL; - return uv_udp_recv_start(handle, &handle_getbuf, &udp_recv); + return io_start_read((uv_handle_t *)handle); } void udp_unbind(struct endpoint *ep) @@ -130,7 +134,11 @@ static void tcp_accept(uv_stream_t *master, int status) int tcp_bind(struct endpoint *ep, struct sockaddr *addr) { uv_tcp_t *handle = &ep->tcp; - int ret = uv_tcp_bind(handle, addr, 0); + unsigned flags = UV_UDP_REUSEADDR; + if (addr->sa_family == AF_INET6) { + flags |= UV_UDP_IPV6ONLY; + } + int ret = uv_tcp_bind(handle, addr, flags); if (ret != 0) { return ret; } -- GitLab