Skip to content

Commit

Permalink
sk-inet: Add support for checkpoint/restore of ICMP sockets
Browse files Browse the repository at this point in the history
Currently there is no option to checkpoint/restore programs that use
ICMP sockets, such as `ping`. This patch adds support for the same.

Fixes checkpoint-restore#2557

Signed-off-by: समीर सिंह Sameer Singh <lumarzeli30@gmail.com>
  • Loading branch information
ss141309 committed Dec 26, 2024
1 parent 32d5a76 commit 71d69b7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
7 changes: 5 additions & 2 deletions criu/sk-inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ static int can_dump_ipproto(unsigned int ino, int proto, int type)
case IPPROTO_TCP:
case IPPROTO_UDP:
case IPPROTO_UDPLITE:
case IPPROTO_ICMP:
case IPPROTO_ICMPV6:
break;
default:
pr_err("Unsupported proto %d for socket %x\n", proto, ino);
Expand Down Expand Up @@ -915,8 +917,9 @@ static int open_inet_sk(struct file_desc *d, int *new_fd)
}

if (ie->src_port) {
if (inet_bind(sk, ii))
goto err;
if (ie->proto != IPPROTO_ICMP && ie->proto != IPPROTO_ICMPV6)
if (inet_bind(sk, ii))
goto err;
}

/*
Expand Down
32 changes: 31 additions & 1 deletion criu/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ enum socket_cl_bits {
INET_UDP_CL_BIT,
INET_UDPLITE_CL_BIT,
INET_RAW_CL_BIT,
INET_ICMP_CL_BIT,
INET6_TCP_CL_BIT,
INET6_UDP_CL_BIT,
INET6_UDPLITE_CL_BIT,
INET6_RAW_CL_BIT,
INET6_ICMP_CL_BIT,
UNIX_CL_BIT,
PACKET_CL_BIT,
_MAX_CL_BIT,
Expand All @@ -161,6 +163,8 @@ static inline enum socket_cl_bits get_collect_bit_nr(unsigned int family, unsign
return INET_UDPLITE_CL_BIT;
if (proto == IPPROTO_RAW)
return INET_RAW_CL_BIT;
if (proto == IPPROTO_ICMP)
return INET_ICMP_CL_BIT;
}
if (family == AF_INET6) {
if (proto == IPPROTO_TCP)
Expand All @@ -171,6 +175,8 @@ static inline enum socket_cl_bits get_collect_bit_nr(unsigned int family, unsign
return INET6_UDPLITE_CL_BIT;
if (proto == IPPROTO_RAW)
return INET6_RAW_CL_BIT;
if (proto == IPPROTO_ICMPV6)
return INET6_ICMP_CL_BIT;
}

pr_err("Unknown pair family %d proto %d\n", family, proto);
Expand Down Expand Up @@ -282,6 +288,12 @@ void preload_socket_modules(void)
req.r.i.sdiag_protocol = IPPROTO_RAW;
probe_diag(nl, &req, -ENOENT);

req.r.i.sdiag_protocol = IPPROTO_ICMP;
probe_diag(nl, &req, -ENOENT);

req.r.i.sdiag_protocol = IPPROTO_ICMPV6;
probe_diag(nl, &req, -ENOENT);

close(nl);
pr_info("Done probing\n");
}
Expand Down Expand Up @@ -773,6 +785,10 @@ static int inet_receive_one(struct nlmsghdr *h, struct ns_id *ns, void *arg)
case IPPROTO_RAW:
type = SOCK_RAW;
break;
case IPPROTO_ICMP:
case IPPROTO_ICMPV6:
type = SOCK_DGRAM;
break;
default:
BUG_ON(1);
return -1;
Expand All @@ -797,7 +813,7 @@ static int collect_err(int err, struct ns_id *ns, void *arg)
char family[32], proto[32];
char msg[256];

snprintf(msg, sizeof(msg), "Sockects collect procedure family %s proto %s",
snprintf(msg, sizeof(msg), "Sockets collect procedure family %s proto %s",
socket_family_name(gr->family, family, sizeof(family)),
socket_proto_name(gr->protocol, proto, sizeof(proto)));

Expand Down Expand Up @@ -905,6 +921,13 @@ int collect_sockets(struct ns_id *ns)
if (tmp)
err = tmp;

/* Collect IPv4 ICMP sockets */
req.r.i.sdiag_family = AF_INET;
req.r.i.sdiag_protocol = IPPROTO_ICMP;
req.r.i.idiag_ext = 0;
req.r.i.idiag_states = -1; /* All */
set_collect_bit(req.r.n.sdiag_family, req.r.n.sdiag_protocol);

/* Collect IPv6 TCP sockets */
req.r.i.sdiag_family = AF_INET6;
req.r.i.sdiag_protocol = IPPROTO_TCP;
Expand Down Expand Up @@ -944,6 +967,13 @@ int collect_sockets(struct ns_id *ns)
if (tmp)
err = tmp;

/* Collect IPv6 ICMP sockets */
req.r.i.sdiag_family = AF_INET6;
req.r.i.sdiag_protocol = IPPROTO_ICMPV6;
req.r.i.idiag_ext = 0;
req.r.i.idiag_states = -1; /* All */
set_collect_bit(req.r.n.sdiag_family, req.r.n.sdiag_protocol);

req.r.p.sdiag_family = AF_PACKET;
req.r.p.sdiag_protocol = 0;
req.r.p.pdiag_show = PACKET_SHOW_INFO | PACKET_SHOW_MCLIST | PACKET_SHOW_FANOUT | PACKET_SHOW_RING_CFG;
Expand Down

0 comments on commit 71d69b7

Please sign in to comment.