[PATCH 0/2] src: Use device alias when ifname is unset in virDomainInterfaceAddresses()
*** BLURB HERE *** Michal Prívozník (2): libvirt-domain: Fix documentation of virDomainInterfaceAddresses() src: Use device alias when ifname is unset in virDomainInterfaceAddresses() src/conf/domain_conf.c | 16 ++++++++++++++-- src/libvirt-domain.c | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) -- 2.52.0
From: Michal Privoznik <mprivozn@redhat.com> Ever since of v1.2.14-rc1~105 the hwaddr member of _virDomainInterface struct can be NULL. And this is documented inside the struct. But then the public API documents it can never be NULL which is obviously wrong. Fix the public API documentation. Fixes: 3640245db7d72bf8e05df726587625a6328c895e Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt-domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 74c70a0a43..a278c4679d 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -12881,7 +12881,7 @@ virDomainFSInfoFree(virDomainFSInfoPtr info) * might be unset (e.g. VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP does not * set IP address prefix as ARP table does not have any notion of that). * - * @ifaces->name and @ifaces->hwaddr are never NULL. + * @ifaces->name is never NULL, and @ifaces->hwaddr may be NULL. * * The caller *must* free @ifaces when no longer needed. Usual use case * looks like this: -- 2.52.0
From: Michal Privoznik <mprivozn@redhat.com> The virDomainInterfaceAddresses() API returns an array of _virDomainInterface structs which then describe IP addresses associated with given domain. The struct contains 'name' member which is documented deliberately vaguely: "interface name". This is because depending on the source of truth used (controlled by 'source' argument) the name can be wildly different from the one in domain XML. Now, in case of source = VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP, the host's ARP table is parsed and matching interfaces are found by comparing MAC addresses. If it's a match then the 'name' is set to net->ifname (corresponds to /interface/target/@dev). But that is not always set and sometimes may be NULL (e.g. for hostdevs, usernet). We can't change the API (like we did for hwaddr in v1.2.14-rc1~105) because this is already released. So the next best thing to do is to put the interface alias in there. To be on a safe side, do the same change to the VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE case. Resolves: https://issues.redhat.com/browse/RHEL-141496 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 16 ++++++++++++++-- src/libvirt-domain.c | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d00a43e969..8b26de674e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15598,6 +15598,12 @@ virDomainNetDHCPInterfaces(virDomainDef *def, goto error; if (n_leases) { + const char *ifname = def->nets[i]->ifname; + + if (!ifname) { + ifname = def->nets[i]->info.alias; + } + ifaces_ret = g_renew(virDomainInterfacePtr, ifaces_ret, ifaces_count + 1); ifaces_ret[ifaces_count] = g_new0(virDomainInterface, 1); iface = ifaces_ret[ifaces_count]; @@ -15606,7 +15612,7 @@ virDomainNetDHCPInterfaces(virDomainDef *def, /* Assuming each lease corresponds to a separate IP */ iface->naddrs = n_leases; iface->addrs = g_new0(virDomainIPAddress, iface->naddrs); - iface->name = g_strdup(def->nets[i]->ifname); + iface->name = g_strdup(ifname); iface->hwaddr = g_strdup(macaddr); } @@ -15660,9 +15666,15 @@ virDomainNetARPInterfaces(virDomainDef *def, virArpTableEntry entry = table->t[j]; if (STREQ(entry.mac, macaddr)) { + const char *ifname = def->nets[i]->ifname; + + if (!ifname) { + ifname = def->nets[i]->info.alias; + } + iface = g_new0(virDomainInterface, 1); - iface->name = g_strdup(def->nets[i]->ifname); + iface->name = g_strdup(ifname); iface->hwaddr = g_strdup(macaddr); diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index a278c4679d..a1f6efde20 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -12880,6 +12880,8 @@ virDomainFSInfoFree(virDomainFSInfoPtr info) * Note that for some @source values some pieces of returned @ifaces * might be unset (e.g. VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP does not * set IP address prefix as ARP table does not have any notion of that). + * Moreover, it may happen that the interface doesn't have a name. In + * that case, @ifaces->name is set to the interface's device alias. * * @ifaces->name is never NULL, and @ifaces->hwaddr may be NULL. * -- 2.52.0
On a Tuesday in 2026, Michal Privoznik via Devel wrote:
*** BLURB HERE ***
Michal Prívozník (2): libvirt-domain: Fix documentation of virDomainInterfaceAddresses() src: Use device alias when ifname is unset in virDomainInterfaceAddresses()
src/conf/domain_conf.c | 16 ++++++++++++++-- src/libvirt-domain.c | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko -
Michal Privoznik