From 4c277bb938854a6a174e8bfece0bc9a7928da1ab Mon Sep 17 00:00:00 2001 From: Lally Singh Date: Fri, 8 May 2015 14:39:04 -0400 Subject: [PATCH] Add basic SCTP packet logging. Attempts to get wireshark to decode the DTLS were problematic (wireshark only does it for certain versions of some DTLS implementations), so just do what firefox does and dump a txt2pcap-compatible log when requested. R=pthatcher@webrtc.org Review URL: https://webrtc-codereview.appspot.com/49159004 Cr-Commit-Position: refs/heads/master@{#9162} --- talk/media/sctp/sctpdataengine.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/talk/media/sctp/sctpdataengine.cc b/talk/media/sctp/sctpdataengine.cc index 136edab840..8c8a6a192f 100644 --- a/talk/media/sctp/sctpdataengine.cc +++ b/talk/media/sctp/sctpdataengine.cc @@ -176,6 +176,18 @@ static bool GetDataMediaType( } } +// Log the packet in text2pcap format, if log level is at LS_VERBOSE. +static void VerboseLogPacket(void *addr, size_t length, int direction) { + if (LOG_CHECK_LEVEL(LS_VERBOSE) && length > 0) { + char *dump_buf; + if ((dump_buf = usrsctp_dumppacket( + addr, length, direction)) != NULL) { + LOG(LS_VERBOSE) << dump_buf; + usrsctp_freedumpbuffer(dump_buf); + } + } +} + // This is the callback usrsctp uses when there's data to send on the network // that has been wrapped appropriatly for the SCTP protocol. static int OnSctpOutboundPacket(void* addr, void* data, size_t length, @@ -185,6 +197,8 @@ static int OnSctpOutboundPacket(void* addr, void* data, size_t length, << "addr: " << addr << "; length: " << length << "; tos: " << std::hex << static_cast(tos) << "; set_df: " << std::hex << static_cast(set_df); + + VerboseLogPacket(addr, length, SCTP_DUMP_OUTBOUND); // Note: We have to copy the data; the caller will delete it. auto* msg = new OutboundPacketMessage( new rtc::Buffer(reinterpret_cast(data), length)); @@ -594,6 +608,8 @@ void SctpDataMediaChannel::OnPacketReceived( // Pass received packet to SCTP stack. Once processed by usrsctp, the data // will be will be given to the global OnSctpInboundData, and then, // marshalled by a Post and handled with OnMessage. + + VerboseLogPacket(packet->data(), packet->size(), SCTP_DUMP_INBOUND); usrsctp_conninput(this, packet->data(), packet->size(), 0); } else { // TODO(ldixon): Consider caching the packet for very slightly better