I have an Asterisk installation that has direct internet connectivity (no NAT). I have a bunch of external devices (mostly FritzBoxes) behind remote NAT. They register with my Asterisk installation using the UDP transport. Everything works great with this configuration.
Then I decided to convert one of the endpoints to TLS, so that they register with my Asterisk using TLS. Incoming calls from the remote endpoint continues to work. BUT: Outgoing calls to the endpoint converted to TLS don’t work any more. In pjsip show contacts, it shows up like this:
CLI> pjsip show contacts
Contact: <Aor/ContactUri..............................> <Hash....> <Status> <RTT(ms)..>
==========================================================================================
Contact: 4711/sip:4711@<remote_nat_gw_public_ip>:49746;transp 3ba68171a7 NonQual nan
Of course, the phone is not reachable on the given port, because there is no port forwarding from the remote NAT gateway to the remote phone behind that NAT gateway.
What I need is to say to PJSIP is:
“Keep the incoming SIP-TLS connection (established from the remote endpont behind NAT) open and send INVITEs over that already established incoming connection.”
But although searching a lot, I haven’t found a way to describe that in PJSIP’s terms.
What I have already tried:
Setting qualify_frequency for the endpoint’s AOR like it was set before, but as I read, that’s only for connectionless transports (UDP), so I removed it again.
Setting keep_alive_interval=25 in PJSIP’s global section
Setting tcp_keepalive_enable=yes and tcp_keepalive_idle_time=15 in my TLS transport
I’m not sure whether any of this can help solving my problem, but at least I’ve tried it.
I then converted a second endpoint (softphone; Linphone on Android) which is also behind a remote NAT gateway and had the same problem.
If anybody of you has an idea how to solve my problem, I’d appreciate any help!
This is incorrect. It will send OPTIONS requests over any connection and keep it alive. If that’s not working, then that may not be the problem and you’d need to provide actual logs of the issue.
@jcolp , first I would like to thank you for your reply. I’m an Asterisk user since 2006, and when running into problems and googling for the solution, your answers to existing threads have often helped me over the years. After nearly 20 years, this is now the first time googling for my Asterisk problem is not sufficient and I need to ask for support here.
I re-added qualify_frequency=15 to the AOR. I know that 15 seconds is quite a low value, but it’s just for testing. Status has changed from NonQual to Unavail.
CLI> pjsip show contacts
Contact: <Aor/ContactUri..............................> <Hash....> <Status> <RTT(ms)..>
==========================================================================================
Contact: 4711/sip:4711@<remote_nat_gw_public_ip>:46250;transpo bf89d1570d Unavail nan
Firstly transmitting OPTIONS isn’t the result of making an outgoing call. (Also, if the lack of an OPTIONS response is the only problem, you can disable qualify.)
Secondly, this looks as though it is trying the reciprocal path, although it is probably using a new local port number, so it might not be recognized as the same transport connection, but that isn’t something that would be visible in the Asterisk logging, you would need to get TCP level logging.
I’m not sure to what extent it is actually SIP compliant to do what you want to do, even if the other side sends the correct Contact header, which I assume it doesn’t. I don’t actually remember anything in the RFCs that allows connection reuse. A quick skim of RFC 3261 seems to say that the REGISTER connection can only be reused for responses and for requests from the same source as the REGISTER, so implicilty doesn’t support re-use in the reverse direction.
On the other hand, I’m not certain that Asterisk doesn’t use heuristics to reuse connections even when the RFCs say you shouldn’t, so I’d also ask what you have done to confirm that the phone didn’t drop the connection immediately after getting the REGISTER response.
PJSIP Transport Selection - Asterisk Documentation seems to say that a connection will be reused, as long as the address and port of the remote end are correct, which they should be, given you have rewrite-contact.
Then I enabled qualify_frequency and see that the connection is not reused, but a new connection is trying to be established, which of course will not go through:
I wondered about that, but the documentation, whilst first saying transport must not be explicit, then has some text in a box that seems to contradict that.
Wow, many thanks for this hint, @jcolp! I would never have found that out by myself. qualify_frequency works now and I can call the remote device behind NAT.