RFC 2543

SIP: Session Initiation Protocol

๐Ÿ“… published March 1999, from ietf

RFC 2543: SIP, Session Initiation Protocol ๐ŸŽ€

Okay bestie, this is RFC 2543, the doc that introduced SIP: Session Initiation Protocol โœจ It's dated March 1999 and it's a Standards Track document in the Network Working Group.

The authors are M. Handley (ACIRI), H. Schulzrinne (Columbia U.), E. Schooler (Cal Tech), and J. Rosenberg (Bell Labs). That's a whole squad ๐Ÿ‘‘ The header doesn't have any Obsoletes or Updates line, so this RFC isn't replacing or amending anything listed there ๐Ÿซถ


Status of this Memo ๐Ÿฆ‹

Here's the vibe: this document specifies an Internet standards track protocol for the Internet community, and it's asking for discussion and suggestions for improvements ๐Ÿ’ฌ For the official standardization state and status, check the current edition of the "Internet Official Protocol Standards" (STD 1). Also, distribution of this memo is unlimited, so share it with everyone ๐Ÿ’…

The legal bit, verbatim: Copyright (C) The Internet Society (1999). All Rights Reserved.

IESG Note ๐Ÿ™ˆ

Okay, so the IESG is planning to charter one or more working groups soon ๐Ÿ‘€ Their job would be to make standards for "name lookup." That means looking up things like email addresses and phone numbers, and the result would be a list of attributes and characteristics of the user or terminal tied to that name.

If your group needs a "name lookup" protocol, the IESG says you should follow those new working groups instead of using SIP for this ๐Ÿ™…โ€โ™€๏ธ They also expect SIP to move toward using those protocols eventually, so SIP implementors are advised to keep an eye on those efforts ๐Ÿ”

Abstract ๐Ÿ’œ

Let's get into it. SIP is an application-layer control (signaling) protocol ๐Ÿงš It's for creating, modifying, and terminating sessions with one or more participants. Those sessions can be Internet multimedia conferences, Internet telephone calls, or multimedia distribution ๐ŸŽถ Members of a session can talk over multicast, over a mesh of unicast relations, or over a mix of both ๐ŸŒˆ

SIP invitations that set up sessions carry session descriptions, which let participants agree on a set of compatible media types ๐Ÿ“ It also supports user mobility by proxying and redirecting requests to the user's current location, and users can register where they currently are ๐Ÿ“ SIP isn't tied to any particular conference control protocol โœจ It's designed to work independently of the lower-layer transport protocol, and it can be extended with additional capabilities ๐Ÿฆ„


Table of Contents ๐Ÿ“š

The table of contents is coming up next, so stay tuned, because there's a lot more to come! ๐Ÿ’–

I can't write part 2 yet because I only have the table of contents for RFC 2543, not the body text. Section 1 (Introduction) through the start of Section 12 are where the normative requirements, grammars, examples, and diagrams live. If I wrote those from memory, I'd be inventing spec details, and implementers rely on every word being exact.

Could you paste the original text starting at 1. Introduction (through at least Section 1.5.3 for this part)? Once I have it, I'll continue from there in the same style, keeping every BCP 14 keyword, grammar, code block, section number, and citation exactly as written.

   12.3       Proxy Server ........................................   98
   12.3.1     Proxying Requests ...................................   98
   12.3.2     Proxying Responses ..................................   99
   12.3.3     Stateless Proxy: Proxying Responses .................   99
   12.3.4     Stateful Proxy: Receiving Requests ..................   99
   12.3.5     Stateful Proxy: Receiving ACKs ......................   99
   12.3.6     Stateful Proxy: Receiving Responses .................  100
   12.3.7     Stateless, Non-Forking Proxy ........................  100
   12.4       Forking Proxy .......................................  100
   13         Security Considerations .............................  104
   13.1       Confidentiality and Privacy: Encryption .............  104
   13.1.1     End-to-End Encryption ...............................  104
   13.1.2     Privacy of SIP Responses ............................  107
   13.1.3     Encryption by Proxies ...............................  108
   13.1.4     Hop-by-Hop Encryption ...............................  108
   13.1.5     Via field encryption ................................  108
   13.2       Message Integrity and Access Control:
              Authentication ......................................  109

   13.2.1     Trusting responses ..................................  112
   13.3       Callee Privacy ......................................  113
   13.4       Known Security Problems .............................  113
   14         SIP Authentication using HTTP Basic and Digest
              Schemes .............................................  113
   14.1       Framework ...........................................  113
   14.2       Basic Authentication ................................  114
   14.3       Digest Authentication ...............................  114
   14.4       Proxy-Authentication ................................  115
   15         SIP Security Using PGP ..............................  115
   15.1       PGP Authentication Scheme ...........................  115
   15.1.1     The WWW-Authenticate Response Header ................  116
   15.1.2     The Authorization Request Header ....................  117
   15.2       PGP Encryption Scheme ...............................  118
   15.3       Response-Key Header Field for PGP ...................  119
   16         Examples ............................................  119
   16.1       Registration ........................................  119
   16.2       Invitation to a Multicast Conference ................  121
   16.2.1     Request .............................................  121
   16.2.2     Response ............................................  122
   16.3       Two-party Call ......................................  123
   16.4       Terminating a Call ..................................  125
   16.5       Forking Proxy .......................................  126
   16.6       Redirects ...........................................  130
   16.7       Negotiation .........................................  131
   16.8       OPTIONS Request .....................................  132
   A          Minimal Implementation ..............................  134
   A.1        Client ..............................................  134
   A.2        Server ..............................................  135
   A.3        Header Processing ...................................  135
   B          Usage of the Session Description Protocol (SDP)......  136
   B.1        Configuring Media Streams ...........................  136
   B.2        Setting SDP Values for Unicast ......................  138
   B.3        Multicast Operation .................................  139
   B.4        Delayed Media Streams ...............................  139
   B.5        Putting Media Streams on Hold .......................  139
   B.6        Subject and SDP "s=" Line ...........................  140
   B.7        The SDP "o=" Line ...................................  140
   C          Summary of Augmented BNF ............................  141
   C.1        Basic Rules .........................................  143
   D          Using SRV DNS Records ...............................  146
   E          IANA Considerations .................................  148
   F          Acknowledgments .....................................  149
   G          Authors' Addresses ..................................  149
   H          Bibliography ........................................  150
   I          Full Copyright Statement ............................  153

1. Introduction โœจ

1.1. Overview of SIP Functionality

okay bestie, let's talk about SIP ๐Ÿ“žโœจ The Session Initiation Protocol is an application-layer control protocol ๐Ÿ’… that can set up, change, and end multimedia sessions or calls. We're talking multimedia conferences, distance learning, Internet telephony, and similar vibes ๐ŸŽ€. SIP can invite both persons AND "robots," like a media storage service ๐Ÿค–. It can invite parties to both unicast and multicast sessions, and the person doing the inviting doesn't have to be a member of the session they're inviting people to. Media and participants can also get added to a session that already exists ๐Ÿฆ‹

SIP can start sessions, but it can also invite members to sessions that were already advertised and set up some other way ๐ŸŒธ Sessions can be advertised using multicast protocols like SAP, electronic mail, news groups, web pages, or directories (LDAP), among others ๐Ÿ’œ

SIP transparently supports name mapping and redirection services ๐Ÿงš, which means it can power ISDN and Intelligent Network telephony subscriber services. These facilities also enable personal mobility ๐Ÿฆ‹ In telecom intelligent network lingo, that's defined as:

"Personal mobility is the ability of end users to originate and receive calls and access subscribed telecommunication services on any terminal in any location, and the ability of the network to identify end users as they move. Personal mobility is based on the use of a unique personal identity (i.e., personal number)." [1]

Personal mobility complements terminal mobility, which is the ability to keep communications going when you move a single end system from one subnet to another ๐ŸŒˆ

SIP supports five facets of setting up and ending multimedia communications, and honestly they're all so important ๐Ÿ˜ญ๐Ÿ‘‘

  • User location: figuring out the end system to use for communication ๐Ÿ“
  • User capabilities: figuring out the media and media parameters to use ๐ŸŽง
  • User availability: figuring out whether the called party is willing to engage in communications ๐Ÿ’ฌ
  • Call setup: "ringing," plus setting up call parameters at both the called and calling party ๐Ÿ“ฒ
  • Call handling: including transfer and termination of calls ๐Ÿ”ฅ

SIP can also start multi-party calls using a multipoint control unit (MCU) or a fully-meshed interconnection instead of multicast ๐Ÿซถ And Internet telephony gateways that connect Public Switched Telephone Network (PSTN) parties can use SIP to set up calls between them too ๐Ÿ“ž๐Ÿ’–

SIP is part of the overall IETF multimedia data and control architecture, which already has protocols like RSVP (RFC 2205 [2]) for reserving network resources, the real-time transport protocol (RTP) (RFC 1889 [3]) for transporting real-time data and providing QOS feedback, the real-time streaming protocol (RTSP) (RFC 2326 [4]) for controlling delivery of streaming media, the session announcement protocol (SAP) [5] for advertising multimedia sessions via multicast, and the session description protocol (SDP) (RFC 2327 [6]) for describing multimedia sessions ๐ŸŽ€ BUT the functionality and operation of SIP doesn't depend on any of these protocols, so it's independent queen behavior ๐Ÿ‘‘

SIP can also be used alongside other call setup and signaling protocols ๐Ÿฆ‹ In that mode, an end system uses SIP exchanges to find the right end system address and protocol from an address that's protocol-independent. For example, SIP could be used to figure out that the party can be reached via H.323 [7], get the H.245 [8] gateway and user address, and then use H.225.0 [9] to set up the call ๐Ÿ’…

Another example: SIP might figure out that the callee is reachable via the PSTN and show the phone number to call, possibly suggesting an Internet-to-PSTN gateway to use ๐Ÿ“ž๐ŸŒธ

SIP doesn't offer conference control services like floor control or voting, and it doesn't dictate how a conference should be managed ๐Ÿ™ˆ But SIP can be used to bring in conference control protocols. Also, SIP does NOT allocate multicast addresses, so don't go looking for that here ๐Ÿ’€

SIP can invite users to sessions with or without resource reservation โœจ SIP doesn't reserve resources itself, but it can pass the invited system the info it needs to do that ๐Ÿซถ

1.2. Terminology

In this document, the key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" are to be interpreted as described in RFC 2119 [10] and indicate requirement levels for compliant SIP implementations ๐Ÿ”ฅ๐Ÿ’… Those words are the whole vibe for how strict each rule is, so read them carefully, bestie ๐ŸŽ€

1.3 Definitions ๐Ÿ’–

okay so this section is basically the SIP glossary ๐ŸŽ€ the people who wrote it say client, server and proxy are kinda like how HTTP does it (RFC 2068 [11]), and URI and URL come from RFC 2396 [12]. then they list the terms that matter most for SIP. let's go bestie ๐Ÿฆ‹

  • Call: A call consists of all participants in a conference invited by a common source. A SIP call is identified by a globally unique call-id (Section 6.12). So if a user gets invited to the same multicast session by several people, each invitation counts as its own call โœจ A point-to-point Internet telephony conversation maps into a single SIP call. In a multiparty conference unit (MCU) based call-in conference, each participant uses a separate call to invite himself to the MCU ๐Ÿ™ˆ
  • Call leg: A call leg is identified by the combination of Call-ID, To and From ๐Ÿ”—
  • Client: An application program that sends SIP requests. Clients may or may not interact directly with a human user. User agents and proxies contain clients (and servers) ๐Ÿ’…
  • Conference: A multimedia session (see below), identified by a common session description. A conference can have zero or more members and includes the cases of a multicast conference, a full-mesh conference and a two-party "telephone call", as well as combinations of these. Any number of calls can be used to create a conference ๐ŸŒˆ
  • Downstream: Requests sent in the direction from the caller to the callee (i.e., user agent client to user agent server) โญ
  • Final response: A response that terminates a SIP transaction, as opposed to a provisional response that does not. All 2xx, 3xx, 4xx, 5xx and 6xx responses are final ๐Ÿ”ฅ
  • Initiator, calling party, caller: The party initiating a conference invitation. Note that the calling party does not have to be the same as the one creating the conference ๐Ÿ‘‘
  • Invitation: A request sent to a user (or service) requesting participation in a session. A successful SIP invitation consists of two transactions: an INVITE request followed by an ACK request ๐Ÿซถ
  • Invitee, invited user, called party, callee: The person or service that the calling party is trying to invite to a conference ๐Ÿงš
  • Isomorphic request or response: Two requests or responses are defined to be isomorphic for the purposes of this document if they have the same values for the Call-ID, To, From and CSeq header fields. In addition, isomorphic requests have to have the same Request-URI ๐Ÿ“
  • Location server: See location service ๐Ÿ—บ๏ธ
  • Location service: A location service is used by a SIP redirect or proxy server to obtain information about a callee's possible location(s). Location services are offered by location servers. Location servers MAY be co-located with a SIP server, but the manner in which a SIP server requests location services is beyond the scope of this document ๐Ÿ“
  • Parallel search: In a parallel search, a proxy issues several requests to possible user locations upon receiving an incoming request. Rather than issuing one request and then waiting for the final response before issuing the next request as in a sequential search, a parallel search issues requests without waiting for the result of previous requests ๐Ÿƒโ€โ™€๏ธ๐Ÿ’จ
  • Provisional response: A response used by the server to indicate progress, but that does not terminate a SIP transaction. 1xx responses are provisional, other responses are considered final โณ
  • Proxy, proxy server: An intermediary program that acts as both a server and a client for the purpose of making requests on behalf of other clients. Requests are serviced internally or by passing them on, possibly after translation, to other servers. A proxy interprets, and, if necessary, rewrites a request message before forwarding it ๐ŸŽ
  • Redirect server: A redirect server is a server that accepts a SIP request, maps the address into zero or more new addresses and returns these addresses to the client. Unlike a proxy server, it does not initiate its own SIP request. Unlike a user agent server, it does not accept calls โ†ช๏ธ
  • Registrar: A registrar is a server that accepts REGISTER requests. A registrar is typically co-located with a proxy or redirect server and MAY offer location services ๐Ÿ“
  • Ringback: Ringback is the signaling tone produced by the calling client's application indicating that a called party is being alerted (ringing) ๐Ÿ””
  • Server: A server is an application program that accepts requests in order to service requests and sends back responses to those requests. Servers are either proxy, redirect or user agent servers or registrars ๐Ÿ 
  • Session: From the SDP specification: "A multimedia session is a set of multimedia senders and receivers and the data streams flowing from senders to receivers. A multimedia conference is an example of a multimedia session." (RFC 2327 [6]) (A session as defined for SDP can comprise one or more RTP sessions.) As defined, a callee can be invited several times, by different calls, to the same session. If SDP is used, a session is defined by the concatenation of the user name, session id, network type, address type and address elements in the origin field ๐ŸŽถ
  • (SIP) transaction: A SIP transaction occurs between a client and a server and comprises all messages from the first request sent from the client to the server up to a final (non-1xx) response sent from the server to the client. A transaction is identified by the CSeq sequence number (Section 6.17) within a single call leg. The ACK request has the same CSeq number as the corresponding INVITE request, but comprises a transaction of its own ๐Ÿงพ
  • Upstream: Responses sent in the direction from the user agent server to the user agent client โฌ†๏ธ
  • URL-encoded: A character string encoded according to RFC 1738, Section 2.2 [13] ๐Ÿ”ค
  • User agent client (UAC), calling user agent: A user agent client is a client application that initiates the SIP request ๐Ÿ“ž
  • User agent server (UAS), called user agent: A user agent server is a server application that contacts the user when a SIP request is received and that returns a response on behalf of the user. The response accepts, rejects or redirects the request ๐Ÿ“ฒ
  • User agent (UA): An application which contains both a user agent client and user agent server ๐Ÿค

An application program MAY be capable of acting both as a client and a server. For example, a typical multimedia conference control application would act as a user agent client to initiate calls or to invite others to conferences and as a user agent server to accept invitations. The properties of the different SIP server types are summarized in Table 1 ๐Ÿ’œ

property                   redirect  proxy   user agent  registrar
                            server   server    server
__________________________________________________________________
also acts as a SIP client     no      yes        no         no
returns 1xx status           yes      yes       yes         yes
returns 2xx status            no      yes       yes         yes
returns 3xx status           yes      yes       yes         yes
returns 4xx status           yes      yes       yes         yes
returns 5xx status           yes      yes       yes         yes
returns 6xx status            no      yes       yes         yes
inserts Via header            no      yes        no         no
accepts ACK                  yes      yes       yes         no

Table 1: Properties of the different SIP server types ๐Ÿ“Š


1.4 Overview of SIP Operation ๐Ÿš€

this section is the quick tour of how SIP actually works ๐Ÿ›ผ callers and callees are identified by SIP addresses (Section 1.4.1). when you make a SIP call, you first find the right server (Section 1.4.2), then send a SIP request (Section 1.4.3). the most common move is the invitation (Section 1.4.4) โœจ instead of going straight to the callee, a SIP request might get redirected, or it might kick off a whole chain of new requests from proxies (Section 1.4.5). and users can register where they're reachable with SIP servers (Section 4.2.6) ๐Ÿ“

1.4.1 SIP Addressing ๐Ÿก

the "objects" SIP addresses are users at hosts, identified by a SIP URL ๐Ÿ’Œ a SIP URL looks kinda like a mailto or telnet URL, so it's user@host. the user part is a user name or a telephone number. the host part is either a domain name or a numeric network address. see section 2 for the full breakdown of SIP URLs ๐Ÿ”

a user's SIP address can come from out-of-band sources, can be learned through existing media agents, can show up in some mailers' message headers, or can get recorded during earlier invitation interactions ๐Ÿ“ฌ honestly, in lots of cases you can guess a user's SIP URL from their email address ๐Ÿ‘€

a SIP URL can point to one individual (who might be at one of several end systems), the first available person from a group, or a whole group ๐Ÿ‘ฏ the form of the address, like sip:sales@example.com, isn't enough on its own, in general, to tell what the caller actually wants ๐Ÿคทโ€โ™€๏ธ

โš ๏ธ privacy check: if a user or service picks an address that's guessable from a person's name and organization, the old trick of keeping your number private with an unlisted "phone" number is compromised ๐Ÿ˜ญ

but here's the plot twist: unlike traditional telephony, SIP offers authentication and access control mechanisms and can use lower-layer security mechanisms too ๐Ÿ” so client software can reject unauthorized or unwanted call attempts. iconic, honestly ๐Ÿ’…โœจ

1.4.2 Locating a SIP Server โœจ

Okay so when a client wants to send a request, it has two options ๐Ÿ’…. It can send it to a locally configured SIP proxy server (kinda like HTTP ๐ŸŒธ), no matter what the Request-URI says. Or it can send it straight to the IP address and port that match the Request-URI ๐Ÿฆ‹.

For that second option, the client must determine the protocol, port and IP address of a server to send the request to. A client SHOULD follow the steps below to get this info, but it MAY follow the alternative, optional procedure defined in Appendix D ๐Ÿงš. At each step, unless stated otherwise, the client SHOULD try to contact a server at the port number in the Request-URI. No port in the Request-URI? Then it uses port 5060 ๐ŸŽ€. If the Request-URI names a protocol (TCP or UDP), the client uses that one. If no protocol is named, the client tries UDP (if UDP is supported). If that attempt fails, or the client doesn't support UDP but does support TCP, it then tries TCP ๐Ÿ’œ.

A client SHOULD be able to read explicit network notifications (like ICMP messages) that say a server can't be reached, instead of only waiting for timeouts ๐Ÿ‘€. (For socket-based programs: for TCP, connect() returns ECONNREFUSED if the client couldn't connect to a server at that address. For UDP, the socket needs to be bound to the destination address using connect() rather than sendto() or similar, so that a second write() fails with ECONNREFUSED if there's no server listening.) If the client finds the server isn't reachable at a particular address, it SHOULD behave as if it had received a 400-class error response to that request ๐Ÿ™ˆ.

The client tries to find one or more addresses for the SIP server by querying DNS. The procedure goes like this:

  1. If the host portion of the Request-URI is an IP address, the client contacts the server at the given address. Otherwise, the client proceeds to the next step.
  2. The client queries the DNS server for address records for the host portion of the Request-URI. If the DNS server returns no address records, the client stops, as it has been unable to locate a server. By address record, we mean A RR's, AAAA RR's, or other similar address records, chosen according to the client's network protocol capabilities.
ngl this next bit is the lore ๐Ÿ“: there are no mandatory rules on how to pick a host name for a SIP server. Users are encouraged to name their SIP servers using the sip.domainname (i.e., sip.example.com) convention, as specified in RFC 2219 [16]. Users may only know an email address instead of a full SIP URL for a callee, though. In that case, implementations may be able to boost the odds of reaching a SIP server for that domain by building a SIP URL from the email address and prefixing the host name with "sip.". Down the road, this mechanism will likely become unnecessary as better DNS techniques, like the one in Appendix D, become widely available โœจ.

A client MAY cache a successful DNS query result. A successful query is one that contained records in the answer, and a server was contacted at one of the addresses from that answer. When the client wants to send a request to the same host, it MUST start the search as if it had just received this answer from the name server. The client MUST follow the procedures in RFC1035 [15] regarding DNS cache invalidation when the DNS time-to-live expires โฐ.


1.4.3 SIP Transaction

Once the host part has been resolved to a SIP server, the client sends one or more SIP requests to that server and gets one or more responses back ๐Ÿ“ฌ. A request (and its retransmissions) plus the responses triggered by that request make up a SIP transaction ๐Ÿงถ. All responses to a request contain the same values in the Call-ID, CSeq, To, and From fields (with the possible addition of a tag in the To field (section 6.37)). This is what lets responses get matched with requests ๐Ÿ’–. The ACK request following an INVITE is not part of the transaction, since it may traverse a different set of hosts ๐Ÿ›ฃ๏ธ.

If TCP is used, requests and responses within a single SIP transaction are carried over the same TCP connection (see Section 10). Several SIP requests from the same client to the same server MAY use the same TCP connection, or MAY use a new connection for each request ๐ŸŒˆ.

If the client sent the request via unicast UDP, the response is sent to the address in the next Via header field (Section 6.40) of the response. If the request is sent via multicast UDP, the response goes to that same multicast address and destination port. For UDP, reliability is achieved using retransmission (Section 10) ๐Ÿ”.

The SIP message format and operation is independent of the transport protocol ๐Ÿซถ.


1.4.4 SIP Invitation

A successful SIP invitation is two requests: INVITE, followed by ACK ๐ŸŽ‰. The INVITE (Section 4.2.1) request asks the callee to join a particular conference or start a two-party conversation. Once the callee has agreed to take part in the call, the caller confirms it got that response by sending an ACK (Section 4.2.2) request. If the caller no longer wants to be part of the call, it sends a BYE request instead of an ACK ๐Ÿ‘‹.

The INVITE request usually has a session description, for example written in SDP (RFC 2327 [6]) format, that gives the called party enough info to join the session ๐Ÿ“. For multicast sessions, the session description lists the media types and formats that are allowed to be distributed to that session. For a unicast session, it lists the media types and formats the caller is willing to use, plus where the caller wants the media data sent ๐Ÿ“. Either way, if the callee wants to accept the call, it answers the invitation by returning a similar description that lists the media it wants to use. For a multicast session, the callee SHOULD only return a session description if it can't receive the media in the caller's description, or wants to receive data via unicast ๐Ÿค“.

The protocol exchanges for the INVITE method are shown in Fig. 1 for a proxy server and in Fig. 2 for a redirect server. (Heads up: the messages in the figures have been abbreviated slightly ๐Ÿ™ˆ.) In Fig. 1, the proxy server accepts the INVITE request (step 1), contacts the location service with all or parts of the address (step 2), and gets a more precise location (step 3). The proxy server then issues a SIP INVITE request to the address(es) the location service returned (step 4). The user agent server alerts the user (step 5) and returns a success indication to the proxy server (step 6). The proxy server then returns the success result to the original caller (step 7). The caller confirms receipt of this message with an ACK request, which is forwarded to the callee (steps 8 and 9). Note that an ACK can also be sent directly to the callee, bypassing the proxy. All requests and responses have the same Call-ID ๐Ÿฆ‹.

                                         +....... cs.columbia.edu .......+
                                         :                               :
                                         : (~~~~~~~~~~)                  :
                                         : ( location )                  :
                                         : ( service  )                  :
                                         : (~~~~~~~~~~)                  :
                                         :     ^    |                    :
                                         :     | hgs@lab                 :
                                         :    2|   3|                    :
                                         :     |    |                    :
                                         : henning  |                    :
+.. cs.tu-berlin.de ..+ 1: INVITE        :     |    |                    :
:                     :    henning@cs.col:     |   \/ 4: INVITE  5: ring :
: cz@cs.tu-berlin.de ========================>(~~~~~~)=========>(~~~~~~) :
:                    <........................(      )<.........(      ) :
:                     : 7: 200 OK        :    (      )6: 200 OK (      ) :
:                     :                  :    ( work )          ( lab  ) :
:                     : 8: ACK           :    (      )9: ACK    (      ) :
:                    ========================>(~~~~~~)=========>(~~~~~~) :
+.....................+                  +...............................+

  ====> SIP request
  ....> SIP response

   ^
   |    non-SIP protocols
   |

Figure 1: Example of SIP proxy server

The redirect server shown in Fig. 2 accepts the INVITE request (step 1), contacts the location service as before (steps 2 and 3), and, instead of contacting the newly found address itself, returns that address to the caller (step 4). The caller acknowledges that with an ACK request (step 5). The caller then issues a new request, with the same call-ID but a higher CSeq, to the address the first server returned (step 6). In the example, the call succeeds (step 7). The caller and callee finish the handshake with an ACK (step 8) ๐ŸŽ€.

The next section discusses what happens if the location service returns more than one possible alternative ๐Ÿ’…โœจ.

1.4.5 Locating a User ๐Ÿ“

okay so a callee can totally wander between a bunch of different end systems over time ๐Ÿฆ‹ These locations can get dynamically registered with the SIP server (Sections 1.4.7, 4.2.6). A location server MAY also use one or more other protocols, like finger (RFC 1288 [17]), rwhois (RFC 2167 [18]), LDAP (RFC 1777 [19]), multicast-based protocols [20] or operating-system dependent mechanisms to actively figure out which end system a user might be reachable at ๐Ÿ” A location server MAY return several locations because the user is logged in at several hosts at once, or because the location server has (temporarily) inaccurate information ๐Ÿ™ƒ The SIP server combines the results to yield a list of a zero or more locations.

what happens next depends on what kind of SIP server you are ๐Ÿ‘€ A SIP redirect server returns the list to the client as Contact headers (Section 6.13). A SIP proxy server can sequentially or in parallel try the addresses until the call is successful (2xx response) or the callee has declined the call (6xx response). With sequential attempts, a proxy server can implement an "anycast" service ๐Ÿงš

If a proxy server forwards a SIP request, it MUST add itself to the beginning of the list of forwarders noted in the Via (Section 6.40) headers. The Via trace makes sure replies can take the same path back, which keeps things working through compliant firewalls and stops request loops ๐Ÿ” On the response path, each host MUST remove its Via, so the routing internal info stays hidden from the callee and outside networks ๐Ÿคซ A proxy server MUST check that it does not generate a request to a host listed in the Via sent-by, via-received or via-maddr parameters (Section 6.40). (Note: If a host has several names or network addresses, this does not always work. Thus, each host also checks if it is part of the Via list.)

A SIP invitation may traverse more than one SIP proxy server ๐ŸŒธ If one of these "forks" the request, meaning it issues more than one request in response to receiving the invitation request, a client can be reached independently by more than one copy of that invitation. Each copy bears the same Call-ID. The user agent MUST return the same status response returned in the first response. Duplicate requests are not an error, so no panic ๐Ÿ’…

1.4.6 Changing an Existing Session ๐Ÿ”„

sometimes you wanna change the parameters of a session that's already going, and that's totally a thing โœจ You do it by re-issuing the INVITE, using the same Call-ID, but with a new or different body or header fields to carry the new info. This re INVITE MUST have a higher CSeq than any previous request from the client to the server ๐Ÿ”ข

for example, two people are chatting and then wanna add a third person, switching to multicast for efficiency ๐ŸŽ€ One of the participants invites the third party with the new multicast address, and at the same time sends an INVITE to the second party with the new multicast session description, but with the old call identifier. iconic teamwork ๐Ÿ‘‘

1.4.7 Registration Services ๐Ÿ“ฃ

The REGISTER request lets a client tell a proxy or redirect server which address(es) it can be reached at. A client MAY also use it to install call handling features at the server ๐Ÿ’œ

1.5 Protocol Properties ๐ŸŒˆ

1.5.1 Minimal State ๐Ÿซง

A single conference session or call involves one or more SIP request-response transactions. Proxy servers do not have to keep state for a particular call, however, they MAY maintain state for a single SIP transaction, as discussed in Section 12. For efficiency, a server MAY cache the results of location service requests ๐Ÿง 

1.5.2 Lower-Layer-Protocol Neutral ๐Ÿฆ‹

SIP makes minimal assumptions about the underlying transport and network-layer protocols ๐Ÿซถ The lower layer can provide either a packet or a byte stream service, with reliable or unreliable service.

In an Internet context, SIP can use both UDP and TCP as transport protocols, among others ๐ŸŒŠ UDP lets the application control the timing of messages and their retransmission more carefully, do parallel searches without needing TCP connection state for each outstanding request, and use multicast. Routers can more easily snoop SIP UDP packets ๐Ÿ‘€ TCP makes it easier to get through existing firewalls ๐Ÿงฑ

                                         +....... cs.columbia.edu .......+
                                         :                               :
                                         : (~~~~~~~~~~)                  :
                                         : ( location )                  :
                                         : ( service  )                  :
                                         : (~~~~~~~~~~)                  :
                                         :    ^   |                      :
                                         :    | hgs@lab                  :
                                         :   2|  3|                      :
                                         :    |   |                      :
                                         : henning|                      :
+.. cs.tu-berlin.de ..+ 1: INVITE        :    |   |                      :
:                     :    henning@cs.col:    |   \/                     :
: cz@cs.tu-berlin.de =======================>(~~~~~~)                    :
:       | ^ |        <.......................(      )                    :
:       | . |         : 4: 302 Moved     :   (      )                    :
:       | . |         :    hgs@lab       :   ( work )                    :
:       | . |         :                  :   (      )                    :
:       | . |         : 5: ACK           :   (      )                    :
:       | . |        =======================>(~~~~~~)                    :
:       | . |         :                  :                               :
+.......|...|.........+                  :                               :
        | . |                            :                               :
        | . |                            :                               :
        | . |                            :                               :
        | . |                            :                               :
        | . | 6: INVITE hgs@lab.cs.columbia.edu                 (~~~~~~) :
        | . ==================================================> (      ) :
        | ..................................................... (      ) :
        |     7: 200 OK                  :                      ( lab  ) :
        |                                :                      (      ) :
        |     8: ACK                     :                      (      ) :
        ======================================================> (~~~~~~) :
                                         +...............................+

  ====> SIP request
  ....> SIP response

    ^
    |   non-SIP protocols
    |

Figure 2: Example of SIP redirect server ๐ŸŽฌ

When TCP is used, SIP can use one or more connections to try to contact a user or to change the parameters of an existing conference. Different SIP requests for the same SIP call MAY use different TCP connections or a single persistent connection, whichever fits best ๐Ÿงต

For concreteness, this document will only refer to Internet protocols ๐ŸŒ However, SIP MAY also be used directly with protocols such as ATM AAL5, IPX, frame relay or X.25. The necessary naming conventions are beyond the scope of this document. User agents SHOULD implement both UDP and TCP transport. Proxy, registrar, and redirect servers MUST implement both UDP and TCP transport ๐Ÿ’–

1.5.3 Text-Based ๐Ÿ’ฌ

SIP is text-based, using ISO 10646 in UTF-8 encoding throughout ๐Ÿ“ This makes it easy to implement in languages like Java, Tcl and Perl, makes debugging easy, and most importantly, makes SIP flexible and extensible ๐ŸŒˆ Since SIP is used for starting multimedia conferences rather than delivering media data, the extra overhead of a text-based protocol is believed to be not significant. literally a win ๐Ÿ™Œ


2 SIP Uniform Resource Locators ๐Ÿ”—

SIP URLs show up inside SIP messages to indicate the originator (From), the current destination (Request-URI) and the final recipient (To) of a SIP request, and to specify redirection addresses (Contact). A SIP URL can also be embedded in web pages or other hyperlinks to show that a particular user or service can be called via SIP ๐Ÿ“ž When it's used as a hyperlink, the SIP URL indicates the use of the INVITE method.

The SIP URL scheme is defined so you can set SIP request-header fields and the SIP message-body ๐ŸŽ

This corresponds to the use of mailto: URLs. It makes it possible, for example, to specify the subject, urgency or media types of calls initiated through a web page or as part of an email message. ๐Ÿ’Œ

