From 1704468a31b5e651af0945f2a6ef03fd0ba23365 Mon Sep 17 00:00:00 2001 From: emax Date: Thu, 18 Oct 2012 16:34:00 +0000 Subject: make sure that socket's send and receive buffers are properly sized Submitted by: Iain Hibbert plunky at rya-online dot net MFC after: 3 weeks --- usr.sbin/bluetooth/btpand/client.c | 34 +++++++++++++++++++++++++++++++++- usr.sbin/bluetooth/btpand/server.c | 12 ++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) (limited to 'usr.sbin/bluetooth') diff --git a/usr.sbin/bluetooth/btpand/client.c b/usr.sbin/bluetooth/btpand/client.c index 97064db..2cc9089 100644 --- a/usr.sbin/bluetooth/btpand/client.c +++ b/usr.sbin/bluetooth/btpand/client.c @@ -47,7 +47,7 @@ client_init(void) struct sockaddr_l2cap sa; channel_t *chan; socklen_t len; - int fd; + int fd, n; uint16_t mru, mtu; if (bdaddr_any(&remote_bdaddr)) @@ -97,6 +97,17 @@ client_init(void) exit(EXIT_FAILURE); } + len = sizeof(n); + if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, &len) == -1) { + log_err("Could not read SO_RCVBUF"); + exit(EXIT_FAILURE); + } + if (n < (mru * 10)) { + n = mru * 10; + if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1) + log_info("Could not increase SO_RCVBUF (from %d)", n); + } + len = sizeof(mtu); if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_OMTU, &mtu, &len) == -1) { log_err("Could not get L2CAP OMTU: %m"); @@ -107,6 +118,27 @@ client_init(void) exit(EXIT_FAILURE); } + len = sizeof(n); + if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, &len) == -1) { + log_err("Could not get socket send buffer size: %m"); + close(fd); + return; + } + if (n < (mtu * 2)) { + n = mtu * 2; + if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) == -1) { + log_err("Could not set socket send buffer size (%d): %m", n); + close(fd); + return; + } + } + n = mtu; + if (setsockopt(fd, SOL_SOCKET, SO_SNDLOWAT, &n, sizeof(n)) == -1) { + log_err("Could not set socket low water mark (%d): %m", n); + close(fd); + return; + } + chan = channel_alloc(); if (chan == NULL) exit(EXIT_FAILURE); diff --git a/usr.sbin/bluetooth/btpand/server.c b/usr.sbin/bluetooth/btpand/server.c index 0843d0c..b24d416 100644 --- a/usr.sbin/bluetooth/btpand/server.c +++ b/usr.sbin/bluetooth/btpand/server.c @@ -177,6 +177,18 @@ server_read(int s, short ev, void *arg) return; } + len = sizeof(n); + if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, &len) == -1) { + log_err("Could not read SO_RCVBUF"); + close(fd); + return; + } + if (n < (mru * 10)) { + n = mru * 10; + if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1) + log_info("Could not increase SO_RCVBUF (from %d)", n); + } + len = sizeof(mtu); if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_OMTU, &mtu, &len) == -1) { log_err("Could not get L2CAP OMTU: %m"); -- cgit v1.1