From: Pavel Hrdina Date: Tue, 27 Aug 2024 17:51:35 +0000 (+0200) Subject: ch: interface: correctly update nicindexes X-Git-Tag: v10.7.0-rc2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a44f786252d3de285605707fe8740eb89ba6699;p=thirdparty%2Flibvirt.git ch: interface: correctly update nicindexes Originally nicindexes were updated only for VIR_DOMAIN_NET_TYPE_BRIDGE and VIR_DOMAIN_NET_TYPE_DIRECT. The mentioned commit adds support for NAT network mode and changes the code to update nicindexes for VIR_DOMAIN_NET_TYPE_ETHERNET and VIR_DOMAIN_NET_TYPE_NETWORK as well. It doesn't work as intended and after the change nicindexes are updated only for VIR_DOMAIN_NET_TYPE_ETHERNET and VIR_DOMAIN_NET_TYPE_NETWORK. Fixes: aa642090738eb276f7bd70dea97d3a4fd03d59e3 Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- diff --git a/src/ch/ch_interface.c b/src/ch/ch_interface.c index 47b02bc322..87a95cde53 100644 --- a/src/ch/ch_interface.c +++ b/src/ch/ch_interface.c @@ -34,6 +34,26 @@ VIR_LOG_INIT("ch.ch_interface"); + +static int +virCHInterfaceUpdateNicindexes(virDomainNetDef *net, + int **nicindexes, + size_t *nnicindexes) +{ + int nicindex = 0; + + if (!nicindexes || !nnicindexes || !net->ifname) + return 0; + + if (virNetDevGetIndex(net->ifname, &nicindex) < 0) + return -1; + + VIR_APPEND_ELEMENT(*nicindexes, *nnicindexes, nicindex); + + return 0; +} + + /** * virCHConnetNetworkInterfaces: * @driver: pointer to ch driver object @@ -78,6 +98,8 @@ virCHConnetNetworkInterfaces(virCHDriver *driver, net->driver.virtio.queues) < 0) return -1; + if (virCHInterfaceUpdateNicindexes(net, nicindexes, nnicindexes) < 0) + return -1; break; case VIR_DOMAIN_NET_TYPE_NETWORK: if (virDomainInterfaceBridgeConnect(vm, net, @@ -88,9 +110,15 @@ virCHConnetNetworkInterfaces(virCHDriver *driver, false, NULL) < 0) return -1; + + if (virCHInterfaceUpdateNicindexes(net, nicindexes, nnicindexes) < 0) + return -1; break; case VIR_DOMAIN_NET_TYPE_BRIDGE: case VIR_DOMAIN_NET_TYPE_DIRECT: + if (virCHInterfaceUpdateNicindexes(net, nicindexes, nnicindexes) < 0) + return -1; + break; case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_CLIENT: @@ -109,19 +137,5 @@ virCHConnetNetworkInterfaces(virCHDriver *driver, return -1; } - if (actualType == VIR_DOMAIN_NET_TYPE_ETHERNET || - actualType == VIR_DOMAIN_NET_TYPE_NETWORK || - actualType == VIR_DOMAIN_NET_TYPE_BRIDGE || - actualType == VIR_DOMAIN_NET_TYPE_DIRECT) { - if (nicindexes && nnicindexes && net->ifname) { - int nicindex = 0; - - if (virNetDevGetIndex(net->ifname, &nicindex) < 0) - return -1; - - VIR_APPEND_ELEMENT(*nicindexes, *nnicindexes, nicindex); - } - } - return 0; }