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: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Andrei Vagin 2017-10-31 08:53:43 +03:00
parent 3503332086
commit 09b93e0ac5
3 changed files with 13 additions and 2 deletions

View file

@ -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) {

View file

@ -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;

View file

@ -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 {