Browse code

core: use the request's interface as outbound interface by default.

Raphael Coeffic authored on 01/02/2012 15:17:13
Showing 6 changed files
... ...
@@ -166,6 +166,7 @@ void AmSipDialog::onRxRequest(const AmSipRequest& req)
166 166
       remote_party = req.from;
167 167
       local_party  = req.to;
168 168
       route        = req.route;
169
+      outbound_interface = req.local_if;
169 170
     }
170 171
   }
171 172
 
... ...
@@ -77,6 +77,8 @@ class AmSipRequest : public _AmSipMsgInDlg
77 77
   unsigned int rack_cseq;
78 78
   string via_branch;
79 79
 
80
+  unsigned short local_if;
81
+
80 82
   AmSipRequest() : _AmSipMsgInDlg() { }
81 83
   ~AmSipRequest() { }
82 84
   
... ...
@@ -241,7 +241,7 @@ int SipCtrlInterface::run()
241 241
     // Init transport instances
242 242
     for(unsigned int i=0; i<AmConfig::Ifs.size();i++) {
243 243
 
244
-	udp_trsp_socket* udp_socket = new udp_trsp_socket;
244
+	udp_trsp_socket* udp_socket = new udp_trsp_socket(i);
245 245
 
246 246
 	if(udp_socket->bind(AmConfig::Ifs[i].LocalSIPIP,
247 247
 			    AmConfig::Ifs[i].LocalSIPPort) < 0){
... ...
@@ -461,6 +461,8 @@ inline void SipCtrlInterface::sip_msg2am_request(const sip_msg *msg,
461 461
     req.remote_port = htons(((sockaddr_in*)&msg->remote_ip)->sin_port);
462 462
     req.local_ip = get_addr_str(&msg->local_ip).c_str();
463 463
     req.local_port = htons(((sockaddr_in*)&msg->local_ip)->sin_port);
464
+
465
+    req.local_if = msg->local_socket->get_if();
464 466
 }
465 467
 
466 468
 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)
549 551
 
550 552
     req.tt = tt;
551 553
 
552
-    DBG("Received new request\n");
554
+    DBG("Received new request from <%s:%i> on intf #%i\n",
555
+	req.remote_ip.c_str(),req.remote_port,req.local_if);
556
+
553 557
     if (SipCtrlInterface::log_parsed_messages) {
554 558
 	//     DBG_PARAM(req.cmd);
555 559
 	DBG_PARAM(req.method);
... ...
@@ -34,8 +34,8 @@
34 34
 #include <netinet/in.h>
35 35
 #include <string.h> // memset, strerror, ...
36 36
 
37
-trsp_socket::trsp_socket()
38
-    : sd(0), ip(), port(0)
37
+trsp_socket::trsp_socket(unsigned short if_num)
38
+    : sd(0), ip(), port(0), if_num(if_num)
39 39
 {
40 40
     memset(&addr,0,sizeof(sockaddr_storage));
41 41
 }
... ...
@@ -90,6 +90,11 @@ int trsp_socket::get_sd()
90 90
     return sd;
91 91
 }
92 92
 
93
+unsigned short trsp_socket::get_if()
94
+{
95
+    return if_num;
96
+}
97
+
93 98
 int trsp_socket::send(const sockaddr_storage* sa, const char* msg, const int msg_len)
94 99
 {
95 100
     if ((SipCtrlInterface::log_raw_messages >= 0)
... ...
@@ -56,8 +56,11 @@ protected:
56 56
     // bound port number
57 57
     unsigned short   port;
58 58
 
59
+    // interface number
60
+    unsigned short   if_num;
61
+
59 62
 public:
60
-    trsp_socket();
63
+    trsp_socket(unsigned short if_num);
61 64
     virtual ~trsp_socket();
62 65
 
63 66
     /**
... ...
@@ -81,6 +84,11 @@ public:
81 84
      */
82 85
     int get_sd();
83 86
 
87
+    /**
88
+     * Getter for the interface number
89
+     */
90
+    unsigned short get_if();
91
+
84 92
     /**
85 93
      * Copy the internal address into the given one (sa).
86 94
      */
... ...
@@ -45,7 +45,7 @@ using std::string;
45 45
 class udp_trsp_socket: public trsp_socket
46 46
 {
47 47
 public:
48
-    udp_trsp_socket() : trsp_socket() {}
48
+    udp_trsp_socket(unsigned short if_num) : trsp_socket(if_num) {}
49 49
     ~udp_trsp_socket() {}
50 50
 
51 51
     /**