The netdev vs network structure is not well defined. Fix that.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
---
 src/lxc/conf.c    |   37 ++++++------------
 src/lxc/conf.h    |   17 --------
 src/lxc/confile.c |  110 ++++++++++++++++--------------------------------------
 src/lxc/start.c   |    4 -
 4 files changed, 52 insertions(+), 116 deletions(-)

Index: lxc/src/lxc/conf.c
===================================================================
--- lxc.orig/src/lxc/conf.c
+++ lxc/src/lxc/conf.c
@@ -896,17 +896,14 @@ static int setup_netdev(struct lxc_netde
 	return 0;
 }
 
-static int setup_network(struct lxc_list *networks)
+static int setup_network(struct lxc_list *network)
 {
 	struct lxc_list *iterator;
-	struct lxc_network *network;
 	struct lxc_netdev *netdev;
 
-	lxc_list_for_each(iterator, networks) {
+	lxc_list_for_each(iterator, network) {
 
-		network = iterator->elem;
-
-		netdev = lxc_list_first_elem(&network->netdev);
+		netdev = iterator->elem;
 
 		if (setup_netdev(netdev)) {
 			ERROR("failed to setup netdev");
@@ -952,7 +949,7 @@ int lxc_conf_init(struct lxc_conf *conf)
 	conf->pts = 0;
 	conf->console[0] = '\0';
 	lxc_list_init(&conf->cgroup);
-	lxc_list_init(&conf->networks);
+	lxc_list_init(&conf->network);
 	return 0;
 }
 
@@ -1108,25 +1105,22 @@ static int instanciate_empty(struct lxc_
 	return 0;
 }
 
-int lxc_create_network(struct lxc_list *networks)
+int lxc_create_network(struct lxc_list *network)
 {
 	struct lxc_list *iterator;
-	struct lxc_network *network;
 	struct lxc_netdev *netdev;
 
-	lxc_list_for_each(iterator, networks) {
+	lxc_list_for_each(iterator, network) {
 
-		network = iterator->elem;
+		netdev = iterator->elem;
 
-		if (network->type < 0 || network->type > MAXCONFTYPE) {
+		if (netdev->type < 0 || netdev->type > MAXCONFTYPE) {
 			ERROR("invalid network configuration type '%d'",
-			      network->type);
+			      netdev->type);
 			return -1;
 		}
 
-		netdev = lxc_list_first_elem(&network->netdev);
-
-		if (netdev_conf[network->type](netdev)) {
+		if (netdev_conf[netdev->type](netdev)) {
 			ERROR("failed to create netdev");
 			return -1;
 		}
@@ -1135,17 +1129,14 @@ int lxc_create_network(struct lxc_list *
 	return 0;
 }
 
-int lxc_assign_network(struct lxc_list *networks, pid_t pid)
+int lxc_assign_network(struct lxc_list *network, pid_t pid)
 {
 	struct lxc_list *iterator;
-	struct lxc_network *network;
 	struct lxc_netdev *netdev;
 
-	lxc_list_for_each(iterator, networks) {
-
-		network = iterator->elem;
+	lxc_list_for_each(iterator, network) {
 
-		netdev = lxc_list_first_elem(&network->netdev);
+		netdev = iterator->elem;
 
 		if (lxc_device_move(netdev->ifindex, pid)) {
 			ERROR("failed to move '%s' to the container",
@@ -1237,7 +1228,7 @@ int lxc_setup(const char *name, struct l
 		return -1;
 	}
 
-	if (setup_network(&lxc_conf->networks)) {
+	if (setup_network(&lxc_conf->network)) {
 		ERROR("failed to setup the network for '%s'", name);
 		return -1;
 	}
Index: lxc/src/lxc/conf.h
===================================================================
--- lxc.orig/src/lxc/conf.h
+++ lxc/src/lxc/conf.h
@@ -75,6 +75,7 @@ struct lxc_route6 {
  * @ipv6   : a list of ipv6 addresses to be set on the network device
  */
 struct lxc_netdev {
+	int type;
 	int flags;
 	int ifindex;
 	char *ifname;
@@ -83,20 +84,6 @@ struct lxc_netdev {
 	char *mtu;
 	struct lxc_list ipv4;
 	struct lxc_list ipv6;
-	struct lxc_list route4;
-	struct lxc_list route6;
-};
-
-/*
- * Defines the kind of the network to use
- * @type : the type of the network virtualization
- * @phys : phys configuration type
- * @veth : veth configuration type
- * @macvlan : macvlan configuration type
- */
-struct lxc_network {
-	int type;
-	struct lxc_list netdev;
 };
 
 /*
@@ -149,7 +136,7 @@ struct lxc_conf {
 	int pts;
 	struct utsname *utsname;
 	struct lxc_list cgroup;
-	struct lxc_list networks;
+	struct lxc_list network;
 	struct lxc_tty_info tty_info;
 	char console[MAXPATHLEN];
 };
Index: lxc/src/lxc/confile.c
===================================================================
--- lxc.orig/src/lxc/confile.c
+++ lxc/src/lxc/confile.c
@@ -94,19 +94,9 @@ static struct config *getconfig(const ch
 
 static int config_network_type(const char *key, char *value, struct lxc_conf *lxc_conf)
 {
-	struct lxc_list *networks = &lxc_conf->networks;
-	struct lxc_network *network;
+	struct lxc_list *network = &lxc_conf->network;
 	struct lxc_netdev *netdev;
 	struct lxc_list *list;
-	struct lxc_list *ndlist;
-
-	network = malloc(sizeof(*network));
-	if (!network) {
-		SYSERROR("failed to allocate memory");
-		return -1;
-	}
-
-	lxc_list_init(&network->netdev);
 
 	netdev = malloc(sizeof(*netdev));
 	if (!netdev) {
@@ -117,18 +107,6 @@ static int config_network_type(const cha
 	memset(netdev, 0, sizeof(*netdev));
 	lxc_list_init(&netdev->ipv4);
 	lxc_list_init(&netdev->ipv6);
-	lxc_list_init(&netdev->route4);
-	lxc_list_init(&netdev->route6);
-
-	ndlist = malloc(sizeof(*ndlist));
-	if (!ndlist) {
-		SYSERROR("failed to allocate memory");
-		return -1;
-	}
-
-	ndlist->elem = netdev;
-
-	lxc_list_add(&network->netdev, ndlist);
 
 	list = malloc(sizeof(*list));
 	if (!list) {
@@ -137,18 +115,18 @@ static int config_network_type(const cha
 	}
 
 	lxc_list_init(list);
-	list->elem = network;
+	list->elem = netdev;
 
-	lxc_list_add(networks, list);
+	lxc_list_add(network, list);
 
 	if (!strcmp(value, "veth"))
-		network->type = VETH;
+		netdev->type = VETH;
 	else if (!strcmp(value, "macvlan"))
-		network->type = MACVLAN;
+		netdev->type = MACVLAN;
 	else if (!strcmp(value, "phys"))
-		network->type = PHYS;
+		netdev->type = PHYS;
 	else if (!strcmp(value, "empty"))
-		network->type = EMPTY;
+		netdev->type = EMPTY;
 	else {
 		ERROR("invalid network type %s", value);
 		return -1;
@@ -158,39 +136,36 @@ static int config_network_type(const cha
 
 static int config_network_flags(const char *key, char *value, struct lxc_conf *lxc_conf)
 {
-	struct lxc_list *networks = &lxc_conf->networks;
-	struct lxc_network *network;
+	struct lxc_list *network = &lxc_conf->network;
 	struct lxc_netdev *netdev;
 
-	if (lxc_list_empty(networks)) {
+	if (lxc_list_empty(network)) {
 		ERROR("network is not created for '%s' option", value);
 		return -1;
 	}
 
-	network = lxc_list_first_elem(networks);
-	if (!network) {
+	netdev = lxc_list_first_elem(network);
+	if (!netdev) {
 		ERROR("no network defined for '%s' option", value);
 		return -1;
 	}
 
-	netdev = lxc_list_first_elem(&network->netdev);
 	netdev->flags |= IFF_UP;
 	return 0;
 }
 
 static int config_network_link(const char *key, char *value, struct lxc_conf *lxc_conf)
 {
-	struct lxc_list *networks = &lxc_conf->networks;
-	struct lxc_network *network;
+	struct lxc_list *network = &lxc_conf->network;
 	struct lxc_netdev *netdev;
 
-	if (lxc_list_empty(networks)) {
+	if (lxc_list_empty(network)) {
 		ERROR("network is not created for %s", value);
 		return -1;
 	}
 
-	network = lxc_list_first_elem(networks);
-	if (!network) {
+	netdev = lxc_list_first_elem(network);
+	if (!netdev) {
 		ERROR("no network defined for %s", value);
 		return -1;
 	}
@@ -200,24 +175,22 @@ static int config_network_link(const cha
 		return -1;
 	}
 
-	netdev = lxc_list_first_elem(&network->netdev);
 	netdev->ifname = strdup(value);
 	return 0;
 }
 
 static int config_network_name(const char *key, char *value, struct lxc_conf *lxc_conf)
 {
-	struct lxc_list *networks = &lxc_conf->networks;
-	struct lxc_network *network;
+	struct lxc_list *network = &lxc_conf->network;
 	struct lxc_netdev *netdev;
 
-	if (lxc_list_empty(networks)) {
+	if (lxc_list_empty(network)) {
 		ERROR("network is not created for %s", value);
 		return -1;
 	}
 
-	network = lxc_list_first_elem(networks);
-	if (!network) {
+	netdev = lxc_list_first_elem(network);
+	if (!netdev) {
 		ERROR("no network defined for %s", value);
 		return -1;
 	}
@@ -227,76 +200,64 @@ static int config_network_name(const cha
 		return -1;
 	}
 
-	netdev = lxc_list_first_elem(&network->netdev);
 	netdev->newname = strdup(value);
 	return 0;
 }
 
 static int config_network_hwaddr(const char *key, char *value, struct lxc_conf *lxc_conf)
 {
-	struct lxc_list *networks = &lxc_conf->networks;
-	struct lxc_network *network;
+	struct lxc_list *network = &lxc_conf->network;
 	struct lxc_netdev *netdev;
 
-	if (lxc_list_empty(networks)) {
+	if (lxc_list_empty(network)) {
 		ERROR("network is not created for %s", value);
 		return -1;
 	}
 
-	network = lxc_list_first_elem(networks);
-	if (!network) {
+	netdev = lxc_list_first_elem(network);
+	if (!netdev) {
 		ERROR("no network defined for %s", value);
 		return -1;
 	}
 
-	netdev = lxc_list_first_elem(&network->netdev);
 	netdev->hwaddr = strdup(value);
 	return 0;
 }
 
 static int config_network_mtu(const char *key, char *value, struct lxc_conf *lxc_conf)
 {
-	struct lxc_list *networks = &lxc_conf->networks;
-	struct lxc_network *network;
+	struct lxc_list *network = &lxc_conf->network;
 	struct lxc_netdev *netdev;
 
-	if (lxc_list_empty(networks)) {
+	if (lxc_list_empty(network)) {
 		ERROR("network is not created for %s", value);
 		return -1;
 	}
 
-	network = lxc_list_first_elem(networks);
-	if (!network) {
+	netdev = lxc_list_first_elem(network);
+	if (!netdev) {
 		ERROR("no network defined for %s", value);
 		return -1;
 	}
 
-	netdev = lxc_list_first_elem(&network->netdev);
 	netdev->mtu = strdup(value);
 	return 0;
 }
 
 static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lxc_conf)
 {
-	struct lxc_list *networks = &lxc_conf->networks;
-	struct lxc_network *network;
+	struct lxc_list *network = &lxc_conf->network;
 	struct lxc_inetdev *inetdev;
 	struct lxc_netdev *netdev;
 	struct lxc_list *list;
 	char *cursor, *slash, *addr = NULL, *bcast = NULL, *prefix = NULL;
 
-	if (lxc_list_empty(networks)) {
+	if (lxc_list_empty(network)) {
 		ERROR("network is not created for '%s'", value);
 		return -1;
 	}
 
-	network = lxc_list_first_elem(networks);
-	if (!network) {
-		ERROR("no network defined for '%s'", value);
-		return -1;
-	}
-
-	netdev = lxc_list_first_elem(&network->netdev);
+	netdev = lxc_list_first_elem(network);
 	if (!netdev) {
 		ERROR("no netdev defined for '%s'", value);
 	}
@@ -357,21 +318,20 @@ static int config_network_ipv4(const cha
 
 static int config_network_ipv6(const char *key, char *value, struct lxc_conf *lxc_conf)
 {
-	struct lxc_list *networks = &lxc_conf->networks;
-	struct lxc_network *network;
+	struct lxc_list *network = &lxc_conf->network;
 	struct lxc_netdev *netdev;
 	struct lxc_inet6dev *inet6dev;
 	struct lxc_list *list;
 	char *slash;
 	char *netmask;
 
-	if (lxc_list_empty(networks)) {
+	if (lxc_list_empty(network)) {
 		ERROR("network is not created for %s", value);
 		return -1;
 	}
 
-	network = lxc_list_first_elem(networks);
-	if (!network) {
+	netdev = lxc_list_first_elem(network);
+	if (!netdev) {
 		ERROR("no network defined for %s", value);
 		return -1;
 	}
@@ -404,8 +364,6 @@ static int config_network_ipv6(const cha
 		return -1;
 	}
 
-
-	netdev = lxc_list_first_elem(&network->netdev);
 	lxc_list_add(&netdev->ipv6, list);
 
 	return 0;
Index: lxc/src/lxc/start.c
===================================================================
--- lxc.orig/src/lxc/start.c
+++ lxc/src/lxc/start.c
@@ -432,7 +432,7 @@ int lxc_spawn(const char *name, struct l
 		/* that should be done before the clone because we will
 		 * fill the netdev index and use them in the child
 		 */
-		if (lxc_create_network(&handler->conf.networks)) {
+		if (lxc_create_network(&handler->conf.network)) {
 			ERROR("failed to create the network");
 			goto out_close;
 		}
@@ -458,7 +458,7 @@ int lxc_spawn(const char *name, struct l
 
 	/* Create the network configuration */
 	if (clone_flags & CLONE_NEWNET) {
-		if (lxc_assign_network(&handler->conf.networks, handler->pid)) {
+		if (lxc_assign_network(&handler->conf.network, handler->pid)) {
 			ERROR("failed to create the configured network");
 			goto out_abort;
 		}



