]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
UDP handler: enable regular check/timeout of XDP-TCP connections
authorLibor Peltan <libor.peltan@nic.cz>
Thu, 6 May 2021 09:26:36 +0000 (11:26 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Thu, 8 Jul 2021 14:04:00 +0000 (16:04 +0200)
src/knot/server/udp-handler.c
src/knot/server/xdp-handler.c
src/knot/server/xdp-handler.h

index 32a64bbe66f6e9248ef8e18880d3e7337ffd9d13..53fee44cd2b268f27d0fc8dfd5159914088c017d 100644 (file)
@@ -113,8 +113,15 @@ typedef struct {
        int (*udp_recv)(int, void *, void *);
        int (*udp_handle)(udp_context_t *, void *, void *);
        int (*udp_send)(void *, void *);
+       int (*udp_tick)(void *, void *);
 } udp_api_t;
 
+static int udp_noop(void *unused1, void *unused2) {
+       UNUSED(unused1);
+       UNUSED(unused2);
+       return KNOT_EOK;
+}
+
 /*! \brief Control message to fit IP_PKTINFO or IPv6_RECVPKTINFO. */
 typedef union {
        struct cmsghdr cmsg;
@@ -245,7 +252,8 @@ static udp_api_t udp_recvfrom_api = {
        udp_recvfrom_deinit,
        udp_recvfrom_recv,
        udp_recvfrom_handle,
-       udp_recvfrom_send
+       udp_recvfrom_send,
+       udp_noop
 };
 
 #ifdef ENABLE_RECVMMSG
@@ -362,7 +370,8 @@ static udp_api_t udp_recvmmsg_api = {
        udp_recvmmsg_deinit,
        udp_recvmmsg_recv,
        udp_recvmmsg_handle,
-       udp_recvmmsg_send
+       udp_recvmmsg_send,
+       udp_noop
 };
 #endif /* ENABLE_RECVMMSG */
 
@@ -394,12 +403,18 @@ static int xdp_recvmmsg_send(void *d, void *xdp_sock)
        return xdp_handle_send(d, xdp_sock);
 }
 
+static int xdp_recvmmsg_tick(void *d, void *xdp_sock)
+{
+       return xdp_handle_timeout(d, xdp_sock);
+}
+
 static udp_api_t xdp_recvmmsg_api = {
        xdp_recvmmsg_init,
        xdp_recvmmsg_deinit,
        xdp_recvmmsg_recv,
        xdp_recvmmsg_handle,
-       xdp_recvmmsg_send
+       xdp_recvmmsg_send,
+       xdp_recvmmsg_tick
 };
 #endif /* ENABLE_XDP */
 
@@ -535,7 +550,7 @@ int udp_master(dthread_t *thread)
 
                /* Wait for events. */
                fdset_it_t it;
-               (void)fdset_poll(&fds, &it, 0, -1);
+               (void)fdset_poll(&fds, &it, 0, 1000);
 
                /* Process the events. */
                for (; !fdset_it_is_done(&it); fdset_it_next(&it)) {
@@ -547,6 +562,9 @@ int udp_master(dthread_t *thread)
                                api->udp_send(rq, xdp_socket);
                        }
                }
+
+               /* Regular maintenance (XDP-TCP only). */
+               api->udp_tick(rq, xdp_socket);
        }
 
 finish:
index a61a783d72bc38ff599d64c16c55adc22293dbb4..4fc314193c3b5d721d8491c2c7a2c80d4b0231c3 100644 (file)
@@ -217,10 +217,15 @@ int xdp_handle_send(xdp_handle_ctx_t *ctx, knot_xdp_socket_t *xdp_sock)
        tcp_relay_dynarray_free(&ctx->tcp_relays);
 
        if (ret == KNOT_EOK) {
-               ret = knot_xdp_tcp_timeout(ctx->tcp_table, xdp_sock, 20, 2000000, 4000000, overweight(ctx->tcp_table->usage, 1000), NULL); // FIXME configurable parameters
+               ret = xdp_handle_timeout(ctx, xdp_sock);
        }
 
        return ret;
 }
 
+int xdp_handle_timeout(xdp_handle_ctx_t *ctx, knot_xdp_socket_t *xdp_sock)
+{
+       return knot_xdp_tcp_timeout(ctx->tcp_table, xdp_sock, 20, 2000000, 4000000, overweight(ctx->tcp_table->usage, 1000), NULL); // FIXME configurable parameters
+}
+
 #endif // ENABLE_XDP
index 8c1be5f9f21c8143967b07dac1dbd0638e5c5f90..2b93fa72950caa086fac19143caa5b4b2ac51712 100644 (file)
@@ -57,4 +57,9 @@ int xdp_handle_msgs(struct xdp_handle_ctx *ctx, knot_xdp_socket_t *sock,
  */
 int xdp_handle_send(struct xdp_handle_ctx *ctx, knot_xdp_socket_t *xdp_sock);
 
+/*!
+ * \brief Check for old TCP connections and close/reset them.
+ */
+int xdp_handle_timeout(struct xdp_handle_ctx *ctx, knot_xdp_socket_t *xdp_sock);
+
 #endif // ENABLE_XDP