Go to the documentation of this file.
55 #define MODULE_NAME "AlertSyslog"
70 static void AlertSyslogDeInitCtx(
OutputCtx *output_ctx)
72 if (output_ctx != NULL) {
74 if (logfile_ctx != NULL) {
90 SCLogWarning(
"The syslog output has been deprecated and will be removed in Suricata 9.0.");
94 if (facility_s == NULL) {
99 if (logfile_ctx == NULL) {
100 SCLogDebug(
"AlertSyslogInitCtx: Could not create new LogFileCtx");
105 if (facility == -1) {
107 " now using \"%s\" as syslog facility",
113 if (level_s != NULL) {
116 alert_syslog_level = level;
124 openlog(ident, LOG_PID|LOG_NDELAY, facility);
133 output_ctx->
data = logfile_ctx;
134 output_ctx->
DeInit = AlertSyslogDeInitCtx;
138 result.
ctx = output_ctx;
151 static TmEcode AlertSyslogThreadInit(
ThreadVars *t,
const void *initdata,
void **data)
153 if(initdata == NULL) {
154 SCLogDebug(
"Error getting context for AlertSyslog. \"initdata\" "
202 const char *action =
"";
208 const char *protoptr;
209 const IPV4Hdr *ipv4h = PacketGetIPv4(p);
214 snprintf(
proto,
sizeof(
proto),
"PROTO:%03" PRIu8, ipproto);
218 char srcip[16], dstip[16];
222 for (
int i = 0; i < p->
alerts.
cnt; i++) {
236 syslog(alert_syslog_level,
"%s[%" PRIu32
":%" PRIu32
":%"
237 PRIu32
"] %s [Classification: %s] [Priority: %"PRIu32
"]"
238 " {%s} %s:%" PRIu32
" -> %s:%" PRIu32
"", action, pa->
s->
gid,
240 protoptr, srcip, p->
sp, dstip, p->
dp);
259 const char *action =
"";
265 const char *protoptr;
270 snprintf(
proto,
sizeof(
proto),
"PROTO:03%" PRIu8, ipproto);
274 char srcip[46], dstip[46];
278 for (
int i = 0; i < p->
alerts.
cnt; i++) {
291 syslog(alert_syslog_level,
"%s[%" PRIu32
":%" PRIu32
":%"
292 "" PRIu32
"] %s [Classification: %s] [Priority: %"
293 "" PRIu32
"] {%s} %s:%" PRIu32
" -> %s:%" PRIu32
"",
295 pa->
s->
prio, protoptr, srcip, p->
sp,
315 const char *action =
"";
320 char temp_buf_hdr[512];
321 char temp_buf_pkt[65] =
"";
322 char temp_buf_tail[64];
323 char alert[2048] =
"";
325 for (
int i = 0; i < p->
alerts.
cnt; i++) {
337 snprintf(temp_buf_hdr,
sizeof(temp_buf_hdr),
"%s[%" PRIu32
":%" PRIu32
338 ":%" PRIu32
"] %s [Classification: %s] [Priority: %" PRIu32
339 "] [**] [Raw pkt: ", action, pa->
s->
gid, pa->
s->
id, pa->
s->
rev, pa->
s->
msg,
341 strlcpy(alert, temp_buf_hdr,
sizeof(alert));
344 strlcat(alert, temp_buf_pkt,
sizeof(alert));
347 snprintf(temp_buf_tail,
sizeof(temp_buf_tail),
"] [pcap file packet: %"PRIu64
"]",
350 temp_buf_tail[0] =
']';
351 temp_buf_tail[1] =
'\0';
353 strlcat(alert, temp_buf_tail,
sizeof(alert));
356 syslog(alert_syslog_level,
"%s", alert);
370 if (PacketIsIPv4(p)) {
371 return AlertSyslogIPv4(
tv, p, thread_data);
372 }
else if (PacketIsIPv6(p)) {
373 return AlertSyslogIPv6(
tv, p, thread_data);
375 return AlertSyslogDecoderEvent(
tv, p, thread_data);
388 AlertSyslogLogger, AlertSyslogCondition, AlertSyslogThreadInit,
389 AlertSyslogThreadDeinit);
const struct Signature_ * s
#define syslog(__pri, __fmt, __param)
#define IPV4_GET_RAW_IPPROTO(ip4h)
LogFileCtx * LogFileNewCtx(void)
LogFileNewCtx() Get a new LogFileCtx.
bool SCProtoNameValid(uint16_t proto)
Function to check if the received protocol number is valid and do we have corresponding name entry fo...
void AlertSyslogRegister(void)
Function to register the AlertSyslog module.
#define IPV6_GET_L4PROTO(p)
const char * known_proto[256]
void OutputRegisterPacketModule(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, PacketLogger PacketLogFunc, PacketLogCondition PacketConditionFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a packet output module.
#define GET_IPV6_DST_ADDR(p)
PacketEngineEvents events
#define DEFAULT_ALERT_SYSLOG_FACILITY
size_t strlcpy(char *dst, const char *src, size_t siz)
#define DEFAULT_ALERT_SYSLOG_LEVEL
#define GET_IPV4_DST_ADDR_PTR(p)
size_t strlcat(char *, const char *src, size_t siz)
SCEnumCharMap * SCSyslogGetFacilityMap(void)
returns the syslog facility enum map
#define SCMutexUnlock(mut)
#define DEFAULT_ALERT_SYSLOG_FACILITY_STR
Per thread variable structure.
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
#define SCLogWarning(...)
Macro used to log WARNING messages.
SCEnumCharMap * SCSyslogGetLogLevelMap(void)
returns the syslog facility enum map
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define GET_IPV4_SRC_ADDR_PTR(p)
int SCMapEnumNameToValue(const char *enum_name, SCEnumCharMap *table)
Maps a string name to an enum value from the supplied table. Please specify the last element of any m...
void(* DeInit)(struct OutputCtx_ *)
int LogFileFreeCtx(LogFileCtx *lf_ctx)
LogFileFreeCtx() Destroy a LogFileCtx (Close the file and free memory)
#define GET_IPV6_SRC_ADDR(p)
int EngineModeIsIPS(void)
struct AlertSyslogThread_ AlertSyslogThread
#define openlog(__ident, __option, __facility)
void PrintRawLineHexBuf(char *retbuf, uint32_t retbuflen, const uint8_t *buf, uint32_t buflen)
print a buffer as hex on a single line into retbuf buffer
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.