A SIP URL follows the guidelines of RFC 2396 [12] and has the syntax shown in Fig. 3. The syntax is described using Augmented Backus-Naur Form (See Section C). Note that reserved characters have to be escaped, and that the "set of characters reserved within any given URI component is defined by that component. In general, a character is reserved if the semantics of the URI changes if the character is replaced with its escaped US-ASCII encoding" [12] ๐Ÿง

  SIP-URL         = "sip:" [ userinfo "@" ] hostport
                    url-parameters [ headers ]
  userinfo        = user [ ":" password ]
  user            = *( unreserved | escaped
                  | "&" | "=" | "+" | "$" | "," )
  password        = *( unreserved | escaped
                  | "&" | "=" | "+" | "$" | "," )
  hostport        = host [ ":" port ]
  host            = hostname | IPv4address
  hostname        = *( domainlabel "." ) toplabel [ "." ]
  domainlabel     = alphanum | alphanum *( alphanum | "-" ) alphanum
  toplabel        = alpha | alpha *( alphanum | "-" ) alphanum
  IPv4address     = 1*digit "." 1*digit "." 1*digit "." 1*digit
  port            = *digit
  url-parameters  = *( ";" url-parameter )
  url-parameter   = transport-param | user-param | method-param
                  | ttl-param | maddr-param | other-param
  transport-param = "transport=" ( "udp" | "tcp" )
  ttl-param       = "ttl=" ttl
  ttl             = 1*3DIGIT       ; 0 to 255
  maddr-param     = "maddr=" host
  user-param      = "user=" ( "phone" | "ip" )
  method-param    = "method=" Method
  tag-param       = "tag=" UUID
  UUID            = 1*( hex | "-" )
  other-param     = ( token | ( token "=" ( token | quoted-string )))
  headers         = "?" header *( "&" header )
  header          = hname "=" hvalue
  hname           = 1*uric
  hvalue          = *uric
  uric            = reserved | unreserved | escaped
  reserved        = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                    "$" | ","
  digits          = 1*DIGIT

Figure 3: SIP URL syntax ๐Ÿ“œ

The URI character classes referenced above are described in Appendix C ๐ŸŒธ

The components of the SIP URI have the following meanings. โœจ

2. SIP Uniform Resource Locators โœจ

okay so this next bit is the telephone number grammar, and it's giving "phone numbers inside a web address" ๐Ÿ“ž๐Ÿฆ‹

telephone-subscriber  = global-phone-number | local-phone-number
   global-phone-number   = "+" 1*phonedigit [isdn-subaddress]
                             [post-dial]
   local-phone-number    = 1*(phonedigit | dtmf-digit |
                             pause-character) [isdn-subaddress]
                             [post-dial]
   isdn-subaddress       = ";isub=" 1*phonedigit
   post-dial             = ";postd=" 1*(phonedigit | dtmf-digit
                         |  pause-character)
   phonedigit            = DIGIT | visual-separator
   visual-separator      = "-" | "."
   pause-character       = one-second-pause | wait-for-dial-tone
   one-second-pause      = "p"
   wait-for-dial-tone    = "w"
   dtmf-digit            = "*" | "#" | "A" | "B" | "C" | "D"

Figure 4: SIP URL syntax; telephone subscriber

user ๐Ÿ’–: If the host is an Internet telephony gateway, the user field MAY also encode a telephone number using the telephone-subscriber notation from Figure 4. The phone number is basically a special kind of user name, and a BNF can't tell them apart, so there's a URL parameter called user that marks it as a phone number โœจ. The phone identifier is for when you're connecting to a telephony gateway. Even without that parameter, recipients of SIP URLs MAY read the stuff before the @ as a phone number, but only if their local rules for user names allow it ๐ŸŒธ.

password ๐Ÿ”: The SIP scheme MAY use the user:password format in the userinfo field. Putting passwords in the userinfo is NOT RECOMMENDED, bestie, because sending auth info in plain text (like inside URIs) has proven to be a security risk in almost every case where it's been done ๐Ÿ’€.

host ๐ŸŒ: The mailto: URL and RFC 822 email addresses want numeric host addresses ("host numbers") wrapped in square brackets, since host names might be numeric too. Every other URL uses host numbers without brackets, and SIP URLs use the no-brackets version โœจ.

The IPv6 literal address thing in URLs is being sorted out somewhere else in the IETF, so SIP implementers are advised to keep up with that work ๐Ÿ‘€.

port ๐Ÿšช: This is the port number you send a request to. If it's not there, you follow the procedures from Section 1.4.2 to figure out which port to use ๐ŸŽ€.

URL parameters ๐Ÿงš: SIP URLs can carry specific parameters for the request. They go after the host and are separated by semi-colons ๐Ÿ’…. The transport parameter picks the transport mechanism (UDP or TCP), and UDP is assumed if you don't include one ๐Ÿฆ‹. The maddr parameter gives the server address to contact for this user, which overrides the address in the host field. That address is usually a multicast address, but it could also be a backup server ๐Ÿ”ฅ. The ttl parameter sets the time-to-live value for the UDP multicast packet, and it MUST only be used if maddr is a multicast address AND the transport protocol is UDP ๐Ÿ˜ญ. We already covered the user parameter above. So, say you want to call j.doe@big.com using multicast to 239.255.255.1 with a ttl of 15. The URL would look like this:

sip:j.doe@big.com;maddr=239.255.255.1;ttl=15
The transport, maddr, and ttl parameters MUST NOT be used in the From and To header fields and the Request-URI. If they show up there anyway, they get ignored ๐Ÿ™ˆ.

Headers ๐Ÿ“ฌ: You can define headers for the SIP request with the "?" mechanism inside a SIP URL. The special hname body means the matching hvalue is the message-body of the SIP INVITE request ๐Ÿ“. Headers MUST NOT be used in the From and To header fields or the Request-URI, and if they're there they get ignored. hname and hvalue are encodings of a SIP header name and value, respectively. All URL reserved characters in the header names and values MUST be escaped ๐Ÿซถ.

Method ๐ŸŽฏ: You can specify the method of the SIP request with the method parameter. This parameter MUST NOT be used in the From and To header fields or the Request-URI, and if it shows up there it gets ignored ๐Ÿ’œ.

Table 2 breaks down where each part of a SIP URL can be used and what default it gets if it's missing โœจ:

                 default    Req.-URI  To  From  Contact  external
  user           --         x         x   x     x        x
  password       --         x         x         x        x
  host           mandatory  x         x   x     x        x
  port           5060       x         x   x     x        x
  user-param     ip         x         x   x     x        x
  method         INVITE                         x        x
  maddr-param    --                             x        x
  ttl-param      1                              x        x
  transp.-param  --                             x        x
  headers        --                             x        x

Table 2: Use and default values of URL components for SIP headers, Request-URI and references

Here are some SIP URL examples, bestie ๐ŸŒˆ:

  sip:j.doe@big.com
  sip:j.doe:secret@big.com;transport=tcp
  sip:j.doe@big.com?subject=project
  sip:+1-212-555-1212:1234@gateway.com;user=phone
  sip:1212@gateway.com
  sip:alice@10.1.2.3
  sip:alice@example.com
  sip:alice%40example.com@gateway.com
  sip:alice@registrar.com;method=REGISTER

Inside a SIP message, URLs show the source and intended destination of a request, redirection addresses, and the current destination of a request. Normally every one of those fields holds a SIP URL ๐Ÿ“.

SIP URLs are case-insensitive, so sip:j.doe@example.com and SIP:J.Doe@Example.com count as the same โœจ. When you compare SIP URLs for equality, ALL the URL parameters get included ๐Ÿ”.

SIP header fields MAY contain non-SIP URLs. For example, if a call from a telephone gets relayed to the Internet over SIP, the SIP From header field might hold a phone URL ๐Ÿ“ž๐Ÿฆ‹.


3. SIP Message Overview โœจ

SIP is a text-based protocol. It uses the ISO 10646 character set with UTF-8 encoding (RFC 2279 [21]). Senders MUST terminate lines with a CRLF, but receivers MUST ALSO interpret a CR or an LF by itself as a line terminator ๐Ÿ’–.

Apart from that character set difference, a lot of the message syntax and header fields are the same as HTTP/1.1. Instead of repeating all of that, we use [HX.Y] to point to Section X.Y of the current HTTP/1.1 specification (RFC 2068 [11]). We also describe SIP in both prose and augmented Backus-Naur form (ABNF). See section C for an ABNF overview ๐ŸŽ€.

Note, however, that SIP is NOT an extension of HTTP ๐Ÿ™…โ€โ™€๏ธ. (We know it looks similar, but it's its own thing, bestie.)

Unlike HTTP, SIP MAY use UDP. Over TCP or UDP, multiple SIP transactions can ride in a single TCP connection or UDP datagram. UDP datagrams, headers included, SHOULD NOT be bigger than the path maximum transmission unit (MTU) when the MTU is known, or 1500 bytes when it isn't ๐ŸŒธ.

The 1500 bytes fits inside the "typical" Ethernet MTU without IP fragmentation. Recent studies [22] say an MTU of 1500 bytes is a reasonable assumption. The next lower common MTU values are 1006 bytes for SLIP and 296 for low-delay PPP (RFC 1191 [23]). So another reasonable value would be a message size of 950 bytes, which fits the packet headers inside the SLIP MTU without fragmentation ๐Ÿงš.

A SIP message is either a request from a client to a server, or a response from a server to a client ๐Ÿ’….

SIP-message  =  Request | Response

Both Request (section 4) and Response (section 5) messages use the generic-message format of RFC 822 [24] to carry entities (the body of the message). Both types have a start-line, one or more header fields (also called "headers"), an empty line (a line with nothing before the carriage-return line-feed (CRLF)) that marks the end of the header fields, and an optional message-body. To avoid mixing them up with similarly named headers in HTTP, we call the headers that describe the message body entity headers ๐Ÿฆ‹. We break all of these parts down in the upcoming sections ๐Ÿ”ฅ.

generic-message  =  start-line
                    *message-header
                    CRLF
                    [ message-body ]

start-line       =  Request-Line |     ;Section 4.1
                    Status-Line        ;Section 5.1

message-header  =  ( general-header
                   | request-header
                   | response-header
                   | entity-header )

Robustness matters here ๐Ÿ›ก๏ธ. Any leading empty line(s) MUST be ignored. So if a Request or Response message starts with one or more CRLF, CR, or LF characters, those characters MUST be ignored ๐Ÿ˜ค.


4. Request โœจ

The Request message format looks like this ๐Ÿ’œ:

Request  =  Request-Line       ;  Section 4.1
            *( general-header
            | request-header
            | entity-header )
            CRLF
            [ message-body ]   ;  Section 8

4.1 Request-Line ๐Ÿ’–

okay so the Request-Line is the very first line of every request, and it's giving table of contents ๐Ÿงš. It starts with a method token, then the Request-URI, then the protocol version, and it ends with CRLF. Everything is separated by SP characters โœจ. ngl the big rule is no CR or LF allowed anywhere except that final CRLF, periodt ๐Ÿ’…

Request-Line  =  Method SP Request-URI SP SIP-Version CRLF

Here's the header menu, sorted into the buckets they live in ๐ŸŽ€

general-header   =  Accept               ; Section 6.7
                 |  Accept-Encoding      ; Section 6.8
                 |  Accept-Language      ; Section 6.9
                 |  Call-ID              ; Section 6.12
                 |  Contact              ; Section 6.13
                 |  CSeq                 ; Section 6.17
                 |  Date                 ; Section 6.18
                 |  Encryption           ; Section 6.19
                 |  Expires              ; Section 6.20
                 |  From                 ; Section 6.21
                 |  Record-Route         ; Section 6.29
                 |  Timestamp            ; Section 6.36
                 |  To                   ; Section 6.37
                 |  Via                  ; Section 6.40
entity-header    =  Content-Encoding     ; Section 6.14
                 |  Content-Length       ; Section 6.15
                 |  Content-Type         ; Section 6.16
request-header   =  Authorization        ; Section 6.11
                 |  Contact              ; Section 6.13
                 |  Hide                 ; Section 6.22
                 |  Max-Forwards         ; Section 6.23
                 |  Organization         ; Section 6.24
                 |  Priority             ; Section 6.25
                 |  Proxy-Authorization  ; Section 6.27
                 |  Proxy-Require        ; Section 6.28
                 |  Route                ; Section 6.33
                 |  Require              ; Section 6.30
                 |  Response-Key         ; Section 6.31
                 |  Subject              ; Section 6.35
                 |  User-Agent           ; Section 6.39
response-header  =  Allow                ; Section 6.10
                 |  Proxy-Authenticate   ; Section 6.26
                 |  Retry-After          ; Section 6.32
                 |  Server               ; Section 6.34
                 |  Unsupported          ; Section 6.38
                 |  Warning              ; Section 6.41
                 |  WWW-Authenticate     ; Section 6.42

Table 3: SIP headers


4.2 Methods ๐Ÿฆ‹

okay, the methods! ๐ŸŒธ Methods that aren't supported by a proxy or redirect server get treated by that server as if they were an OPTIONS method and forwarded accordingly. Methods that aren't supported by a user agent server or registrar cause a 501 (Not Implemented) response to be returned (Section 7). As in HTTP, the Method token is case-sensitive, so capitalisation matters bestie ๐Ÿ™ˆ

Method  =  "INVITE" | "ACK" | "OPTIONS" | "BYE"
           | "CANCEL" | "REGISTER"

4.2.1 INVITE ๐Ÿ’Œ

The INVITE method is how a user or service gets invited to join a session. The message body describes the session the callee is being invited to. For two-party calls, the caller says what kind of media it can receive, and maybe what it's willing to send too, along with details like the network destination. A success response MUST indicate in its message body which media the callee wishes to receive and MAY indicate the media the callee is going to send.

Not all session description formats have the ability to indicate sending media.

A server MAY automatically respond to an invitation for a conference the user is already in, identified either by the SIP Call-ID or by a globally unique identifier inside the session description, with a 200 (OK) response.

If a user agent receives an INVITE request for an existing call leg with a higher CSeq sequence number than any previous INVITE for the same Call-ID, it MUST check any version identifiers in the session description or, if there are no version identifiers, the content of the session description to see if it has changed. It MUST also inspect any other header fields for changes. If there is a change, the user agent MUST update any internal state or information generated as a result of that header. If the session description has changed, the user agent server MUST adjust the session parameters accordingly, possibly after asking the user for confirmation. (Versioning of the session description can be used to accommodate the capabilities of new arrivals to a conference, add or delete media or change from a unicast to a multicast conference.) โœจ

This method MUST be supported by SIP proxy, redirect and user agent servers as well as clients.

4.2.2 ACK ๐ŸŽ€

The ACK request confirms that the client has received a final response to an INVITE request. (ACK is only used with INVITE requests, fr fr.) 2xx responses get acknowledged by client user agents, and all other final responses get acknowledged by the first proxy or client user agent to receive the response. The Via is always initialized to the host that originates the ACK request, i.e., the client user agent after a 2xx response or the first proxy to receive a non-2xx final response. The ACK request is forwarded as the corresponding INVITE request, based on its Request-URI. See Section 10 for details.

The ACK request MAY contain a message body with the final session description to be used by the callee. If the ACK message body is empty, the callee uses the session description in the INVITE request.

A proxy server that gets an ACK request after having sent a 3xx, 4xx, 5xx, or 6xx response has to figure out whether the ACK is for itself or for some user agent or proxy server further downstream. It works this out by checking the tag in the To field. If the tag in the ACK To header field matches the tag in the To header field of the response, and the From, CSeq and Call-ID header fields in the response match those in the ACK, the ACK is meant for the proxy server. Otherwise, the ACK SHOULD be proxied downstream as any other request.

It is possible for a user agent client or proxy server to receive multiple 3xx, 4xx, 5xx, and 6xx responses to a request along a single branch. This can happen under various error conditions, typically when a forking proxy transitions from stateful to stateless before receiving all responses. The various responses will all be identical, except for the tag in the To field, which is different for each one. It can therefore be used as a means to disambiguate them.

This method MUST be supported by SIP proxy, redirect and user agent servers as well as clients.

4.2.3 OPTIONS ๐Ÿงš

This one is the "hey, what can you do?" request ๐ŸŒˆ The server is being asked about its capabilities. A server that believes it can contact the user, such as a user agent where the user is logged in and has been recently active, MAY respond to this request with a capability set. A called user agent MAY return a status reflecting how it would have responded to an invitation, e.g., 600 (Busy). Such a server SHOULD return an Allow header field indicating the methods that it supports. Proxy and redirect servers simply forward the request without indicating their capabilities.

This method MUST be supported by SIP proxy, redirect and user agent servers, registrars and clients.

4.2.4 BYE ๐Ÿ‘‹

The user agent client uses BYE to tell the server it wants to release the call. A BYE request is forwarded like an INVITE request and MAY be issued by either caller or callee. A party to a call SHOULD issue a BYE request before releasing a call ("hanging up") ๐Ÿ“ž A party receiving a BYE request MUST cease transmitting media streams specifically directed at the party issuing the BYE request.

If the INVITE request contained a Contact header, the callee SHOULD send a BYE request to that address rather than the From address.

This method MUST be supported by proxy servers and SHOULD be supported by redirect and user agent SIP servers.

4.2.5 CANCEL ๐Ÿšซ

The CANCEL request cancels a pending request with the same Call-ID, To, From and CSeq (sequence number only) header field values, but it does not affect a completed request. (A request counts as completed once the server has returned a final status response.)

A user agent client or proxy client MAY issue a CANCEL request at any time. A proxy, in particular, MAY choose to send a CANCEL to destinations that have not yet returned a final response after it has received a 2xx or 6xx response for one or more of the parallel-search requests. A proxy that receives a CANCEL request forwards the request to all destinations with pending requests.

The Call-ID, To, the numeric part of CSeq and From headers in the CANCEL request are identical to those in the original request. This lets a CANCEL request get matched with the request it cancels. However, so the client can tell responses to the CANCEL apart from responses to the original request, the CSeq Method component is set to CANCEL. The Via header field is initialized to the proxy issuing the CANCEL request. (So responses to this CANCEL request only reach the issuing proxy, bestie ๐Ÿฆ‹)

Once a user agent server has received a CANCEL, it MUST NOT issue a 2xx response for the cancelled original request.

A redirect or user agent server that receives a CANCEL request responds with a status of 200 (OK) if the transaction exists, and a status of 481 (Transaction Does Not Exist) if not, but it takes no further action. In particular, any existing call is unaffected.

The BYE request cannot be used to cancel branches of a parallel search, since several branches may, through intermediate proxies, find the same user agent server and then terminate the call. To terminate a call instead of just pending searches, the UAC must use BYE instead of or in addition to CANCEL. While CANCEL can terminate any pending request other than ACK or CANCEL, it is typically useful only for INVITE. 200 responses to INVITE and 200 responses to CANCEL are distinguished by the method in the Cseq header field, so there is no ambiguity.

This method MUST be supported by proxy servers and SHOULD be supported by all other SIP server types. ๐Ÿ’œ

4.2.6 REGISTER ๐ŸŽ€

okay so a client uses REGISTER to register the address listed in the To header field with a SIP server ๐Ÿ’… it's the whole "hey, I'm here, this is where to find me" moment โœจ

a user agent MAY register with a local server on startup by sending a REGISTER request to the well-known "all SIP servers" multicast address sip.mcast.net (224.0.1.75) ๐Ÿฆ‹ this request SHOULD be scoped so it doesn't get forwarded past the edge of the administrative system, and that MAY be done with either TTL or administrative scopes [25], depending on what the network supports ๐ŸŒธ SIP user agents MAY listen to that address and use it to find out where other local users are [20] ๐Ÿ‘€ but they do not respond to the request. a user agent MAY also be configured with the address of a registrar server, and then it sends a REGISTER request to that server on startup ๐Ÿซถ

requests get processed in the order they're received ๐Ÿ”ฅ clients SHOULD avoid sending a new registration (as opposed to a retransmission) until they've gotten the server's response to the previous one ๐Ÿ’œ

Clients may register from different locations, by necessity using different Call-ID values. Thus, the CSeq value cannot be used to enforce ordering. Since registrations are additive, ordering is less of a problem than if each REGISTER request completely replaced all earlier ones. ๐Ÿงš

the meaning of the REGISTER request-header fields goes like this ๐Ÿ’– we define "address-of-record" as the SIP address that the registry knows the registrand, typically of the form "user@domain" rather than "user@host" ๐Ÿ“ in third-party registration, the entity issuing the request is different from the entity being registered ๐Ÿ‘‘

To: the To header field contains the address-of-record whose registration is to be created or updated ๐ŸŽ€

From: the From header field contains the address-of-record of the person responsible for the registration. for first-party registration it's identical to the To header field value โœจ

Request-URI: the Request-URI names the destination of the registration request, i.e., the domain of the registrar ๐Ÿ’… the user name MUST be empty. generally the domains in the Request-URI and the To header field have the same value, but it's possible to register as a "visitor" while keeping your own name ๐Ÿฆ‹ for example, a traveler sip:alice@acme.com (To) might register under the Request-URI sip:atlanta.hiayh.org , with the former as the To header field and the latter as the Request-URI ๐ŸŒˆ the REGISTER request is no longer forwarded once it has reached the server whose authoritative domain is the one listed in the Request-URI ๐Ÿซถ

Call-ID: all registrations from a client SHOULD use the same Call-ID header value, at least within the same reboot cycle ๐Ÿ”ฅ

Cseq: registrations with the same Call-ID MUST have increasing CSeq header values ๐Ÿ’œ however, the server does not reject out-of-order requests ๐Ÿ˜ญ

Contact: the request MAY contain a Contact header field ๐ŸŽ€ future non-REGISTER requests for the URI given in the To header field SHOULD be directed to the address(es) given in the Contact header โœจ

if the request does not contain a Contact header, the registration remains unchanged ๐Ÿงš

This is useful to obtain the current list of registrations in the response. Registrations using SIP URIs that differ in one or more of host, port, transport-param or maddr-param (see Figure 3) from an existing registration are added to the list of registrations. Other URI types are compared according to the standard URI equivalency rules for the URI schema. If the URIs are equivalent to that of an existing registration, the new registration replaces the old one if it has a higher q value or, for the same value of q, if the ttl value is higher. All current registrations MUST share the same action value. Registrations that have a different action than current registrations for the same user MUST be rejected with status of 409 (Conflict). ๐Ÿ’€

a proxy server ignores the q parameter when processing non-REGISTER requests, while a redirect server simply returns that parameter in its Contact response header field ๐ŸŒธ

Having the proxy server interpret the q parameter is not sufficient to guide proxy behavior, as it is not clear, for example, how long it is supposed to wait between trying addresses. ๐Ÿ™ˆ

if the registration is changed while a user agent or proxy server processes an invitation, the new information SHOULD be used ๐Ÿ‘‘

This allows a service known as "directed pick-up". In the telephone network, directed pickup permits a user at a remote station who hears his own phone ringing to pick up at that station, dial an access code, and be connected to the calling user as if he had answered his own phone. ๐Ÿ“ž๐ŸŒˆ

a server MAY choose any duration for the registration lifetime ๐Ÿ’– registrations not refreshed after this amount of time SHOULD be silently discarded. responses to a registration SHOULD include an Expires header (Section 6.20) or expires Contact parameters (Section 6.13), indicating the time at which the server will drop the registration โญ if none is present, one hour is assumed. clients MAY request a registration lifetime by indicating the time in an Expires header in the request ๐Ÿฆ‹ a server SHOULD NOT use a higher lifetime than the one requested, but MAY use a lower one ๐Ÿ“ a single address (if host-independent) MAY be registered from several different clients ๐Ÿงš

a client cancels an existing registration by sending a REGISTER request with an expiration time (Expires) of zero seconds for a particular Contact, or the wildcard Contact designated by a "*" for all registrations ๐Ÿซถ registrations are matched based on the user, host, port and maddr parameters ๐ŸŽ€

the server SHOULD return the current list of registrations in the 200 response as Contact header fields โœจ

it is particularly important that REGISTER requests are authenticated, since they allow redirection of future requests (see Section 13.2) ๐Ÿ”ฅ

Beyond its use as a simple location service, this method is needed if there are several SIP servers on a single host. In that case, only one of the servers can use the default port number. ๐ŸŒˆ

support of this method is RECOMMENDED. ๐Ÿ’…


4.3 Request-URI ๐Ÿฆ‹

the Request-URI is a SIP URL as described in Section 2 or a general URI ๐Ÿ’œ it indicates the user or service to which this request is being addressed. unlike the To field, the Request-URI MAY be re-written by proxies ๐Ÿ‘‘

when used as a Request-URI, a SIP-URL MUST NOT contain the transport-param, maddr-param, ttl-param, or headers elements. a server that receives a SIP-URL with these elements removes them before further processing ๐Ÿซถ

Typically, the UAC sets the Request-URI and To to the same SIP URL, presumed to remain unchanged over long time periods. However, if the UAC has cached a more direct path to the callee, e.g., from the Contact header field of a response to a previous request, the To would still contain the long-term, "public" address, while the Request-URI would be set to the cached address. ๐ŸŽ€

proxy and redirect servers MAY use the information in the Request-URI and request header fields to handle the request, and possibly rewrite the Request-URI โœจ for example, a request addressed to the generic address sip:sales@acme.com is proxied to the particular person, e.g., sip:bob@ny.acme.com , with the To field remaining as sip:sales@acme.com. at ny.acme.com, Bob then designates Alice as the temporary substitute ๐Ÿ’–

the host part of the Request-URI typically agrees with one of the host names of the receiving server ๐Ÿงš if it does not, the server SHOULD proxy the request to the address indicated, or return a 404 (Not Found) response if it is unwilling or unable to do so ๐Ÿ“ for example, the Request-URI and server host name can disagree in the case of a firewall proxy that handles outgoing calls. this mode of operation is similar to that of HTTP proxies ๐Ÿฆ‹

if a SIP server receives a request with a URI indicating a scheme other than SIP which that server does not understand, the server MUST return a 400 (Bad Request) response ๐Ÿ˜ญ it MUST do this even if the To header field contains a scheme it does understand ๐Ÿ’€ this is because proxies are responsible for processing the Request-URI, and the To field is of end-to-end significance ๐ŸŒธ

4.3.1 SIP Version ๐ŸŒˆ

both request and response messages include the version of SIP in use, and follow [H3.1] (with HTTP replaced by SIP, and HTTP/1.1 replaced by SIP/2.0) regarding version ordering, compliance requirements, and upgrading of version numbers ๐Ÿ’… to be compliant with this specification, applications sending SIP messages MUST include a SIP-Version of "SIP/2.0" โญ


4.4 Option Tags ๐ŸŽ€

option tags are unique identifiers used to designate new options in SIP ๐Ÿ’– these tags are used in Require (Section 6.30) and Unsupported (Section 6.38) fields โœจ

syntax:

option-tag  =  token

see Section C for a definition of token. the creator of a new SIP option MUST either prefix the option with their reverse domain name or register the new option with the Internet Assigned Numbers Authority (IANA) ๐Ÿ”ฅ for example, "com.foo.mynewfeature" is an apt name for a feature whose inventor can be reached at "foo.com" ๐Ÿ‘‘ individual organizations are then responsible for ensuring that option names don't collide ๐Ÿซถ options registered with IANA have the prefix "org.iana.sip.", options described in RFCs have the prefix "org.ietf.rfc.N", where N is the RFC number ๐Ÿฆ‹ option tags are case-insensitive ๐Ÿงš

4.4.1 Registering New Option Tags with IANA ๐Ÿ“

when registering a new SIP option, the following information MUST be provided:

  • Name and description of option. The name MAY be of any length, but SHOULD be no more than twenty characters long. The name MUST consist of alphanum (See Figure 3) characters only.
  • Indication of who has change control over the option (for example, IETF, ISO, ITU-T, other international standardization bodies, a consortium or a particular company or group of companies).
  • A reference to a further description, if available, for example (in order of preference) an RFC, a published paper, a patent filing, a technical report, documented source code or a computer manual.
  • Contact information (postal and email address).

registrations should be sent to iana@iana.org ๐Ÿ’Œ

This procedure has been borrowed from RTSP [4] and the RTP AVP [26]. ๐ŸŒธ

5 Response ๐Ÿ’œ

after receiving and interpreting a request message, the recipient responds with a SIP response message ๐ŸŽ€ the response message format is shown below:

Response  =  Status-Line        ;  Section 5.1
             *( general-header
             | response-header
             | entity-header )
             CRLF
             [ message-body ]   ;  Section 8

SIP's structure of responses is similar to [H6], but is defined explicitly here ๐Ÿฆ‹

5.1 Status-Line โœจ

the first line of a Response message is the Status-Line ๐Ÿ’… it consists of the protocol version (Section 4.3.1) followed by a numeric Status-Code and its associated textual phrase, with each element separated by SP characters ๐Ÿ”ฅ no CR or LF is allowed except in the final CRLF sequence ๐Ÿซถ

Status-Line  =  SIP-version SP Status-Code SP Reason-Phrase CRLF

5.1.1 Status Codes and Reason Phrases โœจ

okay so the Status-Code is a 3-digit integer result code that tells you how it went when someone tried to understand and satisfy a request ๐Ÿ’– The Reason-Phrase is just a short bit of text describing that code. The Status-Code is for automata (aka machines ๐Ÿค–), and the Reason-Phrase is for the human user. The client is not required to examine or display the Reason-Phrase, so it can ignore that text if it wants ๐Ÿซถ

        Status-Code     =  Informational                     ;Fig. 5
                       |   Success                           ;Fig. 5
                       |   Redirection                       ;Fig. 6
                       |   Client-Error                      ;Fig. 7
                       |   Server-Error                      ;Fig. 8
                       |   Global-Failure                    ;Fig. 9
                       |   extension-code
        extension-code  =  3DIGIT
        Reason-Phrase   =  *<TEXT-UTF8,  excluding CR, LF>

Here's the vibe check ๐ŸŽ€ We give you an overview of the Status-Code right here, and the full definitions live in Section 7. The first digit tells you the class of the response. The last two digits have no categorization role at all, so don't read into them ๐Ÿ’… SIP/2.0 allows 6 values for the first digit:

  • 1xx: Informational, meaning the request was received and the server is still working on it ๐ŸŒธ
  • 2xx: Success, meaning the action was successfully received, understood, and accepted โœจ
  • 3xx: Redirection, meaning further action needs to be taken to complete the request ๐Ÿฆ‹
  • 4xx: Client Error, meaning the request has bad syntax or can't be fulfilled at this server ๐Ÿ™ˆ
  • 5xx: Server Error, meaning the server failed to fulfill a request that seemed totally valid ๐Ÿ’€
  • 6xx: Global Failure, meaning the request can't be fulfilled at any server ๐Ÿ˜ญ

Figures 5 through 9 show the individual values of the numeric response codes, plus an example set of matching reason phrases for SIP/2.0. These reason phrases are only recommended, and they may be replaced by local equivalents without affecting the protocol ๐ŸŒˆ Also, SIP borrows a lot of HTTP/1.1 response codes. SIP/2.0 adds response codes in the range starting at x80 so they don't clash with newly defined HTTP response codes, and it adds a whole new class, 6xx, of response codes. Iconic, honestly ๐Ÿ‘‘

SIP response codes are extensible, which is so cute ๐Ÿงš SIP applications don't have to understand the meaning of every registered response code, though understanding them is obviously desirable. HOWEVER, applications MUST understand the class of any response code, as shown by the first digit. They also need to treat any unrecognized response as the x00 response code of that class, with one exception: an unrecognized response MUST NOT be cached. For example, if a client gets an unrecognized response code of 431, it can safely assume something was wrong with its request and treat the response as if it had gotten a 400 (Bad Request) response code. In cases like that, user agents SHOULD present the message body returned with the response to the user, since that body is likely to include human-readable info explaining the unusual status ๐Ÿซถ Main character energy for the message body, fr fr ๐ŸŽ€

        Informational  =  "100"  ;  Trying
                      |   "180"  ;  Ringing
                      |   "181"  ;  Call Is Being Forwarded
                      |   "182"  ;  Queued
        Success        =  "200"  ;  OK

Figure 5: Informational and success status codes

        Redirection  =  "300"  ;  Multiple Choices
                    |   "301"  ;  Moved Permanently
                    |   "302"  ;  Moved Temporarily
                    |   "303"  ;  See Other
                    |   "305"  ;  Use Proxy
                    |   "380"  ;  Alternative Service

Figure 6: Redirection status codes

        Client-Error  =  "400"  ;  Bad Request
                     |   "401"  ;  Unauthorized
                     |   "402"  ;  Payment Required
                     |   "403"  ;  Forbidden
                     |   "404"  ;  Not Found
                     |   "405"  ;  Method Not Allowed
                     |   "406"  ;  Not Acceptable
                     |   "407"  ;  Proxy Authentication Required
                     |   "408"  ;  Request Timeout
                     |   "409"  ;  Conflict
                     |   "410"  ;  Gone
                     |   "411"  ;  Length Required
                     |   "413"  ;  Request Entity Too Large
                     |   "414"  ;  Request-URI Too Large
                     |   "415"  ;  Unsupported Media Type
                     |   "420"  ;  Bad Extension
                     |   "480"  ;  Temporarily not available
                     |   "481"  ;  Call Leg/Transaction Does Not Exist
                     |   "482"  ;  Loop Detected
                     |   "483"  ;  Too Many Hops
                     |   "484"  ;  Address Incomplete
                     |   "485"  ;  Ambiguous
                     |   "486"  ;  Busy Here

Figure 7: Client error status codes

        Server-Error  =  "500"  ;  Internal Server Error
                     |   "501"  ;  Not Implemented
                     |   "502"  ;  Bad Gateway
                     |   "503"  ;  Service Unavailable
                     |   "504"  ;  Gateway Time-out
                     |   "505"  ;  SIP Version not supported

Figure 8: Server error status codes


6 Header Field Definitions ๐Ÿ’œ

SIP header fields are similar to HTTP header fields in both syntax and semantics. In particular, SIP header fields follow the syntax for message-header as described in [H4.2]. The rules for extending header fields over multiple lines, and for using multiple message-header fields with the same field-name, described in [H4.2] also apply to SIP. Here's the Global Failure lineup ๐Ÿ‘‘

        Global-Failure |  "600"  ;  Busy Everywhere
                       |  "603"  ;  Decline
                       |  "604"  ;  Does not exist anywhere
                       |  "606"  ;  Not Acceptable

Figure 9: Global failure status codes

The rules in [H4.2] about ordering header fields apply to SIP too, except for Via fields (see below), whose order matters ๐Ÿฆ‹ Also, header fields that are hop-by-hop MUST appear before any header fields that are end-to-end. Proxies SHOULD NOT reorder header fields. Proxies add Via header fields and MAY add other hop-by-hop header fields. They can modify certain header fields, such as Max-Forwards (Section 6.23), and "fix up" the Via header fields with "received" parameters as described in Section 6.40.1. Proxies MUST NOT alter any fields that are authenticated (see Section 13.2). Don't touch the authenticated stuff, bestie ๐Ÿ”’๐Ÿซถ

The header fields that are required, optional, and not applicable for each method are listed in Table 4 and Table 5. The table uses "o" to indicate optional, "m" for mandatory, and "-" for not applicable. A "*" indicates that the header fields are needed only if the message body is not empty. See sections 6.15, 6.16 and 8 for details โœจ

The "where" column describes the request and response types that a header field can be used with. "R" refers to header fields that can be used in requests (that is, request and general header fields). "r" designates a response or general-header field that applies to all responses, while a list of numeric values indicates the status codes a header field can be used with. "g" and "e" designate general (Section 6.1) and entity header (Section 6.2) fields, respectively. If a header field is marked "c", it is copied from the request to the response ๐ŸŒธ

The "enc." column describes whether this message header field MAY be encrypted end-to-end. An "n" designates fields that MUST NOT be encrypted, while "c" designates fields that SHOULD be encrypted if encryption is used ๐Ÿ” The "e-e" column has a value of "e" for end-to-end and a value of "h" for hop-by-hop header fields.

                          where  enc.  e-e ACK BYE CAN INV OPT REG
        __________________________________________________________
        Accept              R           e   -   -   -   o   o   o
        Accept             415          e   -   -   -   o   o   o
        Accept-Encoding     R           e   -   -   -   o   o   o
        Accept-Encoding    415          e   -   -   -   o   o   o
        Accept-Language     R           e   -   o   o   o   o   o
        Accept-Language    415          e   -   o   o   o   o   o
        Allow              200          e   -   -   -   -   m   -
        Allow              405          e   o   o   o   o   o   o
        Authorization       R           e   o   o   o   o   o   o
        Call-ID            gc     n     e   m   m   m   m   m   m
        Contact             R           e   o   -   -   o   o   o
        Contact            1xx          e   -   -   -   o   o   -
        Contact            2xx          e   -   -   -   o   o   o
        Contact            3xx          e   -   o   -   o   o   o
        Contact            485          e   -   o   -   o   o   o
        Content-Encoding    e           e   o   -   -   o   o   o
        Content-Length      e           e   o   -   -   o   o   o
        Content-Type        e           e   *   -   -   *   *   *
        CSeq               gc     n     e   m   m   m   m   m   m
        Date                g           e   o   o   o   o   o   o
        Encryption          g     n     e   o   o   o   o   o   o
        Expires             g           e   -   -   -   o   -   o
        From               gc     n     e   m   m   m   m   m   m
        Hide                R     n     h   o   o   o   o   o   o
        Max-Forwards        R     n     e   o   o   o   o   o   o
        Organization        g     c     h   -   -   -   o   o   o

Table 4: Summary of header fields, A--O

Other header fields can be added as required, but a server MUST ignore header fields that aren't defined in this specification and that it doesn't understand. A proxy MUST NOT remove or modify header fields that aren't defined in this specification and that it doesn't understand. There's also a compact form of these header fields, defined in Section 9, for use over UDP when the request has to fit into a single packet and size is an issue ๐Ÿ“ฆโœจ

Table 6 in Appendix A lists those header fields that different client and server types MUST be able to parse ๐Ÿงš

6.1 General Header Fields ๐ŸŽ€

Okay bestie, general header fields apply to BOTH requests and responses ๐Ÿซถ Their names can only be extended reliably if the protocol version changes too ๐Ÿ’… Here's the P through Z chunk of the header field table, so brace yourself โœจ

    ___________________________________________________________________
    Proxy-Authenticate       407       n     h   o   o   o   o   o   o
    Proxy-Authorization       R        n     h   o   o   o   o   o   o
    Proxy-Require             R        n     h   o   o   o   o   o   o
    Priority                  R        c     e   -   -   -   o   -   -
    Require                   R              e   o   o   o   o   o   o
    Retry-After               R        c     e   -   -   -   -   -   o
    Retry-After          404,480,486   c     e   o   o   o   o   o   o
                             503       c     e   o   o   o   o   o   o
                           600,603     c     e   o   o   o   o   o   o
    Response-Key              R        c     e   -   o   o   o   o   o
    Record-Route              R              h   o   o   o   o   o   o
    Record-Route             2xx             h   o   o   o   o   o   o
    Route                     R              h   o   o   o   o   o   o
    Server                    r        c     e   o   o   o   o   o   o
    Subject                   R        c     e   -   -   -   o   -   -
    Timestamp                 g              e   o   o   o   o   o   o
    To                      gc(1)      n     e   m   m   m   m   m   m
    Unsupported              420             e   o   o   o   o   o   o
    User-Agent                g        c     e   o   o   o   o   o   o
    Via                     gc(2)      n     e   m   m   m   m   m   m
    Warning                   r              e   o   o   o   o   o   o
    WWW-Authenticate         401       c     e   o   o   o   o   o   o

Table 5: Summary of header fields, P--Z; (1): copied with possible addition of tag; (2): UAS removes first Via header field

Okay, one more vibe check ๐Ÿ’– Experimental header fields MAY be given the semantics of general header fields if all parties in the communication recognize them to be "general-header" fields ๐Ÿฆ‹ Unrecognized header fields are treated as "entity-header" fields ๐Ÿ’€

6.2 Entity Header Fields ๐Ÿงš

"Entity-header" fields are the meta-info crew ๐Ÿ“ฆ They describe the message-body or, if there's no body, the resource that the request is about ๐Ÿ’… Fun fact: "entity header" is an HTTP 1.1 term, where the response body can be a transformed version of the message body ๐ŸŒˆ The original message body is called the "entity" ๐Ÿซถ We keep the same terminology for header fields, but we usually just say "message body" instead of "entity", because in SIP the two are the same thing โœจ

6.3 Request Header Fields ๐ŸŒธ

"Request-header" fields let the client share extra info about the request, and about itself, with the server ๐Ÿ’– They act as request modifiers, kind of like the parameters you'd pass into a programming language method call ๐Ÿ’…

The "request-header" field names can be extended reliably only in combination with a change in the protocol version. However, new or experimental header fields MAY be given the semantics of "request-header" fields if all parties in the communication recognize them to be request-header fields. Unrecognized header fields are treated as "entity-header" fields. ๐Ÿฆ‹

6.4 Response Header Fields ๐Ÿ“

"Response-header" fields let the server pass along extra info about the response that couldn't fit in the Status-Line ๐Ÿซถ They tell you about the server and about further ways to access the resource named by the Request-URI ๐Ÿ‘‘

Response-header field names can be extended reliably only in combination with a change in the protocol version. However, new or experimental header fields MAY be given the semantics of "response-header" fields if all parties in the communication recognize them to be "response-header" fields. Unrecognized header fields are treated as "entity-header" fields. ๐Ÿ’œ

6.5 End-to-end and Hop-by-hop Headers ๐Ÿ”ฅ

Main character rule ๐Ÿ‘‘ End-to-end headers MUST be transmitted unmodified across all proxies, while hop-by-hop headers MAY be modified or added by proxies. Proxies get to touch the hop-by-hop ones, but the end-to-end ones are hands-off ๐Ÿ™ˆ

6.6 Header Field Format ๐ŸŽ€

Header fields ("general-header", "request-header", "response-header", and "entity-header") all follow the same generic header format as the one in Section 3.1 of RFC 822 [24] ๐Ÿ’… Each header field is a name, then a colon (":"), then the field value. Field names are case-insensitive โœจ The field value MAY be preceded by any amount of leading white space (LWS), though a single space (SP) is the fan favourite ๐ŸŒˆ Header fields can be stretched over multiple lines, as long as each extra line starts with at least one SP or horizontal tab (HT) ๐Ÿฆ‹ Applications MUST follow the HTTP "common form" when generating these constructs, because some implementations might only accept the common forms ๐Ÿ’€ Be nice to the old software, periodt ๐Ÿซถ

        message-header  =  field-name ":" [ field-value ] CRLF
        field-name      =  token
        field-value     =  *( field-content | LWS )
        field-content   =  < the OCTETs  making up the field-value
                            and consisting of either *TEXT-UTF8
                            or combinations of token,
                            separators, and quoted-string>

The relative order of header fields with different field names doesn't matter ๐Ÿ’– Multiple header fields with the same field-name may be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list (i.e., #(values)). It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, so a proxy MUST NOT change the order of these field values when a message is forwarded ๐Ÿ”ฅ The ordering is the tea โ˜•

Field names are not case-sensitive, although their values may be. ๐ŸŒธ

6.7 Accept ๐Ÿง

The Accept header follows the syntax defined in [H14.1] ๐Ÿ’… The semantics are identical too, with one exception: if there's no Accept header, the server SHOULD assume a default value of application/sdp โœจ

This request-header field is only used with the INVITE, OPTIONS and REGISTER request methods, to say which media types are acceptable in the response ๐Ÿฆ‹

Example, because we love a good example ๐Ÿ’–

  Accept: application/sdp;level=1, application/x-private, text/html

6.8 Accept-Encoding ๐ŸŒˆ

The Accept-Encoding request-header field is basically a sibling of Accept, but it restricts the content-codings [H3.4.1] that are acceptable in the response ๐Ÿซถ See [H14.3]. The syntax of this header is defined in [H14.3], and the semantics in SIP are identical to those defined in [H14.3] ๐Ÿ’…

6.9 Accept-Language ๐Ÿ“

The Accept-Language header follows the syntax defined in [H14.4] ๐ŸŒธ The rules for ordering languages by the q parameter apply to SIP too ๐Ÿ’œ When used in SIP, the Accept-Language request-header field lets the client tell the server which language it would prefer to receive reason phrases, session descriptions or status responses carried as message bodies ๐Ÿฆ‹ A proxy MAY use this field to help pick the destination for the call, for example a human operator who speaks a language the caller speaks ๐Ÿ‘‘

Example:

  Accept-Language: da, en-gb;q=0.8, en;q=0.7

6.10 Allow ๐Ÿ’…

The Allow entity-header field lists the set of methods supported by the resource identified by the Request-URI ๐Ÿงš Its purpose is strictly to tell the recipient which methods are valid for that resource โœจ An Allow header field MUST be present in a 405 (Method Not Allowed) response and SHOULD be present in an OPTIONS response ๐Ÿ”ฅ

  Allow  =  "Allow" ":" 1#Method

6.11 Authorization ๐Ÿซถ

A user agent that wants to authenticate itself with a server (usually, but not necessarily, after getting a 401 response) MAY do so by including an Authorization request-header field with the request ๐Ÿ” The Authorization field value holds credentials with the user agent's authentication info for the realm of the resource being requested ๐Ÿ’–

Section 13.2 gives you the overview of the Authorization header, and section 15 covers the syntax and semantics when it's used with PGP based authentication ๐ŸŒˆ Keep scrolling, there's more โœจ

6.12 Call-ID ๐Ÿ“ž

okay bestie, the Call-ID general-header field is the unique ID for one particular invitation, or for all the registrations of one particular client ๐Ÿ†”โœจ it's giving main character identifier. ngl a single multimedia conference can end up with several calls that each have different Call-IDs, like if a user invites the same person a bunch of times to the same long-running conference ๐ŸŽ€

For an INVITE request, a callee user agent server SHOULD NOT alert the user if the user has already responded to the Call-ID in the INVITE request ๐Ÿ™ˆ If the user is already a member of the conference and the conference parameters in the session description haven't changed, a callee user agent server MAY silently accept the call, regardless of the Call-ID ๐Ÿฆ‹ An invitation for an existing Call-ID or session can change the parameters of the conference. A client application MAY decide to simply tell the user that the conference parameters have changed and accept the invitation automatically, or it MAY require user confirmation ๐Ÿ’…

A user can be invited to the same conference or call using several different Call-IDs. If it's wanted, the client MAY use identifiers within the session description to detect this duplication ๐Ÿ” For example, SDP contains a session id and version number in the origin (o) field.

The REGISTER and OPTIONS methods use the Call-ID value to unambiguously match requests and responses ๐ŸŽฏ All REGISTER requests issued by a single client SHOULD use the same Call-ID, at least within the same boot cycle.

Since the Call-ID is generated by and for SIP, there is no reason to deal with the complexity of URL-encoding and case-ignoring string comparison. ๐Ÿ™Œ
Call-ID   =  ( "Call-ID" | "i" ) ":" local-id "@" host
local-id  =  1*uric

host SHOULD be either a fully qualified domain name or a globally routable IP address ๐ŸŒ If this is the case, the local-id SHOULD be an identifier made of URI characters that is unique within host. Using cryptographically random identifiers [27] is RECOMMENDED ๐Ÿ” If, however, host is not an FQDN or globally routable IP address (such as a net 10 address), the local-id MUST be globally unique, as opposed to unique within host. These rules guarantee overall global uniqueness of the Call-ID โœจ The value for Call-ID MUST NOT be reused for a different call. Call-IDs are case-sensitive, so capitalisation matters ๐Ÿง

Using cryptographically random identifiers provides some protection against session hijacking. Call-ID, To and From are needed to identify a call leg. The distinction between call and call leg matters in calls with third-party control. ๐Ÿ•ต๏ธโ€โ™€๏ธ

For systems with tight bandwidth constraints, many of the mandatory SIP headers have a compact form, as discussed in Section 9 ๐Ÿค These are alternate names for the headers that take up less space in the message. For Call-ID, the compact form is i. For example, both of the following are valid:

Call-ID: f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com

or

i:f81d4fae-7dec-11d0-a765-00a0c91e6bf6@foo.bar.com

6.13 Contact ๐Ÿ“‡

the Contact general-header field can show up in INVITE, ACK, and REGISTER requests, and in 1xx, 2xx, 3xx, and 485 responses ๐Ÿ’– In general, it gives a URL where the user can be reached for further communication. literally the "slide into my DMs" header ๐Ÿ’Œ

INVITE and ACK requests: INVITE and ACK requests MAY contain Contact headers showing where the request is coming from.

This lets the callee send future requests, such as BYE, directly to the caller instead of going through a series of proxies ๐Ÿš€ The Via header isn't enough, since the address you want might be that of a proxy.

INVITE 2xx responses: A user agent server sending a definitive, positive response (2xx) MAY insert a Contact response header field showing the SIP address where it can be reached most directly for future SIP requests, such as ACK, within the same Call-ID ๐ŸŽฏ The Contact header field has the address of the server itself or that of a proxy, for example if the host is behind a firewall ๐Ÿงฑ The value of this Contact header is copied into the Request-URI of subsequent requests for this call if the response did not also contain a Record-Route header. If the response also contains a Record-Route header field, the address in the Contact header field is added as the last item in the Route header field. See Section 6.29 for details.

The Contact value SHOULD NOT be cached across calls, since it may not be the most desirable location for a particular destination address ๐Ÿ™…โ€โ™€๏ธ

INVITE 1xx responses: A UAS sending a provisional response (1xx) MAY insert a Contact response header. It has the same meaning in a 1xx response as in a 2xx INVITE response ๐Ÿค Note that CANCEL requests MUST NOT be sent to that address, but should instead follow the same path as the original request ๐Ÿ›‘

REGISTER requests: REGISTER requests MAY contain a Contact header field showing the locations where the user can be reached ๐Ÿ“ The REGISTER request defines a wildcard Contact field, "*", which MUST only be used with Expires: 0 to remove all registrations for a particular user ๐Ÿงน An optional "expires" parameter gives the desired expiration time of the registration. If a Contact entry doesn't have an "expires" parameter, the Expires header field is used as the default value. If neither of these mechanisms is used, SIP URIs are assumed to expire after one hour โฐ Other URI schemes have no expiration times.

REGISTER 2xx responses: A REGISTER response MAY return all the locations where the user is currently reachable ๐Ÿ“ฌ An optional "expires" parameter gives the expiration time of the registration. If a Contact entry doesn't have an "expires" parameter, the value of the Expires header field gives the expiration time. If neither mechanism is used, the expiration time specified in the request, explicitly or by default, is used.

3xx and 485 responses: The Contact response-header field can be used with a 3xx or 485 (Ambiguous) response code to show one or more alternate addresses to try ๐Ÿ—บ๏ธ It can appear in responses to BYE, INVITE and OPTIONS methods. The Contact header field has URIs giving the new locations or user names to try, or it may just give extra transport parameters. A 300 (Multiple Choices), 301 (Moved Permanently), 302 (Moved Temporarily) or 485 (Ambiguous) response SHOULD contain a Contact field with URIs of new addresses to be tried. A 301 or 302 response may also give the same location and username that was being tried, but with extra transport parameters such as a different server or multicast address to try, or a change of SIP transport from UDP to TCP or vice versa ๐Ÿ”„ The client copies the "user", "password", "host", "port" and "user-param" elements of the Contact URI into the Request-URI of the redirected request, and directs the request to the address given by the "maddr" and "port" parameters, using the transport protocol given in the "transport" parameter ๐Ÿงญ If "maddr" is a multicast address, the value of "ttl" is used as the time-to-live value.

Note that the Contact header field MAY also refer to a different entity than the one originally called ๐Ÿ“ข For example, a SIP call connected to a GSTN gateway may need to play a special announcement such as "The number you have dialed has been changed."

A Contact response header field can contain any suitable URI showing where the called party can be reached, and it isn't limited to SIP URLs ๐ŸŒˆ For example, it could contain URLs for phones, fax, or irc (if they were defined), or a mailto: (RFC 2368, [28]) URL.

The following parameters are defined. Additional parameters may be defined in other specifications ๐Ÿงฉ

  • q: The "qvalue" shows the relative preference among the locations given. "qvalue" values are decimal numbers from 0 to 1, with higher values meaning higher preference ๐Ÿ’ฏ
  • action: The "action" parameter is only used when registering with the REGISTER request. It shows whether the client wants the server to proxy or redirect future requests meant for the client ๐Ÿ”€ If this parameter isn't specified, the action taken depends on server configuration. In its response, the registrar SHOULD indicate the mode used. This parameter is ignored for other requests.
  • expires: The "expires" parameter shows how long the URI is valid. The parameter is either a number of seconds or a quoted string containing a SIP-date โŒ› If this parameter isn't provided, the value of the Expires header field decides how long the URI is valid. Implementations MAY treat values larger than 232-1 (4294967295 seconds or 136 years) as equivalent to 232-1. ๐Ÿคฏ
Contact = ( "Contact" | "m" ) ":"
          ("*" | (1# (( name-addr | addr-spec )
          [ *( ";" contact-params ) ] [ comment ] )))

