Recently there’s been discussion on chan_sip going away in the future which led to many comparisons between it and chan_pjsip. What does chan_pjsip do better? What is chan_pjsip missing? What does chan_sip do better? What does chan_pjsip have that chan_sip doesn’t?
Enter dnsmgr for PJSIP
One thing chan_sip has that chan_pjsip was lacking is the ability to handle dynamic IP addresses. This functionality is present in chan_sip via the externhost and externrefresh configuration options in sip.conf. From the sample configuration file:
“externhost = hostname[:port]” is similar to “externaddr” except
that the hostname is looked up every “externrefresh” seconds
(default 10s). This can be useful when your NAT device lets you choose
the port mapping, but the IP address is dynamic.
externhost=foo.dyndns.net ; refreshed periodically
externrefresh=180 ; change the refresh interval
If your Asterisk system is behind a dynamic IP address, chan_sip could be configured appropriately to handle any change to the IP address. The IP address could be changed by something external which Asterisk then uses to update its public IP address every refresh interval. A dynamic hostname can be specified, which is used to keep everything up to date.
For awhile, chan_pjsip did not have this functionality implemented. However, support has been added for dnsmgr (DNS manager) that allowed it to tackle this problem. Here’s what the dnsmgr.conf file looks like:
;enable=yes ; enable creation of managed DNS lookups
; default is 'no'
;refreshinterval=1200 ; refresh managed DNS lookups every <n> seconds
; default is 300 (5 minutes)
In order to have your external address information automatically update you will need to enable dnsmgr and choose a refresh interval. The interval is how often dnsmgr will update the address information. While the default is 300 you can lower it if you want at the cost of more frequent DNS queries.
In pjsip.conf, you’ll need to set up a transport with the correct information. Here’s an example of a very basic configuration:
While full support for dnsmgr has not yet made it into a release it will be in the next set. As of this blog post that will be 13.19.0 and 15.2.0 so if you were holding off on building a PJSIP system due to a lack of support for dynamic IPs, check out those releases when they arrive and be prepared to give it a try!
For those that enjoy looking at the code more, here’s a link to the code review.