render / rpms / libvirt

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