name-addr      = [ display-name ] "<" addr-spec ">"
addr-spec      = SIP-URL | URI
display-name   = *token | quoted-string

contact-params = "q"       "=" qvalue
               | "action"  "=" "proxy" | "redirect"
               | "expires" "=" delta-seconds | <"> SIP-date <">
               | extension-attribute

extension-attribute = extension-name [ "=" extension-value ]
Only one address is allowed, unquoted. Since URIs can contain commas and semicolons as reserved characters, they could be mistaken for header or parameter delimiters, respectively. The current syntax matches the one for the To and From header, which also allows display names. ๐Ÿง

Example:

Contact: "Mr. Watson" <sip:watson@worcester.bell-telephone.com>
   ;q=0.7; expires=3600,
   "Mr. Watson" <mailto:watson@bell-telephone.com> ;q=0.1

6.14 Content-Encoding ๐ŸŽ

        Content-Encoding  =  ( "Content-Encoding" | "e" ) ":"
                             1#content-coding

The Content-Encoding entity-header field is a modifier to the "media-type" ๐Ÿ’… When it's present, its value shows what extra content codings have been applied to the entity-body, and so what decoding mechanisms MUST be applied to get the media-type referenced by the Content-Type header field. Content-Encoding is mainly used to let a body be compressed without losing the identity of its underlying media type ๐Ÿ—œ๏ธ

If multiple encodings have been applied to an entity, the content codings MUST be listed in the order in which they were applied ๐Ÿ“‹

All content-coding values are case-insensitive ๐Ÿ”ค The Internet Assigned Numbers Authority (IANA) acts as a registry for content-coding value tokens. See [3.5] for a definition of the syntax for content-coding.

Clients MAY apply content encodings to the body in requests ๐Ÿ“ค If the server can't decode the body, or doesn't recognise any of the content-coding values, it MUST send a 415 "Unsupported Media Type" response, listing acceptable encodings in the Accept-Encoding header ๐Ÿ™…โ€โ™€๏ธ A server MAY apply content encodings to the bodies in responses ๐Ÿ“ฅ The server MUST only use encodings listed in the Accept-Encoding header in the request. ๐Ÿซถ

6.15 Content-Length ๐ŸŽ€

okay so Content-Length is an entity-header field, and its whole job is telling the recipient how big the message-body is, in decimal octets. ๐Ÿ“โœจ

Content-Length  =  ( "Content-Length" | "l" ) ":" 1*DIGIT

here's an example bestie ๐Ÿซถ

Content-Length: 3495

so applications SHOULD use this field to show the size of the message-body being sent, no matter what media type the entity is ๐Ÿ’… any Content-Length that's zero or bigger is valid. if there's no body at all, the Content-Length header field MUST be set to zero ๐Ÿ™ˆ

now the UDP stuff is kinda wild ๐Ÿ˜ญ if a server gets a UDP request with no Content-Length, it MUST assume the request covers the rest of the packet. but if a server gets a UDP request with a Content-Length that's bigger than the body that actually came through, the client SHOULD generate a 400 class response. and if there's extra data in the UDP packet after the body has been read, the server MUST treat that leftover data as a separate message. this is how you can stack several messages into one single UDP packet, iconic ๐Ÿงš

if a response doesn't have a Content-Length, the client just assumes it covers the rest of the UDP packet, or everything until the TCP connection closes, depending on which one applies. Section 8 explains how to figure out the length of the message body.

6.16 Content-Type ๐ŸŒธ

the Content-Type entity-header field says what media type the message-body is, for the recipient ๐Ÿฆ‹ the "media-type" element is defined in [H3.7].

Content-Type  =  ( "Content-Type" | "c" ) ":" media-type

some examples, slay ๐Ÿ’–

Content-Type: application/sdp
Content-Type: text/html; charset=ISO-8859-4

6.17 CSeq ๐Ÿ‘‘

this one is so important, bestie ๐Ÿ˜ญ clients MUST add the CSeq (command sequence) general-header field to every request. a CSeq header in a request has the request method plus one decimal sequence number that the requesting client picks, and it has to be unique within one value of Call-ID. the sequence number MUST be expressible as a 32-bit unsigned integer. the starting value is arbitrary, but it MUST be less than 2**31. requests in a row that differ in method, headers or body, but share the same Call-ID, MUST have strictly monotonically increasing and contiguous sequence numbers, and they never wrap around ๐Ÿ”ฅ retransmissions of the same request keep the same sequence number, but an INVITE with a different body or different headers (a "re-invitation") gets a new, higher one. a server MUST echo the CSeq value from the request in its response. if the Method value is missing from the CSeq header, the server fills it in properly ๐Ÿ’…

the ACK and CANCEL requests MUST have the same CSeq value as the INVITE they refer to, while a BYE request that cancels an invitation MUST have a higher sequence number. a BYE with a CSeq that isn't higher should cause a 400 response ๐Ÿ™ˆ

a user agent server MUST remember the highest sequence number for any INVITE with the same Call-ID value. it MUST respond to, and then discard, any INVITE with a lower sequence number. main character energy for the server ngl ๐Ÿ‘‘

all requests spun off from a parallel search have the same CSeq value as the request that started the parallel search โœจ

CSeq  =  "CSeq" ":" 1*DIGIT Method
strictly speaking, CSeq header fields are needed for any SIP request that can be cancelled by a BYE or CANCEL request, or where a client can send several requests for the same Call-ID really close together. without a sequence number, the response to an INVITE could get mistaken for the response to the cancellation (BYE or CANCEL). also, if the network duplicates packets, or an ACK gets delayed until the server has already sent another response, the client could read an old response as the answer to a re-invitation sent just after. using CSeq also makes it easy for the server to tell different versions of an invitation apart, without comparing the message body ๐Ÿซถ

the Method value lets the client tell the response to an INVITE apart from the response to a CANCEL ๐ŸŒˆ CANCEL requests can be generated by proxies, and if they increased the sequence number, it could clash with a later request the user agent sends for the same call ๐Ÿ˜ญ

with 32 bits, a server could make one request a second, within a single call, for about 136 years before it needs to wrap around ๐Ÿคฏ that's why the starting value is picked so that requests within the same call won't wrap around. a non-zero starting value lets you use a time-based initial sequence number, if the client wants one. for example, a client could take the 31 most significant bits of a 32-bit second clock as its starting sequence number ๐Ÿงš

forked requests MUST have the same CSeq, otherwise there'd be ambiguity between those forked requests and a later BYE sent by the client user agent ๐Ÿ™…โ€โ™€๏ธ

example time ๐Ÿ“

CSeq: 4711 INVITE

6.18 Date ๐ŸŒˆ

Date is a general-header field, and its syntax is:

SIP-date  =  rfc1123-date

see [H14.19] for what rfc1123-date means. but note this bit ๐Ÿ‘€ unlike HTTP/1.1, SIP only supports the most recent RFC1123 [29] formatting for dates.

the Date header field shows when the request or response is first sent, so retransmissions have the same Date value as the original ๐Ÿ’œ

simple end systems that don't have a battery-backed clock can use the Date header field to get a sense of the current time ๐Ÿ•ฐ๏ธ

6.19 Encryption ๐Ÿ”

the Encryption general-header field says the content has been encrypted ๐Ÿซฃ Section 13 describes the overall SIP security architecture and algorithms. this header is meant for end-to-end encryption of requests and responses. requests get encrypted using the public key of the entity named in the To header field, and responses get encrypted using the public key sent in the Response-Key header field. the public keys themselves might not be used for the encryption, and that depends on which algorithms are in play.

for any encrypted message, at least the message body and maybe some other header fields get encrypted. an app that gets a request or response with an Encryption header decrypts the body, then sticks the plaintext onto the request line and headers of the original message. headers in the decrypted part completely replace the ones with the same field name in the plaintext part. (psst: if only the body is encrypted, the body has to be prefixed with CRLF so the concatenation works right ๐Ÿ™ˆ) the request method and Request-URI can't be encrypted, though ๐Ÿ™…โ€โ™€๏ธ

Encryption only gives you privacy. the recipient has no guarantee that the request or response came from the party in the From message header, only that the sender used the recipient's public key. proxies still won't be able to modify the request or response, though ๐Ÿ”’
Encryption         =  "Encryption" ":" encryption-scheme 1*SP
                      #encryption-params
encryption-scheme  =  token
encryption-params  =  token "=" ( token | quoted-string )

the token shows which form of encryption is used, and section 13 covers it ๐Ÿ’–

the example in Figure 10 is a message encrypted with ASCII-armored PGP, made by running "pgp -ea" on the payload that needs encrypting โœจ

INVITE sip:watson@boston.bell-telephone.com SIP/2.0
Via: SIP/2.0/UDP 169.130.12.5
From: <sip:a.g.bell@bell-telephone.com>
To: T. A. Watson <sip:watson@bell-telephone.com>
Call-ID: 187602141351@worcester.bell-telephone.com
Content-Length: 885
Encryption: PGP version=2.6.2,encoding=ascii

hQEMAxkp5GPd+j5xAQf/ZDIfGD/PDOM1wayvwdQAKgGgjmZWe+MTy9NEX8O25Red
h0/pyrd/+DV5C2BYs7yzSOSXaj1C/tTK/4do6rtjhP8QA3vbDdVdaFciwEVAcuXs
ODxlNAVqyDi1RqFC28BJIvQ5KfEkPuACKTK7WlRSBc7vNPEA3nyqZGBTwhxRSbIR
RuFEsHSVojdCam4htcqxGnFwD9sksqs6LIyCFaiTAhWtwcCaN437G7mUYzy2KLcA
zPVGq1VQg83b99zPzIxRdlZ+K7+bAnu8Rtu+ohOCMLV3TPXbyp+err1YiThCZHIu
X9dOVj3CMjCP66RSHa/ea0wYTRRNYA/G+kdP8DSUcqYAAAE/hZPX6nFIqk7AVnf6
IpWHUPTelNUJpzUp5Ou+q/5P7ZAsn+cSAuF2YWtVjCf+SQmBR13p2EYYWHoxlA2/
GgKADYe4M3JSwOtqwU8zUJF3FIfk7vsxmSqtUQrRQaiIhqNyG7KxJt4YjWnEjF5E
WUIPhvyGFMJaeQXIyGRYZAYvKKklyAJcm29zLACxU5alX4M25lHQd9FR9Zmq6Jed
wbWvia6cAIfsvlZ9JGocmQYF7pcuz5pnczqP+/yvRqFJtDGD/v3s++G2R+ViVYJO
z/lxGUZaM4IWBCf+4DUjNanZM0oxAE28NjaIZ0rrldDQmO8V9FtPKdHxkqA5iJP+
6vGOFti1Ak4kmEz0vM/Nsv7kkubTFhRl05OiJIGr9S1UhenlZv9l6RuXsOY/EwH2
z8X9N4MhMyXEVuC9rt8/AUhmVQ==
=bOW+

Figure 10: PGP Encryption Example ๐Ÿฆ‹

since proxies can base forwarding decisions on any combo of SIP header fields, there's no guarantee that an encrypted request "hiding" header fields will reach the same destination as an otherwise identical un-encrypted request ๐Ÿซ 


6.20 Expires โณ

the Expires entity-header field gives the date and time after which the message content expires ๐Ÿ•ฐ๏ธ

right now this header is only defined for the REGISTER and INVITE methods. for REGISTER, it's both a request and response-header field. in a REGISTER request, the client says how long it wants the registration to stay valid. in the response, the server says the earliest expiration time of all the registrations. the server MAY pick a shorter interval than the client asked for, but it SHOULD NOT pick a longer one ๐Ÿ’…

for INVITE requests, it's also a request and response-header field. in a request, the caller can limit how long an invitation is valid, like if a client wants to cap how long a search or a conference invitation lasts. a user interface MAY take this as a hint to keep the invitation window on screen even when the user isn't at the workstation. it also limits how long a search lasts. if the request expires before the search finishes, the proxy returns a 408 (Request Timeout) status. in a 302 (Moved Temporarily) response, a server can tell the client the maximum duration of the redirection ๐ŸŒธ

the value of this field can be either a SIP-date or an integer number of seconds (in decimal), counted from when the request was received. the integer is better for short durations, because it doesn't depend on clients and servers sharing a synchronized clock ๐Ÿง  implementations MAY treat values larger than 232-1 (4294967295 or 136 years) as equivalent to 232-1.

Expires  =  "Expires" ":" ( SIP-date | delta-seconds )

two examples of how it's used ๐Ÿ“

Expires: Thu, 01 Dec 1994 16:00:00 GMT
Expires: 5

6.21 From ๐Ÿ’–

okay so every request and response MUST have a From general-header field ๐Ÿซถ It tells everyone who started the request. The From field MAY contain the tag parameter ๐ŸŽ€ When the server gets a request, it copies the From header from the request into the response, so the response always knows who sent it โœจ The optional display-name is meant to be shown in a human-facing UI ๐Ÿ‘€ And if the client wants to stay hidden, a system SHOULD show the display name Anonymous ๐Ÿ™ˆ that's giving privacy vibes ๐Ÿ•ถ๏ธ

