mirror of
git://github.com/lxc/lxc
synced 2025-08-31 10:09:37 +00:00
network: user send()/recv()
Also move all functions to network.{c,h}. Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
@@ -3106,43 +3106,6 @@ static int lxc_send_ttys_to_parent(struct lxc_handler *handler)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int lxc_network_send_name_and_ifindex_to_parent(struct lxc_handler *handler)
|
||||
{
|
||||
struct lxc_list *iterator, *network;
|
||||
int data_sock = handler->data_sock[0];
|
||||
|
||||
if (!handler->am_root)
|
||||
return 0;
|
||||
|
||||
network = &handler->conf->network;
|
||||
lxc_list_for_each(iterator, network) {
|
||||
int ret;
|
||||
struct lxc_netdev *netdev = iterator->elem;
|
||||
|
||||
/* Send network device name in the child's namespace to parent. */
|
||||
ret = lxc_abstract_unix_send_credential(data_sock, netdev->name,
|
||||
IFNAMSIZ);
|
||||
if (ret < 0)
|
||||
goto on_error;
|
||||
|
||||
/* Send network device ifindex in the child's namespace to
|
||||
* parent.
|
||||
*/
|
||||
ret = lxc_abstract_unix_send_credential(data_sock, &netdev->ifindex,
|
||||
sizeof(netdev->ifindex));
|
||||
if (ret < 0)
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
TRACE("Sent network device names and ifindeces to parent");
|
||||
return 0;
|
||||
|
||||
on_error:
|
||||
close(handler->data_sock[0]);
|
||||
close(handler->data_sock[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int lxc_setup(struct lxc_handler *handler)
|
||||
{
|
||||
const char *name = handler->name;
|
||||
|
@@ -3009,8 +3009,7 @@ int lxc_network_send_veth_names_to_child(struct lxc_handler *handler)
|
||||
if (netdev->type != LXC_NET_VETH)
|
||||
continue;
|
||||
|
||||
ret = lxc_abstract_unix_send_credential(data_sock, netdev->name,
|
||||
IFNAMSIZ);
|
||||
ret = send(data_sock, netdev->name, IFNAMSIZ, 0);
|
||||
if (ret < 0) {
|
||||
close(handler->data_sock[0]);
|
||||
close(handler->data_sock[1]);
|
||||
@@ -3040,8 +3039,7 @@ int lxc_network_recv_veth_names_from_parent(struct lxc_handler *handler)
|
||||
if (netdev->type != LXC_NET_VETH)
|
||||
continue;
|
||||
|
||||
ret = lxc_abstract_unix_rcv_credential(data_sock, netdev->name,
|
||||
IFNAMSIZ);
|
||||
ret = recv(data_sock, netdev->name, IFNAMSIZ, 0);
|
||||
if (ret < 0) {
|
||||
close(handler->data_sock[0]);
|
||||
close(handler->data_sock[1]);
|
||||
@@ -3054,3 +3052,74 @@ int lxc_network_recv_veth_names_from_parent(struct lxc_handler *handler)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lxc_network_send_name_and_ifindex_to_parent(struct lxc_handler *handler)
|
||||
{
|
||||
struct lxc_list *iterator, *network;
|
||||
int data_sock = handler->data_sock[0];
|
||||
|
||||
if (!handler->am_root)
|
||||
return 0;
|
||||
|
||||
network = &handler->conf->network;
|
||||
lxc_list_for_each(iterator, network) {
|
||||
int ret;
|
||||
struct lxc_netdev *netdev = iterator->elem;
|
||||
|
||||
/* Send network device name in the child's namespace to parent. */
|
||||
ret = send(data_sock, netdev->name, IFNAMSIZ, 0);
|
||||
if (ret < 0)
|
||||
goto on_error;
|
||||
|
||||
/* Send network device ifindex in the child's namespace to
|
||||
* parent.
|
||||
*/
|
||||
ret = send(data_sock, &netdev->ifindex, sizeof(netdev->ifindex), 0);
|
||||
if (ret < 0)
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
TRACE("Sent network device names and ifindeces to parent");
|
||||
return 0;
|
||||
|
||||
on_error:
|
||||
close(handler->data_sock[0]);
|
||||
close(handler->data_sock[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *handler)
|
||||
{
|
||||
struct lxc_list *iterator, *network;
|
||||
int data_sock = handler->data_sock[1];
|
||||
|
||||
if (!handler->am_root)
|
||||
return 0;
|
||||
|
||||
network = &handler->conf->network;
|
||||
lxc_list_for_each(iterator, network) {
|
||||
int ret;
|
||||
struct lxc_netdev *netdev = iterator->elem;
|
||||
|
||||
/* Receive network device name in the child's namespace to
|
||||
* parent.
|
||||
*/
|
||||
ret = recv(data_sock, netdev->name, IFNAMSIZ, 0);
|
||||
if (ret < 0)
|
||||
goto on_error;
|
||||
|
||||
/* Receive network device ifindex in the child's namespace to
|
||||
* parent.
|
||||
*/
|
||||
ret = recv(data_sock, &netdev->ifindex, sizeof(netdev->ifindex), 0);
|
||||
if (ret < 0)
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
on_error:
|
||||
close(handler->data_sock[0]);
|
||||
close(handler->data_sock[1]);
|
||||
return -1;
|
||||
}
|
||||
|
@@ -277,5 +277,7 @@ extern int lxc_setup_network_in_child_namespaces(const struct lxc_conf *conf,
|
||||
struct lxc_list *network);
|
||||
extern int lxc_network_send_veth_names_to_child(struct lxc_handler *handler);
|
||||
extern int lxc_network_recv_veth_names_from_parent(struct lxc_handler *handler);
|
||||
extern int lxc_network_send_name_and_ifindex_to_parent(struct lxc_handler *handler);
|
||||
extern int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *handler);
|
||||
|
||||
#endif /* __LXC_NETWORK_H */
|
||||
|
@@ -1057,43 +1057,6 @@ out_error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int lxc_network_recv_name_and_ifindex_from_child(struct lxc_handler *handler)
|
||||
{
|
||||
struct lxc_list *iterator, *network;
|
||||
int data_sock = handler->data_sock[1];
|
||||
|
||||
if (!handler->am_root)
|
||||
return 0;
|
||||
|
||||
network = &handler->conf->network;
|
||||
lxc_list_for_each(iterator, network) {
|
||||
int ret;
|
||||
struct lxc_netdev *netdev = iterator->elem;
|
||||
|
||||
/* Receive network device name in the child's namespace to
|
||||
* parent.
|
||||
*/
|
||||
ret = lxc_abstract_unix_rcv_credential(data_sock, netdev->name, IFNAMSIZ);
|
||||
if (ret < 0)
|
||||
goto on_error;
|
||||
|
||||
/* Receive network device ifindex in the child's namespace to
|
||||
* parent.
|
||||
*/
|
||||
ret = lxc_abstract_unix_rcv_credential(data_sock, &netdev->ifindex,
|
||||
sizeof(netdev->ifindex));
|
||||
if (ret < 0)
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
on_error:
|
||||
close(handler->data_sock[0]);
|
||||
close(handler->data_sock[1]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int lxc_recv_ttys_from_child(struct lxc_handler *handler)
|
||||
{
|
||||
int i;
|
||||
|
Reference in New Issue
Block a user