[PATCH] Convert 'raw MAC address' usages to use virMacAddr

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

 



Introduce new members in the virMacAddr 'class':
- virMacAddrSet: set virMacAddr from a virMacAddr
- virMacAddrSetRaw: setting virMacAddr from raw 6 byte MAC address buffer
- virMacAddrGetRaw: writing virMacAddr into raw 6 byte MAC address buffer
- virMacAddrCmp: comparing two virMacAddr
- virMacAddrCmpRaw: comparing a virMacAddr with a raw 6 byte MAC address buffer

then replace raw MAC addresses by replacing

- 'unsigned char *' with virMacAddrPtr
- 'unsigned char ... [VIR_MAC_BUFLEN]' with virMacAddr

and introduce usage of above functions where necessary.

---
 src/conf/capabilities.c                   |    4 -
 src/conf/capabilities.h                   |    4 -
 src/conf/domain_audit.c                   |    6 -
 src/conf/domain_conf.c                    |   34 ++++-----
 src/conf/domain_conf.h                    |    6 -
 src/conf/domain_nwfilter.c                |    2
 src/conf/domain_nwfilter.h                |    4 -
 src/conf/network_conf.c                   |   14 ++--
 src/conf/network_conf.h                   |    2
 src/conf/nwfilter_conf.c                  |   17 +---
 src/conf/nwfilter_conf.h                  |   14 +---
 src/conf/nwfilter_params.c                |    2
 src/conf/nwfilter_params.h                |    3
 src/libvirt_private.syms                  |    5 +
 src/libxl/libxl_conf.c                    |    2
 src/lxc/lxc_driver.c                      |    6 -
 src/network/bridge_driver.c               |    2
 src/nwfilter/nwfilter_dhcpsnoop.c         |   18 ++---
 src/nwfilter/nwfilter_dhcpsnoop.h         |    4 -
 src/nwfilter/nwfilter_driver.c            |    2
 src/nwfilter/nwfilter_ebiptables_driver.c |    6 -
 src/nwfilter/nwfilter_gentech_driver.c    |   10 +-
 src/nwfilter/nwfilter_gentech_driver.h    |    4 -
 src/nwfilter/nwfilter_learnipaddr.c       |   29 +++-----
 src/nwfilter/nwfilter_learnipaddr.h       |    4 -
 src/openvz/openvz_conf.c                  |    2
 src/openvz/openvz_driver.c                |    8 +-
 src/qemu/qemu_bridge_filter.c             |    4 -
 src/qemu/qemu_bridge_filter.h             |    4 -
 src/qemu/qemu_command.c                   |   22 +++---
 src/qemu/qemu_driver.c                    |   16 ++--
 src/qemu/qemu_hostdev.c                   |    8 +-
 src/qemu/qemu_hotplug.c                   |   14 ++--
 src/qemu/qemu_migration.c                 |    6 -
 src/qemu/qemu_process.c                   |    4 -
 src/uml/uml_conf.c                        |    6 -
 src/util/ebtables.c                       |   16 ++--
 src/util/ebtables.h                       |    6 +
src/util/virmacaddr.c | 104 +++++++++++++++++++++++++-----
 src/util/virmacaddr.h                     |   25 +++++--
 src/util/virnetdev.c                      |   61 ++++++++---------
 src/util/virnetdev.h                      |   11 +--
 src/util/virnetdevmacvlan.c               |   38 +++++-----
 src/util/virnetdevmacvlan.h               |   11 +--
 src/util/virnetdevopenvswitch.c           |    2
 src/util/virnetdevopenvswitch.h           |    2
 src/util/virnetdevtap.c                   |   19 ++---
 src/util/virnetdevtap.h                   |    2
 src/util/virnetdevvportprofile.c          |   18 ++---
 src/util/virnetdevvportprofile.h          |    5 -
 src/util/virnetlink.c                     |   15 ++--
 src/util/virnetlink.h                     |    7 +-
 src/vbox/vbox_tmpl.c                      |   16 ++--
 src/vmx/vmx.c                             |   10 +-
 src/xen/xend_internal.c                   |    6 -
 src/xen/xm_internal.c                     |    4 -
 src/xenxs/xen_sxpr.c                      |    6 -
 src/xenxs/xen_xm.c                        |    8 +-
 tools/virsh.c                             |    8 +-
 59 files changed, 388 insertions(+), 310 deletions(-)

