From 25331def553ad84804e49d63a51e2dde379989a6 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 3 Aug 2017 07:43:47 -0400 Subject: [PATCH] zebra: Fix crash when OOM happens. The hash key function choosen for mac vni's would tend to clump the key value to the same number. Use a better hash key generator to spread the hash values out. A bad hash key might lead to O(2^n) memory consumption because the hash size is doubled, each time a backet exceeds a predefined threshold. This quickly leads to OOM. Fixing this issue by fixing the hash key generation to actually spread the keys out. Ticket: CM-17412 Signed-off-by: Donald Sharp --- zebra/zebra_vxlan.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index c96f073064..e89f05374f 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -776,18 +776,9 @@ static void zvni_install_neigh_hash(struct hash_backet *backet, void *ctxt) static unsigned int mac_hash_keymake(void *p) { zebra_mac_t *pmac = p; - char *pnt = (char *)pmac->macaddr.octet; - unsigned int key = 0; - int c = 0; - - key += pnt[c]; - key += pnt[c + 1]; - key += pnt[c + 2]; - key += pnt[c + 3]; - key += pnt[c + 4]; - key += pnt[c + 5]; - - return (key); + const void *pnt = (void *)pmac->macaddr.octet; + + return jhash(pnt, ETHER_ADDR_LEN, 0xa5a5a55a); } /* -- 2.39.5