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: aa64209073
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Pavel Hrdina 2024-08-27 19:51:35 +02:00
parent 4d8ebbfee8
commit 8a44f78625

View File

@ -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;
}