RFC 3581 中的 rport 例子详解

A client sends an INVITE to a proxy server which looks like, in part:

INVITE sip:user@example.com SIP/2.0
Via: SIP/2.0/UDP 10.1.1.1:4540;rport;branch=z9hG4bKkjshdyff

This INVITE is sent with a source port of 4540 and a source IP address of 10.1.1.1.

The proxy is at 192.0.2.2 (proxy.example.com), listening on both port 5060 and 5070.

客户端准备向代理服务器发送一个源 IP 为 10.1.1.1,源端口 4540 的 INVITE 请求。代理服务器位于 192.0.2.2,监听着自己的 5060 和 5070 端口。

The client sends the request to port 5060. The request passes through a NAT on the way to the proxy, so that the source IP address appears as 192.0.2.1 and the source port as 9988.

The proxy forwards the request, but not before appending a value to the “rport” parameter in the proxied request:

客户端将这个请求发给代理服务器所在的 IP 的 5060 端口,在这一过程中,该请求会穿过 NAT,这时在外界看来它的源端口和源 IP 就变成了 192.0.2.1 和 9988。因此代理服务器将 rport 值赋为 192.0.2.1,然后继续传递该请求。

INVITE sip:user@example.com SIP/2.0
Via: SIP/2.0/UDP proxy.example.com;branch=z9hG4bKkjsh77
Via: SIP/2.0/UDP 10.1.1.1:4540;received=192.0.2.1;rport=9988;branch=z9hG4bKkjshdyff

This request generates a response which arrives at the proxy:

在这一请求到达目的服务器后,目的服务器会生成一个对应的应答,并将其返回给代理服务器,以下是这个应答的头部内容。

SIP/2.0 200 OK
Via: SIP/2.0/UDP proxy.example.com;branch=z9hG4bKkjsh77
Via: SIP/2.0/UDP 10.1.1.1:4540;received=192.0.2.1;rport=9988;branch=z9hG4bKkjshdyff

The proxy strips(剥去) its top Via header field value, and then examines the next one.

It contains both a “received” parameter and an “rport” parameter.

The server follows the rules specified in Section 4 and sends the response to IP address 192.0.2.1, port 9988, and sends it from port 5060 on 192.0.2.2.

代理服务器会剥去顶部 Via 字段并检验第二个 Via 字段。第二个 Via 字段包含了 received 和 rport 值,于是代理服务器遵循前面提及的规则,将应答通过自身(192.0.2.2)的 5060 端口发送给 192.0.2.1 的 9988 端口。

SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.1.1.1:4540;received=192.0.2.1;rport=9988;branch=z9hG4bKkjshdyff

This packet matches the binding created by the initial request.

Therefore, the NAT rewrites the destination address of this packet back to 10.1.1.1, and the destination port back to 4540.

It forwards this response to the client, which is listening for the response on that address and port. The client properly receives the response.

这个应答包的 Via 字段符合了初始创建的绑定规则,因此 NAT 会按照规则中的描述将目的地址改回 10.1.1.1 的 4540 端口。最后这个包会被发送给客户端。




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • 我和胶片的故事
  • IPv6 地址类型详解
  • DNS 记录的类型及其功能
  • SIP 中 180 与 183 的区别
  • DHCP 八种报文