render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
404507
From 5b225fe7ac882c8696b9759251c519c785f5407c Mon Sep 17 00:00:00 2001
404507
Message-Id: <5b225fe7ac882c8696b9759251c519c785f5407c@dist-git>
404507
From: Laine Stump <laine@laine.org>
404507
Date: Tue, 6 Mar 2018 16:19:31 -0500
404507
Subject: [PATCH] conf: move 'generated' member from virMacAddr to
404507
 virDomainNetDef
404507
404507
Commit 7e62c4cd26d (first appearing in libvirt-3.9.0 as a resolution
404507
to rhbz #1343919) added a "generated" attribute to virMacAddr that was
404507
set whenever a mac address was auto-generated by libvirt. This
404507
knowledge was used in a single place - when trying to match a NetDef
404507
from the Domain to Delete with user-provided XML. Since the XML parser
404507
always auto-generates a MAC address for NetDefs when none is provided,
404507
it was previously impossible to make a search where the MAC address
404507
isn't significant, but the addition of the "generated" attribute made
404507
it possible for the search function to ignore auto-generated MACs.
404507
404507
This implementation had a problem though - it was adding a field to a
404507
"low level" struct - virMacAddr - which is used in other places with
404507
the assumption that it contains exactly a 6 byte MAC address and
404507
nothing else. In particular, virNWFilterSnoopEthHdr uses virMacAddr as
404507
part of the definition of an ethernet packet header, whose layout must
404507
of course match an actual ethernet packet. Adding the extra bools into
404507
virNWFilterSnoopEthHdr caused the nwfilter driver's "IP discovery via
404507
DHCP packet snooping" functionality to mysteriously stop working.
404507
404507
In order to fix that behavior, and prevent potential future similar
404507
odd behavior, this patch moves the "generated" member out of
404507
virMacAddr (so that it is again really is just a MAC address) into
404507
virDomainNetDef, and sets it only when virDomainNetGenerateMAC() is
404507
called from virDomainNetDefParseXML() (which is the only time we care
404507
about it).
404507
404507
Resolves: https://bugzilla.redhat.com/1529338
404507
404507
(It should also be applied to any maintenance branch that applies
404507
commit 7e62c4cd26 and friends to resolve
404507
https://bugzilla.redhat.com/1343919)
404507
404507
Signed-off-by: Laine Stump <laine@laine.org>
404507
(cherry picked from commit e62cb4a9b78c7f4499a206635fb4f06e6ac627e5)
404507
---
404507
 src/conf/domain_conf.c    | 3 ++-
404507
 src/conf/domain_conf.h    | 1 +
404507
 src/util/virmacaddr.c     | 5 -----
404507
 src/util/virmacaddr.h     | 9 +++++++--
404507
 tests/bhyveargv2xmlmock.c | 1 -
404507
 5 files changed, 10 insertions(+), 9 deletions(-)
404507
404507
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
404507
index 0af3dd5ab6..1a3db4a7be 100644
404507
--- a/src/conf/domain_conf.c
404507
+++ b/src/conf/domain_conf.c
404507
@@ -10989,6 +10989,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
404507
         }
404507
     } else {
404507
         virDomainNetGenerateMAC(xmlopt, &def->mac);
404507
+        def->mac_generated = true;
404507
     }
404507
 
404507
     if (devaddr) {
404507
@@ -16205,7 +16206,7 @@ virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net)
404507
     size_t i;
404507
     int matchidx = -1;
404507
     char mac[VIR_MAC_STRING_BUFLEN];
404507
-    bool MACAddrSpecified = !net->mac.generated;
404507
+    bool MACAddrSpecified = !net->mac_generated;
404507
     bool PCIAddrSpecified = virDomainDeviceAddressIsValid(&net->info,
404507
                                                           VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI);
404507
 
