diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2021-10-05 19:27:04 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2021-10-05 20:02:03 +0200 |
commit | d4d61480b6883d462a2c3c99eaf315259e78c984 (patch) | |
tree | 099527a3fb68fcabe3953c55d67de9484ce9309b /util.c | |
parent | eef4e82903311c73a5da3030da7eee790ce783a5 (diff) | |
download | passt-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.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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 |