Commit 7dc4b34e authored by Andrei Vagin's avatar Andrei Vagin

net: give ns_id to link_info functions

It will be used to restore links in different net namesapces.
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 9a2c99c3
...@@ -765,7 +765,7 @@ skip:; ...@@ -765,7 +765,7 @@ skip:;
} }
static int dump_one_sit(struct ifinfomsg *ifi, char *kind, static int dump_one_sit(struct ifinfomsg *ifi, char *kind,
struct nlattr **tb, struct cr_imgset *fds) struct nlattr **tb, struct ns_id *ns, struct cr_imgset *fds)
{ {
char *name; char *name;
...@@ -785,7 +785,7 @@ static int dump_one_sit(struct ifinfomsg *ifi, char *kind, ...@@ -785,7 +785,7 @@ static int dump_one_sit(struct ifinfomsg *ifi, char *kind,
return 0; return 0;
} }
return dump_one_netdev(ND_TYPE__SIT, ifi, tb, fds, dump_sit); return dump_one_netdev(ND_TYPE__SIT, ifi, tb, ns, fds, dump_sit);
} }
static int list_one_link(struct nlmsghdr *hdr, struct ns_id *ns, void *arg) static int list_one_link(struct nlmsghdr *hdr, struct ns_id *ns, void *arg)
...@@ -832,7 +832,7 @@ static int dump_one_link(struct nlmsghdr *hdr, struct ns_id *ns, void *arg) ...@@ -832,7 +832,7 @@ static int dump_one_link(struct nlmsghdr *hdr, struct ns_id *ns, void *arg)
ret = dump_one_gre(ifi, kind, tb, ns, fds); ret = dump_one_gre(ifi, kind, tb, ns, fds);
break; break;
case ARPHRD_SIT: case ARPHRD_SIT:
ret = dump_one_sit(ifi, kind, tb, fds); ret = dump_one_sit(ifi, kind, tb, ns, fds);
break; break;
default: default:
unk: unk:
...@@ -1080,8 +1080,11 @@ struct newlink_extras { ...@@ -1080,8 +1080,11 @@ struct newlink_extras {
int target_netns; /* IFLA_NET_NS_FD */ int target_netns; /* IFLA_NET_NS_FD */
}; };
static int populate_newlink_req(struct newlink_req *req, int msg_type, NetDeviceEntry *nde, typedef int (*link_info_t)(struct ns_id *ns, NetDeviceEntry *, struct newlink_req *);
int (*link_info)(NetDeviceEntry *, struct newlink_req *), struct newlink_extras *extras)
static int populate_newlink_req(struct ns_id *ns, struct newlink_req *req,
int msg_type, NetDeviceEntry *nde,
link_info_t link_info, struct newlink_extras *extras)
{ {
memset(req, 0, sizeof(*req)); memset(req, 0, sizeof(*req));
...@@ -1125,7 +1128,7 @@ static int populate_newlink_req(struct newlink_req *req, int msg_type, NetDevice ...@@ -1125,7 +1128,7 @@ static int populate_newlink_req(struct newlink_req *req, int msg_type, NetDevice
linkinfo = NLMSG_TAIL(&req->h); linkinfo = NLMSG_TAIL(&req->h);
addattr_l(&req->h, sizeof(*req), IFLA_LINKINFO, NULL, 0); addattr_l(&req->h, sizeof(*req), IFLA_LINKINFO, NULL, 0);
ret = link_info(nde, req); ret = link_info(ns, nde, req);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -1135,13 +1138,13 @@ static int populate_newlink_req(struct newlink_req *req, int msg_type, NetDevice ...@@ -1135,13 +1138,13 @@ static int populate_newlink_req(struct newlink_req *req, int msg_type, NetDevice
return 0; return 0;
} }
static int do_rtm_link_req(int msg_type, NetDeviceEntry *nde, int nlsk, static int do_rtm_link_req(int msg_type,
int (*link_info)(NetDeviceEntry *, struct newlink_req *), NetDeviceEntry *nde, int nlsk, struct ns_id *ns,
struct newlink_extras *extras) link_info_t link_info, struct newlink_extras *extras)
{ {
struct newlink_req req; struct newlink_req req;
if (populate_newlink_req(&req, msg_type, nde, link_info, extras) < 0) if (populate_newlink_req(ns, &req, msg_type, nde, link_info, extras) < 0)
return -1; return -1;
return do_rtnl_req(nlsk, &req, req.h.nlmsg_len, restore_link_cb, NULL, NULL, NULL); return do_rtnl_req(nlsk, &req, req.h.nlmsg_len, restore_link_cb, NULL, NULL, NULL);
...@@ -1149,15 +1152,14 @@ static int do_rtm_link_req(int msg_type, NetDeviceEntry *nde, int nlsk, ...@@ -1149,15 +1152,14 @@ static int do_rtm_link_req(int msg_type, NetDeviceEntry *nde, int nlsk,
int restore_link_parms(NetDeviceEntry *nde, int nlsk) int restore_link_parms(NetDeviceEntry *nde, int nlsk)
{ {
return do_rtm_link_req(RTM_SETLINK, nde, nlsk, NULL, NULL); return do_rtm_link_req(RTM_SETLINK, nde, nlsk, NULL, NULL, NULL);
} }
static int restore_one_link(NetDeviceEntry *nde, int nlsk, static int restore_one_link(struct ns_id *ns, NetDeviceEntry *nde, int nlsk,
int (*link_info)(NetDeviceEntry *, struct newlink_req *), link_info_t link_info, struct newlink_extras *extras)
struct newlink_extras *extras)
{ {
pr_info("Restoring netdev %s idx %d\n", nde->name, nde->ifindex); pr_info("Restoring netdev %s idx %d\n", nde->name, nde->ifindex);
return do_rtm_link_req(RTM_NEWLINK, nde, nlsk, link_info, extras); return do_rtm_link_req(RTM_NEWLINK, nde, nlsk, ns, link_info, extras);
} }
#ifndef VETH_INFO_MAX #ifndef VETH_INFO_MAX
...@@ -1188,7 +1190,7 @@ static void veth_peer_info(NetDeviceEntry *nde, struct newlink_req *req) ...@@ -1188,7 +1190,7 @@ static void veth_peer_info(NetDeviceEntry *nde, struct newlink_req *req)
} }
} }
static int veth_link_info(NetDeviceEntry *nde, struct newlink_req *req) static int veth_link_info(struct ns_id *ns, NetDeviceEntry *nde, struct newlink_req *req)
{ {
int ns_fd = get_service_fd(NS_FD_OFF); int ns_fd = get_service_fd(NS_FD_OFF);
struct rtattr *veth_data, *peer_data; struct rtattr *veth_data, *peer_data;
...@@ -1211,7 +1213,7 @@ static int veth_link_info(NetDeviceEntry *nde, struct newlink_req *req) ...@@ -1211,7 +1213,7 @@ static int veth_link_info(NetDeviceEntry *nde, struct newlink_req *req)
return 0; return 0;
} }
static int venet_link_info(NetDeviceEntry *nde, struct newlink_req *req) static int venet_link_info(struct ns_id *ns, NetDeviceEntry *nde, struct newlink_req *req)
{ {
int ns_fd = get_service_fd(NS_FD_OFF); int ns_fd = get_service_fd(NS_FD_OFF);
struct rtattr *venet_data; struct rtattr *venet_data;
...@@ -1227,7 +1229,7 @@ static int venet_link_info(NetDeviceEntry *nde, struct newlink_req *req) ...@@ -1227,7 +1229,7 @@ static int venet_link_info(NetDeviceEntry *nde, struct newlink_req *req)
return 0; return 0;
} }
static int bridge_link_info(NetDeviceEntry *nde, struct newlink_req *req) static int bridge_link_info(struct ns_id *ns, NetDeviceEntry *nde, struct newlink_req *req)
{ {
struct rtattr *bridge_data; struct rtattr *bridge_data;
...@@ -1253,7 +1255,7 @@ static int changeflags(int s, char *name, short flags) ...@@ -1253,7 +1255,7 @@ static int changeflags(int s, char *name, short flags)
return 0; return 0;
} }
static int macvlan_link_info(NetDeviceEntry *nde, struct newlink_req *req) static int macvlan_link_info(struct ns_id *ns, NetDeviceEntry *nde, struct newlink_req *req)
{ {
struct rtattr *macvlan_data; struct rtattr *macvlan_data;
MacvlanLinkEntry *macvlan = nde->macvlan; MacvlanLinkEntry *macvlan = nde->macvlan;
...@@ -1307,7 +1309,7 @@ out: ...@@ -1307,7 +1309,7 @@ out:
return ret; return ret;
} }
static int restore_one_macvlan(NetDeviceEntry *nde, int nlsk, int criu_nlsk) static int restore_one_macvlan(struct ns_id *ns, NetDeviceEntry *nde, int nlsk, int criu_nlsk)
{ {
struct newlink_extras extras = { struct newlink_extras extras = {
.link = -1, .link = -1,
...@@ -1342,7 +1344,7 @@ static int restore_one_macvlan(NetDeviceEntry *nde, int nlsk, int criu_nlsk) ...@@ -1342,7 +1344,7 @@ static int restore_one_macvlan(NetDeviceEntry *nde, int nlsk, int criu_nlsk)
{ {
struct newlink_req req; struct newlink_req req;
if (populate_newlink_req(&req, RTM_NEWLINK, nde, macvlan_link_info, &extras) < 0) if (populate_newlink_req(ns, &req, RTM_NEWLINK, nde, macvlan_link_info, &extras) < 0)
goto out; goto out;
if (userns_call(userns_restore_one_link, 0, &req, sizeof(req), my_netns) < 0) { if (userns_call(userns_restore_one_link, 0, &req, sizeof(req), my_netns) < 0) {
...@@ -1358,7 +1360,7 @@ out: ...@@ -1358,7 +1360,7 @@ out:
return ret; return ret;
} }
static int sit_link_info(NetDeviceEntry *nde, struct newlink_req *req) static int sit_link_info(struct ns_id *ns, NetDeviceEntry *nde, struct newlink_req *req)
{ {
struct rtattr *sit_data; struct rtattr *sit_data;
SitEntry *se = nde->sit; SitEntry *se = nde->sit;
...@@ -1446,7 +1448,7 @@ skip:; ...@@ -1446,7 +1448,7 @@ skip:;
return 0; return 0;
} }
static int restore_link(NetDeviceEntry *nde, int nlsk, int criu_nlsk) static int restore_link(struct ns_id *ns, NetDeviceEntry *nde, int nlsk, int criu_nlsk)
{ {
pr_info("Restoring link %s type %d\n", nde->name, nde->type); pr_info("Restoring link %s type %d\n", nde->name, nde->type);
...@@ -1455,17 +1457,17 @@ static int restore_link(NetDeviceEntry *nde, int nlsk, int criu_nlsk) ...@@ -1455,17 +1457,17 @@ static int restore_link(NetDeviceEntry *nde, int nlsk, int criu_nlsk)
case ND_TYPE__EXTLINK: /* see comment in images/netdev.proto */ case ND_TYPE__EXTLINK: /* see comment in images/netdev.proto */
return restore_link_parms(nde, nlsk); return restore_link_parms(nde, nlsk);
case ND_TYPE__VENET: case ND_TYPE__VENET:
return restore_one_link(nde, nlsk, venet_link_info, NULL); return restore_one_link(ns, nde, nlsk, venet_link_info, NULL);
case ND_TYPE__VETH: case ND_TYPE__VETH:
return restore_one_link(nde, nlsk, veth_link_info, NULL); return restore_one_link(ns, nde, nlsk, veth_link_info, NULL);
case ND_TYPE__TUN: case ND_TYPE__TUN:
return restore_one_tun(nde, nlsk); return restore_one_tun(nde, nlsk);
case ND_TYPE__BRIDGE: case ND_TYPE__BRIDGE:
return restore_one_link(nde, nlsk, bridge_link_info, NULL); return restore_one_link(ns, nde, nlsk, bridge_link_info, NULL);
case ND_TYPE__MACVLAN: case ND_TYPE__MACVLAN:
return restore_one_macvlan(nde, nlsk, criu_nlsk); return restore_one_macvlan(ns, nde, nlsk, criu_nlsk);
case ND_TYPE__SIT: case ND_TYPE__SIT:
return restore_one_link(nde, nlsk, sit_link_info, NULL); return restore_one_link(ns, nde, nlsk, sit_link_info, NULL);
default: default:
pr_err("Unsupported link type %d\n", nde->type); pr_err("Unsupported link type %d\n", nde->type);
break; break;
...@@ -1474,13 +1476,13 @@ static int restore_link(NetDeviceEntry *nde, int nlsk, int criu_nlsk) ...@@ -1474,13 +1476,13 @@ static int restore_link(NetDeviceEntry *nde, int nlsk, int criu_nlsk)
return -1; return -1;
} }
static int restore_links(int pid, NetnsEntry **netns) static int restore_links(struct ns_id *ns, NetnsEntry **netns)
{ {
int nlsk, criu_nlsk = -1, ret = -1; int nlsk, criu_nlsk = -1, ret = -1, id = ns->id;
struct cr_img *img; struct cr_img *img;
NetDeviceEntry *nde; NetDeviceEntry *nde;
img = open_image(CR_FD_NETDEV, O_RSTR, pid); img = open_image(CR_FD_NETDEV, O_RSTR, id);
if (!img) if (!img)
return -1; return -1;
...@@ -1498,7 +1500,7 @@ static int restore_links(int pid, NetnsEntry **netns) ...@@ -1498,7 +1500,7 @@ static int restore_links(int pid, NetnsEntry **netns)
if (ret <= 0) if (ret <= 0)
break; break;
ret = restore_link(nde, nlsk, criu_nlsk); ret = restore_link(ns, nde, nlsk, criu_nlsk);
if (ret) { if (ret) {
pr_err("Can't restore link\n"); pr_err("Can't restore link\n");
goto exit; goto exit;
...@@ -2060,7 +2062,7 @@ static int prepare_net_ns(struct ns_id *ns) ...@@ -2060,7 +2062,7 @@ static int prepare_net_ns(struct ns_id *ns)
if (!ret) if (!ret)
ret = restore_netns_ids(ns, netns); ret = restore_netns_ids(ns, netns);
if (!ret) if (!ret)
ret = restore_links(nsid, &netns); ret = restore_links(ns, &netns);
if (netns) if (netns)
netns_entry__free_unpacked(netns, NULL); netns_entry__free_unpacked(netns, NULL);
...@@ -2687,7 +2689,7 @@ int net_get_nsid(int rtsk, int pid, int *nsid) ...@@ -2687,7 +2689,7 @@ int net_get_nsid(int rtsk, int pid, int *nsid)
} }
static int nsid_link_info(NetDeviceEntry *nde, struct newlink_req *req) static int nsid_link_info(struct ns_id *ns, NetDeviceEntry *nde, struct newlink_req *req)
{ {
struct rtattr *veth_data, *peer_data; struct rtattr *veth_data, *peer_data;
struct ifinfomsg ifm; struct ifinfomsg ifm;
...@@ -2796,7 +2798,7 @@ int kerndat_link_nsid() ...@@ -2796,7 +2798,7 @@ int kerndat_link_nsid()
nde.has_peer_ifindex = true; nde.has_peer_ifindex = true;
nde.has_peer_nsid = true; nde.has_peer_nsid = true;
ret = restore_one_link(&nde, sk, nsid_link_info, NULL); ret = restore_one_link(NULL, &nde, sk, nsid_link_info, NULL);
if (ret) { if (ret) {
pr_err("Unable to create a veth pair: %d\n", ret); pr_err("Unable to create a veth pair: %d\n", ret);
exit(1); exit(1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment