]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/network: enabled Linux-style SO_REUSEPORT if supported
authorMarek Vavruša <marek.vavrusa@nic.cz>
Thu, 25 Jun 2015 17:09:00 +0000 (19:09 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Mon, 29 Jun 2015 19:26:18 +0000 (21:26 +0200)
daemon/network.c
scripts/bootstrap-depends.sh

index 10a8d6ad0412b4c9e22b5c0e6fe899dc9709f232..a7bd16a8f075d9ff5e43b56376ceb249507546b5 100644 (file)
 #include "daemon/worker.h"
 #include "daemon/io.h"
 
+/* libuv 1.7.0+ is able to support SO_REUSEPORT for loadbalancing */
+#define UV_VERSION_NUM UV_VERSION_MAJOR ## UV_VERSION_MINOR ## UV_VERSION_PATCH
+#if (defined(ENABLE_REUSEPORT) || UV_VERSION_NUM >= 170) && (__linux__ && SO_REUSEPORT)
+  #define handle_init(type, loop, handle, family) do { \
+       uv_ ## type ## _init_ex((loop), (handle), (family)); \
+       uv_os_fd_t fd = 0; \
+       if (uv_fileno((uv_handle_t *)(handle), &fd) == 0) { \
+               int on = 1; \
+               setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)); \
+       } \
+  } while (0)
+#else
+  #define handle_init(type, loop, handle, family) \
+       uv_ ## type ## _init((loop), (handle))
+#endif
+
 void network_init(struct network *net, uv_loop_t *loop)
 {
        if (net != NULL) {
@@ -96,7 +112,7 @@ static int insert_endpoint(struct network *net, const char *addr, struct endpoin
 static int open_endpoint(struct network *net, struct endpoint *ep, struct sockaddr *sa, uint32_t flags)
 {
        if (flags & NET_UDP) {
-               uv_udp_init(net->loop, &ep->udp);
+               handle_init(udp, net->loop, &ep->udp, sa->sa_family);
                int ret = udp_bind(ep, sa);
                if (ret != 0) {
                        return ret;
@@ -104,7 +120,7 @@ static int open_endpoint(struct network *net, struct endpoint *ep, struct sockad
                ep->flags |= NET_UDP;
        }
        if (flags & NET_TCP) {
-               uv_tcp_init(net->loop, &ep->tcp);
+               handle_init(tcp, net->loop, &ep->tcp, sa->sa_family);
                int ret = tcp_bind(ep, sa);
                if (ret != 0) {
                        return ret;
index 882d6f5157129baf1f340d73440786a1fa0df347..c1d5f341b8d9448f24c0770636b5185e835b9d24 100755 (executable)
@@ -3,7 +3,7 @@ set -e
 
 CMOCKA_TAG="cmocka-0.4.1"
 CMOCKA_URL="git://git.cryptomilk.org/projects/cmocka.git"
-LIBUV_TAG="v1.5.0"
+LIBUV_TAG="v1.x"
 LIBUV_URL="https://github.com/libuv/libuv.git"
 KNOT_TAG="edc125bc"
 KNOT_URL="https://github.com/CZ-NIC/knot.git"