Sending Messages
SIP Request Handling
1. URI Parsing
The PJSIP stack fundamentally acts on URIs. When sending to a URI it is parsed into the various parts (user, host, port, user parameters). For the purposes of transport selection the transport parameter is examined. This specifies the type of transport. If this parameter is not present it is assumed to be UDP. This is important because it is used in DNS resolution. If a "sips" URI scheme is used an automatic switchover to TLS will occur.
2. DNS SRV Resolution (If host portion is not an IP address)
3a. Transport Selection (No explicit transport provided)
Now that the underlying type of transport is known and the resolved target exists the transport selection process can begin.
Connection-less protocols (such as UDP)
A transport, decided upon by a hashing mechanism, matching the transport type and address family is selected.
Connection-oriented protocols (such as TCP or TLS)
An already open connection to the resolved IP address and port is searched for. If the connection exists it is reused for the request. If no connection exists the first transport matching the transport type and address family as configured in pjsip.conf is chosen. It is instructed to establish a new connection to the resolved IP address and port.
3b. Transport Selection (Explicit transport provided)
Connection-less protocols (such as UDP)
The provided transport is used.
Connection-oriented protocols (such as TCP or TLS)
The provided transport is instructed to establish a new connection to the resolved IP address and port.
4. Multihomed Transport Selection (Connection-less protocols)
Local source interface IP address matches source IP address in message
Local source interface IP address differs from source IP address in message
5. Message is sent
The message is provided to the transport and it is instructed to send it.
SIP Response Handling
1. Transport Selection
Connection-oriented protocols (such as TCP or TLS)
If no connection exists or the connection is no longer open the first configured transport in pjsip.conf matching the transport type and address family is selected. It is instructed to establish a new connection to the destination IP address and port.
Connection-less protocol with maddr in URI of the topmost Via header
Connection-less protocol with rport in URI of the topmost Via header
Connection-less protocol without rport in URI of the topmost Via header
2. Message is sent
Best Configuration Strategies
IPv4 Only (Single Interface)
Configure a wildcard transport. This is simple as it requires no special configuration such as knowing the IP address and has no downsides.
This example includes an endpoint without a transport explicitly defined. Since there is only one transport configured this will always be used. For requests to this endpoint the logic in section 3a will be used.
IPv4 Only (Multiple Interfaces)
This example includes two endpoints which are each present on different networks. To ensure that outgoing requests to each endpoint travel over the correct transport the transport has been explicitly specified on each. For requests to these endpoints the logic in section 3b will be used.
IPv6 Only (Single Interface)
Configure a transport with the IPv6 address:
IPv4+IPv6 Combined (Single Interface)
Configure two transports, one with the IPv4 address and one with the IPv6 address.
Common Issues
Changeover to TCP when sending via UDP
Sending using a transport that is not available