summaryrefslogtreecommitdiffstats
path: root/lib/hash.c
diff options
context:
space:
mode:
authorDaniel Walton <dwalton@cumulusnetworks.com>2017-07-31 23:22:23 +0200
committerDaniel Walton <dwalton@cumulusnetworks.com>2017-07-31 23:22:23 +0200
commit40520c3649dc9d556b3a11f1d60e84130cebf487 (patch)
tree22a1ee7b22142e9fe49caec66da2bcfa7bce6aa4 /lib/hash.c
parentMerge pull request #866 from opensourcerouting/ldpd-config-issues (diff)
downloadfrr-40520c3649dc9d556b3a11f1d60e84130cebf487.tar.xz
frr-40520c3649dc9d556b3a11f1d60e84130cebf487.zip
bgpd: peer hash expands until we are out of memory
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com> swpX peers all start out with the same sockunion so initially they all go into the same hash bucket. Once IPv6 ND has worked its magic they will have different sockunions and will go in different buckets...life is good. Until then though, we are in a phase where all swpX peers have the same socknunion. Once we have HASH_THRESHOLD (10) swpX peers and call hash_get for a new swpX peer the hash code calls hash_expand(). This happens because there are more than HASH_THRESHOLD entries in a single bucket so the logic is "expand the hash to spread things out"...in our case expanding doesn't spread out the swpX peers because all of their sockunions are the same. I looked at having peer_hash_make and peer_hash_same consider the ifname of the swpX peer but that is a large change that we don't want to make at the moment. So the fix is to put a cap on how large we are willing to let the hash table get. By default there is no limit but if max_size is set we will not allow the hash to expand above that.
Diffstat (limited to 'lib/hash.c')
-rw-r--r--lib/hash.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/hash.c b/lib/hash.c
index a7714f156..e74e4355d 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -94,6 +94,10 @@ static void hash_expand(struct hash *hash)
struct hash_backet *hb, *hbnext, **new_index;
new_size = hash->size * 2;
+
+ if (hash->max_size && new_size > hash->max_size)
+ return;
+
new_index = XCALLOC(MTYPE_HASH_INDEX,
sizeof(struct hash_backet *) * new_size);
if (new_index == NULL)