Skip to content

Commit

Permalink
sk-tcp: Move TCP socket options from SkOptsEntry to TcpOptsEntry
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
juntongdeng committed Apr 5, 2024
1 parent 43a8ee0 commit d104042
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
30 changes: 12 additions & 18 deletions criu/sk-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -449,6 +437,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;
}
Expand Down
6 changes: 3 additions & 3 deletions images/sk-opts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ message sk_opts_entry {
optional bool so_reuseport = 17;
optional bool so_broadcast = 18;
optional bool so_keepalive = 19;
optional uint32 tcp_keepcnt = 20;
optional uint32 tcp_keepidle = 21;
optional uint32 tcp_keepintvl = 22;
optional uint32 tcp_keepcnt = 20; /* obsolete */
optional uint32 tcp_keepidle = 21; /* obsolete */
optional uint32 tcp_keepintvl = 22; /* obsolete */
optional uint32 so_oobinline = 23;
optional uint32 so_linger = 24;

Expand Down
3 changes: 3 additions & 0 deletions images/tcp-stream.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d104042

Please sign in to comment.