summaryrefslogtreecommitdiffstats
path: root/src/vnet/l2
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-03-25 16:20:16 +0100
committerBeno�t Ganne <bganne@cisco.com>2022-03-25 17:08:44 +0000
commit38235c38e137507647865e79ddddc046f2f02d35 (patch)
tree7c0c4bd0061e55b32bab3bbbc569a0d9c5a9da88 /src/vnet/l2
parent3d390ba8ded9ea9d5242ef62c56a37fa0a68904a (diff)
l2: avoid overflow read of mac address
Type: improvement Change-Id: I99d2c69ede39b3ba5604e1811ce12209c47f5caf Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vnet/l2')
-rw-r--r--src/vnet/l2/l2_fib.h26
1 files changed, 3 insertions, 23 deletions
diff --git a/src/vnet/l2/l2_fib.h b/src/vnet/l2/l2_fib.h
index 202e2d9a33b..e24d427b4e2 100644
--- a/src/vnet/l2/l2_fib.h
+++ b/src/vnet/l2/l2_fib.h
@@ -240,29 +240,9 @@ l2fib_compute_hash_bucket (l2fib_entry_key_t * key)
always_inline u64
l2fib_make_key (const u8 * mac_address, u16 bd_index)
{
- u64 temp;
-
- /*
- * The mac address in memory is A:B:C:D:E:F
- * The bd id in register is H:L
- */
-#if CLIB_ARCH_IS_LITTLE_ENDIAN
- /*
- * Create the in-register key as F:E:D:C:B:A:H:L
- * In memory the key is L:H:A:B:C:D:E:F
- */
- temp = CLIB_MEM_OVERFLOW_LOAD ((u64 *) mac_address) << 16;
- temp = (temp & ~0xffff) | (u64) (bd_index);
-#else
- /*
- * Create the in-register key as H:L:A:B:C:D:E:F
- * In memory the key is H:L:A:B:C:D:E:F
- */
- temp = CLIB_MEM_OVERFLOW_LOAD ((u64 *) mac_address) >> 16;
- temp = temp | (((u64) bd_index) << 48);
-#endif
-
- return temp;
+ l2fib_entry_key_t key = { .fields.bd_index = bd_index };
+ clib_memcpy_fast (&key.fields.mac, mac_address, sizeof (key.fields.mac));
+ return key.raw;
}