mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
LXC from native: convert macvlan network configuration
This commit is contained in:
parent
f01fe54e75
commit
8e45b88772
@ -332,9 +332,11 @@ static virDomainNetDefPtr
|
|||||||
lxcCreateNetDef(const char *type,
|
lxcCreateNetDef(const char *type,
|
||||||
const char *link,
|
const char *link,
|
||||||
const char *mac,
|
const char *mac,
|
||||||
const char *flag)
|
const char *flag,
|
||||||
|
const char *macvlanmode)
|
||||||
{
|
{
|
||||||
virDomainNetDefPtr net = NULL;
|
virDomainNetDefPtr net = NULL;
|
||||||
|
virMacAddr macAddr;
|
||||||
|
|
||||||
if (VIR_ALLOC(net) < 0)
|
if (VIR_ALLOC(net) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -346,9 +348,11 @@ lxcCreateNetDef(const char *type,
|
|||||||
net->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN;
|
net->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STREQ(type, "veth")) {
|
|
||||||
virMacAddr macAddr;
|
|
||||||
|
|
||||||
|
if (mac && virMacAddrParse(mac, &macAddr) == 0)
|
||||||
|
net->mac = macAddr;
|
||||||
|
|
||||||
|
if (STREQ(type, "veth")) {
|
||||||
if (!link)
|
if (!link)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -357,9 +361,20 @@ lxcCreateNetDef(const char *type,
|
|||||||
if (VIR_STRDUP(net->data.bridge.brname, link) < 0)
|
if (VIR_STRDUP(net->data.bridge.brname, link) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (mac && virMacAddrParse(mac, &macAddr) == 0)
|
} else if (STREQ(type, "macvlan")) {
|
||||||
net->mac = macAddr;
|
net->type = VIR_DOMAIN_NET_TYPE_DIRECT;
|
||||||
|
|
||||||
|
if (!link || VIR_STRDUP(net->data.direct.linkdev, link) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (!macvlanmode || STREQ(macvlanmode, "private"))
|
||||||
|
net->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_PRIVATE;
|
||||||
|
else if (STREQ(macvlanmode, "vepa"))
|
||||||
|
net->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_VEPA;
|
||||||
|
else if (STREQ(macvlanmode, "bridge"))
|
||||||
|
net->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_BRIDGE;
|
||||||
|
else
|
||||||
|
VIR_WARN("Unknown macvlan type: %s", macvlanmode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return net;
|
return net;
|
||||||
@ -394,7 +409,8 @@ lxcAddNetworkDefinition(virDomainDefPtr def,
|
|||||||
const char *type,
|
const char *type,
|
||||||
const char *link,
|
const char *link,
|
||||||
const char *mac,
|
const char *mac,
|
||||||
const char *flag)
|
const char *flag,
|
||||||
|
const char *macvlanmode)
|
||||||
{
|
{
|
||||||
virDomainNetDefPtr net = NULL;
|
virDomainNetDefPtr net = NULL;
|
||||||
virDomainHostdevDefPtr hostdev = NULL;
|
virDomainHostdevDefPtr hostdev = NULL;
|
||||||
@ -414,7 +430,7 @@ lxcAddNetworkDefinition(virDomainDefPtr def,
|
|||||||
goto error;
|
goto error;
|
||||||
def->hostdevs[def->nhostdevs - 1] = hostdev;
|
def->hostdevs[def->nhostdevs - 1] = hostdev;
|
||||||
} else {
|
} else {
|
||||||
if (!(net = lxcCreateNetDef(type, link, mac, flag)))
|
if (!(net = lxcCreateNetDef(type, link, mac, flag, macvlanmode)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0)
|
if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0)
|
||||||
@ -436,6 +452,7 @@ typedef struct {
|
|||||||
char *link;
|
char *link;
|
||||||
char *mac;
|
char *mac;
|
||||||
char *flag;
|
char *flag;
|
||||||
|
char *macvlanmode;
|
||||||
bool privnet;
|
bool privnet;
|
||||||
size_t networks;
|
size_t networks;
|
||||||
} lxcNetworkParseData;
|
} lxcNetworkParseData;
|
||||||
@ -450,7 +467,9 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
|
|||||||
/* Store the previous NIC */
|
/* Store the previous NIC */
|
||||||
status = lxcAddNetworkDefinition(parseData->def, parseData->type,
|
status = lxcAddNetworkDefinition(parseData->def, parseData->type,
|
||||||
parseData->link, parseData->mac,
|
parseData->link, parseData->mac,
|
||||||
parseData->flag);
|
parseData->flag,
|
||||||
|
parseData->macvlanmode);
|
||||||
|
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
return -1;
|
return -1;
|
||||||
else if (status > 0)
|
else if (status > 0)
|
||||||
@ -463,6 +482,7 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
|
|||||||
parseData->link = NULL;
|
parseData->link = NULL;
|
||||||
parseData->mac = NULL;
|
parseData->mac = NULL;
|
||||||
parseData->flag = NULL;
|
parseData->flag = NULL;
|
||||||
|
parseData->macvlanmode = NULL;
|
||||||
|
|
||||||
/* Keep the new value */
|
/* Keep the new value */
|
||||||
parseData->type = value->str;
|
parseData->type = value->str;
|
||||||
@ -473,6 +493,12 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
|
|||||||
parseData->mac = value->str;
|
parseData->mac = value->str;
|
||||||
else if (STREQ(name, "lxc.network.flags"))
|
else if (STREQ(name, "lxc.network.flags"))
|
||||||
parseData->flag = value->str;
|
parseData->flag = value->str;
|
||||||
|
else if (STREQ(name, "lxc.network.macvlan.mode"))
|
||||||
|
parseData->macvlanmode = value->str;
|
||||||
|
else if (STRPREFIX(name, "lxc.network"))
|
||||||
|
VIR_WARN("Unhandled network property: %s = %s",
|
||||||
|
name,
|
||||||
|
value->str);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -481,13 +507,14 @@ static int
|
|||||||
lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties)
|
lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
lxcNetworkParseData data = {def, NULL, NULL, NULL, NULL, true, 0};
|
lxcNetworkParseData data = {def, NULL, NULL, NULL, NULL, NULL, true, 0};
|
||||||
|
|
||||||
virConfWalk(properties, lxcNetworkWalkCallback, &data);
|
virConfWalk(properties, lxcNetworkWalkCallback, &data);
|
||||||
|
|
||||||
/* Add the last network definition found */
|
/* Add the last network definition found */
|
||||||
status = lxcAddNetworkDefinition(def, data.type, data.link,
|
status = lxcAddNetworkDefinition(def, data.type, data.link,
|
||||||
data.mac, data.flag);
|
data.mac, data.flag,
|
||||||
|
data.macvlanmode);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
return -1;
|
return -1;
|
||||||
else if (status > 0)
|
else if (status > 0)
|
||||||
|
13
tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.config
Normal file
13
tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.config
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Template used to create this container: opensuse
|
||||||
|
# Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef
|
||||||
|
|
||||||
|
lxc.network.type = macvlan
|
||||||
|
lxc.network.flags = up
|
||||||
|
lxc.network.link = eth0
|
||||||
|
lxc.network.hwaddr = 02:00:15:8f:05:c1
|
||||||
|
lxc.network.macvlan.mode = vepa
|
||||||
|
|
||||||
|
#remove next line if host DNS configuration should not be available to container
|
||||||
|
lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
|
||||||
|
lxc.utsname = migrate_test
|
||||||
|
lxc.autodev=1
|
26
tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml
Normal file
26
tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<domain type='lxc'>
|
||||||
|
<name>migrate_test</name>
|
||||||
|
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||||
|
<memory unit='KiB'>65536</memory>
|
||||||
|
<currentMemory unit='KiB'>0</currentMemory>
|
||||||
|
<vcpu placement='static' current='0'>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type>exe</type>
|
||||||
|
<init>/sbin/init</init>
|
||||||
|
</os>
|
||||||
|
<clock offset='utc'/>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<filesystem type='mount' accessmode='passthrough'>
|
||||||
|
<source dir='/var/lib/lxc/migrate_test/rootfs'/>
|
||||||
|
<target dir='/'/>
|
||||||
|
</filesystem>
|
||||||
|
<interface type='direct'>
|
||||||
|
<mac address='02:00:15:8f:05:c1'/>
|
||||||
|
<source dev='eth0' mode='vepa'/>
|
||||||
|
<link state='up'/>
|
||||||
|
</interface>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
@ -107,6 +107,7 @@ mymain(void)
|
|||||||
DO_TEST("nonetwork", false);
|
DO_TEST("nonetwork", false);
|
||||||
DO_TEST("nonenetwork", false);
|
DO_TEST("nonenetwork", false);
|
||||||
DO_TEST("physnetwork", false);
|
DO_TEST("physnetwork", false);
|
||||||
|
DO_TEST("macvlannetwork", false);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user