Skip to content

Commit 3573fe7

Browse files
damejerasfals
authored andcommitted
Patch for localhost
feat: castai localhost socket support
1 parent a44aa6d commit 3573fe7

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

criu/include/sk-inet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,7 @@ struct rst_tcp_sock {
105105
union libsoccr_addr;
106106
int restore_sockaddr(union libsoccr_addr *sa, int family, u32 pb_port, u32 *pb_addr, u32 ifindex);
107107

108+
void show_one_inet_img(const char *act, const InetSkEntry *e);
109+
void show_one_inet(const char *act, const struct inet_sk_desc *sk);
110+
108111
#endif /* __CR_SK_INET_H__ */

criu/sk-inet.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static struct inet_port *port_add(struct inet_sk_info *ii, int port)
8585
return e;
8686
}
8787

88-
static void show_one_inet(const char *act, const struct inet_sk_desc *sk)
88+
void show_one_inet(const char *act, const struct inet_sk_desc *sk)
8989
{
9090
char src_addr[INET_ADDR_LEN] = "<unknown>";
9191

@@ -99,7 +99,7 @@ static void show_one_inet(const char *act, const struct inet_sk_desc *sk)
9999
___tcp_state_name(sk->state), src_addr);
100100
}
101101

102-
static void show_one_inet_img(const char *act, const InetSkEntry *e)
102+
void show_one_inet_img(const char *act, const InetSkEntry *e)
103103
{
104104
char src_addr[INET_ADDR_LEN] = "<unknown>";
105105

criu/sk-tcp.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,21 @@ int dump_tcp_opts(int fd, TcpOptsEntry *toe)
242242
return ret;
243243
}
244244

245+
static bool is_localhost(uint32_t *src_addr, uint32_t *dst_addr)
246+
{
247+
return src_addr[0] == htonl(INADDR_LOOPBACK) && dst_addr[0] == htonl(INADDR_LOOPBACK);
248+
}
249+
245250
int dump_one_tcp(int fd, struct inet_sk_desc *sk, SkOptsEntry *soe)
246251
{
247252
if (sk->dst_port == 0)
248253
return 0;
249254

250-
if (opts.tcp_close) {
255+
if (opts.tcp_close && !is_localhost(sk->src_addr, sk->dst_addr)) {
251256
return 0;
252257
}
253258

254-
pr_info("Dumping TCP connection\n");
259+
show_one_inet("Dumping TCP connection", sk);
255260

256261
if (tcp_repair_established(fd, sk))
257262
return -1;
@@ -459,15 +464,17 @@ int restore_one_tcp(int fd, struct inet_sk_info *ii)
459464
{
460465
struct libsoccr_sk *sk;
461466

462-
pr_info("Restoring TCP connection\n");
467+
if (opts.tcp_close && !is_localhost(ii->ie->src_addr, ii->ie->dst_addr)) {
468+
show_one_inet_img("Shutdown TCP connection", ii->ie);
463469

464-
if (opts.tcp_close) {
465470
if (shutdown(fd, SHUT_RDWR) && errno != ENOTCONN) {
466471
pr_perror("Unable to shutdown the socket id %x ino %x", ii->ie->id, ii->ie->ino);
467472
}
468473
return 0;
469474
}
470475

476+
show_one_inet_img("Restoring TCP connection", ii->ie);
477+
471478
sk = libsoccr_pause(fd);
472479
if (!sk)
473480
return -1;

0 commit comments

Comments
 (0)