From 6228a3b8743ea2a6589070de926588e2ceb0f27f Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 7 Dec 2016 13:21:46 -0200 Subject: *: 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 Signed-off-by: David Lamparter --- ospf6d/ospf6_network.c | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) (limited to 'ospf6d/ospf6_network.c') diff --git a/ospf6d/ospf6_network.c b/ospf6d/ospf6_network.c index 0d730c596..0217d6603 100644 --- a/ospf6d/ospf6_network.c +++ b/ospf6d/ospf6_network.c @@ -118,8 +118,6 @@ ospf6_sso (ifindex_t ifindex, struct in6_addr *group, int option) struct ipv6_mreq mreq6; int ret; int bufsize = (8 * 1024 * 1024); - int optval; - socklen_t optlen = sizeof(optval); assert (ifindex); mreq6.ipv6mr_interface = ifindex; @@ -134,40 +132,8 @@ ospf6_sso (ifindex_t ifindex, struct in6_addr *group, int option) return ret; } - if ((ret = setsockopt (ospf6_sock, SOL_SOCKET, SO_SNDBUF, - &bufsize, sizeof (bufsize))) < 0) - { - zlog_err ("Couldn't increase raw wbuf size: %s\n", safe_strerror(errno)); - return ret; - } - - if ((ret = getsockopt (ospf6_sock, SOL_SOCKET, SO_SNDBUF, - &optval, &optlen)) < 0) - { - zlog_err ("getsockopt of SO_SNDBUF failed with error %s\n", safe_strerror(errno)); - return ret; - } - else if (optval < bufsize) - { - zlog_err ("Unable to SO_SNDBUF to %d, set to %d\n", bufsize, optval); - } - - if ((ret = setsockopt (ospf6_sock, SOL_SOCKET, SO_RCVBUF, - &bufsize, sizeof (bufsize))) < 0) - { - zlog_err ("Couldn't increase raw rbuf size: %s\n", safe_strerror(errno)); - } - - if ((ret = getsockopt (ospf6_sock, SOL_SOCKET, SO_RCVBUF, - &optval, &optlen)) < 0) - { - zlog_err ("getsockopt of SO_RCVBUF failed with error %s\n", safe_strerror(errno)); - return ret; - } - else if (optval < bufsize) - { - zlog_err ("Unable to SO_RCVBUF to %d, set to %d\n", bufsize, optval); - } + setsockopt_so_sendbuf (ospf6_sock, bufsize); + setsockopt_so_recvbuf (ospf6_sock, bufsize); return 0; } -- cgit v1.2.3