[syslog-ng]patch: add socket(SO_RCVBUF) option

Dmitry Karasik syslog-ng@lists.balabit.hu
Tue, 12 Oct 2004 14:08:09 +0200


Hello,

I'm playing with syslog-ng under high IO loads, and while doing so I found that
increasing UDP receive buffer helps ( not surprisingly though ) a lot.  Here, I
have a feature request, to add such an option to the config file.  Below I
included a patch that adds such an option to the set of udp() command
sub-options. While I realize that this function is very much useful also
outside of udp, I though that to complement the setsockopt setup() properly I
have also to add support for SO_SNDBUF, and support not only for source() but also
for destination() drivers, etc etc, and this would clearly make an overkill patch.
Probably you can think of something more elegant.

-- 
Sincerely,
	Dmitry Karasik

---
catpipe Systems ApS
*BSD solutions, consulting, development
www.catpipe.net
+45 7021 0050  

diff -ruN syslog-ng-1.6.5/src/afinet.c syslog-ng-1.6.5.patched/src/afinet.c
--- syslog-ng-1.6.5/src/afinet.c	Thu Aug  5 13:35:12 2004
+++ syslog-ng-1.6.5.patched/src/afinet.c	Tue Oct 12 13:37:49 2004
@@ -221,6 +221,13 @@
 	l->flags = set_flags(l->flags, AFINET_TCP_KEEPALIVE_MASK, AFINET_TCP_KEEPALIVE_SHIFT, v);
 }
 
+void afinet_src_set_so_rcvbuf(struct log_source_driver *c, UINT32 v)
+{
+	CAST_SUBTYPE(afsocket_source, l, c);
+
+	l->so_rcvbuf = v;
+}
+
 static int 
 do_open_afinet_connection(struct afsocket_source *c,
 			  struct io_fd *client,
@@ -333,6 +340,13 @@
 		struct io_fd *client = make_io_fd(cfg->backend, fd, NULL);
 		int res;
 
+		if ( self-> super.so_rcvbuf > 0) {
+			if ( setsockopt( client-> super.fd, SOL_SOCKET, SO_RCVBUF, &self-> super.so_rcvbuf, sizeof(self-> super.so_rcvbuf)) < 0) {
+				notice("Error setsockopt(SO_RCVBUF,%i):%s\n", self-> super.so_rcvbuf, strerror(errno));
+				return ST_FAIL | ST_QUIT;
+			}
+		}
+
 		self->super.num_connections = 1;
 		conn = make_afinet_source_connection(client, NULL, &self->super, self->super.super.super.next);
 		res = LOG_HANDLER_INIT(conn, cfg, NULL);
@@ -391,6 +405,7 @@
         self->super.flags = flags;
 	self->super.connections = make_object_queue();
 	self->super.max_connections = 10;
+	self->super.so_rcvbuf = 0;
         return &self->super.super;
 }
 
diff -ruN syslog-ng-1.6.5/src/afsocket.h syslog-ng-1.6.5.patched/src/afsocket.h
--- syslog-ng-1.6.5/src/afsocket.h	Thu May  6 10:57:52 2004
+++ syslog-ng-1.6.5.patched/src/afsocket.h	Tue Oct 12 13:21:09 2004
@@ -90,6 +90,7 @@
        (super log_source_driver)
        (vars
 	 (flags simple UINT32)
+	 (so_rcvbuf simple UINT32)
 	 (bind_addr object address_info)
 	 (max_connections simple UINT32)
 	 (num_connections simple UINT32)
@@ -135,6 +136,7 @@
 void afinet_src_set_mac(struct log_source_driver *c, UINT32 v);
 void afinet_src_set_encrypt(struct log_source_driver *c, UINT32 v);
 void afinet_src_set_tcp_keepalive(struct log_source_driver *c, UINT32 v);
+void afinet_src_set_so_rcvbuf(struct log_source_driver *c, UINT32 value);
 
 void afinet_dest_set_localip(struct log_dest_driver *c, const char *ip);
 void afinet_dest_set_localport(struct log_dest_driver *c, UINT32 port, const char *service,const char *proto);
diff -ruN syslog-ng-1.6.5/src/afsocket.h.x syslog-ng-1.6.5.patched/src/afsocket.h.x
--- syslog-ng-1.6.5/src/afsocket.h.x	Thu May  6 11:02:39 2004
+++ syslog-ng-1.6.5.patched/src/afsocket.h.x	Tue Oct 12 13:32:00 2004
@@ -37,6 +37,7 @@
   struct address_info *bind_addr;
   UINT32 max_connections;
   UINT32 num_connections;
+  int so_rcvbuf;
   struct object_queue *connections;
   int (*(open_connection))(struct afsocket_source *self, struct io_fd *, struct address_info *a);
 };
diff -ruN syslog-ng-1.6.5/src/cfg-grammar.y syslog-ng-1.6.5.patched/src/cfg-grammar.y
--- syslog-ng-1.6.5/src/cfg-grammar.y	Thu May  6 10:57:52 2004
+++ syslog-ng-1.6.5.patched/src/cfg-grammar.y	Tue Oct 12 13:17:10 2004
@@ -82,7 +82,7 @@
 %token KW_GC_IDLE_THRESHOLD KW_CREATE_DIRS KW_SANITIZE_FILENAMES
 %token KW_DIR_OWNER KW_DIR_GROUP KW_DIR_PERM KW_TEMPLATE KW_TEMPLATE_ESCAPE
 %token KW_OWNER KW_GROUP KW_PERM KW_KEEP_ALIVE KW_TCP_KEEP_ALIVE KW_MAX_CONNECTIONS
-%token KW_LOCALIP KW_IP KW_LOCALPORT KW_PORT KW_DESTPORT 
+%token KW_LOCALIP KW_IP KW_LOCALPORT KW_PORT KW_DESTPORT KW_SO_RCVBUF
 %token KW_COMPRESS KW_MAC KW_AUTH KW_ENCRYPT
 %token KW_DNS_CACHE KW_DNS_CACHE_SIZE
 %token KW_DNS_CACHE_EXPIRE KW_DNS_CACHE_EXPIRE_FAILED
@@ -299,6 +299,7 @@
 	: source_afinet_option
 	| KW_LOCALPORT '(' string ')'		{ afinet_src_set_localport(last_source_driver, 0, $3 ,"udp"); free($3); }
 	| KW_PORT '(' string ')'		{ afinet_src_set_localport(last_source_driver, 0, $3, "udp"); free($3); }
+	| KW_SO_RCVBUF '(' NUMBER ')'		{ afinet_src_set_so_rcvbuf( last_source_driver, $3); } 
 	;
 
 source_afinet_option
diff -ruN syslog-ng-1.6.5/src/cfg-lex.l syslog-ng-1.6.5.patched/src/cfg-lex.l
--- syslog-ng-1.6.5/src/cfg-lex.l	Thu Aug  5 13:35:12 2004
+++ syslog-ng-1.6.5.patched/src/cfg-lex.l	Tue Oct 12 13:23:32 2004
@@ -108,6 +108,7 @@
 	{ "pad_size",		KW_PAD_SIZE },
 	{ "spoof_source",	KW_SPOOF_SOURCE },
 	{ "spoof-source",	KW_SPOOF_SOURCE },
+        { "so_rcvbuf",		KW_SO_RCVBUF },
 
 	/* source or destination items */
 	{ "file",		KW_FILE },