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