From nobody Fri May 17 05:26:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1693581184; cv=none; d=zohomail.com; s=zohoarc; b=CGDcGX+tWSNq0ElG/nxaZcMLT6ZNCqyh8fFS9XeirmqQEYr28aXFfptCfU8pIKQ1grY8JEgepGk0KHJr6WWGebfUj2JRV/GFZ29OvdC42MAMh8UVT0jhD6DrGp8eq3tgBUFYzmn2pzbuGeTfpNotJtE6nhzPJq4q9/V9OfnCAok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693581184; 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; bh=dKFmn7eoIuJSxWI5MVy51qBlKDYfTAD6QmY4JFhtQhk=; b=dVuvgNNsJ00nLXU7wUnBL1R58Sj5FqlRe6PwHQMmGW4F+ZYLEYnvcHJbwjs/fCsMQC6Iv2EJrnLqfI7bD/LRui+0LIvqwepyllEvzJWsySiHjIe9kqlykp8y9f1c/oPtYu0XQIWLiOQO7ZWZT9jrnENQMn34+b5Ioc5nEuypZrg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1693581184785808.2334486286991; Fri, 1 Sep 2023 08:13:04 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-124-lYyoOwjSNYuW2FYT7nRb5g-1; Fri, 01 Sep 2023 11:12:26 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 18F368008A4; Fri, 1 Sep 2023 15:12:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0223949310F; Fri, 1 Sep 2023 15:12:24 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B24A01946A46; Fri, 1 Sep 2023 15:12:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 07B8B19465B7 for ; Fri, 1 Sep 2023 15:12:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DD816493110; Fri, 1 Sep 2023 15:12:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D68AC49310F for ; Fri, 1 Sep 2023 15:12:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B8CCA80B709 for ; Fri, 1 Sep 2023 15:12:22 +0000 (UTC) Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-73-NhsDGP9WOpq4CKaaJxPHrg-1; Fri, 01 Sep 2023 11:12:21 -0400 Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-997c891a88dso149207066b.3 for ; Fri, 01 Sep 2023 08:12:21 -0700 (PDT) Received: from wheatley.localdomain (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id rk17-20020a170907215100b00985ed2f1584sm2065562ejb.187.2023.09.01.08.12.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 08:12:19 -0700 (PDT) Received: from wheatley.brq.redhat.com (wheatley.k8r.cz [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id 65E2E13E6A6B5 for ; Fri, 1 Sep 2023 17:12:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1693581183; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dKFmn7eoIuJSxWI5MVy51qBlKDYfTAD6QmY4JFhtQhk=; b=GyTiqJcH69xNTyri+wk/ZX5DR2zyuBFpbiQYoEmHygkZ4WNS+UI0ShiDUmCaCAPeSLMiQJ cne8UnE2UZjVQTHPt9wxO2nRTm0ZM3qZwrhQKVrsvDTTUTtohnBmf2/fOZKyNbIusfaCr7 daobscVPOt1pqB5rDVjkooVk01i4pOg= X-MC-Unique: lYyoOwjSNYuW2FYT7nRb5g-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: NhsDGP9WOpq4CKaaJxPHrg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693581140; x=1694185940; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dKFmn7eoIuJSxWI5MVy51qBlKDYfTAD6QmY4JFhtQhk=; b=LMfnbKTLk8dt4bk538E5x1OwYMlwe17Wflt9moTMOns4dYyXHiY0dUaRAZb9rrx01n NsxoMScbQUnTXTzdxMCgPVqMZzPt/VW98HbE/BWezId3SVuAgmda6ocWPx/je7pfOWT9 JPKSYKoRal+WrppPS6ptJxQ7dHxGau3RIvyB47NLjOmYQHp7g9Zue8LmLB3RPqalOq7t VFVkP5wo9qf+wWS4WobMGCfOWkrjOJbzdujXUWwlfcSBvZfPPbHU5ozpb8IS3YSYWqXw SG+bCLayf4QuPohvl2+Drp/7R8hcaFEllpvlxz+WcmkmDhgHbRE1+RM+lL3n26rClZtE 8dlQ== X-Gm-Message-State: AOJu0YxsaI+RgzfA6q4vI2im22iT17hpiNrSf5SrX/g2kexMCN13+Ja7 83l1lTLBLhFyurHEoXkV1KvkoRlOJQYK2JPMEMbTS6IYTLW6QFLvEOyxtDTTWNWusXXOAJIdIKD hScTSDKamSTCy6dml8BKvXubSJPi051uq1vn+4QNrA4Kn+7GfQtyz2Vg30+xK5QpZFaVO9laAce AZixI= X-Received: by 2002:a17:907:58d:b0:9a2:1b6d:eeca with SMTP id vw13-20020a170907058d00b009a21b6deecamr2010015ejb.44.1693581140365; Fri, 01 Sep 2023 08:12:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG03AYqIaprWSpBf775C+2DL2ocY9sVn2hE7RpEl4npivqGJQdHBZsbeTYLIPogTAQXKlVjzQ== X-Received: by 2002:a17:907:58d:b0:9a2:1b6d:eeca with SMTP id vw13-20020a170907058d00b009a21b6deecamr2010001ejb.44.1693581140086; Fri, 01 Sep 2023 08:12:20 -0700 (PDT) From: Martin Kletzander To: libvir-list@redhat.com Subject: [PATCH] conf: Generate MAC address instead of keeping all zeroes Date: Fri, 1 Sep 2023 17:12:15 +0200 Message-ID: <01546933f264d901d624005f8eb10a62f3de5333.1693581135.git.mkletzan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1693581186101100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When we parse we keep that in memory and pass it down to the hypervisor. However, that MAC address is not strictly valid as it is not marked as locally administered (bit 0x02) but it is not even globally unique. It is also used for loopback device on Linux, for example. And QEMU sees such MAC address just as "not specified" and generates a new one that libvirt does not even know about. So to make the overall experience better we now generate it if the supplied one is all clear. Resolves: https://issues.redhat.com/browse/RHEL-974 Signed-off-by: Martin Kletzander Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 2 +- src/util/virmacaddr.c | 5 +++++ src/util/virmacaddr.h | 1 + .../network-interface-mac-clear.xml | 21 +++++++++++++++++++ .../network-interface-mac-clear.xml | 21 +++++++++++++++++++ tests/genericxml2xmltest.c | 4 +++- 6 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 tests/genericxml2xmlindata/network-interface-mac-clear.= xml create mode 100644 tests/genericxml2xmloutdata/network-interface-mac-clear= .xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bb4f1fdb948d..652bd09b21b8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9675,7 +9675,7 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, return NULL; } =20 - if (!macaddr) { + if (!macaddr || virMacAddrIsAllClear(&def->mac)) { virDomainNetGenerateMAC(xmlopt, &def->mac); def->mac_generated =3D true; } diff --git a/src/util/virmacaddr.c b/src/util/virmacaddr.c index 073f298b5b66..e06bb200fc68 100644 --- a/src/util/virmacaddr.c +++ b/src/util/virmacaddr.c @@ -246,6 +246,11 @@ virMacAddrIsBroadcastRaw(const unsigned char s[VIR_MAC= _BUFLEN]) return memcmp(virMacAddrBroadcastAddrRaw, s, sizeof(*s)) =3D=3D 0; } =20 +bool virMacAddrIsAllClear(const virMacAddr *addr) +{ + return !virMacAddrCmpRaw(addr, (const unsigned char[VIR_MAC_BUFLEN]){0= }); +} + void virMacAddrFree(virMacAddr *addr) { diff --git a/src/util/virmacaddr.h b/src/util/virmacaddr.h index f32b58805a61..7b9eb7443bd1 100644 --- a/src/util/virmacaddr.h +++ b/src/util/virmacaddr.h @@ -58,6 +58,7 @@ int virMacAddrParseHex(const char* str, bool virMacAddrIsUnicast(const virMacAddr *addr); bool virMacAddrIsMulticast(const virMacAddr *addr); bool virMacAddrIsBroadcastRaw(const unsigned char s[VIR_MAC_BUFLEN]); +bool virMacAddrIsAllClear(const virMacAddr *addr); void virMacAddrFree(virMacAddr *addr); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMacAddr, virMacAddrFree); diff --git a/tests/genericxml2xmlindata/network-interface-mac-clear.xml b/t= ests/genericxml2xmlindata/network-interface-mac-clear.xml new file mode 100644 index 000000000000..41beda8a79bb --- /dev/null +++ b/tests/genericxml2xmlindata/network-interface-mac-clear.xml @@ -0,0 +1,21 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + + + + + + diff --git a/tests/genericxml2xmloutdata/network-interface-mac-clear.xml b/= tests/genericxml2xmloutdata/network-interface-mac-clear.xml new file mode 100644 index 000000000000..a7935fa9f4de --- /dev/null +++ b/tests/genericxml2xmloutdata/network-interface-mac-clear.xml @@ -0,0 +1,21 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + + + + + + diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index 3501eadf5597..bf160b7e0bef 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -187,6 +187,7 @@ mymain(void) DO_TEST("cpu-cache-disable"); =20 DO_TEST("network-interface-mac-check"); + DO_TEST_DIFFERENT("network-interface-mac-clear"); =20 DO_TEST_DIFFERENT("chardev-tcp"); DO_TEST_FAIL_ACTIVE("chardev-tcp-missing-host"); @@ -255,4 +256,5 @@ mymain(void) return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 -VIR_TEST_MAIN(mymain) +VIR_TEST_MAIN_PRELOAD(mymain, + VIR_TEST_MOCK("virrandom")) --=20 2.42.0