From: Victor Roemer Date: Tue, 8 Sep 2015 22:46:58 +0000 (-0400) Subject: Fix configure.ac compiler search order for OSX. Add Piglet tests for codecs and... X-Git-Tag: 3.0.0-233~836^2~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d82487331e21b763c663cb1b005b11a1e680bfb2;p=thirdparty%2Fsnort3.git Fix configure.ac compiler search order for OSX. Add Piglet tests for codecs and loggers. Fix segfault in tcp codec. --- diff --git a/configure.ac b/configure.ac index a15b8e5f5..3c7f9b827 100644 --- a/configure.ac +++ b/configure.ac @@ -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.lua b/piglet/tests/instance/codec_ipv4.lua similarity index 100% rename from piglet/tests/instance/codec.lua rename to piglet/tests/instance/codec_ipv4.lua diff --git a/piglet/tests/instance/codec_ipv6.lua b/piglet/tests/instance/codec_ipv6.lua new file mode 100644 index 000000000..59353fac0 --- /dev/null +++ b/piglet/tests/instance/codec_ipv6.lua @@ -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 index 000000000..201dd4b2f --- /dev/null +++ b/piglet/tests/instance/codec_tcp.lua @@ -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 index 000000000..177f46385 --- /dev/null +++ b/piglet/tests/instance/logger_csv.lua @@ -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 index 000000000..204117bf6 --- /dev/null +++ b/piglet/tests/instance/logger_fast.lua @@ -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 index 000000000..5fbe9a179 --- /dev/null +++ b/piglet/tests/instance/logger_full.lua @@ -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 +} diff --git a/src/codecs/ip/cd_tcp.cc b/src/codecs/ip/cd_tcp.cc index 9e3727b50..b3579ef43 100644 --- a/src/codecs/ip/cd_tcp.cc +++ b/src/codecs/ip/cd_tcp.cc @@ -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();