From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: Jon Maloy <jmaloy@redhat.com>,
David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 1/2] tcp: probe for SO_PEEK_OFF both in tcpv4 and tcp6
Date: Wed, 24 Jul 2024 13:31:08 +1000 [thread overview]
Message-ID: <20240724033109.422311-2-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20240724033109.422311-1-david@gibson.dropbear.id.au>
From: Jon Maloy <jmaloy@redhat.com>
Based on an original patch by Jon Maloy:
--
The recently added socket option SO_PEEK_OFF is not supported for
TCP/IPv6 sockets. Until we get that support into the kernel we need to
test for support in both protocols to set the global 'peek_offset_cap´
to true.
--
Compared to the original patch:
- only check for SO_PEEK_OFF support for enabled IP versions
- use sa_family_t instead of int to pass the address family around
Fixes: e63d281871ef ("tcp: leverage support of SO_PEEK_OFF socket option when available")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Message-ID: <20240722220937.3663437-1-sbrivio@redhat.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
tcp.c | 37 +++++++++++++++++++++++++------------
1 file changed, 25 insertions(+), 12 deletions(-)
diff --git a/tcp.c b/tcp.c
index 0c66ac84..c031f13e 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2470,6 +2470,29 @@ static void tcp_sock_refill_init(const struct ctx *c)
}
}
+/**
+ * tcp_probe_peek_offset_cap() - Check if SO_PEEK_OFF is supported by kernel
+ * @af: Address family, IPv4 or IPv6
+ *
+ * Return: true if supported, false otherwise
+ */
+bool tcp_probe_peek_offset_cap(sa_family_t af)
+{
+ bool ret = false;
+ int s, optv = 0;
+
+ s = socket(af, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP);
+ if (s < 0) {
+ warn_perror("Temporary TCP socket creation failed");
+ } else {
+ if (!setsockopt(s, SOL_SOCKET, SO_PEEK_OFF, &optv, sizeof(int)))
+ ret = true;
+ close(s);
+ }
+
+ return ret;
+}
+
/**
* tcp_init() - Get initial sequence, hash secret, initialise per-socket data
* @c: Execution context
@@ -2478,9 +2501,6 @@ static void tcp_sock_refill_init(const struct ctx *c)
*/
int tcp_init(struct ctx *c)
{
- unsigned int optv = 0;
- int s;
-
ASSERT(!c->no_tcp);
if (c->ifi4)
@@ -2502,15 +2522,8 @@ int tcp_init(struct ctx *c)
NS_CALL(tcp_ns_socks_init, c);
}
- /* Probe for SO_PEEK_OFF support */
- s = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP);
- if (s < 0) {
- warn_perror("Temporary TCP socket creation failed");
- } else {
- if (!setsockopt(s, SOL_SOCKET, SO_PEEK_OFF, &optv, sizeof(int)))
- peek_offset_cap = true;
- close(s);
- }
+ peek_offset_cap = (!c->ifi4 || tcp_probe_peek_offset_cap(AF_INET)) &&
+ (!c->ifi6 || tcp_probe_peek_offset_cap(AF_INET6));
info("SO_PEEK_OFF%ssupported", peek_offset_cap ? " " : " not ");
return 0;
--
@@ -2470,6 +2470,29 @@ static void tcp_sock_refill_init(const struct ctx *c)
}
}
+/**
+ * tcp_probe_peek_offset_cap() - Check if SO_PEEK_OFF is supported by kernel
+ * @af: Address family, IPv4 or IPv6
+ *
+ * Return: true if supported, false otherwise
+ */
+bool tcp_probe_peek_offset_cap(sa_family_t af)
+{
+ bool ret = false;
+ int s, optv = 0;
+
+ s = socket(af, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP);
+ if (s < 0) {
+ warn_perror("Temporary TCP socket creation failed");
+ } else {
+ if (!setsockopt(s, SOL_SOCKET, SO_PEEK_OFF, &optv, sizeof(int)))
+ ret = true;
+ close(s);
+ }
+
+ return ret;
+}
+
/**
* tcp_init() - Get initial sequence, hash secret, initialise per-socket data
* @c: Execution context
@@ -2478,9 +2501,6 @@ static void tcp_sock_refill_init(const struct ctx *c)
*/
int tcp_init(struct ctx *c)
{
- unsigned int optv = 0;
- int s;
-
ASSERT(!c->no_tcp);
if (c->ifi4)
@@ -2502,15 +2522,8 @@ int tcp_init(struct ctx *c)
NS_CALL(tcp_ns_socks_init, c);
}
- /* Probe for SO_PEEK_OFF support */
- s = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_TCP);
- if (s < 0) {
- warn_perror("Temporary TCP socket creation failed");
- } else {
- if (!setsockopt(s, SOL_SOCKET, SO_PEEK_OFF, &optv, sizeof(int)))
- peek_offset_cap = true;
- close(s);
- }
+ peek_offset_cap = (!c->ifi4 || tcp_probe_peek_offset_cap(AF_INET)) &&
+ (!c->ifi6 || tcp_probe_peek_offset_cap(AF_INET6));
info("SO_PEEK_OFF%ssupported", peek_offset_cap ? " " : " not ");
return 0;
--
2.45.2
next prev parent reply other threads:[~2024-07-24 3:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-24 3:31 [PATCH 0/2] Small fixes for SO_PEEK_OFF David Gibson
2024-07-24 3:31 ` David Gibson [this message]
2024-07-24 3:31 ` [PATCH 2/2] tcp: Correctly update SO_PEEK_OFF when tcp_send_frames() drops frames David Gibson
2024-07-24 8:16 ` [PATCH 0/2] Small fixes for SO_PEEK_OFF Stefano Brivio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240724033109.422311-2-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=jmaloy@redhat.com \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).