-- changed all output filename configs to be based on module name
-- fixed -K handling
-- fixed laulert when rule has no msg
+-- made some packet data available to alert_luajit
122
-- pulled thread pinning from Josh
virtual void get_protocol_ids(std::vector<uint16_t>&);
- virtual bool decode(const RawData&, CodecData&, SnortData&);
+ virtual bool decode(const RawData&, CodecData&, DecodeData&);
};
v.push_back(IPPROTO_ID_PIM);
}
-bool PimCodec::decode(const RawData&, CodecData& codec, SnortData&)
+bool PimCodec::decode(const RawData&, CodecData& codec, DecodeData&)
{
codec_events::decoder_event(codec, DECODE_IP_BAD_PROTO);
return true;
virtual void get_data_link_type(std::vector<int>&);
- virtual bool decode(const RawData&, CodecData&, SnortData&);
+ virtual bool decode(const RawData&, CodecData&, DecodeData&);
};
//void DecodeTRPkt(Packet * p, const DAQ_PktHdr_t * pkthdr, const uint8_t * pkt)
-bool TrCodec::decode(const RawData& raw, CodecData& codec, SnortData&)
+bool TrCodec::decode(const RawData& raw, CodecData& codec, DecodeData&)
{
const uint32_t cap_len = raw.len;
#include "framework/range.h"
#include "hash/sfhashfcn.h"
#include "protocols/packet.h"
+#include "protocols/tcp.h"
#include "time/profiler.h"
static const char* s_name = "urg";
-- alert() is required
function alert ()
- -- evt is a luajit SnortEvent
+ -- get luajit structs
local evt = ffi.C.get_event()
+ local pkt = ffi.C.get_packet()
-- str is a luajit string
local str = ffi.string(evt.msg)
- print(string.format('%d:%d:%d:%s', evt.gid, evt.sid, evt.rev, str))
+ -- FIXIT - this gets:
+ -- bad argument #2 to 'format' (number expected, got cdata)
+ --print(string.format('%ld %d:%d:%d %s', pkt.num, evt.gid, evt.sid, evt.rev, str))
+
+ print(string.format('%d:%d:%d %s', evt.gid, evt.sid, evt.rev, str))
end
-- plugin table is required
codec.h
counts.h
cursor.h
+ decode_data.h
logger.h
inspector.h
ips_option.h
codec.h \
counts.h \
cursor.h \
+decode_data.h \
logger.h \
inspector.h \
ips_option.h \
* name plus a timestamp.
*/
-#ifndef SF_TEXTLOG_H
-#define SF_TEXTLOG_H
+#ifndef TEXT_LOG_H
+#define TEXT_LOG_H
#include <stdio.h>
#include <string.h>
#define M_BYTES (K_BYTES*K_BYTES)
#define G_BYTES (K_BYTES*M_BYTES)
+// FIXIT-L need a LogMessage based subclass of TextLog
+// or some such to get stdout or syslog
+
/*
* DO NOT ACCESS STRUCT MEMBERS DIRECTLY
* EXCEPT FROM WITHIN THE IMPLEMENTATION!
return TextLog_Write(txt, str, strlen(str));
}
-#endif /* SF_TEXTLOG_H */
+#endif
#include "managers/script_manager.h"
#include "hash/sfhashfcn.h"
#include "parser/parser.h"
+#include "protocols/packet.h"
#include "framework/logger.h"
#include "framework/module.h"
#include "framework/parameter.h"
#include "time/profiler.h"
+#include "utils/stats.h"
static THREAD_LOCAL ProfileStats luaLogPerfStats;
//-------------------------------------------------------------------------
// ffi stuff
+//
+// IMPORTANT - if you change these structs, you must also update
+// snort_plugins.lua.
//-------------------------------------------------------------------------
struct SnortEvent
const char* os;
};
+struct SnortPacket
+{
+ // FIXIT-L add ip addrs and other useful foo to lua packet
+ const char* type;
+ uint64_t num;
+ unsigned sp;
+ unsigned dp;
+};
+
extern "C" {
// ensure Lua can link with this
const SnortEvent* get_event();
+const SnortPacket* get_packet();
}
static THREAD_LOCAL Event* event;
static THREAD_LOCAL SnortEvent lua_event;
+static THREAD_LOCAL Packet* packet;
+static THREAD_LOCAL SnortPacket lua_packet;
+
SO_PUBLIC const SnortEvent* get_event()
{
assert(event);
return &lua_event;
}
+SO_PUBLIC const SnortPacket* get_packet()
+{
+ assert(packet);
+
+ switch ( packet->type() )
+ {
+ case PktType::IP: lua_packet.type = "IP"; break;
+ case PktType::TCP: lua_packet.type = "TCP"; break;
+ case PktType::UDP: lua_packet.type = "UDP"; break;
+ case PktType::ICMP: lua_packet.type = "ICMP"; break;
+ default: lua_packet.type = "OTHER";
+ }
+
+ lua_packet.num = pc.total_from_daq;
+ lua_packet.sp = packet->ptrs.sp;
+ lua_packet.dp = packet->ptrs.dp;
+
+ return &lua_packet;
+}
+
//-------------------------------------------------------------------------
// module stuff
//-------------------------------------------------------------------------
delete[] lua;
}
-void LuaJitLogger::alert(Packet*, const char*, Event* e)
+void LuaJitLogger::alert(Packet* p, const char*, Event* e)
{
PROFILE_VARS;
MODULE_PROFILE_START(luaLogPerfStats);
+ packet = p;
event = e;
lua_State* L = lua[get_instance_id()];
const char* os;
};
const struct SnortEvent* get_event();
+
+struct SnortPacket
+{
+ const char* type;
+ uint64_t num;
+ unsigned sp;
+ unsigned dp;
+};
+const struct SnortPacket* get_packet();
]]