@@ -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+ }
0 commit comments