aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMaksim Yevmenkin <emax@FreeBSD.org>2012-10-18 16:34:00 +0000
committerMaksim Yevmenkin <emax@FreeBSD.org>2012-10-18 16:34:00 +0000
commit2dcf7e97da1eb6ef8c733be9f6069e9eda1b773d (patch)
treec4a94ffe1350a34832e20e53e4387ec8303b2b42 /usr.sbin
parent77833fb00d0ebd6e9d575d7e3fd1a5ae04f5effb (diff)
downloadsrc-2dcf7e97da1eb6ef8c733be9f6069e9eda1b773d.tar.gz
src-2dcf7e97da1eb6ef8c733be9f6069e9eda1b773d.zip
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
Notes
Notes: svn path=/head/; revision=241699
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bluetooth/btpand/client.c34
-rw-r--r--usr.sbin/bluetooth/btpand/server.c12
2 files changed, 45 insertions, 1 deletions
diff --git a/usr.sbin/bluetooth/btpand/client.c b/usr.sbin/bluetooth/btpand/client.c
index 97064dbbbddc..2cc908996584 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 0843d0c70926..b24d416ff196 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");