PJSIP Keepalive Only While Calls Are Present

Home » Asterisk Users » PJSIP Keepalive Only While Calls Are Present
Asterisk Users 4 Comments

Hi,

I see I can set qualify_frequency (for UDP) on an AOR to keep open holes through firewalls etc, and in [global] I can set keep_alive_interval for TCP based transports.

However, is it possible to configure it so that these OPTIONS
keepalives only get sent while there’s an active call to that endpoint?

The reason for this is that we have hundreds of potential endpoints depending on where customers define their call routing, but most of the time these endpoints won’t have any calls on them so we don’t want to send thousands of OPTIONS messages all about when there’s no need.

We definitely do need to do some sort of keepalive, because after some time, remote endpoints send messages back and they get blocked by the firewall if enough time has passed.

Is there a way to define some sort of keepalive in the Dial string or some other dynamic way of doing it?


Cheers, Kingsley.

4 thoughts on - PJSIP Keepalive Only While Calls Are Present

  • No. Session timers on the endpoint is the closest thing to making sure a call is active and keeping things open but does not use OPTIONS. Note that if you’re sending calls to them, then without OPTIONS outside of calls any NAT mapping would go away unless they re-register frequently. If they did re-register frequently then you likely wouldn’t need either.

  • Hi,

    the example I’m testing with is with sending a call to Twilio.

    SIP timers look perfect for this, except that after the first refresh, Twilio turns them off 🙁

    What I’m seeing is after a minute we send a re-invite with these headers:

    Session-Expires: 120;refresher=uac. Min-SE: 90.

    and the 200 OK coming back from Twilio omits them. Asterisk then doesn’t send any more.

    This is not very helpful of them. If the callee hangs up after a while, our system doesn’t notice because our firewall blocks the BYE. We can’t leave these servers open to the world so need somehow to find a way of keeping the firewall open for any calls we send out.

    Any idea how we might solve that?


    Cheers, Kingsley.

  • Allow traffic from specific IP addresses? Others may have better input or guidance on such a situation.

  • Hi,

    Thanks.

    That’s the problem. Customers have automated access to their setup and may at any point change the SIP destination of a number and then immediately make calls, so it’s not really practical to update the firewall to staticallly accept anything a customer might try to deliver to. This is why I was hoping for a more dynamic solution.

    One thought I had was to use ${CHANNEL(pjsip,remote_addr)} to get the actual remote IP address and then put it into an ipset that the firewall uses, either with a timeout or specifically removed when all calls to that IP address have ended. However,
    ${CHANNEL(pjsip,remote_addr)} doesn’t work on our systems here (though there are other PJSIP parameters that it DOES return).

    It’ll be interesting to see whether anyone else has any better ideas. If I could make Asterisk send a re-invite every few minutes, even if nothing has changed, that’d probably sort it.


    Cheers, Kingsley.