Now that we have the network functions accessible, do not longer
use the lxc_configure_veth, lxc_configure_macvlan and split
the configuration of the veth in order to create it, configure it
and finally attach it to the bridge.


Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
---
 src/lxc/lxc_conf.c |   57 +++++++++++++++++++++++++++++++----------------------
 src/lxc/network.c  |   32 -----------------------------
 src/lxc/network.h  |   11 ----------
 3 files changed, 34 insertions(+), 66 deletions(-)

Index: lxc/src/lxc/network.c
===================================================================
--- lxc.orig/src/lxc/network.c
+++ lxc/src/lxc/network.c
@@ -737,35 +737,3 @@ int lxc_bridge_detach(const char *bridge
 {
 	return bridge_add_del_interface(bridge, ifname, 1);
 }
-
-int lxc_configure_veth(const char *veth1, const char *veth2, const char *bridge)
-{
-	int err = -1;
-	if (lxc_veth_create(veth1, veth2)) {
-		fprintf(stderr, "failed to create veth interfaces %s/%s\n",
-			veth1, veth2);
-		return -1;
-	}
-
-	if (lxc_bridge_attach(bridge, veth1)) {
-		fprintf(stderr, "failed to attach %s to %s\n", 
-			veth1, bridge);
-		goto err;
-	}
-
-	err = 0;
-out:
-	return err;
-err:
-	lxc_device_delete(veth1);
-	goto out;
-}
-
-int lxc_configure_macvlan(const char *link, const char *peer)
-{
-	if (lxc_macvlan_create(link, peer)) {
-		fprintf(stderr, "failed to create %s", peer);
-		return -1;
-	}
-	return 0;
-}
Index: lxc/src/lxc/network.h
===================================================================
--- lxc.orig/src/lxc/network.h
+++ lxc/src/lxc/network.h
@@ -24,17 +24,6 @@
 #define _network_h
 
 /*
- * Create a macvlan network device
- */
-extern int lxc_configure_macvlan(const char *link, const char *peer);
-
-/*
- * Create a veth pair virtual device
- */
-extern int lxc_configure_veth(const char *veth1, const char *veth2, 
-			      const char *bridge);
-
-/*
  * Convert a string mac address to a socket structure
  */
 extern int lxc_convert_mac(char *macaddr, struct sockaddr *sockaddr);
Index: lxc/src/lxc/lxc_conf.c
===================================================================
--- lxc.orig/src/lxc/lxc_conf.c
+++ lxc/src/lxc/lxc_conf.c
@@ -1388,48 +1388,54 @@ static int instanciate_veth(const char *
 		goto out;
 	}
 
-	if (lxc_configure_veth(veth1, veth2, bridge)) {
+	if (lxc_veth_create(veth1, veth2)) {
 		lxc_log_error("failed to create %s-%s/%s", veth1, veth2, bridge);
 		goto out;
 	}
 	
-	ifindex = if_nametoindex(veth2);
-	if (!ifindex) {
-		lxc_log_error("failed to retrieve the index for %s", veth2);
-		goto out;
-	}
-	
-	if (!asprintf(&strindex, "%d", ifindex)) {
-		lxc_log_syserror("failed to allocate memory");
-		goto out;
-	}
-
-	if (write_info(path, "ifindex", strindex)) {
-		lxc_log_error("failed to write interface index to %s", path);
-		goto out;
-	}
-
 	if (!read_info(path, "mtu", strmtu, MAXMTULEN)) {
 		if (sscanf(strmtu, "%u", &mtu) < 1) {
 			lxc_log_error("invalid mtu size '%d'", mtu);
-			goto out;
+			goto out_delete;
 		}
 
 		if (lxc_device_set_mtu(veth1, mtu)) {
 			lxc_log_error("failed to set mtu for '%s'", veth1);
-			goto out;
+			goto out_delete;
 		}
 
 		if (lxc_device_set_mtu(veth2, mtu)) {
 			lxc_log_error("failed to set mtu for '%s'", veth2);
-			goto out;
+			goto out_delete;
 		}
 	}
 
+	if (lxc_bridge_attach(bridge, veth1)) {
+		lxc_log_error("failed to attach '%s' to the bridge '%s'",
+			      veth1, bridge);
+		goto out_delete;
+	}
+
+	ifindex = if_nametoindex(veth2);
+	if (!ifindex) {
+		lxc_log_error("failed to retrieve the index for %s", veth2);
+		goto out_delete;
+	}
+
+	if (!asprintf(&strindex, "%d", ifindex)) {
+		lxc_log_syserror("failed to allocate memory");
+		goto out_delete;
+	}
+
+	if (write_info(path, "ifindex", strindex)) {
+		lxc_log_error("failed to write interface index to %s", path);
+		goto out_delete;
+	}
+
 	if (!read_info(path, "up", strindex, sizeof(strindex))) {
 		if (lxc_device_up(veth1)) {
 			lxc_log_error("failed to set %s up", veth1);
-			goto out;
+			goto out_delete;
 		}
 	}
 
@@ -1440,6 +1446,10 @@ out:
 	free(veth1);
 	free(veth2);
 	return ret;
+
+out_delete:
+	lxc_device_delete(veth1);
+	goto out;
 } 
 static int instanciate_macvlan(const char *directory, const char *file, pid_t pid)
 {
@@ -1458,8 +1468,9 @@ static int instanciate_macvlan(const cha
 		goto out;
 	}
 
-	if (lxc_configure_macvlan(link, peer)) {
-		lxc_log_error("failed to create macvlan interface %s", peer);
+	if (lxc_macvlan_create(link, peer)) {
+		lxc_log_error("failed to create macvlan interface '%s' on '%s'",
+			      peer, link);
 		goto out;
 	}
 



