diff options
author | emax <emax@FreeBSD.org> | 2012-10-18 16:34:00 +0000 |
---|---|---|
committer | emax <emax@FreeBSD.org> | 2012-10-18 16:34:00 +0000 |
commit | 1704468a31b5e651af0945f2a6ef03fd0ba23365 (patch) | |
tree | c4a94ffe1350a34832e20e53e4387ec8303b2b42 /usr.sbin/bluetooth | |
parent | c8560cd6fa89b04a65ae80e89fea9e935e193796 (diff) | |
download | FreeBSD-src-1704468a31b5e651af0945f2a6ef03fd0ba23365.zip FreeBSD-src-1704468a31b5e651af0945f2a6ef03fd0ba23365.tar.gz |
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
Diffstat (limited to 'usr.sbin/bluetooth')
-rw-r--r-- | usr.sbin/bluetooth/btpand/client.c | 34 | ||||
-rw-r--r-- | usr.sbin/bluetooth/btpand/server.c | 12 |
2 files changed, 45 insertions, 1 deletions
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"); |