Cluster Project branch, RHEL5, updated. cmirror_1_1_15-60-gb0b6f8f

ccaulfield@sourceware.org ccaulfield@sourceware.org
Tue Apr 29 14:27:00 GMT 2008


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Cluster Project".

http://sources.redhat.com/git/gitweb.cgi?p=cluster.git;a=commitdiff;h=b0b6f8fef397d7ec0099fa07475aaad5b2c81bac

The branch, RHEL5 has been updated
       via  b0b6f8fef397d7ec0099fa07475aaad5b2c81bac (commit)
       via  f5fee58ee9dcdbc602e0dca002a0b1520f3b866e (commit)
      from  940c0488bdaa11a4833788b3d3957248e4765105 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b0b6f8fef397d7ec0099fa07475aaad5b2c81bac
Author: Christine Caulfield <ccaulfie@redhat.com>
Date:   Wed Mar 19 10:08:51 2008 +0000

    [CMAN] Limit outstanding replies
    
    This commit imposes a limit on the number of outstanding replies
    that a connection can have. This is to prevent a DoS attack that
    causes cman to eat all available memory by sending lots of requests
    and not reading the replies.
    
    The deafult is 128, it can be set in cluster.conf as
    <cman max_queued="1000"/>
    
    Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>

commit f5fee58ee9dcdbc602e0dca002a0b1520f3b866e
Author: Christine Caulfield <ccaulfie@redhat.com>
Date:   Tue Mar 18 15:56:45 2008 +0000

    [CMAN] Free up any queued messages when someone disconnects
    
    When a client disconnects we need to go through the list of
    queued replies to get rid of any that have not been collected.
    
    Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>

-----------------------------------------------------------------------

Summary of changes:
 cman/daemon/cmanccs.c        |   11 ++++++++++-
 cman/daemon/cnxman-private.h |    2 +-
 cman/daemon/daemon.c         |   34 ++++++++++++++++++++++++++++++----
 cman/daemon/daemon.h         |    3 ++-
 4 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/cman/daemon/cmanccs.c b/cman/daemon/cmanccs.c
index 7ae87e6..0e15cbf 100644
--- a/cman/daemon/cmanccs.c
+++ b/cman/daemon/cmanccs.c
@@ -1,7 +1,7 @@
 /******************************************************************************
 *******************************************************************************
 **
-**  Copyright (C) 2005-2006 Red Hat, Inc.  All rights reserved.
+**  Copyright (C) 2005-2008 Red Hat, Inc.  All rights reserved.
 **
 **  This copyrighted material is made available to anyone wishing to use,
 **  modify, copy, or redistribute it subject to the terms and conditions
@@ -15,6 +15,7 @@
 #include <netinet/in.h>
 #include <syslog.h>
 #include <string.h>
+#include <signal.h>
 #include <sys/utsname.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -27,6 +28,7 @@
 #include "cnxman-private.h"
 #include "logging.h"
 #include "commands.h"
+#include "daemon.h"
 #include "ais.h"
 #include "ccs.h"
 
@@ -42,6 +44,7 @@
 #define MCAST_ADDR_PATH		"/cluster/cman/multicast/@addr"
 #define PORT_PATH		"/cluster/cman/@port"
 #define KEY_PATH		"/cluster/cman/@keyfile"
+#define MAXQUEUED_PATH		"/cluster/cman/@max_queued"
 
 #define NODEI_NAME_PATH		"/cluster/clusternodes/clusternode[%d]/@name"
 #define NODE_NAME_PATH_BYNAME	"/cluster/clusternodes/clusternode[@name=\"%s\"]/@name"
@@ -438,6 +441,12 @@ static int get_ccs_join_info(void)
 		cluster_id = generate_cluster_id(cluster_name);
 	}
 
+	error = ccs_get(cd, MAXQUEUED_PATH, &str);
+	if (!error) {
+		max_outstanding_messages = atoi(str);
+		free(str);
+	}
+
 	/* our nodename */
 	memset(nodename, 0, sizeof(nodename));
 
diff --git a/cman/daemon/cnxman-private.h b/cman/daemon/cnxman-private.h
index 5691ccf..a3b3f55 100644
--- a/cman/daemon/cnxman-private.h
+++ b/cman/daemon/cnxman-private.h
@@ -132,7 +132,7 @@ struct connection
 	uint32_t   events;      /* Registered for events */
 	uint32_t   confchg;     /* Registered for confchg */
 	struct list write_msgs; /* Queued messages to go to data clients */
-	struct cl_comms_socket *clsock;
+	uint32_t    num_write_msgs; /* Count of messages */
 	struct connection *next;
 	struct list list;       /* when on the client_list */
 };
