[libvirt] virDomainNetGetActualBridgeName doesn't return the actual bridge

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? What is the best way to determine the bridge the interface is connected to? Hendrik Schwartke

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?
What is the best way to determine the bridge the interface is connected to?
For the virtual network case, you could do it in a round about way by getting the network name from the domain <interface> block, then parsing the bridge name from the equivalent of virsh net-dumpxml <netname> But if we are providing an API like that it should probably work for virtual networks (but then again I don't know the specific use case that API was meant to address so it may be conceptually wrong). - Cole

I'm working on a patch to change the network an interface is associated with while the guest is running. So one part of this is of course changing the bridge the interface is actually connected to. I already considered the way your described (from domain to net to bridge) but I'm wondering if that really the right way to do it. I'm not really familiar with the code but virDomainNetGetActualBridgeName seems to do exactly what I'm searching for: const char * virDomainNetGetActualBridgeName(virDomainNetDefPtr iface) { if (iface->type == VIR_DOMAIN_NET_TYPE_BRIDGE) return iface->data.bridge.brname; if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK) return NULL; if (!iface->data.network.actual) return NULL; return iface->data.network.actual->data.bridge.brname; } It simply returns brname from data.network.actual if the struct exists. But it doesn't exist. Is this indented or is the code to create this structure simply missing? On 31.01.2012 17:00, Cole Robinson wrote:
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?
What is the best way to determine the bridge the interface is connected to?
For the virtual network case, you could do it in a round about way by getting the network name from the domain<interface> block, then parsing the bridge name from the equivalent of virsh net-dumpxml<netname>
But if we are providing an API like that it should probably work for virtual networks (but then again I don't know the specific use case that API was meant to address so it may be conceptually wrong).
- Cole

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).

On 01/31/2012 11:55 AM, Laine Stump wrote:
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?
Heh. I just made the connection that you were also doing a patch to hot-switch the bridge that a guest is connected to, so you actually *do* want the bridge (as well as the tap device). In that case, the 2nd part of my earlier response applies.
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).
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (3)
-
Cole Robinson
-
Hendrik Schwartke
-
Laine Stump