Updated documentation to reflect compiler search order.
Added piglet test for icmp and udp.
LT_INIT
-AC_PROG_CXX
+AC_PROG_CXX([clang++ g++])
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CPP
==== 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'
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
--- /dev/null
+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
+}
--- /dev/null
+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
+}
--- /dev/null
+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
+}
--- /dev/null
+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
+}
--- /dev/null
+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
+}
--- /dev/null
+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
+}
--- /dev/null
+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
+}
--- /dev/null
+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
+}
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();
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();