Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion meta/MetaKeyHasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,20 @@ static inline std::size_t sai_get_hash(
return ne.ip_address.addr_family;
}

static_assert(sizeof(uint32_t) == 4, "uint32_t expected to be 4 bytes");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static_assert [](start = 0, length = 13)

This assertion seems not needed. Do you anticipate some failure case?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a surprise for some wired platforms :D


static inline std::size_t sai_get_hash(
_In_ const sai_fdb_entry_t& fe)
{
SWSS_LOG_ENTER();

return *(const uint32_t*)(&fe.mac_address[2]);
uint32_t data;

// use low 4 bytes of mac address as hash value
// use memcpy instead of cast because of strict-aliasing rules
memcpy(&data, fe.mac_address + 2, sizeof(uint32_t));

return data;
}

static inline std::size_t sai_get_hash(
Expand Down