Bug 153278

Summary: [PATCH] net/beacon: Fix udp socket buffer sizes
Product: Ports & Packages Reporter: Craig Leres <leres>
Component: Individual Port(s)Assignee: freebsd-ports-bugs (Nobody) <ports-bugs>
Status: Closed FIXED    
Severity: Affects Only Me CC: chui
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description Craig Leres freebsd_committer freebsd_triage 2010-12-18 20:20:06 UTC
    Although beacon has code to set the SO_SNDBUF and SO_RCVBUF
    buffer sizes, it is only executed if socket() *fails*. If you
    fix this then beacon fails to run because the sizes that it is
    attempting to be set are larger than system defaults allow.

Fix: Add a routine that sets the buffer sizes as high as the OS
    default allows; see attached patch.

    Note that with the FreeBSD default of 256KB you will still see
    udp full socket buffer drops but at least you'll have the option
    to raise kern.ipc.maxsockbuf so that beacon can get the 1MB
    buffers it wants.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0NFuwACgkQWxlAhAje3JsrwgCfSp3S07sHDH8VIJAdNtGhicJ/
0rQAn1AEpSxIfkKCsg7z/UsJJQn01Q7m
=weeU
-----END PGP SIGNATURE-----

--------------020202000407000805010102
Content-Type: text/plain;
 name="patch-patch-common-beacon.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="patch-patch-common-beacon.patch"



--------------020202000407000805010102
Content-Type: application/octet-stream;
 name="patch-patch-common-beacon.patch.sig"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="patch-patch-common-beacon.patch.sig"

iEYEABECAAYFAk0NFuwACgkQWxlAhAje3JvOJQCeMH/CJoii7thoinksWHZVwFuFdwgAnjZm
qIE+TGGeGqk6OcbzFmef+P/D
--------------020202000407000805010102----KNFTP7NOGmMvPcaEWgQ9TxWJk2iJ78TpIqnGqEXSDaYST7vT
Content-Type: text/plain; name="file.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="file.diff"

--- files/patch-common-beacon.patch.orig	2010-12-15 14:44:42.000000000 -0800
+++ files/patch-common-beacon.patch	2010-12-18 12:10:52.000000000 -0800
@@ -1,11 +1,32 @@
 --- common-beacon.patch.orig	2005-06-15 18:46:40.000000000 -0700