A SIP-URL MUST NOT contain the transport-param, maddr-param, ttl-param, or headers elements ๐Ÿšซ If a server gets one with those bits in it, it strips them out before doing anything else ๐Ÿงน

Even if the display-name is totally empty ๐Ÿซฅ, you MUST use the name-addr form whenever the addr-spec has a comma, question mark, or semicolon in it. no excuses ๐Ÿ’…

From         =  ( "From" | "f" ) ":" ( name-addr | addr-spec )
                *( ";" addr-params )
addr-params  =  tag-param
tag-param    =  "tag=" UUID
UUID         =  1*( hex | "-" )

Examples:

From: "A. G. Bell" <sip:agb@bell-telephone.com>
From: sip:+12125551212@server.phone2net.com
From: Anonymous <sip:c8oqz84zk7z@privacy.org>

The tag MAY show up in the From field of a request ๐Ÿ’Œ but it MUST be there when two instances of a user sharing one SIP address could send invites with the same Call-ID ๐Ÿ‘ฏ

The tag value MUST be globally unique AND cryptographically random, with at least 32 bits of randomness ๐ŸŽฒ A single user keeps the same tag for the whole call identified by the Call-ID ๐Ÿ”

Call-ID, To and From are needed to identify a call leg. The distinction between call and call leg matters in calls with multiple responses to a forked request. The format is similar to the equivalent RFC 822 [24] header, but with a URI instead of just an email address. ๐Ÿฆ‹

6.22 Hide ๐Ÿ™ˆ

A client uses the Hide request header field to say it wants the path made up of the Via header fields (Section 6.40) hidden from subsequent proxies and user agents ๐Ÿ•ต๏ธโ€โ™€๏ธ It comes in two flavours: Hide: route and Hide: hop. Hide header fields are usually added by the client user agent, but any proxy along the path MAY add them too ๐Ÿ›ค๏ธ

If a request has the Hide: route header field, all following proxies SHOULD hide their previous hop ๐Ÿซฃ If a request has the Hide: hop header field, only the next proxy SHOULD hide the previous hop, and then it removes the Hide option unless it also wants to stay anonymous ๐ŸŽญ

A server hides the previous hop by encrypting the "host" and "port" parts of the top-most Via header field, using whatever algorithm it likes ๐Ÿ”’ Servers SHOULD add extra "salt" to the "host" and "port" info before encrypting, so sneaky downstream proxies can't guess earlier parts of the path from seeing identical encrypted Via headers ๐Ÿง‚ Hidden Via fields get marked with the "hidden" Via option, as described in Section 6.40 ๐Ÿท๏ธ

A server that can hide Via headers MUST try to decrypt every Via header marked "hidden" to do loop detection ๐Ÿ” Servers that can't hide can just ignore hidden Via fields in their loop detection algorithm ๐Ÿคทโ€โ™€๏ธ

If hidden headers were not marked, a proxy would have to decrypt all headers to detect loops, just in case one was encrypted, as the Hide: Hop option may have been removed along the way. ๐Ÿซ 

A host MUST NOT add a "Hide: hop" header field unless it can guarantee it will only send requests for this destination to the same next hop ๐Ÿšง The reason is that the request could loop right back through this same hop from a downstream proxy. The loop gets caught by the next hop if the choice of next hop is fixed, but otherwise it could loop an arbitrary number of times ๐ŸŒ€

A client asking for "Hide: route" can only count on keeping the request path private if it sends the request to a trusted proxy ๐Ÿค Hiding the route of a SIP request is kinda pointless if the request ends up with data packets going directly between the calling and called user agent ๐Ÿ™ƒ

The use of Hide header fields is discouraged unless path privacy is truly needed ๐Ÿ™…โ€โ™€๏ธ Hide fields add extra processing costs and restrictions for proxies, and they can make requests generate 482 (Loop Detected) responses that could have been avoided anyway ๐Ÿ’€

The encryption of Via header fields is described in more detail in Section 13 ๐Ÿ“–

The Hide header field has the following syntax:

Hide  =  "Hide" ":" ( "route" | "hop" )

6.23 Max-Forwards โณ

The Max-Forwards request-header field can be used with any SIP method to limit how many proxies or gateways can forward the request to the next downstream server ๐Ÿšฆ It's also handy when a client is trying to trace a request chain that seems to be failing or looping in the middle ๐Ÿ”Ž

Max-Forwards  =  "Max-Forwards" ":" 1*DIGIT

The Max-Forwards value is a decimal integer showing how many more times this request message is allowed to be forwarded ๐Ÿ”ข

Every proxy or gateway that receives a request with a Max-Forwards header field MUST check and update its value before forwarding the request ๐Ÿงฎ If the received value is zero (0), the recipient MUST NOT forward the request. Instead, for the OPTIONS and REGISTER methods, it MUST respond as the final recipient. For all other methods, the server returns 483 (Too many hops) ๐Ÿ›‘

If the received Max-Forwards value is greater than zero, then the forwarded message MUST contain an updated Max-Forwards field, with the value decremented by one (1) โž–

Example:

Max-Forwards: 6

6.24 Organization ๐Ÿข

The Organization general-header field tells you the name of the organization that the entity issuing the request or response belongs to ๐Ÿซ It MAY also be inserted by proxies at the boundary of an organization ๐Ÿงฑ

The field MAY be used by client software to filter calls. ๐Ÿ“ต
Organization  =  "Organization" ":" *TEXT-UTF8

6.25 Priority ๐Ÿšจ

The Priority request-header field shows how urgent the request is, as the client sees it ๐Ÿƒโ€โ™€๏ธ

Priority        =  "Priority" ":" priority-value
priority-value  =  "emergency" | "urgent" | "normal"
                |  "non-urgent"

It is RECOMMENDED that the value "emergency" only gets used when life, limb or property are in imminent danger ๐Ÿ†˜ Save it for the real emergencies, bestie ๐Ÿ˜ญ

Examples:

Subject: A tornado is heading our way!
Priority: emergency

Subject: Weekend plans
Priority: non-urgent
These are the values of RFC 2076 [30], with the addition of "emergency". ๐Ÿ“š

6.26 Proxy-Authenticate ๐Ÿ”

The Proxy-Authenticate response-header field MUST be included as part of a 407 (Proxy Authentication Required) response ๐ŸŽซ The field value is a challenge that tells the client the authentication scheme and parameters that apply to the proxy for this Request-URI ๐Ÿงพ

Unlike how it works in HTTP, the Proxy-Authenticate header MUST be passed upstream in the response to the UAC ๐Ÿ”ผ In SIP, only UAC's can authenticate themselves to proxies, so it's a one-way street ๐Ÿ›ฃ๏ธ

The syntax for this header is defined in [H14.33]. See 14 for further details on its usage ๐Ÿ“

A client SHOULD cache the credentials it used for a particular proxy server and realm, for the next request to that server ๐Ÿ—„๏ธ Credentials are generally valid for a specific value of the Request-URI at a particular proxy server ๐ŸŽฏ If a client contacts a proxy that required authentication in the past, but the client doesn't have credentials for that particular Request-URI, it MAY try the most-recently used credential ๐Ÿคž The server responds with 401 (Unauthorized) if the client guessed wrong ๐Ÿ™ˆ

This suggested caching behavior is motivated by proxies restricting phone calls to authenticated users. It seems likely that in most cases, all destinations require the same password. Note that end-to-end authentication is likely to be destination-specific. ๐Ÿง 

6.27 Proxy-Authorization ๐Ÿชช

The Proxy-Authorization request-header field lets the client identify itself (or its user) to a proxy that requires authentication ๐Ÿ™‹โ€โ™€๏ธ The Proxy-Authorization field value holds credentials with the user agent's authentication info for the proxy and/or the realm of the resource being requested ๐Ÿ—๏ธ

Unlike Authorization, the Proxy-Authorization header field only applies to the next outbound proxy that asked for authentication using the Proxy- Authenticate field ๐Ÿ‘‰ When multiple proxies are chained together, the first outbound proxy that was expecting credentials is the one that consumes the Proxy-Authorization header field ๐Ÿฝ๏ธ A proxy MAY relay the credentials from the client request to the next proxy, if that's how the proxies work together to authenticate a request ๐Ÿค

See [H14.34] for a definition of the syntax, and section 14 for a discussion of its usage ๐Ÿ“–


6.28 Proxy-Require ๐Ÿงฉ

The Proxy-Require header field is used to flag proxy-sensitive features that MUST be supported by the proxy ๐Ÿ› ๏ธ Any Proxy-Require features the proxy doesn't support MUST be negatively acknowledged to the client by the proxy, if they aren't supported ๐Ÿ™…โ€โ™€๏ธ Proxy servers treat this field exactly the same as the Require field ๐Ÿ‘ฏ

See Section 6.30 for more details on how this message works and a usage example ๐ŸŽ€


6.29 Record-Route ๐Ÿ—บ๏ธ

The Record-Route request and response header field gets added to a request by any proxy that insists on staying in the path of subsequent requests for the same call leg ๐Ÿ›ฃ๏ธ It holds a globally reachable Request-URI that identifies the proxy server, and each proxy server adds its Request-URI to the beginning of the list ๐Ÿ“

The server copies the Record-Route header field unchanged into the response. (Record-Route is only relevant for 2xx responses.) โœ…

The calling user agent client copies the Record-Route header into a Route header field of subsequent requests within the same call leg, but reverses the order so the first entry is closest to the user agent client ๐Ÿ”„ If the response had a Contact header field, the calling user agent adds its content as the last Route header ๐Ÿ“ฌ Unless that would cause a loop, any client MUST send subsequent requests for this call leg to the first Request-URI in the Route request header field, and remove that entry ๐Ÿš€

The calling user agent MUST NOT use the Record-Route header field in requests that contain Route header fields ๐Ÿ™…โ€โ™€๏ธ

Some proxies, such as those controlling firewalls or in an automatic call distribution (ACD) system, need to maintain call state and thus need to receive any BYE and ACK packets for the call. ๐Ÿงš

The Record-Route header field has the following syntax:

Record-Route  =  "Record-Route" ":" 1# name-addr

Proxy servers SHOULD use the "maddr" URL parameter containing their address, so subsequent requests are guaranteed to reach exactly the same server ๐Ÿ“

Example for a request that has traversed the hosts ieee.org and bell-telephone.com, in that order:

Record-Route: <sip:a.g.bell@bell-telephone.com>,
  <sip:a.bell@ieee.org>

6.30 Require โœจ

okay so Require is how a client gives a heads-up to the user agent server: "hey, I'm counting on you to support these options, so please tell me if you can't." If the server doesn't understand an option, it MUST respond with status code 420 (Bad Extension) and list the options it doesn't understand in the Unsupported header. ๐Ÿ™ˆ

        Require  =  "Require" ":" 1#option-tag

Here's an example ๐Ÿ’…

C->S:   INVITE sip:watson@bell-telephone.com SIP/2.0
        Require: com.example.billing
        Payment: sheep_skins, conch_shells

S->C:   SIP/2.0 420 Bad Extension
        Unsupported: com.example.billing

the whole point is keeping things speedy ๐Ÿƒโ€โ™€๏ธ๐Ÿ’จ when both sides understand every option, the interaction just flows with no delay. It only slows down when something isn't understood (like in the example above). For a well-matched client-server pair, it's super quick, and it saves a round-trip that negotiation mechanisms often need. It also clears up confusion when a client needs a feature the server doesn't understand. Some features, like call handling fields, only matter to end systems ๐ŸŽ€

Proxy and redirect servers MUST ignore features that they don't understand. If an extension needs intermediate devices to support it, the extension MUST also be tagged in the Proxy-Require field (see Section 6.28). ๐Ÿฆ‹


6.31 Response-Key

The Response-Key request-header field lets a client ask for the key that the called user agent SHOULD use to encrypt the response with ๐Ÿ” Here's the syntax:

     Response-Key  =  "Response-Key" ":" key-scheme 1*SP #key-param
     key-scheme    =  token
     key-param     =  token "=" ( token | quoted-string )

The "key-scheme" tells you what type of encryption to use for the response. Section 13 describes security schemes. ๐Ÿ’œ

If the client really insists on getting an encrypted response, it includes this header field in its request:

               Require: org.ietf.sip.encrypt-response

If the server can't encrypt for whatever reason, it MUST follow the normal Require header field procedures and return a 420 (Bad Extension) response. If this Require header field isn't there, a server SHOULD still encrypt if it can. ๐ŸŒธ


6.32 Retry-After

Retry-After is a general-header field that comes with a 503 (Service Unavailable) response to say how long the service will be down for the requesting client ๐Ÿ•ฐ๏ธ It also shows up with a 404 (Not Found), 600 (Busy), or 603 (Decline) response to say when the called party expects to be back. The value can be either a SIP-date or a number of seconds (in decimal) counted from the time of the response.

A REGISTER request MAY include this header field when it deletes registrations with Contact: * ;expires: 0. The Retry-After value then shows when the user might be reachable again. After that, the registrar MAY include this info in responses to future calls. ๐Ÿงš

You can add an optional comment with more details about when to call back. There's also an optional "duration" parameter that says how long the called party will be reachable, starting from the first available time. If there's no duration parameter, the service is assumed to be available indefinitely โœจ

     Retry-After  =  "Retry-After" ":" ( SIP-date | delta-seconds )
                     [ comment ] [ ";" "duration" "=" delta-seconds ]

