]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/net: use REUSEADDR and IPV6ONLY for bound sockets
authorMarek Vavruša <marek.vavrusa@nic.cz>
Mon, 27 Apr 2015 14:18:31 +0000 (16:18 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Mon, 27 Apr 2015 14:18:31 +0000 (16:18 +0200)
this disables dual-stack and allows binding to both v4 and v4-in-v6
addresses separately

daemon/io.c

index 5597c5a59138551a41d7085ceaba1553b6ad4c57..6f7e01187b50f75f3e5b33128e210aae55250350 100644 (file)
@@ -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;
        }