]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Fix configure.ac compiler search order for OSX. Add Piglet tests for codecs and...
authorVictor Roemer <viroemer@cisco.com>
Tue, 8 Sep 2015 22:46:58 +0000 (18:46 -0400)
committerVictor Roemer <viroemer@cisco.com>
Tue, 8 Sep 2015 22:46:58 +0000 (18:46 -0400)
configure.ac
piglet/tests/instance/codec_ipv4.lua [moved from piglet/tests/instance/codec.lua with 100% similarity]
piglet/tests/instance/codec_ipv6.lua [new file with mode: 0644]
piglet/tests/instance/codec_tcp.lua [new file with mode: 0644]
piglet/tests/instance/logger_csv.lua [new file with mode: 0644]
piglet/tests/instance/logger_fast.lua [new file with mode: 0644]
piglet/tests/instance/logger_full.lua [new file with mode: 0644]
src/codecs/ip/cd_tcp.cc

index a15b8e5f5a7ea329e8d987b6c5188fd9e7096b16..3c7f9b82742ef5b8307d304a428a2e3a36a676b8 100644 (file)
@@ -37,7 +37,7 @@ AM_INIT_AUTOMAKE(foreign nostdinc)
 
 LT_INIT
 
-AC_PROG_CXX
+AC_PROG_CXX([clang++ g++])
 AC_PROG_AWK
 AC_PROG_CC
 AC_PROG_CPP
