]> git.proxmox.com Git - mirror_corosync.git/commitdiff
totemudpu: Scale receive buffer
authorJan Friesse <jfriesse@redhat.com>
Thu, 4 Jan 2018 16:07:20 +0000 (17:07 +0100)
committerJan Friesse <jfriesse@redhat.com>
Tue, 9 Jan 2018 16:46:04 +0000 (17:46 +0100)
Receive buffer should be based on PROCESSOR_COUNT_MAX and not static
buffer.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
exec/totemudpu.c

index a0d17687ba1a609fa5ca2cecf1e628a65a73898a..e77d36d129394cd3de5f89afb76cb46687dbfd40 100644 (file)
 #define MSG_NOSIGNAL 0
 #endif
 
-#define UDPU_FRAME_SIZE_MAX 10000
+/*
+ * Estimation of required buffer size - it should be at least
+ *   sizeof(memb_join) + PROCESSOR_MAX * 2 * sizeof(srp_addr))
+ * if we want to support PROCESSOR_MAX nodes, but because we don't have
+ * srp_addr and memb_join, we have to use estimation.
+ * TODO: Consider moving srp_addr/memb_join into totem headers instead of totemsrp.c
+ */
+#define UDPU_FRAME_SIZE_MAX    (PROCESSOR_COUNT_MAX * (INTERFACE_MAX * 2 * sizeof(struct totem_ip_address)) + 1024)
 
 #define MCAST_SOCKET_BUFFER_SIZE (TRANSMITS_ALLOWED * UDPU_FRAME_SIZE_MAX)
 #define NETIF_STATE_REPORT_UP          1
@@ -407,6 +414,7 @@ static int net_deliver_fn (
        struct iovec *iovec;
        struct sockaddr_storage system_from;
        int bytes_received;
+       int truncated_packet;
 
        iovec = &instance->totemudpu_iov_recv;
 
@@ -440,6 +448,31 @@ static int net_deliver_fn (
                instance->stats_recv += bytes_received;
        }
 
+       truncated_packet = 0;
+
+#ifdef HAVE_MSGHDR_FLAGS
+       if (msg_recv.msg_flags & MSG_TRUNC) {
+               truncated_packet = 1;
+       }
+#else
+       /*
+        * We don't have MSGHDR_FLAGS, but we can (hopefully) safely make assumption that
+        * if bytes_received == UDPU_FRAME_SIZE_MAX then packet is truncated
+        */
+       if (bytes_received == UDPU_FRAME_SIZE_MAX) {
+               truncated_packet = 1;
+       }
+#endif
+
+       if (truncated_packet) {
+               log_printf (instance->totemudpu_log_level_error,
+                               "Received too big message. This may be because something bad is happening"
+                               "on the network (attack?), or you tried join more nodes than corosync is"
+                               "compiled with (%u) or bug in the code (bad estimation of "
+                               "the UDPU_FRAME_SIZE_MAX). Dropping packet.", PROCESSOR_COUNT_MAX);
+               return (0);
+       }
+
        iovec->iov_len = bytes_received;
 
        /*