[sr-dev] git:master: modules/lcr: fixed bsearch argument plus doc improvements

Juha Heinanen jh at tutpro.com
Thu Jun 17 12:30:35 CEST 2010


Module: sip-router
Branch: master
Commit: b558d12e5dc1274ef5933bf03e2bdd6b0546eeae
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b558d12e5dc1274ef5933bf03e2bdd6b0546eeae

Author: Juha Heinanen <jh at tutpro.com>
Committer: Juha Heinanen <jh at tutpro.com>
Date:   Thu Jun 17 13:03:35 2010 +0300

modules/lcr: fixed bsearch argument plus doc improvements

- First bsearch argument must be of type struct gw_info.
- README improvements.

---

 modules/lcr/README            |   14 ++++++------
 modules/lcr/doc/lcr_admin.xml |    5 ++-
 modules/lcr/lcr_mod.c         |   48 +++++++++++++++++++++++-----------------
 3 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/modules/lcr/README b/modules/lcr/README
index 7f3f795..5a4a31a 100644
--- a/modules/lcr/README
+++ b/modules/lcr/README
@@ -850,8 +850,8 @@ if (from_gw("1", "$avp(s:real_source_addr)") {
 
 4.5.  from_any_gw([ip_addr])
 
-   Checks if request comes from IP address of any gateway. Only LCR
-   instances, where all gateways have IP address, are included in the
+   Checks if request comes from IP address and port of any gateway. Only
+   LCR instances, where all gateways have IP address, are included in the
    test. IP address to be checked is either taken from source IP address
    of the request or (if present) from ip_addr pseudo variable argument.
 
@@ -875,11 +875,11 @@ $var(lcr_id) = from_any_gw();
 
 4.6.  to_gw(lcr_id [, ip_addr])
 
-   Checks if in-dialog request goes to a gateway in LCR instance specified
-   by lcr_id argument. Fails if LCR instance includes one or more gateways
-   without IP address. IP address to be checked is either taken from
-   Request-URI hostpart or (if present) from ip_addr pseudo variable
-   argument.
+   Checks if in-dialog request goes to IP address and port of a gateway in
+   LCR instance specified by lcr_id argument. Fails if LCR instance
+   includes one or more gateways without IP address. IP address to be
+   checked is either taken from Request-URI hostpart or (if present) from
+   ip_addr pseudo variable argument.
 
    Returns 1 on success and -1 on failure and error.
 
diff --git a/modules/lcr/doc/lcr_admin.xml b/modules/lcr/doc/lcr_admin.xml
index 7d59972..764392f 100644
--- a/modules/lcr/doc/lcr_admin.xml
+++ b/modules/lcr/doc/lcr_admin.xml
@@ -1105,7 +1105,7 @@ if (from_gw("1", "$avp(s:real_source_addr)") {
 		<function moreinfo="none">from_any_gw([ip_addr])</function>
 		</title>
 		<para>
-		Checks if request comes from IP address of
+		Checks if request comes from IP address and port of
 		any gateway.  Only LCR instances, where all gateways
 		have IP address, are included in the test.
 		IP address to be checked is either
@@ -1145,7 +1145,8 @@ $var(lcr_id) = from_any_gw();
 		<function moreinfo="none">to_gw(lcr_id [, ip_addr])</function>
 		</title>
 		<para>
-		Checks if in-dialog request goes to a gateway in LCR
+		Checks if in-dialog request goes to IP address and port
+		of a gateway in LCR
 		instance specified by lcr_id argument.  Fails if LCR
 		instance includes one or more gateways without IP
 		address.  IP address to be
diff --git a/modules/lcr/lcr_mod.c b/modules/lcr/lcr_mod.c
index 7594c1b..e3603cb 100644
--- a/modules/lcr/lcr_mod.c
+++ b/modules/lcr/lcr_mod.c
@@ -769,7 +769,7 @@ static pcre *reg_ex_comp(const char *pattern)
 
 
 /*
- * Compare gateways based on their IP address and port
+ * Compare gateways based on their IP address
  */
 static int comp_gws(const void *_g1, const void *_g2)
 {
@@ -779,9 +779,6 @@ static int comp_gws(const void *_g1, const void *_g2)
     if (g1->ip_addr < g2->ip_addr) return -1;
     if (g1->ip_addr > g2->ip_addr) return 1;
 
-    if (g1->port < g2->port) return -1;
-    if (g1->port > g2->port) return 1;
-
     return 0;
 }
 
@@ -2057,12 +2054,12 @@ static int next_gw(struct sip_msg* _m, char* _s1, char* _s2)
 
 
 /*
- * Checks if request comes from a gateway
+ * Checks if request comes from ip address of a gateway
  */
 static int do_from_gw(struct sip_msg* _m, unsigned int lcr_id,
 		      unsigned int src_addr)
 {
-    struct gw_info *res, *gws;
+    struct gw_info *res, gw, *gws;
     int_str val;
 	
     gws = gw_pt[lcr_id];
@@ -2073,8 +2070,9 @@ static int do_from_gw(struct sip_msg* _m, unsigned int lcr_id,
 	return -1;
     }
 
-    /* Search for gw address */
-    res = (struct gw_info *)bsearch(&src_addr, &(gws[1]), gws[0].ip_addr,
+    /* Search for gw ip address */
+    gw.ip_addr = src_addr;
+    res = (struct gw_info *)bsearch(&gw, &(gws[1]), gws[0].ip_addr,
 				    sizeof(struct gw_info), comp_gws);
 
     /* Store flags and return result */
@@ -2092,7 +2090,8 @@ static int do_from_gw(struct sip_msg* _m, unsigned int lcr_id,
 
 
 /*
- * Checks if request comes from a gateway taking src_address from reques.
+ * Checks if request comes from ip address of a gateway taking source
+ * address from request.
  */
 static int from_gw_1(struct sip_msg* _m, char* _lcr_id, char* _s2)
 {
@@ -2118,7 +2117,8 @@ static int from_gw_1(struct sip_msg* _m, char* _lcr_id, char* _s2)
 
 
 /*
- * Checks if request comes from a gateway taking source address from param.
+ * Checks if request comes from ip address of a gateway taking source
+ * address from param.
  */
 static int from_gw_2(struct sip_msg* _m, char* _lcr_id, char* _addr)
 {
@@ -2163,7 +2163,8 @@ static int from_gw_2(struct sip_msg* _m, char* _lcr_id, char* _addr)
 
 
 /*
- * Checks if request comes from any gateway taking source address from request.
+ * Checks if request comes from ip address of any gateway taking source
+ * address from request.
  */
 static int from_any_gw_0(struct sip_msg* _m, char* _s1, char* _s2)
 {
@@ -2181,7 +2182,8 @@ static int from_any_gw_0(struct sip_msg* _m, char* _s1, char* _s2)
 
 
 /*
- * Checks if request comes from a gateway taking source address from param.
+ * Checks if request comes from ip address of a a gateway taking source
+ * address from param.
  */
 static int from_any_gw_1(struct sip_msg* _m, char* _addr, char* _s2)
 {
@@ -2221,12 +2223,12 @@ static int from_any_gw_1(struct sip_msg* _m, char* _addr, char* _s2)
 
 
 /*
- * Checks if in-dialog request goes to gateway
+ * Checks if in-dialog request goes to ip address of a gateway.
  */
 static int do_to_gw(struct sip_msg* _m, unsigned int lcr_id,
 		    unsigned int dst_addr)
 {
-    struct gw_info *res, *gws;
+    struct gw_info *res, gw, *gws;
 
     gws = gw_pt[lcr_id];
 
@@ -2236,8 +2238,9 @@ static int do_to_gw(struct sip_msg* _m, unsigned int lcr_id,
 	return -1;
     }
 
-    /* Search for gw address */
-    res = (struct gw_info *)bsearch(&dst_addr, &(gws[1]), gws[0].ip_addr,
+    /* Search for gw ip address */
+    gw.ip_addr = dst_addr;
+    res = (struct gw_info *)bsearch(&gw, &(gws[1]), gws[0].ip_addr,
 				    sizeof(struct gw_info), comp_gws);
 
     /* Return result */
@@ -2252,7 +2255,8 @@ static int do_to_gw(struct sip_msg* _m, unsigned int lcr_id,
 
 
 /*
- * Checks if request goes to a gateway taking destination address from request.
+ * Checks if request goes to ip address of a gateway taking destination
+ * address from Request URI.
  */
 static int to_gw_1(struct sip_msg* _m, char* _lcr_id, char* _s2)
 {
@@ -2294,7 +2298,8 @@ static int to_gw_1(struct sip_msg* _m, char* _lcr_id, char* _s2)
 
 
 /*
- * Checks if request goes to a gateway, taking destination address from param.
+ * Checks if request goes to ip address of a gateway taking destination
+ * address from param.
  */
 static int to_gw_2(struct sip_msg* _m, char* _lcr_id, char* _addr)
 {
@@ -2339,7 +2344,8 @@ static int to_gw_2(struct sip_msg* _m, char* _lcr_id, char* _addr)
 
 
 /*
- * Checks if request goes to any gateway taking dst_addr from request.
+ * Checks if request goes to ip address of any gateway taking destination
+ * address from Request-URI.
  */
 static int to_any_gw_0(struct sip_msg* _m, char* _s1, char* _s2)
 {
@@ -2364,6 +2370,7 @@ static int to_any_gw_0(struct sip_msg* _m, char* _s1, char* _s2)
 	dst_addr = ip->u.addr32[0];
     }
 
+    /* Do test */
     for (i = 1; i <= lcr_count_param; i++) {
 	if (do_to_gw(_m, i, dst_addr) == 1) {
 	    return i;
@@ -2374,7 +2381,8 @@ static int to_any_gw_0(struct sip_msg* _m, char* _s1, char* _s2)
 
 
 /*
- * Checks if request goes to any gateway taking dst_addr from param.
+ * Checks if request goes to ip address of any gateway taking destination
+ * address from param.
  */
 static int to_any_gw_1(struct sip_msg* _m, char* _addr, char* _s2)
 {




More information about the sr-dev mailing list