check if lxc.netdev.link is set for macvlan

Ensure that lxc.netdev.link is specified for macvlan interfaces,
since it's required.

While at it, simplify logic in instanciate_macvlan():
remove unnecessary-complicating goto statements (we only
need to perform a cleanup in one place)

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
Michael Tokarev 2009-11-20 15:01:31 +01:00 committed by Daniel Lezcano
parent 734915aca1
commit d957ae2d51

View File

@ -893,10 +893,15 @@ out_delete:
lxc_device_delete(veth1); lxc_device_delete(veth1);
goto out; goto out;
} }
static int instanciate_macvlan(struct lxc_netdev *netdev) static int instanciate_macvlan(struct lxc_netdev *netdev)
{ {
char peer[IFNAMSIZ]; char peer[IFNAMSIZ];
int ret = -1;
if (!netdev->link) {
ERROR("no link specified for macvlan netdev");
return -1;
}
snprintf(peer, sizeof(peer), "mcXXXXXX"); snprintf(peer, sizeof(peer), "mcXXXXXX");
@ -910,24 +915,19 @@ static int instanciate_macvlan(struct lxc_netdev *netdev)
if (lxc_macvlan_create(netdev->link, peer)) { if (lxc_macvlan_create(netdev->link, peer)) {
ERROR("failed to create macvlan interface '%s' on '%s'", ERROR("failed to create macvlan interface '%s' on '%s'",
peer, netdev->link); peer, netdev->link);
goto out; return -1;
} }
netdev->ifindex = if_nametoindex(peer); netdev->ifindex = if_nametoindex(peer);
if (!netdev->ifindex) { if (!netdev->ifindex) {
ERROR("failed to retrieve the index for %s", peer); ERROR("failed to retrieve the index for %s", peer);
goto out_delete; lxc_device_delete(peer);
return -1;
} }
DEBUG("instanciated macvlan '%s', index is '%d'", peer, netdev->ifindex); DEBUG("instanciated macvlan '%s', index is '%d'", peer, netdev->ifindex);
ret = 0; return 0;
out:
return ret;
out_delete:
lxc_device_delete(peer);
goto out;
} }
static int instanciate_phys(struct lxc_netdev *netdev) static int instanciate_phys(struct lxc_netdev *netdev)