404507
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
404507
index ed7b587bed..3817887322 100644
404507
--- a/src/conf/domain_conf.h
404507
+++ b/src/conf/domain_conf.h
404507
@@ -962,6 +962,7 @@ struct _virDomainActualNetDef {
404507
 struct _virDomainNetDef {
404507
     virDomainNetType type;
404507
     virMacAddr mac;
404507
+    bool mac_generated; /* true if mac was *just now* auto-generated by libvirt */
404507
     char *model;
404507
     union {
404507
         struct {
404507
diff --git a/src/util/virmacaddr.c b/src/util/virmacaddr.c
404507
index 409fdc34d5..7afe032b9c 100644
404507
--- a/src/util/virmacaddr.c
404507
+++ b/src/util/virmacaddr.c
404507
@@ -107,7 +107,6 @@ void
404507
 virMacAddrSet(virMacAddrPtr dst, const virMacAddr *src)
404507
 {
404507
     memcpy(dst, src, sizeof(*src));
404507
-    dst->generated = false;
404507
 }
404507
 
404507
 /**
404507
@@ -121,7 +120,6 @@ void
404507
 virMacAddrSetRaw(virMacAddrPtr dst, const unsigned char src[VIR_MAC_BUFLEN])
404507
 {
404507
     memcpy(dst->addr, src, VIR_MAC_BUFLEN);
404507
-    dst->generated = false;
404507
 }
404507
 
404507
 /**
404507
@@ -151,7 +149,6 @@ virMacAddrParse(const char* str, virMacAddrPtr addr)
404507
 {
404507
     size_t i;
404507
 
404507
-    addr->generated = false;
404507
     errno = 0;
404507
     for (i = 0; i < VIR_MAC_BUFLEN; i++) {
404507
         char *end_ptr;
404507
@@ -220,7 +217,6 @@ virMacAddrParseHex(const char *str, virMacAddrPtr addr)
404507
         str[VIR_MAC_HEXLEN])
404507
         return -1;
404507
 
404507
-    addr->generated = false;
404507
     for (i = 0; i < VIR_MAC_BUFLEN; i++)
404507
         addr->addr[i] = (virHexToBin(str[2 * i]) << 4 |
404507
                          virHexToBin(str[2 * i + 1]));
404507
@@ -236,7 +232,6 @@ void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
404507
     addr->addr[3] = virRandomBits(8);
404507
     addr->addr[4] = virRandomBits(8);
404507
     addr->addr[5] = virRandomBits(8);
404507
-    addr->generated = true;
404507
 }
404507
 
404507
 /* The low order bit of the first byte is the "multicast" bit. */
404507
diff --git a/src/util/virmacaddr.h b/src/util/virmacaddr.h
404507
index ef4285d639..d0dd4a45c6 100644
404507
--- a/src/util/virmacaddr.h
404507
+++ b/src/util/virmacaddr.h
404507
@@ -36,9 +36,14 @@ typedef virMacAddr *virMacAddrPtr;
404507
 
404507
 struct _virMacAddr {
404507
     unsigned char addr[VIR_MAC_BUFLEN];
404507
-    bool generated; /* True if MAC address was autogenerated,
404507
-                       false otherwise. */
404507
 };
404507
+/* This struct is used as a part of a larger struct that is
404507
+ * overlaid on an ethernet packet captured with libpcap, so it
404507
+ * must not have any extra members added - it must remain exactly
404507
+ * 6 bytes in length.
404507
+ */
404507
+verify(sizeof(struct _virMacAddr) == 6);
404507
+
404507
 
404507
 int virMacAddrCompare(const char *mac1, const char *mac2);
404507
 int virMacAddrCmp(const virMacAddr *mac1, const virMacAddr *mac2);
404507
diff --git a/tests/bhyveargv2xmlmock.c b/tests/bhyveargv2xmlmock.c
404507
index dd25f4e13a..1f08bebb7b 100644
404507
--- a/tests/bhyveargv2xmlmock.c
404507
+++ b/tests/bhyveargv2xmlmock.c
404507
@@ -16,7 +16,6 @@ virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
404507
     addr->addr[3] = 0;
404507
     addr->addr[4] = 0;
404507
     addr->addr[5] = 0;
404507
-    addr->generated = true;
404507
 }
404507
 
404507
 int
404507
-- 
404507
2.16.2
404507