FortiGate
FortiGate Next Generation Firewall utilizes purpose-built security processors and threat intelligence security services from FortiGuard labs to deliver top-rated protection and high performance, including encrypted traffic.
nprakash
Staff
Staff
Article Id 199783
This article describes how STUN protocol works to resolve the SIP Nat issues

Session helper / SIP ALG translates the SIP and SDP parameters when the packet is sent to the SIP provider.  Fortigate will also open pinholes dynamically based on the “c=” and “m=” attributes in the SDP packet. Some SIP providers recommend disabling session helper or ALG. In this case, how can the SIP NAT issues be resolved?

 

STUN can be used to resolve this issue. First, let us understand what is STUN protocol.  Session Traversal Utilities for NAT, provides a tool for dealing with NATs.  It provides a means for an endpoint to determine the IP address and port allocated by a NAT that corresponds to its private IP address and port.  It also provides a way for an endpoint to keep a NAT binding alive.

 

STUN is a client-server protocol.  It supports two types of transactions.  One is a request/response transaction in which a client sends a request to a server, and the server returns a response.

 

Topology:

 

nprakash_0-1637969337940.png

 

 

 

In this topology, Client-1 (soft client) is registered to PBX hosted in cloud. Client-1 is trying to call Client-2 on its extension (in a real world this would actual phone number).

 

Some SIP providers recommend disabling SIP session helper or SIP ALG. In this case, the provider will suggest an alternate solution to address the NAT issue.  STUN is one of the solution to address this issue.

 

How STUN works?

 

STUN server sits somewhere in public internet, waits for incoming requests, examines packet source IP and port, packs this information as STUN response, and replies to the request with the information it discovered. This way client behind NAT are able to find out about their public ip address/port pair and use that when they need to pass this to remote peer in order to receive audio on that IP/port pair.

 

 

Soft phone on client-1 is brought up , and we can see the STUN messages/response and SIP register / 200 OK.

Bind request from 192.168.250.100 to 10.10.104.4 is nat’d and sent out via wan.

 

LAN PCAP (Bind request)

  nprakash_1-1637969473848.png

 

WAN PCAP (Bind request)

 

nprakash_2-1637969512077.png

 

 

Below are the BIND response from STUN server:

WAN PCAP (Bind Response)

 

nprakash_3-1637969538890.png

 

 

STUN Server is telling the client that it got the bind request from IP “10.10.101.2” and port “56343”.

 

FortiGate will perform session lookup and will do the DNAT to 192.168.250.100.

 

LAN PCAP (Bind Response)

 

 

nprakash_4-1637969568645.png

 

  

With this information, Client-1 can craft the SIP Signaling messages.  Client-1 sends SIP Register message to the PBX server.  If the authentication is successful, PBX server will return with SIP 200 OK message.

 

LAN PCAP (SIP Register)

  

nprakash_5-1637969631731.png

 

In the LAN PCAP, we can see that the SIP headers has the wan interface IP address. If STUN was not used and session helper/ALG was disabled then the same PCAP on the LAN side would have the client’s IP address in the SIP headers.

 

FortiGate will create a new session for this flow and will route to packet to the PBX.

 

WAN PCAP (SIP Register)

 

nprakash_6-1637969684501.png

  

Shown below are the response from the PBX server.

  

WAN PCAP (200 OK)

 

 

nprakash_7-1637969717261.png

 

 

Session lookup is performed and the traffic is sent to the client.

 

LAN PCAP (200 OK)

 

nprakash_8-1637969756269.png

 

Logging into the PBX to make sure, if it has learnt the correct IP addresses of the softphones.

 

nprakash_9-1637969772656.png

 

Now let us make call from Client-2 to Client-1 and review the SIP and RTP packet flows.

 

Show below are the packet exchanges between Client-1 and PBX when Client-2 is initiating the call.

 

WAN PCAP (SIP Invite)

 

nprakash_10-1637969805226.png

 

 

PBX is sending the SIP invite message to Client-1(connected behind the Firewall).  In the PCAP, PBX wants Client-1 to send audio traffic on IP address 10.10.101.7 and on port 12022.

 

Fortigate will find existing session as the IP-tuple is the same as seen in the SIP register message. After the session lookup, traffic will be forwarded to Client-1,

 

nprakash_11-1637969839764.png

 

Client-1 sends Bind request again:

LAN PCAP (Bind request)

 

nprakash_12-1637969874413.png

 

 WAN PCAP (Bind Request)

 nprakash_13-1637969892722.png

 

STUN server responds with mapped IP address 10.10.101.2 and port 64416.

 

WAN PCAP (Bind response)

 

nprakash_14-1637969921651.png

 

 

Response is sent to the client,

 

nprakash_15-1637969939789.png

Now Client-1 constructs SIP 200 OK packet based on the STUN response

LAN PCAP (SIP 200 OK)

 

nprakash_16-1637969962589.png

 

 

Again, without STUN or session helper/ALG , in this pcap client would have added its own IP address and port for the SDP parameters.

 

FortiGate forwards the SIP 200 OK to the PBX,

 

WAN PCAP ( SIP 200 OK )

  

nprakash_17-1637969992184.png

 

 

Based on the SIP signaling messages,

 

Audio Traffic to PBX should be sent to 10.10.101.7 and on port 12022 and Audio Traffic for Client should be sent to 10.10.101.2 and port 64416

 

Now let’s confirm if the Audio traffic is sent and received based as seen on the signaling messages.

 

LAN (RTP – from client to PBX)

 

nprakash_18-1637970021877.png

  

WAN (RTP- from client to PBX)

 

nprakash_19-1637970040855.png

  

WAN ( RTP from PBX to Client-1)

  

nprakash_20-1637970068796.png

  

LAN ( RTP from PBX to Client-1)

 

nprakash_21-1637970087629.png

 

No audio issues observed. There are no helper/ ALG in this case.  Therefore, no expectation session will be created.

  

Extras:

Firewall Configuration:

 

nprakash_22-1637970135879.png

 

 

  •  “permit-stun-host”, Fortigate will open pinhole if request is valid stun. However, fgt may not be able to know all stun request format, so permit-any-host was added. These commands was added  for facetime or other p2p protocol only.   
  • Please check with the SIP provider for recommendation on setting the UDP idle timer. upd-idle timer can be changed by fgt global setting, or in the policy.
  • If there are any audio issues then it would be best to collect,
    • Run sniffer on both end pc (softphone). Please running sniffer from register message.
    • dump sessions (every 15 seconds)
    • monitor cpu/memory usage (every 15 seconds)
      • get sys status
      • get sys per stat
      • diagnose  hard sys cpu
      • diagnose hard sys mem
      • diagnose sys session full
    • Detailed network topology, including sip traffic flow (register, call etc).
Contributors