Index: libvirt-acl/src/conf/domain_conf.h
===================================================================
--- libvirt-acl.orig/src/conf/domain_conf.h
+++ libvirt-acl/src/conf/domain_conf.h
@@ -777,7 +777,7 @@ struct _virDomainActualNetDef {
 /* Stores the virtual network interface configuration */
 struct _virDomainNetDef {
     enum virDomainNetType type;
-    unsigned char mac[VIR_MAC_BUFLEN];
+    virMacAddr mac;
     char *model;
     union {
         struct {
@@ -1990,12 +1990,12 @@ virDomainDiskRemove(virDomainDefPtr def,
 virDomainDiskDefPtr
 virDomainDiskRemoveByName(virDomainDefPtr def, const char *name);

-int virDomainNetIndexByMac(virDomainDefPtr def, const unsigned char *mac);
+int virDomainNetIndexByMac(virDomainDefPtr def, const virMacAddrPtr mac);
 int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net);
 virDomainNetDefPtr
 virDomainNetRemove(virDomainDefPtr def, size_t i);
 virDomainNetDefPtr
-virDomainNetRemoveByMac(virDomainDefPtr def, const unsigned char *mac);
+virDomainNetRemoveByMac(virDomainDefPtr def, const virMacAddrPtr mac);

int virDomainHostdevInsert(virDomainDefPtr def, virDomainHostdevDefPtr hostdev);
 virDomainHostdevDefPtr
Index: libvirt-acl/src/util/virmacaddr.c
===================================================================
--- libvirt-acl.orig/src/util/virmacaddr.c
+++ libvirt-acl/src/util/virmacaddr.c
@@ -62,6 +62,76 @@ virMacAddrCompare(const char *p, const c
 }

 /**
+ * virMacAddrCmp:
+ * @mac1: pointer to 1st MAC address
+ * @mac2: pointer to 2nd MAC address
+ *
+ * Return 0 if MAC addresses are equal,
+ * < 0 if mac1 < mac2,
+ * > 0 if mac1 > mac2
+ */
+int
+virMacAddrCmp(const virMacAddrPtr mac1, const virMacAddrPtr mac2)
+{
+    return memcmp(mac1->addr, mac2->addr, VIR_MAC_BUFLEN);
+}
+
+/**
+ * virMacAddrCmp:
+ * @mac1: pointer to 1st MAC address
+ * @mac2: pointer to 2nd MAC address in plain buffer
+ *
+ * Return 0 if MAC addresses are equal,
+ * < 0 if mac1 < mac2,
+ * > 0 if mac1 > mac2
+ */
+int
+virMacAddrCmpRaw(const virMacAddrPtr mac1,
+                 const unsigned char mac2[VIR_MAC_BUFLEN])
+{
+    return memcmp(mac1->addr, mac2, VIR_MAC_BUFLEN);
+}
+
+/**
+ * virMacAddrSet
+ * @dst: pointer to destination
+ * @src: pointer to source
+ *
+ * Copy src to dst
+ */
+void
+virMacAddrSet(virMacAddrPtr dst, const virMacAddrPtr src)
+{
+    memcpy(dst, src, sizeof(*src));
+}
+
+/**
+ * virMacAddrSetRaw
+ * @dst: pointer to destination to hold MAC address
+ * @src: raw MAC address data
+ *
+ * Set the MAC address to the given value
+ */
+void
+virMacAddrSetRaw(virMacAddrPtr dst, const unsigned char src[VIR_MAC_BUFLEN])
+{
+    memcpy(dst->addr, src, VIR_MAC_BUFLEN);
+}
+
+/**
+ * virMacAddrGet
+ * @src: pointer to MAC address
+ * @dst: pointer to raw memory to write MAC address into
+ *
+ * Copies the MAC address into raw memory
+ */
+void
+virMacAddrGetRaw(virMacAddrPtr src, unsigned char dst[VIR_MAC_BUFLEN])
+{
+    memcpy(dst, src->addr, VIR_MAC_BUFLEN);
+}
+
+/**
  * virMacAddrParse:
  * @str: string representation of MAC address, e.g., "0:1E:FC:E:3a:CB"
  * @addr: 6-byte MAC address
@@ -71,7 +141,7 @@ virMacAddrCompare(const char *p, const c
  * Return 0 upon success, or -1 in case of error.
  */
 int
-virMacAddrParse(const char* str, unsigned char *addr)
+virMacAddrParse(const char* str, virMacAddrPtr addr)
 {
     int i;

@@ -93,7 +163,7 @@ virMacAddrParse(const char* str, unsigne
             (0xFF < result))
             break;

-        addr[i] = (unsigned char) result;
+        addr->addr[i] = (unsigned char) result;

         if ((i == 5) && (*end_ptr == '\0'))
             return 0;
@@ -106,36 +176,36 @@ virMacAddrParse(const char* str, unsigne
     return -1;
 }

-void virMacAddrFormat(const unsigned char *addr,
+void virMacAddrFormat(const virMacAddrPtr addr,
                       char *str)
 {
     snprintf(str, VIR_MAC_STRING_BUFLEN,
              "%02X:%02X:%02X:%02X:%02X:%02X",
-             addr[0], addr[1], addr[2],
-             addr[3], addr[4], addr[5]);
+             addr->addr[0], addr->addr[1], addr->addr[2],
+             addr->addr[3], addr->addr[4], addr->addr[5]);
     str[VIR_MAC_STRING_BUFLEN-1] = '\0';
 }

-void virMacAddrGenerate(const unsigned char *prefix,
-                        unsigned char *addr)
+void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
+                        virMacAddrPtr addr)
 {
-    addr[0] = prefix[0];
-    addr[1] = prefix[1];
-    addr[2] = prefix[2];
-    addr[3] = virRandomBits(8);
-    addr[4] = virRandomBits(8);
-    addr[5] = virRandomBits(8);
+    addr->addr[0] = prefix[0];
+    addr->addr[1] = prefix[1];
+    addr->addr[2] = prefix[2];
+    addr->addr[3] = virRandomBits(8);
+    addr->addr[4] = virRandomBits(8);
+    addr->addr[5] = virRandomBits(8);
 }

 /* The low order bit of the first byte is the "multicast" bit. */
 bool
-virMacAddrIsMulticast(const unsigned char *addr)
+virMacAddrIsMulticast(const virMacAddrPtr mac)
 {
-    return !!(addr[0] & 1);
+    return !!(mac->addr[0] & 1);
 }

 bool
-virMacAddrIsUnicast(const unsigned char *addr)
+virMacAddrIsUnicast(const virMacAddrPtr mac)
 {
-    return !(addr[0] & 1);
+    return !(mac->addr[0] & 1);
 }
Index: libvirt-acl/src/util/virmacaddr.h
===================================================================
--- libvirt-acl.orig/src/util/virmacaddr.h
+++ libvirt-acl/src/util/virmacaddr.h
@@ -30,15 +30,26 @@
 # define VIR_MAC_PREFIX_BUFLEN 3
 # define VIR_MAC_STRING_BUFLEN (VIR_MAC_BUFLEN * 3)

-typedef unsigned char virMacAddr[VIR_MAC_BUFLEN];
+typedef struct _virMacAddr virMacAddr;
+typedef virMacAddr *virMacAddrPtr;
+
+struct _virMacAddr {
+    unsigned char addr[VIR_MAC_BUFLEN];
+};

 int virMacAddrCompare(const char *mac1, const char *mac2);
-void virMacAddrFormat(const unsigned char *addr,
+int virMacAddrCmp(const virMacAddrPtr mac1, const virMacAddrPtr mac2);
+int virMacAddrCmpRaw(const virMacAddrPtr mac1,
+                     const unsigned char s[VIR_MAC_BUFLEN]);
+void virMacAddrSet(virMacAddrPtr dst, const virMacAddrPtr src);
+void virMacAddrSetRaw(virMacAddrPtr dst, const unsigned char s[VIR_MAC_BUFLEN]); +void virMacAddrGetRaw(virMacAddrPtr src, unsigned char dst[VIR_MAC_BUFLEN]);
+void virMacAddrFormat(const virMacAddrPtr addr,
                       char *str);
-void virMacAddrGenerate(const unsigned char *prefix,
-                        unsigned char *addr);
+void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN],
+                        virMacAddrPtr addr);
 int virMacAddrParse(const char* str,
-                    unsigned char *addr) ATTRIBUTE_RETURN_CHECK;
-bool virMacAddrIsUnicast(const unsigned char *addr);
-bool virMacAddrIsMulticast(const unsigned char *addr);
+                    virMacAddrPtr addr) ATTRIBUTE_RETURN_CHECK;
+bool virMacAddrIsUnicast(const virMacAddrPtr addr);
+bool virMacAddrIsMulticast(const virMacAddrPtr addr);
 #endif /* __VIR_MACADDR_H__ */
Index: libvirt-acl/src/util/virnetdev.c
===================================================================
--- libvirt-acl.orig/src/util/virnetdev.c
+++ libvirt-acl/src/util/virnetdev.c
@@ -137,7 +137,7 @@ int virNetDevExists(const char *ifname)
 /**
  * virNetDevSetMAC:
  * @ifname: interface name to set MTU for
- * @macaddr: MAC address (VIR_MAC_BUFLEN in size)
+ * @macaddr: MAC address
  *
  * This function sets the @macaddr for a given interface @ifname. This
  * gets rid of the kernel's automatically assigned random MAC.
@@ -145,7 +145,7 @@ int virNetDevExists(const char *ifname)
  * Returns 0 in case of success or -1 on failure
  */
 int virNetDevSetMAC(const char *ifname,
-                    const unsigned char *macaddr)
+                    const virMacAddrPtr macaddr)
 {
     int fd = -1;
     int ret = -1;
@@ -162,7 +162,7 @@ int virNetDevSetMAC(const char *ifname,
         goto cleanup;
     }

-    memcpy(ifr.ifr_hwaddr.sa_data, macaddr, VIR_MAC_BUFLEN);
+    virMacAddrGetRaw(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data);

     if (ioctl(fd, SIOCSIFHWADDR, &ifr) < 0) {
         virReportSystemError(errno,
@@ -179,7 +179,7 @@ cleanup:
 }
 #else
 int virNetDevSetMAC(const char *ifname,
-                    const unsigned char *macaddr ATTRIBUTE_UNUSED)
+                    const virMacAddrPtr macaddr ATTRIBUTE_UNUSED)
 {
     virReportSystemError(ENOSYS,
                          _("Cannot set interface MAC on '%s'"),
@@ -193,14 +193,14 @@ int virNetDevSetMAC(const char *ifname,
 /**
  * virNetDevGetMAC:
  * @ifname: interface name to set MTU for
- * @macaddr: MAC address (VIR_MAC_BUFLEN in size)
+ * @macaddr: MAC address
  *
  * This function gets the @macaddr for a given interface @ifname.
  *
  * Returns 0 in case of success or -1 on failure
  */
 int virNetDevGetMAC(const char *ifname,
-                    unsigned char *macaddr)
+                    virMacAddrPtr macaddr)
 {
     int fd = -1;
     int ret = -1;
@@ -216,7 +216,7 @@ int virNetDevGetMAC(const char *ifname,
         goto cleanup;
     }

-    memcpy(macaddr, ifr.ifr_hwaddr.sa_data, VIR_MAC_BUFLEN);
+    virMacAddrSetRaw(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data);

     ret = 0;

@@ -226,7 +226,7 @@ cleanup:
 }
 #else
 int virNetDevGetMAC(const char *ifname,
-                    unsigned char *macaddr ATTRIBUTE_UNUSED)
+                    virMacAddrPtr macaddr ATTRIBUTE_UNUSED)
 {
     virReportSystemError(ENOSYS,
                          _("Cannot get interface MAC on '%s'"),
@@ -248,14 +248,14 @@ int virNetDevGetMAC(const char *ifname,
  */
 int
 virNetDevReplaceMacAddress(const char *linkdev,
-                           const unsigned char *macaddress,
+                           const virMacAddrPtr macaddress,
                            const char *stateDir)
 {
-    unsigned char oldmac[6];
+    virMacAddr oldmac;
     char *path = NULL;
     char macstr[VIR_MAC_STRING_BUFLEN];

-    if (virNetDevGetMAC(linkdev, oldmac) < 0)
+    if (virNetDevGetMAC(linkdev, &oldmac) < 0)
         return -1;


@@ -265,7 +265,7 @@ virNetDevReplaceMacAddress(const char *l
         virReportOOMError();
         return -1;
     }
-    virMacAddrFormat(oldmac, macstr);
+    virMacAddrFormat(&oldmac, macstr);
     if (virFileWriteStr(path, macstr, O_CREAT|O_TRUNC|O_WRONLY) < 0) {
         virReportSystemError(errno, _("Unable to preserve mac for %s"),
                              linkdev);
@@ -294,7 +294,7 @@ virNetDevRestoreMacAddress(const char *l
     char *oldmacname = NULL;
     char *macstr = NULL;
     char *path = NULL;
-    unsigned char oldmac[6];
+    virMacAddr oldmac;

     if (virAsprintf(&path, "%s/%s",
                     stateDir,
@@ -306,7 +306,7 @@ virNetDevRestoreMacAddress(const char *l
     if (virFileReadAll(path, VIR_MAC_STRING_BUFLEN, &macstr) < 0)
         return -1;

-    if (virMacAddrParse(macstr, &oldmac[0]) != 0) {
+    if (virMacAddrParse(macstr, &oldmac) != 0) {
         virNetDevError(VIR_ERR_INTERNAL_ERROR,
                        _("Cannot parse MAC address from '%s'"),
                        oldmacname);
@@ -315,7 +315,7 @@ virNetDevRestoreMacAddress(const char *l
     }

     /*reset mac and remove file-ignore results*/
-    rc = virNetDevSetMAC(linkdev, oldmac);
+    rc = virNetDevSetMAC(linkdev, &oldmac);
     ignore_value(unlink(path));
     VIR_FREE(macstr);

@@ -876,7 +876,7 @@ int virNetDevGetIPv4Address(const char *
  */
 #if defined(HAVE_STRUCT_IFREQ)
 int virNetDevValidateConfig(const char *ifname,
-                            const unsigned char *macaddr, int ifindex)
+                            const virMacAddrPtr macaddr, int ifindex)
 {
     int fd = -1;
     int ret = -1;
@@ -906,7 +906,8 @@ int virNetDevValidateConfig(const char *
             goto cleanup;
         }

- if (memcmp(&ifr.ifr_hwaddr.sa_data, macaddr, VIR_MAC_BUFLEN) != 0) {
+        if (virMacAddrCmpRaw(macaddr,
+ (unsigned char *)ifr.ifr_hwaddr.sa_data) != 0) {
             ret = 0;
             goto cleanup;
         }
@@ -1333,7 +1334,7 @@ buffer_too_small:

 static int
 virNetDevSetVfConfig(const char *ifname, int ifindex, int vf,
-                     bool nltarget_kernel, const unsigned char *macaddr,
+                     bool nltarget_kernel, const virMacAddrPtr macaddr,
                      int vlanid, uint32_t (*getPidFunc)(void))
 {
     int rc = -1;
@@ -1378,7 +1379,7 @@ virNetDevSetVfConfig(const char *ifname,
              .mac = { 0, },
         };

-        memcpy(ifla_vf_mac.mac, macaddr, VIR_MAC_BUFLEN);
+        virMacAddrGetRaw(macaddr, ifla_vf_mac.mac);

         if (nla_put(nl_msg, IFLA_VF_MAC, sizeof(ifla_vf_mac),
&ifla_vf_mac) < 0)
@@ -1456,7 +1457,7 @@ buffer_too_small:
 }

 static int
-virNetDevParseVfConfig(struct nlattr **tb, int32_t vf, unsigned char *mac,
+virNetDevParseVfConfig(struct nlattr **tb, int32_t vf, virMacAddrPtr mac,
                        int *vlanid)
 {
     const char *msg = NULL;
@@ -1483,7 +1484,7 @@ virNetDevParseVfConfig(struct nlattr **t
             if (tb[IFLA_VF_MAC]) {
                 vf_mac = RTA_DATA(tb_vf[IFLA_VF_MAC]);
                 if (vf_mac && vf_mac->vf == vf)  {
-                    memcpy(mac, vf_mac->mac, VIR_MAC_BUFLEN);
+                    virMacAddrSetRaw(mac, vf_mac->mac);
                     found = 1;
                 }
             }
@@ -1510,7 +1511,7 @@ cleanup:
 }

 static int
-virNetDevGetVfConfig(const char *ifname, int vf, unsigned char *mac,
+virNetDevGetVfConfig(const char *ifname, int vf, virMacAddrPtr mac,
                      int *vlanid)
 {
     int rc = -1;
@@ -1531,17 +1532,17 @@ virNetDevGetVfConfig(const char *ifname,

 static int
 virNetDevReplaceVfConfig(const char *pflinkdev, int vf,
-                         const unsigned char *macaddress,
+                         const virMacAddrPtr macaddress,
                          int vlanid,
                          const char *stateDir)
 {
-    unsigned char oldmac[6];
+    virMacAddr oldmac;
     int oldvlanid = -1;
     char *path = NULL;
     char macstr[VIR_MAC_STRING_BUFLEN];
     int ifindex = -1;

-    if (virNetDevGetVfConfig(pflinkdev, vf, oldmac, &oldvlanid) < 0)
+    if (virNetDevGetVfConfig(pflinkdev, vf, &oldmac, &oldvlanid) < 0)
         return -1;

     if (virAsprintf(&path, "%s/%s_vf%d",
@@ -1550,7 +1551,7 @@ virNetDevReplaceVfConfig(const char *pfl
         return -1;
     }

-    virMacAddrFormat(oldmac, macstr);
+    virMacAddrFormat(&oldmac, macstr);
     if (virFileWriteStr(path, macstr, O_CREAT|O_TRUNC|O_WRONLY) < 0) {
virReportSystemError(errno, _("Unable to preserve mac for pf = %s,"
                              " vf = %d"), pflinkdev, vf);
@@ -1571,7 +1572,7 @@ virNetDevRestoreVfConfig(const char *pfl
     int rc = -1;
     char *macstr = NULL;
     char *path = NULL;
-    unsigned char oldmac[6];
+    virMacAddr oldmac;
     int vlanid = -1;
     int ifindex = -1;

@@ -1585,7 +1586,7 @@ virNetDevRestoreVfConfig(const char *pfl
         goto cleanup;
     }

-    if (virMacAddrParse(macstr, &oldmac[0]) != 0) {
+    if (virMacAddrParse(macstr, &oldmac) != 0) {
         virNetDevError(VIR_ERR_INTERNAL_ERROR,
                        _("Cannot parse MAC address from '%s'"),
                        macstr);
@@ -1594,7 +1595,7 @@ virNetDevRestoreVfConfig(const char *pfl

     /*reset mac and remove file-ignore results*/
     rc = virNetDevSetVfConfig(pflinkdev, ifindex, vf, true,
-                              oldmac, vlanid, NULL);
+ &oldmac, vlanid, NULL);
     ignore_value(unlink(path));

 cleanup:
@@ -1617,7 +1618,7 @@ cleanup:
  */
 int
 virNetDevReplaceNetConfig(char *linkdev, int vf,
-                          const unsigned char *macaddress, int vlanid,
+                          const virMacAddrPtr macaddress, int vlanid,
                           char *stateDir)
 {
     if (vf == -1)
Index: libvirt-acl/src/util/virnetdev.h
===================================================================
--- libvirt-acl.orig/src/util/virnetdev.h
+++ libvirt-acl/src/util/virnetdev.h
@@ -25,6 +25,7 @@

 # include "virsocketaddr.h"
 # include "virnetlink.h"
+# include "virmacaddr.h"

 int virNetDevExists(const char *brname)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
@@ -49,14 +50,14 @@ int virNetDevGetIPv4Address(const char *


 int virNetDevSetMAC(const char *ifname,
-                    const unsigned char *macaddr)
+                    const virMacAddrPtr macaddr)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 int virNetDevGetMAC(const char *ifname,
-                    unsigned char *macaddr)
+                    virMacAddrPtr macaddr)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;

 int virNetDevReplaceMacAddress(const char *linkdev,
-                               const unsigned char *macaddress,
+                               const virMacAddrPtr macaddress,
                                const char *stateDir)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
     ATTRIBUTE_RETURN_CHECK;
@@ -86,7 +87,7 @@ int virNetDevGetVLanID(const char *ifnam
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;

 int virNetDevValidateConfig(const char *ifname,
-                            const unsigned char *macaddr, int ifindex)
+                            const virMacAddrPtr macaddr, int ifindex)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;

 int virNetDevIsVirtualFunction(const char *ifname)
@@ -113,7 +114,7 @@ int virNetDevLinkDump(const char *ifname
     ATTRIBUTE_RETURN_CHECK;

 int virNetDevReplaceNetConfig(char *linkdev, int vf,
-                              const unsigned char *macaddress, int vlanid,
+                              const virMacAddrPtr macaddress, int vlanid,
                               char *stateDir)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5);

Index: libvirt-acl/src/util/virnetdevmacvlan.c
===================================================================
--- libvirt-acl.orig/src/util/virnetdevmacvlan.c
+++ libvirt-acl/src/util/virnetdevmacvlan.c
@@ -95,7 +95,7 @@ VIR_ENUM_IMPL(virNetDevMacVLanMode, VIR_
 int
 virNetDevMacVLanCreate(const char *ifname,
                        const char *type,
-                       const unsigned char *macaddress,
+                       const virMacAddrPtr macaddress,
                        const char *srcdev,
                        uint32_t macvlan_mode,
                        int *retry)
@@ -435,7 +435,7 @@ static const uint32_t modeMap[VIR_NETDEV
 struct virNetlinkCallbackData {
     char *cr_ifname;
     virNetDevVPortProfilePtr virtPortProfile;
-    unsigned char macaddress[VIR_MAC_BUFLEN];
+    virMacAddr macaddress;
     char *linkdev;
     int vf;
     unsigned char vmuuid[VIR_UUID_BUFLEN];
@@ -589,13 +589,13 @@ virNetDevMacVLanVPortProfileCallback(uns
             VIR_DEBUG("IFLA_VF_MAC = %2x:%2x:%2x:%2x:%2x:%2x",
                       m[0], m[1], m[2], m[3], m[4], m[5]);

-            if (memcmp(calld->macaddress, m, VIR_MAC_BUFLEN))
+            if (virMacAddrCmpRaw(&calld->macaddress, mac->mac))
             {
                 /* Repeat the same check for a broadcast mac */
                 int i;

                 for (i = 0;i < VIR_MAC_BUFLEN; i++) {
-                    if (calld->macaddress[i] != 0xff) {
+                    if (calld->macaddress.addr[i] != 0xff) {
VIR_DEBUG("MAC address match failed (wasn't broadcast)");
                         return;
                     }
@@ -697,13 +697,13 @@ virNetDevMacVLanVPortProfileCallback(uns
     VIR_INFO("  if: %s", calld->cr_ifname);
     VIR_INFO("  lf: %s", calld->linkdev);
     VIR_INFO(" mac: %02x:%02x:%02x:%02x:%02x:%02x",
-             calld->macaddress[0], calld->macaddress[1],
-             calld->macaddress[2], calld->macaddress[3],
-             calld->macaddress[4], calld->macaddress[5]);
+             calld->macaddress.addr[0], calld->macaddress.addr[1],
+             calld->macaddress.addr[2], calld->macaddress.addr[3],
+             calld->macaddress.addr[4], calld->macaddress.addr[5]);

     ignore_value(virNetDevVPortProfileAssociate(calld->cr_ifname,
                                                 calld->virtPortProfile,
-                                                calld->macaddress,
+ &calld->macaddress,
                                                 calld->linkdev,
                                                 calld->vf,
                                                 calld->vmuuid,
@@ -746,7 +746,7 @@ virNetlinkCallbackDataFree(virNetlinkCal
  */
 static void
 virNetDevMacVLanVPortProfileDestroyCallback(int watch ATTRIBUTE_UNUSED,
- const unsigned char *macaddr ATTRIBUTE_UNUSED, + const virMacAddrPtr macaddr ATTRIBUTE_UNUSED,
                                             void *opaque)
 {
     virNetlinkCallbackDataFree((virNetlinkCallbackDataPtr)opaque);
@@ -754,7 +754,7 @@ virNetDevMacVLanVPortProfileDestroyCallb

 int
 virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
- const unsigned char *macaddress, + const virMacAddrPtr macaddress,
                                              const char *linkdev,
                                              const unsigned char *vmuuid,
virNetDevVPortProfilePtr virtPortProfile,
@@ -770,7 +770,7 @@ virNetDevMacVLanVPortProfileRegisterCall
         if (VIR_ALLOC(calld->virtPortProfile) < 0)
             goto memory_error;
memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile));
-        memcpy(calld->macaddress, macaddress, sizeof(calld->macaddress));
+        virMacAddrSet(&calld->macaddress, macaddress);
         if ((calld->linkdev = strdup(linkdev)) == NULL)
             goto  memory_error;
         memcpy(calld->vmuuid, vmuuid, sizeof(calld->vmuuid));
@@ -813,7 +813,7 @@ error:
  * otherwise returns 0; returns -1 on error.
  */
 int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
-                                           const unsigned char *macaddress,
+                                           const virMacAddrPtr macaddress,
                                            const char *linkdev,
                                            enum virNetDevMacVLanMode mode,
                                            bool withTap,
@@ -980,7 +980,7 @@ link_del_exit:
  * were provided.
  */
 int virNetDevMacVLanDeleteWithVPortProfile(const char *ifname,
-                                           const unsigned char *macaddr,
+                                           const virMacAddrPtr macaddr,
                                            const char *linkdev,
                                            int mode,
virNetDevVPortProfilePtr virtPortProfile,
@@ -1025,7 +1025,7 @@ int virNetDevMacVLanDeleteWithVPortProfi
  * Returns 0; returns -1 on error.
  */
 int virNetDevMacVLanRestartWithVPortProfile(const char *cr_ifname,
-                                           const unsigned char *macaddress,
+                                           const virMacAddrPtr macaddress,
                                            const char *linkdev,
                                            const unsigned char *vmuuid,
virNetDevVPortProfilePtr virtPortProfile,
@@ -1055,7 +1055,7 @@ error:
 #else /* ! WITH_MACVTAP */
 int virNetDevMacVLanCreate(const char *ifname ATTRIBUTE_UNUSED,
                            const char *type ATTRIBUTE_UNUSED,
- const unsigned char *macaddress ATTRIBUTE_UNUSED,
+                           const virMacAddrPtr macaddress ATTRIBUTE_UNUSED,
                            const char *srcdev ATTRIBUTE_UNUSED,
                            uint32_t macvlan_mode ATTRIBUTE_UNUSED,
                            int *retry ATTRIBUTE_UNUSED)
@@ -1073,7 +1073,7 @@ int virNetDevMacVLanDelete(const char *i
 }

int virNetDevMacVLanCreateWithVPortProfile(const char *ifname ATTRIBUTE_UNUSED, - const unsigned char *macaddress ATTRIBUTE_UNUSED, + const virMacAddrPtr macaddress ATTRIBUTE_UNUSED, const char *linkdev ATTRIBUTE_UNUSED, enum virNetDevMacVLanMode mode ATTRIBUTE_UNUSED,
                                            bool withTap ATTRIBUTE_UNUSED,
@@ -1091,7 +1091,7 @@ int virNetDevMacVLanCreateWithVPortProfi
 }

int virNetDevMacVLanDeleteWithVPortProfile(const char *ifname ATTRIBUTE_UNUSED, - const unsigned char *macaddress ATTRIBUTE_UNUSED, + const virMacAddrPtr macaddress ATTRIBUTE_UNUSED, const char *linkdev ATTRIBUTE_UNUSED,
                                            int mode ATTRIBUTE_UNUSED,
virNetDevVPortProfilePtr virtPortProfile ATTRIBUTE_UNUSED,
@@ -1103,7 +1103,7 @@ int virNetDevMacVLanDeleteWithVPortProfi
 }

int virNetDevMacVLanRestartWithVPortProfile(const char *cr_ifname ATTRIBUTE_UNUSED, - const unsigned char *macaddress ATTRIBUTE_UNUSED, + const virMacAddrPtr macaddress ATTRIBUTE_UNUSED, const char *linkdev ATTRIBUTE_UNUSED, const unsigned char *vmuuid ATTRIBUTE_UNUSED, virNetDevVPortProfilePtr virtPortProfile ATTRIBUTE_UNUSED,
@@ -1115,7 +1115,7 @@ int virNetDevMacVLanRestartWithVPortProf
 }

int virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname ATTRIBUTE_UNUSED, - const unsigned char *macaddress ATTRIBUTE_UNUSED, + const virMacAddrPtr macaddress ATTRIBUTE_UNUSED, const char *linkdev ATTRIBUTE_UNUSED, const unsigned char *vmuuid ATTRIBUTE_UNUSED, virNetDevVPortProfilePtr virtPortProfile ATTRIBUTE_UNUSED,
Index: libvirt-acl/src/util/virnetdevmacvlan.h
===================================================================
--- libvirt-acl.orig/src/util/virnetdevmacvlan.h
+++ libvirt-acl/src/util/virnetdevmacvlan.h
@@ -24,6 +24,7 @@
 # define __UTIL_MACVTAP_H__

 # include "internal.h"
+# include "virmacaddr.h"
 # include "virsocketaddr.h"
 # include "virnetdevbandwidth.h"
 # include "virnetdevvportprofile.h"
@@ -41,7 +42,7 @@ VIR_ENUM_DECL(virNetDevMacVLanMode)

 int virNetDevMacVLanCreate(const char *ifname,
                            const char *type,
-                           const unsigned char *macaddress,
+                           const virMacAddrPtr macaddress,
                            const char *srcdev,
                            uint32_t macvlan_mode,
                            int *retry)
@@ -52,7 +53,7 @@ int virNetDevMacVLanDelete(const char *i
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;

 int virNetDevMacVLanCreateWithVPortProfile(const char *ifname,
-                                           const unsigned char *macaddress,
+                                           const virMacAddrPtr macaddress,
                                            const char *linkdev,
                                            enum virNetDevMacVLanMode mode,
                                            bool withTap,
@@ -67,7 +68,7 @@ int virNetDevMacVLanCreateWithVPortProfi
     ATTRIBUTE_NONNULL(9) ATTRIBUTE_NONNULL(11) ATTRIBUTE_RETURN_CHECK;

 int virNetDevMacVLanDeleteWithVPortProfile(const char *ifname,
-                                           const unsigned char *macaddress,
+                                           const virMacAddrPtr macaddress,
                                            const char *linkdev,
                                            int mode,
virNetDevVPortProfilePtr virtPortProfile,
@@ -76,7 +77,7 @@ int virNetDevMacVLanDeleteWithVPortProfi
     ATTRIBUTE_NONNULL(6) ATTRIBUTE_RETURN_CHECK;

 int virNetDevMacVLanRestartWithVPortProfile(const char *cr_ifname,
-                                           const unsigned char *macaddress,
+                                           const virMacAddrPtr macaddress,
                                            const char *linkdev,
                                            const unsigned char *vmuuid,
virNetDevVPortProfilePtr virtPortProfile,
@@ -85,7 +86,7 @@ int virNetDevMacVLanRestartWithVPortProf
     ATTRIBUTE_NONNULL(4) ATTRIBUTE_RETURN_CHECK;

 int virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
- const unsigned char *macaddress , + const virMacAddrPtr macaddress ,
                                              const char *linkdev,
                                              const unsigned char *vmuuid,
virNetDevVPortProfilePtr virtPortProfile,
Index: libvirt-acl/src/util/virnetdevvportprofile.h
===================================================================
--- libvirt-acl.orig/src/util/virnetdevvportprofile.h
+++ libvirt-acl/src/util/virnetdevvportprofile.h
@@ -28,6 +28,7 @@
 # include "internal.h"
 # include "uuid.h"
 # include "util.h"
+# include "virmacaddr.h"

 # define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX 40

@@ -83,7 +84,7 @@ bool virNetDevVPortProfileEqual(virNetDe

 int virNetDevVPortProfileAssociate(const char *ifname,
const virNetDevVPortProfilePtr virtPort,
-                                   const unsigned char *macaddr,
+                                   const virMacAddrPtr macaddr,
                                    const char *linkdev,
                                    int vf,
                                    const unsigned char *vmuuid,
@@ -94,7 +95,7 @@ int virNetDevVPortProfileAssociate(const

 int virNetDevVPortProfileDisassociate(const char *ifname,
const virNetDevVPortProfilePtr virtPort,
-                                      const unsigned char *macaddr,
+                                      const virMacAddrPtr macaddr,
                                       const char *linkdev,
                                       int vf,
                                       enum virNetDevVPortProfileOp vmOp)
Index: libvirt-acl/src/util/virnetlink.c
===================================================================
--- libvirt-acl.orig/src/util/virnetlink.c
+++ libvirt-acl/src/util/virnetlink.c
@@ -56,7 +56,7 @@ struct virNetlinkEventHandle {
     virNetlinkEventHandleCallback handleCB;
     virNetlinkEventRemoveCallback removeCB;
     void *opaque;
-    unsigned char macaddr[VIR_MAC_BUFLEN];
+    virMacAddr macaddr;
     int deleted;
 };

@@ -277,7 +277,7 @@ virNetlinkEventRemoveClientPrimitive(siz

     if (removeCB) {
         (removeCB)(server->handles[i].watch,
-                   server->handles[i].macaddr,
+ &server->handles[i].macaddr,
                    server->handles[i].opaque);
     }
     server->handles[i].deleted = VIR_NETLINK_HANDLE_DELETED;
@@ -505,7 +505,7 @@ error_locked:
 int
 virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB,
                          virNetlinkEventRemoveCallback removeCB,
-                         void *opaque, const unsigned char *macaddr)
+                         void *opaque, const virMacAddrPtr macaddr)
 {
     int i, r, ret = -1;
     virNetlinkEventSrvPrivatePtr srv = server;
@@ -547,9 +547,10 @@ addentry:
     srv->handles[r].opaque   = opaque;
     srv->handles[r].deleted  = VIR_NETLINK_HANDLE_VALID;
     if (macaddr)
-        memcpy(srv->handles[r].macaddr, macaddr, VIR_MAC_BUFLEN);
+        virMacAddrSet(&srv->handles[r].macaddr, macaddr);
     else
-        memset(srv->handles[r].macaddr, 0, VIR_MAC_BUFLEN);
+        virMacAddrSetRaw(&srv->handles[r].macaddr,
+                         (unsigned char[VIR_MAC_BUFLEN]){0,0,0,0,0,0});

VIR_DEBUG("added client to loop slot: %d. with macaddr ptr=%p", r, macaddr);

@@ -572,7 +573,7 @@ error:
  * Returns -1 if the file handle was not registered, 0 upon success
  */
 int
-virNetlinkEventRemoveClient(int watch, const unsigned char *macaddr)
+virNetlinkEventRemoveClient(int watch, const virMacAddrPtr macaddr)
 {
     int i;
     int ret = -1;
@@ -593,7 +594,7 @@ virNetlinkEventRemoveClient(int watch, c

         if ((watch && srv->handles[i].watch == watch) ||
             (!watch &&
- memcmp(macaddr, srv->handles[i].macaddr, VIR_MAC_BUFLEN) == 0)) {
+             virMacAddrCmp(macaddr, &srv->handles[i].macaddr) == 0)) {

             VIR_DEBUG("removed client: %d by %s.",
                       srv->handles[i].watch, watch ? "index" : "mac");
Index: libvirt-acl/src/util/virnetlink.h
===================================================================
--- libvirt-acl.orig/src/util/virnetlink.h
+++ libvirt-acl/src/util/virnetlink.h
@@ -22,6 +22,7 @@

 # include "config.h"
 # include "internal.h"
+# include "virmacaddr.h"

 # include <stdint.h>

@@ -46,7 +47,7 @@ int virNetlinkCommand(struct nl_msg *nl_

typedef void (*virNetlinkEventHandleCallback)(unsigned char *msg, int length, struct sockaddr_nl *peer, bool *handled, void *opaque);

-typedef void (*virNetlinkEventRemoveCallback)(int watch, const unsigned char *macaddr, void *opaque); +typedef void (*virNetlinkEventRemoveCallback)(int watch, const virMacAddrPtr macaddr, void *opaque);

 /**
* stopNetlinkEventServer: stop the monitor to receive netlink messages for libvirtd
@@ -73,11 +74,11 @@ int virNetlinkEventServiceLocalPid(void)
  */
 int virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB,
                              virNetlinkEventRemoveCallback removeCB,
-                             void *opaque, const unsigned char *macaddr);
+                             void *opaque, const virMacAddrPtr macaddr);

 /**
* virNetlinkEventRemoveClient: unregister a callback from a netlink monitor
  */
-int virNetlinkEventRemoveClient(int watch, const unsigned char *macaddr);
+int virNetlinkEventRemoveClient(int watch, const virMacAddrPtr macaddr);

 #endif /* __VIR_NETLINK_H__ */
Index: libvirt-acl/src/conf/capabilities.c
===================================================================
--- libvirt-acl.orig/src/conf/capabilities.c
+++ libvirt-acl/src/conf/capabilities.c
@@ -859,14 +859,14 @@ virCapabilitiesFormatXML(virCapsPtr caps

 extern void
 virCapabilitiesSetMacPrefix(virCapsPtr caps,
-                            unsigned char *prefix)
+ const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN])
 {
     memcpy(caps->macPrefix, prefix, sizeof(caps->macPrefix));
 }

 extern void
 virCapabilitiesGenerateMac(virCapsPtr caps,
-                           unsigned char *mac)
+                           virMacAddrPtr mac)
 {
     virMacAddrGenerate(caps->macPrefix, mac);
 }
Index: libvirt-acl/src/conf/capabilities.h
===================================================================
--- libvirt-acl.orig/src/conf/capabilities.h
+++ libvirt-acl/src/conf/capabilities.h
@@ -172,11 +172,11 @@ virCapabilitiesFreeNUMAInfo(virCapsPtr c

 extern void
 virCapabilitiesSetMacPrefix(virCapsPtr caps,
-                            unsigned char *prefix);
+ const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN]);

 extern void
 virCapabilitiesGenerateMac(virCapsPtr caps,
-                           unsigned char *mac);
+                           virMacAddrPtr mac);

 extern void
 virCapabilitiesSetEmulatorRequired(virCapsPtr caps);
Index: libvirt-acl/src/conf/domain_audit.c
===================================================================
--- libvirt-acl.orig/src/conf/domain_audit.c
+++ libvirt-acl/src/conf/domain_audit.c
@@ -161,9 +161,9 @@ virDomainAuditNet(virDomainObjPtr vm,

     virUUIDFormat(vm->def->uuid, uuidstr);
     if (oldDef)
-        virMacAddrFormat(oldDef->mac, oldMacstr);
+        virMacAddrFormat(&oldDef->mac, oldMacstr);
     if (newDef)
-        virMacAddrFormat(newDef->mac, newMacstr);
+        virMacAddrFormat(&newDef->mac, newMacstr);
     if (!(vmname = virAuditEncode("vm", vm->def->name))) {
         VIR_WARN("OOM while encoding audit message");
         return;
@@ -207,7 +207,7 @@ virDomainAuditNetDevice(virDomainDefPtr
     const char *virt;

     virUUIDFormat(vmDef->uuid, uuidstr);
-    virMacAddrFormat(netDef->mac, macstr);
+    virMacAddrFormat(&netDef->mac, macstr);
     rdev = virDomainAuditGetRdev(device);

     if (!(vmname = virAuditEncode("vm", vmDef->name)) ||
Index: libvirt-acl/src/conf/domain_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/domain_conf.c
+++ libvirt-acl/src/conf/domain_conf.c
@@ -4609,20 +4609,20 @@ virDomainNetDefParseXML(virCapsPtr caps,
     }

     if (macaddr) {
-        if (virMacAddrParse((const char *)macaddr, def->mac) < 0) {
+        if (virMacAddrParse((const char *)macaddr, &def->mac) < 0) {
             virDomainReportError(VIR_ERR_XML_ERROR,
                                  _("unable to parse mac address '%s'"),
                                  (const char *)macaddr);
             goto error;
         }
-        if (virMacAddrIsMulticast(def->mac)) {
+        if (virMacAddrIsMulticast(&def->mac)) {
             virDomainReportError(VIR_ERR_XML_ERROR,
_("expected unicast mac address, found multicast '%s'"),
                                  (const char *)macaddr);
             goto error;
         }
     } else {
-        virCapabilitiesGenerateMac(caps, def->mac);
+        virCapabilitiesGenerateMac(caps, &def->mac);
     }

     if (devaddr) {
@@ -7410,12 +7410,12 @@ int virDomainNetInsert(virDomainDefPtr d
     return 0;
 }

-int virDomainNetIndexByMac(virDomainDefPtr def, const unsigned char *mac)
+int virDomainNetIndexByMac(virDomainDefPtr def, const virMacAddrPtr mac)
 {
     int i;

     for (i = 0; i < def->nnets; i++)
-        if (!memcmp(def->nets[i]->mac, mac, VIR_MAC_BUFLEN))
+        if (!virMacAddrCmp(&def->nets[i]->mac, mac))
             return i;
     return -1;
 }
@@ -7456,7 +7456,7 @@ virDomainNetRemove(virDomainDefPtr def,
 }

 virDomainNetDefPtr
-virDomainNetRemoveByMac(virDomainDefPtr def, const unsigned char *mac)
+virDomainNetRemoveByMac(virDomainDefPtr def, const virMacAddrPtr mac)
 {
     int i = virDomainNetIndexByMac(def, mac);

@@ -9678,14 +9678,14 @@ static bool virDomainNetDefCheckABIStabi
 {
     bool identical = false;

-    if (memcmp(src->mac, dst->mac, VIR_MAC_BUFLEN) != 0) {
+    if (virMacAddrCmp(&src->mac, &dst->mac) != 0) {
         virDomainReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target network card mac %02x:%02x:%02x:%02x:%02x:%02x" "does not match source %02x:%02x:%02x:%02x:%02x:%02x"),
-                             dst->mac[0], dst->mac[1], dst->mac[2],
-                             dst->mac[3], dst->mac[4], dst->mac[5],
-                             src->mac[0], src->mac[1], src->mac[2],
-                             src->mac[3], src->mac[4], src->mac[5]);
+ dst->mac.addr[0], dst->mac.addr[1], dst->mac.addr[2], + dst->mac.addr[3], dst->mac.addr[4], dst->mac.addr[5], + src->mac.addr[0], src->mac.addr[1], src->mac.addr[2], + src->mac.addr[3], src->mac.addr[4], src->mac.addr[5]);
         goto cleanup;
     }

@@ -11521,8 +11521,8 @@ virDomainNetDefFormat(virBufferPtr buf,

     virBufferAsprintf(buf,
                       " <mac address='%02x:%02x:%02x:%02x:%02x:%02x'/>\n",
-                      def->mac[0], def->mac[1], def->mac[2],
-                      def->mac[3], def->mac[4], def->mac[5]);
+                      def->mac.addr[0], def->mac.addr[1], def->mac.addr[2],
+ def->mac.addr[3], def->mac.addr[4], def->mac.addr[5]);

     switch (def->type) {
     case VIR_DOMAIN_NET_TYPE_NETWORK:
@@ -11650,7 +11650,7 @@ virDomainNetDefFormat(virBufferPtr buf,

         virBufferAdjustIndent(buf, 6);
         if (virNWFilterFormatParamAttributes(buf, def->filterparams,
-                                             def->filter, vmuuid, def->mac,
+ def->filter, vmuuid, &def->mac,
                                              ifname) < 0)
             return -1;
         virBufferAdjustIndent(buf, -6);
@@ -15169,15 +15169,15 @@ virDomainNetFind(virDomainDefPtr def, co
 {
     bool isMac = false;
     virDomainNetDefPtr net = NULL;
-    unsigned char mac[VIR_MAC_BUFLEN];
+    virMacAddr mac;
     int i;

-    if (virMacAddrParse(device, mac) == 0)
+    if (virMacAddrParse(device, &mac) == 0)
         isMac = true;

     if (isMac) {
         for (i = 0; i < def->nnets; i++) {
-            if (memcmp(mac, def->nets[i]->mac, VIR_MAC_BUFLEN) == 0) {
+            if (virMacAddrCmp(&mac, &def->nets[i]->mac) == 0) {
                 net = def->nets[i];
                 break;
             }
Index: libvirt-acl/src/conf/domain_nwfilter.c
===================================================================
--- libvirt-acl.orig/src/conf/domain_nwfilter.c
+++ libvirt-acl/src/conf/domain_nwfilter.c
@@ -66,7 +66,7 @@ virDomainConfNWFilterFormatLeases(virBuf
                                   virNWFilterHashTablePtr table,
                                   const char *ifname,
                                   const unsigned char *vmuuid,
-                                  const unsigned char *mac)
+                                  const virMacAddrPtr mac)
 {
     if (nwfilterDriver != NULL)
         nwfilterDriver->formatLeases(buf, table, ifname, vmuuid, mac);
Index: libvirt-acl/src/conf/domain_nwfilter.h
===================================================================
--- libvirt-acl.orig/src/conf/domain_nwfilter.h
+++ libvirt-acl/src/conf/domain_nwfilter.h
@@ -32,7 +32,7 @@ typedef void (*virDomainConfFormatLeases
                                           virNWFilterHashTablePtr table,
                                           const char *ifname,
                                           const unsigned char *vmuuid,
-                                          const unsigned char *mac);
+                                          const virMacAddrPtr mac);

 typedef struct {
     virDomainConfInstantiateNWFilter instantiateFilter;
@@ -52,6 +52,6 @@ void virDomainConfNWFilterFormatLeases(v
                                        virNWFilterHashTablePtr table,
                                        const char *ifname,
                                        const unsigned char *vmuuid,
-                                       const unsigned char *mac);
+                                       const virMacAddrPtr mac);

 #endif /* DOMAIN_NWFILTER_H */
Index: libvirt-acl/src/conf/network_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/network_conf.c
+++ libvirt-acl/src/conf/network_conf.c
@@ -420,19 +420,19 @@ virNetworkDHCPRangeDefParseXML(const cha
         } else if (cur->type == XML_ELEMENT_NODE &&
             xmlStrEqual(cur->name, BAD_CAST "host")) {
             char *mac = NULL, *name = NULL, *ip;
-            unsigned char addr[6];
+            virMacAddr addr;
             virSocketAddr inaddr;

             mac = virXMLPropString(cur, "mac");
             if (mac != NULL) {
-                if (virMacAddrParse(mac, &addr[0]) < 0) {
+                if (virMacAddrParse(mac, &addr) < 0) {
                     virNetworkReportError(VIR_ERR_XML_ERROR,
_("Cannot parse MAC address '%s' in network '%s'"),
                                           mac, networkName);
                     VIR_FREE(mac);
                     return -1;
                 }
-                if (virMacAddrIsMulticast(addr)) {
+                if (virMacAddrIsMulticast(&addr)) {
                     virNetworkReportError(VIR_ERR_XML_ERROR,
_("expected unicast mac address, found multicast '%s' in network '%s'"),
                                          (const char *)mac, networkName);
@@ -989,14 +989,14 @@ virNetworkDefParseXML(xmlXPathContextPtr

     tmp = virXPathString("string(./mac[1]/@address)", ctxt);
     if (tmp) {
-        if (virMacAddrParse(tmp, def->mac) < 0) {
+        if (virMacAddrParse(tmp, &def->mac) < 0) {
             virNetworkReportError(VIR_ERR_XML_ERROR,
_("Invalid bridge mac address '%s' in network '%s'"),
                                   tmp, def->name);
             VIR_FREE(tmp);
             goto error;
         }
-        if (virMacAddrIsMulticast(def->mac)) {
+        if (virMacAddrIsMulticast(&def->mac)) {
             virNetworkReportError(VIR_ERR_XML_ERROR,
_("Invalid multicast bridge mac address '%s' in network '%s'"),
                                  tmp, def->name);
@@ -1520,7 +1520,7 @@ char *virNetworkDefFormat(const virNetwo

     if (def->mac_specified) {
         char macaddr[VIR_MAC_STRING_BUFLEN];
-        virMacAddrFormat(def->mac, macaddr);
+        virMacAddrFormat(&def->mac, macaddr);
         virBufferAsprintf(&buf, " <mac address='%s'/>\n", macaddr);
     }

@@ -1848,7 +1848,7 @@ void virNetworkSetBridgeMacAddr(virNetwo
          * autogenerate a random one.
          */
         virMacAddrGenerate((unsigned char[]){ 0x52, 0x54, 0 },
-                           def->mac);
+ &def->mac);
         def->mac_specified = true;
     }
 }
Index: libvirt-acl/src/conf/network_conf.h
===================================================================
--- libvirt-acl.orig/src/conf/network_conf.h
+++ libvirt-acl/src/conf/network_conf.h
@@ -154,7 +154,7 @@ struct _virNetworkDef {
     char *domain;
     unsigned long delay;   /* Bridge forward delay (ms) */
     unsigned int stp :1; /* Spanning tree protocol */
-    unsigned char mac[VIR_MAC_BUFLEN]; /* mac address of bridge device */
+    virMacAddr mac; /* mac address of bridge device */
     bool mac_specified;

     int forwardType;    /* One of virNetworkForwardType constants */
Index: libvirt-acl/src/conf/nwfilter_conf.c
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_conf.c
+++ libvirt-acl/src/conf/nwfilter_conf.c
@@ -1774,15 +1774,6 @@ static const virAttributes virAttr[] = {
     PROTOCOL_ENTRY_LAST
 };

-
-static int
-virNWMACAddressParser(const char *input,
-                      nwMACAddressPtr output)
-{
-    return virMacAddrParse(input, &output->addr[0]);
-}
-
-
 static int
 virNWFilterRuleDetailsParse(xmlNodePtr node,
                             virNWFilterRuleDefPtr nwf,
@@ -1915,8 +1906,8 @@ virNWFilterRuleDetailsParse(xmlNodePtr n
                         break;

                         case DATATYPE_MACADDR:
-                            if (virNWMACAddressParser(prop,
- &item->u.macaddr) < 0) {
+                            if (virMacAddrParse(prop,
+ &item->u.macaddr) < 0) {
                                 rc = -1;
                             }
                             found = 1;
@@ -1924,8 +1915,8 @@ virNWFilterRuleDetailsParse(xmlNodePtr n

                         case DATATYPE_MACMASK:
                             validator = checkMACMask;
-                            if (virNWMACAddressParser(prop,
- &item->u.macaddr) < 0) {
+                            if (virMacAddrParse(prop,
+ &item->u.macaddr) < 0) {
                                 rc = -1;
                             }
                             data.v = &item->u.macaddr;
Index: libvirt-acl/src/conf/nwfilter_conf.h
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_conf.h
+++ libvirt-acl/src/conf/nwfilter_conf.h
@@ -36,6 +36,7 @@
 # include "xml.h"
 # include "buf.h"
 # include "virsocketaddr.h"
+# include "virmacaddr.h"

 /* XXX
  * The config parser/structs should not be using platform specific
@@ -113,13 +114,6 @@ enum attrDatatype {
 # define NWFILTER_MAC_BGA "01:80:c2:00:00:00"


-typedef struct _nwMACAddress nwMACAddress;
-typedef nwMACAddress *nwMACAddressPtr;
-struct _nwMACAddress {
-    unsigned char addr[6];
-};
-
-
 typedef struct _nwItemDesc nwItemDesc;
 typedef nwItemDesc *nwItemDescPtr;
 struct _nwItemDesc {
@@ -127,7 +121,7 @@ struct _nwItemDesc {
     virNWFilterVarAccessPtr varAccess;
     enum attrDatatype datatype;
     union {
-        nwMACAddress macaddr;
+        virMacAddr macaddr;
         virSocketAddr ipaddr;
         bool         boolean;
         uint8_t      u8;
@@ -633,10 +627,10 @@ typedef int (*virNWFilterRuleDisplayInst
 typedef int (*virNWFilterCanApplyBasicRules)(void);

 typedef int (*virNWFilterApplyBasicRules)(const char *ifname,
-                                          const unsigned char *macaddr);
+                                          const virMacAddrPtr macaddr);

 typedef int (*virNWFilterApplyDHCPOnlyRules)(const char *ifname,
-                                             const unsigned char *macaddr,
+                                             const virMacAddrPtr macaddr,
virNWFilterVarValuePtr dhcpsrvs,
                                              bool leaveTemporary);

Index: libvirt-acl/src/conf/nwfilter_params.c
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_params.c
+++ libvirt-acl/src/conf/nwfilter_params.c
@@ -885,7 +885,7 @@ virNWFilterFormatParamAttributes(virBuff
                                  virNWFilterHashTablePtr table,
                                  const char *filterref,
                                  const unsigned char *vmuuid,
-                                 const unsigned char *mac,
+                                 const virMacAddrPtr mac,
                                  const char *ifname)
 {
     virHashKeyValuePairPtr items;
Index: libvirt-acl/src/conf/nwfilter_params.h
===================================================================
--- libvirt-acl.orig/src/conf/nwfilter_params.h
+++ libvirt-acl/src/conf/nwfilter_params.h
@@ -25,6 +25,7 @@

 # include "virhash.h"
 # include "buf.h"
+# include "virmacaddr.h"

 enum virNWFilterVarValueType {
     NWFILTER_VALUE_TYPE_SIMPLE,
@@ -74,7 +75,7 @@ int virNWFilterFormatParamAttributes(vir
                                      virNWFilterHashTablePtr table,
                                      const char *filterref,
                                      const unsigned char *vmuuid,
-                                     const unsigned char *mac,
+                                     const virMacAddrPtr mac,
                                      const char *ifname);

 virNWFilterHashTablePtr virNWFilterHashTableCreate(int n);
Index: libvirt-acl/src/network/bridge_driver.c
===================================================================
--- libvirt-acl.orig/src/network/bridge_driver.c
+++ libvirt-acl/src/network/bridge_driver.c
@@ -1766,7 +1766,7 @@ networkStartNetworkVirtual(struct networ
             goto err0;
         }
         if (virNetDevTapCreateInBridgePort(network->def->bridge,
- &macTapIfName, network->def->mac,
+ &macTapIfName, &network->def->mac,
                                            NULL, NULL, NULL,
VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE) < 0) {
             VIR_FREE(macTapIfName);
Index: libvirt-acl/src/nwfilter/nwfilter_dhcpsnoop.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_dhcpsnoop.c
+++ libvirt-acl/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -484,7 +484,7 @@ virNWFilterSnoopIPLeaseInstallRule(virNW
                                               req->ifindex,
                                               req->linkdev,
                                               req->nettype,
-                                              req->macaddr,
+ &req->macaddr,
                                               req->filtername,
                                               req->vars,
                                               req->driver);
@@ -875,7 +875,7 @@ virNWFilterSnoopReqLeaseDel(virNWFilterS
                                                req->ifindex,
                                                req->linkdev,
                                                req->nettype,
-                                               req->macaddr,
+ &req->macaddr,
                                                req->filtername,
                                                req->vars,
                                                req->driver);
@@ -884,7 +884,7 @@ virNWFilterSnoopReqLeaseDel(virNWFilterS
virHashLookup(req->vars->hashTable, NWFILTER_VARNAME_DHCPSERVER);

         if (req->techdriver &&
-            req->techdriver->applyDHCPOnlyRules(req->ifname, req->macaddr,
+            req->techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr,
                                                 dhcpsrvrs, false) < 0) {
             virNWFilterReportError(VIR_ERR_INTERNAL_ERROR,
                                    _("virNWFilterSnoopListDel failed"));
@@ -1071,7 +1071,7 @@ virNWFilterSnoopDHCPOpen(const char *ifn
     char macaddr[VIR_MAC_STRING_BUFLEN];
     const char *ext;

-    virMacAddrFormat((unsigned char *)mac, macaddr);
+    virMacAddrFormat(mac, macaddr);

     if (dir == PCAP_D_IN /* from VM */) {
         /*
@@ -1560,7 +1560,7 @@ exit:

 static void
 virNWFilterSnoopIFKeyFMT(char *ifkey, const unsigned char *vmuuid,
-                         unsigned const char *macaddr)
+                         const virMacAddrPtr macaddr)
 {
     virUUIDFormat(vmuuid, ifkey);
     ifkey[VIR_UUID_STRING_BUFLEN - 1] = '-';
@@ -1573,7 +1573,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechD
                         const char *linkdev,
                         enum virDomainNetType nettype,
                         const unsigned char *vmuuid,
-                        const unsigned char *macaddr,
+                        const virMacAddrPtr macaddr,
                         const char *filtername,
                         virNWFilterHashTablePtr filterparams,
                         virNWFilterDriverStatePtr driver)
@@ -1609,7 +1609,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechD
     req->linkdev = linkdev ? strdup(linkdev) : NULL;
     req->nettype = nettype;
     req->ifname = strdup(ifname);
-    memcpy(req->macaddr, macaddr, sizeof(req->macaddr));
+    virMacAddrSet(&req->macaddr, macaddr);
     req->filtername = strdup(filtername);
     req->vars = virNWFilterHashTableCreate(0);

@@ -1631,7 +1631,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechD
     dhcpsrvrs = virHashLookup(filterparams->hashTable,
                               NWFILTER_VARNAME_DHCPSERVER);

-    if (techdriver->applyDHCPOnlyRules(req->ifname, req->macaddr,
+    if (techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr,
                                        dhcpsrvrs, false) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, _("applyDHCPOnlyRules "
                                "failed - spoofing not protected!"));
@@ -1993,7 +1993,7 @@ virNWFilterSnoopLeaseFileLoad(void)
 void
 virNWFilterSnoopFormatLeases(virBufferPtr buf,
                              const unsigned char *vmuuid,
-                             const unsigned char *macaddr)
+                             const virMacAddrPtr macaddr)
 {
     char ifkey[VIR_IFKEY_LEN];
     virNWFilterSnoopReqPtr req;
Index: libvirt-acl/src/nwfilter/nwfilter_dhcpsnoop.h
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_dhcpsnoop.h
+++ libvirt-acl/src/nwfilter/nwfilter_dhcpsnoop.h
@@ -31,13 +31,13 @@ int virNWFilterDHCPSnoopReq(virNWFilterT
                             const char *linkdev,
                             enum virDomainNetType nettype,
                             const unsigned char *vmuuid,
-                            const unsigned char *macaddr,
+                            const virMacAddrPtr macaddr,
                             const char *filtername,
                             virNWFilterHashTablePtr filterparams,
                             virNWFilterDriverStatePtr driver);
 void virNWFilterDHCPSnoopEnd(const char *ifname);
 void virNWFilterSnoopFormatLeases(virBufferPtr buf,
                                   const unsigned char *vmuuid,
-                                  const unsigned char *macaddr);
+                                  const virMacAddrPtr macaddr);

 #endif /* __NWFILTER_DHCPSNOOP_H */
Index: libvirt-acl/src/nwfilter/nwfilter_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_driver.c
@@ -468,7 +468,7 @@ nwfilterFormatLeases(virBufferPtr buf,
                      virNWFilterHashTablePtr vars,
                      const char *ifname,
                      const unsigned char *vmuuid,
-                     const unsigned char *mac)
+                     virMacAddrPtr mac)
 {
     virNWFilterFormatLeases(buf, vars, ifname, vmuuid, mac);
 }
Index: libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_ebiptables_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -306,7 +306,7 @@ _printDataType(virNWFilterVarCombIterPtr
             return -1;
         }

-        virMacAddrFormat(item->u.macaddr.addr, buf);
+        virMacAddrFormat(&item->u.macaddr, buf);
     break;

     case DATATYPE_IPV6MASK:
@@ -3189,7 +3189,7 @@ ebiptablesCanApplyBasicRules(void) {
  */
 static int
 ebtablesApplyBasicRules(const char *ifname,
-                        const unsigned char *macaddr)
+                        const virMacAddrPtr macaddr)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     char chain[MAX_CHAINNAME_LENGTH];
@@ -3282,7 +3282,7 @@ tear_down_tmpebchains:
  */
 static int
 ebtablesApplyDHCPOnlyRules(const char *ifname,
-                           const unsigned char *macaddr,
+                           const virMacAddrPtr macaddr,
                            virNWFilterVarValuePtr dhcpsrvrs,
                            bool leaveTemporary)
 {
Index: libvirt-acl/src/nwfilter/nwfilter_gentech_driver.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_gentech_driver.c
+++ libvirt-acl/src/nwfilter/nwfilter_gentech_driver.c
@@ -655,7 +655,7 @@ virNWFilterInstantiate(const unsigned ch
                        virNWFilterHashTablePtr vars,
                        enum instCase useNewFilter, bool *foundNewFilter,
                        bool teardownOld,
-                       const unsigned char *macaddr,
+                       const virMacAddrPtr macaddr,
                        virNWFilterDriverStatePtr driver,
                        bool forceWithPendingReq)
 {
@@ -816,7 +816,7 @@ __virNWFilterInstantiateFilter(const uns
                                int ifindex,
                                const char *linkdev,
                                enum virDomainNetType nettype,
-                               const unsigned char *macaddr,
+                               const virMacAddrPtr macaddr,
                                const char *filtername,
                                virNWFilterHashTablePtr filterparams,
                                enum instCase useNewFilter,
@@ -966,7 +966,7 @@ _virNWFilterInstantiateFilter(virConnect
                                         ifindex,
                                         linkdev,
                                         net->type,
-                                        net->mac,
+ &net->mac,
                                         net->filter,
                                         net->filterparams,
                                         useNewFilter,
@@ -987,7 +987,7 @@ virNWFilterInstantiateFilterLate(const u
                                  int ifindex,
                                  const char *linkdev,
                                  enum virDomainNetType nettype,
-                                 const unsigned char *macaddr,
+                                 const virMacAddrPtr macaddr,
                                  const char *filtername,
                                  virNWFilterHashTablePtr filterparams,
                                  virNWFilterDriverStatePtr driver)
@@ -1215,7 +1215,7 @@ virNWFilterFormatLeases(virBufferPtr buf
                         virNWFilterHashTablePtr vars,
                         const char *ifname,
                         const unsigned char *vmuuid,
-                        const unsigned char *mac)
+                        const virMacAddrPtr mac)
 {
     virNWFilterVarValuePtr lv;
     const char *learning = NULL;
Index: libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_gentech_driver.h
+++ libvirt-acl/src/nwfilter/nwfilter_gentech_driver.h
@@ -50,7 +50,7 @@ int virNWFilterInstantiateFilterLate(con
                                      int ifindex,
                                      const char *linkdev,
                                      enum virDomainNetType nettype,
-                                     const unsigned char *macaddr,
+                                     const virMacAddrPtr macaddr,
                                      const char *filtername,
                                      virNWFilterHashTablePtr filterparams,
                                      virNWFilterDriverStatePtr driver);
@@ -68,6 +68,6 @@ void virNWFilterFormatLeases(virBufferPt
                              virNWFilterHashTablePtr vars,
                              const char *ifname,
                              const unsigned char *vmmuid,
-                             const unsigned char *mac);
+                             const virMacAddrPtr mac);

 #endif
Index: libvirt-acl/src/nwfilter/nwfilter_learnipaddr.c
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_learnipaddr.c
+++ libvirt-acl/src/nwfilter/nwfilter_learnipaddr.c
@@ -404,12 +404,12 @@ learnIPAddressThread(void *arg)
         goto done;
     }

-    virMacAddrFormat(req->macaddr, macaddr);
+    virMacAddrFormat(&req->macaddr, macaddr);

     switch (req->howDetect) {
     case DETECT_DHCP:
         if (techdriver->applyDHCPOnlyRules(req->ifname,
-                                           req->macaddr,
+ &req->macaddr,
                                            NULL, false) < 0) {
             req->status = EINVAL;
             goto done;
@@ -420,7 +420,7 @@ learnIPAddressThread(void *arg)
         break;
     default:
         if (techdriver->applyBasicRules(req->ifname,
-                                        req->macaddr) < 0) {
+ &req->macaddr) < 0) {
             req->status = EINVAL;
             goto done;
         }
@@ -493,9 +493,7 @@ learnIPAddressThread(void *arg)
                 continue;
             }

-            if (memcmp(ether_hdr->ether_shost,
-                       req->macaddr,
-                       VIR_MAC_BUFLEN) == 0) {
+ if (virMacAddrCmpRaw(&req->macaddr, ether_hdr->ether_shost) == 0) {
                 /* packets from the VM */

                 if (etherType == ETHERTYPE_IP &&
@@ -530,9 +528,8 @@ learnIPAddressThread(void *arg)
                     break;
                     }
                 }
-            } else if (memcmp(ether_hdr->ether_dhost,
-                              req->macaddr,
-                              VIR_MAC_BUFLEN) == 0) {
+            } else if (virMacAddrCmpRaw(&req->macaddr,
+                                        ether_hdr->ether_dhost) == 0) {
                 /* packets to the VM */
                 if (etherType == ETHERTYPE_IP &&
                     (header.len >= ethHdrSize +
@@ -554,9 +551,9 @@ learnIPAddressThread(void *arg)
                             struct dhcp *dhcp = (struct dhcp *)
                                         ((char *)udphdr + sizeof(udphdr));
                             if (dhcp->op == 2 /* BOOTREPLY */ &&
-                                !memcmp(&dhcp->chaddr[0],
-                                        req->macaddr,
-                                        6)) {
+                                virMacAddrCmpRaw(
+ &req->macaddr,
+ &dhcp->chaddr[0]) == 0) {
                                 dhcp_opts_len = header.len -
                                     (ethHdrSize + iphdr->ihl * 4 +
                                      sizeof(struct udphdr) +
@@ -602,7 +599,7 @@ learnIPAddressThread(void *arg)
                                                    req->ifindex,
                                                    req->linkdev,
                                                    req->nettype,
-                                                   req->macaddr,
+ &req->macaddr,
                                                    req->filtername,
                                                    req->filterparams,
                                                    req->driver);
@@ -662,7 +659,7 @@ virNWFilterLearnIPAddress(virNWFilterTec
                           int ifindex,
                           const char *linkdev,
                           enum virDomainNetType nettype,
-                          const unsigned char *macaddr,
+                          const virMacAddrPtr macaddr,
                           const char *filtername,
                           virNWFilterHashTablePtr filterparams,
                           virNWFilterDriverStatePtr driver,
@@ -720,7 +717,7 @@ virNWFilterLearnIPAddress(virNWFilterTec

     req->ifindex = ifindex;
     req->nettype = nettype;
-    memcpy(req->macaddr, macaddr, sizeof(req->macaddr));
+    virMacAddrSet(&req->macaddr, macaddr);
     req->driver = driver;
     req->filterparams = ht;
     ht = NULL;
@@ -758,7 +755,7 @@ virNWFilterLearnIPAddress(virNWFilterTec
                           int ifindex ATTRIBUTE_UNUSED,
                           const char *linkdev ATTRIBUTE_UNUSED,
                           enum virDomainNetType nettype ATTRIBUTE_UNUSED,
-                          const unsigned char *macaddr ATTRIBUTE_UNUSED,
+                          const virMacAddrPtr macaddr ATTRIBUTE_UNUSED,
                           const char *filtername ATTRIBUTE_UNUSED,
virNWFilterHashTablePtr filterparams ATTRIBUTE_UNUSED, virNWFilterDriverStatePtr driver ATTRIBUTE_UNUSED,
Index: libvirt-acl/src/nwfilter/nwfilter_learnipaddr.h
===================================================================
--- libvirt-acl.orig/src/nwfilter/nwfilter_learnipaddr.h
+++ libvirt-acl/src/nwfilter/nwfilter_learnipaddr.h
@@ -40,7 +40,7 @@ struct _virNWFilterIPAddrLearnReq {
     int ifindex;
     char linkdev[IF_NAMESIZE];
     enum virDomainNetType nettype;
-    unsigned char macaddr[VIR_MAC_BUFLEN];
+    virMacAddr macaddr;
     char *filtername;
     virNWFilterHashTablePtr filterparams;
     virNWFilterDriverStatePtr driver;
@@ -56,7 +56,7 @@ int virNWFilterLearnIPAddress(virNWFilte
                               int ifindex,
                               const char *linkdev,
                               enum virDomainNetType nettype,
-                              const unsigned char *macaddr,
+                              const virMacAddrPtr macaddr,
                               const char *filtername,
                               virNWFilterHashTablePtr filterparams,
                               virNWFilterDriverStatePtr driver,
Index: libvirt-acl/src/openvz/openvz_conf.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_conf.c
+++ libvirt-acl/src/openvz/openvz_conf.c
@@ -336,7 +336,7 @@ openvzReadNetworkConf(virDomainDefPtr de
_("MAC address %s too long for destination"), p);
                         goto error;
                     }
-                    if (virMacAddrParse(cpy_temp, net->mac) < 0) {
+                    if (virMacAddrParse(cpy_temp, &net->mac) < 0) {
                         openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
                                     _("Wrong MAC address"));
                         goto error;
Index: libvirt-acl/src/openvz/openvz_driver.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_driver.c
+++ libvirt-acl/src/openvz/openvz_driver.c
@@ -732,7 +732,7 @@ openvzDomainSetNetwork(virConnectPtr con
     int rc = 0, narg;
     const char *prog[OPENVZ_MAX_ARG];
     char macaddr[VIR_MAC_STRING_BUFLEN];
-    unsigned char host_mac[VIR_MAC_BUFLEN];
+    virMacAddr host_mac;
     char host_macaddr[VIR_MAC_STRING_BUFLEN];
     struct openvz_driver *driver =  conn->privateData;
     char *opt = NULL;
@@ -767,9 +767,9 @@ openvzDomainSetNetwork(virConnectPtr con
         ADD_ARG_LIT(vpsid);
     }

-    virMacAddrFormat(net->mac, macaddr);
-    virCapabilitiesGenerateMac(driver->caps, host_mac);
-    virMacAddrFormat(host_mac, host_macaddr);
+    virMacAddrFormat(&net->mac, macaddr);
+    virCapabilitiesGenerateMac(driver->caps, &host_mac);
+    virMacAddrFormat(&host_mac, host_macaddr);

     if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
         (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
Index: libvirt-acl/src/qemu/qemu_bridge_filter.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_bridge_filter.c
+++ libvirt-acl/src/qemu/qemu_bridge_filter.c
@@ -66,7 +66,7 @@ networkDisableAllFrames(struct qemud_dri
 int
 networkAllowMacOnPort(struct qemud_driver *driver,
                       const char * ifname,
-                      const unsigned char * mac) {
+                      const virMacAddrPtr mac) {

     int err;

@@ -87,7 +87,7 @@ networkAllowMacOnPort(struct qemud_drive
 int
 networkDisallowMacOnPort(struct qemud_driver *driver,
                          const char * ifname,
-                         const unsigned char * mac) {
+                         const virMacAddrPtr mac) {

     int err;

Index: libvirt-acl/src/qemu/qemu_bridge_filter.h
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_bridge_filter.h
+++ libvirt-acl/src/qemu/qemu_bridge_filter.h
@@ -26,10 +26,10 @@

 int networkAllowMacOnPort(struct qemud_driver *driver,
                           const char * ifname,
-                          const unsigned char * mac);
+                          const virMacAddrPtr mac);
 int networkDisallowMacOnPort(struct qemud_driver *driver,
                              const char * ifname,
-                             const unsigned char * mac);
+                             const virMacAddrPtr mac);
 int networkDisableAllFrames(struct qemud_driver *driver);
 int networkAddEbtablesRules(struct qemud_driver *driver);

Index: libvirt-acl/src/qemu/qemu_command.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_command.c
+++ libvirt-acl/src/qemu/qemu_command.c
@@ -156,7 +156,7 @@ qemuPhysIfaceConnect(virDomainDefPtr def
         vnet_hdr = 1;

     rc = virNetDevMacVLanCreateWithVPortProfile(
-        net->ifname, net->mac,
+        net->ifname, &net->mac,
         virDomainNetGetActualDirectDev(net),
         virDomainNetGetActualDirectMode(net),
         true, vnet_hdr, def->uuid,
@@ -250,7 +250,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr
         tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
     }

-    err = virNetDevTapCreateInBridgePort(brname, &net->ifname, net->mac,
+    err = virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac,
                                          def->uuid, &tapfd,
virDomainNetGetActualVirtPortProfile(net),
                                          tap_create_flags);
@@ -262,7 +262,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr
     }

     if (driver->macFilter) {
-        if ((err = networkAllowMacOnPort(driver, net->ifname, net->mac))) {
+ if ((err = networkAllowMacOnPort(driver, net->ifname, &net->mac))) {
             virReportSystemError(err,
_("failed to add ebtables rule to allow MAC address on '%s'"),
                                  net->ifname);
@@ -2736,9 +2736,9 @@ qemuBuildNicStr(virDomainNetDefPtr net,
     if (virAsprintf(&str,
"%smacaddr=%02x:%02x:%02x:%02x:%02x:%02x,vlan=%d%s%s%s%s",
                     prefix ? prefix : "",
-                    net->mac[0], net->mac[1],
-                    net->mac[2], net->mac[3],
-                    net->mac[4], net->mac[5],
+                    net->mac.addr[0], net->mac.addr[1],
+                    net->mac.addr[2], net->mac.addr[3],
+                    net->mac.addr[4], net->mac.addr[5],
                     vlan,
                     (net->model ? ",model=" : ""),
                     (net->model ? net->model : ""),
@@ -2811,9 +2811,9 @@ qemuBuildNicDevStr(virDomainNetDefPtr ne
         virBufferAsprintf(&buf, ",vlan=%d", vlan);
     virBufferAsprintf(&buf, ",id=%s", net->info.alias);
     virBufferAsprintf(&buf, ",mac=%02x:%02x:%02x:%02x:%02x:%02x",
-                      net->mac[0], net->mac[1],
-                      net->mac[2], net->mac[3],
-                      net->mac[4], net->mac[5]);
+                      net->mac.addr[0], net->mac.addr[1],
+                      net->mac.addr[2], net->mac.addr[3],
+                      net->mac.addr[4], net->mac.addr[5]);
     if (qemuBuildDeviceAddressStr(&buf, &net->info, qemuCaps) < 0)
         goto error;
     if (qemuBuildRomStr(&buf, &net->info, qemuCaps) < 0)
@@ -6902,7 +6902,7 @@ qemuParseCommandLineNet(virCapsPtr caps,
     for (i = 0 ; i < nkeywords ; i++) {
         if (STREQ(keywords[i], "macaddr")) {
             genmac = 0;
-            if (virMacAddrParse(values[i], def->mac) < 0) {
+            if (virMacAddrParse(values[i], &def->mac) < 0) {
                 qemuReportError(VIR_ERR_INTERNAL_ERROR,
                                 _("unable to parse mac address '%s'"),
                                 values[i]);
@@ -6932,7 +6932,7 @@ qemuParseCommandLineNet(virCapsPtr caps,
     }

     if (genmac)
-        virCapabilitiesGenerateMac(caps, def->mac);
+        virCapabilitiesGenerateMac(caps, &def->mac);

 cleanup:
     for (i = 0 ; i < nkeywords ; i++) {
Index: libvirt-acl/src/qemu/qemu_driver.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_driver.c
+++ libvirt-acl/src/qemu/qemu_driver.c
@@ -437,7 +437,7 @@ static void qemuDomainNetsRestart(void *
VIR_DEBUG("VEPA mode device %s active in domain %s. Reassociating.",
                       net->ifname, def->name);
ignore_value(virNetDevMacVLanRestartWithVPortProfile(net->ifname,
-                                                                 net->mac,
+ &net->mac,
virDomainNetGetActualDirectDev(net), def->uuid, virDomainNetGetActualVirtPortProfile(net),
@@ -5488,9 +5488,10 @@ qemuDomainAttachDeviceConfig(virDomainDe

     case VIR_DOMAIN_DEVICE_NET:
         net = dev->data.net;
-        if (virDomainNetIndexByMac(vmdef, net->mac) >= 0) {
+        if (virDomainNetIndexByMac(vmdef, &net->mac) >= 0) {
             char macbuf[VIR_MAC_STRING_BUFLEN];
-            virMacAddrFormat(net->mac, macbuf);
+
+            virMacAddrFormat(&net->mac, macbuf);
             qemuReportError(VIR_ERR_INVALID_ARG,
                             _("mac %s already exists"), macbuf);
             return -1;
@@ -5566,10 +5567,10 @@ qemuDomainDetachDeviceConfig(virDomainDe

     case VIR_DOMAIN_DEVICE_NET:
         net = dev->data.net;
-        if (!(det_net = virDomainNetRemoveByMac(vmdef, net->mac))) {
+        if (!(det_net = virDomainNetRemoveByMac(vmdef, &net->mac))) {
             char macbuf[VIR_MAC_STRING_BUFLEN];

-            virMacAddrFormat(net->mac, macbuf);
+            virMacAddrFormat(&net->mac, macbuf);
             qemuReportError(VIR_ERR_INVALID_ARG,
                             _("no nic of mac %s"), macbuf);
             return -1;
@@ -5657,9 +5658,10 @@ qemuDomainUpdateDeviceConfig(virDomainDe

     case VIR_DOMAIN_DEVICE_NET:
         net = dev->data.net;
-        if ((pos = virDomainNetIndexByMac(vmdef, net->mac)) < 0) {
+        if ((pos = virDomainNetIndexByMac(vmdef, &net->mac)) < 0) {
             char macbuf[VIR_MAC_STRING_BUFLEN];
-            virMacAddrFormat(net->mac, macbuf);
+
+            virMacAddrFormat(&net->mac, macbuf);
             qemuReportError(VIR_ERR_INVALID_ARG,
                             _("mac %s doesn't exist"), macbuf);
             return -1;
Index: libvirt-acl/src/qemu/qemu_hostdev.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_hostdev.c
+++ libvirt-acl/src/qemu/qemu_hostdev.c
@@ -257,7 +257,7 @@ cleanup:
 static int
 qemuDomainHostdevNetConfigVirtPortProfile(const char *linkdev, int vf,
virNetDevVPortProfilePtr virtPort,
-                                          const unsigned char *macaddr,
+                                          const virMacAddrPtr macaddr,
                                           const unsigned char *uuid,
                                           int associate)
 {
@@ -320,12 +320,12 @@ qemuDomainHostdevNetConfigReplace(virDom
                                  hostdev->parent.data.net);
     if (virtPort)
         ret = qemuDomainHostdevNetConfigVirtPortProfile(linkdev, vf,
-                            virtPort, hostdev->parent.data.net->mac, uuid,
+                            virtPort, &hostdev->parent.data.net->mac, uuid,
                             port_profile_associate);
     else
         /* Set only mac */
         ret = virNetDevReplaceNetConfig(linkdev, vf,
- hostdev->parent.data.net->mac, vlanid,
+ &hostdev->parent.data.net->mac, vlanid,
                                         stateDir);
     VIR_FREE(linkdev);

@@ -358,7 +358,7 @@ qemuDomainHostdevNetConfigRestore(virDom
                                  hostdev->parent.data.net);
     if (virtPort)
ret = qemuDomainHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, - hostdev->parent.data.net->mac, NULL,
+ &hostdev->parent.data.net->mac, NULL,
                                           port_profile_associate);
     else
         ret = virNetDevRestoreNetConfig(linkdev, vf, stateDir);
Index: libvirt-acl/src/qemu/qemu_hotplug.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_hotplug.c
+++ libvirt-acl/src/qemu/qemu_hotplug.c
@@ -1226,7 +1226,7 @@ static virDomainNetDefPtr qemuDomainFind
     int i;

     for (i = 0; i < vm->def->nnets; i++) {
-        if (memcmp(vm->def->nets[i]->mac, dev->mac, VIR_MAC_BUFLEN) == 0)
+        if (virMacAddrCmp(&vm->def->nets[i]->mac, &dev->mac) == 0)
             return vm->def->nets[i];
     }

@@ -2185,7 +2185,7 @@ qemuDomainDetachNetDevice(struct qemud_d
     for (i = 0 ; i < vm->def->nnets ; i++) {
         virDomainNetDefPtr net = vm->def->nets[i];

-        if (!memcmp(net->mac, dev->data.net->mac,  sizeof(net->mac))) {
+        if (!virMacAddrCmp(&net->mac, &dev->data.net->mac)) {
             detach = net;
             break;
         }
@@ -2194,9 +2194,9 @@ qemuDomainDetachNetDevice(struct qemud_d
     if (!detach) {
         qemuReportError(VIR_ERR_OPERATION_FAILED,
_("network device %02x:%02x:%02x:%02x:%02x:%02x not found"),
-                        dev->data.net->mac[0], dev->data.net->mac[1],
-                        dev->data.net->mac[2], dev->data.net->mac[3],
-                        dev->data.net->mac[4], dev->data.net->mac[5]);
+ dev->data.net->mac.addr[0], dev->data.net->mac.addr[1], + dev->data.net->mac.addr[2], dev->data.net->mac.addr[3], + dev->data.net->mac.addr[4], dev->data.net->mac.addr[5]);
         goto cleanup;
     }

@@ -2275,7 +2275,7 @@ qemuDomainDetachNetDevice(struct qemud_d

     if (virDomainNetGetActualType(detach) == VIR_DOMAIN_NET_TYPE_DIRECT) {
         ignore_value(virNetDevMacVLanDeleteWithVPortProfile(
-                         detach->ifname, detach->mac,
+                         detach->ifname, &detach->mac,
                          virDomainNetGetActualDirectDev(detach),
                          virDomainNetGetActualDirectMode(detach),
                          virDomainNetGetActualVirtPortProfile(detach),
@@ -2286,7 +2286,7 @@ qemuDomainDetachNetDevice(struct qemud_d
     if ((driver->macFilter) && (detach->ifname != NULL)) {
         if ((errno = networkDisallowMacOnPort(driver,
                                               detach->ifname,
-                                              detach->mac))) {
+ &detach->mac))) {
             virReportSystemError(errno,
              _("failed to remove ebtables rule on  '%s'"),
                                  detach->ifname);
Index: libvirt-acl/src/qemu/qemu_migration.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_migration.c
+++ libvirt-acl/src/qemu/qemu_migration.c
@@ -2849,7 +2849,7 @@ qemuMigrationVPAssociatePortProfiles(vir
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
             if (virNetDevVPortProfileAssociate(net->ifname,
virDomainNetGetActualVirtPortProfile(net),
-                                               net->mac,
+ &net->mac,
virDomainNetGetActualDirectDev(net),
                                                -1,
                                                def->uuid,
@@ -2862,7 +2862,7 @@ qemuMigrationVPAssociatePortProfiles(vir
             }
VIR_DEBUG("Port profile Associate succeeded for %s", net->ifname);

- if (virNetDevMacVLanVPortProfileRegisterCallback(net->ifname, net->mac, + if (virNetDevMacVLanVPortProfileRegisterCallback(net->ifname, &net->mac, virDomainNetGetActualDirectDev(net), def->uuid, virDomainNetGetActualVirtPortProfile(net), VIR_NETDEV_VPORT_PROFILE_OP_CREATE))
@@ -2879,7 +2879,7 @@ err_exit:
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
             ignore_value(virNetDevVPortProfileDisassociate(net->ifname,
virDomainNetGetActualVirtPortProfile(net),
-                                                           net->mac,
+ &net->mac,
virDomainNetGetActualDirectDev(net),
                                                            -1,
VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_FINISH));
Index: libvirt-acl/src/qemu/qemu_process.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_process.c
+++ libvirt-acl/src/qemu/qemu_process.c
@@ -3929,7 +3929,7 @@ void qemuProcessStop(struct qemud_driver
             if (net->ifname == NULL)
                 continue;
             if ((errno = networkDisallowMacOnPort(driver, net->ifname,
-                                                  net->mac))) {
+ &net->mac))) {
                 virReportSystemError(errno,
_("failed to remove ebtables rule to allow MAC address on '%s'"),
                                      net->ifname);
@@ -4000,7 +4000,7 @@ void qemuProcessStop(struct qemud_driver
         virDomainNetDefPtr net = def->nets[i];
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
             ignore_value(virNetDevMacVLanDeleteWithVPortProfile(
-                             net->ifname, net->mac,
+                             net->ifname, &net->mac,
                              virDomainNetGetActualDirectDev(net),
                              virDomainNetGetActualDirectMode(net),
                              virDomainNetGetActualVirtPortProfile(net),
Index: libvirt-acl/src/uml/uml_conf.c
===================================================================
--- libvirt-acl.orig/src/uml/uml_conf.c
+++ libvirt-acl/src/uml/uml_conf.c
@@ -138,7 +138,7 @@ umlConnectTapDevice(virConnectPtr conn,
         template_ifname = true;
     }

-    if (virNetDevTapCreateInBridgePort(bridge, &net->ifname, net->mac,
+    if (virNetDevTapCreateInBridgePort(bridge, &net->ifname, &net->mac,
                                        vm->uuid, NULL,
virDomainNetGetActualVirtPortProfile(net),
                                        VIR_NETDEV_TAP_CREATE_IFUP) < 0) {
@@ -271,8 +271,8 @@ umlBuildCommandLineNet(virConnectPtr con
     }

     virBufferAsprintf(&buf, ",%02x:%02x:%02x:%02x:%02x:%02x",
-                      def->mac[0], def->mac[1], def->mac[2],
-                      def->mac[3], def->mac[4], def->mac[5]);
+                      def->mac.addr[0], def->mac.addr[1], def->mac.addr[2],
+ def->mac.addr[3], def->mac.addr[4], def->mac.addr[5]);

     if (def->type == VIR_DOMAIN_NET_TYPE_MCAST) {
         virBufferAsprintf(&buf, ",%s,%d",
Index: libvirt-acl/src/util/ebtables.c
===================================================================
--- libvirt-acl.orig/src/util/ebtables.c
+++ libvirt-acl/src/util/ebtables.c
@@ -392,15 +392,15 @@ ebtablesForwardAllowIn(ebtablesContext *
 int
 ebtablesAddForwardAllowIn(ebtablesContext *ctx,
                           const char *iface,
-                          const unsigned char *mac)
+                          const virMacAddrPtr mac)
 {
     char *macaddr;

     if (virAsprintf(&macaddr,
                     "%02x:%02x:%02x:%02x:%02x:%02x",
-                    mac[0], mac[1],
-                    mac[2], mac[3],
-                    mac[4], mac[5]) < 0) {
+                    mac->addr[0], mac->addr[1],
+                    mac->addr[2], mac->addr[3],
+                    mac->addr[4], mac->addr[5]) < 0) {
         return -1;
     }
     return ebtablesForwardAllowIn(ctx, iface, macaddr, ADD);
@@ -421,15 +421,15 @@ ebtablesAddForwardAllowIn(ebtablesContex
 int
 ebtablesRemoveForwardAllowIn(ebtablesContext *ctx,
                              const char *iface,
-                             const unsigned char *mac)
+                             const virMacAddrPtr mac)
 {
     char *macaddr;

     if (virAsprintf(&macaddr,
                     "%02x:%02x:%02x:%02x:%02x:%02x",
-                    mac[0], mac[1],
-                    mac[2], mac[3],
-                    mac[4], mac[5]) < 0) {
+                    mac->addr[0], mac->addr[1],
+                    mac->addr[2], mac->addr[3],
+                    mac->addr[4], mac->addr[5]) < 0) {
        return -1;
     }
     return ebtablesForwardAllowIn(ctx, iface, macaddr, REMOVE);
Index: libvirt-acl/src/util/ebtables.h
===================================================================
--- libvirt-acl.orig/src/util/ebtables.h
+++ libvirt-acl/src/util/ebtables.h
@@ -24,6 +24,8 @@
 #ifndef __QEMUD_EBTABLES_H__
 # define __QEMUD_EBTABLES_H__

+# include "virmacaddr.h"
+
 typedef struct
 {
     char  *rule;
@@ -50,10 +52,10 @@ void             ebtablesSaveRules

 int              ebtablesAddForwardAllowIn       (ebtablesContext *ctx,
                                                   const char *iface,
- const unsigned char *mac);
+                                                  const virMacAddrPtr mac);
 int              ebtablesRemoveForwardAllowIn    (ebtablesContext *ctx,
                                                   const char *iface,
- const unsigned char *mac);
+                                                  const virMacAddrPtr mac);

 int              ebtablesAddForwardPolicyReject(ebtablesContext *ctx);

Index: libvirt-acl/src/util/virnetdevopenvswitch.c
===================================================================
--- libvirt-acl.orig/src/util/virnetdevopenvswitch.c
+++ libvirt-acl/src/util/virnetdevopenvswitch.c
@@ -44,7 +44,7 @@
  * Returns 0 in case of success or -1 in case of failure.
  */
 int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
-                                   const unsigned char *macaddr,
+                                   const virMacAddrPtr macaddr,
                                    const unsigned char *vmuuid,
                                    virNetDevVPortProfilePtr ovsport)
 {
Index: libvirt-acl/src/util/virnetdevopenvswitch.h
===================================================================
--- libvirt-acl.orig/src/util/virnetdevopenvswitch.h
+++ libvirt-acl/src/util/virnetdevopenvswitch.h
@@ -31,7 +31,7 @@

 int virNetDevOpenvswitchAddPort(const char *brname,
                                 const char *ifname,
-                                const unsigned char *macaddr,
+                                const virMacAddrPtr macaddr,
                                 const unsigned char *vmuuid,
                                 virNetDevVPortProfilePtr ovsport)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
Index: libvirt-acl/src/util/virnetdevtap.c
===================================================================
--- libvirt-acl.orig/src/util/virnetdevtap.c
+++ libvirt-acl/src/util/virnetdevtap.c
@@ -256,7 +256,7 @@ int virNetDevTapDelete(const char *ifnam
  * virNetDevTapCreateInBridgePort:
  * @brname: the bridge name
  * @ifname: the interface name (or name template)
- * @macaddr: desired MAC address (VIR_MAC_BUFLEN long)
+ * @macaddr: desired MAC address
  * @tapfd: file descriptor return value for the new tap device
  * @virtPortProfile: bridge/port specific configuration
  * @flags: OR of virNetDevTapCreateFlags:
@@ -280,13 +280,13 @@ int virNetDevTapDelete(const char *ifnam
  */
 int virNetDevTapCreateInBridgePort(const char *brname,
                                    char **ifname,
-                                   const unsigned char *macaddr,
+                                   const virMacAddrPtr macaddr,
                                    const unsigned char *vmuuid,
                                    int *tapfd,
virNetDevVPortProfilePtr virtPortProfile,
                                    unsigned int flags)
 {
-    unsigned char tapmac[VIR_MAC_BUFLEN];
+    virMacAddr tapmac;

     if (virNetDevTapCreate(ifname, tapfd, flags) < 0)
         return -1;
@@ -297,9 +297,9 @@ int virNetDevTapCreateInBridgePort(const
      * seeing the kernel allocate random MAC for the TAP
      * device before we set our static MAC.
      */
-    memcpy(tapmac, macaddr, VIR_MAC_BUFLEN);
+    virMacAddrSet(&tapmac, macaddr);
     if (!(flags & VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE)) {
-        if (macaddr[0] == 0xFE) {
+        if (macaddr->addr[0] == 0xFE) {
             /* For normal use, the tap device's MAC address cannot
              * match the MAC address used by the guest. This results
              * in "received packet on vnetX with own address as source
@@ -308,14 +308,15 @@ int virNetDevTapCreateInBridgePort(const
             virNetDevTapError(VIR_ERR_CONFIG_UNSUPPORTED,
                               "Unable to use MAC address starting with "
"reserved value 0xFE - '%02X:%02X:%02X:%02X:%02X:%02X' - ",
-                              macaddr[0], macaddr[1], macaddr[2],
-                              macaddr[3], macaddr[4], macaddr[5]);
+                              macaddr->addr[0], macaddr->addr[1],
+                              macaddr->addr[2], macaddr->addr[3],
+                              macaddr->addr[4], macaddr->addr[5]);
             goto error;
         }
-        tapmac[0] = 0xFE; /* Discourage bridge from using TAP dev MAC */
+ tapmac.addr[0] = 0xFE; /* Discourage bridge from using TAP dev MAC */
     }

-    if (virNetDevSetMAC(*ifname, tapmac) < 0)
+    if (virNetDevSetMAC(*ifname, &tapmac) < 0)
         goto error;

     /* We need to set the interface MTU before adding it
Index: libvirt-acl/src/util/virnetdevtap.h
===================================================================
--- libvirt-acl.orig/src/util/virnetdevtap.h
+++ libvirt-acl/src/util/virnetdevtap.h
@@ -46,7 +46,7 @@ typedef enum {

 int virNetDevTapCreateInBridgePort(const char *brname,
                                    char **ifname,
-                                   const unsigned char *macaddr,
+                                   const virMacAddrPtr macaddr,
                                    const unsigned char *vmuuid,
                                    int *tapfd,
virNetDevVPortProfilePtr virtPortProfile,
Index: libvirt-acl/src/util/virnetdevvportprofile.c
===================================================================
--- libvirt-acl.orig/src/util/virnetdevvportprofile.c
+++ libvirt-acl/src/util/virnetdevvportprofile.c
@@ -264,7 +264,7 @@ cleanup:
 static int
 virNetDevVPortProfileOpSetLink(const char *ifname, int ifindex,
                                bool nltarget_kernel,
-                               const unsigned char *macaddr,
+                               const virMacAddrPtr macaddr,
                                int vlanid,
                                const char *profileId,
                                struct ifla_port_vsi *portVsi,
@@ -315,7 +315,7 @@ virNetDevVPortProfileOpSetLink(const cha
                 .mac = { 0, },
             };

-            memcpy(ifla_vf_mac.mac, macaddr, 6);
+            virMacAddrGetRaw(macaddr, ifla_vf_mac.mac);

             if (nla_put(nl_msg, IFLA_VF_MAC, sizeof(ifla_vf_mac),
&ifla_vf_mac) < 0)
@@ -515,7 +515,7 @@ virNetDevVPortProfileGetNthParent(const
 static int
 virNetDevVPortProfileOpCommon(const char *ifname, int ifindex,
                               bool nltarget_kernel,
-                              const unsigned char *macaddr,
+                              const virMacAddrPtr macaddr,
                               int vlanid,
                               const char *profileId,
                               struct ifla_port_vsi *portVsi,
@@ -633,7 +633,7 @@ virNetDevVPortProfileGetPhysdevAndVlan(c
 /* Returns 0 on success, -1 on general failure, and -2 on timeout */
 static int
 virNetDevVPortProfileOp8021Qbg(const char *ifname,
-                               const unsigned char *macaddr,
+                               const virMacAddrPtr macaddr,
                                int vf,
                                const virNetDevVPortProfilePtr virtPort,
enum virNetDevVPortProfileLinkOp virtPortOp,
@@ -701,7 +701,7 @@ cleanup:
 /* Returns 0 on success, -1 on general failure, and -2 on timeout */
 static int
 virNetDevVPortProfileOp8021Qbh(const char *ifname,
-                               const unsigned char *macaddr,
+                               const virMacAddrPtr macaddr,
                                int32_t vf,
                                const virNetDevVPortProfilePtr virtPort,
                                const unsigned char *vm_uuid,
@@ -825,7 +825,7 @@ cleanup:
 int
 virNetDevVPortProfileAssociate(const char *macvtap_ifname,
                                const virNetDevVPortProfilePtr virtPort,
-                               const unsigned char *macvtap_macaddr,
+                               const virMacAddrPtr macvtap_macaddr,
                                const char *linkdev,
                                int vf,
                                const unsigned char *vmuuid,
@@ -889,7 +889,7 @@ virNetDevVPortProfileAssociate(const cha
 int
 virNetDevVPortProfileDisassociate(const char *macvtap_ifname,
                                   const virNetDevVPortProfilePtr virtPort,
-                                  const unsigned char *macvtap_macaddr,
+                                  const virMacAddrPtr macvtap_macaddr,
                                   const char *linkdev,
                                   int vf,
                                   enum virNetDevVPortProfileOp vmOp)
@@ -933,7 +933,7 @@ virNetDevVPortProfileDisassociate(const
 #else /* ! WITH_VIRTUALPORT */
int virNetDevVPortProfileAssociate(const char *macvtap_ifname ATTRIBUTE_UNUSED, const virNetDevVPortProfilePtr virtPort ATTRIBUTE_UNUSED, - const unsigned char *macvtap_macaddr ATTRIBUTE_UNUSED, + const virMacAddrPtr macvtap_macaddr ATTRIBUTE_UNUSED,
                                const char *linkdev ATTRIBUTE_UNUSED,
                                int vf ATTRIBUTE_UNUSED,
const unsigned char *vmuuid ATTRIBUTE_UNUSED,
@@ -947,7 +947,7 @@ int virNetDevVPortProfileAssociate(const

int virNetDevVPortProfileDisassociate(const char *macvtap_ifname ATTRIBUTE_UNUSED, const virNetDevVPortProfilePtr virtPort ATTRIBUTE_UNUSED, - const unsigned char *macvtap_macaddr ATTRIBUTE_UNUSED, + const virMacAddrPtr macvtap_macaddr ATTRIBUTE_UNUSED, const char *linkdev ATTRIBUTE_UNUSED,
                                       int vf ATTRIBUTE_UNUSED,
enum virNetDevVPortProfileOp vmOp ATTRIBUTE_UNUSED)
Index: libvirt-acl/src/vbox/vbox_tmpl.c
===================================================================
--- libvirt-acl.orig/src/vbox/vbox_tmpl.c
+++ libvirt-acl/src/vbox/vbox_tmpl.c
@@ -2997,7 +2997,7 @@ sharedFoldersCleanup:
MACAddress[8], MACAddress[9], MACAddress[10], MACAddress[11]);

/* XXX some real error handling here some day ... */ - if (virMacAddrParse(macaddr, def->nets[netAdpIncCnt]->mac) < 0) + if (virMacAddrParse(macaddr, &def->nets[netAdpIncCnt]->mac) < 0)
                         {}

                         netAdpIncCnt++;
@@ -4346,15 +4346,15 @@ vboxAttachNetwork(virDomainDefPtr def, v
         char macaddr[VIR_MAC_STRING_BUFLEN] = {0};
         char macaddrvbox[VIR_MAC_STRING_BUFLEN - 5] = {0};

-        virMacAddrFormat(def->nets[i]->mac, macaddr);
+        virMacAddrFormat(&def->nets[i]->mac, macaddr);
         snprintf(macaddrvbox, VIR_MAC_STRING_BUFLEN - 5,
                  "%02X%02X%02X%02X%02X%02X",
-                 def->nets[i]->mac[0],
-                 def->nets[i]->mac[1],
-                 def->nets[i]->mac[2],
-                 def->nets[i]->mac[3],
-                 def->nets[i]->mac[4],
-                 def->nets[i]->mac[5]);
+                 def->nets[i]->mac.addr[0],
+                 def->nets[i]->mac.addr[1],
+                 def->nets[i]->mac.addr[2],
+                 def->nets[i]->mac.addr[3],
+                 def->nets[i]->mac.addr[4],
+                 def->nets[i]->mac.addr[5]);
         macaddrvbox[VIR_MAC_STRING_BUFLEN - 6] = '\0';

         VIR_DEBUG("NIC(%d): Type:   %d", i, def->nets[i]->type);
Index: libvirt-acl/src/vmx/vmx.c
===================================================================
--- libvirt-acl.orig/src/vmx/vmx.c
+++ libvirt-acl/src/vmx/vmx.c
@@ -2365,7 +2365,7 @@ virVMXParseEthernet(virConfPtr conf, int
     if (addressType == NULL || STRCASEEQ(addressType, "generated") ||
         STRCASEEQ(addressType, "vpx")) {
         if (generatedAddress != NULL) {
-            if (virMacAddrParse(generatedAddress, (*def)->mac) < 0) {
+            if (virMacAddrParse(generatedAddress, &(*def)->mac) < 0) {
                 VMX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be MAC address but "
                             "found '%s'"), generatedAddress_name,
@@ -2375,7 +2375,7 @@ virVMXParseEthernet(virConfPtr conf, int
         }
     } else if (STRCASEEQ(addressType, "static")) {
         if (address != NULL) {
-            if (virMacAddrParse(address, (*def)->mac) < 0) {
+            if (virMacAddrParse(address, &(*def)->mac) < 0) {
                 VMX_ERROR(VIR_ERR_INTERNAL_ERROR,
_("Expecting VMX entry '%s' to be MAC address but "
                             "found '%s'"), address_name, address);
@@ -3567,10 +3567,10 @@ virVMXFormatEthernet(virDomainNetDefPtr
     }

/* def:mac -> vmx:addressType, vmx:(generated)Address, vmx:checkMACAddress */
-    virMacAddrFormat(def->mac, mac_string);
+    virMacAddrFormat(&def->mac, mac_string);

-    prefix = (def->mac[0] << 16) | (def->mac[1] << 8) | def->mac[2];
-    suffix = (def->mac[3] << 16) | (def->mac[4] << 8) | def->mac[5];
+ prefix = (def->mac.addr[0] << 16) | (def->mac.addr[1] << 8) | def->mac.addr[2]; + suffix = (def->mac.addr[3] << 16) | (def->mac.addr[4] << 8) | def->mac.addr[5];

     if (prefix == 0x000c29) {
virBufferAsprintf(buffer, "ethernet%d.addressType = \"generated\"\n",
Index: libvirt-acl/src/xen/xend_internal.c
===================================================================
--- libvirt-acl.orig/src/xen/xend_internal.c
+++ libvirt-acl/src/xen/xend_internal.c
@@ -2718,7 +2718,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr
             goto cleanup;

         char macStr[VIR_MAC_STRING_BUFLEN];
-        virMacAddrFormat(dev->data.net->mac, macStr);
+        virMacAddrFormat(&dev->data.net->mac, macStr);

         if (!(target = strdup(macStr))) {
             virReportOOMError();
@@ -3955,8 +3955,8 @@ virDomainXMLDevID(virDomainPtr domain,
         char mac[30];
         virDomainNetDefPtr def = dev->data.net;
         snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
-                 def->mac[0], def->mac[1], def->mac[2],
-                 def->mac[3], def->mac[4], def->mac[5]);
+                 def->mac.addr[0], def->mac.addr[1], def->mac.addr[2],
+                 def->mac.addr[3], def->mac.addr[4], def->mac.addr[5]);

         strcpy(class, "vif");

Index: libvirt-acl/src/xen/xm_internal.c
===================================================================
--- libvirt-acl.orig/src/xen/xm_internal.c
+++ libvirt-acl/src/xen/xm_internal.c
@@ -1533,9 +1533,7 @@ xenXMDomainDetachDeviceFlags(virDomainPt
     case VIR_DOMAIN_DEVICE_NET:
     {
         for (i = 0 ; i < def->nnets ; i++) {
-            if (!memcmp(def->nets[i]->mac,
-                        dev->data.net->mac,
-                        sizeof(def->nets[i]->mac))) {
+            if (!virMacAddrCmp(&def->nets[i]->mac, &dev->data.net->mac)) {
                 virDomainNetDefFree(def->nets[i]);
                 if (i < (def->nnets - 1))
                     memmove(def->nets + i,
Index: libvirt-acl/src/xenxs/xen_sxpr.c
===================================================================
--- libvirt-acl.orig/src/xenxs/xen_sxpr.c
+++ libvirt-acl/src/xenxs/xen_sxpr.c
@@ -600,7 +600,7 @@ xenParseSxprNets(virDomainDefPtr def,

             tmp = sexpr_node(node, "device/vif/mac");
             if (tmp) {
-                if (virMacAddrParse(tmp, net->mac) < 0) {
+                if (virMacAddrParse(tmp, &net->mac) < 0) {
                     XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
                                  _("malformed mac address '%s'"), tmp);
                     goto cleanup;
@@ -1932,8 +1932,8 @@ xenFormatSxprNet(virConnectPtr conn,

     virBufferAsprintf(buf,
                       "(mac '%02x:%02x:%02x:%02x:%02x:%02x')",
-                      def->mac[0], def->mac[1], def->mac[2],
-                      def->mac[3], def->mac[4], def->mac[5]);
+                      def->mac.addr[0], def->mac.addr[1], def->mac.addr[2],
+ def->mac.addr[3], def->mac.addr[4], def->mac.addr[5]);

     switch (def->type) {
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
Index: libvirt-acl/src/xenxs/xen_xm.c
===================================================================
--- libvirt-acl.orig/src/xenxs/xen_xm.c
+++ libvirt-acl/src/xenxs/xen_xm.c
@@ -742,7 +742,7 @@ xenParseXM(virConfPtr conf, int xendConf
                 goto no_memory;

             if (mac[0]) {
-                if (virMacAddrParse(mac, net->mac) < 0) {
+                if (virMacAddrParse(mac, &net->mac) < 0) {
                     XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
                                _("malformed mac address '%s'"), mac);
                     goto cleanup;
@@ -1326,9 +1326,9 @@ static int xenFormatXMNet(virConnectPtr
     virConfValuePtr val, tmp;

     virBufferAsprintf(&buf, "mac=%02x:%02x:%02x:%02x:%02x:%02x",
-                      net->mac[0], net->mac[1],
-                      net->mac[2], net->mac[3],
-                      net->mac[4], net->mac[5]);
+                      net->mac.addr[0], net->mac.addr[1],
+                      net->mac.addr[2], net->mac.addr[3],
+                      net->mac.addr[4], net->mac.addr[5]);

     switch (net->type) {
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
Index: libvirt-acl/tools/virsh.c
===================================================================
--- libvirt-acl.orig/tools/virsh.c
+++ libvirt-acl/tools/virsh.c
@@ -1655,7 +1655,7 @@ cmdDomIfSetLink (vshControl *ctl, const
     const char *state;
     const char *value;
     const char *desc;
-    unsigned char macaddr[VIR_MAC_BUFLEN];
+    virMacAddr macaddr;
     const char *element;
     const char *attr;
     bool config;
@@ -1717,7 +1717,7 @@ cmdDomIfSetLink (vshControl *ctl, const
         goto cleanup;
     }

-    if (virMacAddrParse(iface, macaddr) == 0) {
+    if (virMacAddrParse(iface, &macaddr) == 0) {
         element = "mac";
         attr = "address";
     } else {
@@ -1831,7 +1831,7 @@ cmdDomIfGetLink (vshControl *ctl, const
     int flags = 0;
     char *state = NULL;
     char *value = NULL;
-    unsigned char macaddr[VIR_MAC_BUFLEN];
+    virMacAddr macaddr;
     const char *element;
     const char *attr;
     bool ret = false;
@@ -1876,7 +1876,7 @@ cmdDomIfGetLink (vshControl *ctl, const
         goto cleanup;
     }

-    if (virMacAddrParse(iface, macaddr) == 0) {
+    if (virMacAddrParse(iface, &macaddr) == 0) {
         element = "mac";
         attr = "address";
     } else {
Index: libvirt-acl/src/lxc/lxc_driver.c
===================================================================
--- libvirt-acl.orig/src/lxc/lxc_driver.c
+++ libvirt-acl/src/lxc/lxc_driver.c
@@ -1190,11 +1190,11 @@ static int lxcSetupInterfaceBridged(virC
     (*veths)[(*nveths)] = containerVeth;
     (*nveths)++;

-    if (virNetDevSetMAC(containerVeth, net->mac) < 0)
+    if (virNetDevSetMAC(containerVeth, &net->mac) < 0)
         goto cleanup;

if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH)
-        ret = virNetDevOpenvswitchAddPort(brname, parentVeth, net->mac,
+        ret = virNetDevOpenvswitchAddPort(brname, parentVeth, &net->mac,
                                           vm->uuid, vport);
     else
         ret = virNetDevBridgeAddPort(brname, parentVeth);
@@ -1268,7 +1268,7 @@ static int lxcSetupInterfaceDirect(virCo
     (*veths)[(*nveths)] = NULL;

     if (virNetDevMacVLanCreateWithVPortProfile(
-            net->ifname, net->mac,
+            net->ifname, &net->mac,
             virDomainNetGetActualDirectDev(net),
             virDomainNetGetActualDirectMode(net),
             false, false, def->uuid,
Index: libvirt-acl/src/libvirt_private.syms
===================================================================
--- libvirt-acl.orig/src/libvirt_private.syms
+++ libvirt-acl/src/libvirt_private.syms
@@ -1271,12 +1271,17 @@ virKeyFileGetValueString;


 # virmacaddr.h
+virMacAddrCmp;
+virMacAddrCmpRaw;
 virMacAddrCompare;
 virMacAddrFormat;
 virMacAddrGenerate;
+virMacAddrGetRaw;
 virMacAddrIsMulticast;
 virMacAddrIsUnicast;
 virMacAddrParse;
+virMacAddrSet;
+virMacAddrSetRaw;


 # virnetclient.h
Index: libvirt-acl/src/libxl/libxl_conf.c
===================================================================
--- libvirt-acl.orig/src/libxl/libxl_conf.c
+++ libvirt-acl/src/libxl/libxl_conf.c
@@ -596,7 +596,7 @@ libxlMakeNic(virDomainDefPtr def, virDom
     //x_nics[i].mtu = 1492;

     x_nic->domid = def->id;
-    memcpy(x_nic->mac, l_nic->mac, sizeof(libxl_mac));
+    virMacAddrGetRaw(&l_nic->mac, x_nic->mac);

     if (l_nic->model && !STREQ(l_nic->model, "netfront")) {
         if ((x_nic->model = strdup(l_nic->model)) == NULL) {

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