From: Adam Julis Date: Tue, 9 Jul 2024 15:23:18 +0000 (+0200) Subject: network: allow "modify" option for DNS-Srv records X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=cf934c87cca32149675020ea595712aad25978e6;p=libvirt.git network: allow "modify" option for DNS-Srv records The "modify" command allows to replace an existing Srv record (some of its elements respectively: port, priority and weight). The primary key used to choose the modify record is the remaining parameters, only one of them is required. Not using some of these parameters may cause duplicate records and error message. This logic is there because of the previous implementation (Add and Delete options) in the function. Tests in networkxml2xmlupdatetest.c contain replacements of an existing DNS-Srv record and failure due to non-existing record. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/639 Signed-off-by: Adam Julis Reviewed-by: Michal Privoznik --- diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 3c19ff4ca5..8e7a739d78 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -3257,12 +3257,6 @@ virNetworkDefUpdateDNSSrv(virNetworkDef *def, command == VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); int foundCt = 0; - if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("DNS SRV records cannot be modified, only added or deleted")); - goto cleanup; - } - if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "srv") < 0) goto cleanup; @@ -3312,6 +3306,27 @@ virNetworkDefUpdateDNSSrv(virNetworkDef *def, virNetworkDNSSrvDefClear(&dns->srvs[foundIdx]); VIR_DELETE_ELEMENT(dns->srvs, foundIdx, dns->nsrvs); + } else if (command == VIR_NETWORK_UPDATE_COMMAND_MODIFY) { + + if (foundCt == 0) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("couldn't locate a matching DNS SRV record in network %1$s"), + def->name); + goto cleanup; + } + + if (foundCt > 1) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("multiple DNS SRV records matching all specified fields were found in network %1$s"), + def->name); + goto cleanup; + } + + virNetworkDNSSrvDefClear(&dns->srvs[foundIdx]); + + memcpy(&dns->srvs[foundIdx], &srv, sizeof(virNetworkDNSSrvDef)); + memset(&srv, 0, sizeof(virNetworkDNSSrvDef)); + } else { virNetworkDefUpdateUnknownCommand(command); goto cleanup; diff --git a/tests/networkxml2xmlupdatein/srv-not-existing.xml b/tests/networkxml2xmlupdatein/srv-not-existing.xml new file mode 100644 index 0000000000..401e14c616 --- /dev/null +++ b/tests/networkxml2xmlupdatein/srv-not-existing.xml @@ -0,0 +1 @@ + diff --git a/tests/networkxml2xmlupdatein/srv-record-modify-few.xml b/tests/networkxml2xmlupdatein/srv-record-modify-few.xml new file mode 100644 index 0000000000..88ec1b97d9 --- /dev/null +++ b/tests/networkxml2xmlupdatein/srv-record-modify-few.xml @@ -0,0 +1 @@ + diff --git a/tests/networkxml2xmlupdateout/nat-network-dns-srv-modify-few.xml b/tests/networkxml2xmlupdateout/nat-network-dns-srv-modify-few.xml new file mode 100644 index 0000000000..a7e5fcffa6 --- /dev/null +++ b/tests/networkxml2xmlupdateout/nat-network-dns-srv-modify-few.xml @@ -0,0 +1,26 @@ + + default + 81ff0d90-c91e-6742-64da-4a736edb9a9b + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/networkxml2xmlupdatetest.c b/tests/networkxml2xmlupdatetest.c index 383cbf85ce..59e6ce98e5 100644 --- a/tests/networkxml2xmlupdatetest.c +++ b/tests/networkxml2xmlupdatetest.c @@ -328,7 +328,6 @@ mymain(void) "nat-network-dns-srv-record", "nat-network-dns-srv-records", VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); - DO_TEST_FAIL("delete-missing-srv-record-service", "srv-record-service", "nat-network", @@ -351,6 +350,15 @@ mymain(void) "nat-network-dns-srv-record", "nat-network", VIR_NETWORK_UPDATE_COMMAND_DELETE); + DO_TEST("modify-srv-record-protocol", + "srv-record-modify-few", + "nat-network-dns-srv-record", + "nat-network-dns-srv-modify-few", + VIR_NETWORK_UPDATE_COMMAND_MODIFY); + DO_TEST_FAIL("modify-not-existing-srv-record", + "srv-not-existing", + "nat-network-dns-srv-record", + VIR_NETWORK_UPDATE_COMMAND_MODIFY); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;