[Devel] [PATCH] mediaproxy module and src-ip AVP

Daniel-Constantin Mierla daniel at voice-system.ro
Wed Apr 26 16:00:24 CEST 2006


Just to avoid adding a lot of parameters, in my opinion is better, to 
set the src_ip_avp to null and if not explicitly set, then you skip avp 
searching.

Cheers,
Daniel



On 04/26/06 16:34, Andreas Granig wrote:
> Juha Heinanen wrote:
>> Andreas Granig writes:
>>
>>  > Maybe an additional mediaproxy module parameter "use_src_ip_avp" 
>> would  > do it? Not sure if it's really necessary to decide per 
>> use_media_proxy()  > call whether the avp should be used or not...
>>
>> if no need for per call, then module param would be fine.
>
> Ok, I've extended the patch to use an additional parameter 
> "use_src_ip_avp". If 1, the AVP defined by "src_ip_avp" is used to 
> override the source IP. Otherwise the AVP is completely ignored.
>
> The feature is disabled by default.
>
> Andy
> ------------------------------------------------------------------------
>
> Index: modules/mediaproxy/mediaproxy.c
> ===================================================================
> RCS file: /cvsroot/openser/sip-server/modules/mediaproxy/mediaproxy.c,v
> retrieving revision 1.10
> diff -u -r1.10 mediaproxy.c
> --- modules/mediaproxy/mediaproxy.c	24 Mar 2006 18:04:56 -0000	1.10
> +++ modules/mediaproxy/mediaproxy.c	26 Apr 2006 13:31:47 -0000
> @@ -39,6 +39,7 @@
>  #include "../../parser/parse_to.h"
>  #include "../../parser/parse_uri.h"
>  #include "../../msg_translator.h"
> +#include "../../usr_avp.h"
>  #include "../registrar/sip_msg.h"
>  #include "../usrloc/usrloc.h"
>  
> @@ -78,6 +79,8 @@
>  #define True  1
>  #define False 0
>  
> +#define MPROXY_SRC_IP_AVP	"mediaproxy_source_ip_avp"
> +
>  
>  typedef int  (*CheckLocalPartyProc)(struct sip_msg* msg, char* s1, char* s2);
>  
> @@ -141,6 +144,13 @@
>  
>  
>  /* Local global variables */
> +
> +static char *srcIpParam = MPROXY_SRC_IP_AVP;
> +static str srcIpStr;
> +static int srcIpAvpType = 0;
> +static int_str srcIpAvp = (int_str)0;
> +static int srcIpAvpEnabled = 0;
> +
>  static char *mediaproxySocket = "/var/run/proxydispatcher.sock";
>  
>  static int natpingInterval = 60; // 60 seconds
> @@ -199,6 +209,8 @@
>      {"sip_asymmetrics",   STR_PARAM, &(sipAsymmetrics.file)},
>      {"rtp_asymmetrics",   STR_PARAM, &(rtpAsymmetrics.file)},
>      {"natping_interval",  INT_PARAM, &natpingInterval},
> +    {"use_src_ip_avp",    INT_PARAM, &srcIpAvpEnabled},
> +    {"src_ip_avp",        STR_PARAM, &srcIpParam},
>      {0, 0, 0}
>  };
>  
> @@ -1290,6 +1302,23 @@
>      return isPrivateAddress(&(msg->via1->host));
>  }
>  
> +/* 
> + * returns either the ip stored in the avp or, if not available,
> + * the source ip of the message.
> + */
> +static char* getSrcIp(struct sip_msg* msg)
> +{
> +	struct usr_avp *avp = NULL;
> +	int_str val_istr;
> +
> +	if(srcIpAvpEnabled)
> +		avp = search_first_avp(srcIpAvpType, srcIpAvp, &val_istr);
> +	if (avp && avp->flags & AVP_VAL_STR)
> +		return val_istr.s.s;
> +	else
> +		return ip_addr2a(&msg->rcv.src_ip);
> +}
> +
>  
>  #include "functions.h"
>  
> @@ -1417,7 +1446,7 @@
>          toType = "unknown"; //there's no function to check if To domain is local
>      }
>  
> -    clientIP = ip_addr2a(&msg->rcv.src_ip);
> +    clientIP = getSrcIp(msg);
>  
>      infolen = fromAddr.len + toAddr.len + fromTag.len + toTag.len + 64;
>  
> @@ -1576,6 +1605,19 @@
>      checkAsymmetricFile(&sipAsymmetrics);
>      checkAsymmetricFile(&rtpAsymmetrics);
>  
> +    // process src-ip avp
> +    if (srcIpAvpEnabled && srcIpParam && *srcIpParam) {
> +        srcIpStr.s = srcIpParam;
> +        srcIpStr.len = strlen(srcIpStr.s);
> +        if (parse_avp_spec( &srcIpStr, &srcIpAvpType,
> +            &srcIpAvp)<0) {
> +            LOG(L_ERR,"error: mediaproxy/mod_init(): invalid src_ip "
> +            "AVP specs \"%s\"\n", srcIpParam);
> +            return -1;
> +        }
> +    }
> + 
> +
>      // children won't benefit from this. figure another way
>      //register_timer(checkAsymmetricFiles, NULL, 5);
>  
> Index: modules/mediaproxy/doc/mediaproxy_user.sgml
> ===================================================================
> RCS file: /cvsroot/openser/sip-server/modules/mediaproxy/doc/mediaproxy_user.sgml,v
> retrieving revision 1.4
> diff -u -r1.4 mediaproxy_user.sgml
> --- modules/mediaproxy/doc/mediaproxy_user.sgml	24 Mar 2006 18:04:56 -0000	1.4
> +++ modules/mediaproxy/doc/mediaproxy_user.sgml	26 Apr 2006 13:31:48 -0000
> @@ -260,6 +260,48 @@
>  </programlisting>
>  			</example>
>  		</section>
> +		<section>
> +		<title><varname>src_ip_avp</varname> (string)</title>
> +			<para>
> +				Full specification (NAME, ID, Alias) of an AVP which contains the
> +				source IP of the client used by mediaproxy. If use_src_ip_avp is set
> +				to 1 and the AVP is set, the value of this AVP overrides the source IP
> +				gathered from the transport layer.
> +			</para>
> +			<para>
> +				<emphasis>
> +					Default value is mediaproxy_source_ip_avp.
> +				</emphasis>
> +			</para>
> +			<example>
> +			<title>Setting <varname>src_ip_avp</varname> parameter</title>
> +				<programlisting format="linespecific">
> +...
> +modparam("mediaproxy", "src_ip_avp", "i:99")
> +...
> +</programlisting>
> +			</example>
> +		</section>
> +		<section>
> +		<title><varname>use_src_ip_avp</varname> (int)</title>
> +			<para>
> +				If set to 1, the AVP specified by src_ip_avp is used to override the source
> +				IP gathered from the transport layer. If set to 0, the AVP is ignored.
> +			</para>
> +			<para>
> +				<emphasis>
> +					Default value is 0.
> +				</emphasis>
> +			</para>
> +			<example>
> +			<title>Setting <varname>use_src_ip_avp</varname> parameter</title>
> +				<programlisting format="linespecific">
> +...
> +modparam("mediaproxy", "use_src_ip_avp", 1)
> +...
> +</programlisting>
> +			</example>
> +		</section>
>  	</section>
>  
>  	<section>
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Devel mailing list
> Devel at openser.org
> http://openser.org/cgi-bin/mailman/listinfo/devel
>   



More information about the Devel mailing list