2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 01:51:51 +00:00

sk-tcp: Move TCP socket options from SkOptsEntry to TcpOptsEntry

Currently some TCP socket option information is stored in SkOptsEntry,
which is a little confusing.

SkOptsEntry should only contain socket options that are common to
all sockets.

In this commit move the TCP-specific socket options from SkOptsEntry
to TcpOptsEntry.

Signed-off-by: Juntong Deng <juntong.deng@outlook.com>
This commit is contained in:
Juntong Deng 2024-05-19 12:55:02 +01:00 committed by Andrei Vagin
parent 1cb75c0b1e
commit 9ba9aff77f
4 changed files with 24 additions and 18 deletions

View File

@ -229,33 +229,21 @@ int dump_tcp_opts(int fd, TcpOptsEntry *toe)
ret |= dump_opt(fd, SOL_TCP, TCP_NODELAY, &toe->nodelay);
ret |= dump_opt(fd, SOL_TCP, TCP_CORK, &toe->cork);
ret |= dump_opt(fd, SOL_TCP, TCP_KEEPCNT, &toe->keepcnt);
ret |= dump_opt(fd, SOL_TCP, TCP_KEEPIDLE, &toe->keepidle);
ret |= dump_opt(fd, SOL_TCP, TCP_KEEPINTVL, &toe->keepintvl);
toe->has_nodelay = !!toe->nodelay;
toe->has_cork = !!toe->cork;
toe->has_keepcnt = !!toe->keepcnt;
toe->has_keepidle = !!toe->keepidle;
toe->has_keepintvl = !!toe->keepintvl;
return ret;
}
int dump_one_tcp(int fd, struct inet_sk_desc *sk, SkOptsEntry *soe)
{
soe->has_tcp_keepcnt = true;
if (dump_opt(fd, SOL_TCP, TCP_KEEPCNT, &soe->tcp_keepcnt)) {
pr_perror("Can't read TCP_KEEPCNT");
return -1;
}
soe->has_tcp_keepidle = true;
if (dump_opt(fd, SOL_TCP, TCP_KEEPIDLE, &soe->tcp_keepidle)) {
pr_perror("Can't read TCP_KEEPIDLE");
return -1;
}
soe->has_tcp_keepintvl = true;
if (dump_opt(fd, SOL_TCP, TCP_KEEPINTVL, &soe->tcp_keepintvl)) {
pr_perror("Can't read TCP_KEEPINTVL");
return -1;
}
if (sk->dst_port == 0)
return 0;
@ -457,6 +445,12 @@ int restore_tcp_opts(int sk, TcpOptsEntry *toe)
ret |= restore_opt(sk, SOL_TCP, TCP_NODELAY, &toe->nodelay);
if (toe->has_cork)
ret |= restore_opt(sk, SOL_TCP, TCP_CORK, &toe->cork);
if (toe->has_keepcnt)
ret |= restore_opt(sk, SOL_TCP, TCP_KEEPCNT, &toe->keepcnt);
if (toe->has_keepidle)
ret |= restore_opt(sk, SOL_TCP, TCP_KEEPIDLE, &toe->keepidle);
if (toe->has_keepintvl)
ret |= restore_opt(sk, SOL_TCP, TCP_KEEPINTVL, &toe->keepintvl);
return ret;
}

View File

@ -585,6 +585,12 @@ int restore_socket_opts(int sk, SkOptsEntry *soe)
pr_debug("\tset keepalive for socket\n");
ret |= restore_opt(sk, SOL_SOCKET, SO_KEEPALIVE, &val);
}
/*
* Restoring TCP socket options in SkOptsEntry is
* for backward compatibility only, newer versions
* of CRIU use TcpOptsEntry.
*/
if (soe->has_tcp_keepcnt) {
pr_debug("\tset keepcnt for socket\n");
ret |= restore_opt(sk, SOL_TCP, TCP_KEEPCNT, &soe->tcp_keepcnt);

View File

@ -26,9 +26,12 @@ message sk_opts_entry {
optional bool so_reuseport = 17;
optional bool so_broadcast = 18;
optional bool so_keepalive = 19;
/* These three are deprecated, use tcp_opts_entry instead */
optional uint32 tcp_keepcnt = 20;
optional uint32 tcp_keepidle = 21;
optional uint32 tcp_keepintvl = 22;
optional uint32 so_oobinline = 23;
optional uint32 so_linger = 24;

View File

@ -7,6 +7,9 @@ import "opts.proto";
message tcp_opts_entry {
optional bool cork = 1;
optional bool nodelay = 2;
optional uint32 keepcnt = 3;
optional uint32 keepidle = 4;
optional uint32 keepintvl = 5;
}
message tcp_stream_entry {