Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad source address when run io_uring-udp with " -v" option #814

Closed
mczka opened this issue Mar 7, 2023 · 3 comments
Closed

bad source address when run io_uring-udp with " -v" option #814

mczka opened this issue Mar 7, 2023 · 3 comments

Comments

@mczka
Copy link

mczka commented Mar 7, 2023

name = inet_ntop(ctx->af, addr, buff, sizeof(buff));

line 278 should be

		name = inet_ntop(ctx->af, &(addr->sin_addr), buff, sizeof(buff));

after change it's working as expected

$ ./io_uring-udp -p 5514 -v
received 1200 bytes 16 from 127.0.0.1:56848
received 1200 bytes 16 from 127.0.0.1:40671
received 1200 bytes 16 from 127.0.0.1:56848
received 1200 bytes 16 from 127.0.0.1:56848
received 1200 bytes 16 from 127.0.0.1:40671
received 1200 bytes 16 from 127.0.0.1:56848
@ammarfaizi2
Copy link
Contributor

The fix looks good to me. Do you want to send a pull request?

mczka added a commit to mczka/liburing that referenced this issue Mar 7, 2023
@axboe axboe closed this as completed in 4f1b885 Mar 7, 2023
@illiliti
Copy link

illiliti commented Mar 7, 2023

ipv6 address also needs fixing

@ammarfaizi2
Copy link
Contributor

@illiliti good catch; the fix is below. Jens, can you take it directly?

I have tested it.

From a0a189fa55ccba335b24b12b47241172af9faad0 Mon Sep 17 00:00:00 2001
From: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Date: Wed, 8 Mar 2023 04:11:29 +0700
Subject: [PATCH] io_uring-udp: Fix the wrong IPv6 binary to string conversion

Another io_uring-udp fix.

The verbose output shows the wrong address when using IPv6. AF_INET6
should use 'struct sockaddr_in6', not 'struct sockaddr_in'. Fix that.

Thanks to @illiliti.

Link: https://github.com/axboe/liburing/issues/814#issuecomment-1458862489
Fixes: https://github.com/axboe/liburing/issues/814
Fixes: 61d472b51e761e61c ("add an example for a UDP server")
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
---
 examples/io_uring-udp.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/examples/io_uring-udp.c b/examples/io_uring-udp.c
index b81a5e7c47afd9c8..220c8edb6c85ed02 100644
--- a/examples/io_uring-udp.c
+++ b/examples/io_uring-udp.c
@@ -274,8 +274,14 @@ static int process_cqe_recv(struct ctx *ctx, struct io_uring_cqe *cqe,
 		char buff[INET6_ADDRSTRLEN + 1];
 		const char *name;
 		struct sockaddr_in *addr = io_uring_recvmsg_name(o);
+		const void *ip_addr;
 
-		name = inet_ntop(ctx->af, &addr->sin_addr, buff, sizeof(buff));
+		if (ctx->af == AF_INET6)
+			ip_addr = &((struct sockaddr_in6 *)addr)->sin6_addr.s6_addr;
+		else
+			ip_addr = &addr->sin_addr.s_addr;
+
+		name = inet_ntop(ctx->af, ip_addr, buff, sizeof(buff));
 		if (!name)
 			name = "<INVALID>";
 		fprintf(stderr, "received %u bytes %d from %s:%d\n",
-- 
Ammar Faizi

ammarfaizi2 added a commit to ammarfaizi2/liburing that referenced this issue Apr 15, 2023
Another io_uring-udp fix. The verbose output shows the wrong address
when using IPv6.

When the address family is AF_INET6, the pointer should be cast to
'struct sockaddr_in6', not 'struct sockaddr_in'.

Before this patch:

    port bound to 49567
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:47048
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:54755
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:57968

After this patch:

    port bound to 48033
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:40456
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:50306
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:52291

While in there, also add a square bracket around the IP address to
easily read the port number, especially for IPv6.

Link: axboe#814 (comment)
Fixes: axboe#814
Fixes: 61d472b ("add an example for a UDP server")
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
ammarfaizi2 added a commit to ammarfaizi2/liburing that referenced this issue Apr 15, 2023
Another io_uring-udp fix. The verbose output shows the wrong address
when using IPv6.

When the address family is AF_INET6, the pointer should be cast to
'struct sockaddr_in6', not 'struct sockaddr_in'.

While in there, also add a square bracket around the IP address to
easily read the port number, especially for IPv6.

Before this patch:

    port bound to 49567
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:47048
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:54755
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:57968

(the IPv6 address is wrong)

After this patch:

    port bound to 48033
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:40456
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:50306
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:52291

Link: axboe#814 (comment)
Fixes: axboe#814
Fixes: 61d472b ("add an example for a UDP server")
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
ammarfaizi2 added a commit to ammarfaizi2/liburing that referenced this issue Apr 15, 2023
Another io_uring-udp fix. The verbose output shows the wrong address
when using IPv6.

When the address family is AF_INET6, the pointer should be cast to
'struct sockaddr_in6', not 'struct sockaddr_in'.

While in there, also add a square bracket around the IP address to
easily read the port number, especially for IPv6.

Before this patch:

    port bound to 49567
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:47048
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:54755
    received 4 bytes 28 from ::2400:6180:0:d1:0:0:57968

(the IPv6 address is wrong)

After this patch:

    port bound to 48033
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:40456
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:50306
    received 4 bytes 28 from [2400:6180:0:d1::6a4:a00f]:52291

Link: axboe#814 (comment)
Fixes: axboe#814
Fixes: 61d472b ("add an example for a UDP server")
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants