Connectionless Keep-Alives

After the endpoint-initiated Keep-Alive exchange has been negotiated for an unreliable UDP connection, the SIP endpoint, acting as a STUN client, transmits a periodic STUN binding request so that the interval between each request is randomly distributed between 80 and 100 percent of the value of the keep parameter. Assuming a parameter value of 20 seconds, for example, the SIP endpoint transmits a STUN binding request at random intervals between 16 and 20 seconds in length.

The STUN binding request has the following format.

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0 0|     STUN Message Type     |         Message Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Magic Cookie                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                     Transaction ID (96 bits)                  |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

The initial two bits of any STUN message are always 00

STUN Message Type

This 14-bit field contains the message class and method — for a STUN binding request, class is request and method is binding.

Message Length

This 16-bit field contains the length, in octets, of the Attribute section of the STUN binding request. Since the Attribute section is not present in a binding request, this field contains a value of 0.

Magic Cookie

This 16-bit field always contains a value of 0x2112A442.

Transaction ID

This 96-bit field contains a random value that provides a transaction identifier. The value is generated by the STUN client and echoed in the STUN server response.

Upon receipt of a binding request, the SD, acting as a STUN server, transmits a STUN binding response. Receipt of the binding response by the endpoint confirms the UDP connection between the endpoint and the SD, and the viability of NAT bindings in the transmission path.

The STUN binding response has the following format.

0                   1                   2                   3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0 0|     STUN Message Type     |         Message Length        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                         Magic Cookie                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                     Transaction ID (96 bits)                  |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                         Mapped Address                        |
|                                                               |
|---------------------------------------------------------------

The initial two bits of any STUN message are always 00.

STUN Message Type

This 14-bit field contains the message class and method — for a STUN binding response, class is response and method is binding.

Message Length

This 16-bit field contains the length, in octets, of the Attribute section of the STUN binding response. Since the binding response contains a single attribute, MAPPED-ADDRESS, the message length can be either 8 or 16 octets, depending on the IP address type.

Magic Cookie

This 16-bit field always contains a value of 0x2112A442.

Transaction ID

This 96-bit field contains a random value that provides a transaction identifier. The value is generated by the STUN client and echoed by the STUN server.

MAPPED-ADDRESS

This attribute contains the IP address and port number of the proximate NAT device, that is the address translator closest to the SD, that forwarded the STUN request toward the SD. Specific fields within the attribute identify the IP family (Version 4 or 6), the IP address, and port number. The attribute length is 8 octets if it contains an IPv4 address, or 16 octets if it contains an IPv6 address.

Once initiated, endpoint transmission of STUN binding requests and SD responses continue for the duration of the SIP Registration, 1 hour in the sample negotiation, or until the endpoint transmits a new REGISTER request. In the event of such a new request, the endpoint once again indicates its willingness to exchange STUN Keep-Alives with an unvalued keep parameter in the Via header. If endpoint-initiated Keep-Alive renegotiation is not successful, the endpoint must cease the transmission of Keep-Alive messages.

An endpoint failure to issue a timely STUN binding request is not fatal. In the absence of an expected request, the SD takes no action with regard to the UDP connection, or to current calls, nor does it remove entries from its registration cache. After reception of a tardy STUN request, the SD simply returns a STUN response.

In contrast, however, Section 4.4.2 of RFC 5626 states that an endpoint “considers the flow failed” if (1) it receives a malformed STUN bonding response from the SD, or (2) it fails to receive a timely binding response from the SD. If the endpoint receives a STUN binding response that contains a different MAP Address field from the previous response, It MUST treat this event as a failure on the flow.