Opps i made a mistake, instead of "avp_write" you need to use "avp_printf" to store the pseudo variable into an AVP and when you are doing the comparison with avp_check you need an alias defined for the second AVP otherwise you might end up comparing the AVP with a literal value
modparam( "avpops", "avp_aliases", "dest_ip=i:401" )
avp_printf("i:400", "$si"); avp_printf("i:401", "$rd");
if ( avp_check("i:400", "eq/$dest_ip/g") ) { xlog("L_INFO", ""$si" == "$rd" "); }
Norman Brandinger wrote:
Hi Tavis,
I tried your suggestion.
First, thanks for the information about using avp_printf() to save a pseudo variable to an AVP. Either I overlooked the doc in regard to this or there isn't any doc. Do you know if it's documented ? Seem to recall a comment about this on the mailing list a while ago...??
It in my testing, $si = public IP address of the NAT Router which is what was expected. However, $rd = the private IP of the callee. Unfortunately the private ip isn't useful. A quick look at the location table shows that the private IP stored in the "contact" column. It appears that the value from the "received" column is what is needed. I guess the question is: "after a lookup(), is the "received" column saved in a pseudo variable ?
Regards, Norm
Tavis P wrote:
The one i posted before was for clients using STUN who are behind a NAT that does not support hairpinning (data directed from the internal ip address of one client to the external ip address of the nat does not map to other internal clients) but the logic is similar for media optimization of nat clients in the same network environment.
I'm working on a little bit of script that i think could do it, the first thing that you should check for is that the external IP address is the same (not using the script below as you've shown) and then check of the internal ip address is the same using avp_printf and then avp_subst to subtract the information from the SIP headers where it resides
I'll post it later on today if i get some time
Norman Brandinger wrote:
Sorry my logic was bad, again
It seems that its not really feasable to do media path optimization for clients that are behind the same nat currently (at least not with the approaches i've taken)
The primary issue is that i can find no reliable way to access the external IP address of the callee ( maybe "received" information stored in Location Database?) when both clients are behind a NAT, if this was made available then it should be easy. Somthing like:
# If both clients are behind nat we can check to see if they are behind the same # external IP and optimize the media path to go directly between them else if ( isflagset(2) and isflagset(3) ) { log(1, "Both Clients are behind the same NAT");
avp_printf("i:450", "RECEIVED Header Field of Callee"); avp_subst("i:450", "/need to/extract only the IP from text string/");
if ( avp_check("i:450", "eq/$src_ip/g") ) { log(1, "Both clients seem to be behind the same NAT, disabled mediaproxy use");
# Do not use mediaproxy as the clients are behind the same NAT resetflag(2); resetflag(3); }
Tavis P wrote:
Yes, you pretty much ended up at the same place I did.
It appears that the value from the "received" column is what is needed.
I guess the question is: "after a lookup(), is the "received" column saved in a pseudo variable ?
Norm
Tavis P wrote:
It works!
Thanks for the reference Klaus
Heres a config snippit:
else if ( isflagset(2) and isflagset(3) ) { log(1, "Both Clients are behind NAT");
# Store the destination domain into an AVP avp_printf("i:450", "$dd");
if ( avp_check("i:450", "eq/$src_ip/g") ) { xlog("L_INFO", "Detected Two Clients Behind the Same NAT - Disabling Mediaproxy");
# Do not use mediaproxy as the clients seem to be behind the same NAT resetflag(2); resetflag(3); }
}
Klaus Darilion wrote:
Thanks go out to Klaus and Tavis.
I took the results of this thread and placed it in the docuwiki for the rest of the user community to use (at least, the rest of the user community that reads the docuwiki :)
http://openser.org/dokuwiki/doku.php?id=avp_examples
If I made any typos, please feel free to correct them.
Regards, Norm
Tavis P wrote:
I've not followed the thread, but I think this could work:
#incoming call # step 1 write src_ip $si to AVP lookup("location"); # step 2 write destination IP $dd into AVP compare AVPs if AVP1!=AVP2 && natflag {use rtpproxy}
I think this should work as long as there is only one client registered. If there are multiple branches, step 2 must be done in the branch route.
klaus