ソースを参照

totemudpu: Rework truncated packet detection

Replace the MSG_TRUNC flag check by enlarging the receive buffer
to UDP_RECEIVE_FRAME_SIZE_MAX + 1.

Since Corosync should never send packets larger than
UDP_RECEIVE_FRAME_SIZE_MAX, if the number of bytes received
equals this new, larger buffer size,
we know the original packet was too large and was truncated.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 3 ヶ月 前
コミット
329d1648ee
1 ファイル変更12 行追加24 行削除
  1. 12 24
      exec/totemudpu.c

+ 12 - 24
exec/totemudpu.c

@@ -139,7 +139,7 @@ struct totemudpu_instance {
 
 	void *udpu_context;
 
-	char iov_buffer[UDP_RECEIVE_FRAME_SIZE_MAX];
+	char iov_buffer[UDP_RECEIVE_FRAME_SIZE_MAX + 1];
 
 	struct iovec totemudpu_iov_recv;
 
@@ -214,7 +214,7 @@ static void totemudpu_instance_initialize (struct totemudpu_instance *instance)
 
 	instance->totemudpu_iov_recv.iov_base = instance->iov_buffer;
 
-	instance->totemudpu_iov_recv.iov_len = UDP_RECEIVE_FRAME_SIZE_MAX; //sizeof (instance->iov_buffer);
+	instance->totemudpu_iov_recv.iov_len = UDP_RECEIVE_FRAME_SIZE_MAX + 1; //sizeof (instance->iov_buffer) + 1;
 
 	/*
 	 * There is always atleast 1 processor
@@ -480,7 +480,6 @@ static int net_deliver_fn (
 	struct iovec *iovec;
 	struct sockaddr_storage system_from;
 	int bytes_received;
-	int truncated_packet;
 
 	iovec = &instance->totemudpu_iov_recv;
 
@@ -514,26 +513,15 @@ 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 == UDP_RECEIVE_FRAME_SIZE_MAX then packet is truncated
-	 */
-	if (bytes_received == UDP_RECEIVE_FRAME_SIZE_MAX) {
-		truncated_packet = 1;
-	}
-#endif
-
-	if (truncated_packet) {
+	if (bytes_received >= UDP_RECEIVE_FRAME_SIZE_MAX + 1) {
+		/*
+		 * Maximum packet size should be UDP_RECEIVE_FRAME_SIZE_MAX.
+		 * If received packet is UDP_RECEIVE_FRAME_SIZE_MAX + 1 it means packet was truncated
+		 * (iov_buffer size and iov_len are intentionally set to UDP_RECEIVE_FRAME_SIZE_MAX + 1).
+		 */
 		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"
+				"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 UDP_RECEIVE_FRAME_SIZE_MAX). Dropping packet.", PROCESSOR_COUNT_MAX);
 		return (0);
@@ -559,7 +547,7 @@ static int net_deliver_fn (
 		iovec->iov_len,
 		&system_from);
 
-	iovec->iov_len = UDP_RECEIVE_FRAME_SIZE_MAX;
+	iovec->iov_len = UDP_RECEIVE_FRAME_SIZE_MAX + 1;
 	return (0);
 }
 
@@ -1009,7 +997,7 @@ int totemudpu_initialize (
 	 * Initialize local variables for totemudpu
 	 */
 	instance->totem_interface = &totem_config->interfaces[0];
-	memset (instance->iov_buffer, 0, UDP_RECEIVE_FRAME_SIZE_MAX);
+	memset (instance->iov_buffer, 0, UDP_RECEIVE_FRAME_SIZE_MAX + 1);
 
 	instance->totemudpu_poll_handle = poll_handle;