From nobody Fri Apr 26 21:23:30 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=1559988455; cv=none; d=zoho.com; s=zohoarc; b=LjCdEvK9MBUPfeML1ntZwShUONtF8waQ2MsDVJ5x6xd0Vz/dsEHm0kGtTl5oMA1FRLRAekLMunmac/YgJEYvTa8Sm0JQS5xhD7auA7doKcB1eO242RzlYKs2OjyE5XFa8dINFOa4owoYQqSokdH2VuPwlg9FQP0vFRC5OaHBgUU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559988455; 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=U+qh6VsnkaT0M4zgOTlYoYHKcrlc/7C1q9jcnZj0Jsw=; b=lFOqwdc5ON2e5cDaf+54bAKEjrJTRs7zZrWz+ZP7oXfytiCYT46V33nv+tvnNLi5vhf6EAzSHkGy44HvvlaLqw9Mcb98ddu/xNI7EZcxPrKKKeO48MXtNLZm0Pp84rVJKquGPN2BehY9fOZRneBywwo2wYrA7v2hPEHr4AcjZDI= 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 1559988455865790.9189862210808; Sat, 8 Jun 2019 03:07:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 43A034E92A; Sat, 8 Jun 2019 10:07:04 +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 44AE9601AF; Sat, 8 Jun 2019 10:07:01 +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 236873D87; Sat, 8 Jun 2019 10:06:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x58A0kqJ011108 for ; Sat, 8 Jun 2019 06:00:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id CDDEF6012D; Sat, 8 Jun 2019 10:00:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7BCD600C6 for ; Sat, 8 Jun 2019 10:00:44 +0000 (UTC) Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) (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 6CB2A3091782 for ; Sat, 8 Jun 2019 10:00:43 +0000 (UTC) Received: by mail-ed1-f65.google.com with SMTP id h10so6228531edi.13 for ; Sat, 08 Jun 2019 03:00:43 -0700 (PDT) Received: from archpc.localdomain (x8d1ee222.agdsn.tu-dresden.de. [141.30.226.34]) by smtp.gmail.com with ESMTPSA id e45sm1204725edb.12.2019.06.08.03.00.40 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 08 Jun 2019 03:00:40 -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=avCe3A2Lg6ycgU/G6DVwmJcpyACoVNPSyQGPyWZ71ts=; b=eyZn+I9zv8V78OEhAbdhh4sKY/rVy5/91tflhcoXsungbAWyESgfF0FFkaU3891j+9 9EcQDVYjauJP+NmM8FcHM1OXJlIaaAj+Re2WEHEVyMCQ1Z946Wjgwfgj49G6YZ8oh+lT NaFdlIb+kez0khH6TLUqcKgpgazLjHfDHheIoIEqvg5oAxdlkow97nmUiPRPPhs+IOcw HU4dH/EJFgLRHm9faneEVshUQfJVKdMPN6ENttWJL+0imVS1FRonuOuYBi9JRFErE+6/ sxSDXk559vGz9ITz8KSWB4OWN+3TX1PwwQR1hGWKbG3bzty5dsyn9RFSftRiUEUrp4qr NdhA== 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=avCe3A2Lg6ycgU/G6DVwmJcpyACoVNPSyQGPyWZ71ts=; b=j6UD+ojzl/VFa+Dzk72tW/pmxf10Sy4ASG58qotib5n6S3BHtkX+vRAVXvi3NEddY1 yqOtGgsFn0i6LuICyV1Gq9cNx7CWc5rJ5zpMTTyeieXprKmLBYTTDJJmFo+gCOhwMmQx 9FH/y2NmSxIobYwLJExwRufUO8xyTTetRcQ1s0CN4FAa7OPbzH9/15ad6B5pRbeLVdrl Pv0Pj0zAvV1seNSYzN+3/g1eGslBGWFaWQlv1kMv5/X3qcaMhY18Pl41FTJhnyLceYXb sinwdU1ths41jiAJCUkAMBmfzcN0qQi4ft7r7e/YfuC4D/0yJq2z5PDhpnVyBiMsbR2I S+wQ== X-Gm-Message-State: APjAAAUXDKDyFvefOVx4yt5TINjp1ehCxiO2bG5gXncxtSjedmNJzlKU hHRllbsKxBm02q3b5+JKSXKJO9pGTM0= X-Google-Smtp-Source: APXvYqziWnJie6f2CN4/D87jf2Y7mZoylVtJSIvK0My0b/jXo2yyElg7Ko1hBMGlVwQQ4tkw/sg0LQ== X-Received: by 2002:a17:906:5210:: with SMTP id g16mr29498229ejm.148.1559988041675; Sat, 08 Jun 2019 03:00:41 -0700 (PDT) From: Ilias Stamatis To: libvir-list@redhat.com Date: Sat, 8 Jun 2019 12:00:32 +0200 Message-Id: <20190608100032.23243-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.41]); Sat, 08 Jun 2019 10:00:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Sat, 08 Jun 2019 10:00:43 +0000 (UTC) for IP:'209.85.208.65' DOMAIN:'mail-ed1-f65.google.com' HELO:'mail-ed1-f65.google.com' FROM:'stamatis.iliass@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.773 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS) 209.85.208.65 mail-ed1-f65.google.com 209.85.208.65 mail-ed1-f65.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 08 Jun 2019 10:07:29 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Return infinite time DHCP leases for fixed IPV4 addresses. Signed-off-by: Ilias Stamatis --- src/test/test_driver.c | 118 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 1aa79ce898..b7f8f6ecf2 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3831,6 +3831,123 @@ 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; + bool need_results =3D !!leases; + char *hostname =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; + 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))) + goto cleanup; + obj_def =3D virNetworkObjGetDef(obj); + + ndomains =3D virDomainObjListExport(privconn->domains, net->conn, &dom= ains, + NULL, VIR_CONNECT_LIST_DOMAINS_ACTIV= E); + if (ndomains < 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, obj_def->name)) + continue; + + virMacAddrFormat(&inf->mac, mac_str); + if (mac && virMacAddrCompare(mac, mac_str)) + continue; + + if (!need_results) { + nleases++; + continue; + } + + if (VIR_ALLOC(lease) < 0) + goto error; + + /* the lease is for infinite time */ + lease->expirytime =3D 0; + + if ((VIR_STRDUP(lease->mac, mac_str) < 0) || + (VIR_STRDUP(lease->iface, obj_def->bridge) < 0) || + (VIR_STRDUP(lease->hostname, hostname) < 0)) + goto error; + + lease->prefix =3D 24; + lease->type =3D VIR_IP_ADDR_TYPE_IPV4; + if (virAsprintf(&lease->ipaddr, "192.168.0.%zu", 1 + j) < 0) + goto error; + + lease->iaid =3D 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(hostname); + virNetworkObjEndAPI(&obj); + return ret; + + error: + VIR_FREE(lease); + + if (leases_ret) { + for (i =3D 0; i < nleases; i++) + virNetworkDHCPLeaseFree(leases_ret[i]); + VIR_FREE(leases_ret); + } + + virDomainObjEndAPI(&vm); + goto cleanup; +} + + /* * Physical host interface routines */ @@ -7114,6 +7231,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.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list