From d4d61480b6883d462a2c3c99eaf315259e78c984 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Tue, 5 Oct 2021 19:27:04 +0200 Subject: tcp, tap: Turn tcp_probe_mem() into sock_probe_mem(), use for AF_UNIX socket too Signed-off-by: Stefano Brivio --- util.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'util.c') diff --git a/util.c b/util.c index 3cf3a82..66b088a 100644 --- a/util.c +++ b/util.c @@ -212,6 +212,34 @@ int sock_l4(struct ctx *c, int af, uint8_t proto, uint16_t port, return fd; } +/** + * 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 -- cgit v1.2.3