From nobody Wed May 1 13:38:38 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=1560962774; cv=none; d=zoho.com; s=zohoarc; b=PTxI2ozmDT3fM/28+iTWYC+ZzqEL5hM/4ZW/sV9pEJfWszymPOaiKPbYT/p2sCIKQMkrlaMb+1IHTWa/u5R7zFeWPH4c10X2RH5xyOIQ2f1uuxNjjuKtd71JJHONrnrrvUwOXY694sGd7as/A7IaCUGqeUsLD/iH1O02fUxZ9w4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560962774; 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=EPtTufAVkpBoNxifrpoHLCZhHse8HaaGyePpGLgzxA0=; b=mPEy6Szwl5vMQ9AAPcNQx+PtZ72TkmZM7prITwepQpTwSMxnIKZThSQzwOQcUkRoiGVirOii9IIunu29FJT7ABtSCUtc1ceXCvWWOvu4cnN9fi5tF1BvQ9E7F1/qFYenmCv10h7T7nHNZm9ZMwITesbxL+oGH2m4Gwr3y1970AU= 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 1560962774646396.44716335815815; Wed, 19 Jun 2019 09:46:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EECF730BBE9A; Wed, 19 Jun 2019 16:46:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5B265D9D6; Wed, 19 Jun 2019 16:46:09 +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 63C641806B1D; Wed, 19 Jun 2019 16:46:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5JGjtu8019307 for ; Wed, 19 Jun 2019 12:45:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 64BF3608A7; Wed, 19 Jun 2019 16:45:55 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F8DA60605 for ; Wed, 19 Jun 2019 16:45:52 +0000 (UTC) Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) (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 E5B82307D925 for ; Wed, 19 Jun 2019 16:45:43 +0000 (UTC) Received: by mail-ed1-f67.google.com with SMTP id r12so254857edo.5 for ; Wed, 19 Jun 2019 09:45:43 -0700 (PDT) Received: from archpc.localdomain (x8d1ee222.agdsn.tu-dresden.de. [141.30.226.34]) by smtp.gmail.com with ESMTPSA id x4sm6005489eda.22.2019.06.19.09.45.40 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 09:45:41 -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=9EK++qFIywluNyeRixThdBxPq6cDdjSqAlwUta2bh9c=; b=QBJazXDmBfAnYASayMJmFFvqcGhmD/AdAQQzb2A/9GzQL0F4xjteJQrtlR1BuZOAYn kuMA/Wa6iN7u5kbnMS9Itdkn11iyqWJDGk/+XmVq5DP14lppstocyS/5pB3u9JcAjw1c DpToufNO1O3NZQuDEZMos8uosbKdP+tWEG0C0GG/07I/qDkhId81cQt/7ccCCZQIFbCZ OrrtWHEeInMoaFtsWUP4kc8VRJiPDZUUc/fgOkGec8+pgIhgTc7OyePqYvRZUqNQEPvu 2aVMP57LFYtVtjvW2qT+rFYnn7cM8BaJEeHqjoTJyPstjbFF9fOt/2kFuFI3/Dq8Kbwf Pr9w== 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=9EK++qFIywluNyeRixThdBxPq6cDdjSqAlwUta2bh9c=; b=ngoS4XamCUez5CdW2fG/M8AleYc67oTG4PHpRsPsvNKeTHeCgFXDqRD88Dsu9dJZ70 2R9TCGWCQWLdZpDy5nB9bEgitBWLAseD30WV3DXyWY2UBSAm+TQSqPU59ULNB4PUOOWB QCoLo/ccpvckiSBnhcv77PqrDCv1F93fI2l04NJfeXq0lYezh2wpFLpapB8Ur0FfDovz Qnau4Lz53VDq82vzi59lG4HiCmY6OWDv++tCiI82uPHf9Ein8CmcqVHXGpJRnFjJWdol 8nMAqWmWdYixFJkgErgHq1RTfVGlBjcT4DvE5YIqKfOgxcbbCE6qkIRHJ6IZrNdiuPSo 3ccA== X-Gm-Message-State: APjAAAU/q7qvdtZDTgWukbpT/Qt9sn8kngHKv3f/9EEpn47OvPORRgR9 0nr2o8K3q54z8IKirIgUMwyE53AK8NtZLg== X-Google-Smtp-Source: APXvYqzF4vvzrmKU33txJoxAP3NBb0fZrId4MwC7X2RIr9OfaQ8Jz7NJ1aZ29OTnAYE0zNnZ6D+8mQ== X-Received: by 2002:a50:b561:: with SMTP id z30mr79330179edd.87.1560962742247; Wed, 19 Jun 2019 09:45:42 -0700 (PDT) From: Ilias Stamatis To: libvir-list@redhat.com Date: Wed, 19 Jun 2019 18:45:30 +0200 Message-Id: <20190619164530.9721-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.48]); Wed, 19 Jun 2019 16:45:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 19 Jun 2019 16:45:44 +0000 (UTC) for IP:'209.85.208.67' DOMAIN:'mail-ed1-f67.google.com' HELO:'mail-ed1-f67.google.com' FROM:'stamatis.iliass@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.111 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS) 209.85.208.67 mail-ed1-f67.google.com 209.85.208.67 mail-ed1-f67.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] test_driver: properly handle DHCP ranges and IPv6 networks in testDomainInterfaceAddresses 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 19 Jun 2019 16:46:10 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" testDomainInterfaceAddresses always returns the same hard-coded addresses. Change the behavior such as if there is a DHCP range defined, addresses are returned from that pool. The specific address returned depends on both the domain id and the specific guest interface in an attempt to return unique addresses *most of the time*. Additionally, properly handle IPv6 networks which were previously ignored completely. Signed-off-by: Ilias Stamatis --- src/test/test_driver.c | 44 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2a0ffbc6c5..21bd95941e 100755 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3414,6 +3414,10 @@ static int testDomainBlockStats(virDomainPtr domain, return ret; } + +static virNetworkObjPtr testNetworkObjFindByName(testDriverPtr privconn, c= onst char *name); + + static int testDomainInterfaceAddresses(virDomainPtr dom, virDomainInterfacePtr **ifaces, @@ -3422,11 +3426,15 @@ testDomainInterfaceAddresses(virDomainPtr dom, { size_t i; size_t ifaces_count =3D 0; + size_t addr_offset; int ret =3D -1; char macaddr[VIR_MAC_STRING_BUFLEN]; virDomainObjPtr vm =3D NULL; virDomainInterfacePtr iface =3D NULL; virDomainInterfacePtr *ifaces_ret =3D NULL; + virSocketAddr addr; + virNetworkObjPtr net =3D NULL; + virNetworkDefPtr net_def =3D NULL; virCheckFlags(0, -1); @@ -3447,6 +3455,12 @@ testDomainInterfaceAddresses(virDomainPtr dom, goto cleanup; for (i =3D 0; i < vm->def->nnets; i++) { + if (!(net =3D testNetworkObjFindByName(dom->conn->privateData, + vm->def->nets[i]->data.networ= k.name))) + goto cleanup; + + net_def =3D virNetworkObjGetDef(net); + if (VIR_ALLOC(iface) < 0) goto cleanup; @@ -3460,14 +3474,33 @@ testDomainInterfaceAddresses(virDomainPtr dom, if (VIR_ALLOC(iface->addrs) < 0) goto cleanup; - iface->addrs[0].type =3D VIR_IP_ADDR_TYPE_IPV4; - iface->addrs[0].prefix =3D 24; - if (virAsprintf(&iface->addrs[0].addr, "192.168.0.%zu", 1 + i) < 0) - goto cleanup; - iface->naddrs =3D 1; + iface->addrs[0].prefix =3D virSocketAddrGetIPPrefix(&net_def->ips-= >address, + &net_def->ips->n= etmask, + net_def->ips->pr= efix); + + if (net_def->ips->nranges > 0) + addr =3D net_def->ips->ranges[0].start; + else + addr =3D net_def->ips->address; + + /* try using different addresses per different inf and domain */ + addr_offset =3D 20 * (vm->def->id - 1) + i + 1; + + if (net_def->ips->family && STREQ(net_def->ips->family, "ipv6")) { + iface->addrs[0].type =3D VIR_IP_ADDR_TYPE_IPV6; + addr.data.inet6.sin6_addr.s6_addr[15] +=3D addr_offset; + } else { + iface->addrs[0].type =3D VIR_IP_ADDR_TYPE_IPV4; + addr.data.inet4.sin_addr.s_addr =3D \ + htonl(ntohl(addr.data.inet4.sin_addr.s_addr) + addr_offset= ); + } + + if (!(iface->addrs[0].addr =3D virSocketAddrFormat(&addr))) + goto cleanup; VIR_APPEND_ELEMENT_INPLACE(ifaces_ret, ifaces_count, iface); + virNetworkObjEndAPI(&net); } VIR_STEAL_PTR(*ifaces, ifaces_ret); @@ -3475,6 +3508,7 @@ testDomainInterfaceAddresses(virDomainPtr dom, cleanup: virDomainObjEndAPI(&vm); + virNetworkObjEndAPI(&net); if (ifaces_ret) { for (i =3D 0; i < ifaces_count; i++) -- 2.22.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list