diff --git a/piglet/tests/instance/codec_ipv6.lua b/piglet/tests/instance/codec_ipv6.lua
new file mode 100644 (file)
index 0000000..59353fa
--- /dev/null
@@ -0,0 +1,77 @@
+plugin =
+{
+    type = "piglet",
+    name = "codec::ipv6",
+    test = function()
+        dofile(SCRIPT_DIR .. "/../common.lua")
+        return run_tests(tests)
+    end
+}
+
+DATA_LINK_TYPES = { }
+PROTOCOL_IDS = { 0x86dd, 41 }
+
+tests =
+{
+    initialize = function()
+        assert(Codec)
+    end,
+
+    get_data_link_type = function()
+        local rv = Codec.get_data_link_type()
+        check.arrays_equal(DATA_LINK_TYPES, rv)
+    end,
+
+    get_protocol_ids = function()
+        local rv = Codec.get_protocol_ids()
+        check.arrays_equal(PROTOCOL_IDS, rv)
+    end,
+
+    decode = function()
+        local daq = DAQHeader.new()
+        local rb = RawBuffer.new("foobar")
+        local cd = CodecData.new()
+        local dd = DecodeData.new()
+
+        local rv = Codec.decode(daq, rb, cd, dd)
+        assert(not rv)
+    end,
+
+    log = function()
+        local rb = RawBuffer.new()
+        Codec.log(rb)
+        Codec.log(rb, 0)
+        print()
+    end,
+
+    encode = function()
+        local rb = RawBuffer.new()
+        local es = EncState.new()
+        local rb_buf = RawBuffer.new(128)
+        local buf = Buffer.new(rb_buf)
+
+        local rv = Codec.encode(rb, es, buf)
+        assert(rv)
+    end,
+
+    update = function()
+        local rb = RawBuffer.new(64)
+        assert(1)
+
+        -- FIXIT-H: checksum calculation is failing (temporarily set UPD_COOKED (0x1))
+        --local rv = Codec.update(0, 1, rb)
+        --assert(rv == 0)
+
+        -- FIXIT-H: checksum calculation is failing (temporarily set UPD_COOKED (0x1))
+        --local rv = Codec.update(0, 1, rb, 64)
+        --assert(rv == 0)
+    end,
+
+    format = function()
+        local rb = RawBuffer.new()
+        local dd = DecodeData.new()
+
+        Codec.format(true, rb, dd)
+        Codec.format(false, rb, dd)
+    end
+}
diff --git a/piglet/tests/instance/codec_tcp.lua b/piglet/tests/instance/codec_tcp.lua
new file mode 100644 (file)
index 0000000..201dd4b
--- /dev/null
@@ -0,0 +1,63 @@
+plugin =
+{
+    type = "piglet",
+    name = "codec::tcp",
+    test = function()
+        dofile(SCRIPT_DIR .. "/../common.lua")
+        return run_tests(tests)
+    end
+}
+
+PROTOCOL_IDS = { 6 }
+
+tests =
+{
+    initialize = function()
+        assert(Codec)
+    end,
+
+    get_protocol_ids = function()
+        local rv = Codec.get_protocol_ids()
+        check.arrays_equal(PROTOCOL_IDS, rv)
+    end,
+
+    decode = function()
+        local daq = DAQHeader.new()
+        local rb = RawBuffer.new("foobar")
+        local cd = CodecData.new()
+        local dd = DecodeData.new()
+
+        local rv = Codec.decode(daq, rb, cd, dd)
+        assert(not rv)
+    end,
+
+    log = function()
+        local rb = RawBuffer.new()
+        Codec.log(rb)
+        Codec.log(rb, 0)
+        print()
+    end,
+
+    encode = function()
+        local rb = RawBuffer.new()
+        local es = EncState.new()
+        local rb_buf = RawBuffer.new(128)
+        local buf = Buffer.new(rb_buf)
+
+        local rv = Codec.encode(rb, es, buf)
+        assert(rv)
+    end,
+
+    update = function()
+        local rb = RawBuffer.new(64)
+        assert(1)
+    end,
+
+    format = function()
+        local rb = RawBuffer.new()
+        local dd = DecodeData.new()
+
+        Codec.format(true, rb, dd)
+        Codec.format(false, rb, dd)
+    end
+}
diff --git a/piglet/tests/instance/logger_csv.lua b/piglet/tests/instance/logger_csv.lua
new file mode 100644 (file)
index 0000000..177f463
--- /dev/null
@@ -0,0 +1,53 @@
+plugin =
+{
+    type = "piglet",
+    name = "logger::alert_csv",
+    use_defaults = true,
+    test = function()
+        dofile(SCRIPT_DIR .. "/../common.lua")
+
+        Logger.open()
+        local rv = run_tests(tests)
+        Logger.close()
+        return rv
+    end
+}
+
+IP4 = [[
+45  | 00  | 00  46 | 00 00 | 00 00 | 01 | 06
+00 00 | 00 00 00 01 | 00 00 00 02
+
+00 00 | 00 00 | 00 00 00 00 | 00 00 00 00 | 06 02
+00 00 ff ff | 00 00 | 00 00 | 00 00
+]]
+
+DATA = "abcdefghijklmnopqrstuvwxyz"
+
+tests =
+{
+    exists = function()
+        assert(Logger)
+    end,
+
+    reset = function()
+        Logger.reset()
+    end,
+
+    alert = function()
+        local p = packet.construct_ip4(IP4:encode_hex(), DATA)
+        local e = Event.new()
+
+        e:set { generator = 135, id = 2 }
+
+        Logger.alert(p, "foo", e)
+    end,
+    
+    log = function()
+        local p = packet.construct_ip4(IP4:encode_hex(), DATA)
+        local e = Event.new()
+
+        e:set { generator = 135, id = 2 }
+
+        Logger.log(p, "foo", e)
+    end
+}
diff --git a/piglet/tests/instance/logger_fast.lua b/piglet/tests/instance/logger_fast.lua
new file mode 100644 (file)
index 0000000..204117b
--- /dev/null
@@ -0,0 +1,53 @@
+plugin =
+{
+    type = "piglet",
+    name = "logger::alert_fast",
+    use_defaults = true,
+    test = function()
+        dofile(SCRIPT_DIR .. "/../common.lua")
+
+        Logger.open()
+        local rv = run_tests(tests)
+        Logger.close()
+        return rv
+    end
+}
+
+IP4 = [[
+45  | 00  | 00  46 | 00 00 | 00 00 | 01 | 06
+00 00 | 00 00 00 01 | 00 00 00 02
+
+00 00 | 00 00 | 00 00 00 00 | 00 00 00 00 | 06 02
+00 00 ff ff | 00 00 | 00 00 | 00 00
+]]
+
+DATA = "abcdefghijklmnopqrstuvwxyz"
+
+tests =
+{
+    exists = function()
+        assert(Logger)
+    end,
+
+    reset = function()
+        Logger.reset()
+    end,
+
+    alert = function()
+        local p = packet.construct_ip4(IP4:encode_hex(), DATA)
+        local e = Event.new()
+
+        e:set { generator = 135, id = 2 }
+
+        Logger.alert(p, "foo", e)
+    end,
+    
+    log = function()
+        local p = packet.construct_ip4(IP4:encode_hex(), DATA)
+        local e = Event.new()
+
+        e:set { generator = 135, id = 2 }
+
+        Logger.log(p, "foo", e)
+    end
+}
diff --git a/piglet/tests/instance/logger_full.lua b/piglet/tests/instance/logger_full.lua
new file mode 100644 (file)
index 0000000..5fbe9a1
--- /dev/null
@@ -0,0 +1,53 @@
+plugin =
+{
+    type = "piglet",
+    name = "logger::alert_full",
+    use_defaults = true,
+    test = function()
+        dofile(SCRIPT_DIR .. "/../common.lua")
+
+        Logger.open()
+        local rv = run_tests(tests)
+        Logger.close()
+        return rv
+    end
+}
+
+IP4 = [[
+45  | 00  | 00  46 | 00 00 | 00 00 | 01 | 06
+00 00 | 00 00 00 01 | 00 00 00 02
+
+00 00 | 00 00 | 00 00 00 00 | 00 00 00 00 | 06 02
+00 00 ff ff | 00 00 | 00 00 | 00 00
+]]
+
+DATA = "abcdefghijklmnopqrstuvwxyz"
+
+tests =
+{
+    exists = function()
+        assert(Logger)
+    end,
+
+    reset = function()
+        Logger.reset()
+    end,
+
+    alert = function()
+        local p = packet.construct_ip4(IP4:encode_hex(), DATA)
+        local e = Event.new()
+
+        e:set { generator = 135, id = 2 }
+
+        Logger.alert(p, "foo", e)
+    end,
+    
+    log = function()
+        local p = packet.construct_ip4(IP4:encode_hex(), DATA)
+        local e = Event.new()
+
+        e:set { generator = 135, id = 2 }
+
+        Logger.log(p, "foo", e)
+    end
+}
index 9e3727b50088f1562e8d27ac191ddbae4d7e28cf..b3579ef43e04606205ae720a658ae72a01977365 100644 (file)
@@ -659,7 +659,7 @@ bool TcpCodec::encode(const uint8_t* const raw_in, const uint16_t /*raw_len*/,
         ps.len = htons((uint16_t)len);
         tcph_out->th_sum = checksum::tcp_cksum((uint16_t*)tcph_out, len, &ps);
     }
-    else
+    else if (ip_api.is_ip6())
     {
         checksum::Pseudoheader6 ps6;
         int len = buf.size();