-+++ common-beacon.patch	2010-07-30 17:34:45.000000000 -0700
-@@ -46,3 +46,15 @@
++++ common-beacon.patch	2010-12-18 12:10:48.000000000 -0800
+@@ -1,6 +1,5 @@
+-diff -u -p -w common/src/rtp.c common-beacon/src/rtp.c
+---- common/src/rtp.c	2002-04-15 17:40:05.000000000 -0500
+-+++ common-beacon/src/rtp.c	2005-02-11 13:20:37.000000000 -0600
++--- common.orig/src/rtp.c	2002-04-15 15:40:05.000000000 -0700
+++++ common/src/rtp.c	2010-12-18 10:54:33.000000000 -0800
+ @@ -180,6 +180,7 @@ typedef struct _source {
+  	int		 probation;
+  	uint32_t	 jitter;
+@@ -34,9 +33,8 @@
+  			if (s->sender) {
+  				/* Much of this is taken from A.3 of draft-ietf-avt-rtp-new-01.txt */
+  				int	extended_max      = s->cycles + s->max_seq;
+-diff -u -p -w common/src/rtp.h common-beacon/src/rtp.h
+---- common/src/rtp.h	2002-04-15 17:40:05.000000000 -0500
+-+++ common-beacon/src/rtp.h	2005-02-11 13:22:50.000000000 -0600
++--- common.orig/src/rtp.h	2002-04-15 15:40:05.000000000 -0700
+++++ common/src/rtp.h	2010-12-18 10:54:33.000000000 -0800
+ @@ -41,7 +41,7 @@
+  
+  #define RTP_VERSION 2
+@@ -46,3 +44,82 @@
   
   #if !defined(WORDS_BIGENDIAN) && !defined(WORDS_SMALLENDIAN)
   #error RTP library requires WORDS_BIGENDIAN or WORDS_SMALLENDIAN to be defined.
-+--- common/src/net_udp.c	2004-06-29 09:21:37.000000000 -0700
-++++ common-beacon/src/net_udp.c	2010-07-30 17:28:06.000000000 -0700
++--- common.orig/src/net_udp.c	2004-06-29 09:21:37.000000000 -0700
+++++ common/src/net_udp.c	2010-12-18 12:10:46.000000000 -0800
 +@@ -44,7 +44,9 @@
 + #include "debug.h"
 + #include "memory.h"
@@ -16,3 +37,70 @@
 + #include "vsnprintf.h"
 + #include "net_udp.h"
 + 
++@@ -117,8 +119,10 @@ struct _socket_udp {
++ * compatibility for Winsock 1.
++ */
++ #define SETSOCKOPT winsock_versions_setsockopt
+++#define GETSOCKOPT winsock_versions_getsockopt
++ #else
++ #define SETSOCKOPT setsockopt
+++#define GETSOCKOPT getsockopt
++ #endif /* WIN32 */
++ 
++ /*****************************************************************************/
++@@ -166,6 +170,36 @@ socket_error(const char *msg, ...)
++ #endif
++ }
++ 
+++/* Set the socket buffer size as close to the desired as the OS allows */
+++static int
+++setsockbufsize(int fd, int opt, const char *what, int size)
+++{
+++	int try, def;
+++	socklen_t len;
+++
+++	printf("setsockbufsize: desired %s %d", what, size);
+++	def = 0;
+++	len = sizeof(def);
+++	if (GETSOCKOPT(fd, SOL_SOCKET, opt, (void *)&def, (void *)&len) < 0) {
+++		printf("\n");
+++		socket_error("getsockopt %s", what);
+++		return (-1);
+++	}
+++	printf(", default %d", def);
+++
+++	/* Work from the desired size down to the default */
+++	for (try = size; try > def; try -= 1024) {
+++		if (SETSOCKOPT(fd, SOL_SOCKET, opt,
+++		    (void *)&try, sizeof(try)) >= 0) {
+++			printf(", new %d\n", try);
+++			return (0);
+++		}
+++	}
+++	printf("\n");
+++	socket_error("setsockopt %s", what);
+++	return (-1);
+++}
+++
++ #ifdef WIN32
++ /* ws2tcpip.h defines these constants with different values from
++ * winsock.h so files that use winsock 2 values but try to use 
++@@ -290,16 +324,12 @@ static socket_udp *udp_init4(const char 
++ 	s->fd = socket(AF_INET, SOCK_DGRAM, 0);
++ 	if (s->fd < 0) {
++ 		socket_error("socket");
++-	if (SETSOCKOPT(s->fd, SOL_SOCKET, SO_SNDBUF, (char *) &udpbufsize, sizeof(udpbufsize)) != 0) {
++-		socket_error("setsockopt SO_SNDBUF");
++ 		return NULL;
++ 	}
++-	if (SETSOCKOPT(s->fd, SOL_SOCKET, SO_RCVBUF, (char *) &udpbufsize, sizeof(udpbufsize)) != 0) {
++-		socket_error("setsockopt SO_RCVBUF");
+++	if (setsockbufsize(s->fd, SO_SNDBUF, "SO_SNDBUF", udpbufsize) < 0)
++ 		return NULL;
++-	}
+++	if (setsockbufsize(s->fd, SO_RCVBUF, "SO_RCVBUF", udpbufsize) < 0)
++ 		return NULL;
++-	}
++ 	if (SETSOCKOPT(s->fd, SOL_SOCKET, SO_REUSEADDR, (char *) &reuse, sizeof(reuse)) != 0) {
++ 		socket_error("setsockopt SO_REUSEADDR");
++ 		return NULL;
How-To-Repeat:     Check the udp section of netstat -s after running beacon for a
    few minutes and notice "dropped due to full socket buffers" is
    increasing.
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2010-12-18 20:20:10 UTC
Maintainer of net/beacon,

Please note that PR ports/153278 has just been submitted.

If it contains a patch for an upgrade, an enhancement or a bug fix
you agree on, reply to this email stating that you approve the patch
and a committer will take care of it.

The full text of the PR can be found at:
    http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/153278

-- 
Edwin Groothuis via the GNATS Auto Assign Tool
edwin@FreeBSD.org
Comment 2 Edwin Groothuis freebsd_committer freebsd_triage 2010-12-18 20:20:12 UTC
State Changed
From-To: open->feedback

Awaiting maintainers feedback (via the GNATS Auto Assign Tool)
Comment 3 Craig Leres freebsd_committer freebsd_triage 2011-02-05 05:41:40 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Please close this PR; it has been subsumed by version 1.4 and this PR:

    http://www.freebsd.org/cgi/query-pr.cgi?pr=154519

Thanks!

		Craig
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1M4xQACgkQWxlAhAje3JszSgCfRucgqyceukAkvmFmEYf0CRAN
prAAn3zXcc4GAgXs3fB84aEerCPT4ix4
=0Oew
-----END PGP SIGNATURE-----
Comment 4 Mark Linimon freebsd_committer freebsd_triage 2011-02-05 20:08:35 UTC
State Changed
From-To: feedback->closed

Superseded by ports/154519.