From: Donald Sharp Date: Thu, 3 Aug 2017 11:43:47 +0000 (-0400) Subject: zebra: Fix crash when OOM happens. X-Git-Tag: frr-4.0-dev~452^2~5 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=25331def553ad84804e49d63a51e2dde379989a6;p=matthieu%2Ffrr.git 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 --- 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); } /*