[CRIU] [PATCH] tcp: bind tcp sockets after enabling the repair mode

Pavel Emelyanov xemul at virtuozzo.com
Wed Dec 14 00:06:49 PST 2016


On 12/14/2016 06:55 AM, Andrei Vagin wrote:
> From: Andrei Vagin <avagin at virtuozzo.com>
> 
> Only sockets in the repair mode can be bound to the same
> port a few time, what is required to restore tcp connects.
> 
> Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
> ---
>  criu/sk-inet.c | 9 ++++-----
>  criu/sk-tcp.c  | 7 +++++++
>  2 files changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/criu/sk-inet.c b/criu/sk-inet.c
> index eb798ce..670d66d 100644
> --- a/criu/sk-inet.c
> +++ b/criu/sk-inet.c
> @@ -628,11 +628,6 @@ static int open_inet_sk(struct file_desc *d)
>  	if (restore_opt(sk, SOL_SOCKET, SO_REUSEADDR, &yes))
>  		goto err;
>  
> -	if (ie->src_port) {
> -		if (inet_bind(sk, ii))
> -			goto err;
> -	}
> -
>  	if (tcp_connection(ie)) {
>  		if (!opts.tcp_established_ok) {
>  			pr_err("Connected TCP socket in image\n");
> @@ -649,6 +644,10 @@ static int open_inet_sk(struct file_desc *d)
>  		goto done;
>  	}
>  
> +	if (ie->src_port && inet_bind(sk, ii))
> +		goto err;
> +
> +
>  	/*
>  	 * Listen sockets are easiest ones -- simply
>  	 * bind() and listen(), and that's all.
> diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
> index 8179a35..b5cab96 100644
> --- a/criu/sk-tcp.c
> +++ b/criu/sk-tcp.c
> @@ -428,6 +428,13 @@ int restore_one_tcp(int fd, struct inet_sk_info *ii)
>  	if (!sk)
>  		return -1;
>  
> +	/*
> +	 * The repair mode has to be enabled to be able
> +	 * to connect to the same address twice.
> +	 */
> +	if (ii->ie->src_port && inet_bind(fd, ii))

Why don't we move bind to soccr as well?

> +		return -1;
> +
>  	if (restore_tcp_conn_state(fd, sk, ii))
>  		return -1;
>  
> 



More information about the CRIU mailing list