소스 검색

modules_k/rr: record_route_preset enahancement

 - record_route_preset takes a second parameter allowing
   the setting of a second Record-Route header
 - new rr param 'enable_socket_mismatch_warning': enables or
   disables a warning log

 - closes FS#91 - record_route_preset enhancement
Ovidiu Sas 15 년 전
부모
커밋
65b0d767a1
5개의 변경된 파일105개의 추가작업 그리고 22개의 파일을 삭제
  1. 43 17
      modules_k/rr/README
  2. 37 2
      modules_k/rr/doc/rr_admin.xml
  3. 4 2
      modules_k/rr/loose.c
  4. 20 1
      modules_k/rr/rr_mod.c
  5. 1 0
      modules_k/rr/rr_mod.h

+ 43 - 17
modules_k/rr/README

@@ -40,12 +40,13 @@ Bogdan-Andrei Iancu
               4.2. append_fromtag (integer)
               4.3. enable_double_rr (integer)
               4.4. add_username (integer)
+              4.5. enable_socket_mismatch_warning (integer)
 
         5. Exported Functions
 
               5.1. loose_route()
               5.2. record_route() and record_route(string)
-              5.3. record_route_preset(string)
+              5.3. record_route_preset(string [,string2])
               5.4. add_rr_param(param)
               5.5. check_route_param(re)
               5.6. is_direction(dir)
@@ -69,12 +70,13 @@ Bogdan-Andrei Iancu
    1.3. Set append_fromtag parameter
    1.4. Set enable_double_rr parameter
    1.5. Set add_username parameter
-   1.6. loose_route usage
-   1.7. record_route usage
-   1.8. record_route_preset usage
-   1.9. add_rr_param usage
-   1.10. check_route_param usage
-   1.11. is_direction usage
+   1.6. enable_socket_mismatch_warning usage
+   1.7. loose_route usage
+   1.8. record_route usage
+   1.9. record_route_preset usage
+   1.10. add_rr_param usage
+   1.11. check_route_param usage
+   1.12. is_direction usage
    2.1. Loading RR module's API from another module
 
 Chapter 1. Admin Guide
@@ -94,12 +96,13 @@ Chapter 1. Admin Guide
         4.2. append_fromtag (integer)
         4.3. enable_double_rr (integer)
         4.4. add_username (integer)
+        4.5. enable_socket_mismatch_warning (integer)
 
    5. Exported Functions
 
         5.1. loose_route()
         5.2. record_route() and record_route(string)
-        5.3. record_route_preset(string)
+        5.3. record_route_preset(string [,string2])
         5.4. add_rr_param(param)
         5.5. check_route_param(re)
         5.6. is_direction(dir)
@@ -176,6 +179,7 @@ UAC                       Kamailio PROXY                          UAS
    4.2. append_fromtag (integer)
    4.3. enable_double_rr (integer)
    4.4. add_username (integer)
+   4.5. enable_socket_mismatch_warning (integer)
 
 4.1. enable_full_lr (integer)
 
@@ -232,11 +236,27 @@ modparam("rr", "enable_double_rr", 0)
 modparam("rr", "add_username", 1)
 ...
 
+4.5. enable_socket_mismatch_warning (integer)
+
+   When a preset record-route header is forced in Kamailio config and the
+   host from the record-route header is not the same as the host server, a
+   warning will be printed out in the logs. The
+   'enable_socket_mismatch_warning' parameter enables or disables the
+   warning. When Kamailio is behind a NATed firewall, we don't want this
+   warning to be printed for every bridged call.
+
+   Default value is 1 (yes).
+
+   Example 1.6. enable_socket_mismatch_warning usage
+...
+modparam("rr", "enable_socket_mismatch_warning", 0)
+...
+
 5. Exported Functions
 
    5.1. loose_route()
    5.2. record_route() and record_route(string)
-   5.3. record_route_preset(string)
+   5.3. record_route_preset(string [,string2])
    5.4. add_rr_param(param)
    5.5. check_route_param(re)
    5.6. is_direction(dir)
@@ -270,7 +290,7 @@ modparam("rr", "add_username", 1)
 
    This function can be used from REQUEST_ROUTE.
 
-   Example 1.6. loose_route usage
+   Example 1.7. loose_route usage
 ...
 loose_route();
 ...
@@ -288,24 +308,30 @@ loose_route();
    This function can be used from REQUEST_ROUTE, BRANCH_ROUTE and
    FAILURE_ROUTE.
 
-   Example 1.7. record_route usage
+   Example 1.8. record_route usage
 ...
 record_route();
 ...
 
-5.3.  record_route_preset(string)
+5.3.  record_route_preset(string [,string2])
 
    This function will put the string into Record-Route, don't use unless
    you know what you are doing.
 
    Meaning of the parameters is as follows:
-     * string - String to be inserted into the header field; it may
+     * string - String to be inserted into the first header field; it may
        contain pseudo-variables.
+     * string2 - String to be inserted into the second header field; it
+       may contain pseudo-variables.
+
+   Note: If 'string2' is present, then the 'string' param is pointing to
+   the outbound interface and the 'string2' param is pointing to the
+   inbound interface.
 
    This function can be used from REQUEST_ROUTE, BRANCH_ROUTE and
    FAILURE_ROUTE.
 
-   Example 1.8. record_route_preset usage
+   Example 1.9. record_route_preset usage
 ...
 record_route_preset("1.2.3.4:5090");
 ...
@@ -324,7 +350,7 @@ record_route_preset("1.2.3.4:5090");
    This function can be used from REQUEST_ROUTE, BRANCH_ROUTE and
    FAILURE_ROUTE.
 
-   Example 1.9. add_rr_param usage
+   Example 1.10. add_rr_param usage
 ...
 add_rr_param(";nat=yes");
 ...
@@ -341,7 +367,7 @@ add_rr_param(";nat=yes");
 
    This function can be used from REQUEST_ROUTE.
 
