]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
iprep: fix reputation loading and reloading 588/head
authorVictor Julien <victor@inliniac.net>
Thu, 10 Oct 2013 16:24:40 +0000 (18:24 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 11 Oct 2013 12:59:43 +0000 (14:59 +0200)
When an IP is listed in multiple categories, each new "load" would clear the
previous loads for that IP.

Bug #976

src/detect-iprep.c
src/reputation.c

index 9e537b5a31b213f14fe7ab73818140da82ad95c3..0491f43eef9fa66c9d904161f1a04fa488c4e085 100644 (file)
@@ -204,8 +204,8 @@ int DetectIPRepMatch (ThreadVars *t, DetectEngineThreadCtx *det_ctx, Packet *p,
             break;
 
         case DETECT_IPREP_CMD_SRC:
-            SCLogDebug("checking src");
             val = GetHostRepSrc(p, rd->cat, version);
+            SCLogDebug("checking src -- val %u (looking for cat %u, val %u)", val, rd->cat, rd->val);
             if (val > 0) {
                 return RepMatch(rd->op, val, rd->val);
             }
@@ -335,7 +335,7 @@ int DetectIPRepSetup (DetectEngineCtx *de_ctx, Signature *s, char *rawstr)
     cd->cat = cat;
     cd->op = op;
     cd->val = val;
-    //SCLogInfo("cmd %u, cat %u, op %u, val %u", cd->cmd, cd->cat, cd->op, cd->val);
+    SCLogDebug("cmd %u, cat %u, op %u, val %u", cd->cmd, cd->cat, cd->op, cd->val);
 
     pcre_free_substring(name);
     name = NULL;
index 5832bb36f91abb482232df7bfcdd8bd6752b40b1..04945aa2e239883f7ffa4553cb62bf12cf207f99 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007-2010 Open Information Security Foundation
+/* Copyright (C) 2007-2013 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -42,7 +42,9 @@
  *  time out code will use it to check if a host's
  *  reputation info is outdated. */
 SC_ATOMIC_DECLARE(uint32_t, srep_eversion);
-/** reputation version set to the host's reputation */
+/** reputation version set to the host's reputation,
+ *  this will be set to 1 before rep files are loaded,
+ *  so hosts will always have a minial value of 1 */
 static uint32_t srep_version = 0;
 
 static uint32_t SRepIncrVersion(void) {
@@ -351,14 +353,29 @@ static int SRepLoadFile(char *filename) {
                 if (h->iprep != NULL) {
                     SReputation *rep = h->iprep;
 
-                    /* if version is 0, it has been used before, so
-                     * clear it */
-                    if (rep->version != 0) {
+                    /* if version is outdated, it's an older entry that we'll
+                     * now replace. */
+                    if (rep->version != SRepGetVersion()) {
                         memset(rep, 0x00, sizeof(SReputation));
                     }
 
                     rep->version = SRepGetVersion();
                     rep->rep[cat] = value;
+
+                    SCLogDebug("host %p iprep %p setting cat %u to value %u",
+                        h, h->iprep, cat, value);
+#ifdef DEBUG
+                    if (SCLogDebugEnabled()) {
+                        int i;
+                        for (i = 0; i < SREP_MAX_CATS; i++) {
+                            if (rep->rep[i] == 0)
+                                continue;
+
+                            SCLogDebug("--> host %p iprep %p cat %d to value %u",
+                                    h, h->iprep, i, rep->rep[i]);
+                        }
+                    }
+#endif
                 }
 
                 HostRelease(h);