[sr-dev] git:master: modules_k/nathelper: Add is_rfc1918(ip_addr) function to test ip_addr for rfc1918addresses.
Daniel-Constantin Mierla
miconda at gmail.com
Fri Jul 29 15:41:41 CEST 2011
Hi Alex,
I wonder if does not make more sense to have this function in the new
ipops module:
http://kamailio.org/docs/modules/devel/modules/ipops.html
Cheers,
Daniel
On 7/22/11 6:38 PM, Alex Hermann wrote:
> Module: sip-router
> Branch: master
> Commit: 411de126aa30dd67663b790df7aaa9b303189be5
> URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=411de126aa30dd67663b790df7aaa9b303189be5
>
> Author: Alex Hermann<alex at speakup.nl>
> Committer: Alex Hermann<alex at speakup.nl>
> Date: Tue Jul 19 15:24:11 2011 +0200
>
> modules_k/nathelper: Add is_rfc1918(ip_addr) function to test ip_addr for rfc1918addresses.
>
> ---
>
> modules_k/nathelper/README | 46 ++++++++++++++++----------
> modules_k/nathelper/doc/nathelper_admin.xml | 13 +++++++
> modules_k/nathelper/nathelper.c | 18 ++++++++++
> 3 files changed, 59 insertions(+), 18 deletions(-)
>
> diff --git a/modules_k/nathelper/README b/modules_k/nathelper/README
> index a911951..7497492 100644
> --- a/modules_k/nathelper/README
> +++ b/modules_k/nathelper/README
> @@ -64,8 +64,9 @@ Ovidiu Sas
> 5.4. add_rcv_param([flag]),
> 5.5. fix_nated_register()
> 5.6. nat_uac_test(flags)
> - 5.7. add_contact_alias()
> - 5.8. handle_ruri_alias()
> + 5.7. is_rfc1918(ip_address)
> + 5.8. add_contact_alias()
> + 5.9. handle_ruri_alias()
>
> 6. Exported Pseudo Variables
>
> @@ -131,8 +132,9 @@ Chapter 1. Admin Guide
> 5.4. add_rcv_param([flag]),
> 5.5. fix_nated_register()
> 5.6. nat_uac_test(flags)
> - 5.7. add_contact_alias()
> - 5.8. handle_ruri_alias()
> + 5.7. is_rfc1918(ip_address)
> + 5.8. add_contact_alias()
> + 5.9. handle_ruri_alias()
>
> 6. Exported Pseudo Variables
>
> @@ -235,7 +237,7 @@ modparam("nathelper", "natping_interval", 10)
>
> 4.2. ping_nated_only (integer)
>
> - If this variable is set then only contacts that have “behind_NAT” flag
> + If this variable is set then only contacts that have "behind_NAT" flag
> in user location database set will get ping.
>
> Default value is 0.
> @@ -310,7 +312,7 @@ modparam("nathelper", "sipping_bflag", 7)
> feature, you have to set this parameter. The SIP request pinging will
> be used only for requests marked so.
>
> - Default value is “NULL”.
> + Default value is "NULL".
>
> Example 1.7. Set sipping_from parameter
> ...
> @@ -322,7 +324,7 @@ modparam("nathelper", "sipping_from", "sip:pinger at siphub.net")
> The parameter sets the SIP method to be used in generating the SIP
> requests for NAT ping purposes.
>
> - Default value is “OPTIONS”.
> + Default value is "OPTIONS".
>
> Example 1.8. Set sipping_method parameter
> ...
> @@ -340,7 +342,7 @@ Note
>
> The string must be a complete SDP line, including the EOH (\r\n).
>
> - Default value is “a=nortpproxy:yes\r\n”.
> + Default value is "a=nortpproxy:yes\r\n".
>
> Example 1.9. Set nortpproxy_str parameter
> ...
> @@ -355,8 +357,9 @@ modparam("nathelper", "nortpproxy_str", "a=sdpmangled:yes\r\n")
> 5.4. add_rcv_param([flag]),
> 5.5. fix_nated_register()
> 5.6. nat_uac_test(flags)
> - 5.7. add_contact_alias()
> - 5.8. handle_ruri_alias()
> + 5.7. is_rfc1918(ip_address)
> + 5.8. add_contact_alias()
> + 5.9. handle_ruri_alias()
>
> 5.1. fix_nated_contact()
>
> @@ -373,15 +376,15 @@ if (search("User-Agent: Cisco ATA.*") {fix_nated_contact();};
> 5.2. fix_nated_sdp(flags [, ip_address])
>
> Alters the SDP information in orer to facilitate NAT traversal. What
> - changes to be performed may be controled via the “flags” parameter.
> + changes to be performed may be controled via the "flags" parameter.
>
> Meaning of the parameters is as follows:
> * flags - the value may be a bitwise OR of the following flags:
> - + 0x01 - adds “a=direction:active” SDP line;
> + + 0x01 - adds "a=direction:active" SDP line;
> + 0x02 - rewrite media IP address (c=) with source address of
> the message or the provided IP address (the provide IP address
> take precedence over the source address).
> - + 0x04 - adds “a=nortpproxy:yes” SDP line;
> + + 0x04 - adds "a=nortpproxy:yes" SDP line;
> + 0x08 - rewrite IP from origin description (o=) with source
> address of the message or the provided IP address (the provide
> IP address take precedence over the source address).
> @@ -476,7 +479,14 @@ fix_nated_register();
> This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE,
> FAILURE_ROUTE, BRANCH_ROUTE.
>
> -5.7. add_contact_alias()
> +5.7. is_rfc1918(ip_address)
> +
> + Determines if the address in the parameter is an rfc1918 address. The
> + parameter allows pseudo-variables usage.
> +
> + This function can be used from ANY_ROUTE.
> +
> +5.8. add_contact_alias()
>
> Adds ;alias=ip:port parameter to contact URI containing received
> ip:port if contact uri ip:port does not match received ip:port.
> @@ -495,7 +505,7 @@ fix_nated_register();
> };
> ...
>
> -5.8. handle_ruri_alias()
> +5.9. handle_ruri_alias()
>
> Checks if Request URI has alias param and if so, removes it and sets
> $du based on its value. Note that this means that routing of request is
> @@ -576,16 +586,16 @@ $ kamctl fifo nh_enable_ping 1
>
> Chapter 2. Frequently Asked Questions
>
> - 2.1. What happend with “rtpproxy_disable” parameter?
> + 2.1. What happend with "rtpproxy_disable" parameter?
> 2.2. Where can I find more about Kamailio?
> 2.3. Where can I post a question about this module?
> 2.4. How can I report a bug?
>
> 2.1.
>
> - What happend with “rtpproxy_disable” parameter?
> + What happend with "rtpproxy_disable" parameter?
>
> - It was removed as it became obsolete - now “rtpproxy_sock” can take
> + It was removed as it became obsolete - now "rtpproxy_sock" can take
> empty value to disable the rtpproxy functionality.
>
> 2.2.
> diff --git a/modules_k/nathelper/doc/nathelper_admin.xml b/modules_k/nathelper/doc/nathelper_admin.xml
> index 4d7947b..f01a4c7 100644
> --- a/modules_k/nathelper/doc/nathelper_admin.xml
> +++ b/modules_k/nathelper/doc/nathelper_admin.xml
> @@ -552,6 +552,19 @@ fix_nated_register();
>
> <section>
> <title>
> + <function>is_rfc1918(ip_address)</function>
> + </title>
> + <para>
> + Determines if the address in the parameter is an rfc1918 address.
> + The parameter allows pseudo-variables usage.
> + </para>
> + <para>
> + This function can be used from ANY_ROUTE.
> + </para>
> + </section>
> +
> + <section>
> + <title>
> <function moreinfo="none">add_contact_alias()</function>
> </title>
> <para>
> diff --git a/modules_k/nathelper/nathelper.c b/modules_k/nathelper/nathelper.c
> index bc3784a..ad9954f 100644
> --- a/modules_k/nathelper/nathelper.c
> +++ b/modules_k/nathelper/nathelper.c
> @@ -289,6 +289,7 @@ static int handle_ruri_alias_f(struct sip_msg *, char *, char *);
> static int pv_get_rr_count_f(struct sip_msg *, pv_param_t *, pv_value_t *);
> static int pv_get_rr_top_count_f(struct sip_msg *, pv_param_t *, pv_value_t *);
> static int fix_nated_sdp_f(struct sip_msg *, char *, char *);
> +static int is_rfc1918_f(struct sip_msg *, char *, char *);
> static int extract_mediaip(str *, str *, int *, char *);
> static int alter_mediaip(struct sip_msg *, str *, str *, int, str *, int, int);
> static int fix_nated_register_f(struct sip_msg *, char *, char *);
> @@ -378,6 +379,9 @@ static cmd_export_t cmds[] = {
> {"add_rcv_param", (cmd_function)add_rcv_param_f, 1,
> fixup_uint_null, 0,
> REQUEST_ROUTE },
> + {"is_rfc1918", (cmd_function)is_rfc1918_f, 1,
> + fixup_spve_null, 0,
> + ANY_ROUTE },
> {0, 0, 0, 0, 0, 0}
> };
>
> @@ -1272,6 +1276,20 @@ nat_uac_test_f(struct sip_msg* msg, char* str1, char* str2)
>
> }
>
> +static int
> +is_rfc1918_f(struct sip_msg* msg, char* str1, char* str2)
> +{
> + str address;
> +
> + if(fixup_get_svalue(msg, (gparam_p)str1,&address)!=0 || address.len==0)
> + {
> + LM_ERR("invalid address parameter\n");
> + return -2;
> + }
> +
> + return (is1918addr(&address) == 1) ? 1 : -1;
> +}
> +
> #define ADD_ADIRECTION 0x01
> #define FIX_MEDIP 0x02
> #define ADD_ANORTPPROXY 0x04
>
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
--
Daniel-Constantin Mierla -- http://www.asipto.com
Kamailio Advanced Training, Oct 10-13, Berlin: http://asipto.com/u/kat
http://linkedin.com/in/miconda -- http://twitter.com/miconda
More information about the sr-dev
mailing list