Go to the documentation of this file.
46 #define DEFAULT_LOG_FILENAME "fast.log"
48 #define MODULE_NAME "AlertFastLog"
51 #define MAX_FASTLOG_ALERT_SIZE 2048
54 #define MAX_FASTLOG_BUFFER_SIZE (2 * MAX_FASTLOG_ALERT_SIZE)
59 static void AlertFastLogDeInitCtx(
OutputCtx *);
68 .ConditionFunc = AlertFastLogCondition,
71 .ThreadExitPrintStatsFunc = NULL,
101 int decoder_event = 0;
105 char srcip[46], dstip[46];
106 if (PacketIsIPv4(
p)) {
109 }
else if (PacketIsIPv6(
p)) {
127 const char *protoptr;
131 snprintf(
proto,
sizeof(
proto),
"PROTO:%03" PRIu32, PacketGetIPProto(
p));
134 uint16_t src_port_or_icmp =
p->
sp;
135 uint16_t dst_port_or_icmp =
p->
dp;
136 if (PacketGetIPProto(
p) == IPPROTO_ICMP || PacketGetIPProto(
p) == IPPROTO_ICMPV6) {
137 src_port_or_icmp =
p->
icmp_s.type;
138 dst_port_or_icmp =
p->
icmp_s.code;
146 const char *action =
"";
155 if (
likely(decoder_event == 0)) {
157 "%s %s[**] [%" PRIu32
":%" PRIu32
":%"
158 PRIu32
"] %s [**] [Classification: %s] [Priority: %"PRIu32
"]"
159 " {%s} %s:%" PRIu32
" -> %s:%" PRIu32
"\n", timebuf, action,
161 protoptr, srcip, src_port_or_icmp, dstip, dst_port_or_icmp);
164 "%s %s[**] [%" PRIu32
":%" PRIu32
165 ":%" PRIu32
"] %s [**] [Classification: %s] [Priority: "
166 "%" PRIu32
"] [**] [Raw pkt: ", timebuf, action, pa->
s->
gid,
173 "] [pcap file packet: %" PRIu64
"]\n", pcap_cnt);
180 AlertFastLogOutputAlert(aft, alert_buffer, size);
193 SCLogDebug(
"Error getting context for AlertFastLog. \"initdata\" argument NULL");
227 if (logfile_ctx == NULL) {
228 SCLogDebug(
"AlertFastLogInitCtx2: Could not create new LogFileCtx");
243 output_ctx->
data = logfile_ctx;
244 output_ctx->
DeInit = AlertFastLogDeInitCtx;
246 result.
ctx = output_ctx;
251 static void AlertFastLogDeInitCtx(
OutputCtx *output_ctx)
268 static int AlertFastLogTest01(
void)
270 uint8_t *buf = (uint8_t *)
"GET /one/ HTTP/1.1\r\n"
271 "Host: one.example.org\r\n";
273 uint16_t buflen = strlen((
char *)buf);
290 "(msg:\"FastLog test\"; content:\"GET\"; "
291 "Classtype:unknown; sid:1;)");
308 static int AlertFastLogTest02(
void)
310 uint8_t *buf = (uint8_t *)
"GET /one/ HTTP/1.1\r\n"
311 "Host: one.example.org\r\n";
312 uint16_t buflen = strlen((
char *)buf);
330 "(msg:\"FastLog test\"; content:\"GET\"; "
331 "Classtype:unknown; sid:1;)");
int AlertFastLogger(ThreadVars *tv, void *data, const Packet *p)
void AlertFastLogRegisterTests(void)
This function registers unit tests for AlertFastLog API.
const struct Signature_ * s
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
LogFileCtx * LogFileNewCtx(void)
LogFileNewCtx() Get a new LogFileCtx.
uint64_t PcapPacketCntGet(const Packet *p)
const char * PrintInetIPv6(const void *src, char *dst, socklen_t size, bool compress_ipv6)
void AlertFastLogRegister(void)
main detection engine ctx
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
bool SCProtoNameValid(uint16_t proto)
Function to check if the received protocol number is valid and do we have corresponding name entry fo...
int(* Write)(const char *buffer, int buffer_len, struct LogFileCtx_ *fp)
const char * known_proto[256]
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
TmEcode AlertFastLogThreadInit(ThreadVars *, const void *, void **)
#define MAX_FASTLOG_BUFFER_SIZE
#define GET_IPV6_DST_ADDR(p)
#define DEFAULT_LOG_FILENAME
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
struct Packet_::@32::@39 icmp_s
#define PASS
Pass the test.
#define GET_IPV4_DST_ADDR_PTR(p)
void PrintBufferRawLineHex(char *nbuf, int *offset, int max_size, const uint8_t *buf, uint32_t buflen)
print a buffer as hex on a single line
OutputInitResult AlertFastLogInitCtx(SCConfNode *conf)
Create a new LogFileCtx for "fast" output style.
Per thread variable structure.
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
void StatsThreadInit(StatsThreadContext *stats)
#define MAX_FASTLOG_ALERT_SIZE
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
#define GET_IPV4_SRC_ADDR_PTR(p)
#define PrintBufferData(buf, buf_offset_ptr, buf_size,...)
void(* DeInit)(struct OutputCtx_ *)
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
void OutputRegisterPacketModule(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, OutputPacketLoggerFunctions *output_module_functions)
Register a packet output module.
int LogFileFreeCtx(LogFileCtx *lf_ctx)
LogFileFreeCtx() Destroy a LogFileCtx (Close the file and free memory)
struct AlertFastLogThread_ AlertFastLogThread
int SCConfLogOpenGeneric(SCConfNode *conf, LogFileCtx *log_ctx, const char *default_filename, int rotate)
open a generic output "log file", which may be a regular file or a socket
#define GET_IPV6_SRC_ADDR(p)
DetectEngineCtx * DetectEngineCtxInit(void)
int EngineModeIsIPS(void)
FILE * SCClassConfGenerateValidDummyClassConfigFD01(void)
Creates a dummy classification file, with all valid Classtypes, for testing purposes.
void StatsThreadCleanup(StatsThreadContext *stats)
bool SCClassConfLoadClassificationConfigFile(DetectEngineCtx *de_ctx, FILE *fd)
Loads the Classtype info from the classification.config file.
TmEcode AlertFastLogThreadDeinit(ThreadVars *, void *)
void CreateTimeString(const SCTime_t ts, char *str, size_t size)
void SCClassConfDeInitContext(DetectEngineCtx *de_ctx)
Releases resources used by the Classification Config API.
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.