Skip to content

Commit 2bab666

Browse files
committed
ch: Activate the host side of the ethernet tap device
When using an interface type='ethernet' the device can be given a host side configuration that can be activated before starting cloud-hypervisor (similar to how the network is activated for qemu).
1 parent f713dba commit 2bab666

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

src/ch/ch_interface.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,78 @@ chInterfaceBridgeConnect(virDomainDefPtr def,
254254

255255
return ret;
256256
}
257+
258+
/**
259+
* chInterfaceStartDevice:
260+
* @net: net device to start
261+
*
262+
* Based upon the type of device provided, perform the appropriate
263+
* work to completely activate the device and make it reachable from
264+
* the rest of the network.
265+
*/
266+
static int
267+
chInterfaceStartDevice(virDomainNetDefPtr net)
268+
{
269+
virDomainNetType actualType = virDomainNetGetActualType(net);
270+
271+
switch (actualType) {
272+
case VIR_DOMAIN_NET_TYPE_BRIDGE:
273+
case VIR_DOMAIN_NET_TYPE_NETWORK:
274+
if (virDomainNetGetActualBridgeMACTableManager(net)
275+
== VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_LIBVIRT) {
276+
/* libvirt is managing the FDB of the bridge this device
277+
* is attaching to, so we have turned off learning and
278+
* unicast_flood on the device to prevent the kernel from
279+
* adding any FDB entries for it. This means we need to
280+
* add an fdb entry ourselves, using the MAC address from
281+
* the interface config.
282+
*/
283+
if (virNetDevBridgeFDBAdd(&net->mac, net->ifname,
284+
VIR_NETDEVBRIDGE_FDB_FLAG_MASTER |
285+
VIR_NETDEVBRIDGE_FDB_FLAG_TEMP) < 0)
286+
return -1;
287+
}
288+
break;
289+
290+
case VIR_DOMAIN_NET_TYPE_DIRECT:
291+
break;
292+
293+
case VIR_DOMAIN_NET_TYPE_ETHERNET:
294+
if (virNetDevIPInfoAddToDev(net->ifname, &net->hostIP) < 0)
295+
return -1;
296+
297+
break;
298+
299+
case VIR_DOMAIN_NET_TYPE_USER:
300+
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
301+
case VIR_DOMAIN_NET_TYPE_SERVER:
302+
case VIR_DOMAIN_NET_TYPE_CLIENT:
303+
case VIR_DOMAIN_NET_TYPE_MCAST:
304+
case VIR_DOMAIN_NET_TYPE_UDP:
305+
case VIR_DOMAIN_NET_TYPE_INTERNAL:
306+
case VIR_DOMAIN_NET_TYPE_HOSTDEV:
307+
case VIR_DOMAIN_NET_TYPE_LAST:
308+
/* these types all require no action */
309+
break;
310+
}
311+
312+
return 0;
313+
}
314+
315+
/**
316+
* chInterfaceStartDevices:
317+
* @def: domain definition
318+
*
319+
* Set all ifaces associated with this domain to the online state.
320+
*/
321+
int
322+
chInterfaceStartDevices(virDomainDefPtr def)
323+
{
324+
size_t i;
325+
326+
for (i = 0; i < def->nnets; i++) {
327+
if (chInterfaceStartDevice(def->nets[i]) < 0)
328+
return -1;
329+
}
330+
return 0;
331+
}

src/ch/ch_interface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ int chInterfaceBridgeConnect(virDomainDefPtr def,
1313
virDomainNetDefPtr net,
1414
int *tapfd,
1515
size_t *tapfdSize);
16+
17+
int chInterfaceStartDevices(virDomainDefPtr def);

src/ch/ch_process.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@ int virCHProcessStart(virCHDriverPtr driver,
663663
if (chProcessNetworkPrepareDevices(driver, vm) < 0)
664664
goto cleanup;
665665

666+
/* Bring up netdevs before starting CPUs */
667+
if (chInterfaceStartDevices(vm->def) < 0)
668+
return -1;
669+
666670
VIR_DEBUG("Preparing host devices");
667671
if (chHostdevPrepareDomainDevices(driver, vm->def,
668672
VIR_HOSTDEV_COLD_BOOT) < 0)

0 commit comments

Comments
 (0)