Browse code

core: use PublicIP in Via-HF

Raphael Coeffic authored on 18/07/2013 15:59:53
Showing 4 changed files
... ...
@@ -123,6 +123,10 @@ int _SipCtrlInterface::load()
123 123
 				   trsp_socket::force_outbound_if : 0),
124 124
 				AmConfig::SIP_Ifs[i].NetIfIdx);
125 125
 	
126
+	if(!AmConfig::SIP_Ifs[i].PublicIP.empty()) {
127
+	    udp_socket->set_public_ip(AmConfig::SIP_Ifs[i].PublicIP);
128
+	}
129
+
126 130
 	if(udp_socket->bind(AmConfig::SIP_Ifs[i].LocalIP,
127 131
 			    AmConfig::SIP_Ifs[i].LocalPort) < 0){
128 132
 
... ...
@@ -927,7 +927,7 @@ static int generate_and_parse_new_msg(sip_msg* msg, sip_msg*& p_msg)
927 927
     compute_branch(branch_buf,msg->callid->value,msg->cseq->value);
928 928
     cstring branch(branch_buf,BRANCH_BUF_LEN);
929 929
      
930
-    string via(msg->local_socket->get_ip());
930
+    string via(msg->local_socket->get_advertised_ip());
931 931
     if(msg->local_socket->get_port() != 5060)
932 932
  	via += ":" + int2str(msg->local_socket->get_port());
933 933
  
... ...
@@ -58,6 +58,19 @@ unsigned short trsp_socket::get_port() const
58 58
     return port;
59 59
 }
60 60
 
61
+void trsp_socket::set_public_ip(const string& ip)
62
+{
63
+    public_ip = ip;
64
+}
65
+    
66
+const char* trsp_socket::get_advertised_ip() const
67
+{
68
+    if(!public_ip.empty())
69
+	return public_ip.c_str();
70
+
71
+    return get_ip();
72
+}
73
+
61 74
 bool trsp_socket::is_opt_set(unsigned int mask) const
62 75
 {
63 76
     DBG("trsp_socket::socket_options = 0x%x\n",socket_options);
... ...
@@ -60,6 +60,9 @@ protected:
60 60
     // bound port number
61 61
     unsigned short   port;
62 62
 
63
+    // public IP (Via-HF)
64
+    string      public_ip;
65
+
63 66
     // internal interface number
64 67
     unsigned short   if_num;
65 68
 
... ...
@@ -95,6 +98,17 @@ public:
95 98
      */
96 99
     unsigned short get_port() const;
97 100
 
101
+    /**
102
+     * Setter for public IP address
103
+     */
104
+    void set_public_ip(const string& ip);
105
+    
106
+    /**
107
+     * Getter for advertised IP address
108
+     * @return either bound IP or public IP
109
+     */
110
+    const char* get_advertised_ip() const;
111
+
98 112
     /**
99 113
      *  Getter for the socket descriptor
100 114
      */