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~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6953cdf45246295f561eb342cb4846a0fe78cd14;p=thirdparty%2Fsnort3.git Fix configure.ac compiler search order for OSX. Add Piglet tests for codecs and loggers. Fix segfault in tcp codec. Updated documentation to reflect compiler search order. Added piglet test for icmp and udp. --- 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/doc/bugs.txt b/doc/bugs.txt index 30b866ad5..95fdf2203 100644 --- a/doc/bugs.txt +++ b/doc/bugs.txt @@ -1,11 +1,11 @@ ==== Build -* configure bombs on OSX with g\++ wrapper to clang because g++ version < 4.8 -(compare g\++ -dumpversion and g++ --version) +* configure will use clang++ by default if it is installed. +To compile with g++ instead: - workaround: export CXX=clang++ + export CXX=g++ -* export CXX=clang++ to build with clang; coughs up these warnings: +* clang; coughs up these warnings: Wunused-but-set-variable is not understood by clang clang: warning: argument unused during compilation: '-pthread' diff --git a/doc/start.txt b/doc/start.txt index 609022495..5ecb5cc5c 100644 --- a/doc/start.txt +++ b/doc/start.txt @@ -88,9 +88,9 @@ d. Or use ccmake directly to configure and generate from an arbitrary build ccmake -G "Eclipse CDT4 - Unix Makefiles" /path/to/Snort++/tree run eclipse and do File > Import > Existing Eclipse Project -* To build with clang++ on OS X with gcc installed, do this first: +* To build with g++ on OS X where clang is installed, do this first: - export CXX=clang++ + export CXX=g++ === Run diff --git a/piglet/tests/instance/codec_icmp.lua b/piglet/tests/instance/codec_icmp.lua new file mode 100644 index 000000000..7bf2a36d3 --- /dev/null +++ b/piglet/tests/instance/codec_icmp.lua @@ -0,0 +1,63 @@ +plugin = +{ + type = "piglet", + name = "codec::icmp4", + test = function() + dofile(SCRIPT_DIR .. "/../common.lua") + return run_tests(tests) + end +} + +PROTOCOL_IDS = { 1 } + +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("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + 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/codec_icmp6.lua b/piglet/tests/instance/codec_icmp6.lua new file mode 100644 index 000000000..24571e0cf --- /dev/null +++ b/piglet/tests/instance/codec_icmp6.lua @@ -0,0 +1,63 @@ +plugin = +{ + type = "piglet", + name = "codec::icmp6", + test = function() + dofile(SCRIPT_DIR .. "/../common.lua") + return run_tests(tests) + end +} + +PROTOCOL_IDS = { 58 } + +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("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + 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/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/codec_udp.lua b/piglet/tests/instance/codec_udp.lua new file mode 100644 index 000000000..cd33b7f88 --- /dev/null +++ b/piglet/tests/instance/codec_udp.lua @@ -0,0 +1,63 @@ +plugin = +{ + type = "piglet", + name = "codec::udp", + test = function() + dofile(SCRIPT_DIR .. "/../common.lua") + return run_tests(tests) + end +} + +PROTOCOL_IDS = { 17 } + +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("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + 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(); diff --git a/src/codecs/ip/cd_udp.cc b/src/codecs/ip/cd_udp.cc index 434438aa2..5f71acca2 100644 --- a/src/codecs/ip/cd_udp.cc +++ b/src/codecs/ip/cd_udp.cc @@ -383,7 +383,7 @@ bool UdpCodec::encode(const uint8_t* const raw_in, const uint16_t /*raw_len*/, ps.len = udph_out->uh_len; udph_out->uh_chk = checksum::udp_cksum((uint16_t*)udph_out, len, &ps); } - else + else if (ip_api.is_ip6()) { checksum::Pseudoheader6 ps6; const ip::IP6Hdr* const ip6h = ip_api.get_ip6h();