@Peter Krempa <pkrempa(a)redhat.com> Can you take a look ?
On Mon, Jun 23, 2025 at 12:04 PM Han Han <hhan(a)redhat.com> wrote:
On Mon, Jun 23, 2025 at 5:39 PM Han Han <hhan(a)redhat.com> wrote:
>
>
> On Fri, May 30, 2025 at 8:22 PM Enrique Llorente via Devel <
> devel(a)lists.libvirt.org> wrote:
>
>> This commit introduces a feature enhancement for configuring hostnames in
>> virtual machines (VMs) using DHCP. It adds new options to the "passt"
>> tool
>> to set the hostname and fully qualified domain name (FQDN) for VMs. These
>> map to DHCP option 12 for the hostname and options 81 (IPv4) and 39
>> (IPv6)
>> for the FQDN.
>>
>> The update enables passt to dynamically assign hostnames to DHCP-aware
>> VMs. To achieve this, the commit adds two fields to the passt domain XML
>> backend. These fields allow passt to configure the hostname and FQDN for
>> the virtual machine, ensuring smooth integration with the DHCP protocol.
>>
>> This improvement is particularly valuable in environments where VMs need
>> dynamic hostname configuration, enhancing flexibility and automation in
>> virtualized network setups.
>>
>> libvirt: Integrate passt --hostname --fqdn options
>> Resolves:
https://issues.redhat.com/browse/RHEL-79806
>>
>> Signed-off-by: Enrique Llorente <ellorent(a)redhat.com>
>> ---
>> Compared to v1 this fix the mapping between backend fqdn and hostname
>>
>> docs/formatdomain.rst | 8 +++++---
>> src/conf/domain_conf.c | 10 +++++++++-
>> src/conf/domain_conf.h | 2 ++
>> src/conf/schemas/domaincommon.rng | 6 ++++++
>> src/qemu/qemu_passt.c | 6 ++++++
>> tests/qemuxmlconfdata/net-user-passt.x86_64-7.2.0.xml | 2 +-
>> tests/qemuxmlconfdata/net-user-passt.x86_64-latest.xml | 2 +-
>> tests/qemuxmlconfdata/net-user-passt.xml | 2 +-
>> .../net-vhostuser-passt.x86_64-latest.xml | 2 +-
>> tests/qemuxmlconfdata/net-vhostuser-passt.xml | 2 +-
>> 10 files changed, 33 insertions(+), 9 deletions(-)
>>
>> diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
>> index 8753ee9c23..9c80aa9270 100644
>> --- a/docs/formatdomain.rst
>> +++ b/docs/formatdomain.rst
>> @@ -5372,10 +5372,12 @@ came from the host's IP.
>> There are a few other options that are configurable only for the passt
>> backend. For example, the ``<backend>`` attribute ``logFile`` can be
>> used to tell the passt process for this interface where to write its
>> -message log, and the ``<source>`` attribute ``dev`` can tell it a
>> +message log, the ``<source>`` attribute ``dev`` can tell it a
>> particular host interface to use when deriving the routes given to the
>> -guest for forwarding traffic upstream. Due to the design decisions of
>> -passt, when using SELinux on the host, it is recommended that the log
>> +guest for forwarding traffic upstream and the ``hostname`` and ``fqdn``
>> +will conigure the DHCP option 12 hostname and DHCP option 81 and DHCPv6
>> +option 39 fqdn attribute. Due to the design decisions of passt, when
>> using
>> +SELinux on the host, it is recommended that the log
>> file reside in the runtime directory of the user under which the passt
>> process will run, most probably ``/run/user/$UID`` (where ``$UID`` is
>> the UID of that user), e.g. ``/run/user/1000``. Be aware that libvirt
>> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>> index b3b0bd7329..15143f8fa2 100644
>> --- a/src/conf/domain_conf.c
>> +++ b/src/conf/domain_conf.c
>> @@ -2909,6 +2909,8 @@ virDomainNetDefFree(virDomainNetDef *def)
>> g_free(def->backend.tap);
>> g_free(def->backend.vhost);
>> g_free(def->backend.logFile);
>> + g_free(def->backend.hostname);
>> + g_free(def->backend.fqdn);
>> virDomainNetTeamingInfoFree(def->teaming);
>> g_free(def->virtPortProfile);
>> g_free(def->script);
>> @@ -9757,6 +9759,8 @@ virDomainNetBackendParseXML(xmlNodePtr node,
>> }
>>
>> def->backend.logFile = virXMLPropString(node, "logFile");
>> + def->backend.hostname = virXMLPropString(node, "hostname");
>> + def->backend.fqdn = virXMLPropString(node, "fqdn");
>>
>> if (tap)
>> def->backend.tap = virFileSanitizePath(tap);
>> @@ -20757,7 +20761,9 @@ virDomainNetBackendIsEqual(virDomainNetBackend
>> *src,
>> if (src->type != dst->type ||
>> STRNEQ_NULLABLE(src->tap, dst->tap) ||
>> STRNEQ_NULLABLE(src->vhost, dst->vhost) ||
>> - STRNEQ_NULLABLE(src->logFile, dst->logFile)) {
>> + STRNEQ_NULLABLE(src->logFile, dst->logFile) ||
>> + STRNEQ_NULLABLE(src->hostname, dst->hostname) ||
>> + STRNEQ_NULLABLE(src->fqdn, dst->fqdn)) {
>> return false;
>> }
>> return true;
>> @@ -24838,6 +24844,8 @@ virDomainNetBackendFormat(virBuffer *buf,
>> virBufferEscapeString(&attrBuf, " tap='%s'",
backend->tap);
>> virBufferEscapeString(&attrBuf, " vhost='%s'",
backend->vhost);
>> virBufferEscapeString(&attrBuf, " logFile='%s'",
backend->logFile);
>> + virBufferEscapeString(&attrBuf, " hostname='%s'",
>> backend->hostname);
>> + virBufferEscapeString(&attrBuf, " fqdn='%s'",
backend->fqdn);
>> virXMLFormatElement(buf, "backend", &attrBuf, NULL);
>> }
>>
>> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
>> index 58b97a2b54..79fd2f1f63 100644
>> --- a/src/conf/domain_conf.h
>> +++ b/src/conf/domain_conf.h
>> @@ -1067,6 +1067,8 @@ struct _virDomainNetBackend {
>> char *vhost;
>> /* The following are currently only valid/used when backend
>> type='passt' */
>> char *logFile; /* path to logfile used by passt process */
>> + char *hostname; /* hostname of the passt process */
>> + char *fqdn; /* fully qualified domain name of the passt process */
>> };
>>
>> struct _virDomainNetPortForwardRange {
>> diff --git a/src/conf/schemas/domaincommon.rng
>> b/src/conf/schemas/domaincommon.rng
>> index 5597d5a66b..f64199ca18 100644
>> --- a/src/conf/schemas/domaincommon.rng
>> +++ b/src/conf/schemas/domaincommon.rng
>> @@ -3913,6 +3913,12 @@
>> <ref name="absFilePath"/>
>> </attribute>
>> </optional>
>> + <optional>
>> + <attribute name="hostname"/>
>> + </optional>
>> + <optional>
>> + <attribute name="fqdn"/>
>> + </optional>
>> </element>
>> </optional>
>> <optional>
>> diff --git a/src/qemu/qemu_passt.c b/src/qemu/qemu_passt.c
>> index fcc34de384..81e5c51f6c 100644
>> --- a/src/qemu/qemu_passt.c
>> +++ b/src/qemu/qemu_passt.c
>> @@ -229,6 +229,12 @@ qemuPasstStart(virDomainObj *vm,
>> if (net->backend.logFile)
>> virCommandAddArgList(cmd, "--log-file",
net->backend.logFile,
>> NULL);
>>
>> + if (net->backend.hostname)
>> + virCommandAddArgList(cmd, "--hostname",
net->backend.hostname,
>> NULL);
>> +
>> + if (net->backend.fqdn)
>> + virCommandAddArgList(cmd, "--fqdn", net->backend.fqdn,
NULL);
>> +
>> /* Add IP address info */
>> for (i = 0; i < net->guestIP.nips; i++) {
>> const virNetDevIPAddr *ip = net->guestIP.ips[i];
>> diff --git a/tests/qemuxmlconfdata/net-user-passt.x86_64-7.2.0.xml
>> b/tests/qemuxmlconfdata/net-user-passt.x86_64-7.2.0.xml
>> index cfe07cc627..77da297936 100644
>> --- a/tests/qemuxmlconfdata/net-user-passt.x86_64-7.2.0.xml
>> +++ b/tests/qemuxmlconfdata/net-user-passt.x86_64-7.2.0.xml
>> @@ -50,7 +50,7 @@
>> <range start='443' to='344'/>
>> </portForward>
>> <model type='rtl8139'/>
>> - <backend type='passt'
logFile='/var/log/loglaw.blog'/>
>> + <backend type='passt' logFile='/var/log/loglaw.blog'
>> hostname='hostname1' fqdn='hostname1.test.local'/>
>> <address type='pci' domain='0x0000' bus='0x00'
slot='0x02'
>> function='0x0'/>
>> </interface>
>> <input type='mouse' bus='ps2'/>
>> diff --git a/tests/qemuxmlconfdata/net-user-passt.x86_64-latest.xml
>> b/tests/qemuxmlconfdata/net-user-passt.x86_64-latest.xml
>> index d7e0ef5f90..917a9edaa0 100644
>> --- a/tests/qemuxmlconfdata/net-user-passt.x86_64-latest.xml
>> +++ b/tests/qemuxmlconfdata/net-user-passt.x86_64-latest.xml
>> @@ -50,7 +50,7 @@
>> <range start='443' to='344'/>
>> </portForward>
>> <model type='rtl8139'/>
>> - <backend type='passt'
logFile='/var/log/loglaw.blog'/>
>> + <backend type='passt' logFile='/var/log/loglaw.blog'
>> hostname='hostname1' fqdn='hostname1.test.local'/>
>> <address type='pci' domain='0x0000' bus='0x00'
slot='0x02'
>> function='0x0'/>
>> </interface>
>> <input type='mouse' bus='ps2'/>
>> diff --git a/tests/qemuxmlconfdata/net-user-passt.xml
>> b/tests/qemuxmlconfdata/net-user-passt.xml
>> index 20c9f50542..80d15de2ed 100644
>> --- a/tests/qemuxmlconfdata/net-user-passt.xml
>> +++ b/tests/qemuxmlconfdata/net-user-passt.xml
>> @@ -47,7 +47,7 @@
>> <range start='443' to='344'/>
>> </portForward>
>> <model type='rtl8139'/>
>> - <backend type='passt'
logFile='/var/log/loglaw.blog'/>
>> + <backend type='passt' logFile='/var/log/loglaw.blog'
>> hostname='hostname1' fqdn='hostname1.test.local'/>
>> <address type='pci' domain='0x0000' bus='0x00'
slot='0x02'
>> function='0x0'/>
>> </interface>
>> <input type='mouse' bus='ps2'/>
>> diff --git a/tests/qemuxmlconfdata/net-vhostuser-passt.x86_64-latest.xml
>> b/tests/qemuxmlconfdata/net-vhostuser-passt.x86_64-latest.xml
>> index 529aff11f8..5802754c4b 100644
>> --- a/tests/qemuxmlconfdata/net-vhostuser-passt.x86_64-latest.xml
>> +++ b/tests/qemuxmlconfdata/net-vhostuser-passt.x86_64-latest.xml
>> @@ -53,7 +53,7 @@
>> <range start='443' to='344'/>
>> </portForward>
>> <model type='virtio'/>
>> - <backend type='passt'
logFile='/var/log/loglaw.blog'/>
>> + <backend type='passt' logFile='/var/log/loglaw.blog'
>> hostname='hostname1' fqdn='hostname1.test.local'/>
>> <address type='pci' domain='0x0000' bus='0x00'
slot='0x02'
>> function='0x0'/>
>> </interface>
>> <interface type='vhostuser'>
>> diff --git a/tests/qemuxmlconfdata/net-vhostuser-passt.xml
>> b/tests/qemuxmlconfdata/net-vhostuser-passt.xml
>> index 71b845329b..0a37511a0f 100644
>> --- a/tests/qemuxmlconfdata/net-vhostuser-passt.xml
>> +++ b/tests/qemuxmlconfdata/net-vhostuser-passt.xml
>> @@ -50,7 +50,7 @@
>> <range start='443' to='344'/>
>> </portForward>
>> <model type='virtio'/>
>> - <backend type='passt'
logFile='/var/log/loglaw.blog'/>
>> + <backend type='passt' logFile='/var/log/loglaw.blog'
>> hostname='hostname1' fqdn='hostname1.test.local'/>
>> <address type='pci' domain='0x0000' bus='0x00'
slot='0x02'
>> function='0x0'/>
>> </interface>
>> <interface type='vhostuser'>
>> --
>> 2.49.0
>>
>> Build libvirt-11.5 with this patch. It works for me.
>
> Correct the version: v11.4.0-98-g1ee74707bd
> --
> Tested-by: Han Han <hhan(a)redhat.com>
>