From 0edfb2dfcc8e6fa289177d93599e599ae1e7f0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gh?= Date: Wed, 16 Nov 2016 10:19:02 +0100 Subject: [PATCH] Make pcap file format an option Valid options are raw and eth. Default is raw as it was before last commit. fixes #290 --- daemon/main.c | 4 +++- daemon/recording.c | 34 ++++++++++++++++++++++++++-------- daemon/recording.h | 2 +- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/daemon/main.c b/daemon/main.c index a4b95c599..8d1f6a79c 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -88,6 +88,7 @@ static int delete_delay = 30; static int graphite_interval = 0; static char *spooldir; static char *rec_method = "pcap"; +static char *rec_format = "raw"; static void sighandler(gpointer x) { sigset_t ss; @@ -329,6 +330,7 @@ static void options(int *argc, char ***argv) { { "homer-id", 0, 0, G_OPTION_ARG_STRING, &homer_id, "'Capture ID' to use within the HEP protocol", "INT" }, { "recording-dir", 0, 0, G_OPTION_ARG_STRING, &spooldir, "Directory for storing pcap and metadata files", "FILE" }, { "recording-method",0, 0, G_OPTION_ARG_STRING, &rec_method, "Strategy for call recording", "pcap|proc" }, + { "recording-format",0, 0, G_OPTION_ARG_STRING, &rec_format, "File format for stored pcap files", "raw|eth" }, { NULL, } }; @@ -529,7 +531,7 @@ static void init_everything() { struct timespec ts; log_init(); - recording_fs_init(spooldir, rec_method); + recording_fs_init(spooldir, rec_method, rec_format); clock_gettime(CLOCK_REALTIME, &ts); srandom(ts.tv_sec ^ ts.tv_nsec); SSL_library_init(); diff --git a/daemon/recording.c b/daemon/recording.c index 40672018c..7a6f6a026 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -82,7 +82,7 @@ static const struct recording_method methods[] = { static char *spooldir = NULL; const struct recording_method *selected_recording_method; - +int rec_format; @@ -90,7 +90,7 @@ const struct recording_method *selected_recording_method; * Initialize RTP Engine filesystem settings and structure. * Check for or create the RTP Engine spool directory. */ -void recording_fs_init(const char *spoolpath, const char *method_str) { +void recording_fs_init(const char *spoolpath, const char *method_str, const char *format_str) { int i; // Whether or not to fail if the spool directory does not exist. @@ -108,6 +108,15 @@ void recording_fs_init(const char *spoolpath, const char *method_str) { return; found: + if(!strcmp("raw", format_str)) + rec_format = 0; + else if(!strcmp("eth", format_str)) + rec_format = 1; + else { + ilog(LOG_ERR, "Invalid value for recording format \"%s\".", format_str); + exit(-1); + } + spooldir = strdup(spoolpath); int path_len = strlen(spooldir); @@ -399,7 +408,10 @@ static char *recording_setup_file(struct recording *recording) { recording_path = file_path_str(recording->meta_prefix, "/pcaps/", ".pcap"); recording->pcap.recording_path = recording_path; - recording->pcap.recording_pd = pcap_open_dead(DLT_EN10MB, 65535); + if(rec_format == 1) + recording->pcap.recording_pd = pcap_open_dead(DLT_EN10MB, 65535); + else + recording->pcap.recording_pd = pcap_open_dead(DLT_RAW, 65535); recording->pcap.recording_pdumper = pcap_dump_open(recording->pcap.recording_pd, recording_path); if (recording->pcap.recording_pdumper == NULL) { pcap_close(recording->pcap.recording_pd); @@ -450,11 +462,17 @@ static void stream_pcap_dump(pcap_dumper_t *pdumper, struct packet_stream *strea if (!pdumper) return; - unsigned char pkt[s->len + MAX_PACKET_HEADER_LEN + 14]; - unsigned int pkt_len = fake_ip_header(pkt + 14, stream, s); - pkt_len += 14; - memset(pkt, 0, 14); - pkt[12] = 0x08; + int ether_len = 0; + if(rec_format == 1) + ether_len = 14; + + unsigned char pkt[s->len + MAX_PACKET_HEADER_LEN + ether_len]; + unsigned int pkt_len = fake_ip_header(pkt + ether_len, stream, s); + if(rec_format == 1) { + pkt_len += 14; + memset(pkt, 0, 14); + pkt[12] = 0x08; + } // Set up PCAP packet header struct pcap_pkthdr header; diff --git a/daemon/recording.h b/daemon/recording.h index fdd6b588d..d577a772e 100644 --- a/daemon/recording.h +++ b/daemon/recording.h @@ -100,7 +100,7 @@ extern const struct recording_method *selected_recording_method; * Initialize RTP Engine filesystem settings and structure. * Check for or create the RTP Engine spool directory. */ -void recording_fs_init(const char *spooldir, const char *method); +void recording_fs_init(const char *spooldir, const char *method, const char *format); /**