SIP Wackyness

We’re experiencing what may be some SIP strangeness with Asterisk. I can’t confess to being a SIP expert because I’ve only been involved with it for a few weeks.

We have an Asterisk box that sends all off-net calls to a SER box. The SER box just forwards all the packets to our PSTN gateway which is an Audiocodes Mediant 2000 with a couple of PRI’s. For incoming calls from the PSTN, the mediant gateway sends all packets to SER, which again forwards them to Asterisk.

For an outgoing call to the PSTN, Asterisk initially sets a Contact: header for example to sip:3250071@192.168.10.7, where 3250071 is the number we are dialling, and 192.168.10.7 is it’s own IP address.

Now, for some reason, when the Mediant gateway sends ‘180 Ringing’ back to Asterisk/SER, it replaces the Contact: header with the value ‘sip:58@192.168.10.3’ where 192.168.10.3 is it’s own IP address, and the ‘58’… well we don’t quite know what that means.

We’re yet to determine if the mediant replacing the contact field is supposed to happen or not or a bad thing.

Anyway, what then happens is, after Asterisk sends it’s 'ACK message to SER/Mediant, it promptly proceeds to send ANOTHER INVITE again, this time with the SIP URI replaced with the modified Contact: header, so we get it sending:

INVITE sip:58@192.168.10.3 SIP/2.0.

The million dollar question is, why is Asterisk doing this? Is this what is supposed to happen when a proxy modifies a contact header to something new? Is Asterisk sending an INVITE again because this is a RE-INVITE, and it thinks the user at the other end has moved?

Anyway, by the time the mediant gets the second INVITE, it really spews at having a SIP URI of ‘sip:58@192.168.10.3’ and this time it sends a ‘405 Method Not Allowed’ back to Asterisk because it doesn’t like the SIP URI any more.

Here’s the full SIP packet exchange pasted for reference.
Asterisk = 192.168.10.7
SER = 192.168.10.4
Mediant = 192.168.10.3

interface: eth0 (192.168.10.0/255.255.255.0)
filter: (ip) and ( port 5060 )

U 192.168.10.7:5060 -> 192.168.10.4:5060
INVITE sip:13033372500@bil-pdev-3.voip.180internal.com SIP/2.0.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK7f6cff48.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com.
Contact: sip:3250071@192.168.10.7.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 102 INVITE.
User-Agent: Asterisk PBX.
Date: Mon, 14 Nov 2005 21:13:35 GMT.
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY.
Content-Type: application/sdp.
Content-Length: 207.
.
v=0.
o=root 28392 28392 IN IP4 192.168.10.7.
s=session.
c=IN IP4 192.168.10.7.
t=0 0.
m=audio 11284 RTP/AVP 0 3 8.
a=rtpmap:0 PCMU/8000.
a=rtpmap:3 GSM/8000.
a=rtpmap:8 PCMA/8000.
a=silenceSupp:off - - - -.

U 192.168.10.4:5060 -> 192.168.10.3:5060
INVITE sip:13033372500@bil-pdev-3.voip.180internal.com SIP/2.0.
Max-Forwards: 10.
Record-Route: sip:192.168.10.4;ftag=as79352c7c;lr=on.
Via: SIP/2.0/UDP 192.168.10.4;branch=0.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK7f6cff48.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com.
Contact: sip:3250071@192.168.10.7.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 102 INVITE.
User-Agent: Asterisk PBX.
Date: Mon, 14 Nov 2005 21:13:35 GMT.
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY.
Content-Type: application/sdp.
Content-Length: 207.
.
v=0.
o=root 28392 28392 IN IP4 192.168.10.7.
s=session.
c=IN IP4 192.168.10.7.
t=0 0.
m=audio 11284 RTP/AVP 0 3 8.
a=rtpmap:0 PCMU/8000.
a=rtpmap:3 GSM/8000.
a=rtpmap:8 PCMA/8000.
a=silenceSupp:off - - - -.

