Re: [PATCH net v2 3/6] vsock/test: Introduce vsock_bind()
From: Michal Luczaj <hidden>
Date: 2025-01-22 20:11:55
On 1/22/25 17:01, Luigi Leonardi wrote:
On Tue, Jan 21, 2025 at 03:44:04PM +0100, Michal Luczaj wrote:quoted
Add a helper for socket()+bind(). Adapt callers. Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Michal Luczaj <redacted> --- tools/testing/vsock/util.c | 56 +++++++++++++++++----------------------- tools/testing/vsock/util.h | 1 + tools/testing/vsock/vsock_test.c | 17 +----------- 3 files changed, 25 insertions(+), 49 deletions(-)diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index 34e9dac0a105f8aeb8c9af379b080d5ce8cb2782..31ee1767c8b73c05cfd219c3d520a677df6e66a6 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c@@ -96,33 +96,42 @@ void vsock_wait_remote_close(int fd)close(epollfd); } -/* Bind to <bind_port>, connect to <cid, port> and return the file descriptor. */ -int vsock_bind_connect(unsigned int cid, unsigned int port, unsigned int bind_port, int type)If you need to send a v3, it would be nice to have a comment for vsock_bind, as there used to be one.
Comment for vsock_bind_connect() remains, see below. As for vsock_bind(), perhaps it's time to start using kernel-doc comments? v3 isn't coming, it seems, but I'll comment the function later. Thanks, Michal
quoted
+/* Bind to <bind_port>, connect to <cid, port> and return the file descriptor. */ +int vsock_bind_connect(unsigned int cid, unsigned int port, unsigned int bind_port, int type) +{ + struct sockaddr_vm sa_server = { + .svm_family = AF_VSOCK, + .svm_cid = cid, + .svm_port = port, + }; + + int client_fd, ret; + + client_fd = vsock_bind(VMADDR_CID_ANY, bind_port, type); + timeout_begin(TIMEOUT); do { ret = connect(client_fd, (struct sockaddr *)&sa_server, sizeof(sa_server));