[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sems
Subject:    [Sems] sems IP problem
From:       jan () iptel ! org (Jan Janak)
Date:       2004-01-16 19:48:38
Message-ID: 20040116184657.GM824 () localhost ! localdomain
[Download RAW message or body]

Attached patch fixes the problem, it explicitly sets the source IP
address of the stream to the IP address advertised in SDP if the remote
party inserted direction:active into SDP.

  Jan.

On 16-01 18:09, Jan Janak wrote:
> On 16-01 18:08, Jan Janak wrote:
> > Hello,
> > 
> > I have configured sems to use IP 81.91.160.163 using local_ip directive
> > in the config file, but it doesn't seem to work properly, see:
> > 
> > U 193.175.135.38:5060 -> 81.91.160.163:5060
> > INVITE sip:1234@denic.de;user=phone SIP/2.0
> > Via: SIP/2.0/UDP 192.168.0.132:5060
> > From: jan <sip:jan@denic.de>;tag=1048188841
> > To: <sip:1234@denic.de;user=phone>
> > Call-ID: 3363424972@192.168.0.132
> > CSeq: 2 INVITE
> > Contact: jan <sip:jan@192.168.0.132:5060;transport=udp>
> > User-Agent: Cisco-CP7905/1.01-030807A..Allow: ACK, BYE, CANCEL, INVITE, NOTIF
> > Y, OPTIONS, REFER, REGISTER
> > Proxy-Authorization: Digest username="jan", realm="denic.de",
> > nonce="40081903a6014bc5b6d1b58a23eace2e6737285", uri="sip:1234@denic.de",
> > response="c4e90a8a3bd76416816e409cec962096"
> > Expires:300
> > Content-Length: 258
> > Content-Type: application/sdp
> > 
> > v=0
> > o=jan 25470 25470 IN IP4 192.168.0.132
> > s=Cisco 7905 SIP Call
> > c=IN IP4 192.168.0.132
> > t=0 0
> > m=audio 16384 RTP/AVP 0 18 8 101
> > a=rtpmap:0 PCMU/8000/1
> > a=rtpmap:18 G729/8000/1
> > a=rtpmap:8 PCMA/8000/1
> > a=rtpmap:101 telephone-event/8000
> > a=fmtp:101 0-15
> 
> There was a=direction:active here, I just cut and pasted wrong
> message from the dumps.
> 
> > 
> > 
> > U 81.91.160.163:5060 -> 193.175.135.38:5060
> > SIP/2.0 200 OK
> > Record-Route: <sip:1234@81.91.160.163;ftag=1048188841;lr=on>
> > Via: SIP/2.0/UDP 192.168.0.132:5060;rport=5060;received=193.175.135.38
> > From: jan <sip:jan@denic.de>;tag=1048188841
> > To: <sip:1234@denic.de;user=phone>;tag=000031B464E3B441
> > Call-ID: 3363424972@192.168.0.132
> > CSeq: 2 INVITE
> > Contact: <sip:voicemail+jan2@81.91.160.163:5090>
> > Content-Type: application/sdp
> > Server: Sip EXpress router (0.8.12-tcp_nonb (i386/linux))
> > Content-Length: 152
> > Warning: 392 81.91.160.163:5090 "Noisy feedback tells: pid=10295 
> > req_src_ip=81.91.160.163 req_src_port=5060 in_uri=sip:vm+jan2@81.91.160.163:5090 \
> > out_uri=sip:vm+jan2@81.91.160.163:5090 via_cnt==0" 
> > v=0
> > o=username 0 0 IN IP4 81.91.160.163
> > s=session
> > c=IN IP4 81.91.160.163
> > t=0 0
> > m=audio 14766 RTP/AVP 0
> > a=rtpmap:0 PCMU/8000
> > a=direction:passive
> > 
> > 
> > RTP streams:
> > 
> > U 193.175.135.38:16384 -> 81.91.160.163:14766
> > #
> > U 81.91.160.162:14766 -> 193.175.135.38:16384
> > #
> > I 193.175.135.38 -> 81.91.160.162 3:3
> > #
> > U 193.175.135.38:16384 -> 81.91.160.163:14766
> > 
> > 
> > The machine has two interfaces, eth0 with IP 81.91.160.162 (default
> > route points to this interface) and eth0:1 with IP 81.91.160.163
> > 
> > My guess is that sems creates the socket listening on * and the kernel
> > will later bind it to the IP of the outgoing interface (eth0 in this
> > case) -- ignoring the configured IP address.
> > 
> > I also tried to use -d option with the same result.
> > 
> > Jan.
> > 
> > 
> > _______________________________________________
> > Sems mailing list
> > Sems@iptel.org
> > http://mail.iptel.org/cgi-bin/mailman/listinfo/sems
> 
> _______________________________________________
> Sems mailing list
> Sems@iptel.org
> http://mail.iptel.org/cgi-bin/mailman/listinfo/sems
-------------- next part --------------
diff -Naur sems.org/AmRtpStream.cpp sems.new/AmRtpStream.cpp
--- sems.org/AmRtpStream.cpp	2004-01-14 18:24:01.000000000 +0100
+++ sems.new/AmRtpStream.cpp	2004-01-16 19:10:42.000000000 +0100
@@ -93,6 +93,19 @@
     }
 }
 
