[PATCH 2/3] virmacaddr: Track if MAC address is autogenerated

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It will come handy to know if the MAC address was generated (e.g.
during XML parse) or if it was parsed since provided by user in
the XML.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/util/virmacaddr.c     | 5 +++++
 src/util/virmacaddr.h     | 2 ++
 tests/bhyveargv2xmlmock.c | 1 +
 tests/bhyvexml2argvmock.c | 1 +
 4 files changed, 9 insertions(+)

diff --git a/src/util/virmacaddr.c b/src/util/virmacaddr.c
index 7afe032b9..409fdc34d 100644
--- a/src/util/virmacaddr.c
+++ b/src/util/virmacaddr.c
@@ -107,6 +107,7 @@ void
 virMacAddrSet(virMacAddrPtr dst, const virMacAddr *src)
 {
     memcpy(dst, src, sizeof(*src));
+    dst->generated = false;
 }
 
 /**
@@ -120,6 +121,7 @@ void
 virMacAddrSetRaw(virMacAddrPtr dst, const unsigned char src[VIR_MAC_BUFLEN])
 {
     memcpy(dst->addr, src, VIR_MAC_BUFLEN);
+    dst->generated = false;
 }
 
 /**
@@ -149,6 +151,7 @@ virMacAddrParse(const char* str, virMacAddrPtr addr)
 {
     size_t i;
 
+    addr->generated = false;
     errno = 0;
     for (i = 0; i < VIR_MAC_BUFLEN; i++) {
         char *end_ptr;
@@ -217,6 +220,7 @@ virMacAddrParseHex(const char *str, virMacAddrPtr addr)
         str[VIR_MAC_HEXLEN])
         return -1;
 
+    addr->generated = false;
     for (i = 0; i < VIR_MAC_BUFLEN; i++)
         addr->addr[i] = (virHexToBin(str[2 * i]) << 4 |
                          virHexToBin(str[2 * i + 1]));
@@ -232,6 +236,7 @@ void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
     addr->addr[3] = virRandomBits(8);
     addr->addr[4] = virRandomBits(8);
     addr->addr[5] = virRandomBits(8);
+    addr->generated = true;
 }
 
 /* The low order bit of the first byte is the "multicast" bit. */
diff --git a/src/util/virmacaddr.h b/src/util/virmacaddr.h
index f4f5e2ce1..ef4285d63 100644
--- a/src/util/virmacaddr.h
+++ b/src/util/virmacaddr.h
@@ -36,6 +36,8 @@ typedef virMacAddr *virMacAddrPtr;
 
 struct _virMacAddr {
     unsigned char addr[VIR_MAC_BUFLEN];
+    bool generated; /* True if MAC address was autogenerated,
+                       false otherwise. */
 };
 
 int virMacAddrCompare(const char *mac1, const char *mac2);
diff --git a/tests/bhyveargv2xmlmock.c b/tests/bhyveargv2xmlmock.c
index 1f08bebb7..dd25f4e13 100644
--- a/tests/bhyveargv2xmlmock.c
+++ b/tests/bhyveargv2xmlmock.c
@@ -16,6 +16,7 @@ virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
     addr->addr[3] = 0;
     addr->addr[4] = 0;
     addr->addr[5] = 0;
+    addr->generated = true;
 }
 
 int
diff --git a/tests/bhyvexml2argvmock.c b/tests/bhyvexml2argvmock.c
index 7afa0e34c..bec7f902a 100644
--- a/tests/bhyvexml2argvmock.c
+++ b/tests/bhyvexml2argvmock.c
@@ -17,6 +17,7 @@ void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
     addr->addr[3] = 0;
     addr->addr[4] = 0;
     addr->addr[5] = 0;
+    addr->generated = true;
 }
 
 int virNetDevTapCreateInBridgePort(const char *brname ATTRIBUTE_UNUSED,
-- 
2.13.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux