Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 18 Dec 2010 12:17:48 -0800
From:      Craig Leres <leres@ee.lbl.gov>
To:        freebsd-gnats-submit@FreeBSD.org
Cc:        Jon Dugan <jdugan@es.net>, Cedric Hui <chui@lbl.gov>
Subject:   ports/153278: [PATCH] net/beacon: Fix udp socket buffer sizes
Message-ID:  <4D0D16EC.2090302@ee.lbl.gov>
Resent-Message-ID: <201012182020.oBIKK62x046029@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         153278
>Category:       ports
>Synopsis:       [PATCH] net/beacon: Fix udp socket buffer sizes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Dec 18 20:20:06 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Craig Leres
>Release:        FreeBSD 7.2-RELEASE amd64
>Organization:
Lawrence Berkeley National Laboratory
>Environment:
	FreeBSD mon.lbl.gov 7.2-RELEASE FreeBSD 7.2-RELEASE #0 r105: Mon Dec 13
14:35:39 PST 2010
leres@fun.ee.lbl.gov:/home/fun/u2/src/7.2-RELEASE/sys/amd64/compile/GENERIC
 amd64

>Description:
    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.

>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.

>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"

--- 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;

--------------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--
>Release-Note:
>Audit-Trail:
>Unformatted:
 This is a multi-part message in MIME format.
 --------------020202000407000805010102
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4D0D16EC.2090302>