+
+/*
+ * This function must be called before setLocalPort, because
+ * setLocalPort will bind the socket and it will be not
+ * possible to change the IP later
+ */
+void AmRtpStream::setLocalIP(const string& ip)
+{
+    if (!inet_aton(ip.c_str(), (in_addr*)&l_saddr.sin_addr.s_addr)) {
+	    throw string ("Invalid IP address.");
+    }
+}
+
 void AmRtpStream::setLocalPort()
 {
     if(l_port)
@@ -111,10 +124,6 @@
 	throw string ("while setting socket non blocking.");
     }
 
-    struct sockaddr_in sa;
-    sa.sin_family = AF_INET;
-    sa.sin_addr.s_addr = INADDR_ANY;
-
     int retry = 10;
     unsigned short port = 0;
     DBG("setting random local port\n");
@@ -125,8 +134,8 @@
 	}
 	while (port < 1024);
 	
-	sa.sin_port = htons(port);
-	if(!bind(sd,(const struct sockaddr*)&sa,
+	l_saddr.sin_port = htons(port);
+	if(!bind(sd,(const struct sockaddr*)&l_saddr,
 		 sizeof(struct sockaddr_in)))
 	    break;
     }
@@ -279,7 +288,13 @@
       thread(_t)
 {
     memset(&r_saddr,0,sizeof(struct sockaddr_in));
+    memset(&l_saddr,0,sizeof(struct sockaddr_in));
     sched = AmRtpScheduler::instance();
+
+    /* By default we listen on all interfaces */
+    l_saddr.sin_family = AF_INET;
+    l_saddr.sin_addr.s_addr = INADDR_ANY;
+
 }
 
 AmRtpStream::~AmRtpStream()
diff -Naur sems.org/AmRtpStream.h sems.new/AmRtpStream.h
--- sems.org/AmRtpStream.h	2003-11-13 15:06:08.000000000 +0100
+++ sems.new/AmRtpStream.h	2004-01-16 19:08:43.000000000 +0100
@@ -78,6 +78,7 @@
     struct sockaddr_in r_saddr;
 
     unsigned short     l_port;
+    struct sockaddr_in l_saddr;
     int                l_sd;
 
     RtpSync        send_s;
@@ -115,6 +116,13 @@
     /** Stops the stream and frees all resources. */
     ~AmRtpStream();
 
+    /**
+     * This function must be called before setLocalPort, because
+     * setLocalPort will bind the socket and it will be not
+     * possible to change the IP later
+     */
+    void setLocalIP(const string& ip);
+	    
     /** 
      * Gets RTP port number. If no RTP port in assigned, assigns a new one.
      * @return local RTP port. 
diff -Naur sems.org/AmSession.cpp sems.new/AmSession.cpp
--- sems.org/AmSession.cpp	2003-11-13 14:59:49.000000000 +0100
+++ sems.new/AmSession.cpp	2004-01-16 19:32:17.000000000 +0100
@@ -117,6 +117,17 @@
 
 		if(!req->getReplied()){
 		    dialog_st->onBeforeCallAccept(req.get());
+		    if (dir == SdpMedia::DirActive) {
+			/* If the remote party indicated that it wants to
+			 * be in active mode (meaning it is behind NAT, then
+			 * we must set the IP for outgoing stream explicitely,
+			 * otherwise the kernel could assign a different address
+			 * to the socket and the data will not pass the NAT (it can
+			 * happen on multihomed machines), we set it to the same IP that
+			 * will be put into the SDP reply.
+			 */
+	            	rtp_str.setLocalIP(req->cmd.dstip);
+		    }
 		    req->accept(rtp_str.getLocalPort(),payload,dir);
 		}
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic