[PATCH] core: use the request's interface as outbound interface by default.
Raphael Coeffic
rco at iptel.org
Wed Feb 1 16:17:13 CET 2012
---
core/AmSipDialog.cpp | 1 +
core/AmSipMsg.h | 2 ++
core/SipCtrlInterface.cpp | 8 ++++++--
core/sip/transport.cpp | 9 +++++++--
core/sip/transport.h | 10 +++++++++-
core/sip/udp_trsp.h | 2 +-
6 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/core/AmSipDialog.cpp b/core/AmSipDialog.cpp
index 0e6adff..5c6756c 100644
--- a/core/AmSipDialog.cpp
+++ b/core/AmSipDialog.cpp
@@ -166,6 +166,7 @@ void AmSipDialog::onRxRequest(const AmSipRequest& req)
remote_party = req.from;
local_party = req.to;
route = req.route;
+ outbound_interface = req.local_if;
}
}
diff --git a/core/AmSipMsg.h b/core/AmSipMsg.h
index 5b9c9c2..fe2dda2 100644
--- a/core/AmSipMsg.h
+++ b/core/AmSipMsg.h
@@ -77,6 +77,8 @@ class AmSipRequest : public _AmSipMsgInDlg
unsigned int rack_cseq;
string via_branch;
+ unsigned short local_if;
+
AmSipRequest() : _AmSipMsgInDlg() { }
~AmSipRequest() { }
diff --git a/core/SipCtrlInterface.cpp b/core/SipCtrlInterface.cpp
index f84f905..18d5c4e 100644
--- a/core/SipCtrlInterface.cpp
+++ b/core/SipCtrlInterface.cpp
@@ -241,7 +241,7 @@ int SipCtrlInterface::run()
// Init transport instances
for(unsigned int i=0; i<AmConfig::Ifs.size();i++) {
- udp_trsp_socket* udp_socket = new udp_trsp_socket;
+ udp_trsp_socket* udp_socket = new udp_trsp_socket(i);
if(udp_socket->bind(AmConfig::Ifs[i].LocalSIPIP,
AmConfig::Ifs[i].LocalSIPPort) < 0){
@@ -461,6 +461,8 @@ inline void SipCtrlInterface::sip_msg2am_request(const sip_msg *msg,
req.remote_port = htons(((sockaddr_in*)&msg->remote_ip)->sin_port);
req.local_ip = get_addr_str(&msg->local_ip).c_str();
req.local_port = htons(((sockaddr_in*)&msg->local_ip)->sin_port);
+
+ req.local_if = msg->local_socket->get_if();
}
inline bool SipCtrlInterface::sip_msg2am_reply(sip_msg *msg, AmSipReply &reply)
@@ -549,7 +551,9 @@ void SipCtrlInterface::handle_sip_request(const trans_ticket& tt, sip_msg* msg)
req.tt = tt;
- DBG("Received new request\n");
+ DBG("Received new request from <%s:%i> on intf #%i\n",
+ req.remote_ip.c_str(),req.remote_port,req.local_if);
+
if (SipCtrlInterface::log_parsed_messages) {
// DBG_PARAM(req.cmd);
DBG_PARAM(req.method);
diff --git a/core/sip/transport.cpp b/core/sip/transport.cpp
index d8328db..b773030 100644
--- a/core/sip/transport.cpp
+++ b/core/sip/transport.cpp
@@ -34,8 +34,8 @@
#include <netinet/in.h>
#include <string.h> // memset, strerror, ...
-trsp_socket::trsp_socket()
- : sd(0), ip(), port(0)
+trsp_socket::trsp_socket(unsigned short if_num)
+ : sd(0), ip(), port(0), if_num(if_num)
{
memset(&addr,0,sizeof(sockaddr_storage));
}
@@ -90,6 +90,11 @@ int trsp_socket::get_sd()
return sd;
}
+unsigned short trsp_socket::get_if()
+{
+ return if_num;
+}
+
int trsp_socket::send(const sockaddr_storage* sa, const char* msg, const int msg_len)
{
if ((SipCtrlInterface::log_raw_messages >= 0)
diff --git a/core/sip/transport.h b/core/sip/transport.h
index 219c904..6b9f14f 100644
--- a/core/sip/transport.h
+++ b/core/sip/transport.h
@@ -56,8 +56,11 @@ protected:
// bound port number
unsigned short port;
+ // interface number
+ unsigned short if_num;
+
public:
- trsp_socket();
+ trsp_socket(unsigned short if_num);
virtual ~trsp_socket();
/**
@@ -82,6 +85,11 @@ public:
int get_sd();
/**
+ * Getter for the interface number
+ */
+ unsigned short get_if();
+
+ /**
* Copy the internal address into the given one (sa).
*/
void copy_addr_to(sockaddr_storage* sa);
diff --git a/core/sip/udp_trsp.h b/core/sip/udp_trsp.h
index e6852d4..f508489 100644
--- a/core/sip/udp_trsp.h
+++ b/core/sip/udp_trsp.h
@@ -45,7 +45,7 @@ using std::string;
class udp_trsp_socket: public trsp_socket
{
public:
- udp_trsp_socket() : trsp_socket() {}
+ udp_trsp_socket(unsigned short if_num) : trsp_socket(if_num) {}
~udp_trsp_socket() {}
/**
--
1.7.7.3
--------------050907080704090604090601--
More information about the sr-dev
mailing list