Commit 08a52062 authored by Geliang Tang's avatar Geliang Tang Committed by Alexei Starovoitov
Browse files

selftests/bpf: Use connect_to_addr in connect_to_fd_opt



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.

Acked-by: default avatarEduard Zingerman <eddyz87@gmail.com>
Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Link: https://lore.kernel.org/r/4569c30533e14c22fae6c05070aad809720551c1.1718932493.git.tanggeliang@kylinos.cn


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 34ad6ec9
Loading
Loading
Loading
Loading
+7 −26
Original line number Diff line number Diff line
@@ -293,6 +293,11 @@ int connect_to_addr(int type, const struct sockaddr_storage *addr, socklen_t add
	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;

@@ -306,9 +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;
	int fd;

	if (!opts)
		opts = &default_opts;
@@ -319,29 +322,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, 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;

	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)