Skip to content

Commit

Permalink
types: New struct eth_addr64 for EUI-64 identifiers.
Browse files Browse the repository at this point in the history
This will see its first real user in the following commit.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Andy Zhou <azhou@ovn.org>
  • Loading branch information
blp committed Apr 7, 2017
1 parent b7a859e commit b2342f7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions build-aux/check-structs
Expand Up @@ -16,6 +16,7 @@ types['ovs_be32'] = {"size": 4, "alignment": 4}
types['ovs_be64'] = {"size": 8, "alignment": 8}
types['ovs_32aligned_be64'] = {"size": 8, "alignment": 4}
types['struct eth_addr'] = {"size": 6, "alignment": 2}
types['struct eth_addr64'] = {"size": 8, "alignment": 2}

token = None
line = ""
Expand Down
10 changes: 9 additions & 1 deletion include/openvswitch/types.h
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2011, 2013, 2014, 2016 Nicira, Inc.
* Copyright (c) 2010, 2011, 2013, 2014, 2016, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -152,4 +152,12 @@ struct eth_addr {
};
};

/* Similar to struct eth_addr, for EUI-64 addresses. */
struct eth_addr64 {
union {
uint8_t ea64[8];
ovs_be16 be16[4];
};
};

#endif /* openvswitch/types.h */
34 changes: 33 additions & 1 deletion lib/packets.h
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -156,6 +156,8 @@ static const struct eth_addr eth_addr_exact OVS_UNUSED

static const struct eth_addr eth_addr_zero OVS_UNUSED
= { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } };
static const struct eth_addr64 eth_addr64_zero OVS_UNUSED
= { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } };

static const struct eth_addr eth_addr_stp OVS_UNUSED
= { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x00 } } };
Expand Down Expand Up @@ -188,6 +190,10 @@ static inline bool eth_addr_is_zero(const struct eth_addr a)
{
return !(a.be16[0] | a.be16[1] | a.be16[2]);
}
static inline bool eth_addr64_is_zero(const struct eth_addr64 a)
{
return !(a.be16[0] | a.be16[1] | a.be16[2] | a.be16[3]);
}

static inline int eth_mask_is_exact(const struct eth_addr a)
{
Expand All @@ -199,12 +205,22 @@ static inline int eth_addr_compare_3way(const struct eth_addr a,
{
return memcmp(&a, &b, sizeof a);
}
static inline int eth_addr64_compare_3way(const struct eth_addr64 a,
const struct eth_addr64 b)
{
return memcmp(&a, &b, sizeof a);
}

static inline bool eth_addr_equals(const struct eth_addr a,
const struct eth_addr b)
{
return !eth_addr_compare_3way(a, b);
}
static inline bool eth_addr64_equals(const struct eth_addr64 a,
const struct eth_addr64 b)
{
return !eth_addr64_compare_3way(a, b);
}

static inline bool eth_addr_equal_except(const struct eth_addr a,
const struct eth_addr b,
Expand Down Expand Up @@ -313,6 +329,22 @@ ovs_be32 set_mpls_lse_values(uint8_t ttl, uint8_t tc, uint8_t bos,
(EAB)[0], (EAB)[1], (EAB)[2], (EAB)[3], (EAB)[4], (EAB)[5]
#define ETH_ADDR_STRLEN 17

/* Example:
*
* struct eth_addr64 eui64;
* [...]
* printf("The EUI-64 address is "ETH_ADDR64_FMT"\n", ETH_ADDR64_ARGS(mac));
*
*/
#define ETH_ADDR64_FMT \
"%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":" \
"%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8
#define ETH_ADDR64_ARGS(EA) ETH_ADDR64_BYTES_ARGS((EA).ea64)
#define ETH_ADDR64_BYTES_ARGS(EAB) \
(EAB)[0], (EAB)[1], (EAB)[2], (EAB)[3], \
(EAB)[4], (EAB)[5], (EAB)[6], (EAB)[7]
#define ETH_ADDR64_STRLEN 23

/* Example:
*
* char *string = "1 00:11:22:33:44:55 2";
Expand Down

0 comments on commit b2342f7

Please sign in to comment.