summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schneider <asn@samba.org>2015-08-11 12:11:16 +0200
committerAndreas Schneider <asn@samba.org>2015-08-11 13:58:45 +0200
commit6ece682ee36794aebd08503c60ecb1797c04849f (patch)
tree4ad909eecb4ca771516633d4962bb479a7f46a38
parentc2d26a8dbd89d3db32461061e0b33df4f3eb87a1 (diff)
downloadsocket_wrapper-6ece682ee36794aebd08503c60ecb1797c04849f.tar.gz
socket_wrapper-6ece682ee36794aebd08503c60ecb1797c04849f.tar.xz
socket_wrapper-6ece682ee36794aebd08503c60ecb1797c04849f.zip
swrap: Add enviornment variable to specify mtu size
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r--doc/socket_wrapper.111
-rw-r--r--doc/socket_wrapper.1.txt9
-rw-r--r--src/socket_wrapper.c62
3 files changed, 67 insertions, 15 deletions
diff --git a/doc/socket_wrapper.1 b/doc/socket_wrapper.1
index 4e0dd01..c3cf835 100644
--- a/doc/socket_wrapper.1
+++ b/doc/socket_wrapper.1
@@ -2,12 +2,12 @@
.\" Title: socket_wrapper
.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
-.\" Date: 2014-07-09
+.\" Date: 2015-08-11
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "SOCKET_WRAPPER" "1" "2014\-07\-09" "\ \&" "\ \&"
+.TH "SOCKET_WRAPPER" "1" "2015\-08\-11" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -85,6 +85,13 @@ Additionally, the default interface to be used by an application is defined with
When debugging, it is often interesting to investigate the network traffic between the client and server within your application\&. If you define SOCKET_WRAPPER_PCAP_FILE=/path/to/file\&.pcap, socket_wrapper will dump all your network traffic to the specified file\&. After the test has been finished you\(cqre able to open the file for example with Wireshark\&.
.RE
.PP
+\fBSOCKET_WRAPPER_MTU\fR
+.RS 4
+With this variable you can change the MTU size\&. However we do not recomment to do that as the default size of 1500 byte is best for formatting PCAP files\&.
+.RE
+.sp
+The minimum value you can set is 512 and the maximum 32768\&.
+.PP
\fBSOCKET_WRAPPER_DEBUGLEVEL\fR
.RS 4
If you need to see what is going on in socket_wrapper itself or try to find a bug, you can enable logging support in socket_wrapper if you built it with debug symbols\&.
diff --git a/doc/socket_wrapper.1.txt b/doc/socket_wrapper.1.txt
index 2ab330e..f4e82a8 100644
--- a/doc/socket_wrapper.1.txt
+++ b/doc/socket_wrapper.1.txt
@@ -1,6 +1,6 @@
socket_wrapper(1)
=================
-:revdate: 2014-07-09
+:revdate: 2015-08-11
NAME
----
@@ -52,6 +52,13 @@ SOCKET_WRAPPER_PCAP_FILE=/path/to/file.pcap, socket_wrapper will dump all your
network traffic to the specified file. After the test has been finished you're
able to open the file for example with Wireshark.
+*SOCKET_WRAPPER_MTU*::
+
+With this variable you can change the MTU size. However we do not recomment to
+do that as the default size of 1500 byte is best for formatting PCAP files.
+
+The minimum value you can set is 512 and the maximum 32768.
+
*SOCKET_WRAPPER_DEBUGLEVEL*::
If you need to see what is going on in socket_wrapper itself or try to find a
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index 18622af..01ab8d5 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -203,11 +203,12 @@ enum swrap_dbglvl_e {
#define SOCKET_TYPE_CHAR_UDP_V6 'Y'
/*
- * Cut down to 1500 byte packets for stream sockets,
- * which makes it easier to format PCAP capture files
- * (as the caller will simply continue from here)
+ * Set the packet MTU to 1500 bytes for stream sockets to make it it easier to
+ * format PCAP capture files (as the caller will simply continue from here).
*/
-#define SOCKET_MAX_PACKET 1500
+#define SOCKET_WRAPPER_MTU_DEFAULT 1500
+#define SOCKET_WRAPPER_MTU_MIN 512
+#define SOCKET_WRAPPER_MTU_MAX 32768
#define SOCKET_MAX_SOCKETS 1024
@@ -912,6 +913,38 @@ static const char *socket_wrapper_dir(void)
return s;
}
+static unsigned int socket_wrapper_mtu(void)
+{
+ static unsigned int max_mtu = 0;
+ unsigned int tmp;
+ const char *s;
+ char *endp;
+
+ if (max_mtu != 0) {
+ return max_mtu;
+ }
+
+ max_mtu = SOCKET_WRAPPER_MTU_DEFAULT;
+
+ s = getenv("SOCKET_WRAPPER_MTU");
+ if (s == NULL) {
+ goto done;
+ }
+
+ tmp = strtol(s, &endp, 10);
+ if (s == endp) {
+ goto done;
+ }
+
+ if (tmp < SOCKET_WRAPPER_MTU_MIN || tmp > SOCKET_WRAPPER_MTU_MAX) {
+ goto done;
+ }
+ max_mtu = tmp;
+
+done:
+ return max_mtu;
+}
+
bool socket_wrapper_enabled(void)
{
const char *s = socket_wrapper_dir();
@@ -3743,7 +3776,9 @@ static ssize_t swrap_sendmsg_before(int fd,
}
switch (si->type) {
- case SOCK_STREAM:
+ case SOCK_STREAM: {
+ unsigned long mtu;
+
if (!si->connected) {
errno = ENOTCONN;
return -1;
@@ -3753,22 +3788,23 @@ static ssize_t swrap_sendmsg_before(int fd,
break;
}
+ mtu = socket_wrapper_mtu();
for (i = 0; i < (size_t)msg->msg_iovlen; i++) {
size_t nlen;
nlen = len + msg->msg_iov[i].iov_len;
- if (nlen > SOCKET_MAX_PACKET) {
+ if (nlen > mtu) {
break;
}
}
msg->msg_iovlen = i;
if (msg->msg_iovlen == 0) {
*tmp_iov = msg->msg_iov[0];
- tmp_iov->iov_len = MIN(tmp_iov->iov_len, SOCKET_MAX_PACKET);
+ tmp_iov->iov_len = MIN(tmp_iov->iov_len, mtu);
msg->msg_iov = tmp_iov;
msg->msg_iovlen = 1;
}
break;
-
+ }
case SOCK_DGRAM:
if (si->connected) {
if (msg->msg_name) {
@@ -3958,7 +3994,8 @@ static int swrap_recvmsg_before(int fd,
(void)fd; /* unused */
switch (si->type) {
- case SOCK_STREAM:
+ case SOCK_STREAM: {
+ unsigned int mtu;
if (!si->connected) {
errno = ENOTCONN;
return -1;
@@ -3968,22 +4005,23 @@ static int swrap_recvmsg_before(int fd,
break;
}
+ mtu = socket_wrapper_mtu();
for (i = 0; i < (size_t)msg->msg_iovlen; i++) {
size_t nlen;
nlen = len + msg->msg_iov[i].iov_len;
- if (nlen > SOCKET_MAX_PACKET) {
+ if (nlen > mtu) {
break;
}
}
msg->msg_iovlen = i;
if (msg->msg_iovlen == 0) {
*tmp_iov = msg->msg_iov[0];
- tmp_iov->iov_len = MIN(tmp_iov->iov_len, SOCKET_MAX_PACKET);
+ tmp_iov->iov_len = MIN(tmp_iov->iov_len, mtu);
msg->msg_iov = tmp_iov;
msg->msg_iovlen = 1;
}
break;
-
+ }
case SOCK_DGRAM:
if (msg->msg_name == NULL) {
errno = EINVAL;