65 lines
1.8 KiB
Diff
65 lines
1.8 KiB
Diff
From b9ae48172fff77d41b5cf19d334ccbe002ac0686 Mon Sep 17 00:00:00 2001
|
|
From: Adrian Reber <areber@redhat.com>
|
|
Date: Tue, 7 Dec 2021 09:10:14 +0000
|
|
Subject: [PATCH] util: make page-server IPv6 safe
|
|
|
|
The function run_tcp_server() was the last place CRIU was still using
|
|
the IPv4 only function inet_ntoa(). It was only used during a print, so
|
|
that it did not really break anything, but with this commit the output
|
|
is now no longer:
|
|
|
|
Accepted connection from 0.0.0.0:58396
|
|
|
|
but correctly displaying the IPv6 address
|
|
|
|
Accepted connection from ::1:58398
|
|
|
|
if connecting via IPv6.
|
|
|
|
Signed-off-by: Adrian Reber <areber@redhat.com>
|
|
---
|
|
criu/util.c | 15 +++++++++++----
|
|
1 file changed, 11 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/criu/util.c b/criu/util.c
|
|
index 2917102fd..822822186 100644
|
|
--- a/criu/util.c
|
|
+++ b/criu/util.c
|
|
@@ -1098,7 +1098,7 @@ out:
|
|
int run_tcp_server(bool daemon_mode, int *ask, int cfd, int sk)
|
|
{
|
|
int ret;
|
|
- struct sockaddr_in caddr;
|
|
+ struct sockaddr_storage caddr;
|
|
socklen_t clen = sizeof(caddr);
|
|
|
|
if (daemon_mode) {
|
|
@@ -1126,14 +1126,20 @@ int run_tcp_server(bool daemon_mode, int *ask, int cfd, int sk)
|
|
return -1;
|
|
|
|
if (sk >= 0) {
|
|
+ char port[6];
|
|
+ char address[INET6_ADDRSTRLEN];
|
|
*ask = accept(sk, (struct sockaddr *)&caddr, &clen);
|
|
if (*ask < 0) {
|
|
pr_perror("Can't accept connection to server");
|
|
goto err;
|
|
- } else
|
|
- pr_info("Accepted connection from %s:%u\n",
|
|
- inet_ntoa(caddr.sin_addr),
|
|
- (int)ntohs(caddr.sin_port));
|
|
+ }
|
|
+ ret = getnameinfo((struct sockaddr *)&caddr, clen, address, sizeof(address), port, sizeof(port),
|
|
+ NI_NUMERICHOST | NI_NUMERICSERV);
|
|
+ if (ret) {
|
|
+ pr_err("Failed converting address: %s\n", gai_strerror(ret));
|
|
+ goto err;
|
|
+ }
|
|
+ pr_info("Accepted connection from %s:%s\n", address, port);
|
|
close(sk);
|
|
}
|
|
|
|
--
|
|
2.34.1
|
|
|