Commit 09b93e0a authored by Andrei Vagin's avatar Andrei Vagin

sk-inet: restore a value of SO_REUSEPORT

The SO_REUSEPORT 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.
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 35033320
...@@ -586,14 +586,18 @@ static int post_open_inet_sk(struct file_desc *d, int sk) ...@@ -586,14 +586,18 @@ static int post_open_inet_sk(struct file_desc *d, int sk)
} }
/* SO_REUSEADDR is set for all sockets */ /* SO_REUSEADDR is set for all sockets */
if (ii->ie->opts->reuseaddr) if (ii->ie->opts->reuseaddr && ii->ie->opts->so_reuseport)
return 0; return 0;
if (atomic_read(&ii->port->users)) if (atomic_read(&ii->port->users))
return 1; return 1;
val = ii->ie->opts->reuseaddr; 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 -1;
return 0; return 0;
...@@ -653,6 +657,8 @@ static int open_inet_sk(struct file_desc *d, int *new_fd) ...@@ -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)) if (restore_opt(sk, SOL_SOCKET, SO_REUSEADDR, &yes))
goto err; goto err;
if (restore_opt(sk, SOL_SOCKET, SO_REUSEPORT, &yes))
goto err;
if (tcp_connection(ie)) { if (tcp_connection(ie)) {
if (!opts.tcp_established_ok && !opts.tcp_close) { if (!opts.tcp_established_ok && !opts.tcp_close) {
......
...@@ -524,6 +524,10 @@ int dump_socket_opts(int sk, SkOptsEntry *soe) ...@@ -524,6 +524,10 @@ int dump_socket_opts(int sk, SkOptsEntry *soe)
soe->reuseaddr = val ? true : false; soe->reuseaddr = val ? true : false;
soe->has_reuseaddr = true; 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); ret |= dump_opt(sk, SOL_SOCKET, SO_PASSCRED, &val);
soe->has_so_passcred = true; soe->has_so_passcred = true;
soe->so_passcred = val ? true : false; soe->so_passcred = val ? true : false;
......
...@@ -21,6 +21,7 @@ message sk_opts_entry { ...@@ -21,6 +21,7 @@ message sk_opts_entry {
optional string so_bound_dev = 15; optional string so_bound_dev = 15;
repeated fixed64 so_filter = 16; repeated fixed64 so_filter = 16;
optional bool so_reuseport = 17;
} }
enum sk_shutdown { enum sk_shutdown {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment