eve: log pcap filename

pull/3281/head
Victor Julien 7 years ago
parent 19988310d1
commit 50a182194a

@ -47,6 +47,29 @@ The common part has a field "event_type" to indicate the log type.
"event_type":"TYPE"
PCAP fields
~~~~~~~~~~~
If Suricata is processing a pcap file, additional fields are added:
::
"pcap_cnt": 123
``pcap_cnt`` contains the packet number in the pcap. This can be used to look
up a packet in Wireshark for example.
::
"pcap_filename":"/path/to/file.pcap"
``pcap_filename`` contains the file name and location of the pcap that
generated the event.
.. note:: the pcap fields are only available on "real" packets, and are
omitted from internal "pseudo" packets such as flow timeout
packets.
Event type: Alert
-----------------

@ -63,6 +63,8 @@
#include "flow-var.h"
#include "flow-bit.h"
#include "source-pcap-file.h"
#ifndef HAVE_LIBJANSSON
/** Handle the case where no JSON support is compiled in.
@ -601,6 +603,10 @@ int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer)
json_string(file_ctx->sensor_name));
}
if (file_ctx->is_pcap_offline) {
json_object_set_new(js, "pcap_filename", json_string(PcapFileGetFilename()));
}
if (file_ctx->prefix) {
MemBufferWriteRaw((*buffer), file_ctx->prefix, file_ctx->prefix_len);
}
@ -805,9 +811,16 @@ OutputInitResult OutputJsonInitCtx(ConfNode *conf)
json_ctx->include_metadata = true;
}
const char *pcapfile_s = ConfNodeLookupChildValue(conf, "pcap-file");
if (pcapfile_s != NULL && ConfValIsTrue(pcapfile_s)) {
json_ctx->file_ctx->is_pcap_offline =
(RunmodeGetCurrent() == RUNMODE_PCAP_FILE);
}
json_ctx->file_ctx->type = json_ctx->json_out;
}
SCLogDebug("returning output_ctx %p", output_ctx);
result.ctx = output_ctx;

@ -26,6 +26,7 @@
#include "source-pcap-file-directory-helper.h"
#include "runmode-unix-socket.h"
#include "util-mem.h"
#include "source-pcap-file.h"
static void GetTime(struct timespec *tm);
static void CopyTime(struct timespec *from, struct timespec *to);

@ -26,6 +26,7 @@
#include "source-pcap-file-helper.h"
#include "util-checksum.h"
#include "util-profiling.h"
#include "source-pcap-file.h"
extern int max_pending_packets;
extern PcapFileGlobalVars pcap_g;
@ -98,6 +99,13 @@ void PcapFileCallbackLoop(char *user, struct pcap_pkthdr *h, u_char *pkt)
SCReturn;
}
char pcap_filename[PATH_MAX] = "unknown";
const char *PcapFileGetFilename(void)
{
return pcap_filename;
}
/**
* \brief Main PCAP file reading Loop function
*/
@ -108,6 +116,7 @@ TmEcode PcapFileDispatch(PcapFileFileVars *ptv)
int packet_q_len = 64;
int r;
TmEcode loop_result = TM_ECODE_OK;
strlcpy(pcap_filename, ptv->filename, sizeof(pcap_filename));
while (loop_result == TM_ECODE_OK) {
if (suricata_ctl_flags & SURICATA_STOP) {

@ -30,6 +30,7 @@ void TmModuleDecodePcapFileRegister (void);
void PcapIncreaseInvalidChecksum(void);
void PcapFileGlobalInit(void);
const char *PcapFileGetFilename(void);
#endif /* __SOURCE_PCAP_FILE_H__ */

@ -125,6 +125,9 @@ typedef struct LogFileCtx_ {
/* Set to true if the filename should not be timestamped. */
bool nostamp;
/* if set to true EVE will add a pcap file record */
bool is_pcap_offline;
/* Socket types may need to drop events to keep from blocking
* Suricata. */
uint64_t dropped;

Loading…
Cancel
Save