U 192.168.10.3:5060 -> 192.168.10.4:5060
SIP/2.0 100 Trying.
Via: SIP/2.0/UDP 192.168.10.4;branch=0.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK7f6cff48.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 102 INVITE.
Supported: em,timer,replaces,path.
Allow: REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE.
Server: Audiocodes-Sip-Gateway-OneEighty Communications GW1/v.4.40.200.371.
Content-Length: 0.
.

U 192.168.10.4:5060 -> 192.168.10.7:5060
SIP/2.0 100 Trying.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK7f6cff48.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 102 INVITE.
Supported: em,timer,replaces,path.
Allow: REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE.
Server: Audiocodes-Sip-Gateway-OneEighty Communications GW1/v.4.40.200.371.
Content-Length: 0.
.

U 192.168.10.3:5060 -> 192.168.10.4:5060
SIP/2.0 180 Ringing.
Via: SIP/2.0/UDP 192.168.10.4;branch=0.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK7f6cff48.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 102 INVITE.
Contact: sip:58@192.168.10.3.
Record-Route: sip:192.168.10.4;ftag=as79352c7c;lr=on.
Supported: em,timer,replaces,path.
Allow: REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE.
Server: Audiocodes-Sip-Gateway-OneEighty Communications GW1/v.4.40.200.371.
Content-Type: application/sdp.
Content-Length: 169.
.
v=0.
o=AudiocodesGW 408855 144200 IN IP4 192.168.10.3.
s=Phone-Call.
c=IN IP4 192.168.10.3.
t=0 0.
m=audio 6690 RTP/AVP 0.
a=rtpmap:0 pcmu/8000.
a=ptime:20.
a=sendrecv.

U 192.168.10.4:5060 -> 192.168.10.7:5060
SIP/2.0 180 Ringing.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK7f6cff48.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 102 INVITE.
Contact: sip:58@192.168.10.3.
Record-Route: sip:192.168.10.4;ftag=as79352c7c;lr=on.
Supported: em,timer,replaces,path.
Allow: REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE.
Server: Audiocodes-Sip-Gateway-OneEighty Communications GW1/v.4.40.200.371.
Content-Type: application/sdp.
Content-Length: 169.
.
v=0.
o=AudiocodesGW 408855 144200 IN IP4 192.168.10.3.
s=Phone-Call.
c=IN IP4 192.168.10.3.
t=0 0.
m=audio 6690 RTP/AVP 0.
a=rtpmap:0 pcmu/8000.
a=ptime:20.
a=sendrecv.

U 192.168.10.3:5060 -> 192.168.10.4:5060
SIP/2.0 200 OK.
Via: SIP/2.0/UDP 192.168.10.4;branch=0.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK7f6cff48.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 102 INVITE.
Contact: sip:58@192.168.10.3.
Record-Route: sip:192.168.10.4;ftag=as79352c7c;lr=on.
Supported: em,timer,replaces,path.
Allow: REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE.
Server: Audiocodes-Sip-Gateway-OneEighty Communications GW1/v.4.40.200.371.
Content-Type: application/sdp.
Content-Length: 169.
.
v=0.
o=AudiocodesGW 408855 144200 IN IP4 192.168.10.3.
s=Phone-Call.
c=IN IP4 192.168.10.3.
t=0 0.
m=audio 6690 RTP/AVP 0.
a=rtpmap:0 pcmu/8000.
a=ptime:20.
a=sendrecv.

U 192.168.10.4:5060 -> 192.168.10.7:5060
SIP/2.0 200 OK.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK7f6cff48.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 102 INVITE.
Contact: sip:58@192.168.10.3.
Record-Route: sip:192.168.10.4;ftag=as79352c7c;lr=on.
Supported: em,timer,replaces,path.
Allow: REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE.
Server: Audiocodes-Sip-Gateway-OneEighty Communications GW1/v.4.40.200.371.
Content-Type: application/sdp.
Content-Length: 169.
.
v=0.
o=AudiocodesGW 408855 144200 IN IP4 192.168.10.3.
s=Phone-Call.
c=IN IP4 192.168.10.3.
t=0 0.
m=audio 6690 RTP/AVP 0.
a=rtpmap:0 pcmu/8000.
a=ptime:20.
a=sendrecv.

U 192.168.10.7:5060 -> 192.168.10.4:5060
ACK sip:58@192.168.10.3 SIP/2.0.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK5668d295.
Route: sip:58@192.168.10.3.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Contact: sip:3250071@192.168.10.7.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 102 ACK.
User-Agent: Asterisk PBX.
Content-Length: 0.
.

U 192.168.10.7:5060 -> 192.168.10.4:5060
INVITE sip:58@192.168.10.3 SIP/2.0.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK23298bd0.
Route: sip:58@192.168.10.3.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Contact: sip:3250071@192.168.10.7.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 103 INVITE.
User-Agent: Asterisk PBX.
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY.
Content-Type: application/sdp.
Content-Length: 213.
.
v=0.
o=root 28392 28393 IN IP4 192.168.10.121.
s=session.
c=IN IP4 192.168.10.121.
t=0 0.
m=audio 2234 RTP/AVP 0 8 18.
a=rtpmap:0 PCMU/8000.
a=rtpmap:8 PCMA/8000.
a=rtpmap:18 G729/8000.
a=silenceSupp:off - - - -.

U 192.168.10.4:5060 -> 192.168.10.7:5060
SIP/2.0 100 trying – your call is important to us.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK23298bd0.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 103 INVITE.
Server: OpenSer (1.0.0 (i386/linux)).
Content-Length: 0.
Warning: 392 192.168.10.4:5060 “Noisy feedback tells: pid=2035 req_src_ip=192.168.10.7 req_src_port=5060 in_uri=sip:58@192.168.10.3 out_uri=sip:58@192.168.10.3 via_cnt==1”.
.

U 192.168.10.4:5060 -> 192.168.10.3:5060
INVITE sip:58@192.168.10.3 SIP/2.0.
Max-Forwards: 10.
Record-Route: sip:192.168.10.4;ftag=as79352c7c;lr=on.
Via: SIP/2.0/UDP 192.168.10.4;branch=z9hG4bKce1c.db89e89.0.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK23298bd0.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Contact: sip:3250071@192.168.10.7.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 103 INVITE.
User-Agent: Asterisk PBX.
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY.
Content-Type: application/sdp.
Content-Length: 213.
Route: sip:58@192.168.10.3.
.
v=0.
o=root 28392 28393 IN IP4 192.168.10.121.
s=session.
c=IN IP4 192.168.10.121.
t=0 0.
m=audio 2234 RTP/AVP 0 8 18.
a=rtpmap:0 PCMU/8000.
a=rtpmap:8 PCMA/8000.
a=rtpmap:18 G729/8000.
a=silenceSupp:off - - - -.

U 192.168.10.4:5060 -> 192.168.10.3:5060
ACK sip:58@192.168.10.3 SIP/2.0.
Max-Forwards: 10.
Record-Route: sip:192.168.10.4;ftag=as79352c7c;lr=on.
Via: SIP/2.0/UDP 192.168.10.4;branch=0.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK5668d295.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Contact: sip:3250071@192.168.10.7.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 102 ACK.
User-Agent: Asterisk PBX.
Content-Length: 0.
Route: sip:58@192.168.10.3.
.

U 192.168.10.3:5060 -> 192.168.10.4:5060
SIP/2.0 405 Method Not Allowed.
Via: SIP/2.0/UDP 192.168.10.4;branch=z9hG4bKce1c.db89e89.0.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK23298bd0.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 103 INVITE.
Contact: sip:58@192.168.10.3.
Record-Route: sip:192.168.10.4;ftag=as79352c7c;lr=on.
Supported: em,timer,replaces,path.
Allow: REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE.
Server: Audiocodes-Sip-Gateway-OneEighty Communications GW1/v.4.40.200.371.
Content-Length: 0.
.