-   Example 1.10. check_route_param usage
+   Example 1.11. check_route_param usage
 ...
 if (check_route_param("nat=yes")) {
     setflag(6);
@@ -369,7 +395,7 @@ if (check_route_param("nat=yes")) {
 
    This function can be used from REQUEST_ROUTE.
 
-   Example 1.11. is_direction usage
+   Example 1.12. is_direction usage
 ...
 if (is_direction("downstream")) {
     xdbg("in-dialog request from caller to callee (downstream) ($rm)\n");

+ 37 - 2
modules_k/rr/doc/rr_admin.xml

@@ -209,6 +209,31 @@ modparam("rr", "enable_double_rr", 0)
 ...
 modparam("rr", "add_username", 1)
 ...
+</programlisting>
+		</example>
+	</section>
+
+	<section>
+		<title><varname>enable_socket_mismatch_warning</varname> (integer)</title>
+		<para>
+		When a preset record-route header is forced in &kamailio; config and the
+		host from the record-route header is not the same as the host server,
+		a warning will be printed out in the logs.
+		The 'enable_socket_mismatch_warning' parameter enables or disables the warning.
+		When &kamailio; is behind a NATed firewall, we don't want this warning
+		to be printed for every bridged call.
+		</para>
+		<para>
+		<emphasis>
+			Default value is 1 (yes).
+		</emphasis>
+		</para>
+		<example>
+		<title><varname>enable_socket_mismatch_warning</varname> usage</title>
+		<programlisting format="linespecific">
+...
+modparam("rr", "enable_socket_mismatch_warning", 0)
+...
 </programlisting>
 		</example>
 	</section>
@@ -296,7 +321,7 @@ record_route();
 
 	<section>
 		<title>
-		<function moreinfo="none">record_route_preset(string)</function>
+		<function moreinfo="none">record_route_preset(string [,string2])</function>
 		</title>
 		<para>
 		This function will put the string into Record-Route, don't use 
@@ -307,11 +332,21 @@ record_route();
 		<listitem>
 			<para>
 			<emphasis>string</emphasis> - String to be inserted into the 
-				header field; it may contain pseudo-variables.
+				first header field; it may contain pseudo-variables.
+			</para>
+		</listitem>
+		<listitem>
+			<para>
+			<emphasis>string2</emphasis> - String to be inserted into the 
+				second header field; it may contain pseudo-variables.
 			</para>
 		</listitem>
 		</itemizedlist>
 		<para>
+		Note: If 'string2' is present, then the 'string' param is pointing to the
+		outbound interface and the 'string2' param is pointing to the inbound interface.
+		</para>
+		<para>
 		This function can be used from REQUEST_ROUTE, BRANCH_ROUTE and 
 		FAILURE_ROUTE.
 		</para>

+ 4 - 2
modules_k/rr/loose.c

@@ -599,7 +599,8 @@ static inline int after_strict(struct sip_msg* _m)
 		if (si) {
 			set_force_socket(_m, si);
 		} else {
-			LM_WARN("no socket found for match second RR\n");
+			if (enable_socket_mismatch_warning)
+				LM_WARN("no socket found for match second RR\n");
 		}
 
 		if (!rt->next) {
@@ -815,7 +816,8 @@ static inline int after_loose(struct sip_msg* _m, int preloaded)
 			if (si) {
 				set_force_socket(_m, si);
 			} else {
-				LM_WARN("no socket found for match second RR\n");
+				if (enable_socket_mismatch_warning)
+					LM_WARN("no socket found for match second RR\n");
 			}
 
 			if (!rt->next) {

+ 20 - 1
modules_k/rr/rr_mod.c

@@ -54,6 +54,7 @@ int append_fromtag = 1;		/*!< append from tag by default */
 int enable_double_rr = 1;	/*!< enable using of 2 RR by default */
 int enable_full_lr = 0;		/*!< compatibilty mode disabled by default */
 int add_username = 0;	 	/*!< do not add username by default */
+ int enable_socket_mismatch_warning = 1; /*!< enable socket mismatch warning */
 
 static unsigned int last_rr_msg;
 
@@ -82,6 +83,8 @@ static cmd_export_t cmds[] = {
 			REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
 	{"record_route_preset",  (cmd_function)w_record_route_preset, 1, it_list_fixup, 0,
 			REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
+	{"record_route_preset",  (cmd_function)w_record_route_preset, 2, it_list_fixup, 0,
+			REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
 	{"add_rr_param",         (cmd_function)w_add_rr_param,	1, it_list_fixup, 0,
 			REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE},
 	{"check_route_param",    (cmd_function)w_check_route_param, 1, fixup_regexp_null, fixup_free_regexp_null,
@@ -104,6 +107,7 @@ static param_export_t params[] ={
 	{"ignore_user",		STR_PARAM, &ignore_user},
 #endif
 	{"add_username",		INT_PARAM, &add_username},
+	{"enable_socket_mismatch_warning",INT_PARAM,&enable_socket_mismatch_warning},
 	{0, 0, 0 }
 };
 
@@ -217,7 +221,7 @@ static int w_record_route(struct sip_msg *msg, char *key, char *bar)
 }
 
 
-static int w_record_route_preset(struct sip_msg *msg, char *key, char *bar)
+static int w_record_route_preset(struct sip_msg *msg, char *key, char *key2)
 {
 	str s;
 
@@ -225,6 +229,10 @@ static int w_record_route_preset(struct sip_msg *msg, char *key, char *bar)
 		LM_ERR("Duble attempt to record-route\n");
 		return -1;
 	}
+	if (key2 && !enable_double_rr) {
+		LM_ERR("Attempt to double record-route while 'enable_double_rr' param is disabled\n");
+		return -1;
+	}
 
 	if (pv_printf_s(msg, (pv_elem_t*)key, &s)<0) {
 		LM_ERR("failed to print the format\n");
@@ -233,6 +241,17 @@ static int w_record_route_preset(struct sip_msg *msg, char *key, char *bar)
 	if ( record_route_preset( msg, &s)<0 )
 		return -1;
 
+	if (!key2)
+		goto done;
+
+	if (pv_printf_s(msg, (pv_elem_t*)key2, &s)<0) {
+		LM_ERR("failed to print the format\n");
+		return -1;
+	}
+	if ( record_route_preset( msg, &s)<0 )
+		return -1;
+
+done:
 	last_rr_msg = msg->id;
 	return 1;
 }

+ 1 - 0
modules_k/rr/rr_mod.h

@@ -42,6 +42,7 @@ extern int enable_double_rr;
 extern int enable_full_lr;
 /*! add username to record-route URI */
 extern int add_username;
+extern int enable_socket_mismatch_warning;
 
 
 #endif /* RR_MOD_H */