diff --git a/cman/daemon/daemon.c b/cman/daemon/daemon.c
index 35d65a7..08aeb80 100644
--- a/cman/daemon/daemon.c
+++ b/cman/daemon/daemon.c
@@ -1,7 +1,7 @@
 /******************************************************************************
 *******************************************************************************
 **
-**  Copyright (C) 2005-2006 Red Hat, Inc.  All rights reserved.
+**  Copyright (C) 2005-2008 Red Hat, Inc.  All rights reserved.
 **
 **  This copyrighted material is made available to anyone wishing to use,
 **  modify, copy, or redistribute it subject to the terms and conditions
@@ -57,8 +57,10 @@ volatile sig_atomic_t quit_threads=0;
 
 int num_connections = 0;
 poll_handle ais_poll_handle;
+uint32_t max_outstanding_messages = 128;
 
 static int process_client(poll_handle handle, int fd, int revent, void *data);
+static void remove_client(poll_handle handle, struct connection *con);
 
 /* Send it, or queue it for later if the socket is busy */
 static int send_reply_message(struct connection *con, struct sock_header *msg)
@@ -79,8 +81,17 @@ static int send_reply_message(struct connection *con, struct sock_header *msg)
 
 	if ((ret > 0 && ret != msg->length) ||
 	    (ret == -1 && errno == EAGAIN)) {
+		struct queued_reply *qm;
+
+		/* Have we exceeded the allowed number of queued messages ? */
+		if (con->num_write_msgs > max_outstanding_messages) {
+			P_DAEMON("Disconnecting. client has more that %d replies outstanding (%d)\n", max_outstanding_messages, con->num_write_msgs);
+			remove_client(ais_poll_handle, con);
+			return -1;
+		}
+
 		/* Queue it */
-		struct queued_reply *qm = malloc(sizeof(struct queued_reply) + msg->length);
+		qm = malloc(sizeof(struct queued_reply) + msg->length);
 		if (!qm)
 		{
 			perror("Error allocating queued message");
@@ -92,15 +103,19 @@ static int send_reply_message(struct connection *con, struct sock_header *msg)
 		else
 			qm->offset = 0;
 		list_add(&con->write_msgs, &qm->list);
-		P_DAEMON("queued last message\n");
+		con->num_write_msgs++;
+		P_DAEMON("queued last message, count is %d\n", con->num_write_msgs);
 		poll_dispatch_modify(ais_poll_handle, con->fd, POLLIN | POLLOUT, process_client);
 	}
 	return 0;
 }
 
-
 static void remove_client(poll_handle handle, struct connection *con)
 {
+	struct list *tmp, *qmh;
+	struct queued_reply *qm;
+	int msgs=0;
+
 	poll_dispatch_delete(handle, con->fd);
 	close(con->fd);
 	if (con->type == CON_CLIENT)
@@ -109,6 +124,15 @@ static void remove_client(poll_handle handle, struct connection *con)
 	unbind_con(con);
 	remove_barriers(con);
 
+	list_iterate_safe(qmh, tmp, &con->write_msgs) {
+		qm = list_item(qmh, struct queued_reply);
+
+		list_del(&qm->list);
+		free(qm);
+		msgs++;
+	}
+
+	P_DAEMON("Freed %d queued messages\n", msgs);
 	free(con);
 	num_connections--;
 }
@@ -129,6 +153,7 @@ static void send_queued_reply(struct connection *con)
 		{
 			list_del(&qm->list);
 			free(qm);
+			con->num_write_msgs--;
 		}
 		else
 		{
@@ -314,6 +339,7 @@ static int process_rendezvous(poll_handle handle, int fd, int revent, void *data
 		newcon->type = con->type;
 		newcon->port = 0;
 		newcon->events = 0;
+		newcon->num_write_msgs = 0;
 		list_init(&newcon->write_msgs);
 		fcntl(client_fd, F_SETFL, fcntl(client_fd, F_GETFL, 0) | O_NONBLOCK);
 
diff --git a/cman/daemon/daemon.h b/cman/daemon/daemon.h
index 3897bd9..7f604a8 100644
--- a/cman/daemon/daemon.h
+++ b/cman/daemon/daemon.h
@@ -1,7 +1,7 @@
 /******************************************************************************
 *******************************************************************************
 **
-**  Copyright (C) 2005 Red Hat, Inc.  All rights reserved.
+**  Copyright (C) 2005-2008 Red Hat, Inc.  All rights reserved.
 **
 **  This copyrighted material is made available to anyone wishing to use,
 **  modify, copy, or redistribute it subject to the terms and conditions
@@ -22,3 +22,4 @@ extern void notify_confchg(struct sock_header *message);
 
 extern volatile sig_atomic_t quit_threads;
 extern int num_connections;
+extern uint32_t max_outstanding_messages;


hooks/post-receive
--
Cluster Project



More information about the Cluster-cvs mailing list