[SR-Users] how to extract the ip address in the via header received paramter

Ajay Sabat Ajay.Sabat at panasonic.aero
Wed Mar 13 19:49:16 CET 2013


I added the append_hf() inside the if condition in oureply_route[] block as given below, and it is working.
I still want to learn how to store data in a variable to use it later in another block. 

Thanks,
Ajay 

Hi Daniel,

Thanks for your response. But I don't want the IP in the received parameter of the incoming request. 
Instead, I want to read it (i.e. the public IP address of my own network where the local user and Kamailio are located) from the incoming response received from another proxy located outside the network. And I need that because Kamailio strips the top most via (where the received parameter is present ) in the incoming response before sending it back to the local user, which I guess is correct. But the user needs to know that IP address. So we are planning to send that IP address in a custom header in the response back to the user.

After going through some Kamailio documents I found that $sel(via.received) would return the IP address in top most via of a message. Can I store it in a variable inside onreply_route[MANAGE_REPLY] block and use that variable later in some appropriate route block to insert a new header in the response to the local user? 

Can I do something as given below to fetch and store the IP address from received parameter in the via header of incoming response

onreply_route[MANAGE_REPLY] {
...
if(search_hf("Via", "received", "f")) {
		xdbg("received param exists on top most via header \n");
		$var(public_ip) = $sel(via.received);
	}
...
}

and insert a new header as given below in an appropriate route block which is executed while sending response back?
append_hf("My-custom-hdr: $var(public_ip) \r\n");

I am not sure if this logic would work. Is the $var() variable retained through two different sip transactions? And which route block should be used to insert the header as mentioned above? Please help.

Thanks,
Ajay

Hello,

the received parameter is constructed from source IP of the incoming request. You get it via $si script variable.

Cheers,
Daniel

On 3/12/13 7:22 PM, Ajay Sabat wrote:
>
> Hi,
>
> I want to extract the IP address in the received parameter of the top 
> most via header of a response and use that in a custom header while 
> sending response back to the caller. Can somebody please tell how to 
> implement that in the Kamailio configuration file?
>
> I need to handle a NAT traversal scenario without enabling NAT in 
> Kamailio which is used as the proxy server. The caller which is in the 
> same network as Kamailio first sends a OPTIONS request to the callee 
> before sending the INVITE. It uses the public IP address returned in 
> the custom header of the OPTIONS response to build the contact header 
> and SDP of the INVITE request. In fact, it first looks for the IP 
> address in the received parameter of the via header to do that. But 
> Kamailio removes the top most via with received parameter and then 
> sends the OPTIONS response back to the caller. So we are using a 
> custom header for that purpose.
>
> I would appreciate other suggestions to achieve this in Kamailio, may 
> be by enabling NAT or some other alternative.
>
> Thanks,
>
> Ajay
>
>
>
> _______________________________________________
> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing 
> list sr-users at lists.sip-router.org 
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

--
Daniel-Constantin Mierla - http://www.asipto.com http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Kamailio World Conference, April 16-17, 2013, Berlin
  - http://conference.kamailio.com -





More information about the sr-users mailing list