From abd953812f1a009c4309bdf74112e62649850d0f Mon Sep 17 00:00:00 2001 From: Dylan Mikus Date: Mon, 8 Feb 2016 18:24:50 -0500 Subject: [PATCH] Fixes to match PCAP packets with SDP We want to be able to match up the source and target : with the IP and port info sent in SDP. I adjusted the source and target : we write to the IP and UDP headers in the PCAP file. I added the offer SDP (in addition to the already written answer SDP) to the metadata file. As a consequence of writing out the offer SDP, we will have empty PCAP files and associated metadata files for calls that are never answered. squash! Fixes to match PCAP packets with SDP Added comments detailing the types of endpoint IP/port values we can use. --- daemon/call_interfaces.c | 4 ++-- daemon/media_socket.c | 20 ++++++++++++++++++++ daemon/recording.c | 6 +++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index efd8cd402..206e9b15d 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -712,7 +712,7 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster bencode_buffer_destroy_add(output->buffer, (free_func_t) sdp_chopper_destroy, chopper); bencode_dictionary_get_str(input, "record-call", &recordcall); - if (opmode == OP_ANSWER && recordcall.s) { + if (recordcall.s) { detect_setup_recording(call, recordcall); } @@ -741,7 +741,7 @@ static const char *call_offer_answer_ng(bencode_item_t *input, struct callmaster bencode_dictionary_add_string(output, "result", "ok"); struct recording *recording = call->recording; - if (opmode == OP_ANSWER && call->record_call && recording != NULL && recording->meta_fp != NULL) { + if (call->record_call && recording != NULL && recording->meta_fp != NULL) { struct iovec *iov = &g_array_index(chopper->iov, struct iovec, 0); int iovcnt = chopper->iov_num; meta_write_sdp(recording->meta_fp, iov, iovcnt); diff --git a/daemon/media_socket.c b/daemon/media_socket.c index baab02145..dba3aa354 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1018,6 +1018,26 @@ noop: /* XXX split this function into pieces */ /* called lock-free */ static int stream_packet(struct stream_fd *sfd, str *s, const endpoint_t *fsin, const struct timeval *tv) { +/** + * Incoming packets: + * - sfd->socket.local: the local IP/port on which the packet arrived + * - sfd->stream->endpoint: adjusted/learned IP/port from where the packet + * was sent + * - sfd->stream->advertised_endpoint: the unadjusted IP/port from where the + * packet was sent. These are the values present in the SDP + * + * Outgoing packets: + * - sfd->stream->rtp_sink->endpoint: the destination IP/port + * - sfd->stream->selected_sfd->socket.local: the local source IP/port for the + * outgoing packet + * + * If the rtpengine runs behind a NAT and local addresses are configured with + * different advertised endpoints, the SDP would not contain the address from + * `...->socket.local`, but rather from `sfd->local_intf->spec->address.advertised` + * (of type `sockaddr_t`). The port will be the same. + */ +/* TODO move the above comments to the data structure definitions, if the above + * always holds true */ struct packet_stream *stream, *sink = NULL, *in_srtp, *out_srtp; diff --git a/daemon/recording.c b/daemon/recording.c index bcf26b801..f68ff7375 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -337,9 +337,9 @@ void recording_finish_file(struct recording *recording) { * Write out a PCAP packet with payload string. * A fair amount extraneous of packet data is spoofed. */ -void stream_pcap_dump(pcap_dumper_t *pdumper, struct packet_stream *sink, str *s) { - endpoint_t src_endpoint = sink->advertised_endpoint; - endpoint_t dst_endpoint = sink->endpoint; +void stream_pcap_dump(pcap_dumper_t *pdumper, struct packet_stream *stream, str *s) { + endpoint_t src_endpoint = stream->advertised_endpoint; + endpoint_t dst_endpoint = stream->selected_sfd->socket.local; // Wrap RTP in fake UDP packet header // Right now, we spoof it all