Skip to content

Commit

Permalink
reorg: clang-format src/*
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonish committed Dec 4, 2023
1 parent 8bbaffd commit d1469db
Show file tree
Hide file tree
Showing 921 changed files with 38,655 additions and 42,030 deletions.
16 changes: 8 additions & 8 deletions src/action-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

/* Changing them as flags, so later we can have alerts
* and drop simultaneously */
#define ACTION_ALERT 0x01
#define ACTION_DROP 0x02
#define ACTION_REJECT 0x04
#define ACTION_REJECT_DST 0x08
#define ACTION_REJECT_BOTH 0x10
#define ACTION_PASS 0x20
#define ACTION_CONFIG 0x40
#define ACTION_ALERT 0x01
#define ACTION_DROP 0x02
#define ACTION_REJECT 0x04
#define ACTION_REJECT_DST 0x08
#define ACTION_REJECT_BOTH 0x10
#define ACTION_PASS 0x20
#define ACTION_CONFIG 0x40

#define ACTION_REJECT_ANY (ACTION_REJECT|ACTION_REJECT_DST|ACTION_REJECT_BOTH)
#define ACTION_REJECT_ANY (ACTION_REJECT | ACTION_REJECT_DST | ACTION_REJECT_BOTH)

#define ACTION_DROP_REJECT (ACTION_REJECT_ANY | ACTION_DROP)

Expand Down
229 changes: 108 additions & 121 deletions src/alert-debuglog.c

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/alert-debuglog.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@
void AlertDebugLogRegister(void);

#endif /* __ALERT_DEBUGLOG_H__ */

61 changes: 30 additions & 31 deletions src/alert-fastlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,23 @@ int AlertFastLogger(ThreadVars *tv, void *data, const Packet *p);

void AlertFastLogRegister(void)
{
OutputRegisterPacketModule(LOGGER_ALERT_FAST, MODULE_NAME, "fast",
AlertFastLogInitCtx, AlertFastLogger, AlertFastLogCondition,
AlertFastLogThreadInit, AlertFastLogThreadDeinit, NULL);
OutputRegisterPacketModule(LOGGER_ALERT_FAST, MODULE_NAME, "fast", AlertFastLogInitCtx,
AlertFastLogger, AlertFastLogCondition, AlertFastLogThreadInit,
AlertFastLogThreadDeinit, NULL);
AlertFastLogRegisterTests();
}

typedef struct AlertFastLogThread_ {
/** LogFileCtx has the pointer to the file and a mutex to allow multithreading */
LogFileCtx* file_ctx;
LogFileCtx *file_ctx;
} AlertFastLogThread;

static bool AlertFastLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
{
return (p->alerts.cnt > 0);
}

