[libvirt] virDomainNetGetActualBridgeName doesn't return the actual bridge

Laine Stump laine at laine.org
Tue Jan 31 16:55:56 UTC 2012


On 01/30/2012 08:15 AM, Hendrik Schwartke wrote:
> Hi,
>
> calling virDomainNetGetActualBridgeName on a bridge with type 
> VIR_DOMAIN_NET_TYPE_NETWORK seems to return NULL in any case, because 
> iface->data.network.actual is NULL. Is that intented?

Yes, that's how it was intended to work. It has a very narrow purpose, 
only to be used for interfaces that end up being connected to host 
bridges not managed by libvirt (i.e., either the interface type is 
VIR_DOMAIN_NET_TYPE_BRIDGE, or the type is NETWORK, and the network has 
<forward mode='bridge'>). It's an internal API, so that purpose could 
change, but I would need to look and see if that would have any adverse 
side effect.

>
> What is the best way to determine the bridge the interface is 
> connected to?

I'm guessing you're writing the packet sniffing code you asked about the 
other day. Do you really want the bridge device that the guest is 
connecting to? I think the device you actually want to watch is the tap 
device that connects the guest to the bridge. That is in net->ifname 
("net" being the virDomainNetDef containing the configuration for the 
interface); qemu uses that value directly when setting up the guests' 
interfaces.

If you really do need to get the device that the guest tap is connected 
to (which might be a bridge, or might be a physical ethernet, or might 
be ???), where that is depends on the type of interface:

1) for interface "actualType"=VIR_DOMAIN_NET_TYPE_NETWORK, currently you 
would need to call the public API virNetworkGetBridgeName (that requires 
you to first call virNetworkLookupByName).

2) for interface actualType=VIR_DOMAIN_NET_TYPE_DIRECT you would want to 
call virDomainNetGetActualDirectDev() - this gives you a physical 
interface which the guest connects to in one of the mavctap modes.

3) for interface actualType=VIR_DOMAIN_NET_TYPE_BRIDGE you would call 
virDomainNetGetActualBridgeName().

Note that in all cases, I'm talking about using the result of 
virDomainNetGetActualType(net), *not* just looking at net->type. (the 
latter is what's in the config, the former is what is figured out at 
runtime based on the config).

(Still, I'm guessing what you really want is just net->ifname).




More information about the libvir-list mailing list