Просмотр исходного кода

totemudp[u]: Drop truncated packets on receive

This is backport of part of "totemudpu: Scale receive buffer" patch in
master branch.

We shouldn't not need to enlarge buffer because maximum number of nodes
for needle is 2 so join message is smaller.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 8 лет назад
Родитель
Сommit
89d36a80a4
2 измененных файлов с 52 добавлено и 0 удалено
  1. 26 0
      exec/totemudp.c
  2. 26 0
      exec/totemudpu.c

+ 26 - 0
exec/totemudp.c

@@ -452,6 +452,7 @@ static int net_deliver_fn (
 	struct sockaddr_storage system_from;
 	int bytes_received;
 	int res = 0;
+	int truncated_packet;
 
 	if (instance->flushing == 1) {
 		iovec = &instance->totemudp_iov_recv_flush;
@@ -489,6 +490,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 == FRAME_SIZE_MAX then packet is truncated
+	 */
+	if (bytes_received == FRAME_SIZE_MAX) {
+		truncated_packet = 1;
+	}
+#endif
+
+	if (truncated_packet) {
+		log_printf(instance->totemudp_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 FRAME_SIZE_MAX). Dropping packet.", PROCESSOR_COUNT_MAX);
+		return (0);
+	}
+
 	/*
 	 * Authenticate and if authenticated, decrypt datagram
 	 */

+ 26 - 0
exec/totemudpu.c

@@ -446,6 +446,7 @@ static int net_deliver_fn (
 	struct sockaddr_storage system_from;
 	int bytes_received;
 	int res = 0;
+	int truncated_packet;
 
 	iovec = &instance->totemudpu_iov_recv;
 
@@ -479,6 +480,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 == FRAME_SIZE_MAX then packet is truncated
+	 */
+	if (bytes_received == 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 FRAME_SIZE_MAX). Dropping packet.", PROCESSOR_COUNT_MAX);
+		return (0);
+	}
+
 	/*
 	 * Authenticate and if authenticated, decrypt datagram
 	 */