static inline void AlertFastLogOutputAlert(AlertFastLogThread *aft, char *buffer,
int alert_size)
static inline void AlertFastLogOutputAlert(AlertFastLogThread *aft, char *buffer, int alert_size)
{
/* Output the alert string and count alerts. Only need to lock here. */
aft->file_ctx->Write(buffer, alert_size, aft->file_ctx);
Expand Down Expand Up @@ -158,22 +157,24 @@ int AlertFastLogger(ThreadVars *tv, void *data, const Packet *p)
int size = 0;
if (likely(decoder_event == 0)) {
PrintBufferData(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE,
"%s %s[**] [%" PRIu32 ":%" PRIu32 ":%"
PRIu32 "] %s [**] [Classification: %s] [Priority: %"PRIu32"]"
" {%s} %s:%" PRIu32 " -> %s:%" PRIu32 "\n", timebuf, action,
pa->s->gid, pa->s->id, pa->s->rev, pa->s->msg, pa->s->class_msg, pa->s->prio,
protoptr, srcip, src_port_or_icmp, dstip, dst_port_or_icmp);
"%s %s[**] [%" PRIu32 ":%" PRIu32 ":%" PRIu32
"] %s [**] [Classification: %s] [Priority: %" PRIu32 "]"
" {%s} %s:%" PRIu32 " -> %s:%" PRIu32 "\n",
timebuf, action, pa->s->gid, pa->s->id, pa->s->rev, pa->s->msg,
pa->s->class_msg, pa->s->prio, protoptr, srcip, src_port_or_icmp, dstip,
dst_port_or_icmp);
} else {
PrintBufferData(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE,
"%s %s[**] [%" PRIu32 ":%" PRIu32
":%" PRIu32 "] %s [**] [Classification: %s] [Priority: "
"%" PRIu32 "] [**] [Raw pkt: ", timebuf, action, pa->s->gid,
pa->s->id, pa->s->rev, pa->s->msg, pa->s->class_msg, pa->s->prio);
PrintBufferRawLineHex(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE,
GET_PKT_DATA(p), GET_PKT_LEN(p) < 32 ? GET_PKT_LEN(p) : 32);
PrintBufferData(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE,
"%s %s[**] [%" PRIu32 ":%" PRIu32 ":%" PRIu32
"] %s [**] [Classification: %s] [Priority: "
"%" PRIu32 "] [**] [Raw pkt: ",
timebuf, action, pa->s->gid, pa->s->id, pa->s->rev, pa->s->msg,
pa->s->class_msg, pa->s->prio);
PrintBufferRawLineHex(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE, GET_PKT_DATA(p),
GET_PKT_LEN(p) < 32 ? GET_PKT_LEN(p) : 32);
if (p->pcap_cnt != 0) {
PrintBufferData(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE,
"] [pcap file packet: %"PRIu64"]\n", p->pcap_cnt);
PrintBufferData(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE,
"] [pcap file packet: %" PRIu64 "]\n", p->pcap_cnt);
} else {
PrintBufferData(alert_buffer, &size, MAX_FASTLOG_ALERT_SIZE, "]\n");
}
Expand All @@ -191,8 +192,7 @@ TmEcode AlertFastLogThreadInit(ThreadVars *t, const void *initdata, void **data)
AlertFastLogThread *aft = SCCalloc(1, sizeof(AlertFastLogThread));
if (unlikely(aft == NULL))
return TM_ECODE_FAILED;
if(initdata == NULL)
{
if (initdata == NULL) {
SCLogDebug("Error getting context for AlertFastLog. \"initdata\" argument NULL");
SCFree(aft);
return TM_ECODE_FAILED;
Expand Down Expand Up @@ -264,8 +264,8 @@ static void AlertFastLogDeInitCtx(OutputCtx *output_ctx)

static int AlertFastLogTest01(void)
{
uint8_t *buf = (uint8_t *) "GET /one/ HTTP/1.1\r\n"
"Host: one.example.org\r\n";
uint8_t *buf = (uint8_t *)"GET /one/ HTTP/1.1\r\n"
"Host: one.example.org\r\n";

uint16_t buflen = strlen((char *)buf);
Packet *p = NULL;
Expand All @@ -284,8 +284,8 @@ static int AlertFastLogTest01(void)
SCClassConfLoadClassificationConfigFile(de_ctx, fd);

de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
"(msg:\"FastLog test\"; content:\"GET\"; "
"Classtype:unknown; sid:1;)");
"(msg:\"FastLog test\"; content:\"GET\"; "
"Classtype:unknown; sid:1;)");

SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
Expand All @@ -305,8 +305,8 @@ static int AlertFastLogTest01(void)

static int AlertFastLogTest02(void)
{
uint8_t *buf = (uint8_t *) "GET /one/ HTTP/1.1\r\n"
"Host: one.example.org\r\n";
uint8_t *buf = (uint8_t *)"GET /one/ HTTP/1.1\r\n"
"Host: one.example.org\r\n";
uint16_t buflen = strlen((char *)buf);
Packet *p = NULL;
ThreadVars th_v;
Expand All @@ -325,8 +325,8 @@ static int AlertFastLogTest02(void)
SCClassConfLoadClassificationConfigFile(de_ctx, fd);

de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any "
"(msg:\"FastLog test\"; content:\"GET\"; "
"Classtype:unknown; sid:1;)");
"(msg:\"FastLog test\"; content:\"GET\"; "
"Classtype:unknown; sid:1;)");

SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
Expand Down Expand Up @@ -358,5 +358,4 @@ void AlertFastLogRegisterTests(void)
UtRegisterTest("AlertFastLogTest02", AlertFastLogTest02);

#endif /* UNITTESTS */

}
1 change: 0 additions & 1 deletion src/alert-fastlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ void AlertFastLogRegister(void);
OutputInitResult AlertFastLogInitCtx(ConfNode *);

#endif /* __ALERT_FASTLOG_H__ */

50 changes: 26 additions & 24 deletions src/alert-syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@

#ifndef OS_WIN32

#define MODULE_NAME "AlertSyslog"
#define MODULE_NAME "AlertSyslog"

static int alert_syslog_level = DEFAULT_ALERT_SYSLOG_LEVEL;

typedef struct AlertSyslogThread_ {
/** LogFileCtx has the pointer to the file and a mutex to allow multithreading */
LogFileCtx* file_ctx;
LogFileCtx *file_ctx;
} AlertSyslogThread;

/**
Expand Down Expand Up @@ -119,7 +119,7 @@ static OutputInitResult AlertSyslogInitCtx(ConfNode *conf)
/* if null we just pass that to openlog, which will then
* figure it out by itself. */

openlog(ident, LOG_PID|LOG_NDELAY, facility);
openlog(ident, LOG_PID | LOG_NDELAY, facility);

OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
Expand Down Expand Up @@ -148,9 +148,9 @@ static OutputInitResult AlertSyslogInitCtx(ConfNode *conf)
*/
static TmEcode AlertSyslogThreadInit(ThreadVars *t, const void *initdata, void **data)
{
if(initdata == NULL) {
if (initdata == NULL) {
SCLogDebug("Error getting context for AlertSyslog. \"initdata\" "
"argument NULL");
"argument NULL");
return TM_ECODE_FAILED;
}

Expand Down Expand Up @@ -232,11 +232,12 @@ static TmEcode AlertSyslogIPv4(ThreadVars *tv, const Packet *p, void *data)
action = "[wDrop] ";
}

