2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-29 13:28:27 +00:00

net: Add file_desc_ops::get_user_ns for sockets

Return user_ns of saved net ns_id.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
Kirill Tkhai 2017-06-07 14:28:12 +03:00 committed by Andrei Vagin
parent ecd57e0a3c
commit eecdaebaee
6 changed files with 47 additions and 0 deletions

View File

@ -45,6 +45,7 @@ extern struct collect_image_info netlink_sk_cinfo;
extern struct socket_desc *lookup_socket(unsigned ino, int family, int proto);
extern void fixup_sock_net_ns_id(uint32_t *ns_id, protobuf_c_boolean *has_ns_id);
extern void sock_get_user_ns(uint32_t sock_net_ns_id, struct ns_id **sock_user_ns);
extern const struct fdtype_ops unix_dump_ops;
extern const struct fdtype_ops inet_dump_ops;

View File

@ -509,9 +509,17 @@ int inet_collect_one(struct nlmsghdr *h, int family, int type, struct ns_id *ns)
static int open_inet_sk(struct file_desc *d, int *new_fd);
static int post_open_inet_sk(struct file_desc *d, int sk);
static void inet_get_user_ns(struct file_desc *desc, uint32_t *file_uns_id, struct ns_id **setns_uns)
{
uint32_t net_ns_id;
net_ns_id = container_of(desc, struct inet_sk_info, d)->ie->ns_id;
sock_get_user_ns(net_ns_id, setns_uns);
}
static struct file_desc_ops inet_desc_ops = {
.type = FD_TYPES__INETSK,
.open = open_inet_sk,
.get_user_ns = inet_get_user_ns,
};
static inline int tcp_connection(InetSkEntry *ie)

View File

@ -249,9 +249,17 @@ err:
return -1;
}
static void netlink_get_user_ns(struct file_desc *desc, uint32_t *file_uns_id, struct ns_id **setns_uns)
{
uint32_t net_ns_id;
net_ns_id = container_of(desc, struct netlink_sock_info, d)->nse->ns_id;
sock_get_user_ns(net_ns_id, setns_uns);
}
static struct file_desc_ops netlink_sock_desc_ops = {
.type = FD_TYPES__NETLINKSK,
.open = open_netlink_sk,
.get_user_ns = netlink_get_user_ns,
};
static int collect_one_netlink_sk(void *o, ProtobufCMessage *base, struct cr_img *i)

View File

@ -559,9 +559,17 @@ err:
return -1;
}
static void packet_get_user_ns(struct file_desc *desc, uint32_t *file_uns_id, struct ns_id **setns_uns)
{
uint32_t net_ns_id;
net_ns_id = container_of(desc, struct packet_sock_info, d)->pse->ns_id;
sock_get_user_ns(net_ns_id, setns_uns);
}
static struct file_desc_ops packet_sock_desc_ops = {
.type = FD_TYPES__PACKETSK,
.open = open_packet_sk,
.get_user_ns = packet_get_user_ns,
};
static int collect_one_packet_sk(void *o, ProtobufCMessage *base, struct cr_img *i)

View File

@ -1503,9 +1503,23 @@ static char *socket_d_name(struct file_desc *d, char *buf, size_t s)
return buf;
}
static void unix_get_user_ns(struct file_desc *desc, uint32_t *file_uns_id, struct ns_id **setns_uns)
{
struct unix_sk_info *ui;
uint32_t net_ns_id;
ui = container_of(desc, struct unix_sk_info, d);
net_ns_id = ui->ue->ns_id;
if (ui->ue->uflags & USK_EXTERN)
*setns_uns = NULL;
else
sock_get_user_ns(net_ns_id, setns_uns);
}
static struct file_desc_ops unix_desc_ops = {
.type = FD_TYPES__UNIXSK,
.open = open_unix_sk,
.get_user_ns = unix_get_user_ns,
.name = socket_d_name,
};

View File

@ -790,3 +790,11 @@ void fixup_sock_net_ns_id(uint32_t *ns_id, protobuf_c_boolean *has_ns_id)
*has_ns_id = true;
*ns_id = top_net_ns->id;
}
void sock_get_user_ns(uint32_t sock_net_ns_id, struct ns_id **sock_user_ns)
{
struct ns_id *net_ns_id;
net_ns_id = lookup_ns_by_id(sock_net_ns_id, &net_ns_desc);
BUG_ON(!net_ns_id);
*sock_user_ns = net_ns_id->user_ns;
}