network: non-functional changes

parent 9b0df30f
...@@ -2326,7 +2326,7 @@ static int setup_ipv6_addr(struct lxc_list *ip, int ifindex) ...@@ -2326,7 +2326,7 @@ static int setup_ipv6_addr(struct lxc_list *ip, int ifindex)
return 0; return 0;
} }
static int setup_netdev(struct lxc_netdev *netdev) static int lxc_setup_netdev_in_child_namespaces(struct lxc_netdev *netdev)
{ {
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
char *current_ifname = ifname; char *current_ifname = ifname;
...@@ -2508,7 +2508,8 @@ static int setup_netdev(struct lxc_netdev *netdev) ...@@ -2508,7 +2508,8 @@ static int setup_netdev(struct lxc_netdev *netdev)
return 0; return 0;
} }
static int setup_network(const struct lxc_conf *conf, struct lxc_list *network) static int lxc_setup_networks_in_child_namespaces(const struct lxc_conf *conf,
struct lxc_list *network)
{ {
struct lxc_list *iterator; struct lxc_list *iterator;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
...@@ -2516,10 +2517,9 @@ static int setup_network(const struct lxc_conf *conf, struct lxc_list *network) ...@@ -2516,10 +2517,9 @@ static int setup_network(const struct lxc_conf *conf, struct lxc_list *network)
lxc_log_configured_netdevs(conf); lxc_log_configured_netdevs(conf);
lxc_list_for_each(iterator, network) { lxc_list_for_each(iterator, network) {
netdev = iterator->elem; netdev = iterator->elem;
if (setup_netdev(netdev)) { if (lxc_setup_netdev_in_child_namespaces(netdev)) {
ERROR("failed to setup netdev"); ERROR("failed to setup netdev");
return -1; return -1;
} }
...@@ -3036,38 +3036,42 @@ int lxc_requests_empty_network(struct lxc_handler *handler) ...@@ -3036,38 +3036,42 @@ int lxc_requests_empty_network(struct lxc_handler *handler)
return 0; return 0;
} }
int lxc_create_network(struct lxc_handler *handler) int lxc_setup_networks_in_parent_namespaces(struct lxc_handler *handler)
{ {
struct lxc_list *network = &handler->conf->network; bool am_root;
struct lxc_list *iterator;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
int am_root = (getuid() == 0); struct lxc_list *iterator;
struct lxc_list *network = &handler->conf->network;
/* We need to be root. */
am_root = (getuid() == 0);
if (!am_root) if (!am_root)
return 0; return 0;
lxc_list_for_each(iterator, network) { lxc_list_for_each(iterator, network) {
netdev = iterator->elem; netdev = iterator->elem;
if (netdev->type != LXC_NET_MACVLAN && netdev->priv.macvlan_attr.mode) { if (netdev->type < 0 || netdev->type > LXC_NET_MAXCONFTYPE) {
ERROR("Invalid macvlan.mode for a non-macvlan netdev"); ERROR("invalid network configuration type '%d'",
netdev->type);
return -1; return -1;
} }
if (netdev->type != LXC_NET_VETH && netdev->priv.veth_attr.pair) { if (netdev->type != LXC_NET_MACVLAN &&
ERROR("Invalid veth pair for a non-veth netdev"); netdev->priv.macvlan_attr.mode) {
ERROR("Invalid macvlan.mode for a non-macvlan netdev");
return -1; return -1;
} }
if (netdev->type != LXC_NET_VLAN && netdev->priv.vlan_attr.vid > 0) { if (netdev->type != LXC_NET_VETH &&
ERROR("Invalid vlan.id for a non-macvlan netdev"); netdev->priv.veth_attr.pair) {
ERROR("Invalid veth pair for a non-veth netdev");
return -1; return -1;
} }
if (netdev->type < 0 || netdev->type > LXC_NET_MAXCONFTYPE) { if (netdev->type != LXC_NET_VLAN &&
ERROR("invalid network configuration type '%d'", netdev->priv.vlan_attr.vid > 0) {
netdev->type); ERROR("Invalid vlan.id for a non-macvlan netdev");
return -1; return -1;
} }
...@@ -3285,9 +3289,11 @@ int lxc_assign_network(const char *lxcpath, char *lxcname, ...@@ -3285,9 +3289,11 @@ int lxc_assign_network(const char *lxcpath, char *lxcname,
INFO("mtu ignored due to insufficient privilege"); INFO("mtu ignored due to insufficient privilege");
if (unpriv_assign_nic(lxcpath, lxcname, netdev, pid)) if (unpriv_assign_nic(lxcpath, lxcname, netdev, pid))
return -1; return -1;
// lxc-user-nic has moved the nic to the new ns. /* lxc-user-nic has moved the nic to the new ns.
// unpriv_assign_nic() fills in netdev->name. * unpriv_assign_nic() fills in netdev->name.
// netdev->ifindex will be filed in at setup_netdev. * netdev->ifindex will be filed in at
* lxc_setup_netdev_in_child_namespaces.
*/
continue; continue;
} }
...@@ -4110,7 +4116,8 @@ int lxc_setup(struct lxc_handler *handler) ...@@ -4110,7 +4116,8 @@ int lxc_setup(struct lxc_handler *handler)
} }
} }
if (setup_network(lxc_conf, &lxc_conf->network)) { if (lxc_setup_networks_in_child_namespaces(lxc_conf,
&lxc_conf->network)) {
ERROR("failed to setup the network for '%s'", name); ERROR("failed to setup the network for '%s'", name);
return -1; return -1;
} }
......
...@@ -432,7 +432,7 @@ extern void lxc_conf_free(struct lxc_conf *conf); ...@@ -432,7 +432,7 @@ extern void lxc_conf_free(struct lxc_conf *conf);
extern int pin_rootfs(const char *rootfs); extern int pin_rootfs(const char *rootfs);
extern int lxc_requests_empty_network(struct lxc_handler *handler); extern int lxc_requests_empty_network(struct lxc_handler *handler);
extern int lxc_create_network(struct lxc_handler *handler); extern int lxc_setup_networks_in_parent_namespaces(struct lxc_handler *handler);
extern bool lxc_delete_network(struct lxc_handler *handler); extern bool lxc_delete_network(struct lxc_handler *handler);
extern int lxc_assign_network(const char *lxcpath, char *lxcname, extern int lxc_assign_network(const char *lxcpath, char *lxcname,
struct lxc_list *networks, pid_t pid); struct lxc_list *networks, pid_t pid);
......
...@@ -1239,7 +1239,7 @@ static int lxc_spawn(struct lxc_handler *handler) ...@@ -1239,7 +1239,7 @@ static int lxc_spawn(struct lxc_handler *handler)
/* That should be done before the clone because we will /* That should be done before the clone because we will
* fill the netdev index and use them in the child. * fill the netdev index and use them in the child.
*/ */
if (lxc_create_network(handler)) { if (lxc_setup_networks_in_parent_namespaces(handler)) {
ERROR("Failed to create the network."); ERROR("Failed to create the network.");
lxc_sync_fini(handler); lxc_sync_fini(handler);
return -1; return -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