[PATCH 0/2] network: Introduce port for DNS forwarder
*** BLURB HERE *** Michal Prívozník (2): network: Introduce port for DNS forwarder network: Propagate DNS forwarder port into dnsmasq config docs/formatnetwork.rst | 8 +++-- src/conf/network_conf.c | 36 +++++++++++++++---- src/conf/schemas/network.rng | 5 +++ src/network/bridge_driver.c | 6 +++- .../nat-network-dns-forwarders.conf | 2 +- .../nat-network-dns-forwarders.xml | 2 +- .../nat-network-dns-forwarders.xml | 2 +- .../nat-network-dns-forwarders.xml | 2 +- 8 files changed, 49 insertions(+), 14 deletions(-) -- 2.51.2
From: Michal Privoznik <mprivozn@redhat.com> In the <dns/> section of network configuration users can set up forwarding of DNS requests to custom DNS servers. These are specified using 'addr' attribute. But configuring port wasn't possible, until now. New 'port' attribute is introduced, which allows overriding the default DNS port for given address. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/formatnetwork.rst | 8 +++-- src/conf/network_conf.c | 36 +++++++++++++++---- src/conf/schemas/network.rng | 5 +++ .../nat-network-dns-forwarders.xml | 2 +- .../nat-network-dns-forwarders.xml | 2 +- 5 files changed, 42 insertions(+), 11 deletions(-) diff --git a/docs/formatnetwork.rst b/docs/formatnetwork.rst index 6694a145af..1dd336211d 100644 --- a/docs/formatnetwork.rst +++ b/docs/formatnetwork.rst @@ -695,7 +695,7 @@ of 'route' or 'nat'. <dns> <txt name="example" value="example value"/> <forwarder addr="8.8.8.8"/> - <forwarder domain='example.com' addr="8.8.4.4"/> + <forwarder domain='example.com' addr='8.8.4.4' port='1234'/> <forwarder domain='www.example.com'/> <srv service='name' protocol='tcp' domain='test-domain-name' target='.' port='1024' priority='10' weight='10'/> @@ -762,8 +762,10 @@ of 'route' or 'nat'. will be resolved locally (or via the host's standard DNS forwarding if they can't be resolved locally). If an ``addr`` is specified by itself, then all DNS requests to the network's DNS server will be forwarded to the - DNS server at that address with no exceptions. ``addr`` :since:`Since - 1.1.3` , ``domain`` :since:`Since 2.2.0`. + DNS server at that address with no exceptions. Optionally, ``port`` + attribute can be specified among with ``addr`` to specify a nonstandard + port of the DNS server. ``addr`` :since:`Since 1.1.3`, ``domain`` + :since:`Since 2.2.0`, ``port`` :since:`Since 12.0.0`. ``txt`` A ``dns`` element can have 0 or more ``txt`` elements. Each txt element defines a DNS TXT record and has two attributes, both required: a name diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 8cd26de72f..fe44fd28c3 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -901,12 +901,32 @@ virNetworkDNSDefParseXML(const char *networkName, for (i = 0; i < nfwds; i++) { g_autofree char *addr = virXMLPropString(fwdNodes[i], "addr"); - if (addr && virSocketAddrParse(&def->forwarders[i].addr, - addr, AF_UNSPEC) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid forwarder IP address '%1$s' in network '%2$s'"), - addr, networkName); - return -1; + if (addr) { + int port = -1; + int rc; + + if (virSocketAddrParse(&def->forwarders[i].addr, + addr, AF_UNSPEC) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid forwarder IP address '%1$s' in network '%2$s'"), + addr, networkName); + return -1; + } + + if ((rc = virXMLPropInt(fwdNodes[i], "port", 10, + VIR_XML_PROP_NONZERO | + VIR_XML_PROP_NONNEGATIVE, + &port, -1)) < 0) { + return -1; + } else if (rc > 0) { + if (port > 65535) { + virReportError(VIR_ERR_INVALID_ARG, + _("port '%1$d' out of range"), port); + return -1; + } + + virSocketAddrSetPort(&def->forwarders[i].addr, port); + } } def->forwarders[i].domain = virXMLPropString(fwdNodes[i], "domain"); if (!(addr || def->forwarders[i].domain)) { @@ -1986,11 +2006,15 @@ virNetworkDNSDefFormat(virBuffer *buf, } if (VIR_SOCKET_ADDR_VALID(&def->forwarders[i].addr)) { g_autofree char *addr = virSocketAddrFormat(&def->forwarders[i].addr); + int port = virSocketAddrGetPort(&def->forwarders[i].addr); if (!addr) return -1; virBufferAsprintf(buf, " addr='%s'", addr); + + if (port > 0) + virBufferAsprintf(buf, " port='%d'", port); } virBufferAddLit(buf, "/>\n"); } diff --git a/src/conf/schemas/network.rng b/src/conf/schemas/network.rng index b7c8551fad..0d293af93b 100644 --- a/src/conf/schemas/network.rng +++ b/src/conf/schemas/network.rng @@ -287,6 +287,11 @@ <optional> <attribute name="domain"><ref name="dnsName"/></attribute> </optional> + <optional> + <attribute name="port"> + <ref name="unsignedShort"/> + </attribute> + </optional> <empty/> </element> </zeroOrMore> diff --git a/tests/networkxml2xmlin/nat-network-dns-forwarders.xml b/tests/networkxml2xmlin/nat-network-dns-forwarders.xml index 426dd45cd9..dd22b686ab 100644 --- a/tests/networkxml2xmlin/nat-network-dns-forwarders.xml +++ b/tests/networkxml2xmlin/nat-network-dns-forwarders.xml @@ -6,7 +6,7 @@ <dns> <forwarder addr='8.8.8.8'/> <forwarder addr='8.8.4.4'/> - <forwarder domain='example.com' addr='192.168.1.1'/> + <forwarder domain='example.com' addr='192.168.1.1' port='1234'/> <forwarder domain='www.example.com'/> </dns> <ip address='192.168.122.1' netmask='255.255.255.0'> diff --git a/tests/networkxml2xmlout/nat-network-dns-forwarders.xml b/tests/networkxml2xmlout/nat-network-dns-forwarders.xml index c05ad5514d..e03912750c 100644 --- a/tests/networkxml2xmlout/nat-network-dns-forwarders.xml +++ b/tests/networkxml2xmlout/nat-network-dns-forwarders.xml @@ -8,7 +8,7 @@ <dns> <forwarder addr='8.8.8.8'/> <forwarder addr='8.8.4.4'/> - <forwarder domain='example.com' addr='192.168.1.1'/> + <forwarder domain='example.com' addr='192.168.1.1' port='1234'/> <forwarder domain='www.example.com'/> </dns> <ip address='192.168.122.1' netmask='255.255.255.0'> -- 2.51.2
On 12/18/25 5:00 AM, Michal Privoznik via Devel wrote:
From: Michal Privoznik <mprivozn@redhat.com>
In the <dns/> section of network configuration users can set up forwarding of DNS requests to custom DNS servers. These are specified using 'addr' attribute. But configuring port wasn't possible, until now. New 'port' attribute is introduced, which allows overriding the default DNS port for given address.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/formatnetwork.rst | 8 +++-- src/conf/network_conf.c | 36 +++++++++++++++---- src/conf/schemas/network.rng | 5 +++ .../nat-network-dns-forwarders.xml | 2 +- .../nat-network-dns-forwarders.xml | 2 +- 5 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/docs/formatnetwork.rst b/docs/formatnetwork.rst index 6694a145af..1dd336211d 100644 --- a/docs/formatnetwork.rst +++ b/docs/formatnetwork.rst @@ -695,7 +695,7 @@ of 'route' or 'nat'. <dns> <txt name="example" value="example value"/> <forwarder addr="8.8.8.8"/> - <forwarder domain='example.com' addr="8.8.4.4"/> + <forwarder domain='example.com' addr='8.8.4.4' port='1234'/> <forwarder domain='www.example.com'/> <srv service='name' protocol='tcp' domain='test-domain-name' target='.' port='1024' priority='10' weight='10'/> @@ -762,8 +762,10 @@ of 'route' or 'nat'. will be resolved locally (or via the host's standard DNS forwarding if they can't be resolved locally). If an ``addr`` is specified by itself, then all DNS requests to the network's DNS server will be forwarded to the - DNS server at that address with no exceptions. ``addr`` :since:`Since - 1.1.3` , ``domain`` :since:`Since 2.2.0`. + DNS server at that address with no exceptions. Optionally, ``port`` + attribute can be specified among with ``addr`` to specify a nonstandard
"Optionally, the ``port`` attribute can be given along with ... (in case you're wondering about "given" - that's just to avoid using variations of "specify" twice in the same sentence)
+ port of the DNS server. ``addr`` :since:`Since 1.1.3`, ``domain`` + :since:`Since 2.2.0`, ``port`` :since:`Since 12.0.0`. ``txt`` A ``dns`` element can have 0 or more ``txt`` elements. Each txt element defines a DNS TXT record and has two attributes, both required: a name diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 8cd26de72f..fe44fd28c3 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -901,12 +901,32 @@ virNetworkDNSDefParseXML(const char *networkName, for (i = 0; i < nfwds; i++) { g_autofree char *addr = virXMLPropString(fwdNodes[i], "addr");
- if (addr && virSocketAddrParse(&def->forwarders[i].addr, - addr, AF_UNSPEC) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid forwarder IP address '%1$s' in network '%2$s'"), - addr, networkName); - return -1; + if (addr) { + int port = -1; + int rc; + + if (virSocketAddrParse(&def->forwarders[i].addr, + addr, AF_UNSPEC) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid forwarder IP address '%1$s' in network '%2$s'"), + addr, networkName); + return -1; + } + + if ((rc = virXMLPropInt(fwdNodes[i], "port", 10, + VIR_XML_PROP_NONZERO | + VIR_XML_PROP_NONNEGATIVE, + &port, -1)) < 0) { + return -1; + } else if (rc > 0) { + if (port > 65535) { + virReportError(VIR_ERR_INVALID_ARG, + _("port '%1$d' out of range"), port); + return -1; + } + + virSocketAddrSetPort(&def->forwarders[i].addr, port); + }
One validation hole is that if someone specifies a port without an address, the port will just be ignored (and also not stored, so it will just disappear from the config). Otherwise Reviewed-by: Laine Stump <laine@redhat.com>
} def->forwarders[i].domain = virXMLPropString(fwdNodes[i], "domain"); if (!(addr || def->forwarders[i].domain)) { @@ -1986,11 +2006,15 @@ virNetworkDNSDefFormat(virBuffer *buf, } if (VIR_SOCKET_ADDR_VALID(&def->forwarders[i].addr)) { g_autofree char *addr = virSocketAddrFormat(&def->forwarders[i].addr); + int port = virSocketAddrGetPort(&def->forwarders[i].addr);
if (!addr) return -1;
virBufferAsprintf(buf, " addr='%s'", addr); + + if (port > 0) + virBufferAsprintf(buf, " port='%d'", port); } virBufferAddLit(buf, "/>\n"); } diff --git a/src/conf/schemas/network.rng b/src/conf/schemas/network.rng index b7c8551fad..0d293af93b 100644 --- a/src/conf/schemas/network.rng +++ b/src/conf/schemas/network.rng @@ -287,6 +287,11 @@ <optional> <attribute name="domain"><ref name="dnsName"/></attribute> </optional> + <optional> + <attribute name="port"> + <ref name="unsignedShort"/>
You could instead use <ref name="port"/> (which is defined as an integer between 1 and 65535), but the only difference is that XML validation would flag a "0" value, and the parser already does that (and provides a much better error message) so it's kind of pointless (also I looked it up and we don't consistently use "port"). (I guess I'm more wondering why we bother having the special type in the RNG, rather than wondering why you didn't use it - its value seems dubious :-P)
+ </attribute> + </optional> <empty/> </element> </zeroOrMore> diff --git a/tests/networkxml2xmlin/nat-network-dns-forwarders.xml b/tests/networkxml2xmlin/nat-network-dns-forwarders.xml index 426dd45cd9..dd22b686ab 100644 --- a/tests/networkxml2xmlin/nat-network-dns-forwarders.xml +++ b/tests/networkxml2xmlin/nat-network-dns-forwarders.xml @@ -6,7 +6,7 @@ <dns> <forwarder addr='8.8.8.8'/> <forwarder addr='8.8.4.4'/> - <forwarder domain='example.com' addr='192.168.1.1'/> + <forwarder domain='example.com' addr='192.168.1.1' port='1234'/> <forwarder domain='www.example.com'/> </dns> <ip address='192.168.122.1' netmask='255.255.255.0'> diff --git a/tests/networkxml2xmlout/nat-network-dns-forwarders.xml b/tests/networkxml2xmlout/nat-network-dns-forwarders.xml index c05ad5514d..e03912750c 100644 --- a/tests/networkxml2xmlout/nat-network-dns-forwarders.xml +++ b/tests/networkxml2xmlout/nat-network-dns-forwarders.xml @@ -8,7 +8,7 @@ <dns> <forwarder addr='8.8.8.8'/> <forwarder addr='8.8.4.4'/> - <forwarder domain='example.com' addr='192.168.1.1'/> + <forwarder domain='example.com' addr='192.168.1.1' port='1234'/> <forwarder domain='www.example.com'/> </dns> <ip address='192.168.122.1' netmask='255.255.255.0'>
On 12/18/25 20:35, Laine Stump wrote:
On 12/18/25 5:00 AM, Michal Privoznik via Devel wrote:
From: Michal Privoznik <mprivozn@redhat.com>
In the <dns/> section of network configuration users can set up forwarding of DNS requests to custom DNS servers. These are specified using 'addr' attribute. But configuring port wasn't possible, until now. New 'port' attribute is introduced, which allows overriding the default DNS port for given address.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/formatnetwork.rst | 8 +++-- src/conf/network_conf.c | 36 +++++++++++++++---- src/conf/schemas/network.rng | 5 +++ .../nat-network-dns-forwarders.xml | 2 +- .../nat-network-dns-forwarders.xml | 2 +- 5 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 8cd26de72f..fe44fd28c3 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -901,12 +901,32 @@ virNetworkDNSDefParseXML(const char *networkName, for (i = 0; i < nfwds; i++) { g_autofree char *addr = virXMLPropString(fwdNodes[i], "addr"); - if (addr && virSocketAddrParse(&def->forwarders[i].addr, - addr, AF_UNSPEC) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid forwarder IP address '%1$s' in network '%2$s'"), - addr, networkName); - return -1; + if (addr) { + int port = -1; + int rc; + + if (virSocketAddrParse(&def->forwarders[i].addr, + addr, AF_UNSPEC) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid forwarder IP address '%1$s' in network '%2$s'"), + addr, networkName); + return -1; + } + + if ((rc = virXMLPropInt(fwdNodes[i], "port", 10, + VIR_XML_PROP_NONZERO | + VIR_XML_PROP_NONNEGATIVE, + &port, -1)) < 0) { + return -1; + } else if (rc > 0) { + if (port > 65535) { + virReportError(VIR_ERR_INVALID_ARG, + _("port '%1$d' out of range"), port); + return -1; + } + + virSocketAddrSetPort(&def->forwarders[i].addr, port); + }
One validation hole is that if someone specifies a port without an address, the port will just be ignored (and also not stored, so it will just disappear from the config).
That's intentional. Hence slightly weird wording in documentation.
Otherwise
Reviewed-by: Laine Stump <laine@redhat.com>
forwarders[i].addr); + int port = virSocketAddrGetPort(&def->forwarders[i].addr); if (!addr) return -1; virBufferAsprintf(buf, " addr='%s'", addr);
} def->forwarders[i].domain = virXMLPropString(fwdNodes[i], "domain"); if (!(addr || def->forwarders[i].domain)) { @@ -1986,11 +2006,15 @@ virNetworkDNSDefFormat(virBuffer *buf, } if (VIR_SOCKET_ADDR_VALID(&def->forwarders[i].addr)) { g_autofree char *addr = virSocketAddrFormat(&def- + + if (port > 0) + virBufferAsprintf(buf, " port='%d'", port); } virBufferAddLit(buf, "/>\n"); } diff --git a/src/conf/schemas/network.rng b/src/conf/schemas/network.rng index b7c8551fad..0d293af93b 100644 --- a/src/conf/schemas/network.rng +++ b/src/conf/schemas/network.rng @@ -287,6 +287,11 @@ <optional> <attribute name="domain"><ref name="dnsName"/></ attribute> </optional> + <optional> + <attribute name="port"> + <ref name="unsignedShort"/>
You could instead use <ref name="port"/> (which is defined as an integer between 1 and 65535), but the only difference is that XML validation would flag a "0" value, and the parser already does that (and provides a much better error message) so it's kind of pointless (also I looked it up and we don't consistently use "port"). (I guess I'm more wondering why we bother having the special type in the RNG, rather than wondering why you didn't use it - its value seems dubious :-P)
Honestly, I just looked a few lines up and down to see how is the attribute declared elsewhere and found unsignedShort. But since we already have "port" type might as well use it. Thanks, Michal
On 12/19/25 4:02 AM, Michal Prívozník wrote:
On 12/18/25 20:35, Laine Stump wrote:
On 12/18/25 5:00 AM, Michal Privoznik via Devel wrote:
From: Michal Privoznik <mprivozn@redhat.com>
In the <dns/> section of network configuration users can set up forwarding of DNS requests to custom DNS servers. These are specified using 'addr' attribute. But configuring port wasn't possible, until now. New 'port' attribute is introduced, which allows overriding the default DNS port for given address.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/formatnetwork.rst | 8 +++-- src/conf/network_conf.c | 36 +++++++++++++++---- src/conf/schemas/network.rng | 5 +++ .../nat-network-dns-forwarders.xml | 2 +- .../nat-network-dns-forwarders.xml | 2 +- 5 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 8cd26de72f..fe44fd28c3 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -901,12 +901,32 @@ virNetworkDNSDefParseXML(const char *networkName, for (i = 0; i < nfwds; i++) { g_autofree char *addr = virXMLPropString(fwdNodes[i], "addr"); - if (addr && virSocketAddrParse(&def->forwarders[i].addr, - addr, AF_UNSPEC) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid forwarder IP address '%1$s' in network '%2$s'"), - addr, networkName); - return -1; + if (addr) { + int port = -1; + int rc; + + if (virSocketAddrParse(&def->forwarders[i].addr, + addr, AF_UNSPEC) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid forwarder IP address '%1$s' in network '%2$s'"), + addr, networkName); + return -1; + } + + if ((rc = virXMLPropInt(fwdNodes[i], "port", 10, + VIR_XML_PROP_NONZERO | + VIR_XML_PROP_NONNEGATIVE, + &port, -1)) < 0) { + return -1; + } else if (rc > 0) { + if (port > 65535) { + virReportError(VIR_ERR_INVALID_ARG, + _("port '%1$d' out of range"), port); + return -1; + } + + virSocketAddrSetPort(&def->forwarders[i].addr, port); + }
One validation hole is that if someone specifies a port without an address, the port will just be ignored (and also not stored, so it will just disappear from the config).
That's intentional. Hence slightly weird wording in documentation.
?? Why would you want to do that?
Otherwise
Reviewed-by: Laine Stump <laine@redhat.com>
forwarders[i].addr); + int port = virSocketAddrGetPort(&def->forwarders[i].addr); if (!addr) return -1; virBufferAsprintf(buf, " addr='%s'", addr);
} def->forwarders[i].domain = virXMLPropString(fwdNodes[i], "domain"); if (!(addr || def->forwarders[i].domain)) { @@ -1986,11 +2006,15 @@ virNetworkDNSDefFormat(virBuffer *buf, } if (VIR_SOCKET_ADDR_VALID(&def->forwarders[i].addr)) { g_autofree char *addr = virSocketAddrFormat(&def- + + if (port > 0) + virBufferAsprintf(buf, " port='%d'", port); } virBufferAddLit(buf, "/>\n"); } diff --git a/src/conf/schemas/network.rng b/src/conf/schemas/network.rng index b7c8551fad..0d293af93b 100644 --- a/src/conf/schemas/network.rng +++ b/src/conf/schemas/network.rng @@ -287,6 +287,11 @@ <optional> <attribute name="domain"><ref name="dnsName"/></ attribute> </optional> + <optional> + <attribute name="port"> + <ref name="unsignedShort"/>
You could instead use <ref name="port"/> (which is defined as an integer between 1 and 65535), but the only difference is that XML validation would flag a "0" value, and the parser already does that (and provides a much better error message) so it's kind of pointless (also I looked it up and we don't consistently use "port"). (I guess I'm more wondering why we bother having the special type in the RNG, rather than wondering why you didn't use it - its value seems dubious :-P)
Honestly, I just looked a few lines up and down to see how is the attribute declared elsewhere and found unsignedShort. But since we already have "port" type might as well use it.
Yeah, I'm ambivalent about it, so either way is fine with me.
From: Michal Privoznik <mprivozn@redhat.com> If a DNS forwarder has port specified then we ought to format it into dnsmasq config. The correct syntax is server=/domain/ip-address#port Closes: https://gitlab.com/libvirt/libvirt/-/issues/833 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/network/bridge_driver.c | 6 +++++- tests/networkxml2confdata/nat-network-dns-forwarders.conf | 2 +- tests/networkxml2confdata/nat-network-dns-forwarders.xml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 34b655e816..8b5dbb3ab7 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1212,10 +1212,14 @@ networkDnsmasqConfContents(virNetworkObj *obj, virBufferAsprintf(&configbuf, "/%s/", fwd->domain); if (VIR_SOCKET_ADDR_VALID(&fwd->addr)) { g_autofree char *addr = virSocketAddrFormat(&fwd->addr); + int port = virSocketAddrGetPort(&fwd->addr); if (!addr) return -1; - virBufferAsprintf(&configbuf, "%s\n", addr); + virBufferAddStr(&configbuf, addr); + if (port > 0) + virBufferAsprintf(&configbuf, "#%d", port); + virBufferAddChar(&configbuf, '\n'); if (!fwd->domain) addNoResolv = true; } else { diff --git a/tests/networkxml2confdata/nat-network-dns-forwarders.conf b/tests/networkxml2confdata/nat-network-dns-forwarders.conf index 1b0c94c3fb..85d6c6ceb9 100644 --- a/tests/networkxml2confdata/nat-network-dns-forwarders.conf +++ b/tests/networkxml2confdata/nat-network-dns-forwarders.conf @@ -7,7 +7,7 @@ strict-order server=8.8.8.8 server=8.8.4.4 -server=/example.com/192.168.1.1 +server=/example.com/192.168.1.1#1234 server=/www.example.com/# no-resolv except-interface=lo diff --git a/tests/networkxml2confdata/nat-network-dns-forwarders.xml b/tests/networkxml2confdata/nat-network-dns-forwarders.xml index 5d4f3fa697..98d9660b14 100644 --- a/tests/networkxml2confdata/nat-network-dns-forwarders.xml +++ b/tests/networkxml2confdata/nat-network-dns-forwarders.xml @@ -6,7 +6,7 @@ <dns> <forwarder addr='8.8.8.8'/> <forwarder addr='8.8.4.4'/> - <forwarder domain='example.com' addr='192.168.1.1'/> + <forwarder domain='example.com' addr='192.168.1.1' port='1234'/> <forwarder domain='www.example.com'/> </dns> <ip address='192.168.122.1' netmask='255.255.255.0'> -- 2.51.2
On 12/18/25 5:00 AM, Michal Privoznik via Devel wrote:
From: Michal Privoznik <mprivozn@redhat.com>
If a DNS forwarder has port specified then we ought to format it into dnsmasq config. The correct syntax is
server=/domain/ip-address#port
Closes: https://gitlab.com/libvirt/libvirt/-/issues/833 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/network/bridge_driver.c | 6 +++++- tests/networkxml2confdata/nat-network-dns-forwarders.conf | 2 +- tests/networkxml2confdata/nat-network-dns-forwarders.xml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 34b655e816..8b5dbb3ab7 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1212,10 +1212,14 @@ networkDnsmasqConfContents(virNetworkObj *obj, virBufferAsprintf(&configbuf, "/%s/", fwd->domain); if (VIR_SOCKET_ADDR_VALID(&fwd->addr)) { g_autofree char *addr = virSocketAddrFormat(&fwd->addr); + int port = virSocketAddrGetPort(&fwd->addr);
if (!addr) return -1; - virBufferAsprintf(&configbuf, "%s\n", addr); + virBufferAddStr(&configbuf, addr); + if (port > 0) + virBufferAsprintf(&configbuf, "#%d", port); + virBufferAddChar(&configbuf, '\n'); if (!fwd->domain) addNoResolv = true; } else { diff --git a/tests/networkxml2confdata/nat-network-dns-forwarders.conf b/tests/networkxml2confdata/nat-network-dns-forwarders.conf index 1b0c94c3fb..85d6c6ceb9 100644 --- a/tests/networkxml2confdata/nat-network-dns-forwarders.conf +++ b/tests/networkxml2confdata/nat-network-dns-forwarders.conf @@ -7,7 +7,7 @@ strict-order server=8.8.8.8 server=8.8.4.4 -server=/example.com/192.168.1.1 +server=/example.com/192.168.1.1#1234 server=/www.example.com/# no-resolv except-interface=lo diff --git a/tests/networkxml2confdata/nat-network-dns-forwarders.xml b/tests/networkxml2confdata/nat-network-dns-forwarders.xml index 5d4f3fa697..98d9660b14 100644 --- a/tests/networkxml2confdata/nat-network-dns-forwarders.xml +++ b/tests/networkxml2confdata/nat-network-dns-forwarders.xml @@ -6,7 +6,7 @@ <dns> <forwarder addr='8.8.8.8'/> <forwarder addr='8.8.4.4'/> - <forwarder domain='example.com' addr='192.168.1.1'/> + <forwarder domain='example.com' addr='192.168.1.1' port='1234'/> <forwarder domain='www.example.com'/>
The one issue with this is that by changing an existing entry rather than adding a new one, you've eliminated the test case that checks for proper operation when domain & addr are specified, but port is not. Otherwise Reviewed-by: Laine Stump <laine@redhat.com>
</dns> <ip address='192.168.122.1' netmask='255.255.255.0'>
participants (3)
-
Laine Stump -
Michal Privoznik -
Michal Prívozník