MPTCP Linux Development
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: mptcp@lists.linux.dev
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH mptcp-next] selftests: mptcp: add TCP_DEFER test case
Date: Mon,  2 May 2022 18:36:41 +0200	[thread overview]
Message-ID: <20220502163641.6146-1-fw@strlen.de> (raw)

Check that value x can be set and retrieved.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 .../selftests/net/mptcp/mptcp_sockopt.c       | 41 ++++++++++++++++++-
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
index ac9a4d9c1764..12aa2d921fd5 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
@@ -133,10 +133,43 @@ static void xgetaddrinfo(const char *node, const char *service,
 	}
 }
 
+static void check_tcp_defer(int sock, unsigned int value)
+{
+	unsigned int rv;
+	socklen_t rvl;
+	int err;
+
+	rvl = sizeof(rv);
+	err = getsockopt(sock, IPPROTO_TCP, TCP_DEFER_ACCEPT, &rv, &rvl);
+	if (err) {
+		perror("getsockopt TCP_DEFER_ACCEPT");
+		exit(1);
+	}
+
+	assert(rvl == (int)sizeof(rv));
+	assert(rv == value);
+}
+
+static unsigned int set_tcp_defer(int sock)
+{
+	unsigned int v = rand();
+	int err;
+
+	v &= 0x1f;
+
+	err = setsockopt(sock, IPPROTO_TCP, TCP_DEFER_ACCEPT, &v, sizeof(v));
+	if (err) {
+		perror("setsockopt TCP_DEFER_ACCEPT");
+		exit(1);
+	}
+
+	return v;
+}
+
 static int sock_listen_mptcp(const char * const listenaddr,
 			     const char * const port)
 {
-	int sock;
+	int sock, value;
 	struct addrinfo hints = {
 		.ai_protocol = IPPROTO_TCP,
 		.ai_socktype = SOCK_STREAM,
@@ -173,9 +206,13 @@ static int sock_listen_mptcp(const char * const listenaddr,
 	if (sock < 0)
 		xerror("could not create listen socket");
 
+	value = set_tcp_defer(sock);
+
 	if (listen(sock, 20))
 		die_perror("listen");
 
+	check_tcp_defer(sock, value);
+
 	return sock;
 }
 
@@ -630,7 +667,7 @@ static void test_ip_tos_sockopt(int fd)
 	r = getsockopt(fd, SOL_IP, IP_TOS, &tos_out, &s);
 	if (r != -1 && errno != EINVAL)
 		die_perror("getsockopt IP_TOS did not indicate -EINVAL");
-	if (s != -1)
+	if ((int)s != -1)
 		xerror("expect socklen_t == -1");
 }
 
-- 
2.35.1


             reply	other threads:[~2022-05-02 16:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-02 16:36 Florian Westphal [this message]
2022-05-02 18:14 ` selftests: mptcp: add TCP_DEFER test case: Tests Results MPTCP CI
2022-05-03 21:22 ` [PATCH mptcp-next] selftests: mptcp: add TCP_DEFER test case Mat Martineau
2022-05-03 21:32   ` Florian Westphal
2022-05-05  0:04     ` Mat Martineau

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=20220502163641.6146-1-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=mptcp@lists.linux.dev \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox