From nobody Mon Feb 9 00:54:11 2026 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=1560943214; cv=none; d=zoho.com; s=zohoarc; b=dlOC5PXhICu/POfeCU4ILmkJV7MpNdHXWsRI2WWWbi/zU07ZOqg811e0eFAaW1vnBQBGUhcy3SrC3/BVmBUDQakUCjo9qx5uJVxMA0GE/S53wjZ7znwj7PV05mq27QtMwVTEEO7OOU17JHfK7cOdDJZJ9z7K//i2a+/cdK44I28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560943214; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=h25RYCpSw9e61tJAUOrZTnV6FquH3zyNdX9c3KfwVp0=; b=STfICdzXnEhQHY83ksfbyCW8otii1G/Ms0KlgiDA/FnavfiXooj4kJZReYuJZ547N0vu3P1s0PMRv3AsC6lN8BX2TInEj41051gAGyVuVhr4g7YeVKlXIgBrZngODu1fO4YOdhaU3o8iZ4TH79HNOxufvEhVMdDKYUQIHEalP9k= 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 1560943214946936.7193307337976; Wed, 19 Jun 2019 04:20:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0859A368B1; Wed, 19 Jun 2019 11:20:03 +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 BC3B919C6F; Wed, 19 Jun 2019 11:20: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 76F201806B1A; Wed, 19 Jun 2019 11:19:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5JBJpn1012291 for ; Wed, 19 Jun 2019 07:19:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6588C19C6F; Wed, 19 Jun 2019 11:19:51 +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 5E76319C6A for ; Wed, 19 Jun 2019 11:19:49 +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 5E167308A9E2 for ; Wed, 19 Jun 2019 11:19:44 +0000 (UTC) Received: by mail-ed1-f65.google.com with SMTP id p15so26622111eds.8 for ; Wed, 19 Jun 2019 04:19:44 -0700 (PDT) Received: from archpc.localdomain (x8d1ee222.agdsn.tu-dresden.de. [141.30.226.34]) by smtp.gmail.com with ESMTPSA id y21sm3183020ejm.60.2019.06.19.04.19.41 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 04:19: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:in-reply-to:references:mime-version :content-transfer-encoding; bh=kXn/bMH0eblccv4qGoZnLzhDXO2lfKSdXva1QcHjM38=; b=Ewag1GWNovCryvew2/7hfeWlHxLbEokxOdMRJKkkM3ZdiTpADXyjdnNrq3YrPayy0I uchjK2XwvdF3S6QZ1+r07q5/Iw4pA6fJT/8PFzaly9gph2LtEq+rfeSp11vKin/2rXph nL+SZ+OVS/GBRiSl3L3nkwfxKGnEURHjRer2sBMa8zdW5svKZltbiBbHfg4CQVEB87bE lHa9VE2lLeBWKrcJC6qjjemnbbF7w/tWUOzWmV7pVXA4jULb8gkOvMjlS0qzYA1XJwsT mLdPJS+aug/yquy8LOdA1dr3UqPVPr5bkZXNhhlvR3Nwv2wnK7luaif3ZCJGRuw5dXwn uMNQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=kXn/bMH0eblccv4qGoZnLzhDXO2lfKSdXva1QcHjM38=; b=sw3MGlOkHXt5pyMtoWKzEaOHj3MEC42rs0Px6P9RYseA6GfME76FWN9yQYI19/I2Ez vnQKR5YpY0lpRwNUP4yY5RoOWFlRSsoWOvlrvkv7qIomAX0NMLYIIyhhURFT28+keJAi 1h++BIANn3KnEcDqY2GmOYr14Ii8r5i4TrNjYcw4nxw4iNLaWdlFu2WCFGe9wMpZQHZ8 DzSHbFm0JlnCdopvgPRhEM7X4LRCUfif8cGSVqCNzmExGfFVCaERDubmTCblI9PWlzWQ 1GoG3tPQPKVWQi7ZAPHSyOv0LK4bh2B0YmXuxegYG9ORvO41gM2Gcgr8PDPAHOPkOJkN W2nw== X-Gm-Message-State: APjAAAW9Emfjr/x92nrpglRYVdk8rnRxp+hzeT53LObKszIQ2wiVDjy1 TMMO3z8AmybbytXCUtOiJKa0SNibMQh2Kg== X-Google-Smtp-Source: APXvYqwe887qRgrYcZFRRY+2EJTTCnyXsoh09zTalFpoiwbtARgm6oVu8QbWYYSDPfy5y18MJtO0Vw== X-Received: by 2002:a50:eb96:: with SMTP id y22mr17784937edr.211.1560943182591; Wed, 19 Jun 2019 04:19:42 -0700 (PDT) From: Ilias Stamatis To: libvir-list@redhat.com Date: Wed, 19 Jun 2019 13:18:17 +0200 Message-Id: <20190619111817.19562-4-stamatis.iliass@gmail.com> In-Reply-To: <20190619111817.19562-1-stamatis.iliass@gmail.com> References: <20190619111817.19562-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]); Wed, 19 Jun 2019 11:19:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 19 Jun 2019 11:19:44 +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.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.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.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] test_driver: consider DHCP ranges 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 19 Jun 2019 11:20:05 +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, return IPv6 addresses too when needed. Signed-off-by: Ilias Stamatis --- src/test/test_driver.c | 78 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 0c2cfdd2f7..96142b549c 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "virerror.h" @@ -3380,6 +3381,11 @@ static int testDomainBlockStats(virDomainPtr domain, return ret; } + +static virNetworkObjPtr testNetworkObjFindByName(testDriverPtr privconn, c= onst char *name); +static virNetworkPtr testNetworkLookupByName(virConnectPtr conn, const cha= r *name); + + static int testDomainInterfaceAddresses(virDomainPtr dom, virDomainInterfacePtr **ifaces, @@ -3388,11 +3394,18 @@ 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]; + char ip_str[INET6_ADDRSTRLEN]; + struct sockaddr_in ipv4_addr; + struct sockaddr_in6 ipv6_addr; virDomainObjPtr vm =3D NULL; virDomainInterfacePtr iface =3D NULL; virDomainInterfacePtr *ifaces_ret =3D NULL; + virNetworkPtr net =3D NULL; + virNetworkObjPtr net_obj =3D NULL; + virNetworkDefPtr net_obj_def =3D NULL; virCheckFlags(0, -1); @@ -3413,6 +3426,16 @@ testDomainInterfaceAddresses(virDomainPtr dom, if (vm->def->nets[i]->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) continue; + virObjectUnref(net); + if (!(net =3D testNetworkLookupByName(dom->conn, + vm->def->nets[i]->data.network= .name))) + goto cleanup; + + if (!(net_obj =3D testNetworkObjFindByName(net->conn->privateData,= net->name))) + goto cleanup; + + net_obj_def =3D virNetworkObjGetDef(net_obj); + if (VIR_ALLOC(iface) < 0) goto cleanup; @@ -3426,15 +3449,58 @@ 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; + if (net_obj_def->ips->family && STREQ(net_obj_def->ips->family, "i= pv6")) + iface->addrs[0].type =3D VIR_IP_ADDR_TYPE_IPV6; + else + iface->addrs[0].type =3D VIR_IP_ADDR_TYPE_IPV4; + + /* try using different addresses per different inf and domain */ + addr_offset =3D 20 * (vm->def->id - 1) + i; + + if (net_obj_def->ips->nranges > 0) { + /* use ip addresses from the defined DHCP range */ + + if (iface->addrs[0].type =3D=3D VIR_IP_ADDR_TYPE_IPV6) { + ipv6_addr =3D net_obj_def->ips->ranges[0].start.data.inet6; + ipv6_addr.sin6_addr.s6_addr[15] +=3D addr_offset; + inet_ntop(AF_INET6, &(ipv6_addr.sin6_addr), ip_str, INET6_= ADDRSTRLEN); + } else { + ipv4_addr =3D net_obj_def->ips->ranges[0].start.data.inet4; + ipv4_addr.sin_addr.s_addr =3D htonl(ntohl(ipv4_addr.sin_ad= dr.s_addr) + + addr_offset); + inet_ntop(AF_INET, &(ipv4_addr.sin_addr), ip_str, INET_ADD= RSTRLEN); + } + + if (VIR_STRDUP(iface->addrs[0].addr, ip_str) < 0) + goto cleanup; + + iface->addrs[0].prefix =3D virSocketAddrGetIPPrefix( + &net_obj_def->ips->ranges[0].star= t, + &net_obj_def->ips->netmask, + net_obj_def->ips->prefix); + + } else { + /* use hard-coded addresses when a DHCP range isn't defined */ + + if (iface->addrs[0].type =3D=3D VIR_IP_ADDR_TYPE_IPV6) { + iface->addrs[0].prefix =3D 64; + if (virAsprintf(&iface->addrs[0].addr, "fc00::%zu", + 1 + addr_offset) < 0) + goto cleanup; + } else { + iface->addrs[0].prefix =3D 24; + if (virAsprintf(&iface->addrs[0].addr, "192.168.0.%zu", + 1 + addr_offset) < 0) + goto cleanup; + } + } + if (VIR_APPEND_ELEMENT(ifaces_ret, ifaces_count, iface) < 0) goto cleanup; + + virNetworkObjEndAPI(&net_obj); } VIR_STEAL_PTR(*ifaces, ifaces_ret); @@ -3442,6 +3508,8 @@ testDomainInterfaceAddresses(virDomainPtr dom, cleanup: virDomainObjEndAPI(&vm); + virNetworkObjEndAPI(&net_obj); + virObjectUnref(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