summaryrefslogtreecommitdiffstats
path: root/src/vnet/ethernet/mac_address.h
diff options
context:
space:
mode:
authorNeale Ranns <nranns@cisco.com>2018-11-16 05:20:36 -0800
committerDave Barach <openvpp@barachs.net>2018-11-18 17:21:03 +0000
commitfaf22cb303b65e2a6bf8dad959d7f5ee6d031c4f (patch)
tree59b048f98a1b88fa9f7f47f27fb9de52fd8bad3a /src/vnet/ethernet/mac_address.h
parent3ae2873e568dd441a22903ab9f8c7954835b0bf1 (diff)
mac_address_t: size to 6 bytes so it represents wire format
Change-Id: I4d6b505a2b1e0cb960a4145796351ad1bc7e860d Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet/ethernet/mac_address.h')
-rw-r--r--src/vnet/ethernet/mac_address.h22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/vnet/ethernet/mac_address.h b/src/vnet/ethernet/mac_address.h
index a249cb58e7c..e89fb6516a0 100644
--- a/src/vnet/ethernet/mac_address.h
+++ b/src/vnet/ethernet/mac_address.h
@@ -23,17 +23,23 @@ typedef struct mac_address_t_
union
{
u8 bytes[6];
- u64 as_u64;
+ struct
+ {
+ u32 first_4;
+ u16 last_2;
+ } __clib_packed u;
};
} mac_address_t;
+STATIC_ASSERT ((sizeof (mac_address_t) == 6),
+ "MAC address must represent the on wire format");
+
extern const mac_address_t ZERO_MAC_ADDRESS;
static_always_inline void
mac_address_from_bytes (mac_address_t * mac, const u8 * bytes)
{
/* zero out the last 2 bytes, then copy over only 6 */
- mac->as_u64 = 0;
clib_memcpy (mac->bytes, bytes, 6);
}
@@ -47,21 +53,23 @@ mac_address_to_bytes (const mac_address_t * mac, u8 * bytes)
static_always_inline int
mac_address_is_zero (const mac_address_t * mac)
{
- return (0 == mac->as_u64);
+ return (0 == mac->u.first_4 && 0 == mac->u.last_2);
}
static_always_inline u64
mac_address_as_u64 (const mac_address_t * mac)
{
- return (mac->as_u64);
+ u64 *as_u64;
+
+ as_u64 = (u64 *) mac->bytes;
+
+ return (*as_u64);
}
static_always_inline void
mac_address_from_u64 (u64 u, mac_address_t * mac)
{
- mac->as_u64 = u;
- mac->bytes[4] = 0;
- mac->bytes[5] = 0;
+ clib_memcpy (mac->bytes, &u, 6);
}
static_always_inline void