summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authormichi <michi+ngircd@dataswamp.org>2020-04-15 10:32:08 +0200
committerAlexander Barton <alex@barton.de>2020-04-20 00:20:46 +0200
commitc6e3c13f27744971fcb1d2de4e561d3bcdaa5aed (patch)
treec5712c3a68429afa2ec2e6ecc32c754c86876870 /src
parent04de1423eb26da60c192d343a7e7a6bcda2aca37 (diff)
downloadngircd-c6e3c13f27744971fcb1d2de4e561d3bcdaa5aed.tar.gz
ngircd-c6e3c13f27744971fcb1d2de4e561d3bcdaa5aed.zip
Increase read buffer size for server connections
This applies the same logic we have for write buffers to distinguish
between server and client connections and sets the maximum buffer size
accordingly. As a result peering with servers with many GLINE/KLINEs
does not kill the connecting server connection anymore.
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/conn.c26
-rw-r--r--src/ngircd/defines.h8
2 files changed, 26 insertions, 8 deletions
diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c
index 92d9939a..ef0f95fa 100644
--- a/src/ngircd/conn.c
+++ b/src/ngircd/conn.c
@@ -1546,34 +1546,46 @@ static void
 Read_Request( CONN_ID Idx )
 {
 	ssize_t len;
+	size_t readbuf_limit = READBUFFER_LEN;
 	static const unsigned int maxbps = COMMAND_LEN / 2;
-	char readbuf[READBUFFER_LEN];
+	char readbuf[READBUFFER_MAX_LEN];
 	time_t t;
 	CLIENT *c;
 	assert( Idx > NONE );
 	assert( My_Connections[Idx].sock > NONE );
 
+	/* Make sure that there still exists a CLIENT structure associated
+	 * with this connection and check if this is a server or not: */
+	c = Conn_GetClient(Idx);
+	if (c) {
+		/* Servers do get special read buffer limits, so they can
+		 * process all the messages that are required while peering. */
+		if (Client_Type(c) == CLIENT_SERVER)
+			readbuf_limit = READBUFFER_SLINK_LEN;
+	} else
+		LogDebug("Read request without client (connection %d)!?", Idx);
+
 #ifdef ZLIB
-	if ((array_bytes(&My_Connections[Idx].rbuf) >= READBUFFER_LEN) ||
-		(array_bytes(&My_Connections[Idx].zip.rbuf) >= READBUFFER_LEN))
+	if ((array_bytes(&My_Connections[Idx].rbuf) >= readbuf_limit) ||
+		(array_bytes(&My_Connections[Idx].zip.rbuf) >= readbuf_limit))
 #else
-	if (array_bytes(&My_Connections[Idx].rbuf) >= READBUFFER_LEN)
+	if (array_bytes(&My_Connections[Idx].rbuf) >= readbuf_limit)
 #endif
 	{
 		/* Read buffer is full */
 		Log(LOG_ERR,
 		    "Receive buffer space exhausted (connection %d): %d/%d bytes",
-		    Idx, array_bytes(&My_Connections[Idx].rbuf), READBUFFER_LEN);
+		    Idx, array_bytes(&My_Connections[Idx].rbuf), readbuf_limit);
 		Conn_Close(Idx, "Receive buffer space exhausted", NULL, false);
 		return;
 	}
 
 #ifdef SSL_SUPPORT
 	if (Conn_OPTION_ISSET(&My_Connections[Idx], CONN_SSL))
-		len = ConnSSL_Read( &My_Connections[Idx], readbuf, sizeof(readbuf));
+		len = ConnSSL_Read( &My_Connections[Idx], readbuf, readbuf_limit);
 	else
 #endif
-	len = read(My_Connections[Idx].sock, readbuf, sizeof(readbuf));
+	len = read(My_Connections[Idx].sock, readbuf, readbuf_limit);
 	if (len == 0) {
 		LogDebug("Client \"%s:%u\" is closing connection %d ...",
 			 My_Connections[Idx].host,
diff --git a/src/ngircd/defines.h b/src/ngircd/defines.h
index ff8cd226..7ce30e57 100644
--- a/src/ngircd/defines.h
+++ b/src/ngircd/defines.h
@@ -153,6 +153,12 @@
 /** Size of the read buffer of a connection in bytes. */
 #define READBUFFER_LEN 2048
 
+/** Maximum size of the read buffer of a connection in bytes. */
+#define READBUFFER_MAX_LEN 65535
+
+/** Maximum size of the read buffer of a server link connection in bytes. */
+#define READBUFFER_SLINK_LEN 65536
+
 /** Size that triggers write buffer flushing if more space is needed. */
 #define WRITEBUFFER_FLUSH_LEN 4096
 
@@ -160,7 +166,7 @@
 #define WRITEBUFFER_MAX_LEN 32768
 
 /** Maximum size of the write buffer of a server link connection in bytes. */
-#define WRITEBUFFER_SLINK_LEN 65536
+#define WRITEBUFFER_SLINK_LEN READBUFFER_SLINK_LEN
 
 
 /* IRC/IRC+ protocol */