Skip to content
This repository
Browse code

Performance tweeks:

- Made the default flow bucket bigger (BUCKET_SIZE).
- Hashing of connections set to the 5-tuplets again.
  • Loading branch information...
commit 49a280ff8d45b69710405f06e5b049ac656be80d 1 parent d83cae3
Edward Fjellskål authored July 07, 2012
4  src/passivedns.c
@@ -385,9 +385,9 @@ int connection_tracking(packetinfo *pi) {
385 385
 
386 386
     // find the right connection bucket
387 387
     if (af == AF_INET) {
388  
-        hash = CXT_HASH4(IP4ADDR(ip_src),IP4ADDR(ip_dst));
  388
+        hash = CXT_HASH4(IP4ADDR(ip_src),IP4ADDR(ip_dst),src_port,dst_port,pi->proto);
389 389
     } else if (af == AF_INET6) {
390  
-        hash = CXT_HASH6(ip_src,ip_dst);
  390
+        hash = CXT_HASH6(ip_src,ip_dst,src_port,dst_port,pi->proto);
391 391
     }
392 392
     cxt = bucket[hash];
393 393
     head = cxt;
18  src/passivedns.h
@@ -24,7 +24,7 @@
24 24
 /*  D E F I N E S  ************************************************************/
25 25
 #define VERSION                       "0.5.0"
26 26
 #define TIMEOUT                       60
27  
-#define BUCKET_SIZE                   1211
  27
+#define BUCKET_SIZE                   65536
28 28
 #define SNAPLENGTH                    1600
29 29
 #define PKT_MAXPAY                    255
30 30
 #define MAX_BYTE_CHECK                500000
@@ -338,25 +338,25 @@ typedef struct _connection {
338 338
 }
339 339
 #endif
340 340
 
341  
-#define CXT_HASH4(src,dst) \
342  
-   ((src + dst) % BUCKET_SIZE)
  341
+#define CXT_HASH4(src,dst,sp,dp,pr) \
  342
+   ((src + dst + sp + dp + pr) % BUCKET_SIZE)
343 343
 
344 344
 #ifndef OSX
345  
-#define CXT_HASH6(src,dst) \
  345
+#define CXT_HASH6(src,dst,sp,dp,pr) \
346 346
  (( \
347 347
   (src)->s6_addr32[0] + (src)->s6_addr32[1] + \
348 348
   (src)->s6_addr32[2] + (src)->s6_addr32[3] + \
349 349
   (dst)->s6_addr32[0] + (dst)->s6_addr32[1] + \
350  
-  (dst)->s6_addr32[2] + (dst)->s6_addr32[3] \
351  
- ) % BUCKET_SIZE)
  350
+  (dst)->s6_addr32[2] + (dst)->s6_addr32[3] + \
  351
+  sp + dp + pr ) % BUCKET_SIZE)
352 352
 #else
353  
-#define CXT_HASH6(src,dest) \
  353
+#define CXT_HASH6(src,dest,sp,dp,pr) \
354 354
  (( \
355 355
   (src)->__u6_addr.__u6_addr32[0] + (src)->__u6_addr.__u6_addr32[1] + \
356 356
   (src)->__u6_addr.__u6_addr32[2] + (src)->__u6_addr.__u6_addr32[3] + \
357 357
   (dst)->__u6_addr.__u6_addr32[0] + (dst)->__u6_addr.__u6_addr32[1] + \
358  
-  (dst)->__u6_addr.__u6_addr32[2] + (dst)->__u6_addr.__u6_addr32[3] \
359  
- ) % BUCKET_SIZE)
  358
+  (dst)->__u6_addr.__u6_addr32[2] + (dst)->__u6_addr.__u6_addr32[3] + \
  359
+  sp + dp + pr ) % BUCKET_SIZE)
360 360
 #endif
361 361
 
362 362
 typedef struct _packetinfo {

0 notes on commit 49a280f

Please sign in to comment.
Something went wrong with that request. Please try again.