On 6/12/26 07:14, Radosław Śmigielski via Devel wrote:
From: Radoslaw Smigielski <rsmigiel@redhat.com>
LXC domains did not assign device aliases to network interface devices during domain startup.
This change assigns aliases in the format 'net0', 'net1', etc. to all network interfaces during domain startup, following the same pattern used for console and filesystem devices.
Before this patch, virsh dumpxml showed network interfaces without aliases:
<interface type='network'> <mac address='52:54:00:12:34:56'/> <source network='default'/> </interface>
After this patch, network interfaces have auto-generated aliases:
<interface type='network'> <mac address='52:54:00:12:34:56'/> <source network='default'/> <alias name='net0'/> </interface>
This ensures all LXC device types (consoles, filesystems, and network interfaces) have consistent alias assigned.
Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com> --- src/lxc/lxc_process.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index aae9fcc9dfd1..f93f3f05c394 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -1356,6 +1356,12 @@ int virLXCProcessStart(virLXCDriver * driver, vm->def->fss[i]->info.alias = g_strdup_printf("fs%zu", i); }
+ VIR_DEBUG("Setting up network interface aliases"); + for (i = 0; i < vm->def->nnets; i++) { + g_free(vm->def->nets[i]->info.alias);
Again, no need to free this.
+ vm->def->nets[i]->info.alias = g_strdup_printf("net%zu", i); + } + VIR_DEBUG("Setting up Interfaces"); if (virLXCProcessSetupInterfaces(driver, vm->def, &veths) < 0) goto cleanup;
This covers domain startup, but there's one more case to cover: device hotplug. For LXC domains it is possible to attach an <interface/> on the fly, see lxcDomainAttachDeviceLive(). Now, attaching and detaching interfaces complicates alias generation a bit, because we're not starting with an empty canvas. For instance, I can start a domain with one interface and it'd get "net0" alias. Then hotplug another one (say, it'd get "net1" alias) and detach "net0" subsequently. At this point we have vm->def->nnets = 1, and hotplugging another interface must NOT assign "net1" alias because it is already used. But we can re-use what other drivers have, say QEMU driver. If you take a look at how aliases are assigned there, you'd find qemuAssignDeviceNetAlias() which iterates over array of existing interfaces and finds next unused index. We can use the same approach in LXC and then just call the function from lxcDomainAttachDeviceNetLive() - the line just after call to virDomainActualNetDefValidate() looks like a good fit. Michal