[Asterisk-Dev] Patch: SIP bindaddr not always used
matt at overloaded.net
matt at overloaded.net
Tue May 13 12:07:59 MST 2003
I ran into a problem where my Asterisk system has two interfaces. Initially I saw that even though my phones were configured to contact one IP, Asterisk was later
contacting them using the other interface (which happened to be the one facing the local phones). For consistency, I used the SIP bindaddr configuration option to set SIP
to only use one IP. However, I then started having problems with calls failing. Below is some information I collected on the problem:
192.168.0.1 asterisk interface1 (only interface that should be speaking SIP)
10.0.0.1 asterisk interface 2 (no SIP)
10.0.0.6 Cisco 1750 (gateway to PSTN)
tcpdump:
17:44:24.547830 10.0.0.6.57232 > 192.168.0.1.5060: udp 700
17:44:24.548526 192.168.0.1.5060 > 10.0.0.6.5060: udp 319 (DF)
17:44:25.547948 192.168.0.1.5060 > 10.0.0.6.5060: udp 473 (DF)
17:44:25.560930 10.0.0.6.57232 > 10.0.0.1.5060: udp 489
17:44:25.561004 10.0.0.1 > 10.0.0.6: icmp: 10.0.0.1 udp port 5060 unreachable [tos 0xc0]
The first offending SIP packet sent from Asterisk (this is the 2nd packet in the tcpdump above though the third also has the same problem):
Sending to 10.0.0.6 : 5060 (non-NAT)
Capabilities: us - 14, them - 4, combined - 4
Non-codec capabilities: us - 1, them - 0, combined - 0
Looking for 202 in all
list_route: hop: <sip:unknown at 10.0.0.6:5060>
Transmitting (no NAT):
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.0.0.6:5060
From: "unknown" <sip:unknown at 10.0.0.6>
To: <sip:202 at 192.168.0.1;user=phone;phone-context=unknown>;tag=as70354688
Call-ID: 557C0F54-83FB11D7-89ECD971-E4361B09 at 10.0.0.6
CSeq: 101 INVITE
User-Agent: Asterisk PBX
Contact: <sip:202 at 10.0.0.1>
Content-Length: 0
In this SIP message, the "Contact:" line is providing an IP address which is on the same host as Asterisk, but since Asterisk is bound only to the other IP there is nothing listening on 10.0.0.1:5060. The 1750 attempts to contact 10.0.0.1 but gets an ICMP port unreachable and the call fails.
Attached is a patch I created that seems to fix this problem. I want to make it clear that I'm by no means experienced at C nor am I very familiar with the
Asterisk code internals. This patch may be completely wrong and may break all kinds of stuff. However, I have it running on my system and it seems to have solved
the problem for me.
http://www.overloaded.net/patches/asterisk-contactip.patch
-------------- next part --------------
--- channels/chan_sip.c.default 2003-05-12 18:26:50.000000000 -0400
+++ channels/chan_sip.c 2003-05-12 20:24:26.000000000 -0400
@@ -1276,7 +1276,9 @@
#endif
if (sin) {
memcpy(&p->sa, sin, sizeof(p->sa));
- if (ast_ouraddrfor(&p->sa.sin_addr,&p->ourip))
+ if (&bindaddr)
+ memcpy(&p->ourip, &bindaddr.sin_addr, sizeof(p->ourip));
+ else if (ast_ouraddrfor(&p->sa.sin_addr,&p->ourip))
memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
} else {
memcpy(&p->ourip, &__ourip, sizeof(p->ourip));
More information about the asterisk-dev
mailing list