diff --git a/criu/include/sockets.h b/criu/include/sockets.h index d9ed4e96b..1bd5c67d2 100644 --- a/criu/include/sockets.h +++ b/criu/include/sockets.h @@ -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; diff --git a/criu/sk-inet.c b/criu/sk-inet.c index 21165511d..feae97c68 100644 --- a/criu/sk-inet.c +++ b/criu/sk-inet.c @@ -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) diff --git a/criu/sk-netlink.c b/criu/sk-netlink.c index 2f0880520..2761305d1 100644 --- a/criu/sk-netlink.c +++ b/criu/sk-netlink.c @@ -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) diff --git a/criu/sk-packet.c b/criu/sk-packet.c index 90619f12e..bb1bd88b6 100644 --- a/criu/sk-packet.c +++ b/criu/sk-packet.c @@ -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) diff --git a/criu/sk-unix.c b/criu/sk-unix.c index 81587ac69..3963a4ad5 100644 --- a/criu/sk-unix.c +++ b/criu/sk-unix.c @@ -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, }; diff --git a/criu/sockets.c b/criu/sockets.c index 28fabaac0..727ba4adf 100644 --- a/criu/sockets.c +++ b/criu/sockets.c @@ -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; +}