net: linkaddr: calculate linkaddr storage addr size via config

- Introduce NET_LINK_ADDR_MAX_LENGTH which is either 6 or 8
  depending on whether CONFIG_NET_L2_IEEE802154 is used
- Instead of being a placeholder single index array of uint8_t,
  let's use NET_LINK_ADDR_MAX_LENGTH to assign the size of the
  "addr" array field in the net_linkaddr_storage structure.
- Now that the "addr" field of net_linkaddr_storage contains the
  true size of the link address, we can remove "storage" field
  which was hard coded to 8 bytes (2 uint32_t's).
- Fix 2 references to the "storage" field of the net_linkaddr_storage
  structure.

Change-Id: I2ea12058280b289f65085964eb7d503d4fd260c2
Signed-off-by: Michael Scott <michael.scott@linaro.org>
This commit is contained in:
Michael Scott 2017-01-11 14:57:42 -08:00 committed by Jukka Rissanen
commit 4aad767328
3 changed files with 17 additions and 21 deletions

View file

@ -19,6 +19,12 @@
extern "C" { extern "C" {
#endif #endif
#ifdef CONFIG_NET_L2_IEEE802154
#define NET_LINK_ADDR_MAX_LENGTH 8
#else
#define NET_LINK_ADDR_MAX_LENGTH 6
#endif
/** /**
* @brief Hardware link address structure * @brief Hardware link address structure
* *
@ -37,27 +43,17 @@ struct net_linkaddr {
* *
* Used to hold the link address information. This variant is needed * Used to hold the link address information. This variant is needed
* when we have to store the link layer address. * when we have to store the link layer address.
* Note that you cannot cast this to net_linkaddr as they store *
* different things. * Note that you cannot cast this to net_linkaddr as uint8_t * is
* handled differently than uint8_t addr[] and the fields are purposely
* in a different order.
*/ */
struct net_linkaddr_storage { struct net_linkaddr_storage {
/** The real length of the ll address. */ /** The real length of the ll address. */
uint8_t len; uint8_t len;
union {
/** The array of bytes representing the address */ /** The array of bytes representing the address */
uint8_t addr[0]; uint8_t addr[NET_LINK_ADDR_MAX_LENGTH];
struct {
/* The integer array allocate total of 8 bytes
* that can hold currently all the supported
* link layer addresses. These int's can be
* used when comparing lladdr instead of using
* memcmp()
*/
uint32_t storage[2];
};
};
}; };
/** /**

View file

@ -148,7 +148,7 @@ int net_nbr_unlink(struct net_nbr *nbr, struct net_linkaddr *lladdr)
if (!net_neighbor_lladdr[nbr->idx].ref) { if (!net_neighbor_lladdr[nbr->idx].ref) {
memset(net_neighbor_lladdr[nbr->idx].lladdr.addr, 0, memset(net_neighbor_lladdr[nbr->idx].lladdr.addr, 0,
sizeof(net_neighbor_lladdr[nbr->idx].lladdr.storage)); sizeof(net_neighbor_lladdr[nbr->idx].lladdr.addr));
} }
nbr->idx = NET_NBR_LLADDR_UNKNOWN; nbr->idx = NET_NBR_LLADDR_UNKNOWN;

View file

@ -48,12 +48,12 @@ static struct in6_addr in6addr_mcast = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0x1 } } }; 0, 0, 0, 0, 0, 0, 0, 0x1 } } };
static struct net_linkaddr_storage lladdr_src_storage = { static struct net_linkaddr_storage lladdr_src_storage = {
.storage = { 0x00000102, 0x03040506 }, .addr = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 },
.len = 6 .len = NET_LINK_ADDR_MAX_LENGTH
}; };
static struct net_linkaddr lladdr_src = { static struct net_linkaddr lladdr_src = {
.addr = &lladdr_src_storage.addr[0], .addr = lladdr_src_storage.addr,
.len = 6 .len = NET_LINK_ADDR_MAX_LENGTH
}; };
static bool test_failed; static bool test_failed;