]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4133: host_cache: fix for race condition on peg counts
authorRaza Shafiq (rshafiq) <rshafiq@cisco.com>
Thu, 7 Dec 2023 21:49:00 +0000 (21:49 +0000)
committerSteven Baigal (sbaigal) <sbaigal@cisco.com>
Thu, 7 Dec 2023 21:49:00 +0000 (21:49 +0000)
Merge in SNORT/snort3 from ~RSHAFIQ/snort3:host_cache_pegs to master

Squashed commit of the following:

commit 2d742de0301f5940aa7f658336f382f33059f1e9
Author: rshafiq <rshafiq@cisco.com>
Date:   Wed Dec 6 08:37:52 2023 -0500

    host_cache: fix for race condition on peg counts

src/host_tracker/host_cache_segmented.h

index e80519262e04afe8caf96c5f19b24b1e6d987d63..fa01cce903a032b1576b19b5d2f59ead5c7fb981 100644 (file)
@@ -242,12 +242,16 @@ void HostCacheSegmented<Key, Value>::update_counts()
     PegCount* pcs = (PegCount*)&counts;
     const PegInfo* pegs = get_pegs();
 
-    for ( int i = 0; pegs[i].type != CountType::END; i++ )
+    for (int i = 0; pegs[i].type != CountType::END; i++)
+        pcs[i] = 0;
+
+    for (auto cache : seg_list) 
     {
-        PegCount c = 0;
-        for(auto cache : seg_list)
-            c += cache->get_counts()[i];
-        pcs[i] = c;
+        const PegCount* cache_counts = cache->get_counts();
+        cache->lock();
+        for (int i = 0; pegs[i].type != CountType::END; i++) 
+            pcs[i] += cache_counts[i];
+        cache->unlock();
     }
 }