From f91b64fcdfbaac9bb5be6b2db206e1fd03546fb7 Mon Sep 17 00:00:00 2001 From: Eric Green Date: Thu, 2 Aug 2018 12:30:05 -0400 Subject: [PATCH] Make recording more accurately report source address. Fixes #584 --- daemon/media_socket.c | 2 +- daemon/recording.c | 27 +++++++++++++++------------ include/recording.h | 3 ++- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/daemon/media_socket.c b/daemon/media_socket.c index ca132cea0..c7d548c3b 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1648,7 +1648,7 @@ static int stream_packet(struct packet_handler_ctx *phc) { // If recording pcap dumper is set, then we record the call. if (phc->mp.call->recording) - dump_packet(phc->mp.call->recording, phc->mp.stream, &phc->s); + dump_packet(&phc->mp, &phc->s); // ready to process diff --git a/daemon/recording.c b/daemon/recording.c index fb1dde91f..9a5b9746e 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -40,7 +40,7 @@ static char *meta_setup_file(struct recording *recording); static int pcap_create_spool_dir(const char *dirpath); static void pcap_init(struct call *); static void sdp_after_pcap(struct recording *, GString *str, struct call_monologue *, enum call_opmode opmode); -static void dump_packet_pcap(struct recording *recording, struct packet_stream *sink, const str *s); +static void dump_packet_pcap(struct media_packet *mp, const str *s); static void finish_pcap(struct call *); static void response_pcap(struct recording *, bencode_item_t *); @@ -50,7 +50,7 @@ static void sdp_before_proc(struct recording *, const str *, struct call_monolog static void sdp_after_proc(struct recording *, GString *str, struct call_monologue *, enum call_opmode opmode); static void meta_chunk_proc(struct recording *, const char *, const str *); static void finish_proc(struct call *); -static void dump_packet_proc(struct recording *recording, struct packet_stream *sink, const str *s); +static void dump_packet_proc(struct media_packet *mp, const str *s); static void init_stream_proc(struct packet_stream *); static void setup_stream_proc(struct packet_stream *); static void setup_media_proc(struct call_media *); @@ -490,9 +490,9 @@ static void pcap_recording_finish_file(struct recording *recording) { } // "out" must be at least inp->len + MAX_PACKET_HEADER_LEN bytes -static unsigned int fake_ip_header(unsigned char *out, struct packet_stream *stream, const str *inp) { - endpoint_t *src_endpoint = &stream->advertised_endpoint; - endpoint_t *dst_endpoint = &stream->selected_sfd->socket.local; +static unsigned int fake_ip_header(unsigned char *out, struct media_packet *mp, const str *inp) { + endpoint_t *src_endpoint = &mp->fsin; + endpoint_t *dst_endpoint = &mp->sfd->socket.local; unsigned int hdr_len = endpoint_packet_header(out, src_endpoint, dst_endpoint, inp->len); @@ -515,14 +515,15 @@ static void pcap_eth_header(unsigned char *pkt, struct packet_stream *stream) { * Write out a PCAP packet with payload string. * A fair amount extraneous of packet data is spoofed. */ -static void stream_pcap_dump(pcap_dumper_t *pdumper, struct packet_stream *stream, const str *s) { +static void stream_pcap_dump(struct media_packet *mp, const str *s) { + pcap_dumper_t *pdumper = mp->call->recording->u.pcap.recording_pdumper; if (!pdumper) return; unsigned char pkt[s->len + MAX_PACKET_HEADER_LEN + pcap_format->headerlen]; - unsigned int pkt_len = fake_ip_header(pkt + pcap_format->headerlen, stream, s) + pcap_format->headerlen; + unsigned int pkt_len = fake_ip_header(pkt + pcap_format->headerlen, mp, s) + pcap_format->headerlen; if (pcap_format->header) - pcap_format->header(pkt, stream); + pcap_format->header(pkt, mp->stream); // Set up PCAP packet header struct pcap_pkthdr header; @@ -536,9 +537,10 @@ static void stream_pcap_dump(pcap_dumper_t *pdumper, struct packet_stream *strea pcap_dump((unsigned char *)pdumper, &header, pkt); } -static void dump_packet_pcap(struct recording *recording, struct packet_stream *stream, const str *s) { +static void dump_packet_pcap(struct media_packet *mp, const str *s) { + struct recording *recording = mp->call->recording; mutex_lock(&recording->u.pcap.recording_lock); - stream_pcap_dump(recording->u.pcap.recording_pdumper, stream, s); + stream_pcap_dump(mp, s); recording->u.pcap.packet_num++; mutex_unlock(&recording->u.pcap.recording_lock); } @@ -752,7 +754,8 @@ static void setup_media_proc(struct call_media *media) { -static void dump_packet_proc(struct recording *recording, struct packet_stream *stream, const str *s) { +static void dump_packet_proc(struct media_packet *mp, const str *s) { + struct packet_stream *stream = mp->stream; if (stream->recording.u.proc.stream_idx == UNINIT_IDX) return; @@ -765,7 +768,7 @@ static void dump_packet_proc(struct recording *recording, struct packet_stream * //remsg->u.packet.call_idx = stream->call->recording->u.proc.call_idx; // unused remsg->u.packet.stream_idx = stream->recording.u.proc.stream_idx; - unsigned int pkt_len = fake_ip_header(remsg->data, stream, s); + unsigned int pkt_len = fake_ip_header(remsg->data, mp, s); pkt_len += sizeof(*remsg); int ret = write(kernel.fd, pkt, pkt_len); diff --git a/include/recording.h b/include/recording.h index 45db5f38c..5382139cb 100644 --- a/include/recording.h +++ b/include/recording.h @@ -18,6 +18,7 @@ struct packet_stream; +struct media_packet; struct call; enum call_opmode; struct rtpengine_target_info; @@ -71,7 +72,7 @@ struct recording_method { enum call_opmode); void (*meta_chunk)(struct recording *, const char *, const str *); - void (*dump_packet)(struct recording *, struct packet_stream *sink, const str *s); + void (*dump_packet)(struct media_packet *, const str *s); void (*finish)(struct call *); void (*response)(struct recording *, bencode_item_t *);