<div dir="ltr">Thanks!<br><div class="gmail_quote"><div dir="ltr">wt., 12 cze 2018 o 00:49 Andrei Vagin <<a href="mailto:avagin@virtuozzo.com">avagin@virtuozzo.com</a>> napisał(a):<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Applied, thanks!<br>
<br>
On Thu, Jun 07, 2018 at 12:32:49PM +0200, Pawel Stradomski wrote:<br>
> From 084e03dfb1a3069deebfb50dc3b8daf948477b9e Mon Sep 17 00:00:00 2001<br>
> From: Pawel Stradomski <<a href="mailto:pstradomski@google.com" target="_blank">pstradomski@google.com</a>><br>
> Date: Wed, 6 Jun 2018 21:09:13 +0200<br>
> Subject: [PATCH] Allow criu page-server to work over ipv6.<br>
> <br>
> Signed-off-by: Pawel Stradomski <<a href="mailto:pstradomski@google.com" target="_blank">pstradomski@google.com</a>><br>
> ---<br>
> criu/util.c | 44 ++++++++++++++++++++++++++++++--------------<br>
> 1 file changed, 30 insertions(+), 14 deletions(-)<br>
> <br>
> diff --git a/criu/util.c b/criu/util.c<br>
> index be892bbb..b46f2964 100644<br>
> --- a/criu/util.c<br>
> +++ b/criu/util.c<br>
> @@ -1268,39 +1268,50 @@ void print_data(unsigned long addr, unsigned char *data, size_t size)<br>
> }<br>
> }<br>
> <br>
> -static int get_sockaddr_in(struct sockaddr_in *addr, char *host)<br>
> +static int get_sockaddr_in(struct sockaddr_storage *addr, char *host)<br>
> {<br>
> memset(addr, 0, sizeof(*addr));<br>
> - addr->sin_family = AF_INET;<br>
> <br>
> - if (!host)<br>
> - addr->sin_addr.s_addr = INADDR_ANY;<br>
> - else if (!inet_aton(host, &addr->sin_addr)) {<br>
> + if (!host) {<br>
> + ((struct sockaddr_in *)addr)->sin_addr.s_addr = INADDR_ANY;<br>
> + addr->ss_family = AF_INET;<br>
> + } else if (inet_pton(AF_INET, host, &((struct sockaddr_in *)addr)->sin_addr)) {<br>
> + addr->ss_family = AF_INET;<br>
> + } else if (inet_pton(AF_INET6, host, &((struct sockaddr_in6 *)addr)->sin6_addr)) {<br>
> + addr->ss_family = AF_INET6;<br>
> + } else {<br>
> pr_perror("Bad server address");<br>
> return -1;<br>
> }<br>
> <br>
> - addr->sin_port = htons(opts.port);<br>
> + if (addr->ss_family == AF_INET6) {<br>
> + ((struct sockaddr_in6 *)addr)->sin6_port = htons(opts.port);<br>
> + } else if (addr->ss_family == AF_INET) {<br>
> + ((struct sockaddr_in *)addr)->sin_port = htons(opts.port);<br>
> + }<br>
> +<br>
> return 0;<br>
> }<br>
> <br>
> int setup_tcp_server(char *type)<br>
> {<br>
> int sk = -1;<br>
> - struct sockaddr_in saddr;<br>
> + struct sockaddr_storage saddr;<br>
> socklen_t slen = sizeof(saddr);<br>
> <br>
> + if (get_sockaddr_in(&saddr, opts.addr)) {<br>
> + return -1;<br>
> + }<br>
> +<br>
> pr_info("Starting %s server on port %u\n", type, opts.port);<br>
> <br>
> - sk = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);<br>
> + sk = socket(saddr.ss_family, SOCK_STREAM, IPPROTO_TCP);<br>
> +<br>
> if (sk < 0) {<br>
> pr_perror("Can't init %s server", type);<br>
> return -1;<br>
> }<br>
> <br>
> - if (get_sockaddr_in(&saddr, opts.addr))<br>
> - goto out;<br>
> -<br>
> if (bind(sk, (struct sockaddr *)&saddr, slen)) {<br>
> pr_perror("Can't bind %s server", type);<br>
> goto out;<br>
> @@ -1318,7 +1329,12 @@ int setup_tcp_server(char *type)<br>
> goto out;<br>
> }<br>
> <br>
> - opts.port = ntohs(saddr.sin_port);<br>
> + if (saddr.ss_family == AF_INET6) {<br>
> + opts.port = ntohs(((struct sockaddr_in *)&saddr)->sin_port);<br>
> + } else if (saddr.ss_family == AF_INET) {<br>
> + opts.port = ntohs(((struct sockaddr_in6 *)&saddr)->sin6_port);<br>
> + }<br>
> +<br>
> pr_info("Using %u port\n", opts.port);<br>
> }<br>
> <br>
> @@ -1377,7 +1393,7 @@ out:<br>
> <br>
> int setup_tcp_client(char *addr)<br>
> {<br>
> - struct sockaddr_in saddr;<br>
> + struct sockaddr_storage saddr;<br>
> int sk;<br>
> <br>
> pr_info("Connecting to server %s:%u\n", addr, opts.port);<br>
> @@ -1385,7 +1401,7 @@ int setup_tcp_client(char *addr)<br>
> if (get_sockaddr_in(&saddr, addr))<br>
> return -1;<br>
> <br>
> - sk = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);<br>
> + sk = socket(saddr.ss_family, SOCK_STREAM, IPPROTO_TCP);<br>
> if (sk < 0) {<br>
> pr_perror("Can't create socket");<br>
> return -1;<br>
> -- <br>
> 2.18.0.rc1.242.g61856ae69a-goog<br>
> <br>
> <br>
> -- <br>
> Pawel Stradomski<br>
> _______________________________________________<br>
> CRIU mailing list<br>
> <a href="mailto:CRIU@openvz.org" target="_blank">CRIU@openvz.org</a><br>
> <a href="https://lists.openvz.org/mailman/listinfo/criu" rel="noreferrer" target="_blank">https://lists.openvz.org/mailman/listinfo/criu</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Paweł Stradomski</div></div>