Here are some examples of how it's used ๐Ÿ‘‘

  Retry-After: Mon, 21 Jul 1997 18:48:34 GMT (I'm in a meeting)
  Retry-After: Mon, 01 Jan 9999 00:00:00 GMT
    (Dear John: Don't call me back, ever)
  Retry-After: Fri, 26 Sep 1997 21:00:00 GMT;duration=3600
  Retry-After: 120

In the third example, the callee is reachable for one hour, starting at 21:00 GMT. In the last example, the delay is 2 minutes. โฐ๐Ÿ˜ญ


6.33 Route

The Route request-header field decides which route a request takes ๐Ÿ—บ๏ธ Each host removes the first entry, then proxies the request to the host listed in that entry, and it also uses that entry as the Request-URI. You can read more about how this works in Section 6.29.

The Route header field has this syntax:

     Route  =  "Route" ":" 1# name-addr

6.34 Server

The Server response-header field tells you about the software the user agent server used to handle the request ๐Ÿ–ฅ๏ธ The syntax for this field is defined in [H14.39].


6.35 Subject

This field is meant to give a summary of the call, or to say what kind of call it is. That way, you can filter calls without having to parse the session description ๐Ÿ“ž (Also, the session description doesn't have to use the same subject as the invitation. Plot twist ๐Ÿ™ˆ)

     Subject  =  ( "Subject" | "s" ) ":" *TEXT-UTF8

Example:

   Subject: Tune in - they are talking about your work!

6.36 Timestamp

The timestamp general-header field says when the client sent the request to the server โฑ๏ธ Only the client really cares about the value, so it MAY use any timescale it likes. The server MUST echo the exact same value. If it has accurate info about this, it MAY also add a floating point number showing how many seconds have passed since it got the request. The client uses the timestamp to figure out the round-trip time to the server, so it can tune its timeout for retransmissions. ๐Ÿ”

     Timestamp  =  "Timestamp" ":" *(DIGIT) [ "." *(DIGIT) ] [ delay ]
     delay      =  *(DIGIT) [ "." *(DIGIT) ]

Quick note: there MUST NOT be any LWS between a DIGIT and the decimal point. ๐Ÿ™…โ€โ™€๏ธ


6.37 To

The To general-header field says who the request is for, and it uses the same SIP URL syntax as the From field ๐Ÿ’Œ

     To  =  ( "To" | "t" ) ":" ( name-addr | addr-spec )
            *( ";" addr-params )

Requests and responses MUST contain a To general-header field, which shows the intended recipient of the request. The optional "display-name" is meant to be shown in a human-facing interface. The UAS or redirect server copies the To header field into its response, and it MUST add a "tag" parameter if the request had more than one Via header field.

Here's the deal with that last part: if there was more than one Via header field, at least one proxy server handled the request. The receiver can't know whether any proxy forked the request, so it's safest to assume that they might have. ๐Ÿค”

The SIP-URL MUST NOT contain the "transport-param", "maddr-param", "ttl-param", or "headers" elements. If a server gets a SIP-URL with any of these, it removes them before doing anything else. ๐Ÿงน

The "tag" parameter is a general way to tell apart multiple instances of a user who has one SIP URL. Since proxies can fork requests, the same request can reach several instances of a user (like a mobile phone and a home phone, for example). Each one can respond, so the caller needs a way to tell those responses apart. Multicast requests can end up in this situation too. The tag in the To header field is what lets the UAC tell responses apart. It MUST be placed in the To field of the response by each instance when there's a chance the request was forked at an intermediate proxy. The "tag" MUST be added by UAS, registrars, and redirect servers, but it MUST NOT be inserted into responses that proxies forward upstream. The "tag" gets added to all definitive responses for all methods, and it MAY be added to informational responses from a UAS or redirect server. All subsequent transactions between two entities MUST include the "tag" parameter, as described in Section 11. ๐Ÿท๏ธ

See Section 6.21 for the details on the "tag" parameter.

The "tag" parameter in To headers gets ignored when matching responses to requests that didn't have a "tag" in their To header.

A SIP server returns a 400 (Bad Request) response if it gets a request with a To header field containing a URI whose scheme it doesn't recognize. ๐Ÿšซ

Even if the "display-name" is empty, the "name-addr" form MUST be used if the "addr-spec" contains a comma, question mark, or semicolon. ๐Ÿ’…

Here are some valid To headers:

  To: The Operator <sip:operator@cs.columbia.edu>;tag=287447
  To: sip:+12125551212@server.phone2net.com

Call-ID, To, and From are what identify a call leg ๐Ÿ“Ž The difference between a call and a call leg matters when a forked request gets several responses. The "tag" gets added to the To header in the response so proxies can fork future requests for the same call, while still addressing only one of the possibly several responding user agent servers. It also lets several instances of the callee send requests that can be told apart. ๐Ÿ’–


6.38 Unsupported

The Unsupported response-header field lists the features the server doesn't support. Check out Section 6.30 for a usage example and the reasoning behind it ๐Ÿ™Œ

Syntax:

     Unsupported  =  "Unsupported" ":" 1#option-tag

6.39 User-Agent

The User-Agent general-header field tells you about the client user agent that started the request ๐Ÿ“ฑ The syntax and semantics are defined in [H14.42].


6.40 Via

The Via field shows the path the request has taken so far ๐Ÿ›ค๏ธ This stops requests from looping forever, and it makes sure replies take the same path as the requests. That helps with firewall traversal and other unusual routing situations. ๐Ÿฆ‹๐ŸŒˆ

6.40.1 Requests ๐ŸŽ€

okay so the client that starts the request MUST slap a Via field on it with its host name or network address, plus the port it wants responses sent to if that's not the default port number. (heads up: that response port can be different from the UDP source port of the request ๐Ÿ‘€) A fully-qualified domain name is RECOMMENDED. Every proxy that passes the request onward MUST add its own Via field before any existing ones ๐Ÿ’…. And if a proxy gets a redirection (3xx) response and then searches recursively, it MUST use the same Via headers as on the original proxied request ๐Ÿงš

A proxy SHOULD check the top-most Via header field to make sure it has the sender's correct network address, as that proxy sees it ๐Ÿ”. If the sender's address is wrong, the proxy MUST add an extra "received" attribute, which is described in 6.40.2.

okay this part is the NAT tea โ˜•๐Ÿซถ. A host behind a network address translator (NAT) or firewall might not be able to put an address in the Via header that the next hop past the NAT can actually reach. The received attribute lets SIP requests get through NATs that only change the source IP address. NATs that also change port numbers, called Network Address Port Translators (NAPT), won't pass SIP properly over UDP, so you'd need an application layer gateway ๐Ÿ’€. Over TCP, SIP has a better shot at getting through NATs, since it acts kind of like HTTP in this case (just on different ports, obvs) ๐ŸŒธ

A proxy sending a request to a multicast address MUST add the "maddr" parameter to its Via header field, and SHOULD add the "ttl" parameter โœจ. If a server gets a request with a "maddr" parameter in the topmost Via field, it SHOULD send the response to the multicast address listed in that "maddr" parameter ๐Ÿ“ก.

If a proxy server gets a request that has its own address in the Via header value, it MUST respond with a 482 (Loop Detected) status code ๐Ÿ”.

A proxy server MUST NOT forward a request to a multicast group that already shows up in any of the Via headers ๐Ÿšซ.

this is how we stop a malfunctioning proxy from causing loops ๐Ÿ”. And it's not always possible for a proxy to notice that an address returned by a location service refers to a host already listed in the Via list. A single host can have aliases or several network interfaces, so it's kinda tricky ๐Ÿ™ˆ.

6.40.2 Receiver-tagged Via Header Fields ๐Ÿฆ‹

Normally, every host that sends or forwards a SIP message adds a Via field showing the path it took ๐Ÿ›ค๏ธ. But NATs can change the source address and port of the request (for example, from net-10 to a globally routable address). When that happens, the Via header field can't be relied on to route replies ๐Ÿ˜ญ. To fix this, a proxy SHOULD check the top-most Via header field to make sure it has the sender's correct network address, as that proxy sees it. If the sender's address is incorrect, the proxy MUST add a "received" parameter to the Via header field inserted by the previous hop ๐ŸŽฏ. That modified Via header field is known as a receiver-tagged Via header field. Here's an example:

Via: SIP/2.0/UDP erlang.bell-telephone.com:5060
Via: SIP/2.0/UDP 10.0.0.1:5060 ;received=199.172.136.3

In this example, the message came from 10.0.0.1 and went through a NAT with the external address border.ieee.org (199.172.136.3) to reach erlang.bell-telephone.com. The latter noticed the mismatch and added a parameter to the previous hop's Via header field, containing the address the packet actually came from ๐Ÿ•ต๏ธโ€โ™€๏ธ. (Note that the NAT border.ieee.org is not a SIP server.)

6.40.3 Responses ๐Ÿ’Œ

Via header fields in responses get processed by a proxy or UAC using these rules:

  1. The first Via header field should indicate the proxy or client processing this response. If it doesn't, discard the message. Otherwise, remove this Via field ๐Ÿ—‘๏ธ.
  2. If there's no second Via header field, this response is destined for this client ๐Ÿ’–. Otherwise, what happens next depends on whether that Via field has a "maddr" parameter or is a receiver-tagged field:
    • If the second Via header field contains a "maddr" parameter, send the response to the multicast address listed there, using the port indicated in "sent-by", or port 5060 if none is present. The response SHOULD be sent using the TTL indicated in the "ttl" parameter, or with a TTL of 1 if that parameter isn't present. For robustness, responses MUST be sent to the address indicated in the "maddr" parameter even if it isn't a multicast address ๐ŸŒˆ.
    • If the second Via header field does not contain a "maddr" parameter and is a receiver-tagged field (Section 6.40.2), send the message to the address in the "received" parameter, using the port indicated in the "sent-by" value, or using port 5060 if none is present ๐Ÿฆ‹.
    • If neither of the previous cases apply, send the message to the address indicated by the "sent-by" value in the second Via header field ๐Ÿ“ฌ.

6.40.4 User Agent and Redirect Servers ๐Ÿงšโ€โ™€๏ธ

A UAS or redirect server sends a response based on one of the following rules:

  • If the first Via header field in the request contains a "maddr" parameter, send the response to the multicast address listed there, using the port indicated in "sent-by", or port 5060 if none is present. The response SHOULD be sent using the TTL indicated in the "ttl" parameter, or with a TTL of 1 if that parameter isn't present. For robustness, responses MUST be sent to the address indicated in the "maddr" parameter even if it isn't a multicast address ๐Ÿ“ก.
  • If the address in the "sent-by" value of the first Via field differs from the source address of the packet, send the response to the actual packet source address, similar to the treatment for receiver-tagged Via header fields (Section 6.40.2) ๐ŸŽ€.
  • If neither of these conditions is true, send the response to the address contained in the "sent-by" value. If the request was sent using TCP, use the existing TCP connection if it's available ๐Ÿค.

6.40.5 Syntax ๐ŸŒธ

The format for a Via header field is shown in Fig. 11 ๐Ÿ“. The defaults for "protocol-name" and "transport" are "SIP" and "UDP", respectively. The "maddr" parameter (which designates the multicast address) and the "ttl" parameter (which designates the time-to-live (TTL) value) are only included if the request was sent via multicast ๐Ÿ“ก. The "received" parameter is only added for receiver-added Via fields (Section 6.40.2). For privacy reasons, a client or proxy may want to hide its Via information by encrypting it (see Section 6.22) ๐Ÿ™ˆ. The "hidden" parameter is included if this header field was hidden by the upstream proxy (see 6.22). Note that the privacy of the proxy relies on the cooperation of the next hop, because the next-hop proxy will, by necessity, know the IP address and port number of the source host ๐Ÿซฃ.

The "branch" parameter is included by every forking proxy ๐Ÿ“. The token MUST be unique for each distinct request generated when a proxy forks. CANCEL requests MUST have the same branch value as the corresponding forked request ๐Ÿ’œ. When a response arrives at the proxy, it can use the branch value to figure out which branch the response corresponds to ๐Ÿงฉ. A proxy which generates a single request (non-forking) MAY also insert the "branch" parameter. The identifier only has to be unique within a set of isomorphic requests โœจ.

Here's an example:

Via: SIP/2.0/UDP first.example.com:4000;ttl=16
  ;maddr=224.2.0.1 ;branch=a7c6a8dlze (Example)
Via: SIP/2.0/UDP adk8

And here's the grammar:

Via              = ( "Via" | "v") ":" 1#( sent-protocol sent-by
                   *( ";" via-params ) [ comment ] )
via-params       = via-hidden | via-ttl | via-maddr
                 | via-received | via-branch
via-hidden       = "hidden"
via-ttl          = "ttl" "=" ttl
via-maddr        = "maddr" "=" maddr
via-received     = "received" "=" host
via-branch       = "branch" "=" token
sent-protocol    = protocol-name "/" protocol-version "/" transport
protocol-name    = "SIP" | token
protocol-version = token
transport        = "UDP" | "TCP" | token
sent-by          = ( host [ ":" port ] ) | ( concealed-host )
concealed-host   = token
ttl              = 1*3DIGIT     ; 0 to 255

Figure 11: Syntax of Via header field ๐Ÿ’…

6.41 Warning ๐Ÿฆ‹

okay so the Warning header is the response's way of spilling extra tea about how its status is going ๐Ÿ’… it carries additional information about the status of a response, and warning headers are always sent with responses. the format is:

Warning        =  "Warning" ":" 1#warning-value
warning-value  =  warn-code SP warn-agent SP warn-text
warn-code      =  3DIGIT
warn-agent     =  ( host [ ":" port ] ) | pseudonym
                  ;  the name or pseudonym of the server adding
                  ;  the Warning header, for use in debugging
warn-text      =  quoted-string

A response MAY carry more than one Warning header, so you can stack the tea โ˜•โœจ

The warn-text should be in a natural language that's most likely to be intelligible to the human user receiving the response ๐ŸŒธ you can figure that out from whatever you know, like where the cache or user is, the Accept-Language field in a request, or the Content-Language field in a response. the default language is i-default [31].

Any server MAY add Warning headers to a response. Proxy servers MUST place additional Warning headers before any Authorization headers ๐Ÿ” and within that rule, Warning headers MUST be added after any existing Warning headers that aren't covered by a signature. a proxy server MUST NOT delete any Warning header field it received with a response. no deleting the receipts, periodt ๐Ÿ’…

when there are multiple Warning headers on a response, the user agent SHOULD display as many of them as it can, in the order they appear in the response. if it can't show them all, it shows the warnings that appear early in the response first ๐Ÿซถ

the warn-code is three digits. a first digit of "3" means the warning is specific to SIP ๐Ÿฆ‹

here's the list of currently-defined warn-codes. each one has a recommended English warn-text and a meaning. these warnings describe failures caused by the session description, so keep that in mind ๐Ÿ‘€

  • 300 to 329 are reserved for problems with keywords in the session description
  • 330 to 339 are for warnings about basic network services requested in the session description
  • 370 to 379 are for warnings about quantitative QoS parameters requested in the session description
  • 390 to 399 are miscellaneous warnings that don't fit into any of the above categories
  • 300 Incompatible network protocol: one or more network protocols in the session description aren't available.
  • 301 Incompatible network address formats: one or more network address formats in the session description aren't available.
  • 302 Incompatible transport protocol: one or more transport protocols in the session description aren't available.
  • 303 Incompatible bandwidth units: one or more bandwidth measurement units in the session description weren't understood.
  • 304 Media type not available: one or more media types in the session description aren't available.
  • 305 Incompatible media format: one or more media formats in the session description aren't available.
  • 306 Attribute not understood: one or more of the media attributes in the session description aren't supported.
  • 307 Session description parameter not understood: a parameter other than the ones listed above wasn't understood.
  • 330 Multicast not available: the site where the user is located doesn't support multicast.
  • 331 Unicast not available: the site where the user is located doesn't support unicast communication (usually because of a firewall).
  • 370 Insufficient bandwidth: the bandwidth specified in the session description, or defined by the media, is more than what's known to be available.
  • 399 Miscellaneous warning: the warning text can include arbitrary information to show a human user or to log. a system that receives this warning MUST NOT take any automated action ๐Ÿ™ˆ
the 1xx and 2xx codes are already taken by HTTP/1.1, so SIP doesn't use them here ๐ŸŽ€

more warn-codes, like the example below, can be defined through IANA ๐Ÿงš

here are the examples:

Warning: 307 isi.edu "Session parameter 'foo' not understood"
Warning: 301 isi.edu "Incompatible network address type 'E.164'"

6.42 WWW-Authenticate ๐Ÿ”

the WWW-Authenticate response-header field MUST be included in 401 (Unauthorized) response messages, no exceptions bestie ๐Ÿ˜ญ its value is made of at least one challenge that names the authentication scheme(s) and parameters that apply to the Request-URI. see [H14.46] for the syntax definition, and section 14 for an overview of how it's used.

the content of the "realm" parameter SHOULD be displayed to the user ๐Ÿ’œ a user agent SHOULD also cache the authorization credentials for a given value of the destination (To header) and "realm", and try to re-use those values on the next request to that destination. main character caching energy โœจ

on top of the "basic" and "digest" schemes from the specs cited above, SIP defines a new scheme, PGP (RFC 2015, [32]), Section 15 ๐ŸŒˆ other schemes, like S/MIME, are for further study ๐Ÿ‘€


7 Status Code Definitions ๐ŸŒˆ

the response codes are consistent with HTTP/1.1 response codes, and they extend them. not every HTTP/1.1 response code is appropriate, so only the appropriate ones are listed here. other HTTP/1.1 response codes SHOULD NOT be used ๐Ÿ™…โ€โ™€๏ธ response codes that HTTP/1.1 doesn't define get codes x80 and up, so they won't clash with future HTTP response codes. SIP also adds a brand-new class, 6xx ๐Ÿ”ฅ the default behavior for unknown response codes is given for each category.

7.1 Informational 1xx โœจ

informational responses say the server or proxy you contacted is still doing something and doesn't have a final answer yet. the client SHOULD wait for a further response from the server, and the server SHOULD send one without needing to be prompted ๐Ÿซถ a server SHOULD send a 1xx response if it expects to take more than 200 ms to get a final response. a server MAY send zero or more 1xx responses, with no rules about their ordering or uniqueness.

note that 1xx responses aren't transmitted reliably, which means they don't make the client send an ACK ๐Ÿฆ‹ servers are free to retransmit informational responses, and clients can check on the state of call processing by re-sending the request.

7.1.1 100 Trying ๐Ÿงš

some unspecified action is being taken on behalf of this call (like a database being consulted), but the user hasn't been located yet ๐Ÿ”

7.1.2 180 Ringing ๐Ÿ””

the called user agent found a possible location where the user has registered recently, and it's trying to alert the user ๐Ÿ“ž

7.1.3 181 Call Is Being Forwarded ๐Ÿ“

a proxy server MAY use this status code to say the call is being forwarded to a different set of destinations โœˆ๏ธ

7.1.4 182 Queued ๐ŸŽ€

the called party is temporarily unavailable, but the callee decided to queue the call instead of rejecting it ๐Ÿ’… when the callee becomes available, it returns the appropriate final status response. the reason phrase MAY give more details about the call's status, like "5 calls queued; expected waiting time is 15 minutes" ๐Ÿ˜ญ the server MAY send several 182 responses to keep the caller updated on the queued call.

7.2 Successful 2xx ๐Ÿ’–

the request was successful and MUST terminate a search. iconic ๐Ÿ‘‘

7.2.1 200 OK ๐Ÿ’…

the request has succeeded ๐ŸŽ‰ what comes back depends on the method used in the request:

  • BYE: the call has been terminated. the message body is empty.
  • CANCEL: the search has been cancelled. the message body is empty.
  • INVITE: the callee has agreed to participate, and the message body shows the callee's capabilities.
  • OPTIONS: the callee has agreed to share its capabilities, which are included in the message body.
  • REGISTER: the registration has succeeded. the client treats the message body according to its Content-Type.

7.3 Redirection 3xx ๐Ÿฆ‹

3xx responses tell you about the user's new location, or about alternative services that might be able to handle the call. they SHOULD terminate an existing search, and they MAY cause the initiator to start a new search if that makes sense ๐Ÿงญ

any redirection (3xx) response MUST NOT suggest any of the addresses in the Via (Section 6.40) path of the request in the Contact header field. (addresses match if their host and port number match ๐Ÿ’œ)

to avoid forwarding loops, a user agent client or proxy MUST check whether the address returned by a redirect server equals an address it already tried earlier. no going in circles, bestie ๐Ÿ”

7.3.1 300 Multiple Choices ๐ŸŒธ

the address in the request resolved to several choices, each with its own specific location, and the user (or user agent) can pick a preferred communication end point and redirect the request there ๐Ÿ’…

the response SHOULD include an entity with a list of resource characteristics and location(s) so the user or user agent can pick the one that fits best, if the Accept request header allows it. the entity format is set by the media type in the Content-Type header field. the choices SHOULD also be listed as Contact fields (Section 6.13). unlike HTTP, the SIP response MAY contain several Contact fields, or a list of addresses in one Contact field ๐Ÿ™Œ user agents MAY use the Contact header field value for automatic redirection, or MAY ask the user to confirm a choice. this specification doesn't define any standard for that automatic selection though ๐Ÿคทโ€โ™€๏ธ

this status response is appropriate if the callee can be reached at several different locations and the server can't, or would rather not, proxy the request ๐ŸŽ€

7.3.2 301 Moved Permanently ๐Ÿ 

the user can no longer be found at the address in the Request-URI, so the requesting client SHOULD retry at the new address given by the Contact header field (Section 6.13). the caller SHOULD update any local directories, address books, and user location caches with this new value, and send future requests to the address(es) listed ๐Ÿ“’

7.3.3 302 Moved Temporarily โณ

the requesting client SHOULD retry the request at the new address(es) given by the Contact header field (Section 6.13). the length of the redirection can be shown with an Expires (Section 6.20) header. if there's no explicit expiration time, the address is only valid for this call, and it MUST NOT be cached for future calls ๐Ÿซฃ

7.3.4 305 Use Proxy ๐Ÿšช

the requested resource MUST be accessed through the proxy given by the Contact field. the Contact field gives the URI of the proxy, and the recipient is expected to repeat this single request via that proxy ๐Ÿงš 305 responses MUST only be generated by user agent servers.

7.3.5 380 Alternative Service ๐ŸŒˆ

the call wasn't successful, but alternative services are possible ๐Ÿ’ซ those alternative services are described in the message body of the response. formats for those bodies aren't defined here, and may be the subject of future standardization ๐Ÿ‘€

7.4 Request Failure 4xx ๐Ÿ’€

4xx responses are definite failure responses from one particular server ๐Ÿ™…โ€โ™€๏ธ the client SHOULD NOT retry the same request without modifying it (for example, by adding appropriate authorization). however, the same request sent to a different server might work ๐Ÿซถ

7.4.1 400 Bad Request ๐Ÿ™ˆ

the request couldn't be understood because of malformed syntax. the vibes were just off ๐Ÿ˜ญ

7.4.2 401 Unauthorized ๐Ÿ”

the request requires user authentication, so show your ID, bestie ๐Ÿชช

7.4.3 402 Payment Required ๐Ÿ’ธ

reserved for future use ๐Ÿ”ฎ

7.4.4. 403 Forbidden ๐Ÿ™…โ€โ™€๏ธ

Okay so 403 is the server basically saying "I see you, I get what you asked for, and nope." ๐Ÿ’… Logging in again won't fix it, so the request SHOULD NOT be repeated. ๐Ÿšซ

7.4.5. 404 Not Found ๐Ÿ‘ป

The server has definitive info that the user doesn't exist at the domain in the Request-URI. ๐Ÿ˜ถ It also gets sent if the domain in the Request-URI doesn't match any of the domains the recipient handles. Total ghosting. ๐Ÿ’€

7.4.6. 405 Method Not Allowed ๐Ÿšท

The method in the Request-Line isn't allowed for the address in the Request-URI. The response MUST include an Allow header field listing the valid methods for that address. ๐Ÿ“‹

7.4.7. 406 Not Acceptable ๐Ÿฅฒ

The resource can only make response entities with content characteristics that don't match the accept headers sent in the request. Not the vibe. ๐Ÿ™ƒ

7.4.8. 407 Proxy Authentication Required ๐Ÿ”

This one is kinda like 401 (Unauthorized), but the client MUST first authenticate itself with the proxy. ๐Ÿซ  The proxy MUST return a Proxy-Authenticate header field (section 6.26) with a challenge that applies to the proxy for the requested resource. The client MAY repeat the request with a suitable Proxy-Authorization header field (section 6.27). SIP access authentication is explained in section 13.2 and 14. ๐Ÿ“–

This status code is used for apps where access to the communication channel (like a telephony gateway) needs authentication, instead of the callee. ๐Ÿ“ž

7.4.9. 408 Request Timeout โฐ

The server couldn't produce a response (for example, a user location) within the time indicated in the Expires request-header field. The client MAY repeat the request without modifications at any later time. ๐Ÿ”

7.4.10. 409 Conflict ๐Ÿ’ฅ

The request couldn't be completed because it clashes with the current state of the resource. This response comes back if the action parameter in a REGISTER request conflicts with existing registrations. Drama. ๐ŸŽญ

7.4.11. 410 Gone ๐Ÿชฆ

The requested resource is no longer available at the server, and no forwarding address is known. This is expected to be permanent. ๐Ÿ˜” If the server doesn't know, or has no way to figure out, whether the condition is permanent, 404 (Not Found) SHOULD be used instead. ๐Ÿซถ

7.4.12. 411 Length Required ๐Ÿ“

The server won't accept the request without a defined Content-Length. ๐Ÿ™… The client MAY repeat the request if it adds a valid Content-Length header field containing the length of the message-body in the request message. Fix it and try again, bestie. ๐Ÿ’–

7.4.13. 413 Request Entity Too Large ๐Ÿ˜

The server is refusing to process the request because the request entity is bigger than the server is willing or able to handle. ๐Ÿ˜ฉ The server MAY close the connection so the client can't keep going with the request.

If the condition is temporary, the server SHOULD include a Retry-After header field to show that it's temporary and after what time the client MAY try again. โณ

7.4.14. 414 Request-URI Too Long ๐Ÿ“œ

The server is refusing to service the request because the Request-URI is longer than the server is willing to read. That's a lot of text, babe. ๐Ÿ™ˆ

7.4.15. 415 Unsupported Media Type ๐ŸŽž๏ธ

The server won't service the request because the message body is in a format the requested resource doesn't support for the requested method. ๐Ÿ˜ค The server SHOULD return a list of acceptable formats using the Accept, Accept-Encoding and Accept-Language header fields. Helpful, iykyk. ๐ŸŒธ

7.4.16. 420 Bad Extension ๐Ÿงฉ

The server didn't understand the protocol extension named in a Require (Section 6.30) header field. Confusing, but at least it's honest. ๐Ÿคทโ€โ™€๏ธ

7.4.17. 480 Temporarily Unavailable ๐Ÿ“ต

The callee's end system was contacted successfully, but the callee is unavailable right now. Maybe they're not logged in, or they're logged in in a way that blocks communication. ๐Ÿ˜ด The response MAY indicate a better time to call in the Retry-After header. The user could also be available somewhere else (unbeknownst to this host), so this response does not end any searches. ๐Ÿ”

The reason phrase SHOULD say more precisely why the callee is unavailable. ๐Ÿ’ฌ This value SHOULD be setable by the user agent. Status 486 (Busy Here) MAY be used to be more specific about a particular reason for the call failure. ๐Ÿ“ž

This status also comes back from a redirect server that recognizes the user in the Request-URI but doesn't have a valid forwarding location for them right now. ๐Ÿงญ

7.4.18. 481 Call Leg/Transaction Does Not Exist ๐Ÿซฅ

This status shows up under two conditions. The server gets a BYE request that doesn't match any existing call leg, or it gets a CANCEL request that doesn't match any existing transaction. ๐Ÿ™ƒ (A server just quietly discards an ACK that refers to an unknown transaction. Chill. ๐ŸงŠ)

7.4.19. 482 Loop Detected ๐Ÿ”

The server got a request with a Via (Section 6.40) path that contains itself. Ouroboros energy. ๐Ÿ

7.4.20. 483 Too Many Hops ๐Ÿƒโ€โ™€๏ธ

The server got a request with more Via entries (hops) (Section 6.40) than the Max-Forwards (Section 6.23) header field allows. It's been around the block way too many times. ๐Ÿ›ฃ๏ธ

7.4.21. 484 Address Incomplete โœ‚๏ธ

The server got a request where the To (Section 6.37) address or the Request-URI was incomplete. Additional information SHOULD be provided. ๐Ÿซถ

This status code lets you do overlapped dialing. With overlapped dialing, the client doesn't know how long the dialing string is going to be. It sends strings of increasing length, asking the user for more input, until it stops getting a 484 status response. Patience, the way it's giving sequential. ๐ŸŒˆ

7.4.22. 485 Ambiguous ๐Ÿค”

The callee address in the request was ambiguous. The response MAY include a list of possible unambiguous addresses in Contact headers. ๐Ÿ“‡

Revealing alternatives can invade the privacy of the user or the organization, so it MUST be possible to configure a server to respond with 404 (Not Found), or to suppress the list of possible choices when the request address was ambiguous. Privacy is not optional, periodt. ๐Ÿ”’

Example response to a request with the URL lee@example.com :

485 Ambiguous SIP/2.0
Contact: Carol Lee <sip:carol.lee@example.com>
Contact: Ping Lee <sip:p.lee@example.com>
Contact: Lee M. Foote <sip:lee.foote@example.com>
Some email and voice mail systems do this too. A status code that's separate from 3xx is used because the semantics are different. For 300, it's assumed that the same person or service will be reached by all the choices. An automated choice or sequential search makes sense for a 3xx response, but a 485 response needs a real human to step in. ๐Ÿ™‹โ€โ™€๏ธ

7.4.23. 486 Busy Here ๐Ÿ“ž

The callee's end system was contacted successfully, but the callee isn't willing or able to take more calls right now. ๐Ÿ™…โ€โ™€๏ธ The response MAY indicate a better time to call in the Retry-After header. The user could also be available somewhere else, like a voice mail service, so this response does not end any searches. ๐Ÿ“ฌ Status 600 (Busy Everywhere) SHOULD be used if the client knows that no other end system will be able to accept this call. ๐Ÿ’…

7.5. Server Failure 5xx ๐Ÿ› ๏ธ

5xx responses are failure responses sent when the server itself has erred. They aren't definitive failures, and they MUST NOT end a search if other possible locations are still untried. It's not over until it's over. ๐ŸŒˆ

7.5.1. 500 Server Internal Error ๐Ÿซ 

The server ran into an unexpected condition that stopped it from fulfilling the request. ๐Ÿ˜ต The client MAY display the specific error condition, and MAY retry the request after several seconds. ๐Ÿ”„

7.5.2. 501 Not Implemented ๐Ÿšง

The server doesn't support the functionality needed to fulfill the request. This is the right response when the server doesn't recognize the request method and can't support it for any user. Not yet, sweetie. ๐ŸŒฑ

7.5.3. 502 Bad Gateway ๐ŸŒ‰

While acting as a gateway or proxy, the server got an invalid response from the downstream server it reached out to while trying to fulfill the request. Somebody upstream dropped the ball. ๐Ÿ€

7.5.4. 503 Service Unavailable ๐Ÿ˜ด

The server can't handle the request right now because it's temporarily overloaded or under maintenance. The idea is that this is a temporary condition that will get better after some delay. โ˜• If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client MUST handle the response the same way it would handle a 500 response. ๐Ÿซถ

Note: Having the 503 status code doesn't mean a server has to use it when it gets overloaded. Some servers MAY wish to simply refuse the connection. Boundaries are iconic. ๐Ÿšช

7.5.5. 504 Gateway Time-out โŒ›

While acting as a gateway, the server didn't get a timely response from the server it accessed (for example, a location server) while trying to complete the request. Waiting on the group chat reply, but make it tragic. ๐Ÿ“ฑ

7.5.6. 505 Version Not Supported ๐Ÿ”ข

The server doesn't support, or refuses to support, the SIP protocol version used in the request message. It's saying it's unable or unwilling to finish the request using the same major version as the client, except through this error message. ๐Ÿ™… The response MAY contain an entity explaining why that version isn't supported and what other protocols that server does support. The format for that entity isn't defined here, and it may be the subject of future standardization. ๐Ÿ”ฎ

7.6. Global Failures 6xx ๐ŸŒ

6xx responses mean the server has definitive info about a particular user, not just the one instance in the Request-URI. All further searches for this user are doomed, so pending searches SHOULD be terminated. ๐Ÿ›‘ Hard pass, no second chances. ๐Ÿ’€

7.6.1. 600 Busy Everywhere ๐Ÿ™…โ€โ™€๏ธ

The callee's end system was contacted successfully, but the callee is busy and doesn't want to take the call right now. ๐Ÿ˜ค The response MAY indicate a better time to call in the Retry-After header. If the callee doesn't want to share why they're declining, they use status code 603 (Decline) instead. ๐Ÿซฅ This status response only comes back if the client knows no other end point (like a voice mail system) will answer the request. Otherwise, 486 (Busy Here) should be returned. ๐Ÿ“ž

7.6.2. 603 Decline ๐Ÿšซ

The callee's machine was successfully contacted, but the user explicitly doesn't want to or can't participate. ๐Ÿ’… The response MAY indicate a better time to call in the Retry-After header. Respect the no. ๐Ÿซถ

7.6.3. 604 Does Not Exist Anywhere ๐Ÿซฅ

The server has authoritative info that the user named in the To request field doesn't exist anywhere. Searching for them elsewhere won't turn up anything. Gone, reduced to atoms. โš›๏ธ

7.6.4. 606 Not Acceptable ๐Ÿ™…

The user's agent was contacted successfully, but some parts of the session description, like the requested media, bandwidth, or addressing style, weren't acceptable. ๐ŸŽ€

A 606 (Not Acceptable) response means the user does want to communicate, but can't adequately support the session described. ๐Ÿฅบ The 606 (Not Acceptable) response MAY contain a list of reasons in a Warning header field describing why the session can't be supported. Those reasons are listed in Section 6.41. ๐Ÿ“ It's hoped that negotiation won't come up often. When a new user is being invited to join an already existing conference, negotiation may not be possible at all. ๐ŸŽช It's up to the invitation initiator to decide whether or not to act on a 606 (Not Acceptable) response. You're the boss of that call. ๐Ÿ‘‘

8. SIP Message Body โœจ

8.1 Body Inclusion โœจ

okay bestie, message bodies are where the fun stuff lives ๐ŸŽ€. requests MAY contain bodies unless the spec says otherwise, but BYE is the exception: a BYE MUST NOT contain a body ๐Ÿ™…โ€โ™€๏ธ. for ACK, INVITE and OPTIONS, the body is always a session description ๐Ÿ“ž. using bodies in REGISTER requests is still for further study ๐Ÿ”ฎ.

for responses, the request method plus the status code decide what the body means ๐Ÿ’…. every response MAY include a body. 1xx bodies carry advisory info about how the request is progressing ๐ŸŒธ. 2xx responses to INVITE carry session descriptions ๐Ÿฆ‹. in 3xx responses the body MAY describe alternative destinations or services, see Section 7.3 ๐Ÿงš. for anything 400 or higher, the body MAY hold human-readable reasons for the failure ๐Ÿ˜ญ. it is RECOMMENDED that 1xx and 300-and-up bodies be text/plain or text/html ๐Ÿ’œ.

8.2 Message Body Type ๐ŸŒˆ

the Internet media type of the body MUST be given by the Content-Type header field ๐ŸŽ€. if the body was encoded somehow (like compressed), that MUST be flagged in the Content-Encoding header field, and Content-Encoding MUST be left out otherwise ๐Ÿ™ˆ. if it applies, the body's character set goes inside the Content-Type header value too ๐Ÿ“.

8.3 Message Body Length ๐Ÿ“

the body length in bytes SHOULD be given by the Content-Length header field ๐Ÿ’–. Section 6.15 explains the details โœจ.

the "chunked" transfer encoding from HTTP/1.1 MUST NOT be used for SIP ๐Ÿšซ. (fyi, chunked encoding changes the body by splitting it into a series of chunks, each with its own size indicator ๐Ÿงฉ.)

9. Compact Form ๐Ÿ’…

when SIP runs over UDP with authentication and a chunky session description, a request or response might end up bigger than the MTU ๐Ÿ˜ฑ. to fix that, there's a more compact form of SIP that uses short names for these common header fields ๐Ÿฆ‹:

short field name  long field name   note
c                 Content-Type
e                 Content-Encoding
f                 From
i                 Call-ID
m                 Contact           from "moved"
l                 Content-Length
s                 Subject
t                 To
v                 Via

so the message in section 16.2 could also be written like this ๐Ÿ‘‘:

INVITE sip:schooler@vlsi.caltech.edu SIP/2.0
v:SIP/2.0/UDP 131.215.131.131;maddr=239.128.16.254;ttl=16
v:SIP/2.0/UDP 128.16.64.19
f:sip:mjh@isi.edu
t:sip:schooler@cs.caltech.edu
i:62729-27@128.16.64.19
c:application/sdp
CSeq: 4711 INVITE
l:187

v=0
o=user1 53655765 2353687637 IN IP4 128.3.4.5
s=Mbone Audio
i=Discussion of Mbone Engineering Issues
e=mbone@somewhere.com
c=IN IP4 224.2.0.1/127
t=0 0
m=audio 3456 RTP/AVP 0

clients MAY mix short and long field names inside the same request ๐ŸŒธ. servers MUST accept both short and long names on requests ๐Ÿ’œ. proxies MAY switch header fields between long and short forms, but this MUST NOT be done to fields that come after an Authorization header ๐Ÿ”.

10. Behavior of SIP Clients and Servers ๐Ÿงš

10.1 General Remarks ๐ŸŒท

SIP can run over either UDP (unicast or multicast) or TCP โœจ. it doesn't rely on the transport for reliability, because it brings its own reliability mechanism ๐Ÿ’ช.

10.1.1 Requests ๐Ÿ“จ

servers throw away isomorphic requests, but they first retransmit the matching response ๐Ÿ”. (SIP requests are idempotent, meaning getting more than one copy of a request doesn't change the server's state ๐Ÿง .)

after a stateful proxy gets a CANCEL from an upstream client, it MAY send a CANCEL on every branch where it hasn't received a final response yet ๐Ÿ›‘.

when a user agent gets a request, it checks the Call-ID against its in-progress calls ๐Ÿ”. if the Call-ID is found, it compares the To tag with the user's tag and rejects the request if they don't match ๐Ÿ™…โ€โ™€๏ธ. if the From header, tag included, matches an existing call leg, the server compares the CSeq value. if it's less than or equal to the current sequence number, the request is a retransmission ๐Ÿ”„. otherwise it's a new request ๐ŸŽ‰. if the From header doesn't match any existing call leg, a new call leg gets created ๐ŸŒฑ.

if the Call-ID isn't found, a new call leg is created with entries for the To, From and Call-ID headers โœจ. in this case the To header shouldn't have had a tag. the server sends back a response with the same To value, but with a unique tag added ๐Ÿท๏ธ. the tag MAY be omitted if the request had only one Via header field ๐Ÿฆ‹.

10.1.2 Responses ๐Ÿ’Œ

a server MAY send one or more provisional responses at any time before its final response ๐ŸŒค๏ธ. if a stateful proxy, user agent server, redirect server or registrar can't answer a request with a final response within 200 ms, it SHOULD send a provisional (1xx) response as soon as it can โฑ๏ธ. stateless proxies MUST NOT send provisional responses on their own ๐Ÿ™…โ€โ™€๏ธ.

responses get matched to requests using the To, From, Call-ID and CSeq headers, plus the branch parameter of the first Via header ๐Ÿงฉ. responses stop request retransmissions even when their Via headers route them to an upstream client ๐Ÿ›‘.

a stateful proxy can get a response it has no state for, meaning it has no record of the associated request ๐Ÿ‘€. if the Via header says the upstream server used TCP, the proxy actively opens a TCP connection to that address ๐Ÿ”Œ. so proxies have to be ready to get responses on the incoming side of passive TCP connections, even though most responses will show up on the incoming side of an active connection ๐Ÿซถ. (an active connection is a TCP connection the proxy starts itself. a passive connection is one the proxy accepts, but that some other entity started ๐Ÿค.)

100 responses SHOULD NOT be forwarded ๐Ÿšซ. other 1xx responses MAY be forwarded, possibly after the server removes responses with status codes it already sent earlier ๐Ÿงน. 2xx responses get forwarded according to the Via header ๐Ÿ’ซ. once a stateful proxy has received a 2xx response, it MUST NOT forward non-2xx final responses ๐Ÿ™…โ€โ™€๏ธ. responses with status 300 and higher get retransmitted by each stateful proxy until the next upstream proxy sends an ACK (timing details below) or a CANCEL ๐Ÿ”.

a stateful proxy SHOULD keep state for at least 32 seconds after it gets the first definitive non-200 response, so it can handle retransmissions of that response โณ.

The 32 second window comes from the maximum retransmission duration of 200-class responses using the default timers, in case the ACK gets lost on the way to the called user agent or the next stateful proxy ๐Ÿ•ฐ๏ธ.

10.2 Source Addresses, Destination Addresses and Connections ๐Ÿ—บ๏ธ

10.2.1 Unicast UDP ๐Ÿ“ฌ

responses go back to the address listed in the Via header (Section 6.40), not to the source address of the request ๐Ÿ’Œ.

recall that responses aren't generated by the next-hop stateless server. they come from either a proxy server or the user agent server. so a stateless proxy can only use the Via header to forward the response ๐Ÿง .

10.2.2 Multicast UDP ๐Ÿ“ก

requests MAY be multicast, and multicast requests will likely have a host-independent Request-URI ๐ŸŒ. this request SHOULD be scoped so it doesn't get forwarded past the boundaries of the administrative system ๐Ÿšง. this MAY be done with either TTL or administrative scopes[25], depending on what the network supports ๐Ÿ› ๏ธ.

a client that gets a multicast query doesn't have to check whether the host part of the Request-URI matches its own host or domain name ๐Ÿ™Œ. if the request came in via multicast, the response also goes back via multicast ๐Ÿ“ข. multicast responses use the same TTL as the request, where that TTL is taken from the ttl parameter in the Via header (Section 6.40) โฒ๏ธ.

to avoid response implosion ๐Ÿ’ฅ, servers MUST NOT answer multicast requests with any status code other than 2xx or 6xx ๐Ÿ™…โ€โ™€๏ธ. the server waits a random interval, uniformly distributed between zero and one second, before responding โณ. servers MAY suppress their response if they hear a lower-numbered or 6xx response from another group member before they send theirs ๐Ÿคซ. servers don't respond to CANCEL requests that arrive via multicast, to avoid request implosion ๐Ÿšซ. a proxy or UAC SHOULD send a CANCEL when it gets the first 2xx or 6xx response to a multicast request ๐Ÿ›‘.

ok real talk about response suppression: it's a MAY because it means a server has to break some basic message processing rules ๐Ÿ˜ญ. say A sends a multicast request and B, C and D receive it. B sends a 200 response. the topmost Via field in that response will contain A's address. C will also receive the response and could use it to suppress its own response. but C normally wouldn't look at this response, since the topmost Via isn't its own. normally, a response that arrives with an incorrect topmost Via MUST be dropped, but not in this case ๐Ÿ™ˆ. telling this packet apart from a misrouted or multicast-looped packet is pretty complex, which is why the procedure is a MAY ๐ŸŒ€. CANCEL is the simpler, more standard way to do response suppression, and that's exactly why using CANCEL here is a SHOULD ๐Ÿ’…โœจ.

10.3 TCP ๐Ÿ”Œ

a single TCP connection can serve one or more SIP transactions ๐Ÿงต. a transaction holds zero or more provisional responses followed by one or more final responses. (usually a transaction has exactly one final response, but there are exceptional cases, like when multiple 200 responses get generated ๐ŸŒˆ.)

the client SHOULD keep the connection open at least until the first final response shows up ๐Ÿ’–. if the client closes or resets the TCP connection before getting the first final response, the server treats that as if it had received a CANCEL request ๐Ÿ›‘.

this behavior makes it less likely that a misbehaving client makes a proxy server keep connection state forever ๐Ÿซ .

the server SHOULD NOT close the TCP connection until it has sent its final response ๐Ÿ™…โ€โ™€๏ธ. at that point it MAY close the connection if it wants to. still, it's normally the client's job to close the connection ๐ŸŽ€.

if the server leaves the connection open, and the client wants to, the client MAY reuse it for more SIP requests or for requests from the same family of protocols (like HTTP or stream control commands) ๐Ÿ”„.

if a server needs to return a response to a client and no longer has a connection open to that client, it MAY open a connection to the address listed in the Via header ๐Ÿช„. so a proxy or user agent MUST be prepared to receive both requests and responses on a "passive" connection ๐Ÿซถ.

10.4 Reliability for BYE, CANCEL, OPTIONS, REGISTER Requests ๐Ÿ”

10.4.1 UDP โœจ

okay so if you're a SIP client on UDP ๐Ÿ“ก, you SHOULD retransmit your BYE, CANCEL, OPTIONS, or REGISTER request using exponential backoff ๐Ÿ”. You start at a T1 second interval, double it for every packet, and cap it at a T2 second interval. So after the first packet goes out, the second one follows T1 seconds later, the next one 2*T1 seconds after that, then 4*T1 seconds after that, and so on until you hit T2. From there, retransmissions are spaced by T2 seconds. If you get a provisional response, you keep retransmitting, but now every T2 seconds. Retransmissions stop when you've sent eleven packets in total or you get a definitive response. The defaults are 500 ms for T1 and 4 s for T2 ๐ŸŽ€. Clients MAY use larger values, but SHOULD NOT use smaller ones. Servers retransmit the response whenever they get a request retransmission. Once the server sends a final response, it can't be sure the client actually got it, so it SHOULD cache the results for at least 10*T2 seconds ๐Ÿง . That way it doesn't have to, say, bug the user or location server again when a request retransmission shows up.

Use of the exponential backoff is for congestion control purposes ๐ŸŒŠ. However, the back-off must cap off, since request retransmissions are used to trigger response retransmissions at the server. Without a cap, the loss of a single response could significantly increase transaction latencies. ๐Ÿ˜ญ

The initial retransmission timer is smaller than the one for TCP, because network paths that are good for interactive communication are expected to have round-trip times under 500 ms โšก. For congestion control, the retransmission count has to be bounded ๐Ÿšง. Most transactions are expected to be one request and a few responses, so round-trip time estimation isn't likely to be super useful. If you do want RTT estimation to find a missing final response faster, each request retransmission needs its own Timestamp (Section 6.36), which comes back in the response. The server caches the result until it can be sure the client won't retransmit the same request again.

Each server in a proxy chain generates its own final response to a CANCEL request ๐Ÿ”—. It responds right away when it gets the CANCEL, rather than waiting for final responses to the CANCEL requests it generated itself.

BYE and OPTIONS final responses come from redirect and user agent servers, and REGISTER final responses come from registrars ๐Ÿ“ฎ. Heads up: unlike the reliability mechanism in Section 10.5, responses to these requests are not retransmitted periodically and not acknowledged via ACK ๐Ÿ™ˆ.

10.4.2 TCP ๐Ÿงฆ

Clients using TCP don't need to retransmit requests ๐Ÿ™Œ.

10.5 Reliability for INVITE Requests ๐Ÿ’Œ

Special considerations apply for the INVITE method, so pay attention ๐Ÿ‘€.

  1. After a server gets an invitation, a LOT of time can pass before it knows the outcome โณ. If the called party is "rung" or extensive searches are performed, the gap between the request and a definitive response can hit several tens of seconds. If either the caller or the callee is an automated server not directly controlled by a human being, a call attempt could be unbounded in time ๐Ÿค–.
  2. If a telephony user interface is modeled, or we need to interface with the PSTN ๐Ÿ“ž, the caller's UI provides "ringback", a signal that the callee is being alerted. (The status response 180 (Ringing) MAY be used to initiate ringback.) Once the callee picks up, the caller needs to know so it can enable the voice path and stop ringback. The callee's response to the invitation could get lost. Unless the response is sent reliably, the caller keeps hearing ringback while the callee thinks the call exists ๐Ÿ’€.
  3. The client has to be able to terminate an ongoing request, e.g., because it's no longer willing to wait for the connection or search to succeed ๐Ÿ™…. The server will have to wait several retransmission intervals to read the lack of request retransmissions as the end of a call. If the call succeeds shortly after the caller has given up, the callee will "pick up the phone" and not be "connected" ๐Ÿ˜ฌ.

10.5.1 UDP ๐Ÿ“ฆ

For UDP, a SIP client SHOULD retransmit a SIP INVITE request with an interval that starts at T1 seconds and doubles after each packet transmission. The client stops retransmitting if it gets a provisional or definitive response, or once it has sent a total of 7 request packets.

A server which transmits a provisional response should retransmit it upon reception of a duplicate request. A server which transmits a final response should retransmit it with an interval that starts at T1 seconds, and doubles for each subsequent packet. Response retransmissions cease when any one of the following occurs:

  1. An ACK request for the same transaction is received;
  2. a BYE request for the same call leg is received;
  3. a CANCEL request for the same call leg is received and the final response status was equal or greater to 300;
  4. the response has been transmitted 7 times.

Only the user agent client generates an ACK for 2xx final responses. If the response contained a Contact header field, the ACK MAY be sent to the address listed in that Contact header field. If the response did not contain a Contact header, the client uses the same To header field and Request-URI as for the INVITE request and sends the ACK to the same destination as the original INVITE request. ACKs for final responses other than 2xx are sent to the same server that the original request was sent to, using the same Request-URI as the original request. Note, however, that the To header field in the ACK is copied from the response being acknowledged, not the request, and thus MAY additionally contain the tag parameter. Also note that unlike 2xx final responses, a proxy generates an ACK for non-2xx final responses ๐Ÿง.

The ACK request MUST NOT be acknowledged to prevent a response-ACK feedback loop ๐Ÿ”๐Ÿšซ. Fig. 12 and 13 show the client and server state diagrams for invitations ๐Ÿฆ‹.

The mechanism in Sec. 10.4 would not work well for INVITE because of the long delays between INVITE and a final response. If the 200 response were to get lost, the callee would believe the call to exist, but the voice path would
              +===========+
              *           *
  ...........>*  Initial  *<;;;;;;;;;;
  : 7 INVITE  *           *          ;
  :   sent    +===========+          ;
  :                 |                ;
  :                 |    -           ;
  :                 |  INVITE        ;
  :                 |                ;
  :                 v                ;
  :           *************          ;
  : T1*2^n <--*           *          ;
  : INVITE -->*  Calling  *--------+ ;
  :           *           *        | ;
  :           *************        | ;
  :             :   |              | ;
  :.............:   | 1xx      xxx | ;
                    |  -       ACK | ;
                    |              | ;
                    v              | ;
              *************        | ;
              *           *        | ;
              *  Ringing  *<->1xx  | ;
              *           *        | ;
              *************        | ;
                    |              | ;
                    |<-------------+ ;
                    |                ;
                    v                ;
              *************          ;
      xxx  <--*           *          ;
      ACK  -->* Completed *          ;
              *           *          ;
              *************          ;
                    ; 32s (for proxy);
                    ;;;;;;;;;;;;;;;;;;

 event (xxx=status)
     message

Figure 12: State transition diagram of client for INVITE method

   7 pkts sent  +===============+
+-------------->*               *
|               *   Initial     *<...............
|;;;;;;;;;;;;;;>*               *               :
|;              +===============+               :
|; CANCEL               !                       :
|;  200                 !  INVITE               :
|;                      !   1xx                 :
|;                      !                       :
|;                      v                       :
|;              *****************          BYE  :
|;    INVITE -->*               *          200  :
|;      1xx  <--* Call proceed. *..............>:
|;              *               *               :
|;;;;;;;;;;;;;;;*****************               :
|;                    !   !                     :
|:                    !   !                     :
|;         failure    !   !  picks up           :
|;         >= 300     !   !    200              :
|;            +-------+   +-------+             :
|;            v                   v             :
|;       ***********         ***********        :
|;INVITE<*         *<T1*2^n->*         *>INVITE :
|;status>* failure *>status<-* success *<status :
|;       *         *         *         *        :
|;;;;;;;;***********         ***********        :
|             ! : |            |  !  :          :
|             ! : |            |  !  :          :
+-------------!-:-+------------+  !  :          :
              ! :.................!..:.........>:
              !                   !         BYE :
              +---------+---------+         200 :
  event                 ! ACK                   :
message sent            v                       :
                *****************               :
            V---*               *               :
           ACK  *   Confirmed   *               :
            |-->*               *               :
                *****************               .
                        :......................>:

Figure 13: State transition diagram of server for INVITE method

be dead since the caller does not know that the callee has picked up. Thus, the INVITE retransmission interval would have to be on the order of a second or two to limit the duration of this state confusion. Retransmitting the response with an exponential back-off helps ensure that the response is received, without placing an undue burden on the network ๐ŸŒท.

10.5.2 TCP ๐Ÿงต

A user agent using TCP MUST NOT retransmit requests, but uses the same algorithm as for UDP (Section 10.5.1) to retransmit responses until it receives an ACK ๐Ÿซถ.

It is necessary to retransmit 2xx responses as their reliability is assured end-to-end only. If the chain of proxies has a UDP link in the middle, it could lose the response, with no possibility of recovery. For simplicity, we also retransmit non-2xx responses, although that is not strictly necessary ๐Ÿ’œ.

10.6 Reliability for ACK Requests ๐ŸŒˆ

The ACK request does not generate responses. It is only generated when a response to an INVITE request arrives (see Section 10.5). This behavior is independent of the transport protocol. Note that the ACK request MAY take a different path than the original INVITE request, and MAY even cause a new TCP connection to be opened in order to send it ๐Ÿ’….

10.7 ICMP Handling โœจ

okay so ICMP errors with UDP are honestly pretty straightforward ๐Ÿ’…. For requests, a host, network, port, or protocol unreachable error SHOULD be treated as if a 400-class response was received. For responses, these errors SHOULD cause the server to cease retransmitting the response. ๐Ÿซถ

Source quench ICMP messages SHOULD be ignored. TTL exceeded errors SHOULD be ignored. Parameter problem errors SHOULD be treated as if a 400-class response was received. ๐Ÿ™ˆ

11 Behavior of SIP User Agents ๐ŸŽ€

this section is where we get into the rules for user agent clients and servers when they're making and handling requests and responses ๐Ÿ“ž

11.1 Caller Issues Initial INVITE Request ๐Ÿ“ž

when a user agent client wants to start a call, it builds an INVITE request ๐Ÿ’– The To field holds the callee's address, and the Request-URI has that same address. The From field has the caller's address. If that From address could show up in requests from other user agent clients for the same call, the caller MUST insert the tag parameter in the From field. A UAC MAY optionally add a Contact header with an address where it'd like to be contacted for transactions from the callee back to the caller. ๐Ÿฆ‹

11.2 Callee Issues Response ๐Ÿ’…

when the initial INVITE hits the callee, they can accept, redirect, or reject the call. Whatever they pick, they build a response. The response MUST copy the To, From, Call-ID, CSeq and Via fields from the request. Also, the responding UAS MUST add the tag parameter to the To field in the response if the request had more than one Via header field. Since a request from a UAC might fork and land at multiple hosts, the tag parameter is what lets the UAC tell apart responses from different UASs ๐Ÿ‘‘

The UAS MAY add a Contact header field in the response, with an address where the callee wants to be contacted for later transactions, including the ACK for the current INVITE. The UAS stores the To and From values, tags included. Those become the local and remote addresses of the call leg, respectively. ๐ŸŒธ

11.3 Caller Receives Response to Initial Request ๐Ÿงš

multiple responses can show up at the UAC for one INVITE, thanks to a forking proxy ๐Ÿ˜ญ Each response is told apart by the "tag" parameter in the To header field, and each one is its own call leg. The caller MAY choose to acknowledge or terminate the call with each responding UAS. To acknowledge, it sends an ACK request; to terminate, it sends a BYE request. The To header field in the ACK or BYE MUST be the same as the To field in the 200 response, including any tag. The From header field MUST be the same as the From header field in the 200 (OK) response, including any tag. The Request-URI of the ACK or BYE request MAY be set to whatever address was in the Contact header field of the 200 (OK) response, if there is one. Alternately, a UAC may copy the address from the To header field into the Request-URI. The UAC also notes the To and From values in each response. For each call leg, the To header field becomes the remote address and the From header field becomes the local address. ๐Ÿ”ฅ

11.4 Caller or Callee Generate Subsequent Requests ๐Ÿ“

once the call is up, either the caller or the callee MAY send INVITE or BYE requests to change or end the call โœจ No matter who's sending the new request, the header fields get set like this. For the call leg in question, the To header field is set to the remote address, and the From header field is set to the local address (both with any tags). The Contact header field MAY be different from the Contact header field sent in a previous response or request. The Request-URI MAY be set to the value of the Contact header field from a previous request or response from the remote party, or to the value of the remote address. ๐Ÿ’œ

11.5 Receiving Subsequent Requests ๐ŸŒˆ

when a request comes in later, these checks happen:

  1. If the Call-ID is new, the request is for a new call, no matter what the To and From header fields say.
  2. If the Call-ID already exists, the request is for an existing call. If the To, From, Call-ID, and CSeq values exactly match (tags included) those of any requests received previously, the request is a retransmission.
  3. If step 2 didn't match, the To and From fields get compared against the existing call leg local and remote addresses. If there's a match, and the CSeq in the request is higher than the last CSeq received on that leg, the request is a new transaction for an existing call leg. ๐Ÿซถ

12 Behavior of SIP Proxy and Redirect Servers ๐ŸŒธ

this section goes deep on how SIP redirect and proxy servers behave ๐Ÿงš Proxy servers can "fork" connections, i.e., one incoming request can spawn several outgoing (client) requests. main character energy ๐Ÿ‘‘

12.1 Redirect Server ๐Ÿ’…

a redirect server doesn't send out any SIP requests of its own. After it gets a request other than CANCEL, it gathers the list of alternative locations and returns a final response of class 3xx, or it refuses the request. For well-formed CANCEL requests, it SHOULD return a 2xx response. That response ends the SIP transaction. The redirect server keeps transaction state for the whole SIP transaction. It's up to the client to detect forwarding loops between redirect servers. ๐Ÿ”ฅ

12.2 User Agent Server ๐ŸŽ€

user agent servers act a lot like redirect servers, except they also accept requests and can return a response of class 2xx ๐Ÿฆ‹

12.3 Proxy Server ๐Ÿ“

this section lays out the processing rules for proxy servers โœจ A proxy server can be either stateful or stateless. When it's stateful, a proxy remembers the incoming request that generated outgoing requests, and the outgoing requests themselves. A stateless proxy forgets everything once an outgoing request is generated. A forking proxy SHOULD be stateful. Proxies that accept TCP connections MUST be stateful. ๐Ÿ’–

Otherwise, if the proxy were to lose a request, the TCP client would never retransmit it. ๐Ÿ˜ญ

A stateful proxy SHOULD NOT become stateless until after it sends a definitive response upstream, and at least 32 seconds after it received a definitive response. โณ

A stateful proxy acts as a virtual UAS/UAC. It runs the server state machine when receiving requests, and the client state machine for generating outgoing requests, except when it receives a 2xx response to an INVITE. Instead of generating an ACK, the 2xx response is always forwarded upstream towards the caller. Furthermore, ACKs for 200 responses to INVITEs are always proxied downstream towards the UAS, just as they would be for a stateless proxy. ๐Ÿงš

A stateless proxy doesn't act as a virtual UAS/UAC, since that would need state. Instead, it forwards every request it gets downstream, and every response it gets upstream. ๐ŸŒˆ

12.3.1 Proxying Requests ๐Ÿซถ

to prevent loops, a server MUST check whether its own address is already in the Via header field of the incoming request. ๐Ÿ”

The To, From, Call-ID, and Contact tags are copied exactly from the original request. The proxy SHOULD change the Request-URI to indicate the server where it intends to send the request.

A proxy server always inserts a Via header field containing its own address into requests caused by an incoming request. Each proxy MUST insert a "branch" parameter (Section 6.40). ๐Ÿ’…

12.3.2 Proxying Responses ๐Ÿฆ‹

a proxy only processes a response if the topmost Via field matches one of its addresses. A response with a non-matching top Via field MUST be dropped. ๐Ÿ™ˆ

12.3.3 Stateless Proxy: Proxying Responses ๐Ÿ’œ

a stateless proxy removes its own Via field, and checks the address in the next Via field. For UDP, the response goes to the address in the "maddr" tag if present, otherwise to the "received" tag if present, and finally to the address in the "sent-by" field. A proxy MUST remain stateful when handling requests received via TCP.

A stateless proxy MUST NOT generate its own provisional responses. ๐Ÿšซ

12.3.4 Stateful Proxy: Receiving Requests ๐Ÿ“

when a stateful proxy gets a request, it checks the To, From (including tags), Call-ID and CSeq against existing request records. If the tuple exists, the request is a retransmission. The provisional or final response sent previously is retransmitted, as per the server state machine. If the tuple doesn't exist, the request corresponds to a new transaction, and the request should be proxied. โœจ

A stateful proxy server MAY generate its own provisional (1xx) responses. ๐ŸŽ€

12.3.5 Stateful Proxy: Receiving ACKs ๐Ÿ‘‘

when an ACK request comes in, it's either processed locally or proxied. To decide, the To, From, CSeq and Call-ID fields are compared against those in previous requests. If there's no match, the ACK request is proxied as if it were an INVITE request. If there's a match, and the server had ever sent a 200 response upstream, the ACK is proxied. If the server had never sent any responses upstream, the ACK is also proxied. If the server had sent a 3xx, 4xx, 5xx or 6xx response, but no 2xx response, the ACK is processed locally if the tag in the To field of the ACK matches the tag the proxy sent in the response. ๐Ÿ”ฅ

12.3.6 Stateful Proxy: Receiving Responses ๐ŸŒˆ

when a proxy server gets a response that passed the Via checks, it compares the To (without the tag), From (including the tag), Call-ID and CSeq against values seen in previous requests. If there's no match, the response is forwarded upstream to the address in the Via field. If there's a match, the "branch" tag in the Via field is examined. If it matches a known branch identifier, the response is for that branch and gets processed by the virtual client for that branch. Otherwise, the response is dropped. ๐Ÿฆ‹

A stateful proxy should follow the rules in Section 12.4 to decide if the response should be proxied upstream. If it is to be proxied, the same rules as for stateless proxies above apply, with the following addition for TCP. If a request was received via TCP (indicated by the protocol in the top Via header), the proxy checks to see if it has a connection currently open to that address. If so, the response goes out on that connection. Otherwise, a new TCP connection is opened to the address and port in the Via field, and the response is sent there. Note that this implies that a UAC or proxy MUST be prepared to receive responses on the incoming side of a TCP connection. Definitive non 200-class responses MUST be retransmitted by the proxy, even over a TCP connection. ๐Ÿซถ

12.3.7 Stateless, Non-Forking Proxy โœจ

okay so this one is the chill proxy ๐ŸŒธ Proxies in this category send at most one unicast request for each incoming SIP request, so they don't "fork" anything ๐Ÿ“ Tiny plot twist though: servers MAY choose to always operate in a mode that allows issuing of several requests, as described in Section 12.4.

The server can forward the request and any responses. It doesn't have to keep any state for the SIP transaction ๐Ÿงš Reliability is handled by the next redirect or stateful proxy server down the server chain ๐Ÿซถ

A proxy server SHOULD cache the result of any address translations and the response to speed up forwarding of retransmissions โšก Once that cache entry has expired, the server can't tell whether an incoming request is actually a retransmission of an older request ๐Ÿ˜ญ So it treats it as a brand new request and starts another search ๐Ÿ’€

12.4 Forking Proxy ๐Ÿฆ‹

The server MUST respond to the request immediately with a 100 (Trying) response ๐Ÿ’–

Successful responses to an INVITE request MAY contain a Contact header field so that the following ACK or BYE bypasses the proxy search mechanism ๐ŸŽ€ If the proxy requires future requests to be routed through it, it adds a Record-Route header to the request (Section 6.29).

Okay the next bit is the C-code that describes a proxy issuing several requests in response to one incoming INVITE ๐Ÿง  The function request(r, a, b) sends a SIP request of type r to address a, with branch id b. await_response() waits until a response is received and returns the response. close(a) closes the TCP connection to client with address a. response(r) sends a response to the client. ismulticast() returns 1 if the location is a multicast address and zero otherwise. The variable timeleft indicates the amount of time left until the maximum response time has expired. The variable recurse indicates whether the server will recursively try addresses returned through a 3xx response. A server MAY decide to recursively try only certain addresses, e.g., those which are within the same domain as the proxy server. Thus, an initial multicast request can trigger additional unicast requests ๐Ÿ‘‘

/* request type */
typedef enum {INVITE, ACK, BYE, OPTIONS, CANCEL, REGISTER} Method;

process_request(Method R, int N, address_t address[])
{
  struct {
    int branch;         /* branch id */
    int done;           /* has responded */
  } outgoing[];
  int done[];           /* address has responded */
  char *location[];     /* list of locations */
  int heard = 0;        /* number of sites heard from */
  int class;            /* class of status code */
  int timeleft = 120;   /* sample timeout value */
  int loc = 0;          /* number of locations */
  struct {              /* response */
    int status;         /* response: CANCEL=-1 */
    int locations;      /* number of redirect locations */
    char *location[];   /* redirect locations */
    address_t a;        /* address of respondent */
    int branch;         /* branch identifier */
  } r, best;            /* response, best response */
  int i;

  best.status = 1000;
  for (i = 0; i < N; i++) {

    request(R, address[i], i);
    outgoing[i].done = 0;
    outgoing[i].branch = i;
  }

  while (timeleft > 0 && heard < N) {
    r = await_response();
    class = r.status / 100;

    /* If final response, mark branch as done. */
    if (class >= 2) {
      heard++;
      for (i = 0; i < N; i++) {
        if (r.branch == outgoing[i].branch) {
          outgoing[i].done = 1;
          break;
        }
      }
    }
    /* CANCEL: respond, fork and wait for responses */
    else if (class < 0) {
      best.status = 200;
      response(best);
      for (i = 0; i < N; i++) {
        if (!outgoing[i].done)
          request(CANCEL, address[i], outgoing[i].branch);
      }
      best.status = -1;
    }

    /* Send an ACK */

    if (class != 2) {
      if (R == INVITE) request(ACK, r.a, r.branch);
    }


    if (class == 2) {
      if (r.status < best.status) best = r;
      break;
    }
    else if (class == 3) {
      /* A server MAY optionally recurse.  The server MUST check
       * whether it has tried this location before and whether
       * the location is part of the Via path of the incoming
       * request.  This check is omitted here for brevity.
       * Multicast locations MUST NOT be returned to the client if
       * the server is not recursing.

       */
      if (recurse) {
        multicast = 0;
        N += r.locations;
        for (i = 0; i < r.locations; i++) {
          request(R, r.location[i]);
        }
      } else if (!ismulticast(r.location)) {
        best = r;
      }
    }
    else if (class == 4) {
      if (best.status >= 400) best = r;
    }
    else if (class == 5) {
      if (best.status >= 500) best = r;
    }
    else if (class == 6) {
      best = r;
      break;
    }
  }

  /* We haven't heard anything useful from anybody. */
  if (best.status == 1000) {
    best.status = 404;
  }
  if (best.status/100 != 3) loc = 0;
  response(best);
}

Responses get processed as follows ๐ŸŽฌ The process completes (and state can be freed) when all requests have been answered by final status responses (for unicast) or 60 seconds have elapsed (for multicast). A proxy MAY send a CANCEL to all branches and return a 408 (Timeout) to the client after 60 seconds or more โฐ

1xx: The proxy MAY forward the response upstream towards the client ๐ŸŒˆ

2xx: The proxy MUST forward the response upstream towards the client, without sending an ACK downstream ๐Ÿ† After receiving a 2xx, the server MAY terminate all other pending requests by sending a CANCEL request and closing the TCP connection, if applicable. (Terminating pending requests is advisable as searches consume resources. Also, INVITE requests could "ring" on a number of workstations if the callee is currently logged in more than once.) ๐Ÿ“ฑ๐Ÿ“ฑ๐Ÿ“ฑ

3xx: The proxy MUST send an ACK and MAY recurse on the listed Contact addresses. Otherwise, the lowest-numbered response is returned if there were no 2xx responses. ๐Ÿ”

Location lists are not merged, because that would prevent forwarding of authenticated responses ๐Ÿ” Also, responses can have message bodies, so merging isn't feasible either ๐Ÿ™…โ€โ™€๏ธ

4xx, 5xx: The proxy MUST send an ACK and remember the response if it has a lower status code than any previous 4xx and 5xx responses. On completion, the lowest-numbered response is returned if there were no 2xx or 3xx responses. ๐Ÿ“‰

6xx: The proxy MUST forward the response to the client and send an ACK. Other pending requests MAY be terminated with CANCEL as described for 2xx responses. ๐Ÿ›‘

A proxy server forwards any response for Call-IDs for which it does not have a pending transaction, according to the response's Via header ๐Ÿ“ฌ User agent servers respond to BYE requests for unknown call legs with status code 481 (Transaction Does Not Exist), and they silently drop ACK requests with unknown call legs ๐Ÿ™ˆ

Special considerations apply when choosing forwarding destinations for ACK and BYE requests ๐Ÿ’Œ In most cases these requests bypass proxies and reach the desired party directly, so proxies don't have to make forwarding decisions ๐Ÿฆ„

A proxy MAY maintain call state for a period of its choosing. If a proxy still has a list of destinations that it forwarded the last INVITE to, it SHOULD direct ACK requests only to those downstream servers ๐ŸŽฏ

13 Security Considerations ๐Ÿ”

13.1 Confidentiality and Privacy: Encryption ๐Ÿ’œ

13.1.1 End-to-End Encryption โœจ

okay so SIP requests and responses can spill tea about who's talking to who and what they're talking about ๐Ÿ‘€ The SIP message body MAY also contain encryption keys for the session itself. SIP supports three complementary forms of encryption to protect privacy ๐Ÿ”:

  • end-to-end encryption of the SIP message body and certain sensitive header fields ๐Ÿ’–
  • hop-by-hop encryption to stop eavesdroppers from tracking who is calling whom ๐Ÿ•ต๏ธ
  • hop-by-hop encryption of Via fields to hide the route a request has taken ๐Ÿฆ‹

Not all of the SIP request or response can be encrypted end-to-end, bestie, because header fields like To and Via need to stay visible to proxies so the request can still be routed correctly ๐Ÿงญ Hop-by-hop encryption scrambles the entire SIP request or response on the wire, so packet sniffers and other eavesdroppers can't see who's calling whom ๐Ÿ™ˆ It can even wrap requests and responses that were already end-to-end encrypted. BUT proxies can still see who's calling whom, and that info can also be figured out through network traffic analysis, so this is a very limited, but still worthwhile, amount of protection ๐Ÿงธ

SIP Via fields are used to route a response back along the path the request took, and they help prevent infinite request loops ๐Ÿ” The catch is that they can also give an attacker useful info ๐Ÿ‘€ Section 6.22 describes how a sender can ask cooperating proxies to encrypt Via fields without messing up the whole point of the Via field ๐Ÿ’…

End-to-end encryption relies on keys shared by the two user agents involved in the request. Typically, the message is sent encrypted with the public key of the recipient, so only that recipient can read it ๐Ÿ”‘ All implementations SHOULD support PGP-based encryption [33] and MAY implement other schemes.

A SIP request (or response) is end-to-end encrypted by splitting the message into a part to be encrypted and a short header that stays in the clear ๐ŸŽ€ Some parts of the SIP message, namely the request line, the response line, and certain header fields marked with "n" in the "enc." column in Table 4 and 5, need to be read and returned by proxies, so they MUST NOT be encrypted end-to-end ๐Ÿšซ The possibly sensitive info that has to stay readable includes the destination address (To) and the forwarding path (Via) of the call. The Authorization header field MUST remain in the clear if it contains a digital signature, since the signature is generated after encryption. It MAY be encrypted if it contains "basic" or "digest" authentication ๐Ÿง The From header field SHOULD normally remain in the clear, but it MAY be encrypted if required. In that case, some proxies MAY return a 401 (Unauthorized) status if they require a From field ๐Ÿ™ƒ

Other header fields MAY be encrypted or MAY travel in the clear, totally up to the sender ๐ŸŒธ The Subject, Allow, and Content-Type header fields will typically be encrypted. The Accept, Accept-Language, Date, Expires, Priority, Require, Call-ID, Cseq, and Timestamp header fields will remain in the clear ๐ŸŒˆ

All fields that will remain in the clear MUST precede those that will be encrypted. The message is encrypted starting with the first character of the first header field that will be encrypted, and it keeps going through to the end of the message body. If no header fields are going to be encrypted, encryption starts with the second CRLF pair after the last header field, as shown below. Carriage return and line feed characters have been made visible as "$", and the encrypted part of the message is outlined ๐Ÿ–๏ธ

     INVITE sip:watson@boston.bell-telephone.com SIP/2.0$
     Via: SIP/2.0/UDP 169.130.12.5$
     To: T. A. Watson <sip:watson@bell-telephone.com>$
     From: A. Bell <sip:a.g.bell@bell-telephone.com>$
     Encryption: PGP version=5.0$
     Content-Length: 224$
     Call-ID: 187602141351@worcester.bell-telephone.com$
     CSeq: 488$
     $
   *******************************************************
   * Subject: Mr. Watson, come here.$                    *
   * Content-Type: application/sdp$                      *
   * $                                                   *
   * v=0$                                                *
   * o=bell 53655765 2353687637 IN IP4 128.3.4.5$        *
   * c=IN IP4 135.180.144.94$                            *
   * m=audio 3456 RTP/AVP 0 3 4 5$                       *
   *******************************************************

An Encryption header field MUST be added to indicate the encryption mechanism used ๐Ÿ” A Content-Length field is added too, showing the length of the encrypted body. The encrypted body is preceded by a blank line, just like a normal SIP message body ๐Ÿ’œ

When the called user agent gets the message and has the correct decryption key ๐Ÿ—๏ธ the message body (as indicated by the Content-Length field) is decrypted, and the now-decrypted body is appended to the clear-text header fields. There's no need for an additional Content-Length header field inside the encrypted body, because the length of the actual message body is unambiguous after decryption โœจ

Had no SIP header fields required encryption, the message would have looked like this. Note that the encrypted body MUST then include a blank line (starting with CRLF) to tell apart any possible SIP header fields and the SIP message body ๐Ÿงš

     INVITE sip:watson@boston.bell-telephone.com SIP/2.0$
     Via: SIP/2.0/UDP 169.130.12.5$
     To: T. A. Watson <sip:watson@bell-telephone.com>$
     From: A. Bell <a.g.bell@bell-telephone.com>$
     Encryption: PGP version=5.0$
     Content-Type: application/sdp$
     Content-Length: 107$
     $
   *************************************************
   * $                                             *
   * v=0$                                          *
   * o=bell 53655765 2353687637 IN IP4 128.3.4.5$  *
   * c=IN IP4 135.180.144.94$                      *
   * m=audio 3456 RTP/AVP 0 3 4 5$                 *
   *************************************************

13.1.2 Privacy of SIP Responses

okay this one is so real ๐Ÿ˜ญ SIP requests can be sent securely, with end-to-end encryption and authentication, to a called user agent that then sends back an insecure response. The SIP security model allows this, but it's not a good idea ๐Ÿ’€ The thing is, unless the correct behavior is spelled out, the called user agent wouldn't always be able to figure out what a reasonable behavior was ๐Ÿคทโ€โ™€๏ธ So when the request originator uses end-to-end encryption, the encryption key to be used for the response SHOULD be specified in the request. If that doesn't happen, the called user agent might guess the wrong key to use in the response ๐Ÿ˜ฌ To stop key-guessing from becoming an acceptable strategy, we specify that a called user agent receiving a request that does not specify a key for the response SHOULD send that response unencrypted ๐Ÿ”“

Any SIP header fields that were encrypted in a request SHOULD also be encrypted in an encrypted response ๐Ÿซถ Contact response fields MAY be encrypted if the info they hold is sensitive, or they MAY be left in the clear to give proxies more room for localized searches ๐Ÿ”


13.1.3 Encryption by Proxies

Normally, proxies are not allowed to alter end-to-end header fields and message bodies ๐Ÿ™…โ€โ™€๏ธ Proxies MAY, however, encrypt an unsigned request or response with the key of the call recipient ๐ŸŽ€

Proxies need to encrypt a SIP request if the end system cannot perform encryption or to enforce organizational security policies.

13.1.4 Hop-by-Hop Encryption

SIP requests and responses MAY also be protected by security mechanisms at the transport or network layer ๐Ÿ›ก๏ธ No particular mechanism is defined or recommended here. Two possibilities are IPSEC [34] or TLS [35]. The use of a particular mechanism will generally need to be specified out of band, through manual configuration, for example ๐Ÿงฉ


13.1.5 Via field encryption

When Via header fields are to be hidden, a proxy that receives a request containing an appropriate "Hide: hop" header field (as specified in section 6.22) SHOULD encrypt the header field ๐Ÿฆ‹ Only the proxy that encrypts the field will decrypt it, so the algorithm is entirely up to the proxy implementor ๐Ÿง  Two methods satisfy these requirements:

  • The server keeps a cache of Via header fields and the associated To header field, and replaces the Via header field with an index into the cache. On the reverse path, it takes the Via header field from the cache rather than the message.

This is insufficient to prevent message looping, so an additional ID MUST be added so that the proxy can detect loops. This SHOULD NOT normally be the address of the proxy, since the goal is to hide the route. Instead, a sufficiently large random number SHOULD be used by the proxy and maintained in the cache ๐ŸŽฒ

It's possible for replies to get sent to the wrong originator if the cache entry gets reused, so great care needs to be taken to make sure this doesn't happen ๐Ÿ˜ฐ

  • The server MAY use a secret key to encrypt the Via field, a timestamp, and an appropriate checksum in any such message with the same secret key. The checksum is needed to detect whether successful decoding has occurred, and the timestamp is required to prevent possible replay attacks and to ensure that no two requests from the same previous hop have the same encrypted Via field. This is the preferred solution ๐Ÿ‘‘

13.2 Message Integrity and Access Control: Authentication โœจ

Okay so, we need protective measures to stop an active attacker from messing with SIP requests and responses by modifying or replaying them ๐Ÿšจ. The same crypto that proves a SIP message is authentic also proves who sent it ๐Ÿ”. BUT the "basic" and "digest" mechanisms only do authentication, not message integrity ๐Ÿ’€.

Transport-layer or network-layer authentication MAY be used for hop-by-hop authentication ๐Ÿงš. SIP also levels up the HTTP WWW-Authenticate (Section 6.42) and Authorization (Section 6.11) header field, plus their Proxy counterparts, so they can carry cryptographically strong signatures ๐Ÿ’…. SIP also supports the HTTP "basic" and "digest" schemes (see Section 14) and other HTTP authentication schemes to be defined, which give a rudimentary way to figure out who the caller is ๐Ÿฆ‹.

Since SIP requests are often sent to parties with which no prior communication relationship has existed, we do not specify authentication based on shared secrets. ๐Ÿ™ˆ

SIP requests MAY be authenticated using the Authorization header field to include a digital signature of certain header fields, the request method and version number and the payload, none of which are modified between client and called user agent ๐ŸŽ€. The Authorization header field is used in requests to authenticate the request originator end-to-end to proxies and the called user agent. In responses, it authenticates the called user agent or proxies returning their own failure codes. If you need hop-by-hop authentication, you can get it with something like the IPSEC Authentication Header ๐Ÿ”ฅ.

SIP does not dictate which digital signature scheme is used for authentication, but it does define how to provide authentication using PGP in Section 15 ๐ŸŒธ. As indicated above, SIP implementations MAY also use "basic" and "digest" authentication and other authentication mechanisms defined for HTTP. Note that "basic" authentication has severe security limitations, so be careful ๐Ÿ˜ญ. The following does not apply to these schemes.

To cryptographically sign a SIP request, the order of the SIP header fields is everything ๐Ÿ‘‘. When an Authorization header field is present, it indicates that all header fields following it have been included in the signature. So hop-by-hop header fields which MUST or SHOULD be modified by proxies MUST precede the Authorization header field, since they'll generally be modified or added-to by proxy servers. Hop-by-hop header fields which MAY be modified by a proxy MAY appear before or after the Authorization header. When they appear before, they MAY be modified by a proxy. When they appear after, they MUST NOT be modified by a proxy. To sign a request, a client builds a message from the request method (in upper case), followed without LWS by the SIP version number, followed again without LWS by the request headers to be signed and the message body. That constructed message is then signed โœจ.

For example, if the SIP request is to be:

INVITE sip:watson@boston.bell-telephone.com SIP/2.0
Via: SIP/2.0/UDP 169.130.12.5
Authorization: PGP version=5.0, signature=...
From: A. Bell <sip:a.g.bell@bell-telephone.com>
To: T. A. Watson <sip:watson@bell-telephone.com>
Call-ID: 187602141351@worcester.bell-telephone.com
Subject: Mr. Watson, come here.
Content-Type: application/sdp
Content-Length: ...

v=0
o=bell 53655765 2353687637 IN IP4 128.3.4.5
c=IN IP4 135.180.144.94
m=audio 3456 RTP/AVP 0 3 4 5

Then the data block that is signed is:

INVITESIP/2.0From: A. Bell <sip:a.g.bell@bell-telephone.com>
To: T. A. Watson <sip:watson@bell-telephone.com>
Call-ID: 187602141351@worcester.bell-telephone.com
Subject: Mr. Watson, come here.
Content-Type: application/sdp
Content-Length: ...

v=0
o=bell 53655765 2353687637 IN IP4 128.3.4.5
c=IN IP4 135.180.144.94
m=audio 3456 RTP/AVP 0 3 4 5

Clients wishing to authenticate requests MUST construct the portion of the message below the Authorization header using a canonical form ๐Ÿง. This lets a proxy parse the message, take it apart, and reconstruct it without causing an authentication failure due to extra white space, for example. Canonical form follows these rules:

  • No short form header fields
  • Header field names are capitalized as shown in this document
  • No white space between the header name and the colon
  • A single space after the colon
  • Line termination with a CRLF
  • No line folding
  • No comma separated lists of header values; each must appear as a separate header
  • Only a single SP between tokens, between tokens and quoted strings, and between quoted strings; no SP after last token or quoted string
  • No LWS between tokens and separators, except as described above for after the colon in header fields

Note that if a message is encrypted and authenticated using a digital signature, encryption happens before the digital signature is generated when the message is created. On receipt, the digital signature is checked before decryption ๐Ÿ”.

A client MAY require that a server sign its response by including a Require: org.ietf.sip.signed-response request header field ๐Ÿฆ‹. The client indicates the desired authentication method via the WWW-Authenticate header.

The correct behavior when handling unauthenticated responses to a request that requires authenticated responses is described in section 13.2.1 ๐Ÿ’–.

13.2.1 Trusting responses

There's a real possibility that an eavesdropper listens to requests and then injects unauthenticated responses that terminate, redirect or otherwise interfere with a call ๐Ÿ˜ฑ. (Even encrypted requests contain enough information to fake a response.)

Clients need to be extra careful with 3xx redirection responses ๐Ÿšฉ. So a client that gets, say, a 301 (Moved Permanently) which wasn't authenticated, even though the public key of the called user agent is known to the client and authentication was requested in the request, SHOULD be treated as suspicious. The correct move in that case is for the called-user to form a dated response containing the Contact field to be used, sign it, and give this signed stub response to the proxy that will provide the redirection. That way the response can be authenticated correctly ๐Ÿงš. A client SHOULD NOT automatically redirect such a request to the new location without alerting the user to the authentication failure before doing so.

Another problem might be responses such as 6xx failure responses, which would simply terminate a search, or "4xx" and "5xx" response failures ๐Ÿ’€.

If TCP is being used, a proxy SHOULD treat 4xx and 5xx responses as valid, since they won't terminate a search. However, fake 6xx responses from a rogue proxy terminate a search incorrectly ๐Ÿ™ˆ. 6xx responses SHOULD be authenticated if requested by the client, and failure to do so SHOULD cause such a client to ignore the 6xx response and continue a search.

With UDP, the same problem with 6xx responses exists, but there's also the issue that an active eavesdropper can generate 4xx and 5xx responses that might make a proxy or client believe a failure occurred when in fact it didn't ๐Ÿ˜ญ. Typically 4xx and 5xx responses won't be signed by the called user agent, so there's no simple way to detect these rogue responses. The best prevention is hop-by-hop encryption of the SIP request, which removes any extra problems UDP might have over TCP ๐Ÿ”ฅ.

These attacks are prevented by having the client require response authentication and dropping unauthenticated responses โœจ. A server user agent that can't perform response authentication responds using the normal Require response of 420 (Bad Extension).

13.3 Callee Privacy

User location and SIP-initiated calls can violate a callee's privacy ๐Ÿซถ. An implementation SHOULD be able to restrict, on a per-user basis, what kind of location and availability information gets given out to certain classes of callers ๐ŸŒˆ.

13.4 Known Security Problems

Okay, this one's serious ๐Ÿšจ. With either TCP or UDP, a denial of service attack exists when a rogue proxy sends 6xx responses. Although a client SHOULD choose to ignore such responses if it requested authentication, a proxy can't do that. It's obliged to forward the 6xx response back to the client. The client can then ignore the response, but if it repeats the request, it'll probably reach the same rogue proxy again, and the process will repeat ๐Ÿ’€.

14 SIP Authentication using HTTP Basic and Digest Schemes

SIP implementations MAY use HTTP's basic and digest authentication mechanisms to provide a rudimentary form of security ๐ŸŒธ. This section overviews how these mechanisms are used in SIP. The basic operation is almost completely identical to that for HTTP [36]. This section outlines that operation, points to [36] for details, and notes the differences when used in SIP ๐Ÿ’….

14.1 Framework

The framework for SIP authentication parallels the one for HTTP [36]. In particular, the BNF for auth-scheme, auth-param, challenge, realm, realm-value, and credentials is identical ๐Ÿง. The 401 response is used by user agent servers in SIP to challenge the authorization of a user agent client. Additionally, registrars and redirect servers MAY make use of 401 responses for authorization, but proxies MUST NOT, and instead MAY use the 407 response ๐Ÿ‘‘. The requirements for including the Proxy-Authenticate, Proxy-Authorization, WWW-Authenticate, and Authorization in the various messages are identical to [36].

Since SIP doesn't have the concept of a canonical root URL, protection spaces are interpreted differently for SIP ๐Ÿฆ‹. The realm is a protection domain for all SIP URIs with the same value for the userinfo, host and port part of the SIP Request-URI. For example:

INVITE sip:alice.wonderland@example.com SIP/2.0
WWW-Authenticate:  Basic realm="business"

and

INVITE sip:aw@example.com SIP/2.0
WWW-Authenticate: Basic realm="business"

define different protection realms according to this rule ๐ŸŽ€.

When a UAC resubmits a request with its credentials after receiving a 401 or 407 response, it MUST increment the CSeq header field, just as it would normally do when sending an updated request ๐Ÿ’–.

14.2 Basic Authentication

The rules for basic authentication follow those defined in [36], but with the words "origin server" replaced with "user agent server, redirect server , or registrar" ๐ŸŒธ.

Since SIP URIs aren't hierarchical, the paragraph in [36] that states that "all paths at or deeper than the depth of the last symbolic element in the path field of the Request-URI also are within the protection space specified by the Basic realm value of the current challenge" does not apply to SIP ๐Ÿ™ˆ. SIP clients MAY preemptively send the corresponding Authorization header with requests for SIP URIs within the same protection realm (as defined above) without receiving another challenge from the server ๐Ÿงš.

14.3 Digest Authentication โœจ

okay so digest auth follows the rules from [36] ๐Ÿ’… with one big swap: "HTTP 1.1" becomes "SIP/2.0". But there are a few extra differences you NEED to know about, bestie ๐Ÿซถ

  1. The URI included in the challenge has the following BNF:
URI  =  SIP-URL
  1. The BNF for digest-uri-value is:
digest-uri-value  =  Request-URI ; a defined in Section
4.3
  1. The example procedure for choosing a nonce based on Etag does not work for SIP. ๐Ÿ™ˆ
  2. The Authentication-Info and Proxy-Authentication-Info fields are not used in SIP.
  3. The text in [36] regarding cache operation does not apply to SIP.
  4. [36] requires that a server check that the URI in the request line, and the URI included in the Authorization header, point to the same resource. In a SIP context, these two URI's may actually refer to different users, due to forwarding at some proxy. Therefore, in SIP, a server MAY check that the request-uri in the Authorization header corresponds to a user that the server is willing to accept forwarded or direct calls for. ๐Ÿฆ‹ this one is lowkey the plot twist, because forwarding can make the two URIs point at different people, so the check is optional instead of a must.

14.4 Proxy-Authentication ๐Ÿ”

the Proxy-Authentication and Proxy-Authorization stuff works like it does in [36], with one big difference. Proxies MUST NOT add the Proxy-Authorization header. 407 responses MUST be forwarded upstream towards the client, following the same procedures as any other response. It is the client's job to add the Proxy-Authorization header with credentials for the proxy that asked for authentication. ๐Ÿ’–

okay bestie, this is the part that's kind of a trap ๐Ÿ˜ญ If a proxy were to resubmit a request with a Proxy-Authorization header field, it would need to increment the CSeq in the new request. However, this would mean that the UAC which submitted the original request would discard a response from the UAS, as the CSeq value would be different. so yeah, proxies just don't do it ๐Ÿ™…โ€โ™€๏ธ

see sections 6.26 and 6.27 for more info on how these fields are used in SIP. ๐Ÿ“–

15 SIP Security Using PGP ๐ŸŽ€

15.1 PGP Authentication Scheme ๐ŸŒธ

the "pgp" authentication scheme is based on the idea that the client proves who it is by signing its request with its own private key. the server can then figure out where the request came from, as long as it has the public key, ideally signed by a trusted third party. ๐Ÿ”‘

15.1.1 The WWW-Authenticate Response Header ๐Ÿงš

WWW-Authenticate =  "WWW-Authenticate" ":" "pgp" pgp-challenge
pgp-challenge    =  * (";" pgp-params )
pgp-params       =  realm | pgp-version | pgp-algorithm | nonce
realm            =  "realm" "=" realm-value
realm-value      =  quoted-string
pgp-version      =  "version" "="
                     <"> digit *( "." digit ) *letter <">
pgp-algorithm    =  "algorithm" "=" ( "md5" | "sha1" | token )
nonce            =  "nonce" "=" nonce-value
nonce-value      =  quoted-string

here's what each parameter means, bestie ๐Ÿ’œ

realm: a string shown to users so they know which identity to use. This string SHOULD contain at least the name of the host performing the authentication, and MAY additionally indicate the group of users who might have access. An example might be "Users with call-out privileges".

pgp-algorithm: the value of this parameter tells you which PGP message integrity check (MIC) to use to produce the signature. If it's not present, it's assumed to be "md5". The currently defined values are "md5" for the MD5 checksum, and "sha1" for the SHA.1 algorithm. ๐Ÿ”

pgp-version: the version of PGP that the client MUST use. Common values are "2.6.2" and "5.0". The default is 5.0. โœจ

nonce: a server-specified data string which should be uniquely generated each time a 401 response is made. It is RECOMMENDED that this string be base64 or hexadecimal data. Specifically, since the string is passed in the header lines as a quoted string, the double-quote character is not allowed. The contents of the nonce are implementation dependent. The quality of the implementation depends on a good choice. Since the nonce is only used to prevent replay attacks and is signed, a time stamp in units convenient to the server is sufficient. ๐Ÿซถ

replay attacks within the duration of the call setup are of limited interest, so timestamps with a resolution of a few seconds are often should be sufficient. In that case, the server does not have to keep a record of the nonces. ๐Ÿ•ฐ๏ธ

Example:

WWW-Authenticate: pgp ;version="5.0"
  ;realm="Your Startrek identity, please" ;algorithm=md5
  ;nonce="913082051"

15.1.2 The Authorization Request Header ๐Ÿฆ‹

the client is expected to retry the request, passing an Authorization header line, which is defined as follows. ๐Ÿ’…

Authorization  =  "Authorization" ":" "pgp" *( ";" pgp-response )
pgp-response   =  realm | pgp-version | pgp-signature
                  | signed-by | nonce
pgp-signature  =  "signature" "=" quoted-string
signed-by      =  "signed-by" "=" <"> URI <">

the client MUST increment the CSeq header before resubmitting the request. The signature MUST correspond to the From header of the request unless the signed-by parameter is provided. ๐Ÿ”ฅ

pgp-signature: the PGP ASCII-armored signature [33], as it appears between the "BEGIN PGP MESSAGE" and "END PGP MESSAGE" delimiters, without the version indication. The signature is included without any linebreaks. ๐Ÿ“œ

the signature is computed across the nonce (if present), request method, request version and header fields following the Authorization header and the message body, in the same order as they appear in the message. The request method and version are prepended to the header fields without any white space. The signature is computed across the headers as sent, and the terminating CRLF. The CRLF following the Authorization header is NOT included in the signature. ๐Ÿ™ˆ

a server MAY be configured not to generate nonces only if replay attacks are not a concern.

not generating nonces skips the extra request, 401 response and possibly ACK messages, and it cuts delay by one round-trip time โฉ
okay side quest ๐ŸŽ€ ASCII-armored is about 25% less space-efficient than the binary signature, but it's way easier for the receiver to piece together. PGP programs always include the full (compressed) signed text in their output unless ASCII-armored mode ( -sta ) is specified. Typical signatures are about 200 bytes long. The PGP signature mechanism lets the client just pass the request to an external PGP program, and this relies on the requirement that proxy servers are not allowed to reorder or change header fields. ๐Ÿ’€ that's the whole vibe check

realm: the realm is copied from the corresponding WWW-Authenticate header field parameter. ๐ŸŒˆ

signed-by: if and only if the request was not signed by the entity listed in the From header, the signed-by header indicates the name of the signing entity, expressed as a URI. ๐Ÿ‘‘

Receivers of signed SIP messages SHOULD discard any end-to-end header fields above the Authorization header, as they may have been maliciously added en route by a proxy. ๐Ÿšจ bestie be suspicious of anything sitting above that header!!

Example:

Authorization: pgp version="5.0"
  ;realm="Your Startrek identity, please"
  ;nonce="913082051"
  ;signature="iQB1AwUBNNJiUaYBnHmiiQh1AQFYsgL/Wt3dk6TWK81/b0gcNDf
  VAUGU4rhEBW972IPxFSOZ94L1qhCLInTPaqhHFw1cb3lB01rA0RhpV4t5yCdUt
  SRYBSkOK29o5e1KlFeW23EzYPVUm2TlDAhbcjbMdfC+KLFX
  =aIrx"

15.2 PGP Encryption Scheme ๐Ÿ”’

the PGP encryption scheme uses the following syntax:

Encryption    =  "Encryption" ":" "pgp" pgp-eparams
pgp-eparams   =  1# ( pgp-version | pgp-encoding )
pgp-encoding  =  "encoding" "=" "ascii" | token

encoding: describes the encoding or "armor" used by PGP. The value "ascii" refers to the standard PGP ASCII armor, without the lines containing "BEGIN PGP MESSAGE" and "END PGP MESSAGE" and without the version identifier. By default, the encrypted part is included as binary. ๐Ÿง

Example:

Encryption: pgp version="2.6.2", encoding="ascii"

15.3 Response-Key Header Field for PGP ๐Ÿ—๏ธ

Response-Key  =  "Response-Key" ":" "pgp" pgp-eparams
pgp-eparams   =  1# ( pgp-version | pgp-encoding | pgp-key)
pgp-key       =  "key" "=" quoted-string

if ASCII encoding has been requested via the encoding parameter, the key parameter contains the user's public key as extracted from the pgp key ring with the "pgp -kxa user " command. ๐Ÿ’œ

Example:

Response-Key: pgp version="2.6.2", encoding="ascii",
  key="mQBtAzNWHNYAAAEDAL7QvAdK2utY05wuUG+ItYK5tCF8HNJM60sU4rLaV+eUnkMk
  mOmJWtc2wXcZx1XaXb2lkydTQOesrUR75IwNXBuZXPEIMThEa5WLsT7VLme7njnx
  sE86SgWmAZx5ookIdQAFEbQxSGVubmluZyBTY2h1bHpyaW5uZSA8c2NodWx6cmlu
  bmVAY3MuY29sdW1iaWEuZWR1Pg==
  =+y19"

16 Examples ๐Ÿ“

In the following examples, we often omit the message body and the corresponding Content-Length and Content-Type headers for brevity. โœจ no body, no stress, let's go!

16.1 Registration โœจ

okay so a user at host saturn.bell-tel.com registers on start-up ๐ŸŒธ, via multicast, with the local SIP server named bell-tel.com. In this example, the user agent on saturn expects to receive SIP requests on UDP port 3890 ๐Ÿฆ‹

C->S: REGISTER sip:bell-tel.com SIP/2.0
      Via: SIP/2.0/UDP saturn.bell-tel.com
      From: sip:watson@bell-tel.com
      To: sip:watson@bell-tel.com
      Call-ID: 70710@saturn.bell-tel.com
      CSeq: 1 REGISTER
      Contact: <sip:watson@saturn.bell-tel.com:3890;transport=udp>
      Expires: 7200

the registration expires after two hours โฐ and any future invitations for watson@bell-tel.com arriving at sip.bell-tel.com will now get redirected to watson@saturn.bell-tel.com, UDP port 3890 ๐Ÿ’…

if Watson wants to be reached somewhere else, like an on-line service he uses while traveling โœˆ๏ธ, he updates his reservation. He has to cancel any existing locations first ๐Ÿ™ˆ

C->S: REGISTER sip:bell-tel.com SIP/2.0
      Via: SIP/2.0/UDP saturn.bell-tel.com
      From: sip:watson@bell-tel.com
      To: sip:watson@bell-tel.com
      Call-ID: 70710@saturn.bell-tel.com
      CSeq: 2 REGISTER
      Contact: *
      Expires: 0

C->S: REGISTER sip:bell-tel.com SIP/2.0
      Via: SIP/2.0/UDP saturn.bell-tel.com
      From: sip:watson@bell-tel.com
      To: sip:watson@bell-tel.com
      Call-ID: 70710@saturn.bell-tel.com
      CSeq: 3 REGISTER
      Contact: sip:tawatson@example.com

now the server will forward any request for Watson to the server at example.com, using the Request-URI tawatson@example.com ๐ŸŽ€. For the server at example.com to reach Watson, he will need to send a REGISTER there, or inform the server of his current location through some other means ๐Ÿงš

it's also possible to use third-party registration ๐Ÿ‘‘ Here, the secretary jon.diligent registers his boss, T. Watson ๐Ÿ’ผ

C->S: REGISTER sip:bell-tel.com SIP/2.0
      Via: SIP/2.0/UDP pluto.bell-tel.com
      From: sip:jon.diligent@bell-tel.com
      To: sip:watson@bell-tel.com
      Call-ID: 17320@pluto.bell-tel.com
      CSeq: 1 REGISTER
      Contact: sip:tawatson@example.com

the request could be sent to either the registrar at bell-tel.com or the server at example.com ๐ŸŒˆ In the latter case, the server at example.com would proxy the request to the address indicated in the Request-URI. Then, the Max-Forwards header could be used to restrict the registration to that server ๐Ÿ’œ


16.2 Invitation to a Multicast Conference ๐ŸŽถ

the first example invites schooler@vlsi.cs.caltech.edu to a multicast session ๐ŸŽง All examples use the Session Description Protocol (SDP) (RFC 2327 [6]) as the session description format โœจ

16.2.1 Request

C->S: INVITE sip:schooler@cs.caltech.edu SIP/2.0
      Via: SIP/2.0/UDP csvax.cs.caltech.edu;branch=8348
        ;maddr=239.128.16.254;ttl=16
      Via: SIP/2.0/UDP north.east.isi.edu
      From: Mark Handley <sip:mjh@isi.edu>
      To: Eve Schooler <sip:schooler@caltech.edu>
      Call-ID: 2963313058@north.east.isi.edu
      CSeq: 1 INVITE
      Subject: SIP will be discussed, too
      Content-Type: application/sdp
      Content-Length: 187

      v=0
      o=user1 53655765 2353687637 IN IP4 128.3.4.5
      s=Mbone Audio
      i=Discussion of Mbone Engineering Issues
      e=mbone@somewhere.com
      c=IN IP4 224.2.0.1/127
      t=0 0
      m=audio 3456 RTP/AVP 0

the From header up there tells us the request came from mjh@isi.edu and was addressed to schooler@caltech.edu ๐Ÿ’Œ The Via fields list the hosts along the path, from the invitation initiator (the last element of the list) towards the callee ๐Ÿ—บ๏ธ In this example, the message was last multicast to the administratively scoped group 239.128.16.254 with a ttl of 16, from the host csvax.cs.caltech.edu. The second Via header field shows it was originally sent from north.east.isi.edu ๐Ÿ” And the Request-URI says the request is currently being being addressed to schooler@cs.caltech.edu, which is the local address csvax looked up for the callee ๐Ÿซถ

here the session description uses the Session Description Protocol (SDP), as the Content-Type header says ๐ŸŒธ

the header ends with an empty line, and then comes a message body with the session description ๐Ÿ’–

16.2.2 Response

the called user agent, directly or indirectly through proxy servers, says it's alerting ("ringing") the called party ๐Ÿ””

S->C: SIP/2.0 180 Ringing
      Via: SIP/2.0/UDP csvax.cs.caltech.edu;branch=8348
        ;maddr=239.128.16.254;ttl=16
      Via: SIP/2.0/UDP north.east.isi.edu
      From: Mark Handley <sip:mjh@isi.edu>
      To: Eve Schooler <sip:schooler@caltech.edu> ;tag=9883472
      Call-ID: 2963313058@north.east.isi.edu
      CSeq: 1 INVITE

here's a sample response to the invitation ๐Ÿฅฐ The first line says the SIP version, plus a 200 (OK) response, which means the request went through โœ… The Via headers are copied from the request, and entries get removed hop by hop as the response retraces the path of the request ๐Ÿ”™ A new authentication field MAY be added by the invited user's agent if required ๐Ÿ” The Call-ID is taken straight from the original request, along with the remaining fields of the request message. The original sense of the From field is kept (so it's still the session initiator) ๐Ÿ‘‘

also, the Contact header gives details of the host where the user was located, or the relevant proxy contact point, which should be reachable from the caller's host ๐Ÿ“

S->C: SIP/2.0 200 OK
      Via: SIP/2.0/UDP csvax.cs.caltech.edu;branch=8348
        ;maddr=239.128.16.254;ttl=16
      Via: SIP/2.0/UDP north.east.isi.edu
      From: Mark Handley <sip:mjh@isi.edu>
      To: Eve Schooler <sip:schooler@caltech.edu> ;tag=9883472
      Call-ID: 2963313058@north.east.isi.edu
      CSeq: 1 INVITE
      Contact: sip:es@jove.cs.caltech.edu

the caller confirms the invitation by sending an ACK request to the location named in the Contact header ๐Ÿค

C->S: ACK sip:es@jove.cs.caltech.edu SIP/2.0
      Via: SIP/2.0/UDP north.east.isi.edu
      From: Mark Handley <sip:mjh@isi.edu>
      To: Eve Schooler <sip:schooler@caltech.edu> ;tag=9883472
      Call-ID: 2963313058@north.east.isi.edu
      CSeq: 1 ACK

16.3 Two-party Call ๐Ÿ“ž

for two-party Internet phone calls, the response must contain a description of where to send the data ๐Ÿ“จ In the example below, Bell calls Watson ๐ŸŽค Bell says he can receive RTP audio codings 0 (PCMU), 3 (GSM), 4 (G.723) and 5 (DVI4) ๐ŸŽต

C->S: INVITE sip:watson@boston.bell-tel.com SIP/2.0
      Via: SIP/2.0/UDP kton.bell-tel.com
      From: A. Bell <sip:a.g.bell@bell-tel.com>
      To: T. Watson <sip:watson@bell-tel.com>
      Call-ID: 3298420296@kton.bell-tel.com
      CSeq: 1 INVITE
      Subject: Mr. Watson, come here.
      Content-Type: application/sdp
      Content-Length: ...

      v=0
      o=bell 53655765 2353687637 IN IP4 128.3.4.5
      s=Mr. Watson, come here.
      c=IN IP4 kton.bell-tel.com
      m=audio 3456 RTP/AVP 0 3 4 5
S->C: SIP/2.0 100 Trying
      Via: SIP/2.0/UDP kton.bell-tel.com
      From: A. Bell <sip:a.g.bell@bell-tel.com>
      To: T. Watson <sip:watson@bell-tel.com> ;tag=37462311
      Call-ID: 3298420296@kton.bell-tel.com
      CSeq: 1 INVITE
      Content-Length: 0

S->C: SIP/2.0 180 Ringing
      Via: SIP/2.0/UDP kton.bell-tel.com
      From: A. Bell <sip:a.g.bell@bell-tel.com>
      To: T. Watson <sip:watson@bell-tel.com> ;tag=37462311
      Call-ID: 3298420296@kton.bell-tel.com
      CSeq: 1 INVITE
      Content-Length: 0

S->C: SIP/2.0 182 Queued, 2 callers ahead
      Via: SIP/2.0/UDP kton.bell-tel.com
      From: A. Bell <sip:a.g.bell@bell-tel.com>
      To: T. Watson <sip:watson@bell-tel.com> ;tag=37462311
      Call-ID: 3298420296@kton.bell-tel.com
      CSeq: 1 INVITE
      Content-Length: 0

S->C: SIP/2.0 182 Queued, 1 caller ahead
      Via: SIP/2.0/UDP kton.bell-tel.com
      From: A. Bell <sip:a.g.bell@bell-tel.com>
      To: T. Watson <sip:watson@bell-tel.com> ;tag=37462311
      Call-ID: 3298420296@kton.bell-tel.com
      CSeq: 1 INVITE
      Content-Length: 0

S->C: SIP/2.0 200 OK
      Via: SIP/2.0/UDP kton.bell-tel.com
      From: A. Bell <sip:a.g.bell@bell-tel.com>
      To: <sip:watson@bell-tel.com> ;tag=37462311
      Call-ID: 3298420296@kton.bell-tel.com
      CSeq: 1 INVITE
      Contact: sip:watson@boston.bell-tel.com
      Content-Type: application/sdp
      Content-Length: ...

      v=0
      o=watson 4858949 4858949 IN IP4 192.1.2.3
      s=I'm on my way
      c=IN IP4 boston.bell-tel.com
      m=audio 5004 RTP/AVP 0 3

this example shows informational status responses in action ๐ŸŒŸ The call gets confirmed right away (100), then, maybe after some database mapping delay, it rings (180) and gets queued, with periodic status updates ๐Ÿ”„

Watson can only receive PCMU and GSM ๐ŸŽง Watson's list of codecs may or may not be a subset of the one Bell offered, since each party says which data types it's willing to receive ๐Ÿงƒ Watson will send audio data to port 3456 at c.bell-tel.com, and Bell will send to port 5004 at boston.bell-tel.com ๐Ÿ’ซ

by default, the media session is one RTP session ๐ŸŽ€ Watson will receive RTCP packets on port 5005, while Bell will receive them on port 3457 ๐Ÿฆ‹

since both sides agreed on the set of media, Bell confirms the call without adding another session description ๐Ÿ’…

C->S: ACK sip:watson@boston.bell-tel.com SIP/2.0
      Via: SIP/2.0/UDP kton.bell-tel.com
      From: A. Bell <sip:a.g.bell@bell-tel.com>
      To: T. Watson <sip:watson@bell-tel.com> ;tag=37462311
      Call-ID: 3298420296@kton.bell-tel.com
      CSeq: 1 ACK

16.4 Terminating a Call ๐Ÿ‘‹

to end a call, either the caller or the callee can send a BYE request ๐Ÿ“ด

C->S: BYE sip:watson@boston.bell-tel.com SIP/2.0
      Via: SIP/2.0/UDP kton.bell-tel.com
      From: A. Bell <sip:a.g.bell@bell-tel.com>
      To: T. A. Watson <sip:watson@bell-tel.com> ;tag=37462311
      Call-ID: 3298420296@kton.bell-tel.com
      CSeq: 2 BYE

if the callee wants to hang up on the call, they just swap the To and From fields ๐Ÿ”„ Also, it's unlikely that a BYE from the callee will go through the same proxies as the original INVITE ๐ŸŒ

16.5 Forking Proxy โœจ

okay so this one is giving main character energy ๐Ÿ’… Bell (a.g.bell@bell-tel.com) (C) is sitting at host c.bell-tel.com and wants to call Watson (t.watson@ieee.org) ๐Ÿ“ž At the time of the call, Watson is logged in at two workstations, t.watson@x.bell-tel.com (X) and watson@y.bell-tel.com (Y), and has registered with the IEEE proxy server (P) called sip.ieee.org ๐Ÿฆ‹ The IEEE server also has a registration for the home machine of Watson, at watson@h.bell-tel.com (H), as well as a permanent registration at watson@acm.org (A) ๐ŸŒˆ For brevity, the examples leave out the session description and Via header fields ๐Ÿ™ˆ

Bell's user agent sends the invitation to the SIP server for the ieee.org domain ๐Ÿ’Œ

C->P: INVITE sip:t.watson@ieee.org SIP/2.0
      Via:     SIP/2.0/UDP c.bell-tel.com
      From:    A. Bell <sip:a.g.bell@bell-tel.com>
      To:      T. Watson <sip:t.watson@ieee.org>
      Call-ID: 31415@c.bell-tel.com
      CSeq:    1 INVITE

The SIP server at ieee.org tries the four addresses in parallel ๐Ÿ”ฅ It sends the following message to the home machine:

P->H: INVITE sip:watson@h.bell-tel.com SIP/2.0
      Via:     SIP/2.0/UDP sip.ieee.org ;branch=1
      Via:     SIP/2.0/UDP c.bell-tel.com
      From:    A. Bell <sip:a.g.bell@bell-tel.com>
      To:      T. Watson <sip:t.watson@ieee.org>
      Call-ID: 31415@c.bell-tel.com
      CSeq:    1 INVITE

This request immediately yields a 404 (Not Found) response, since Watson is not currently logged in at home ๐Ÿ’€

H->P: SIP/2.0 404 Not Found
      Via:     SIP/2.0/UDP sip.ieee.org ;branch=1
      Via:     SIP/2.0/UDP c.bell-tel.com
      From:    A. Bell <sip:a.g.bell@bell-tel.com>
      To:      T. Watson <sip:t.watson@ieee.org>;tag=87454273
      Call-ID: 31415@c.bell-tel.com
      CSeq:    1 INVITE

The proxy ACKs the response so that host H can stop retransmitting it ๐Ÿซถ

P->H: ACK sip:watson@h.bell-tel.com SIP/2.0
      Via:     SIP/2.0/UDP sip.ieee.org ;branch=1
      From:    A. Bell <sip:a.g.bell@bell-tel.com>
      To:      T. Watson <sip:t.watson@ieee.org>;tag=87454273
      Call-ID: 31415@c.bell-tel.com
      CSeq:    1 ACK

Also, P attempts to reach Watson through the ACM server ๐ŸŒธ

P->A: INVITE sip:watson@acm.org SIP/2.0
      Via:     SIP/2.0/UDP sip.ieee.org ;branch=2
      Via:     SIP/2.0/UDP c.bell-tel.com
      From:    A. Bell <sip:a.g.bell@bell-tel.com>
      To:      T. Watson <sip:t.watson@ieee.org>
      Call-ID: 31415@c.bell-tel.com
      CSeq:    1 INVITE

In parallel, the next attempt proceeds, with an INVITE to X and Y โšก

P->X: INVITE sip:t.watson@x.bell-tel.com SIP/2.0
      Via:     SIP/2.0/UDP sip.ieee.org ;branch=3
      Via:     SIP/2.0/UDP c.bell-tel.com
      From:    A. Bell <sip:a.g.bell@bell-tel.com>
      To:      T. Watson <sip:t.watson@ieee.org>
      Call-ID: 31415@c.bell-tel.com
      CSeq:    1 INVITE

P->Y: INVITE sip:watson@y.bell-tel.com SIP/2.0
      Via:     SIP/2.0/UDP sip.ieee.org ;branch=4
      Via:     SIP/2.0/UDP c.bell-tel.com
      From:    A. Bell <sip:a.g.bell@bell-tel.com>
      To:      T. Watson <sip:t.watson@ieee.org>
      Call-ID: 31415@c.bell-tel.com
      CSeq:    1 INVITE

As it happens, both Watson at X and a colleague in the other lab at host Y hear the phones ringing and pick up ๐Ÿ™Œ Both X and Y return 200s via the proxy to Bell.

X->P: SIP/2.0 200 OK
      Via:      SIP/2.0/UDP sip.ieee.org ;branch=3
      Via:      SIP/2.0/UDP c.bell-tel.com
      From:     A. Bell <sip:a.g.bell@bell-tel.com>
      To:       T. Watson <sip:t.watson@ieee.org> ;tag=192137601
      Call-ID:  31415@c.bell-tel.com
      CSeq:     1 INVITE
      Contact:  sip:t.watson@x.bell-tel.com

Y->P: SIP/2.0 200 OK
      Via:      SIP/2.0/UDP sip.ieee.org ;branch=4
      Via:      SIP/2.0/UDP c.bell-tel.com
      Contact:  sip:t.watson@y.bell-tel.com
      From:     A. Bell <sip:a.g.bell@bell-tel.com>
      To:       T. Watson <sip:t.watson@ieee.org> ;tag=35253448
      Call-ID:  31415@c.bell-tel.com
      CSeq:     1 INVITE

Both responses are forwarded to Bell, using the Via information. At this point, the ACM server is still searching its database. P can now cancel this attempt ๐Ÿ›‘

P->A: CANCEL sip:watson@acm.org SIP/2.0
      Via:     SIP/2.0/UDP sip.ieee.org ;branch=2
      From:    A. Bell <sip:a.g.bell@bell-tel.com>
      To:      T. Watson <sip:t.watson@ieee.org>
      Call-ID: 31415@c.bell-tel.com
      CSeq:    1 CANCEL

The ACM server gladly stops its neural-network database search and responds with a 200. The 200 will not travel any further, since P is the last Via stop ๐Ÿงš

A->P: SIP/2.0 200 OK
      Via:     SIP/2.0/UDP sip.ieee.org ;branch=2
      From:    A. Bell <sip:a.g.bell@bell-tel.com>
      To:      T. Watson <sip:t.watson@ieee.org>
      Call-ID: 31415@c.bell-tel.com
      CSeq:    1 CANCEL

Bell gets the two 200 responses from X and Y in short order. Bell's reaction now depends on his software. He can either send an ACK to both if human intelligence is needed to determine who he wants to talk to, or he can automatically reject one of the two calls. Here, he acknowledges both, separately and directly to the final destination ๐ŸŽ€

C->X: ACK sip:t.watson@x.bell-tel.com SIP/2.0
      Via:      SIP/2.0/UDP c.bell-tel.com
      From:     A. Bell <sip:a.g.bell@bell-tel.com>
      To:       T. Watson <sip:t.watson@ieee.org>;tag=192137601
      Call-ID:  31415@c.bell-tel.com
      CSeq:     1 ACK

C->Y: ACK sip:watson@y.bell-tel.com SIP/2.0
      Via:      SIP/2.0/UDP c.bell-tel.com
      From:     A. Bell <sip:a.g.bell@bell-tel.com>
      To:       T. Watson <sip:t.watson@ieee.org>;tag=35253448
      Call-ID:  31415@c.bell-tel.com
      CSeq:     1 ACK

After a brief discussion between Bell with X and Y, it becomes clear that Watson is at X. (Note that this is not a three-way call; only Bell can talk to X and Y, but X and Y cannot talk to each other ๐Ÿ™…โ€โ™€๏ธ) Thus, Bell sends a BYE to Y, which is replied to ๐Ÿ‘‹

C->Y: BYE sip:watson@y.bell-tel.com SIP/2.0
      Via:      SIP/2.0/UDP c.bell-tel.com
      From:     A. Bell <sip:a.g.bell@bell-tel.com>
      To:       T. Watson <sip:t.watson@ieee.org>;tag=35253448
      Call-ID:  31415@c.bell-tel.com
      CSeq:     2 BYE

Y->C: SIP/2.0 200 OK
      Via:      SIP/2.0/UDP c.bell-tel.com
      From:     A. Bell <sip:a.g.bell@bell-tel.com>
      To:       T. Watson <sip:t.watson@ieee.org>;tag=35253448
      Call-ID:  31415@c.bell-tel.com
      CSeq:     2 BYE

16.6 Redirects ๐Ÿฆ‹

Replies with status codes 301 (Moved Permanently) or 302 (Moved Temporarily) specify another location using the Contact field. Continuing our earlier example, the server P at ieee.org decides to redirect rather than proxy the request ๐Ÿ”€

P->C: SIP/2.0 302 Moved temporarily
      Via:     SIP/2.0/UDP c.bell-tel.com
      From:    A. Bell <sip:a.g.bell@bell-tel.com>
      To:      T. Watson <sip:t.watson@ieee.org>;tag=72538263
      Call-ID: 31415@c.bell-tel.com
      CSeq:    1 INVITE
      Contact: sip:watson@h.bell-tel.com,
                sip:watson@acm.org, sip:t.watson@x.bell-tel.com,
                sip:watson@y.bell-tel.com
      CSeq: 1 INVITE

As another example, assume Alice (A) wants to delegate her calls to Bob (B) while she is on vacation until July 29th, 1998 ๐Ÿ–๏ธ Any calls meant for her will reach Bob with Alice's To field, indicating to him what role he is to play. Charlie (C) calls Alice (A), and her server returns:

A->C: SIP/2.0 302 Moved temporarily
      From: Charlie <sip:charlie@caller.com>
      To: Alice <sip:alice@anywhere.com> ;tag=2332462
      Call-ID: 27182@caller.com
      Contact: sip:bob@anywhere.com
      Expires: Wed, 29 Jul 1998 9:00:00 GMT
      CSeq: 1 INVITE

Charlie then sends the following request to the SIP server of the anywhere.com domain. Note that the server at anywhere.com forwards the request to Bob based on the Request-URI ๐Ÿ‘€

C->B: INVITE sip:bob@anywhere.com SIP/2.0
      From: sip:charlie@caller.com
      To: sip:alice@anywhere.com
      Call-ID: 27182@caller.com
      CSeq: 2 INVITE

In the third redirection example, we assume that all outgoing requests are directed through a local firewall F at caller.com, with Charlie again inviting Alice ๐Ÿ”ฅ

C->F: INVITE sip:alice@anywhere.com SIP/2.0
      From: sip:charlie@caller.com
      To: Alice <sip:alice@anywhere.com>
      Call-ID: 27182@caller.com
      CSeq: 1 INVITE

The local firewall at caller.com happens to be overloaded and thus redirects the call from Charlie to a secondary server S ๐Ÿ˜ฉ

F->C: SIP/2.0 302 Moved temporarily
      From: sip:charlie@caller.com
      To: Alice <sip:alice@anywhere.com>
      Call-ID: 27182@caller.com
      CSeq: 1 INVITE
      Contact: <sip:alice@anywhere.com:5080;maddr=spare.caller.com>

Based on this response, Charlie directs the same invitation to the secondary server spare.caller.com at port 5080, but maintains the same Request-URI as before ๐Ÿซก

C->S: INVITE sip:alice@anywhere.com SIP/2.0
      From: sip:charlie@caller.com
      To: Alice <sip:alice@anywhere.com>
      Call-ID: 27182@caller.com
      CSeq: 2 INVITE

16.7 Negotiation ๐ŸŽถ

An example of a 606 (Not Acceptable) response is:

S->C: SIP/2.0 606 Not Acceptable
      From: sip:mjh@isi.edu
      To: <sip:schooler@cs.caltech.edu> ;tag=7434264
      Call-ID: 14142@north.east.isi.edu
      CSeq: 1 INVITE
      Contact: sip:mjh@north.east.isi.edu
      Warning: 370 "Insufficient bandwidth (only have ISDN)",
        305 "Incompatible media format",
        330 "Multicast not available"
      Content-Type: application/sdp
      Content-Length: 50

      v=0
      s=Let's talk
      b=CT:128
      c=IN IP4 north.east.isi.edu
      m=audio 3456 RTP/AVP 5 0 7
      m=video 2232 RTP/AVP 31

In this example, the original request specified a bandwidth that was higher than the access link could support, requested multicast, and requested a set of media encodings. The response states that only 128 kb/s is available and that (only) DVI, PCM or LPC audio could be supported in order of preference ๐ŸŽง

The response also states that multicast is not available. In such a case, it might be appropriate to set up a transcoding gateway and re-invite the user ๐Ÿ™


16.8 OPTIONS Request ๐Ÿ”

A caller Alice can use an OPTIONS request to find out the capabilities of a potential callee Bob, without "ringing" the designated address ๐Ÿ›Ž๏ธ Bob returns a description indicating that he is capable of receiving audio encodings PCM Ulaw (payload type 0), 1016 (payload type 1), GSM (payload type 3), and SX7300/8000 (dynamic payload type 99), and video encodings H.261 (payload type 31) and H.263 (payload type 34) ๐Ÿ’œ

C->S: OPTIONS sip:bob@example.com SIP/2.0
      From: Alice <sip:alice@anywhere.org>
      To: Bob <sip:bob@example.com>
      Call-ID: 6378@host.anywhere.org
      CSeq: 1 OPTIONS
      Accept: application/sdp

S->C: SIP/2.0 200 OK
      From: Alice <sip:alice@anywhere.org>
      To: Bob <sip:bob@example.com> ;tag=376364382
      Call-ID: 6378@host.anywhere.org
      Content-Length: 81
      Content-Type: application/sdp

      v=0
      m=audio 0 RTP/AVP 0 1 3 99
      m=video 0 RTP/AVP 31 34
      a=rtpmap:99 SX7300/8000

A Minimal Implementation โœจ

A.1 Client ๐Ÿ’…

Okay bestie, clients are the ones who start the calls, so they've got a LOT to do ๐Ÿ˜ญ All clients MUST be able to generate the INVITE and ACK requests. Clients MUST generate and parse the Call-ID, Content-Length, Content-Type, CSeq, From and To headers. Clients MUST also parse the Require header. A minimal implementation MUST understand SDP (RFC 2327, [6]). It MUST be able to recognize the status code classes 1 through 6 and act accordingly โœจ

Now for the extra capability sets! Each one stacks on the ones above it, so it's giving layered cake ๐ŸŽ‚

Basic: A basic implementation adds support for the BYE method so it can interrupt a pending call attempt. It includes a User-Agent header in its requests and says its preferred language in the Accept-Language header ๐ŸŒธ

Redirection: To support call forwarding, a client needs to understand the Contact header, but only the SIP-URL part, not the parameters ๐Ÿฆ‹

Firewall-friendly: A firewall-friendly client understands the Route and Record-Route header fields, and it can be set up to use a local proxy for all outgoing requests ๐Ÿงš

Negotiation: A client MUST be able to request the OPTIONS method and understand the 380 (Alternative Service) status and the Contact parameters, so it can take part in terminal and media negotiation. It SHOULD be able to parse the Warning response header to give the caller useful feedback ๐Ÿ’–

Authentication: If a client wants to invite callees that require caller authentication, it MUST be able to recognize the 401 (Unauthorized) status code, MUST be able to generate the Authorization request header and MUST understand the WWW-Authenticate response header ๐Ÿ”

If a client wants to use proxies that require caller authentication, it MUST be able to recognize the 407 (Proxy Authentication Required) status code, MUST be able to generate the Proxy-Authorization request header and understand the Proxy-Authenticate response header. Main character energy, fr fr ๐Ÿ‘‘


A.2 Server ๐Ÿงš

A minimally compliant server implementation MUST understand the INVITE, ACK, OPTIONS and BYE requests. A proxy server MUST also understand CANCEL. It MUST parse and generate, as appropriate, the Call-ID, Content-Length, Content-Type, CSeq, Expires, From, Max-Forwards, Require, To and Via headers. It MUST echo the CSeq and Timestamp headers in the response. It SHOULD include the Server header in its responses ๐ŸŽ€


A.3 Header Processing ๐Ÿ“‹

Table 6 is the cheat sheet for which headers each kind of system has to deal with, and it's honestly so iconic. UAC means a user-agent client (the calling user agent), and UAS means a user-agent server (the called user-agent) ๐Ÿ’…

Here's what the letters mean:

  • - means the field is not meaningful to this system (although it might still be generated by it).
  • m means the field MUST be understood.
  • b means the field SHOULD be understood by a Basic implementation.
  • r means the field SHOULD be understood if the system claims to understand redirection.
  • a means the field SHOULD be understood if the system claims to support authentication.
  • e means the field SHOULD be understood if the system claims to support encryption.
  • o means support of the field is purely optional.

Type is as in Table 4 and 5. Headers whose support is optional for all implementations are not shown, so don't go looking for them ๐Ÿ™ˆ

                        type  UAC  proxy  UAS  registrar
   _____________________________________________________
   Accept                R     -     o     m      m
   Accept-Encoding       R     -     -     m      m
   Accept-Language       R     -     b     b      b
   Allow                405    o     -     -      -
   Authorization         R     a     o     a      a
   Call-ID               g     m     m     m      m
   Content-Encoding      g     m     -     m      m
   Content-Length        g     m     m     m      m
   Content-Type          g     m     -     m      m
   CSeq                  g     m     m     m      m
   Encryption            g     e     -     e      e
   Expires               g     -     o     o      m
   From                  g     m     o     m      m
   Hide                  R     -     m     -      -
   Contact               R     -     -     -      m
   Contact               r     r     r     -      -
   Max-Forwards          R     -     b     -      -
   Proxy-Authenticate   407    a     -     -      -
   Proxy-Authorization   R     -     a     -      -
   Proxy-Require         R     -     m     -      -
   Require               R     m     -     m      m
   Response-Key          R     -     -     e      e
   Route                 R     -     m     -      -
   Timestamp             g     o     o     m      m
   To                    g     m     m     m      m
   Unsupported           r     b     b     -      -
   User-Agent            g     b     -     b      -
   Via                   g     m     m     m      m
   WWW-Authenticate     401    a     -     -      -

Table 6: Header Field Processing Requirements โœจ


B Usage of the Session Description Protocol (SDP) ๐ŸŽ€

This section is all about how to use the Session Description Protocol (SDP) (RFC 2327 [6]), so grab your snacks ๐Ÿ“

B.1 Configuring Media Streams ๐ŸŽถ

The caller and callee line up their media descriptions so that the nth media stream ("m=" line) in the caller's session description matches the nth media stream in the callee's description. It's like a dance routine, everyone has to hit their marks ๐Ÿ’ƒ

All media descriptions SHOULD contain "a=rtpmap" mappings from RTP payload types to encodings.

This allows easier migration away from static payload types.

If the callee wants to neither send nor receive a stream offered by the caller, the callee sets the port number of that stream to zero in its media description.

There's currently no other way than port zero for the callee to refuse a bidirectional stream offered by the caller. Both caller and callee need to be aware of which media tools are to be started. Teamwork makes the dream work ๐Ÿซถ

For example, assume that the caller Alice has put the following description in her INVITE request. It includes an audio stream and two bidirectional video streams, using H.261 (payload type 31) and MPEG (payload type 32) ๐Ÿฆ‹

v=0
o=alice 2890844526 2890844526 IN IP4 host.anywhere.com
c=IN IP4 host.anywhere.com
m=audio 49170 RTP/AVP 0
a=rtpmap:0 PCMU/8000
m=video 51372 RTP/AVP 31
a=rtpmap:31 H261/90000
m=video 53000 RTP/AVP 32
a=rtpmap:32 MPV/90000

The callee, Bob, doesn't want to receive or send the first video stream, so he sends back the media description below ๐Ÿ™…โ€โ™€๏ธ

v=0
o=bob 2890844730 2890844730 IN IP4 host.example.com
c=IN IP4 host.example.com
m=audio 47920 RTP/AVP 0 1
a=rtpmap:0 PCMU/8000
a=rtpmap:1 1016/8000
m=video 0 RTP/AVP 31
m=video 53000 RTP/AVP 32
a=rtpmap:32 MPV/90000

B.2 Setting SDP Values for Unicast ๐Ÿ“ก

If a session description from a caller has a media stream listed as send (receive) only, it means the caller is only willing to send (receive) that stream, not receive (send) it. Same goes for the callee ๐ŸŒˆ

For receive-only and send-or-receive streams, the port number and address in the session description show where the media stream should be sent by whoever receives the session description, either the caller or the callee. For send-only streams, the address and port number have no significance and SHOULD be set to zero.

The list of payload types for each media stream carries two pieces of info: the set of codecs the caller or callee can send or receive, and the RTP payload type numbers used to identify those codecs. For receive-only or send-and-receive media streams, a caller SHOULD list all of the codecs it can support in the session description in an INVITE or ACK. For send-only streams, the caller SHOULD indicate only the ones it wants to send for this session. For receive-only streams, the payload type numbers are the payload type field values in the RTP packets the caller expects to receive for that codec type. For send-only streams, the payload type numbers are the payload type field values in the RTP packets the caller plans to send for that codec type. For send-and-receive streams, the payload type numbers are the payload type field values the caller expects to both send and receive ๐ŸŽง

If a media stream is listed as receive-only by the caller, the callee lists, in the response, the codecs it plans to use from among the ones in the request. If a media stream is listed as send-only by the caller, the callee lists, in the response, the codecs it is willing to receive from among the ones in the request. If the media stream is listed as both send and receive, the callee lists the codecs it can send or receive from among the ones the caller listed in the INVITE. The actual payload type numbers in the callee's session description for a particular codec MUST be the same as the caller's session description. Matching is everything, bestie ๐Ÿ’œ

If caller and callee have no media formats in common for a particular stream, the callee MUST return a session description containing that particular "m=" line, but with the port number set to zero, and no payload types listed ๐Ÿ˜ญ

If there are no media formats in common for all streams, the callee SHOULD return a 400 response, with a 304 Warning header field. ๐Ÿ’€

B.3 Multicast Operation ๐Ÿ“ฃ

The meaning of send-only and receive-only for multicast media sessions is different from unicast sessions. For multicast, send-only means the recipient of the session description (caller or callee) SHOULD only send media streams to the address and port indicated. Receive-only means the recipient of the session description SHOULD only receive media on the address and port indicated.

For multicast, the receive and send multicast addresses are the same, and all parties use the same port numbers to receive media data. If the session description the caller provided is acceptable to the callee, the callee can choose not to include a session description or MAY echo the description in the response.

A callee MAY, in the response, return a session description with some of the payload types removed, or port numbers set to zero (but no other value). This tells the caller that the callee doesn't support the given stream or media types that were removed. A callee MUST NOT change whether a given stream is send-only, receive-only, or send-and-receive. Don't mess with the vibes ๐Ÿšซ

If a callee doesn't support multicast at all, it SHOULD return a 400 status response and include a 330 Warning. ๐Ÿ™ƒ

B.4 Delayed Media Streams โณ

Sometimes a caller doesn't know yet which media formats it can support when it wants to send the invitation. This happens when the caller is actually a gateway to another protocol that does media format negotiation after call setup. When that's the case, a caller MAY issue an INVITE with a session description that contains no media lines. The callee SHOULD read this as the caller wanting to take part in a multimedia session described by the session description, but with the media streams not known yet. The callee SHOULD still return a session description indicating the streams and media formats it is willing to support. The caller MAY update the session description, either in the ACK request or in a re-INVITE at a later time, once the streams are known ๐ŸŒธ

B.5 Putting Media Streams on Hold ๐Ÿ™ˆ

okay so if one party in a call wants to put the other one "on hold" (aka ask them to temporarily stop sending one or more media streams), they re-invite them by sending an INVITE request with a modified session description ๐Ÿ’Œ The session description is the same as in the original invitation (or response), except the "c" destination addresses for the media streams being put on hold get set to zero (0.0.0.0). main character energy for the hold request ๐Ÿ“žโœจ

B.6 Subject and SDP "s=" Line ๐Ÿ’…

the SDP "s=" line and the SIP Subject header field mean different things when you're inviting someone to a multicast session ๐Ÿ‘€ The session description line describes the subject of the multicast session, while the SIP Subject header field describes the reason for the invitation. The example in Section 16.2 shows this off perfectly ๐Ÿฆ‹ For invitations to two-party sessions, the SDP "s=" line MAY be left empty ๐Ÿซถ

B.7 The SDP "o=" Line ๐ŸŽ€

the "o=" line isn't strictly necessary for two-party sessions, but it MUST be present so SDP-based tools can still be re-used ๐Ÿ”ง๐Ÿ’–

C Summary of Augmented BNF ๐Ÿงš

all of the mechanisms in this spec are described in both prose and an augmented Backus-Naur Form (BNF), which is similar to the one used by RFC 822 [9] ๐Ÿ“ Implementors will need to be familiar with the notation to understand this spec, so bookmark this part bestie ๐Ÿ”– The augmented BNF has these constructs:

name  =  definition

the name of a rule is just the name itself (no enclosing "<" and ">") and it's separated from its definition by the equal "=" character ๐ŸŒธ White space only matters in that indentation of continuation lines shows a rule definition that spans more than one line. Certain basic rules are in uppercase, like SP, LWS, HT, CRLF, DIGIT, ALPHA, etc. Angle brackets get used inside definitions whenever they make it easier to tell which rule names are being used ๐Ÿง 

Quotation marks surround literal text. Unless stated otherwise, the text is case-insensitive ๐Ÿ”ค

"literal"

elements separated by a bar ("|") are alternatives, so "yes | no" will accept yes or no โœ…

rule1 | rule2

elements enclosed in parentheses are treated as a single element. So "(elem (foo | bar) elem)" allows the token sequences "elem foo elem" and "elem bar elem" ๐Ÿงฉ

(rule1 rule2)

the character "" in front of an element means repetition ๐Ÿ” The full form is "<n><m>element", which means at least <n> and at most <m> occurrences of element. The defaults are 0 and infinity, so "*(element)" allows any number (zero included), "1*element" requires at least one, and "1*2element" allows one or two ๐Ÿ’ซ

*rule

square brackets enclose optional elements, so "[foo bar]" is equivalent to "*1(foo bar)" ๐ŸŽˆ

[rule]

specific repetition: "<n>(element)" is equivalent to "<n>*<n>(element)", which means exactly <n> occurrences of (element). So 2DIGIT is a 2-digit number, and 3ALPHA is a string of three alphabetic characters ๐Ÿ”ข

N rule

the construct "#" is defined, similar to "*", for lists of elements โœจ The full form is "<n>#<m> element", meaning at least <n> and at most <m> elements, each separated by one or more commas (",") and OPTIONAL linear white space (LWS). This makes the usual list form super easy, because a rule like this:

( *LWS element *( *LWS "," *LWS element ))

can be written as 1# element. Wherever this construct is used, null elements are allowed, but they don't count toward the number of elements present. So "(element), , (element)" is permitted but only counts as two elements. That means that wherever at least one element is required, at least one non-null element MUST be present. The defaults are 0 and infinity, so "#element" allows any number (zero included), "1#element" requires at least one, and "1#2element" allows one or two ๐Ÿ“‹

#rule

a semi-colon set off some distance to the right of the rule text starts a comment that runs to the end of the line. It's a simple way of adding useful notes alongside the specs ๐Ÿ’ฌ

; comment

the grammar in this spec is word-based. Except where noted otherwise, linear white space (LWS) can go between any two adjacent words (token or quoted-string), and between adjacent tokens and separators, without changing how a field is interpreted ๐Ÿซง At least one delimiter (LWS and/or separators) MUST exist between any two tokens (see the definition of "token" below), since otherwise they'd be read as one single token ๐Ÿ™…โ€โ™€๏ธ

implied *LWS

C.1 Basic Rules ๐ŸŒˆ

these rules get used all over this spec to describe basic parsing stuff. The US-ASCII coded character set is defined by ANSI X3.4-1986 ๐Ÿ” 

OCTET     =  <any 8-bit sequence of data>
CHAR      =  <any US-ASCII character (octets 0 - 127)>
upalpha   =  "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" |
             "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" |
             "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
lowalpha  =  "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" |
             "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" |
             "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
alpha     =  lowalpha | upalpha
digit     =  "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
             "8" | "9"
alphanum  =  alpha | digit
CTL       =  <any US-ASCII control character
             (octets 0 -- 31) and DEL (127)>
CR        =  %d13 ; US-ASCII CR, carriage return character
LF        =  %d10 ; US-ASCII LF, line feed character
SP        =  %d32 ; US-ASCII SP, space character
HT        =  %d09 ; US-ASCII HT, horizontal tab character
CRLF      =  CR LF ; typically the end of a line

these ones are defined in RFC 2396 [12] for the SIP URI ๐Ÿ”—

unreserved  =  alphanum | mark
mark        =  "-" | "_" | "." | "!" | "~" | "*" | "'"
            |   "(" | ")"
escaped     =  "%" hex hex

SIP header field values can be folded onto multiple lines if the continuation line begins with a space or horizontal tab ๐Ÿช„ All linear white space, folding included, has the same semantics as SP. A recipient MAY replace any linear white space with a single SP before interpreting the field value or forwarding the message downstream ๐Ÿ”

LWS  =  [CRLF] 1*( SP | HT ) ; linear whitespace

the TEXT-UTF8 rule is only for descriptive field contents and values that aren't meant to be interpreted by the message parser ๐Ÿ“– Words of *TEXT-UTF8 contain characters from the UTF-8 character set (RFC 2279 [21]). This is where SIP differs from HTTP, which uses the ISO 8859-1 character set ๐ŸŒ

TEXT-UTF8  =  <any UTF-8 character encoding, except CTLs,
              but including LWS>

a CRLF is only allowed in the definition of TEXT-UTF8 as part of a header field continuation. The folding LWS is expected to be replaced with a single SP before the TEXT-UTF8 value gets interpreted ๐Ÿซถ

hexadecimal numeric characters show up in lots of protocol elements ๐Ÿ”ข

hex  =  "A" | "B" | "C" | "D" | "E" | "F"
        | "a" | "b" | "c" | "d" | "e" | "f" | digit

lots of SIP header field values are made of words separated by LWS or special characters. These special characters MUST be in a quoted string to be used within a parameter value ๐Ÿšจ

token       =  1*< any CHAR  except CTL's  or separators>
separators  =  "(" | ")" | "<" | ">" | "@" |
               "," | ";" | ":" | "\" | <"> |
               "/" | "[" | "]" | "?" | "=" |
               "{" | "}" | SP | HT

comments can be included in some SIP header fields by wrapping the comment text in parentheses ๐Ÿ’ญ Comments are only allowed in fields that have "comment" as part of their field value definition. In all other fields, parentheses count as part of the field value ๐Ÿ™ƒ

comment  =  "(" *(ctext | quoted-pair | comment) ")"
ctext    =  < any TEXT-UTF8  excluding "("  and ")">

a string of text is parsed as a single word if it's quoted using double-quote marks ๐ŸŽ€

quoted-string  =  ( <"> *(qdtext | quoted-pair ) <"> )
qdtext         =  <any TEXT-UTF8 except <">>

the backslash character ("") MAY be used as a single-character quoting mechanism, but only within quoted-string and comment constructs ๐Ÿงต

quoted-pair  =  " \ " CHAR

D Using SRV DNS Records ๐Ÿงš

Okay bestie, this procedure is experimental ๐Ÿงช and it relies on DNS SRV records (RFC 2052 [14]). These steps replace the two steps in section 1.4.2 โœจ

If a step gives back no addresses, the client just moves on to the next step ๐Ÿ’… But if a step gives back one or more addresses and none of the SIP servers at those addresses respond, the client concludes the server is down and doesn't keep going. Main character energy, no notes ๐Ÿ’€

When SRV records are in play, the protocol used for the SRV query is "sip" ๐Ÿฆ‹ SRV records include port numbers as well as IP addresses, so the client always uses that port when it contacts the SIP server. Otherwise, it uses the port in the SIP URI if there is one. If there's no port in the URI, it falls back to the default port, 5060 ๐ŸŒธ

  1. If the host portion of the Request-URI is an IP address, the client contacts the server at the given address. If the host portion of the Request-URI is not an IP address, the client proceeds to the next step.
  2. The Request-URI is examined. If it contains an explicit port number, the next two steps are skipped.
  3. The Request-URI is examined. If it does not specify a protocol (TCP or UDP), the client queries the name server for SRV records for both UDP (if supported by the client) and TCP (if supported by the client) SIP servers. The format of these queries is defined in RFC 2052 [14]. The results of the query or queries are merged together and ordered based on priority. Then, the searching technique outlined in RFC 2052 [14] is used to select servers in order. If DNS doesn't return any records, the user goes to the last step. Otherwise, the user attempts to contact each server in the order listed. If no server is contacted, the user gives up.
  4. If the Request-URI specifies a protocol (TCP or UDP) that is supported by the client, the client queries the name server for SRV records for SIP servers of that protocol type only. If the client does not support the protocol specified in the Request-URI, it gives up. The searching technique outlined in RFC 2052 [14] is used to select servers from the DNS response in order. If DNS doesn't return any records, the user goes to the last step. Otherwise, the user attempts to contact each server in the order listed. If no server is contacted, the user gives up.
  5. The client queries the name server for address records for the host portion of the Request-URI. If there were no address records, the client stops, as it has been unable to locate a server. By address record, we mean A RR's, AAAA RR's, or their most modern equivalent.

A client MAY cache a successful DNS query result. A successful query is one which contained records in the answer, and a server was contacted at one of the addresses from the answer. When the client wishes to send a request to the same host, it starts the search as if it had just received this answer from the name server. The server uses the procedures specified in RFC1035 [15] regarding cache invalidation when the time-to-live of the DNS result expires. If the client does not find a SIP server among the addresses listed in the cached answer, it starts the search at the beginning of the sequence described above. ๐Ÿ—‚๏ธ

For example, consider a client that wishes to send a SIP request. The Request-URI for the destination is sip:user@company.com. The client only supports UDP. It would follow these steps ๐Ÿ‘€

  1. The host portion is not an IP address, so the client goes to step 2 above.
  2. The client does a DNS query of QNAME="sip.udp.company.com", QCLASS=IN, QTYPE=SRV. Since it doesn't support TCP, it omits the TCP query. There were no addresses in the DNS response, so the client goes to the next step.
  3. The client does a DNS query for A records for "company.com". An address is found, so that client attempts to contact a server at that address at port 5060.

E IANA Considerations ๐ŸŽ€

Section 4.4 describes a name space and mechanism for registering SIP options.

Section 6.41 describes the name space for registering SIP warn-codes.

F Acknowledgments ๐Ÿซถ

We wish to thank the members of the IETF MMUSIC WG for their comments and suggestions. Detailed comments were provided by Anders Kristensen, Jim Buller, Dave Devanathan, Yaron Goland, Christian Huitema, Gadi Karmi, Jonathan Lennox, Keith Moore, Vern Paxson, Moshe J. Sambol, and Eric Tremblay. Iconic cast ๐Ÿ‘‘

This work is based, inter alia, on [37,38].

G Authors' Addresses ๐Ÿ“ฎ

Mark Handley
AT&T Center for Internet Research at ISCI (ACIRI)
1947 Center St., Suite 600
Berkeley, CA 94704-119
USA
Email: mjh@aciri.org
Henning Schulzrinne
Dept. of Computer Science
Columbia University
1214 Amsterdam Avenue
New York, NY 10027
USA
Email:  schulzrinne@cs.columbia.edu
Eve Schooler
Computer Science Department 256-80
California Institute of Technology
Pasadena, CA 91125
USA
Email:  schooler@cs.caltech.edu
Jonathan Rosenberg
Lucent Technologies, Bell Laboratories
Rm. 4C-526
101 Crawfords Corner Road
Holmdel, NJ 07733
USA
Email:  jdrosen@bell-labs.com

H Bibliography ๐Ÿ“š

[1] Pandya, R., "Emerging mobile and personal communication systems," IEEE Communications Magazine, vol. 33, pp. 44--52, June 1995. ๐ŸŒˆ

[2] Braden, B., Zhang, L., Berson, S., Herzog, S. and S. Jamin, "Resource ReSerVation protocol (RSVP) -- version 1 functional specification", RFC 2205, October 1997.

[3] Schulzrinne, H., Casner, S., Frederick, R. and V. Jacobson, "RTP: a transport protocol for real-time applications", RFC 1889, Internet Engineering Task Force, Jan. 1996.

[4] Schulzrinne, H., Lanphier, R. and A. Rao, "Real time streaming protocol (RTSP)", RFC 2326, April 1998.

[5] Handley, M., "SAP: Session announcement protocol," Internet Draft, Internet Engineering Task Force, Nov. 1996. Work in progress.

[6] Handley, M. and V. Jacobson, "SDP: session description protocol", RFC 2327, April 1998.

[7] International Telecommunication Union, "Visual telephone systems and equipment for local area networks which provide a non-guaranteed quality of service," Recommendation H.323, Telecommunication Standardization Sector of ITU, Geneva, Switzerland, May 1996.

[8] International Telecommunication Union, "Control protocol for multimedia communication," Recommendation H.245, Telecommunication Standardization Sector of ITU, Geneva, Switzerland, Feb. 1998.

[9] International Telecommunication Union, "Media stream packetization and synchronization on non-guaranteed quality of service LANs," Recommendation H.225.0, Telecommunication Standardization Sector of ITU, Geneva, Switzerland, Nov. 1996.

[10] Bradner, S., "Key words for use in RFCs to indicate requirement levels", BCP 14, RFC 2119, Mardch 1997.

[11] Fielding, R., Gettys, J., Mogul, J., Nielsen, H. and T. Berners-Lee, "Hypertext transfer protocol -- HTTP/1.1", RFC 2068, January 1997.

[12] Berners-Lee, T., Fielding, R. and L. Masinter, "Uniform resource identifiers (URI): generic syntax", RFC 2396, August 1998.

[13] Berners-Lee, T., Masinter, L. and M. McCahill, "Uniform resource locators (URL)", RFC 1738, December 1994.

[14] Gulbrandsen, A. and P. Vixie, "A DNS RR for specifying the location of services (DNS SRV)", RFC 2052, October 1996.

[15] Mockapetris, P., "Domain names - implementation and specification", STD 13, RFC 1035, Noveberm 1997.

[16] Hamilton, M. and R. Wright, "Use of DNS aliases for network services", RFC 2219, October 1997.

[17] Zimmerman, D., "The finger user information protocol", RFC 1288, December 1991.

[18] Williamson, S., Kosters, M., Blacka, D., Singh, J. and K. Zeilstra, "Referral whois (rwhois) protocol V1.5", RFC 2167, June 1997.

[19] Yeong, W., Howes, T. and S. Kille, "Lightweight directory access protocol", RFC 1777, March 1995.

[20] Schooler, E., "A multicast user directory service for synchronous rendezvous," Master's Thesis CS-TR-96-18, Department of Computer Science, California Institute of Technology, Pasadena, California, Aug. 1996.

[21] Yergeau, F., "UTF-8, a transformation format of ISO 10646", RFC 2279, January 1998.

[22] Stevens, W., TCP/IP illustrated: the protocols, vol. 1. Reading, Massachusetts: Addison-Wesley, 1994.

[23] Mogul, J. and S. Deering, "Path MTU discovery", RFC 1191, November 1990.

[24] Crocker, D., "Standard for the format of ARPA internet text messages", RFC STD 11, RFC 822, August 1982.

[25] Meyer, D., "Administratively scoped IP multicast", RFC 2365, July 1998.

[26] Schulzrinne, H., "RTP profile for audio and video conferences with minimal control", RFC 1890, January 1996

[27] Eastlake, D., Crocker, S. and J. Schiller, "Randomness recommendations for security", RFC 1750, December 1994.

[28] Hoffman, P., Masinter, L. and J. Zawinski, "The mailto URL scheme", RFC 2368, July 1998.

[29] Braden, B., "Requirements for internet hosts - application and support", STD 3, RFC 1123, October 1989.

[30] Palme, J., "Common internet message headers", RFC 2076, February 1997.

[31] Alvestrand, H., "IETF policy on character sets and languages", RFC 2277, January 1998.

[32] Elkins, M., "MIME security with pretty good privacy (PGP)", RFC 2015, October 1996.

[33] Atkins, D., Stallings, W. and P. Zimmermann, "PGP message exchange formats", RFC 1991, August 1996.

[34] Atkinson, R., "Security architecture for the internet protocol", RFC 2401, November 1998.

[35] Allen, C. and T. Dierks, "The TLS protocol version 1.0," RFC 2246, January 1999.

[36] Franks, J., Hallam-Baker, P., Hostetler, J., Lawrence, S., Leach, P., Luotonen, A. and L. Stewart, "HTTP authentication: Basic and digest access authentication," Internet Draft, Internet Engineering Task Force, Sept. 1998. Work in progress.

[37] Schooler, E., "Case study: multimedia conference control in a packet-switched teleconferencing system," Journal of Internetworking: Research and Experience, vol. 4, pp. 99--120, June 1993. ISI reprint series ISI/RS-93-359.

[38] Schulzrinne, H., "Personal mobility for multimedia services in the Internet," in European Workshop on Interactive Distributed Multimedia Systems and Services (IDMS), (Berlin, Germany), Mar. 1996.

Okay so the copyright bit is basically the legal fine print ๐ŸŽ€. The Internet Society owns the copyright for this one (it's 1999, so that's the year on it), and all rights are reserved ๐Ÿ’….

Here's what you're allowed to do, bestie. You can copy this document and share it with anyone ๐Ÿซถ. You can also make derivative works that comment on it, explain it, or help people implement it, and you can prepare, copy, publish, and distribute those, in whole or in part, with no real restrictions ๐ŸŒธ. The one catch is that the copyright notice and this paragraph have to stay on every copy and every derivative work ๐Ÿ”’.

Here's the part you can't do. You can't modify this document itself in any way. That means you can't delete the copyright notice or the references to the Internet Society or other Internet organizations ๐Ÿ™…โ€โ™€๏ธ. There are two exceptions. The first is when you need it to develop Internet standards, and then the copyright procedures in the Internet Standards process have to be followed. The second is when you need to translate it into a language that isn't English ๐ŸŒ.

The permissions above are perpetual, meaning they last forever and the Internet Society (or whoever takes over for them later) can't take them back โญ.

The big legal disclaimer, iykyk: This document and the information in it are provided "AS IS" ๐Ÿ’€. THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED. That includes, but isn't limited to, any warranty that using the information here won't infringe anyone's rights, and any implied warranties of merchantability or fitness for a particular purpose ๐Ÿ™ˆ.

Fr, that's the whole vibe: use it, share it, build cool stuff with it, just keep the credit and the notice attached ๐Ÿฆ‹๐Ÿ’œ

๐Ÿ“ฆ where this page comes from