When PJSIP support was written for Asterisk we naturally needed the ability to display the SIP messages being sent and received. This took the form of the res_pjsip_logger module which hooks into the message sending and receiving path and logs the messages. The functionality was written to be familiar to users of chan_sip by allowing it to be toggled on and off and allowing a specific IP address or hostname to be specified. This has worked for some time but there is always room for improvement. As of Asterisk 13.34.0, 16.11.0, and 17.5.0 some new functionality is available alongside this!
Multiple IPs and Subnet Support
The “pjsip set logger host” CLI command now supports specifying a subnet mask, for example:
pjsip set logger host 172.16.1.0/255.255.255.0
As well you can now place “add” at the end to have it be an additional host or subnet to log for:
pjsip set logger host 172.16.1.0/255.255.255.0 add
Console Disabling Support
In some cases you may not want PJSIP logging to go to the console. There is now a CLI command to toggle this on and off:
pjsip set logger verbose off
PCAP Output Support
Finally a really handy option is the ability to output messages in a pcap file, so you can later filter and view in such tools as Wireshark:
pjsip set logger pcap /tmp/packets.cap
Packets are placed into the pcap as UDP packets in all cases and they are unencrypted. This even applies if you are using, for example, SIP over Websockets with TLS.
Adding these changes also provided the foundation for potential future improvements. These could be the ability to have multiple independent logging sessions going on or the ability to also include RTP packets in the pcap file as well. Stay tuned in case these or other things are added!