问题描述

FreeSWITCH位于公网,对方设备位于内网中。
在sip信令进行协商的时候,由于对方送来的200ok中contact地址是内网地址,导致freeswitch将ack送到了对方的内网地址。
信令如下:

U 2018/08/08 17:12:03.359287 123.71.105.233:5060 -> 172.16.8.223:50602 SIP/2.0 200 OK. Via: SIP/2.0/UDP 17.96.184.10:50602;branch=z9hG4bK2FBSj6QZN3Zje;rport=50602. Call-ID: e899a721-158d-1237-6fb3-00163e042395. From: “guomei”sip:gm@123.71.105.233:5060;tag=89t8ZrXFNtSKr. To: sip:924018652003060@123.71.105.233:5060;tag=haria6cc-CC-56. CSeq: 126523687 INVITE. Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,REGISTER,INFO,PRACK,SUBSCRIBE,NOTIFY,UPDATE,MESSAGE,REFER. Contact: sip:10.103.11.62:5060. Supported: 100rel,replaces,timer,precondition,histinfo. Content-Length: 163. Content-Type: application/sdp. . v=0. o=HuaWeiUAP6600 470984495 470984496 IN IP4 10.103.11.62. s=Sip Call. c=IN IP4 10.103.11.51. t=0 0. m=audio 10204 RTP/AVP 8. a=rtpmap:8 PCMA/8000. a=ptime:20.

下面的ack,一直都向对方的内网去发送。

U 2018/08/08 17:12:03.371007 172.16.8.223:50602 -> 10.103.11.62:5060 ACK sip:10.103.11.62:5060 SIP/2.0. Via: SIP/2.0/UDP 17.96.184.10:50602;rport;branch=z9hG4bKKa2Q9KHc8Q36N. Max-Forwards: 70. From: “guomei” sip:gm@123.71.105.233:5060;tag=89t8ZrXFNtSKr. To: sip:924018652003060@123.71.105.233:5060;tag=haria6cc-CC-56. Call-ID: e899a721-158d-1237-6fb3-00163e042395. CSeq: 126523687 ACK. Contact: sip:gw+gw_guomei@17.96.184.10:50602;transport=udp;gw=gw_guomei. Content-Length: 0.

对方因为一直没收到ack,会一直发送200ok。
而freeswitch会一直向对方的内网地址发送ack。
导致双方对不上。

解决方案

在拨号方案中增加如下参数:

  1. <action application="set" data="sip_sticky_contact=true"/>

该参数主要用于固定住contact地址,防止在sip协商过程中被对方的内网地址所改写。

Anthony Minessale的介绍:

also you can set sip_sticky_contact=true channel var which will make that session turn on nat lock in the b leg so they can’t change the contact to a nat addr . add it in {} to your dial string like . {sip_sticky_contact=true}sofia/internal/foo@bar.com mailto:foo@bar.com

参考资料

http://asterisk.voicemeup.com/viewtopic.php?t=13059&sid=3ec2583c36752f1fd2332d57348a9c1e