[Devel] [PATCH] sk-inet: restore a value of SO_REUSEADDR

Andrei Vagin avagin at openvz.org
Tue Oct 31 08:54:47 MSK 2017


From: Andrei Vagin <avagin at virtuozzo.com>

The SO_REUSEADDR option allows multiple sockets on the same
host to bind to the same port. This option has to ve restored when all
sockets are bound to a port. The same logic is already used to restore
SO_REUSEADDR.

https://jira.sw.ru/browse/PSBM-75515

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/sk-inet.c       | 10 ++++++++--
 criu/sockets.c       |  4 ++++
 images/sk-opts.proto |  1 +
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index 93de1e2ee..06275c922 100644
--- a/criu/sk-inet.c
+++ b/criu/sk-inet.c
@@ -586,14 +586,18 @@ static int post_open_inet_sk(struct file_desc *d, int sk)
 	}
 
 	/* SO_REUSEADDR is set for all sockets */
-	if (ii->ie->opts->reuseaddr)
+	if (ii->ie->opts->reuseaddr && ii->ie->opts->so_reuseport)
 		return 0;
 
 	if (atomic_read(&ii->port->users))
 		return 1;
 
 	val = ii->ie->opts->reuseaddr;
-	if (restore_opt(sk, SOL_SOCKET, SO_REUSEADDR, &val))
+	if (!val && restore_opt(sk, SOL_SOCKET, SO_REUSEADDR, &val))
+		return -1;
+
+	val = ii->ie->opts->so_reuseport;
+	if (!val && restore_opt(sk, SOL_SOCKET, SO_REUSEPORT, &val))
 		return -1;
 
 	return 0;
@@ -653,6 +657,8 @@ static int open_inet_sk(struct file_desc *d, int *new_fd)
 	 */
 	if (restore_opt(sk, SOL_SOCKET, SO_REUSEADDR, &yes))
 		goto err;
+	if (restore_opt(sk, SOL_SOCKET, SO_REUSEPORT, &yes))
+		goto err;
 
 	if (tcp_connection(ie)) {
 		if (!opts.tcp_established_ok && !opts.tcp_close) {
diff --git a/criu/sockets.c b/criu/sockets.c
index c2a5cd130..70d57b009 100644
--- a/criu/sockets.c
+++ b/criu/sockets.c
@@ -524,6 +524,10 @@ int dump_socket_opts(int sk, SkOptsEntry *soe)
 	soe->reuseaddr = val ? true : false;
 	soe->has_reuseaddr = true;
 
+	ret |= dump_opt(sk, SOL_SOCKET, SO_REUSEPORT, &val);
+	soe->so_reuseport = val ? true : false;
+	soe->has_so_reuseport = true;
+
 	ret |= dump_opt(sk, SOL_SOCKET, SO_PASSCRED, &val);
 	soe->has_so_passcred = true;
 	soe->so_passcred = val ? true : false;
diff --git a/images/sk-opts.proto b/images/sk-opts.proto
index b5374c976..af61975e9 100644
--- a/images/sk-opts.proto
+++ b/images/sk-opts.proto
@@ -21,6 +21,7 @@ message sk_opts_entry {
 	optional string		so_bound_dev	= 15;
 
 	repeated fixed64	so_filter	= 16;
+	optional bool		so_reuseport	= 17;
 }
 
 enum sk_shutdown {
-- 
2.13.6



More information about the Devel mailing list