U 192.168.10.4:5060 -> 192.168.10.3:5060
ACK sip:58@192.168.10.3 SIP/2.0.
Via: SIP/2.0/UDP 192.168.10.4;branch=z9hG4bKce1c.db89e89.0.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
CSeq: 103 ACK.
Route: sip:58@192.168.10.3.
User-Agent: OpenSer (1.0.0 (i386/linux)).
Content-Length: 0.
.

U 192.168.10.4:5060 -> 192.168.10.7:5060
SIP/2.0 405 Method Not Allowed.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK23298bd0.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 103 INVITE.
Contact: sip:58@192.168.10.3.
Record-Route: sip:192.168.10.4;ftag=as79352c7c;lr=on.
Supported: em,timer,replaces,path.
Allow: REGISTER,OPTIONS,INVITE,ACK,CANCEL,BYE,NOTIFY,PRACK,REFER,INFO,SUBSCRIBE,UPDATE.
Server: Audiocodes-Sip-Gateway-OneEighty Communications GW1/v.4.40.200.371.
Content-Length: 0.
.

U 192.168.10.7:5060 -> 192.168.10.4:5060
ACK sip:58@192.168.10.3 SIP/2.0.
Via: SIP/2.0/UDP 192.168.10.7:5060;branch=z9hG4bK23298bd0.
Route: sip:58@192.168.10.3.
From: “3250071” sip:3250071@voip.180internal.com;tag=as79352c7c.
To: sip:13033372500@bil-pdev-3.voip.180internal.com;tag=1c1081028615.
Contact: sip:3250071@192.168.10.7.
Call-ID: 64aa45ef2fd81299638d42b020be2200@voip.180internal.com.
CSeq: 103 ACK.
User-Agent: Asterisk PBX.
Content-Length: 0.
.

Ok, so I think I’m understanding this a little better. After reading RFC 3261, I see that a reinvite has the same dialog (ie call-id) as the original dialog generated by the original invite. In my case, the second invite does have the same dialog/call-id, and therefore it’s a reinvite.

So, is this something that Asterisk always does because it acts as a B2BUA? I wonder why it uses the contact: from the ringing for it’s SIP URI in the new invite?

Oh Damn. The RFC also says that if a message has multiple Via fields in there that a UAC should throw it away, and I see we have multiple Via: headers in the packets, one from Asterisk and one from SER. Now I’m really confused. This doesn’t seem to be causing a problem.

Ok, now I’m even more confused. I just read somewhere that multiple Via headers are ok. GRRR!

Ok, I also just noticed that the codec info changed between the first invite and the second, from:

v=0.F
o=root 28392 28392 IN IP4 192.168.10.7.
s=session.
c=IN IP4 192.168.10.7.
t=0 0.
m=audio 11284 RTP/AVP 0 3 8.
a=rtpmap:0 PCMU/8000.
a=rtpmap:3 GSM/8000.
a=rtpmap:8 PCMA/8000.
a=silenceSupp:off - - - -.

to:

v=0.
o=root 28392 28393 IN IP4 192.168.10.121.
s=session.
c=IN IP4 192.168.10.121.
t=0 0.
m=audio 2234 RTP/AVP 0 8 18.
a=rtpmap:0 PCMU/8000.
a=rtpmap:8 PCMA/8000.
a=rtpmap:18 G729/8000.
a=silenceSupp:off - - -

But if you look at the first OK message, it has:

v=0.
o=AudiocodesGW 408855 144200 IN IP4 192.168.10.3.
s=Phone-Call.
c=IN IP4 192.168.10.3.
t=0 0.
m=audio 6690 RTP/AVP 0.
a=rtpmap:0 pcmu/8000.
a=ptime:20.
a=sendrecv.

which means it has negotiated with the UAC to use PCMU (ie G711 ulaw), so why is the requested codec info different on the second invite???