From patchwork Mon Jun 17 08:33:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13700316 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1914B17F5; Mon, 17 Jun 2024 08:33:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613212; cv=none; b=pwAVG1NeUfGsMeqKbXAIcA0MeQdAXl7HtQ2YczLiEGL6wfDN/ausOrK80CaLIkxuAB43vyNtXpA5TAT5pnZGwAldBa1hOmFuvQ/Wf5QSL4DOxnNPScaDe11JH2bITw5ulGIfHYG9sqyJ6gHOB3v1VyOqfldzQX0+k9/cFyCIuxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613212; c=relaxed/simple; bh=AsdAeRE0aIxwv2Q2OeCYD5fNH5nAbKhA8vWFDG9rv9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CJhHos7ZInQxzeLqgluydj0yZAmZEy8OrvrrS/t0nabQwsx0tUujJhyliTQoY5/BNlHOOQfYgpJ9Na6/U3lLVQhOpK5/P0CFq3c+ywG0xJX1ZZh1vfep2agvwr4ivAifXjWRownP3+t49CEzLcbWRcPZrz96w5w8RWKGFaIJqTo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Oh3PZfpQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Oh3PZfpQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3228C3277B; Mon, 17 Jun 2024 08:33:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718613211; bh=AsdAeRE0aIxwv2Q2OeCYD5fNH5nAbKhA8vWFDG9rv9s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oh3PZfpQn8LS8QytECiWAm2IZAa5d7GkN+Mr0HKS8j0OtolRReVrcutC/Rdtu79sK cxGozLWQ8Xptq41PeFBHZAc6bStAOHApsjO6zNaCRMWGH1au4AA+Q3R7iZh06iudKF 62ONbz2AAn8ry2v7MuaEhgJG9sw2L+LLsc+fDDDAPyuJ//XhDCv0XGvo/4jo0cR11d yhLuIiLyxjmGcDRvq1BS6gi+Jb/YXXSjaYd7Gd1MCUMCujVOJ5so48rwwF6rbMiG9E jGcWutwOqQlh8KihVrZ5A5QKA9mLiCXRLF01KDjCCGkPcQkyV0c83vfnkn1NZwXHLz CrYh0Ojf3s6Jw== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH mptcp-next v3 1/6] selftests/bpf: Drop type from network_helper_opts Date: Mon, 17 Jun 2024 16:33:06 +0800 Message-ID: <6a902bdceb90763bfeb6500fc2ce70acf7cf51ad.1718612857.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang The opts.{type, noconnect} is at least a bit non intuitive or unnecessary. The only use case now is in test_bpf_ip_check_defrag_ok which ends up bypassing most (or at least some) of the connect_to_fd_opts() logic. It's much better that test should have its own connect_to_fd_opts() instead. This patch adds a new "type" parameter for connect_to_fd_opts(), then opts->type and getsockopt(SO_TYPE) can be replaced by "type" parameter in it. In connect_to_fd(), use getsockopt(SO_TYPE) to get "type" value and pass it to connect_to_fd_opts(). In bpf_tcp_ca.c and cgroup_v1v2.c, "SOCK_STREAM" types are passed to connect_to_fd_opts(), and in ip_check_defrag.c, different types "SOCK_RAW" and "SOCK_DGRAM" are passed to it. With these changes, the strcut member "type" of network_helper_opts can be dropped now. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 26 +++++++++---------- tools/testing/selftests/bpf/network_helpers.h | 3 +-- .../selftests/bpf/prog_tests/bpf_tcp_ca.c | 2 +- .../selftests/bpf/prog_tests/cgroup_v1v2.c | 4 +-- .../bpf/prog_tests/ip_check_defrag.c | 5 ++-- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index e20caef06aae..c0efccaae488 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -303,27 +303,16 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add return -1; } -int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts) +int connect_to_fd_opts(int server_fd, int type, const struct network_helper_opts *opts) { struct sockaddr_storage addr; struct sockaddr_in *addr_in; socklen_t addrlen, optlen; - int fd, type, protocol; + int fd, protocol; if (!opts) opts = &default_opts; - optlen = sizeof(type); - - if (opts->type) { - type = opts->type; - } else { - if (getsockopt(server_fd, SOL_SOCKET, SO_TYPE, &type, &optlen)) { - log_err("getsockopt(SOL_TYPE)"); - return -1; - } - } - if (opts->proto) { protocol = opts->proto; } else { @@ -369,8 +358,17 @@ int connect_to_fd(int server_fd, int timeout_ms) struct network_helper_opts opts = { .timeout_ms = timeout_ms, }; + socklen_t optlen; + int type; + + optlen = sizeof(type); + + if (getsockopt(server_fd, SOL_SOCKET, SO_TYPE, &type, &optlen)) { + log_err("getsockopt(SOL_TYPE)"); + return -1; + } - return connect_to_fd_opts(server_fd, &opts); + return connect_to_fd_opts(server_fd, type, &opts); } int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms) diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index 11eea8e2e4f1..c92bed35dfe2 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -25,7 +25,6 @@ struct network_helper_opts { int timeout_ms; bool must_fail; bool noconnect; - int type; int proto; int (*post_socket_cb)(int fd, void *opts); void *cb_opts; @@ -61,7 +60,7 @@ void free_fds(int *fds, unsigned int nr_close_fds); int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t len, const struct network_helper_opts *opts); int connect_to_fd(int server_fd, int timeout_ms); -int connect_to_fd_opts(int server_fd, const struct network_helper_opts *opts); +int connect_to_fd_opts(int server_fd, int type, const struct network_helper_opts *opts); int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms); int fastopen_connect(int server_fd, const char *data, unsigned int data_len, int timeout_ms); diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c index 67358adf5db3..164f237b24dd 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c @@ -49,7 +49,7 @@ static bool start_test(char *addr_str, goto err; /* connect to server */ - *cli_fd = connect_to_fd_opts(*srv_fd, cli_opts); + *cli_fd = connect_to_fd_opts(*srv_fd, SOCK_STREAM, cli_opts); if (!ASSERT_NEQ(*cli_fd, -1, "connect_to_fd_opts")) goto err; diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c b/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c index addf720428f7..9709c8db7275 100644 --- a/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_v1v2.c @@ -32,7 +32,7 @@ static int run_test(int cgroup_fd, int server_fd, bool classid) goto out; } - fd = connect_to_fd_opts(server_fd, &opts); + fd = connect_to_fd_opts(server_fd, SOCK_STREAM, &opts); if (fd < 0) err = -1; else @@ -52,7 +52,7 @@ void test_cgroup_v1v2(void) server_fd = start_server(AF_INET, SOCK_STREAM, NULL, port, 0); if (!ASSERT_GE(server_fd, 0, "server_fd")) return; - client_fd = connect_to_fd_opts(server_fd, &opts); + client_fd = connect_to_fd_opts(server_fd, SOCK_STREAM, &opts); if (!ASSERT_GE(client_fd, 0, "client_fd")) { close(server_fd); return; diff --git a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c index 284764e7179f..1607a05bf2c2 100644 --- a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c +++ b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c @@ -164,7 +164,6 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) }; struct network_helper_opts tx_ops = { .timeout_ms = 1000, - .type = SOCK_RAW, .proto = IPPROTO_RAW, .noconnect = true, }; @@ -201,7 +200,7 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) nstoken = open_netns(NS0); if (!ASSERT_OK_PTR(nstoken, "setns ns0")) goto out; - client_tx_fd = connect_to_fd_opts(srv_fd, &tx_ops); + client_tx_fd = connect_to_fd_opts(srv_fd, SOCK_RAW, &tx_ops); close_netns(nstoken); if (!ASSERT_GE(client_tx_fd, 0, "connect_to_fd_opts")) goto out; @@ -210,7 +209,7 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) nstoken = open_netns(NS0); if (!ASSERT_OK_PTR(nstoken, "setns ns0")) goto out; - client_rx_fd = connect_to_fd_opts(srv_fd, &rx_opts); + client_rx_fd = connect_to_fd_opts(srv_fd, SOCK_DGRAM, &rx_opts); close_netns(nstoken); if (!ASSERT_GE(client_rx_fd, 0, "connect_to_fd_opts")) goto out; From patchwork Mon Jun 17 08:33:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13700317 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2BEA187331; Mon, 17 Jun 2024 08:33:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613218; cv=none; b=icpXk9JEUjNVAkHo7JjkaxgqxzQTu1YikyQB5vh0dy5CveMG2j918uPYWS5oz96N8Ji2m64Ku/bLZNlAIN1j2ucxB4S6OiNgmEMklG4KGYl5EOGJdDsUG6JwVJfCfnFoj1F2NT0sF0/wguVSTnWn2tbDRYM9NwwEbqQmjs+aZGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613218; c=relaxed/simple; bh=aEFykOZejhBgMZF7//pmJaPg/hEDx7vFpnaHlP05k68=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n1O63O1IdjQbuqeMS4IPQUUSNTyuixnnrhTwK7KR8+jHC1BaNpqjSKIzQ076+ultz3A/uwbST9LdCLg8TLpDMNxVUF6+gGTZ6cmXJYgczJaqheS0u173Tc4YUnw0O5csCB591IkTdo97anXd7H8hwY4F5TSzm07c1gvhWXhesSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W9+RB92B; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="W9+RB92B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AE8EC3277B; Mon, 17 Jun 2024 08:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718613217; bh=aEFykOZejhBgMZF7//pmJaPg/hEDx7vFpnaHlP05k68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W9+RB92B4IMOvz8FQzyahXUSI116AypsqCzYxaFTDtyG1JXXWKYZG1QqznniDAqnp zdQjs0q7Hp0FXDJl89lGdft3FgYGYpcMkUY5//5PxIaJQf1ZwjzJaQxTKq8QIo8Eay E2m4TJUddTEBlmEXQUQw26KJVkiOZvENhcLh1NRxcoxDfQShxDq9+VHY3qvlQqVL7p Eu32/I3HJXfOK1RfF/64tiqVg9MEKoUBNoFlbkFx2rvAK+rPuOgjEagvecfBJ/Y8z8 +gYuoDaD+8P50Qfjn8dKj+uknwPjyLffHguUXnCFJN1TsNxMU9OP1zZYF1P6DT3e7K /ki2X/+Zpixzw== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH mptcp-next v3 2/6] selftests/bpf: Use connect_to_addr in connect_to_fd_opt Date: Mon, 17 Jun 2024 16:33:07 +0800 Message-ID: <67fd5e82a8d7041e964b8ff9d943ac4947690d7d.1718612857.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang This patch moves "post_socket_cb" and "noconnect" into connect_to_addr(), then connect_to_fd_opts() can be implemented by getsockname() and connect_to_addr(). This change makes connect_to_* interfaces more unified. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 47 ++++--------------- 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index c0efccaae488..028dfe9001e4 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -293,9 +293,14 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add if (settimeo(fd, opts->timeout_ms)) goto error_close; - if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail)) + if (opts->post_socket_cb && + opts->post_socket_cb(fd, opts->cb_opts)) goto error_close; + if (!opts->noconnect) + if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail)) + goto error_close; + return fd; error_close: @@ -306,21 +311,7 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add int connect_to_fd_opts(int server_fd, int type, const struct network_helper_opts *opts) { struct sockaddr_storage addr; - struct sockaddr_in *addr_in; - socklen_t addrlen, optlen; - int fd, protocol; - - if (!opts) - opts = &default_opts; - - if (opts->proto) { - protocol = opts->proto; - } else { - if (getsockopt(server_fd, SOL_SOCKET, SO_PROTOCOL, &protocol, &optlen)) { - log_err("getsockopt(SOL_PROTOCOL)"); - return -1; - } - } + socklen_t addrlen; addrlen = sizeof(addr); if (getsockname(server_fd, (struct sockaddr *)&addr, &addrlen)) { @@ -328,29 +319,7 @@ int connect_to_fd_opts(int server_fd, int type, const struct network_helper_opts return -1; } - addr_in = (struct sockaddr_in *)&addr; - fd = socket(addr_in->sin_family, type, protocol); - if (fd < 0) { - log_err("Failed to create client socket"); - return -1; - } - - if (settimeo(fd, opts->timeout_ms)) - goto error_close; - - if (opts->post_socket_cb && - opts->post_socket_cb(fd, opts->cb_opts)) - goto error_close; - - if (!opts->noconnect) - if (connect_fd_to_addr(fd, &addr, addrlen, opts->must_fail)) - goto error_close; - - return fd; - -error_close: - save_errno_close(fd); - return -1; + return connect_to_addr(type, &addr, addrlen, opts); } int connect_to_fd(int server_fd, int timeout_ms) From patchwork Mon Jun 17 08:33:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13700318 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 815CB190693; Mon, 17 Jun 2024 08:33:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613223; cv=none; b=Y136ws7v9GnBdDPBRBf6pVpQV/sB+286pK6e6Dhn81BIwEAqbH02prIySmnPZu7vgR7MP7DR3RFXOYRb5N32tuOSRDJVVYxgvZb3bE4rL6VniRWHp3EOYpOWwZxn0pxi3i/pbnBCe3TK1qmUGaVElEj9XhaOYpMVaZBk7umR1So= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613223; c=relaxed/simple; bh=X/LxyGZLZ9oatWPHMAY/G5tTZCrag5nUuRKRgwlgybw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aR9diyjjcbYropZvYe11YAdIKEm9hpG/4fduO9O5LK5Vk4bmo/rL53nSqeO20W3yS53j/GVZfmz9DHg6+WR2dh3M8KB+mSbfwp0Pe9ab6Mgb2ndUiyxlc/YZsemacYXRXNA2mRC4US/PN+n2Uva53m3teD+YzoN8xeG8FYXG/4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lAZ1uDqg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lAZ1uDqg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED675C4AF1A; Mon, 17 Jun 2024 08:33:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718613223; bh=X/LxyGZLZ9oatWPHMAY/G5tTZCrag5nUuRKRgwlgybw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lAZ1uDqgPVoa6IlEYp5AdjnVmS5nhIOFmBu5rwW7nNuaIPdiSI7vrGvMterRbYi3B Ru6wZh5ZY6rTGe8C0HyscfaxCskZNoVIBOx4ABAJJJZ1XNPfXPRUHjyZcz4R3HruUe 6fK7ROjBghK+/L3Sk6fJcjY/ca9XKn5AS7xxlGn2crbFnGjyshcY1bcucPKLBbtElD k1Eu8+S9Sf5ukhDfEVb7GaS+B7X2pkqAUZGYlTgbqU/9+XDeiI5Bq0QnV/wUZDTRUK pDL9KKmHi0OyL1mfk1J9XRHjGsdCtSWz09VPbNStDuOqZBrvPeboBmu/ljEoiyf6uR yg/akGxyBnQtA== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH mptcp-next v3 3/6] selftests/bpf: Add client_socket helper Date: Mon, 17 Jun 2024 16:33:08 +0800 Message-ID: <8be911a728dbd8dd50c55434a46cf960c51ae7c9.1718612857.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang This patch extracts a new helper client_socket() from connect_to_fd_opts() to create the client socket, but don't connect to the server. Then connect_to_fd_opts() can be implemented using client_socket() and connect_fd_to_addr(). This helper can be used in connect_to_addr() too, and make "noconnect" opts useless. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 40 ++++++++++++++----- tools/testing/selftests/bpf/network_helpers.h | 2 + 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 028dfe9001e4..3afeddeead39 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -249,6 +249,34 @@ int fastopen_connect(int server_fd, const char *data, unsigned int data_len, return -1; } +int client_socket(int family, int type, + const struct network_helper_opts *opts) +{ + int fd; + + if (!opts) + opts = &default_opts; + + fd = socket(family, type, opts->proto); + if (fd < 0) { + log_err("Failed to create client socket"); + return -1; + } + + if (settimeo(fd, opts->timeout_ms)) + goto error_close; + + if (opts->post_socket_cb && + opts->post_socket_cb(fd, opts->cb_opts)) + goto error_close; + + return fd; + +error_close: + save_errno_close(fd); + return -1; +} + static int connect_fd_to_addr(int fd, const struct sockaddr_storage *addr, socklen_t addrlen, const bool must_fail) @@ -281,22 +309,12 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add { int fd; - if (!opts) - opts = &default_opts; - - fd = socket(addr->ss_family, type, opts->proto); + fd = client_socket(addr->ss_family, type, opts); if (fd < 0) { log_err("Failed to create client socket"); return -1; } - if (settimeo(fd, opts->timeout_ms)) - goto error_close; - - if (opts->post_socket_cb && - opts->post_socket_cb(fd, opts->cb_opts)) - goto error_close; - if (!opts->noconnect) if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail)) goto error_close; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index c92bed35dfe2..e89eadfb02d6 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -57,6 +57,8 @@ int *start_reuseport_server(int family, int type, const char *addr_str, int start_server_addr(int type, const struct sockaddr_storage *addr, socklen_t len, const struct network_helper_opts *opts); void free_fds(int *fds, unsigned int nr_close_fds); +int client_socket(int family, int type, + const struct network_helper_opts *opts); int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t len, const struct network_helper_opts *opts); int connect_to_fd(int server_fd, int timeout_ms); From patchwork Mon Jun 17 08:33:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13700319 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A9A1190499; Mon, 17 Jun 2024 08:33:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613229; cv=none; b=C//tVq6KQ5h+vQQjJcyge8JsJM7CYNPr6zX3ZdktxddBGSfox4UUJ5olBlrj4KaT+cMOJYX9taetpRSDfycZEqcc3CwsASWNSsVA0zSrAsCMbfr7TQ/ReikUpBhO8v3samV6gmiRro37Vg/hoRvWb+67r1v+nmfmXxrCyZeqle4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613229; c=relaxed/simple; bh=dONvtBc6jyUucALIR2AS8nKEZfwDAlGd7sZO1E3sQaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lJndwlwvDIHC5jkynUz9YCeCxKXZRd9IcAe/qnm/uLgqVNpqgq778Sf4grVWjEnEtVJ/3ciMvUsqyb/K5bBWQVDnPT0OilFCGdtcf4lOvrJoG9Yb5xsRxWugHFogOBSsSHNNuiYugeVuT70ynnIyZx6oh0GGMvui+9AJI0IW6aA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DmsIi+/p; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DmsIi+/p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D239C4AF52; Mon, 17 Jun 2024 08:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718613228; bh=dONvtBc6jyUucALIR2AS8nKEZfwDAlGd7sZO1E3sQaw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DmsIi+/pEiO9Rhd1SaQIkgYf0sweDKi9udqGfQWZs5EYd9y77hmsliv0ymTa9XuvQ gwv8ieKudsBfkxHGp81bE4IrHQEQFn8x/BGOw12WLTNkyzjBHo7IjlL556DcqOX7wO St04yXPJfc2cW5GcXQ5mFWCKopDiQCDZsbSpcmj0ppnLNyvTryyJ6C2w852x60bfpj dQmYUAvYHCC7igZERTXy8PlvIEvGWfpHm34BDUocdjr4sBRHWg/gEjka+iVQ39oA4D f2+NtFcpAFIXKk1YCs8H/jOAHHiwwHUDA0dCslm+oPs1Rqpu1dZzByXvYIeV0p8jiN mSpQYxZNENvig== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH mptcp-next v3 4/6] selftests/bpf: Drop noconnect from network_helper_opts Date: Mon, 17 Jun 2024 16:33:09 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang In test_bpf_ip_check_defrag_ok(), the new helper client_socket() can be used to replace connect_to_fd_opts() with "noconnect" opts, and the strcut member "noconnect" of network_helper_opts can be dropped now, always connect to server in connect_to_fd_opts(). Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_helpers.c | 5 ++--- tools/testing/selftests/bpf/network_helpers.h | 1 - tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c | 9 ++++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 3afeddeead39..b5d23ea146b7 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -315,9 +315,8 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add return -1; } - if (!opts->noconnect) - if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail)) - goto error_close; + if (connect_fd_to_addr(fd, addr, addrlen, opts->must_fail)) + goto error_close; return fd; diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index e89eadfb02d6..9ea36524b9db 100644 --- a/tools/testing/selftests/bpf/network_helpers.h +++ b/tools/testing/selftests/bpf/network_helpers.h @@ -24,7 +24,6 @@ typedef __u16 __sum16; struct network_helper_opts { int timeout_ms; bool must_fail; - bool noconnect; int proto; int (*post_socket_cb)(int fd, void *opts); void *cb_opts; diff --git a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c index 1607a05bf2c2..e73da3de5bf6 100644 --- a/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c +++ b/tools/testing/selftests/bpf/prog_tests/ip_check_defrag.c @@ -158,14 +158,13 @@ static int send_frags6(int client) void test_bpf_ip_check_defrag_ok(bool ipv6) { + int family = ipv6 ? AF_INET6 : AF_INET; struct network_helper_opts rx_opts = { .timeout_ms = 1000, - .noconnect = true, }; struct network_helper_opts tx_ops = { .timeout_ms = 1000, .proto = IPPROTO_RAW, - .noconnect = true, }; struct sockaddr_storage caddr; struct ip_check_defrag *skel; @@ -191,7 +190,7 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) nstoken = open_netns(NS1); if (!ASSERT_OK_PTR(nstoken, "setns ns1")) goto out; - srv_fd = start_server(ipv6 ? AF_INET6 : AF_INET, SOCK_DGRAM, NULL, SERVER_PORT, 0); + srv_fd = start_server(family, SOCK_DGRAM, NULL, SERVER_PORT, 0); close_netns(nstoken); if (!ASSERT_GE(srv_fd, 0, "start_server")) goto out; @@ -200,7 +199,7 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) nstoken = open_netns(NS0); if (!ASSERT_OK_PTR(nstoken, "setns ns0")) goto out; - client_tx_fd = connect_to_fd_opts(srv_fd, SOCK_RAW, &tx_ops); + client_tx_fd = client_socket(family, SOCK_RAW, &tx_ops); close_netns(nstoken); if (!ASSERT_GE(client_tx_fd, 0, "connect_to_fd_opts")) goto out; @@ -209,7 +208,7 @@ void test_bpf_ip_check_defrag_ok(bool ipv6) nstoken = open_netns(NS0); if (!ASSERT_OK_PTR(nstoken, "setns ns0")) goto out; - client_rx_fd = connect_to_fd_opts(srv_fd, SOCK_DGRAM, &rx_opts); + client_rx_fd = client_socket(family, SOCK_DGRAM, &rx_opts); close_netns(nstoken); if (!ASSERT_GE(client_rx_fd, 0, "connect_to_fd_opts")) goto out; From patchwork Mon Jun 17 08:33:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13700320 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 558C8187331; Mon, 17 Jun 2024 08:33:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613234; cv=none; b=UfMWiripVWMLzL/DgJbPwx/cvXrCoIM0nwFoPnfKdTTd0CWGFgFcdxAbhA/b3NUS0yYHsFTEgRLX4J3xGbxnGvefJGVLxQofQe1UKFbC2FhoQFjdP17bu8aSgl3PlxtfZeyKY07Uz5U6dfWsz4nJfKyt2yRWKbGDQDMJZvVDm/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613234; c=relaxed/simple; bh=QDeYipd1o0V9wiiSdEf3dBRvIuDzcvSCSFdjltKsxtY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PLZ68go6TAHH1o5+D3HJPKdrYOsUw/bikDmKtvD+73+heLCmn0V9I509jphs28xwLXpapKKXaekipenDdNIQ6/CBD6XkzdbiSedNcrihuasxEDCfLRU//gmCmeGYJiAFD1fMleXLq94VuXGsVvJo1rdi2R6NASgkWY8tPTT2LDw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=js2CZoD+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="js2CZoD+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54F82C4AF1A; Mon, 17 Jun 2024 08:33:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718613234; bh=QDeYipd1o0V9wiiSdEf3dBRvIuDzcvSCSFdjltKsxtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=js2CZoD+Dap8Z7pwnWPMwVBO8JBzbTrRjHTPipY2pFRGZofw8XTsbObW2uCVFopE7 bX4BIUOp0LOa7lJOA7GTJ/R2kk5fqnPIgXJtHIbSySH4AfKBUSFeXOaR/lMHbq11CJ h/6+v++VzgOAuIcSMmHduHhKXnm3Kq1v7+vuOJqI5+Kj/aGP6YWkBJRerkRjSDUKg6 lnjKR8UBXmEoRnUZhOCe5ueeBbukagzw/A6u/9HKz5loqlLpFiqrBMIjLHxHYzwx3I uGtZGcek8pos9kRtaacZ+gqNoFUrW+K+lEDZnK/3lF8iQUWpehLRWNzPwEhhVho26h FNybk9X2yMk/g== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH mptcp-next v3 5/6] selftests/bpf: Use start_server_str in mptcp Date: Mon, 17 Jun 2024 16:33:10 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Since start_server_str() is added now, it can be used in mptcp.c in start_mptcp_server() instead of using helpers make_sockaddr() and start_server_addr() to simplify the code. Signed-off-by: Geliang Tang Acked-by: Eduard Zingerman --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 274d2e033e39..d2ca32fa3b21 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -89,13 +89,8 @@ static int start_mptcp_server(int family, const char *addr_str, __u16 port, .timeout_ms = timeout_ms, .proto = IPPROTO_MPTCP, }; - struct sockaddr_storage addr; - socklen_t addrlen; - if (make_sockaddr(family, addr_str, port, &addr, &addrlen)) - return -1; - - return start_server_addr(SOCK_STREAM, &addr, addrlen, &opts); + return start_server_str(family, SOCK_STREAM, addr_str, port, &opts); } static int verify_tsk(int map_fd, int client_fd) From patchwork Mon Jun 17 08:33:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13700321 X-Patchwork-Delegate: bpf@iogearbox.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0874D190679; Mon, 17 Jun 2024 08:34:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613241; cv=none; b=gPht25t4oQWKoOzlgz8/IeqUBLXW00GLwzR2uDjagucmvSSdEo+3mZW1BxFcYLppvMwrNx3sGOOfSVbR9XDWdMX1Ia6VcFBtL10+/UChAq89znLhbKCwlHUJWGL7uj6+MIrUHeVYu/estxw5AQGoX0gC2E2ScETYWoyI5VyznRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718613241; c=relaxed/simple; bh=ek0iCBSuhwxmBUkXZ25YiD2CARKWMEhFftoQUiEh56g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H+Qx16PsShcJFbOAbImIJMFTMOvkQoqc+I9EZpqDcC641l0X563liBd8ovaf5naOQGjVFxqPlO2UnwfpQObcocarCF4Mz+Wfrbxkxn8nIn61qAS2Jr3zaQGgfWsSRd9yTYhsb1R0myIgupbw3bPeV0u7jl1XkMMrYL4sTrYNSxk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PAUys201; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PAUys201" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB4A0C4AF48; Mon, 17 Jun 2024 08:33:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718613240; bh=ek0iCBSuhwxmBUkXZ25YiD2CARKWMEhFftoQUiEh56g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PAUys201J8c7+ROTjLTWwfsb8nz/U2qXjomVQzIoxGNWOUcvPqxrPkY3b64Vc7B9R pluexHMy56kqg8Vh5JkZeyJPZlJCndTDS8laqsglMGzjYbvYG04jniXmYlXINwuoWZ zubNlHg2rfMF0LR3Ri08zrOjQpIbUsnpZCofGtEfSLWDF9flsRxaUnA/XBp3DZdjU1 5NfiNtNMBCdHjDzWXn4AHYAXz+SGYyiIQkRkpho0QtF12UD6pF9UzPhsC9CfCVW7m9 00xJWNWc5VyHiJv758haO6j7tnu73yIGJQVYLGEfvj+SrD6XZPJdizo5rrVtFX/ZLL a6uRThP2vdC3Q== From: Geliang Tang To: Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH mptcp-next v3 6/6] selftests/bpf: Use start_server_str in test_tcp_check_syncookie_user Date: Mon, 17 Jun 2024 16:33:11 +0800 Message-ID: <5b1f4e6fd899a858d2357c4df7038364b9686176.1718612857.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net From: Geliang Tang Since start_server_str() is added now, it can be used in script test_tcp_check_syncookie_user.c instead of start_server_addr() to simplify the code. Signed-off-by: Geliang Tang Acked-by: Eduard Zingerman --- .../bpf/test_tcp_check_syncookie_user.c | 29 ++----------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c index aebc58c24dc5..3844f9b8232a 100644 --- a/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c +++ b/tools/testing/selftests/bpf/test_tcp_check_syncookie_user.c @@ -156,10 +156,6 @@ static int v6only_false(int fd, void *opts) int main(int argc, char **argv) { struct network_helper_opts opts = { 0 }; - struct sockaddr_in addr4; - struct sockaddr_in6 addr6; - struct sockaddr_in addr4dual; - struct sockaddr_in6 addr6dual; int server = -1; int server_v6 = -1; int server_dual = -1; @@ -181,36 +177,17 @@ int main(int argc, char **argv) goto err; } - memset(&addr4, 0, sizeof(addr4)); - addr4.sin_family = AF_INET; - addr4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - addr4.sin_port = 0; - memcpy(&addr4dual, &addr4, sizeof(addr4dual)); - - memset(&addr6, 0, sizeof(addr6)); - addr6.sin6_family = AF_INET6; - addr6.sin6_addr = in6addr_loopback; - addr6.sin6_port = 0; - - memset(&addr6dual, 0, sizeof(addr6dual)); - addr6dual.sin6_family = AF_INET6; - addr6dual.sin6_addr = in6addr_any; - addr6dual.sin6_port = 0; - - server = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr4, - sizeof(addr4), NULL); + server = start_server_str(AF_INET, SOCK_STREAM, "127.0.0.1", 0, NULL); if (server == -1) goto err; opts.post_socket_cb = v6only_true; - server_v6 = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr6, - sizeof(addr6), &opts); + server_v6 = start_server_str(AF_INET6, SOCK_STREAM, "::1", 0, &opts); if (server_v6 == -1) goto err; opts.post_socket_cb = v6only_false; - server_dual = start_server_addr(SOCK_STREAM, (struct sockaddr_storage *)&addr6dual, - sizeof(addr6dual), &opts); + server_dual = start_server_str(AF_INET6, SOCK_STREAM, "::0", 0, &opts); if (server_dual == -1) goto err;