virmacaddr: Track if MAC address is autogenerated

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@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Michal Privoznik 2017-10-02 10:47:27 +02:00
parent b2482c084a
commit 7e62c4cd26
4 changed files with 9 additions and 0 deletions

View File

@ -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. */

View File

@ -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);

View File

@ -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

View File

@ -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,