aboutgitcodebugslistschat
path: root/util.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2021-10-05 19:27:04 +0200
committerStefano Brivio <sbrivio@redhat.com>2021-10-05 20:02:03 +0200
commitd4d61480b6883d462a2c3c99eaf315259e78c984 (patch)
tree099527a3fb68fcabe3953c55d67de9484ce9309b /util.c
parenteef4e82903311c73a5da3030da7eee790ce783a5 (diff)
downloadpasst-d4d61480b6883d462a2c3c99eaf315259e78c984.tar
passt-d4d61480b6883d462a2c3c99eaf315259e78c984.tar.gz
passt-d4d61480b6883d462a2c3c99eaf315259e78c984.tar.bz2
passt-d4d61480b6883d462a2c3c99eaf315259e78c984.tar.lz
passt-d4d61480b6883d462a2c3c99eaf315259e78c984.tar.xz
passt-d4d61480b6883d462a2c3c99eaf315259e78c984.tar.zst
passt-d4d61480b6883d462a2c3c99eaf315259e78c984.zip
tcp, tap: Turn tcp_probe_mem() into sock_probe_mem(), use for AF_UNIX socket too
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'util.c')
-rw-r--r--util.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/util.c b/util.c
index 3cf3a82..66b088a 100644
--- a/util.c
+++ b/util.c
@@ -213,6 +213,34 @@ int sock_l4(struct ctx *c, int af, uint8_t proto, uint16_t port,
}
/**
+ * sock_probe_mem() - Check if setting high SO_SNDBUF and SO_RCVBUF is allowed
+ * @c: Execution context
+ */
+void sock_probe_mem(struct ctx *c)
+{
+ int v = INT_MAX / 2, s;
+ socklen_t sl;
+
+ if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+ c->low_wmem = c->low_rmem = 1;
+ return;
+ }
+
+ sl = sizeof(v);
+ if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &v, sizeof(v)) ||
+ getsockopt(s, SOL_SOCKET, SO_SNDBUF, &v, &sl) || v < SNDBUF_BIG)
+ c->low_wmem = 1;
+
+ v = INT_MAX / 2;
+ if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &v, sizeof(v)) ||
+ getsockopt(s, SOL_SOCKET, SO_RCVBUF, &v, &sl) || v < RCVBUF_BIG)
+ c->low_rmem = 1;
+
+ close(s);
+}
+
+
+/**
* timespec_diff_ms() - Report difference in milliseconds between two timestamps
* @a: Minuend timestamp
* @b: Subtrahend timestamp