SIP ALG: what it is, why it breaks calls and how to test for it
A SIP ALG is a feature of a router or firewall that reads SIP call signalling as it passes and rewrites the addresses in it, to help phones behind NAT. In practice it often does harm: it rewrites some addresses and not others, or rewrites ones that were already right, and the result is one way audio, calls that drop, phones that unregister at random and registrations that fail. The usual fix is to switch the SIP ALG off, after proving that it is the cause.
What a SIP ALG does, and why it goes wrong
SIP messages carry addresses inside them: in the Via and Contact headers, and in the SDP that says where audio should be sent. NAT changes the addresses in the packet's own header and knows nothing about the ones inside the message, so a phone behind NAT can advertise an address that the other side cannot reach. An application layer gateway (ALG) is the router's attempt to fix that. It opens the message, replaces the private addresses with the router's public one, and opens a path for the audio.
That is the idea. These are the ways it goes wrong:
- It rewrites some addresses and not others. If it changes the Contact header but not the Record-Route, or the connection address in the SDP but not the origin line, the two ends disagree about where to send things.
- It rewrites addresses that were already right. A modern phone or phone system handles NAT itself, with rport, STUN or an outbound proxy. Two systems that both correct the same address can undo each other.
- It only reads what it expects. Some ALGs inspect only the standard SIP port, and none can read SIP over TLS, so the same call can behave differently on different ports and transports.
- It keeps its own record of each call, and gets it wrong. It tracks calls to open and close the path for audio, and a path that is closed early gives audio that stops and calls that drop.
- Its quality is the router's firmware's, which you can neither see nor fix.
Signs of a SIP ALG problem
- One way audio, especially on inbound calls.
- Calls that end after a steady 30 or 32 seconds (see calls drop after 30 seconds).
- Phones that register and then show as unregistered after a few minutes, or registrations that fail from one site only.
- A fault that follows the router: it is there from the office and gone from a phone's mobile hotspot.
- A fault that goes when SIP moves to another port, or to TLS.
How to prove it is the SIP ALG
- Test from a network that does not have your router in the way, such as a mobile hotspot. If the fault disappears, something on the original path is responsible.
- Capture the same call on both sides of the router and compare the Via, Contact and SDP lines, as the guide on one way audio describes. NAT changes the packet's own header and nothing else, so if the addresses inside the messages differ between the two captures, something between them is rewriting the messages.
- Switch the SIP ALG off (next section), restart the phones or the trunk registration, and test again. If the fault goes, you have your answer.
- Optionally, move SIP to another port or to TLS. If the fault goes, an ALG was acting on the standard port.
How to switch the SIP ALG off
The name varies. Look in the router's NAT, firewall, advanced or VoIP settings for SIP ALG, SIP helper, SIP passthrough, SIP inspection, VoIP ALG or application layer gateway, and switch it off. On a Linux router it is the connection tracking helper for SIP, the nf_conntrack_sip module. Some routers have no setting, and others hide it, so use the manufacturer's documentation for your model. A setting that looks off is not proof, so test as above.
After switching it off, restart the phones or the phone system's trunk registration, because a call or a mapping that already exists may still be handled the old way. Check the setting again after a firmware update or when the router is replaced, because a new device may arrive with it on.
If you cannot switch it off
- Use SIP over TLS, which an ALG cannot read, if the phone system and the carrier support it.
- Move SIP to another port, if the ALG acts only on the standard one. Test it first. It is a workaround and not a fix.
- Give the phone system a public address of its own, or put it in a network zone that the ALG does not inspect.
- Put a business firewall without a SIP ALG between the phones and the internet, in place of the router's own.
- Ask the internet provider whether the router they supplied can be put into bridge mode, so that your own firewall does the routing.
What to set up instead of a SIP ALG
A phone system that knows its public address, and phones that use symmetric RTP, rport (RFC 3581) or an outbound proxy, need no help from the router. Set the external address and the local networks on the phone system, keep the NAT keep-alive on for phones away from the office, and open the audio port range.
Questions people ask
Should SIP ALG be on or off?
For a business phone system that handles NAT itself, off, and then test. Leave it on only if switching it off breaks something that you cannot fix another way, and in that case change what does the router's job, because a feature that rewrites signalling is a risk to every call.
Can a SIP ALG cause one way audio on a SIP trunk?
Yes. The trunk's signalling passes through the router like any other SIP, so an ALG that rewrites the SDP wrongly sends audio to the wrong address and the trunk carries it in one direction only.
Does a SIP ALG affect SIP over TLS?
No, because it cannot read the messages. That is also why TLS works as a workaround.
In Wafflr
Wafflr is a phone system in development, and it has not launched, so this section describes its console as it is being built. It does not need a router's help with NAT. For a request from a phone behind NAT it records where the request really came from, in the Via header as received and rport (RFC 3581), because a handset's own Via names a private address that no response could reach. The system can also learn its own public address from a STUN server on a schedule; that is off unless a server is named. The Diagnostics page captures the SIP messages the system receives and sends when an administrator starts a capture, so you can set it beside a capture taken on the other side of the router and see whether anything between them changed an address. Wafflr's own troubleshooting guide tells you to turn SIP ALG off on the firewall.