]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
cmdline: add -k to specify checksum validation
authorEric Leblond <eric@regit.org>
Wed, 27 Nov 2013 12:22:42 +0000 (13:22 +0100)
committerEric Leblond <eric@regit.org>
Mon, 2 Dec 2013 10:05:46 +0000 (11:05 +0100)
This patch adds a '-k' option to suricata to be able to specify
the checksum validation to use. If '-k all' is used, checksum
validation is forced. If '-k none' is used, no checksum validation
is made.

Message output in case of detection of a pcap file with a probable
cheksum issue has been updated to indicate that '-k' is a solution.

src/source-pcap-file.c
src/suricata.c
src/suricata.h

index f88cb4517de699002eafa13bda5f2cea73c7cd5e..004efac06eb0a289df219f5b52b54a2d5babd549 100644 (file)
@@ -358,7 +358,8 @@ void ReceivePcapFileThreadExitStats(ThreadVars *tv, void *data) {
         if (chrate < CHECKSUM_INVALID_RATIO)
             SCLogWarning(SC_ERR_INVALID_CHECKSUM,
                          "1/%" PRIu64 "th of packets have an invalid checksum,"
-                         " consider setting pcap-file.checksum-checks variable to no",
+                         " consider setting pcap-file.checksum-checks variable to no"
+                         " or use '-k none' option on command line.",
                          chrate);
         else
             SCLogInfo("1/%" PRIu64 "th of packets have an invalid checksum",
index b4c4a31e74392bafe53b5118ed2dfdfbfed205f8..a569bafa94ba20c0c4125cd01da6028be32fe7fe 100644 (file)
@@ -497,6 +497,7 @@ void usage(const char *progname)
        printf("\t--service-remove                     : remove service\n");
        printf("\t--service-change-params              : change service startup parameters\n");
 #endif /* OS_WIN32 */
+    printf("\t-k [all|none]                        : force checksum check (all) or disabled it (none)\n");
     printf("\t-V                                   : display Suricata version\n");
     printf("\t-v[v]                                : increase default Suricata verbosity\n");
 #ifdef UNITTESTS
@@ -939,6 +940,8 @@ static void SCInstanceInit(SCInstance *suri)
     suri->daemon = 0;
     suri->offline = 0;
     suri->verbose = 0;
+    /* use -1 as unknown */
+    suri->checksum_validation = -1;
 }
 
 static TmEcode PrintVersion()
@@ -1046,7 +1049,7 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
     /* getopt_long stores the option index here. */
     int option_index = 0;
 
-    char short_opts[] = "c:TDhi:l:q:d:r:us:S:U:VF:v";
+    char short_opts[] = "c:TDhi:l:q:d:r:us:S:U:VF:vk:";
 
     while ((opt = getopt_long(argc, argv, short_opts, long_opts, &option_index)) != -1) {
         switch (opt) {
@@ -1509,6 +1512,20 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
         case 'v':
             suri->verbose++;
             break;
+        case 'k':
+            if (optarg == NULL) {
+                SCLogError(SC_ERR_INITIALIZATION, "no option argument (optarg) for -k");
+                return TM_ECODE_FAILED;
+            }
+            if (!strcmp("all", optarg))
+                suri->checksum_validation = 1;
+            else if (!strcmp("none", optarg))
+                suri->checksum_validation = 0;
+            else {
+                SCLogError(SC_ERR_INITIALIZATION, "option '%s' invalid for -k", optarg);
+                return TM_ECODE_FAILED;
+            }
+            break;
         default:
             usage(argv[0]);
             return TM_ECODE_FAILED;
@@ -1833,6 +1850,15 @@ static int PostConfLoadedSetup(SCInstance *suri)
 
     suri->rule_reload = IsRuleReloadSet(FALSE);
 
+    switch (suri->checksum_validation) {
+        case 0:
+            ConfSet("stream.checksum-validation", "0", 0);
+            break;
+        case 1:
+            ConfSet("stream.checksum-validation", "1", 1);
+            break;
+    }
+
     AppLayerDetectProtoThreadInit();
     AppLayerParsersInitPostProcess();
 
index 551013c7eb94e022db5c2acc204ae1b00b30c60c..fa131acdcef833f93ed34863c08616c948b39482 100644 (file)
@@ -155,6 +155,7 @@ typedef struct SCInstance_ {
     int daemon;
     int offline;
     int verbose;
+    int checksum_validation;
 
     struct timeval start_time;