From nobody Mon Apr 29 06:54:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1561403602; cv=none; d=zoho.com; s=zohoarc; b=hcRrtbJTFD73wIK2lasGxf/FIHn4oDRlzc4DjeAUbgCUJAfUUlcIJ0owo5h//5ZpDQrc3RFlLmfJEuqAtcxoSwmRC8jZZXXCbaw/JfN4FUXM9iki8I1h+ajPTRBeQI9Cc0aYLHgtjahz+uuLzQJ70dpkBZGJcSZ1O7LXl8ivLrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1561403602; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=JBVxhvV8qA71aR85W9BAvfw+z/vcxdBAiNdbvgSu23M=; b=leppOIztw3jQBH39F22454fKobKIo0QcDcRkVr0g7VC1p9GGNBUc3mjX/FKs6NC2dgVP99AoMPKZiaEIFdWbudT5yxNaxHJuGo8CKkfhBq3J+QOmLibtOa4X5G1ygfKxrwo89hDK59qUd8e2EU/dwnjCDAn6MHjJRUUexiAOLPE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1561403602335681.6279141539009; Mon, 24 Jun 2019 12:13:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6BD7356CA; Mon, 24 Jun 2019 19:12:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 815E45D71A; Mon, 24 Jun 2019 19:12:25 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E6571206D2; Mon, 24 Jun 2019 19:12:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5OJAwvx019789 for ; Mon, 24 Jun 2019 15:10:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id D76F65D9D3; Mon, 24 Jun 2019 19:10:58 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CEC665D9C5 for ; Mon, 24 Jun 2019 19:10:56 +0000 (UTC) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13C6E3082E6A for ; Mon, 24 Jun 2019 19:10:45 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id x15so412132wmj.3 for ; Mon, 24 Jun 2019 12:10:44 -0700 (PDT) Received: from archpc.localdomain (x8d1ee222.agdsn.tu-dresden.de. [141.30.226.34]) by smtp.gmail.com with ESMTPSA id p3sm8594281wrd.47.2019.06.24.12.10.41 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 24 Jun 2019 12:10:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=tj5J5tw+y4URMyqYrpb1Ou4EL5ePlv/e1lB8/bVczQM=; b=u2YfhPIKsL9GPdDybSAniC/tlXKGfjC74WUA1zicEiFBFOI53AwLSrcpKRRnVWoRGD ZvYwJnrSE6PZvuwdATylduf/lS0eO7rmg8w4MdrSYdw73d7MC5HCgu6zWTazQVfgprMe str8T2XQwiQ3kj6gLimrs+SxIimtTal0GG5Erzxuvhg11FSyrbkpMyEkUf5+IvULskdm gOWeJQdlfBFfi3ABg7N8/Djng7Z/SWZnswTHYF22d1bQjN7H59FLI8+60JmDJoISvZtS 8bYWToXeSWpbsYZMYk2BnNQPJ5XlVqcpnPnluEE71FbneRk6UzXHhIgk6+ngzphYzXY+ talw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=tj5J5tw+y4URMyqYrpb1Ou4EL5ePlv/e1lB8/bVczQM=; b=YSub1Tj1yBGoooLKvnsVyavPQasDjPTalLOO/A6MTnGbHPH7IVGsl2RwnAb7RzEgh4 FcoFVufv74yogf5w+mTku5Yr/OtFBXgAvlQdKgGzNL6whsAFrhzwMlkTfdElE0aozm1D TzZOGsyQ+OyhkHpanmmXgU0Dai+TRdEW3E8dbp3gG3sdSmzByQmPJs0QYJMxfsG3cmT5 PfKj9B1Vc52HdzfzYQxz//7szflBzslXK9gf+MTejqQRzHgrfwU4llfCDyFGTx9aJO3w 7mSZdhzkn42As+toiJMaMIDn62moHAd03YBcUCD7cZ7v/5wF6a8phJFLG+j/5NOlqZfs eOcA== X-Gm-Message-State: APjAAAWSvHByVYq5E4QEWHIMT46szqOLfsRBoW9QHodpeWEPRs2o3Wex Inp8fLLlznxaHUEqsa3ZMPj8G4mCh+l9BQ== X-Google-Smtp-Source: APXvYqzzlXwa0JYj/+aVssCcdk07wQahG/CpY2z/PqVNZmXtg7FJha3zyJ2LHVc2JLu9p47SqERn7Q== X-Received: by 2002:a1c:2311:: with SMTP id j17mr8814028wmj.84.1561403443238; Mon, 24 Jun 2019 12:10:43 -0700 (PDT) From: Ilias Stamatis To: libvir-list@redhat.com Date: Mon, 24 Jun 2019 21:10:36 +0200 Message-Id: <20190624191036.18868-1-stamatis.iliass@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 24 Jun 2019 19:10:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 24 Jun 2019 19:10:45 +0000 (UTC) for IP:'209.85.128.68' DOMAIN:'mail-wm1-f68.google.com' HELO:'mail-wm1-f68.google.com' FROM:'stamatis.iliass@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.11 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS) 209.85.128.68 mail-wm1-f68.google.com 209.85.128.68 mail-wm1-f68.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] test_driver: implement virNetworkGetDHCPLeases X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 24 Jun 2019 19:13:15 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Ilias Stamatis --- src/test/test_driver.c | 141 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 4b1f2724a0..180940f859 100755 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4072,6 +4072,146 @@ testNetworkSetAutostart(virNetworkPtr net, } +static int +testNetworkGetDHCPLeases(virNetworkPtr net, + const char *mac, + virNetworkDHCPLeasePtr **leases, + unsigned int flags) +{ + int ret =3D -1; + int ndomains =3D 0; + size_t i, j; + size_t nleases =3D 0; + size_t addr_offset; + bool need_results =3D !!leases; + char *hostname =3D NULL; + VIR_AUTOFREE(char *) bridge_name =3D NULL; + char mac_str[VIR_MAC_STRING_BUFLEN]; + virMacAddr mac_addr; + virDomainObjPtr vm =3D NULL; + virDomainPtr *domains =3D NULL; + virDomainNetDefPtr inf =3D NULL; + virNetworkObjPtr obj =3D NULL; + virNetworkDefPtr obj_def =3D NULL; + virNetworkDHCPLeasePtr lease =3D NULL; + virNetworkDHCPLeasePtr *leases_ret =3D NULL; + virDomainInterfacePtr iface =3D NULL; + testDriverPtr privconn =3D net->conn->privateData; + + virCheckFlags(0, -1); + + if (mac && virMacAddrParse(mac, &mac_addr) < 0) { + virReportError(VIR_ERR_INVALID_MAC, "%s", mac); + return -1; + } + + if (!(obj =3D testNetworkObjFindByName(privconn, net->name))) + return -1; + + obj_def =3D virNetworkObjGetDef(obj); + + if (VIR_STRDUP(bridge_name, obj_def->bridge) < 0) + goto cleanup; + + virNetworkObjEndAPI(&obj); + + if ((ndomains =3D virDomainObjListExport(privconn->domains, net->conn,= &domains, + NULL, VIR_CONNECT_LIST_DOMAINS_= ACTIVE)) < 0) + goto cleanup; + + for (i =3D 0; i < ndomains; i++) { + /* the following must be called before testDomObjFromDomain */ + hostname =3D testDomainGetHostname(domains[i], 0); + + if (!(vm =3D testDomObjFromDomain(domains[i]))) + continue; + + for (j =3D 0; j < vm->def->nnets; j++) { + inf =3D vm->def->nets[j]; + + if (STRNEQ(inf->data.network.name, net->name)) + continue; + + virMacAddrFormat(&inf->mac, mac_str); + if (mac && virMacAddrCompare(mac, mac_str)) + continue; + + if (!need_results) { + nleases++; + continue; + } + + if (VIR_ALLOC(lease) < 0 || VIR_ALLOC(iface) < 0 || VIR_ALLOC(= iface->addrs) < 0) + goto error; + iface->naddrs =3D 1; + + /* should be the same value as in testDomainInterfaceAddresses= */ + addr_offset =3D 20 * (vm->def->id - 1) + j + 1; + if (testDomainInterfaceAddressFromNet(privconn, inf, addr_offs= et, iface) < 0) + goto error; + + if (VIR_STRDUP(lease->mac, mac_str) < 0 || + VIR_STRDUP(lease->iface, bridge_name) < 0 || + VIR_STRDUP(lease->hostname, hostname) < 0 || + VIR_STRDUP(lease->ipaddr, iface->addrs->addr) < 0) + goto error; + + lease->prefix =3D iface->addrs->prefix; + lease->type =3D iface->addrs->type; + + virDomainInterfaceFree(iface); + iface =3D NULL; + + lease->expirytime =3D 0; + + lease->iaid =3D NULL; + if (lease->type =3D=3D VIR_IP_ADDR_TYPE_IPV6) { + if (VIR_STRDUP(lease->clientid, + "00:01:00:01:16:C1:BA:6E:08:00:27:30:C3:B8"= ) < 0) + goto error; + } else { + lease->clientid =3D NULL; + } + + if (VIR_INSERT_ELEMENT(leases_ret, nleases, nleases, lease) < = 0) + goto error; + } + + VIR_FREE(hostname); + virDomainObjEndAPI(&vm); + } + + if (leases_ret) { + /* NULL terminated array */ + ignore_value(VIR_REALLOC_N(leases_ret, nleases + 1)); + VIR_STEAL_PTR(*leases, leases_ret); + } + + ret =3D nleases; + + cleanup: + for (i =3D 0; i < ndomains; i++) + virDomainFree(domains[i]); + + VIR_FREE(domains); + VIR_FREE(lease); + VIR_FREE(hostname); + + virNetworkObjEndAPI(&obj); + virDomainInterfaceFree(iface); + virDomainObjEndAPI(&vm); + return ret; + + error: + if (leases_ret) { + for (i =3D 0; i < nleases; i++) + virNetworkDHCPLeaseFree(leases_ret[i]); + VIR_FREE(leases_ret); + } + goto cleanup; +} + + /* * Physical host interface routines */ @@ -7359,6 +7499,7 @@ static virNetworkDriver testNetworkDriver =3D { .networkGetBridgeName =3D testNetworkGetBridgeName, /* 0.3.2 */ .networkGetAutostart =3D testNetworkGetAutostart, /* 0.3.2 */ .networkSetAutostart =3D testNetworkSetAutostart, /* 0.3.2 */ + .networkGetDHCPLeases =3D testNetworkGetDHCPLeases, /* 5.5.0 */ .networkIsActive =3D testNetworkIsActive, /* 0.7.3 */ .networkIsPersistent =3D testNetworkIsPersistent, /* 0.7.3 */ }; -- 2.22.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list