summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2016-12-07 16:21:46 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2016-12-08 12:50:25 +0100
commit6228a3b8743ea2a6589070de926588e2ceb0f27f (patch)
tree1d4f333086f14d333c2aae31b1c01a27e55e8b0b /lib
parentospfd: set the OSPF socket's send buffer size only once (diff)
downloadfrr-6228a3b8743ea2a6589070de926588e2ceb0f27f.tar.xz
frr-6228a3b8743ea2a6589070de926588e2ceb0f27f.zip
*: always set SO_SNDBUF and SO_RCVBUF using a best effort approach
If we fail to set any socket's buffer size, try again with a smaller value and keep going until it succeeds. This is better than just giving up or, even worse, abort the creation of a socket (ospf6d and ripd). Fix broken ospf6d on FreeBSD. Signed-off-by: Renato Westphal <renato@opensourcerouting.org> Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/sockopt.c32
-rw-r--r--lib/sockopt.h4
2 files changed, 18 insertions, 18 deletions
diff --git a/lib/sockopt.c b/lib/sockopt.c
index be3ac0e4b..461e1f7f5 100644
--- a/lib/sockopt.c
+++ b/lib/sockopt.c
@@ -29,30 +29,30 @@
#include "sockopt.h"
#include "sockunion.h"
-int
+void
setsockopt_so_recvbuf (int sock, int size)
{
- int ret;
-
- if ( (ret = setsockopt (sock, SOL_SOCKET, SO_RCVBUF, (char *)
- &size, sizeof (int))) < 0)
- zlog_err ("fd %d: can't setsockopt SO_RCVBUF to %d: %s",
- sock,size,safe_strerror(errno));
+ int orig_req = size;
- return ret;
+ while (setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &size, sizeof (size)) == -1)
+ size /= 2;
+
+ if (size != orig_req)
+ zlog_warn ("%s: fd %d: SO_RCVBUF set to %d (requested %d)", __func__, sock,
+ size, orig_req);
}
-int
+void
setsockopt_so_sendbuf (const int sock, int size)
{
- int ret = setsockopt (sock, SOL_SOCKET, SO_SNDBUF,
- (char *)&size, sizeof (int));
-
- if (ret < 0)
- zlog_err ("fd %d: can't setsockopt SO_SNDBUF to %d: %s",
- sock, size, safe_strerror (errno));
+ int orig_req = size;
- return ret;
+ while (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &size, sizeof (size)) == -1)
+ size /= 2;
+
+ if (size != orig_req)
+ zlog_warn ("%s: fd %d: SO_SNDBUF set to %d (requested %d)", __func__, sock,
+ size, orig_req);
}
int
diff --git a/lib/sockopt.h b/lib/sockopt.h
index 02f018934..b3ab57ab7 100644
--- a/lib/sockopt.h
+++ b/lib/sockopt.h
@@ -24,8 +24,8 @@
#include "sockunion.h"
-extern int setsockopt_so_recvbuf (int sock, int size);
-extern int setsockopt_so_sendbuf (const int sock, int size);
+extern void setsockopt_so_recvbuf (int sock, int size);
+extern void setsockopt_so_sendbuf (const int sock, int size);
extern int getsockopt_so_sendbuf (const int sock);
#ifdef HAVE_IPV6