]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
defrag: link hash size with number of frags.
authorEric Leblond <eric@regit.org>
Thu, 26 Jul 2012 16:29:51 +0000 (18:29 +0200)
committerEric Leblond <eric@regit.org>
Wed, 22 Aug 2012 12:30:13 +0000 (14:30 +0200)
We set defrag_hash_size by using the number of trackers. This is
effective to avoid collision.

src/defrag.c

index 51e91c102f7fe4c274022b6b359bc702d91ec026..8e6961290947355091dd3a67b6bade0b1d249219 100644 (file)
@@ -418,7 +418,7 @@ DefragContextNew(void)
         return NULL;
 
     /* Initialize the hash table. */
-    dc->frag_table = HashListTableInit(DEFAULT_DEFRAG_HASH_SIZE, DefragHashFunc,
+    dc->frag_table = HashListTableInit(defrag_hash_size, DefragHashFunc,
         DefragHashCompare, DefragHashFree);
     if (dc->frag_table == NULL) {
         SCLogError(SC_ERR_MEM_ALLOC,
@@ -1238,10 +1238,14 @@ DefragInit(void)
 {
     /* Initialize random value for hashing and hash table size. */
     unsigned int seed = RandomTimePreseed();
-    /* set defaults */
-    defrag_hash_rand = (int)( DEFAULT_DEFRAG_HASH_SIZE * (rand_r(&seed) / RAND_MAX + 1.0));
+    intmax_t tracker_pool_size;
+    if (!ConfGetInt("defrag.trackers", &tracker_pool_size)) {
+        tracker_pool_size = DEFAULT_DEFRAG_HASH_SIZE;
+    }
 
-    defrag_hash_size = DEFAULT_DEFRAG_HASH_SIZE;
+    /* set defaults */
+    defrag_hash_rand = (int)(tracker_pool_size * (rand_r(&seed) / RAND_MAX + 1.0));
+    defrag_hash_size = tracker_pool_size;
 
     /* Allocate the DefragContext. */
     defrag_context = DefragContextNew();