[sr-dev] git:master: modules/lcr: minor fix and improvement

Juha Heinanen jh at tutpro.com
Sat Sep 25 08:38:59 CEST 2010


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

Author: Juha Heinanen <jh at tutpro.com>
Committer: Juha Heinanen <jh at tutpro.com>
Date:   Sat Sep 25 09:32:35 2010 +0300

modules/lcr: minor fix and improvement
- RPC command lcr.reload caused db tables to be loaded in some
  situations more than once.
- If defunct column value of a gw is max UNIX timestamp value 4294967295
  or greater, gw is considered currently unused and is not loaded into
  memory at all.

---

 modules/lcr/README            |    4 +++-
 modules/lcr/doc/lcr_admin.xml |    3 +++
 modules/lcr/lcr_mod.c         |   41 ++++++++++++++++++++++-------------------
 modules/lcr/lcr_rpc.c         |    7 ++-----
 4 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/modules/lcr/README b/modules/lcr/README
index 5a4a31a..44b9f1f 100644
--- a/modules/lcr/README
+++ b/modules/lcr/README
@@ -473,7 +473,9 @@ modparam("lcr", "flags_column", "gw_flags")
 3.15. defunct_column (string)
 
    Name of the column holding UNIX timestamp telling the time until which
-   the gw is considered as defunct.
+   the gw is considered as defunct. If timestamp value is 4294967295 (=
+   max UNIX timestamp value) or greater, gw is considered currently unused
+   and is not loaded into memory at all.
 
    Default value is “defunct”.
 
diff --git a/modules/lcr/doc/lcr_admin.xml b/modules/lcr/doc/lcr_admin.xml
index 764392f..ab0b45e 100644
--- a/modules/lcr/doc/lcr_admin.xml
+++ b/modules/lcr/doc/lcr_admin.xml
@@ -438,6 +438,9 @@ modparam("lcr", "flags_column", "gw_flags")
 		<para>
 		Name of the column holding UNIX timestamp telling the
 		time until which the gw is considered as defunct.
+		If timestamp value is 4294967295 (= max UNIX timestamp value)
+		or greater, gw is considered currently unused and is not
+		loaded into memory at all.
 		</para>
 		<para>
 		<emphasis>
diff --git a/modules/lcr/lcr_mod.c b/modules/lcr/lcr_mod.c
index 3d74975..6f705e1 100644
--- a/modules/lcr/lcr_mod.c
+++ b/modules/lcr/lcr_mod.c
@@ -1110,10 +1110,29 @@ int reload_tables()
 	    goto err;
 	}
 
-	null_gw_ip_addr = 0;
+	null_gw_ip_addr = gw_cnt = 0;
 
 	for (i = 0; i < RES_ROW_N(res); i++) {
 	    row = RES_ROWS(res) + i;
+	    if ((VAL_NULL(ROW_VALUES(row) + 11) == 1) ||
+		(VAL_TYPE(ROW_VALUES(row) + 11) != DB1_INT)) {
+		LM_ERR("lcr_gw id at row <%u> is null or not int\n", i);
+		goto err;
+	    }
+	    gw_id = (unsigned int)VAL_INT(ROW_VALUES(row) + 11);
+	    if (VAL_NULL(ROW_VALUES(row) + 10)) {
+		defunct_until = 0;
+	    } else {
+		if (VAL_TYPE(ROW_VALUES(row) + 10) != DB1_INT) {
+		    LM_ERR("lcr_gw defunct at row <%u> is not int\n", i);
+		    goto err;
+		}
+		defunct_until = (unsigned int)VAL_INT(ROW_VALUES(row) + 10);
+		if (defunct_until > 4294967294UL) {
+		    LM_DBG("skipping disabled gw <%u>\n", gw_id);
+		    continue;
+		}
+	    }
 	    if (!VAL_NULL(ROW_VALUES(row)) &&
 		(VAL_TYPE(ROW_VALUES(row)) != DB1_STRING)) {
 		LM_ERR("lcr_gw gw_name at row <%u> is not null or string\n", i);
@@ -1277,22 +1296,8 @@ int reload_tables()
 		goto err;
 	    }
 	    flags = (unsigned int)VAL_INT(ROW_VALUES(row) + 9);
-	    if (VAL_NULL(ROW_VALUES(row) + 10)) {
-		defunct_until = 0;
-	    } else {
-		if (VAL_TYPE(ROW_VALUES(row) + 10) != DB1_INT) {
-		    LM_ERR("lcr_gw defunct at row <%u> is not int\n", i);
-		    goto err;
-		}
-		defunct_until = (unsigned int)VAL_INT(ROW_VALUES(row) + 10);
-	    }
-	    if ((VAL_NULL(ROW_VALUES(row) + 11) == 1) ||
-		(VAL_TYPE(ROW_VALUES(row) + 11) != DB1_INT)) {
-		LM_ERR("lcr_gw id at row <%u> is null or not int\n", i);
-		goto err;
-	    }
-	    gw_id = (unsigned int)VAL_INT(ROW_VALUES(row) + 11);
-	    if (!insert_gw(gws, i + 1, gw_id, gw_name, gw_name_len,
+	    gw_cnt++;
+	    if (!insert_gw(gws, gw_cnt, gw_id, gw_name, gw_name_len,
 			   scheme, (unsigned int)ip_addr.s_addr, port,
 			   transport, params, params_len, hostname,
 			   hostname_len, ip_string, strip, tag, tag_len, flags,
@@ -1303,8 +1308,6 @@ int reload_tables()
 
 	lcr_dbf.free_result(dbh, res);
 	res = NULL;
-    
-	gw_cnt = i;
 
 	qsort(&(gws[1]), gw_cnt, sizeof(struct gw_info), comp_gws);
 	gws[0].ip_addr = gw_cnt;
diff --git a/modules/lcr/lcr_rpc.c b/modules/lcr/lcr_rpc.c
index f19297b..2f0d43f 100644
--- a/modules/lcr/lcr_rpc.c
+++ b/modules/lcr/lcr_rpc.c
@@ -46,12 +46,9 @@ static const char* reload_doc[2] = {
 
 static void reload(rpc_t* rpc, void* c)
 {
-    int i;
     lock_get(reload_lock);
-    for (i = 1; i <= lcr_count_param; i++) {
-	if (reload_tables(i) != 1)
-	    rpc->fault(c, 500, "LCR Module Reload Failed");
-    }
+    if (reload_tables() != 1)
+	rpc->fault(c, 500, "LCR Module Reload Failed");
     lock_release(reload_lock);
 }
 




More information about the sr-dev mailing list