The network functions are too encapsulated and do not allow
flexibility. Export all these api and prepare the changes for the
next patch to set the mtu.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
---
 src/lxc/lxc_conf.c |   22 +++++++++++-----------
 src/lxc/network.c  |   44 ++++++++++++++++++++++----------------------
 src/lxc/network.h  |   42 ++++++++++++++++++++++--------------------
 3 files changed, 55 insertions(+), 53 deletions(-)

Index: lxc/src/lxc/network.h
===================================================================
--- lxc.orig/src/lxc/network.h
+++ lxc/src/lxc/network.h
@@ -42,90 +42,92 @@ extern int lxc_convert_mac(char *macaddr
 /*
  * Move a device between namespaces
  */
-extern int device_move(const char *name, pid_t pid);
+extern int lxc_device_move(const char *name, pid_t pid);
 
 /*
  * Delete a network device
  */
-extern int device_delete(const char *name);
+extern int lxc_device_delete(const char *name);
 
 /*
  * Set the device network up
  */
-extern int device_up(const char *name);
+extern int lxc_device_up(const char *name);
 
 /*
  * Set the device network down
  */
-extern int device_down(const char *name);
+extern int lxc_device_down(const char *name);
 
 /*
  * Change the device name
  */
-extern int device_rename(const char *oldname, const char *newname);
+extern int lxc_device_rename(const char *oldname, const char *newname);
 
 /*
  * Change the mtu size for the specified device
  */
-extern int device_set_mtu(const char *name, int mtu);
+extern int lxc_device_set_mtu(const char *name, int mtu);
 
 /*
  * Create a veth network device
  */
-extern int veth_create(const char *name1, const char *name2);
+extern int lxc_veth_create(const char *name1, const char *name2);
 
 /* 
  * Create a macvlan network device
  */
-extern int macvlan_create(const char *master, const char *name);
+extern int lxc_macvlan_create(const char *master, const char *name);
 
 /*
  * Activate forwarding
  */
-extern int ip_forward_on(const char *name, int family);
+extern int lxc_ip_forward_on(const char *name, int family);
 
 /*
  * Disable forwarding
  */
-extern int ip_forward_off(const char *name, int family);
+extern int lxc_ip_forward_off(const char *name, int family);
 
 /*
  * Set ip address
  */
-extern int ip_addr_add(const char *ifname, const char *addr, 
-		       int prefix, const char *bcast);
+extern int lxc_ip_addr_add(const char *ifname, const char *addr,
+			   int prefix, const char *bcast);
 
-extern int ip6_addr_add(const char *ifname, const char *addr, 
-			int prefix, const char *bcast);
+extern int lxc_ip6_addr_add(const char *ifname, const char *addr,
+			    int prefix, const char *bcast);
 
 /*
  * Attach an interface to the bridge
  */
-extern int bridge_attach(const char *bridge, const char *ifname);
+extern int lxc_bridge_attach(const char *bridge, const char *ifname);
 
 /*
  * Detach an interface from the bridge
  */
-extern int bridge_detach(const char *bridge, const char *ifname);
+extern int lxc_bridge_detach(const char *bridge, const char *ifname);
 
 /* 
  * Create default gateway
  */
-extern int route_create_default(const char *addr, const char *ifname, int gateway);
+extern int lxc_route_create_default(const char *addr, const char *ifname,
+				    int gateway);
 
 /*
  * Delete default gateway
  */
-extern int route_delete_default(const char *addr, const char *ifname, int gateway);
+extern int lxc_route_delete_default(const char *addr, const char *ifname,
+				    int gateway);
 
 /*
  * Activate neighbor proxying
  */
-extern int neigh_proxy_on(const char *name, int family);
+extern int lxc_neigh_proxy_on(const char *name, int family);
 
 /*
  * Disable neighbor proxying
  */
-extern int neigh_proxy_off(const char *name, int family);
+extern int lxc_neigh_proxy_off(const char *name, int family);
 
 #endif
Index: lxc/src/lxc/network.c
===================================================================
--- lxc.orig/src/lxc/network.c
+++ lxc/src/lxc/network.c
@@ -81,7 +81,7 @@ struct ip_req {
 	struct ifaddrmsg ifa;
 };
 
-int device_move(const char *name, pid_t pid)
+int lxc_device_move(const char *name, pid_t pid)
 {
 	struct nl_handler nlh;
 	struct nlmsg *nlmsg = NULL;
@@ -126,7 +126,7 @@ out:
 	return err;
 }
 
-extern int device_delete(const char *name)
+extern int lxc_device_delete(const char *name)
 {
 	struct nl_handler nlh;
 	struct nlmsg *nlmsg = NULL, *answer = NULL;
@@ -220,7 +220,7 @@ out:
 	return err;
 }
 
-extern int device_set_mtu(const char *name, int mtu)
+extern int lxc_device_set_mtu(const char *name, int mtu)
 {
 	struct nl_handler nlh;
 	struct nlmsg *nlmsg = NULL, *answer = NULL;
@@ -268,17 +268,17 @@ out:
 	return err;
 }
 
-int device_up(const char *name)
+int lxc_device_up(const char *name)
 {
 	return device_set_flag(name, IFF_UP);
 }
 
-int device_down(const char *name)
+int lxc_device_down(const char *name)
 {
 	return device_set_flag(name, 0);
 }
 
-int device_rename(const char *oldname, const char *newname)
+int lxc_device_rename(const char *oldname, const char *newname)
 {
 	struct nl_handler nlh;
 	struct nlmsg *nlmsg = NULL, *answer = NULL;
@@ -329,7 +329,7 @@ out:
 	return err;
 }
 
-int veth_create(const char *name1, const char *name2)
+int lxc_veth_create(const char *name1, const char *name2)
 {
 	struct nl_handler nlh;
 	struct nlmsg *nlmsg = NULL, *answer = NULL;
@@ -403,7 +403,7 @@ out:
 	return err;
 }
 
-int macvlan_create(const char *master, const char *name)
+int lxc_macvlan_create(const char *master, const char *name)
 {
 	struct nl_handler nlh;
 	struct nlmsg *nlmsg = NULL, *answer = NULL;
@@ -495,12 +495,12 @@ static int ip_forward_set(const char *if
 	return proc_sys_net_write(path, flag?"1":"0");
 }
 
-int ip_forward_on(const char *ifname, int family)
+int lxc_ip_forward_on(const char *ifname, int family)
 {
 	return ip_forward_set(ifname, family, 1);
 }
 
-int ip_forward_off(const char *ifname, int family)
+int lxc_ip_forward_off(const char *ifname, int family)
 {
 	return ip_forward_set(ifname, family, 0);
 }
@@ -519,12 +519,12 @@ static int neigh_proxy_set(const char *i
 	return proc_sys_net_write(path, flag?"1":"0");
 }
 
-int neigh_proxy_on(const char *name, int family)
+int lxc_neigh_proxy_on(const char *name, int family)
 {
 	return neigh_proxy_set(name, family, 1);
 }
 
-int neigh_proxy_off(const char *name, int family)
+int lxc_neigh_proxy_off(const char *name, int family)
 {
 	return neigh_proxy_set(name, family, 0);
 }
@@ -576,8 +576,8 @@ int lxc_convert_mac(char *macaddr, struc
     return 0;
 }
 
-int ip_addr_add(const char *ifname, const char *addr, 
-		int prefix, const char *bcast)
+int lxc_ip_addr_add(const char *ifname, const char *addr,
+		    int prefix, const char *bcast)
 {
 	struct nl_handler nlh;
 	struct in_addr in_addr;
@@ -639,8 +639,8 @@ out:
 	return err;
 }
 
-int ip6_addr_add(const char *ifname, const char *addr, 
-		int prefix, const char *bcast)
+int lxc_ip6_addr_add(const char *ifname, const char *addr,
+		     int prefix, const char *bcast)
 {
 	struct nl_handler nlh;
 	struct in6_addr in6_addr;
@@ -728,12 +728,12 @@ static int bridge_add_del_interface(cons
 	return err;
 }
 
-int bridge_attach(const char *bridge, const char *ifname)
+int lxc_bridge_attach(const char *bridge, const char *ifname)
 {
 	return bridge_add_del_interface(bridge, ifname, 0);
 }
 
-int bridge_detach(const char *bridge, const char *ifname)
+int lxc_bridge_detach(const char *bridge, const char *ifname)
 {
 	return bridge_add_del_interface(bridge, ifname, 1);
 }
@@ -741,13 +741,13 @@ int bridge_detach(const char *bridge, co
 int lxc_configure_veth(const char *veth1, const char *veth2, const char *bridge)
 {
 	int err = -1;
-	if (veth_create(veth1, veth2)) {
+	if (lxc_veth_create(veth1, veth2)) {
 		fprintf(stderr, "failed to create veth interfaces %s/%s\n",
 			veth1, veth2);
 		return -1;
 	}
 
-	if (bridge_attach(bridge, veth1)) {
+	if (lxc_bridge_attach(bridge, veth1)) {
 		fprintf(stderr, "failed to attach %s to %s\n", 
 			veth1, bridge);
 		goto err;
@@ -757,13 +757,13 @@ int lxc_configure_veth(const char *veth1
 out:
 	return err;
 err:
-	device_delete(veth1);
+	lxc_device_delete(veth1);
 	goto out;
 }
 
 int lxc_configure_macvlan(const char *link, const char *peer)
 {
-	if (macvlan_create(link, peer)) {
+	if (lxc_macvlan_create(link, peer)) {
 		fprintf(stderr, "failed to create %s", peer);
 		return -1;
 	}
Index: lxc/src/lxc/lxc_conf.c
===================================================================
--- lxc.orig/src/lxc/lxc_conf.c
+++ lxc/src/lxc/lxc_conf.c
@@ -1093,7 +1093,7 @@ static int setup_ipv4_addr_cb(void *buff
 	if (prefix)
 		p = atoi(prefix);
 	
-	if (ip_addr_add(ifname, addr, p, bcast)) {
+	if (lxc_ip_addr_add(ifname, addr, p, bcast)) {
 		lxc_log_error("failed to set %s to addr %s/%d %s", ifname,
 			      addr, p, bcast?bcast:"");
 		return -1;
@@ -1127,7 +1127,7 @@ static int setup_ipv6_addr_cb(void *buff
 	if (prefix)
 		p = atoi(prefix);
 	
-	if (ip6_addr_add(ifname, addr, p, bcast)) {
+	if (lxc_ip6_addr_add(ifname, addr, p, bcast)) {
 		lxc_log_error("failed to set %s to addr %s/%d %s", ifname,
 			      addr, p, bcast?bcast:"");
 		return -1;
@@ -1211,7 +1211,7 @@ static int setup_network_cb(const char *
 	ifindex = atoi(strindex);
 	if (!ifindex) {
 		if (!read_info(path, "up", strindex, sizeof(strindex)))
-		    if (device_up("lo")) {
+		    if (lxc_device_up("lo")) {
 			    lxc_log_error("failed to set the loopback up");
 			    return -1;
 		    }
@@ -1225,7 +1225,7 @@ static int setup_network_cb(const char *
 	}
 	
 	if (!read_info(path, "name", newname, sizeof(newname))) {
-		if (device_rename(ifname, newname)) {
+		if (lxc_device_rename(ifname, newname)) {
 			lxc_log_error("failed to rename %s->%s", 
 				      ifname, newname);
 			return -1;
@@ -1254,13 +1254,13 @@ static int setup_network_cb(const char *
 	}
 
 	if (!read_info(path, "up", strindex, sizeof(strindex))) {
-		if (device_up(current_ifname)) {
+		if (lxc_device_up(current_ifname)) {
 			lxc_log_error("failed to set '%s' up", current_ifname);
 			return -1;
 		}
 
 		/* the network is up, make the loopback up too */
-		if (device_up("lo")) {
+		if (lxc_device_up("lo")) {
 			lxc_log_error("failed to set the loopback up");
 			return -1;
 		}
@@ -1415,19 +1415,19 @@ static int instanciate_veth(const char *
 			goto out;
 		}
 
-		if (device_set_mtu(veth1, mtu)) {
+		if (lxc_device_set_mtu(veth1, mtu)) {
 			lxc_log_error("failed to set mtu for '%s'", veth1);
 			goto out;
 		}
 
-		if (device_set_mtu(veth2, mtu)) {
+		if (lxc_device_set_mtu(veth2, mtu)) {
 			lxc_log_error("failed to set mtu for '%s'", veth2);
 			goto out;
 		}
 	}
 
 	if (!read_info(path, "up", strindex, sizeof(strindex))) {
-		if (device_up(veth1)) {
+		if (lxc_device_up(veth1)) {
 			lxc_log_error("failed to set %s up", veth1);
 			goto out;
 		}
@@ -1590,7 +1590,7 @@ static int move_netdev_cb(const char *na
 		return -1;
 	}
 	
-	if (device_move(ifname, *pid)) {
+	if (lxc_device_move(ifname, *pid)) {
 		lxc_log_error("failed to move %s to %d", ifname, *pid);
 		return -1;
 	}
@@ -1653,7 +1653,7 @@ static int delete_netdev_cb(const char *
 
 	/* do not delete a physical network device */
 	if (strncmp("phys", file, strlen("phys")))
-		if (device_delete(ifname)) {
+		if (lxc_device_delete(ifname)) {
 			lxc_log_error("failed to remove the netdev %s", ifname);
 		}
 



