From nobody Mon Sep 16 19:13:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1720538621090618.1154663840355; Tue, 9 Jul 2024 08:23:41 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id F3A451260; Tue, 9 Jul 2024 11:23:39 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C220010F4; Tue, 9 Jul 2024 11:23:14 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B6EE110F4; Tue, 9 Jul 2024 11:23:11 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 1E20FCE3 for ; Tue, 9 Jul 2024 11:23:11 -0400 (EDT) Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-562-9okoqVqSPBO1USBDjdKlig-1; Tue, 09 Jul 2024 11:23:08 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F40E51955F66 for ; Tue, 9 Jul 2024 15:23:07 +0000 (UTC) Received: from ajulis-thinkpadt14gen4.remote.csb (unknown [10.43.2.246]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 539EA1955F68 for ; Tue, 9 Jul 2024 15:23:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720538590; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rr1KhZJTqilPMNd4ydcMiMbe6Q4gexQaLxF3Lf1NwyM=; b=C4jAKBPyBrOhggUM4qGAl4MqVEOP8+JXo6dP+1riySZc/jIZFfLZnWFycPulFtsMo03lq1 3BAs08jEFXne5Hkh3dJsipK2byyO9VG21zdKMsua6ug+AI6JyTe9vdsr/5adVfE2Jtwe30 HL3tvjyzSmQi6p7VDUYvMz1O8EeCW+s= X-MC-Unique: 9okoqVqSPBO1USBDjdKlig-1 From: Adam Julis To: devel@lists.libvirt.org Subject: [PATCH] network: allow "modify" option for DNS hostname Date: Tue, 9 Jul 2024 17:23:02 +0200 Message-ID: <4bb180e02afe3848b33d2b1ad47d95c54c0d538c.1720538538.git.ajulis@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DBS3NQEEJ7HZDP3JYAGTZH26UVLS64FV X-Message-ID-Hash: DBS3NQEEJ7HZDP3JYAGTZH26UVLS64FV X-MailFrom: ajulis@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1720538643102116600 Content-Type: text/plain; charset="utf-8"; x-default="true" The "modify" command allows you to replace an existing record (its hostname, sub-elements). IP address acts as the primary key. If it is not found, the attempt ends with an error message. If the XML contains a duplicate address, it will select the last one. Tests in networkxml2xmlupdatetest.c contain replacements of an existing DNS-Host 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 --- src/conf/network_conf.c | 28 ++++++++++++++----- .../dns-host-modify-not-existing.xml | 4 +++ .../dns-host-modify.xml | 5 ++++ .../nat-network-dns-hosts-modified.xml | 28 +++++++++++++++++++ tests/networkxml2xmlupdatetest.c | 9 ++++++ 5 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 tests/networkxml2xmlupdatein/dns-host-modify-not-existi= ng.xml create mode 100644 tests/networkxml2xmlupdatein/dns-host-modify.xml create mode 100644 tests/networkxml2xmlupdateout/nat-network-dns-hosts-mod= ified.xml diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index f5ccf4bd12..2a541cd5b0 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -3138,19 +3138,13 @@ virNetworkDefUpdateDNSHost(virNetworkDef *def, unsigned int fflags G_GNUC_UNUSED) { size_t i, j, k; - int foundIdx =3D -1, ret =3D -1; + int foundIdx =3D -1, ret =3D -1, foundIdxModify =3D -1; virNetworkDNSDef *dns =3D &def->dns; virNetworkDNSHostDef host =3D { 0 }; bool isAdd =3D (command =3D=3D VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command =3D=3D VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); int foundCt =3D 0; =20 - if (command =3D=3D VIR_NETWORK_UPDATE_COMMAND_MODIFY) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("DNS HOST records cannot be modified, only added = or deleted")); - goto cleanup; - } - if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "host") < 0) goto cleanup; =20 @@ -3163,6 +3157,12 @@ virNetworkDefUpdateDNSHost(virNetworkDef *def, if (virSocketAddrEqual(&host.ip, &dns->hosts[i].ip)) foundThisTime =3D true; =20 + /* modify option required index of matching ip-address, the loop u= nder + * this comment could affect results of found index foundThisTime, + * so the foundIdxModify is there used instead */ + if (foundThisTime) + foundIdxModify =3D i; + /* when adding we want to only check duplicates of address since h= aving * multiple addresses with the same hostname is a legitimate confi= guration */ if (!isAdd) { @@ -3213,6 +3213,20 @@ virNetworkDefUpdateDNSHost(virNetworkDef *def, virNetworkDNSHostDefClear(&dns->hosts[foundIdx]); VIR_DELETE_ELEMENT(dns->hosts, foundIdx, dns->nhosts); =20 + } else if (command =3D=3D VIR_NETWORK_UPDATE_COMMAND_MODIFY) { + + if (foundCt =3D=3D 0) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("couldn't locate a matching DNS HOST record i= n network %1$s"), + def->name); + goto cleanup; + } + + virNetworkDNSHostDefClear(&dns->hosts[foundIdxModify]); + + memcpy(&dns->hosts[foundIdxModify], &host, sizeof(virNetworkDNSHos= tDef)); + memset(&host, 0, sizeof(virNetworkDNSHostDef)); + } else { virNetworkDefUpdateUnknownCommand(command); goto cleanup; diff --git a/tests/networkxml2xmlupdatein/dns-host-modify-not-existing.xml = b/tests/networkxml2xmlupdatein/dns-host-modify-not-existing.xml new file mode 100644 index 0000000000..357fccd110 --- /dev/null +++ b/tests/networkxml2xmlupdatein/dns-host-modify-not-existing.xml @@ -0,0 +1,4 @@ + + shared + names + diff --git a/tests/networkxml2xmlupdatein/dns-host-modify.xml b/tests/netwo= rkxml2xmlupdatein/dns-host-modify.xml new file mode 100644 index 0000000000..78b9fd88a6 --- /dev/null +++ b/tests/networkxml2xmlupdatein/dns-host-modify.xml @@ -0,0 +1,5 @@ + + Another + decent + names + diff --git a/tests/networkxml2xmlupdateout/nat-network-dns-hosts-modified.x= ml b/tests/networkxml2xmlupdateout/nat-network-dns-hosts-modified.xml new file mode 100644 index 0000000000..8fcaad15d1 --- /dev/null +++ b/tests/networkxml2xmlupdateout/nat-network-dns-hosts-modified.xml @@ -0,0 +1,28 @@ + + default + 81ff0d90-c91e-6742-64da-4a736edb9a9c + + + + + + + pudding + + + host + gateway + + + Another + decent + names + + + shared + names + + + + + diff --git a/tests/networkxml2xmlupdatetest.c b/tests/networkxml2xmlupdatet= est.c index afe2b1f574..383cbf85ce 100644 --- a/tests/networkxml2xmlupdatetest.c +++ b/tests/networkxml2xmlupdatetest.c @@ -276,6 +276,15 @@ mymain(void) "nat-network-dns-hosts", "nat-network-no-hosts", VIR_NETWORK_UPDATE_COMMAND_DELETE); + DO_TEST("modify-dns-host", + "dns-host-modify", + "nat-network-dns-hosts", + "nat-network-dns-hosts-modified", + VIR_NETWORK_UPDATE_COMMAND_MODIFY); + DO_TEST_FAIL("modify-dns-host-not-existing", + "dns-host-modify-not-existing", + "nat-network-dns-hosts", + VIR_NETWORK_UPDATE_COMMAND_MODIFY); =20 =20 section =3D VIR_NETWORK_SECTION_DNS_TXT; --=20 2.45.2