syslog(alert_syslog_level, "%s[%" PRIu32 ":%" PRIu32 ":%"
PRIu32 "] %s [Classification: %s] [Priority: %"PRIu32"]"
" {%s} %s:%" PRIu32 " -> %s:%" PRIu32 "", action, pa->s->gid,
pa->s->id, pa->s->rev, pa->s->msg, pa->s->class_msg, pa->s->prio,
protoptr, srcip, p->sp, dstip, p->dp);
syslog(alert_syslog_level,
"%s[%" PRIu32 ":%" PRIu32 ":%" PRIu32
"] %s [Classification: %s] [Priority: %" PRIu32 "]"
" {%s} %s:%" PRIu32 " -> %s:%" PRIu32 "",
action, pa->s->gid, pa->s->id, pa->s->rev, pa->s->msg, pa->s->class_msg,
pa->s->prio, protoptr, srcip, p->sp, dstip, p->dp);
}
SCMutexUnlock(&ast->file_ctx->fp_mutex);

Expand Down Expand Up @@ -289,13 +290,12 @@ static TmEcode AlertSyslogIPv6(ThreadVars *tv, const Packet *p, void *data)
action = "[wDrop] ";
}

syslog(alert_syslog_level, "%s[%" PRIu32 ":%" PRIu32 ":%"
syslog(alert_syslog_level,
"%s[%" PRIu32 ":%" PRIu32 ":%"
"" PRIu32 "] %s [Classification: %s] [Priority: %"
"" PRIu32 "] {%s} %s:%" PRIu32 " -> %s:%" PRIu32 "",
action, pa->s->gid, pa->s->id, pa->s->rev, pa->s->msg, pa->s->class_msg,
pa->s->prio, protoptr, srcip, p->sp,
dstip, p->dp);

pa->s->prio, protoptr, srcip, p->sp, dstip, p->dp);
}
SCMutexUnlock(&ast->file_ctx->fp_mutex);

Expand Down Expand Up @@ -339,17 +339,19 @@ static TmEcode AlertSyslogDecoderEvent(ThreadVars *tv, const Packet *p, void *da
action = "[wDrop] ";
}

snprintf(temp_buf_hdr, sizeof(temp_buf_hdr), "%s[%" PRIu32 ":%" PRIu32
":%" PRIu32 "] %s [Classification: %s] [Priority: %" PRIu32
"] [**] [Raw pkt: ", action, pa->s->gid, pa->s->id, pa->s->rev, pa->s->msg,
pa->s->class_msg, pa->s->prio);
snprintf(temp_buf_hdr, sizeof(temp_buf_hdr),
"%s[%" PRIu32 ":%" PRIu32 ":%" PRIu32
"] %s [Classification: %s] [Priority: %" PRIu32 "] [**] [Raw pkt: ",
action, pa->s->gid, pa->s->id, pa->s->rev, pa->s->msg, pa->s->class_msg,
pa->s->prio);
strlcpy(alert, temp_buf_hdr, sizeof(alert));

PrintRawLineHexBuf(temp_buf_pkt, sizeof(temp_buf_pkt), GET_PKT_DATA(p), GET_PKT_LEN(p) < 32 ? GET_PKT_LEN(p) : 32);
PrintRawLineHexBuf(temp_buf_pkt, sizeof(temp_buf_pkt), GET_PKT_DATA(p),
GET_PKT_LEN(p) < 32 ? GET_PKT_LEN(p) : 32);
strlcat(alert, temp_buf_pkt, sizeof(alert));

if (p->pcap_cnt != 0) {
snprintf(temp_buf_tail, sizeof(temp_buf_tail), "] [pcap file packet: %"PRIu64"]",
snprintf(temp_buf_tail, sizeof(temp_buf_tail), "] [pcap file packet: %" PRIu64 "]",
p->pcap_cnt);
} else {
temp_buf_tail[0] = ']';
Expand Down Expand Up @@ -385,11 +387,11 @@ static int AlertSyslogLogger(ThreadVars *tv, void *thread_data, const Packet *p)
#endif /* !OS_WIN32 */

/** \brief Function to register the AlertSyslog module */
void AlertSyslogRegister (void)
void AlertSyslogRegister(void)
{
#ifndef OS_WIN32
OutputRegisterPacketModule(LOGGER_ALERT_SYSLOG, MODULE_NAME, "syslog",
AlertSyslogInitCtx, AlertSyslogLogger, AlertSyslogCondition,
AlertSyslogThreadInit, AlertSyslogThreadDeinit, NULL);
OutputRegisterPacketModule(LOGGER_ALERT_SYSLOG, MODULE_NAME, "syslog", AlertSyslogInitCtx,
AlertSyslogLogger, AlertSyslogCondition, AlertSyslogThreadInit, AlertSyslogThreadDeinit,
NULL);
#endif /* !OS_WIN32 */
}
1 change: 0 additions & 1 deletion src/alert-syslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@
void AlertSyslogRegister(void);

#endif /* __ALERT_SYSLOG_H__ */

Loading

0 comments on commit d1469db

Please sign in to comment.