mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
network: allow "modify" option for DNS-Txt records
The "modify" command allows to replace an existing record (its text value). The primary key is the name of the record. If duplicity or missing record detected, throw error. Tests in networkxml2xmlupdatetest.c contain replacements of an existing DNS-text record and failure due to non-existing record. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/639 Signed-off-by: Adam Julis <ajulis@redhat.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
cf934c87cc
commit
7a9e9dfb18
@ -3353,12 +3353,6 @@ virNetworkDefUpdateDNSTxt(virNetworkDef *def,
|
|||||||
bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST ||
|
bool isAdd = (command == VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST ||
|
||||||
command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST);
|
command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST);
|
||||||
|
|
||||||
if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
||||||
_("DNS TXT records cannot be modified, only added or deleted"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "txt") < 0)
|
if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "txt") < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -3397,6 +3391,18 @@ virNetworkDefUpdateDNSTxt(virNetworkDef *def,
|
|||||||
virNetworkDNSTxtDefClear(&dns->txts[foundIdx]);
|
virNetworkDNSTxtDefClear(&dns->txts[foundIdx]);
|
||||||
VIR_DELETE_ELEMENT(dns->txts, foundIdx, dns->ntxts);
|
VIR_DELETE_ELEMENT(dns->txts, foundIdx, dns->ntxts);
|
||||||
|
|
||||||
|
} else if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) {
|
||||||
|
|
||||||
|
if (foundIdx == dns->ntxts) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
|
_("couldn't locate a matching DNS TXT record in network %1$s"),
|
||||||
|
def->name);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
VIR_FREE(dns->txts[foundIdx].value);
|
||||||
|
dns->txts[foundIdx].value = g_steal_pointer(&txt.value);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
virNetworkDefUpdateUnknownCommand(command);
|
virNetworkDefUpdateUnknownCommand(command);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
<txt name='notexisted' value='modified example'/>
|
@ -0,0 +1 @@
|
|||||||
|
<txt name='example' value='modified example'/>
|
@ -0,0 +1,26 @@
|
|||||||
|
<network>
|
||||||
|
<name>default</name>
|
||||||
|
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
|
||||||
|
<forward dev='eth1' mode='nat'>
|
||||||
|
<interface dev='eth1'/>
|
||||||
|
</forward>
|
||||||
|
<bridge name='virbr0' stp='on' delay='0'/>
|
||||||
|
<dns>
|
||||||
|
<txt name='example' value='modified example'/>
|
||||||
|
</dns>
|
||||||
|
<ip address='192.168.122.1' netmask='255.255.255.0'>
|
||||||
|
<dhcp>
|
||||||
|
<range start='192.168.122.2' end='192.168.122.254'/>
|
||||||
|
<host mac='00:16:3e:77:e2:ed' name='a.example.com' ip='192.168.122.10'/>
|
||||||
|
<host mac='00:16:3e:3e:a9:1a' name='b.example.com' ip='192.168.122.11'/>
|
||||||
|
</dhcp>
|
||||||
|
</ip>
|
||||||
|
<ip family='ipv4' address='192.168.123.1' netmask='255.255.255.0'>
|
||||||
|
</ip>
|
||||||
|
<ip family='ipv6' address='2001:db8:ac10:fe01::1' prefix='64'>
|
||||||
|
</ip>
|
||||||
|
<ip family='ipv6' address='2001:db8:ac10:fd01::1' prefix='64'>
|
||||||
|
</ip>
|
||||||
|
<ip family='ipv4' address='10.24.10.1'>
|
||||||
|
</ip>
|
||||||
|
</network>
|
@ -306,6 +306,15 @@ mymain(void)
|
|||||||
"dns-txt-record-snowman",
|
"dns-txt-record-snowman",
|
||||||
"nat-network-dns-txt-record",
|
"nat-network-dns-txt-record",
|
||||||
VIR_NETWORK_UPDATE_COMMAND_DELETE);
|
VIR_NETWORK_UPDATE_COMMAND_DELETE);
|
||||||
|
DO_TEST("modify-dns-txt-record",
|
||||||
|
"dns-txt-record-modify-success",
|
||||||
|
"nat-network-dns-txt-record",
|
||||||
|
"nat-network-dns-txt-modify-ok",
|
||||||
|
VIR_NETWORK_UPDATE_COMMAND_MODIFY);
|
||||||
|
DO_TEST_FAIL("modify-missing-dns-txt-record",
|
||||||
|
"dns-txt-record-modify-fail",
|
||||||
|
"nat-network-dns-txt-record",
|
||||||
|
VIR_NETWORK_UPDATE_COMMAND_MODIFY);
|
||||||
|
|
||||||
|
|
||||||
section = VIR_NETWORK_SECTION_DNS_SRV;
|
section = VIR_NETWORK_SECTION_DNS_SRV;
|
||||||
|
Loading…
Reference in New Issue
Block a user