소스 검색

modules/lcr: added lcr.defunct_gw rpc command

Juha Heinanen 13 년 전
부모
커밋
1c6fed07a1
5개의 변경된 파일100개의 추가작업 그리고 5개의 파일을 삭제
  1. 17 0
      modules/lcr/README
  2. 19 0
      modules/lcr/doc/lcr_admin.xml
  3. 32 0
      modules/lcr/lcr_mod.c
  4. 2 3
      modules/lcr/lcr_mod.h
  5. 30 2
      modules/lcr/lcr_rpc.c

+ 17 - 0
modules/lcr/README

@@ -78,6 +78,7 @@ Juha Heinanen
               5.1. lcr.reload
               5.2. lcr.dump_gws
               5.3. lcr.dump_rules
+              5.4. lcr.defunct_gw
 
         6. Known Limitations
 
@@ -131,6 +132,7 @@ Juha Heinanen
    1.46. lcr.reload RPC example
    1.47. lcr.dump_gws RPC example
    1.48. lcr.dump_rules RPC example
+   1.49. lcr.defunct_gw RPC example
 
 Chapter 1. Admin Guide
 
@@ -197,6 +199,7 @@ Chapter 1. Admin Guide
         5.1. lcr.reload
         5.2. lcr.dump_gws
         5.3. lcr.dump_rules
+        5.4. lcr.defunct_gw
 
    6. Known Limitations
 
@@ -971,6 +974,7 @@ if (to_any_gw("192.55.66.2", 1)) {
    5.1. lcr.reload
    5.2. lcr.dump_gws
    5.3. lcr.dump_rules
+   5.4. lcr.defunct_gw
 
 5.1. lcr.reload
 
@@ -1002,6 +1006,19 @@ if (to_any_gw("192.55.66.2", 1)) {
    Example 1.48. lcr.dump_rules RPC example
                 $ sercmd lcr.dump_rules
 
+5.4. lcr.defunct_gw
+
+   Defuncts gateway loaded into memory for a period of time (seconds)
+   without a need to store gateway's defunct value into database and
+   reload the tables.
+
+   Name: lcr.defunct_gw
+
+   Parameters: lcr_id gw_id period
+
+   Example 1.49. lcr.defunct_gw RPC example
+                $ sercmd lcr.defunct_gw 1 4 120
+
 6. Known Limitations
 
    In-memory LCR rules and gw tables are switched by two consecutive

+ 19 - 0
modules/lcr/doc/lcr_admin.xml

@@ -1324,6 +1324,25 @@ if (to_any_gw("192.55.66.2", 1)) {
 		</programlisting>
 		</example>
 		</section>
+
+		<section>
+		<title><function>lcr.defunct_gw</function></title>
+		<para>
+			Defuncts gateway loaded into memory for a period of
+			time (seconds) without a need to store gateway's
+			defunct	value into database and reload the tables.
+		</para>
+		<para>
+		Name: <emphasis>lcr.defunct_gw</emphasis>
+		</para>
+		<para>Parameters: <emphasis>lcr_id gw_id period</emphasis></para>
+		<example>
+		<title><function>lcr.defunct_gw</function> RPC example</title>
+		<programlisting  format="linespecific">
+		$ sercmd lcr.defunct_gw 1 4 120
+		</programlisting>
+		</example>
+		</section>
 	</section>
 	<section>
 	<title>Known Limitations</title>

+ 32 - 0
modules/lcr/lcr_mod.c

@@ -2048,6 +2048,38 @@ static int defunct_gw(struct sip_msg* _m, char *_defunct_period, char *_s2)
 }    
 
 
+/*
+ * Defunct given gw in given lcr until time period given as argument has passed.
+ */
+int rpc_defunct_gw(unsigned int lcr_id, unsigned int gw_id, unsigned int period)
+{
+    struct gw_info *gws;
+    unsigned int until, i;
+
+    if ((lcr_id < 1) || (lcr_id > lcr_count_param)) {
+	LM_ERR("invalid lcr_id value <%u>\n", lcr_id);
+	return 0;
+    }
+
+    until = time((time_t *)NULL) + period;
+
+    LM_DBG("defuncting gw <lcr_id/gw_id>=<%u/%u> for %u seconds until %d\n",
+	   lcr_id, gw_id, period, until);
+
+    gws = gw_pt[lcr_id];
+    for (i = 1; i <= gws[0].ip_addr.u.addr32[0]; i++) {
+	if (gws[i].gw_id == gw_id) {
+	    gws[i].defunct_until = until;
+	    return 1;
+	}
+    }
+    
+    LM_ERR("gateway with id <%u> not found\n", gw_id);
+
+    return 0;
+}
+
+
 /*
  * When called first time, rewrites scheme, host, port, and
  * transport parts of R-URI based on first gw_uri_avp value, which is then

+ 2 - 3
modules/lcr/lcr_mod.h

@@ -110,8 +110,7 @@ extern gen_lock_t *reload_lock;
 extern struct gw_info **gw_pt;
 extern struct rule_info ***rule_pt;
 
-int  mi_print_gws(struct mi_node* rpl);
-int  mi_print_lcrs(struct mi_node* rpl);
-int  reload_tables();
+extern int reload_tables();
+extern int rpc_defunct_gw(unsigned int, unsigned int, unsigned int);
 
 #endif /* LCR_MOD_H */

+ 30 - 2
modules/lcr/lcr_rpc.c

@@ -67,6 +67,8 @@ static void dump_gws(rpc_t* rpc, void* c)
     str gw_name, hostname, params;
     str prefix, tag;
     struct gw_info *gws;
+    char buf[INT2STR_MAX_LEN], *start;
+    int len;
 
     for (j = 1; j <= lcr_count_param; j++) {
 
@@ -132,12 +134,14 @@ static void dump_gws(rpc_t* rpc, void* c)
 	    prefix.len=gws[i].prefix_len;
 	    tag.s=gws[i].tag;
 	    tag.len=gws[i].tag_len;
-	    rpc->struct_add(st, "dSSdd",
+	    start = int2strbuf(gws[i].defunct_until, &(buf[0]), INT2STR_MAX_LEN,
+			       &len);
+	    rpc->struct_add(st, "dSSds",
 			    "strip",  gws[i].strip,
 			    "prefix", &prefix,
 			    "tag",    &tag,
 			    "flags",  gws[i].flags,
-			    "defunct_until",  &gws[i].defunct_until
+			    "defunct_until",  start
 			    );
 	}
     }
@@ -199,9 +203,33 @@ static void dump_rules(rpc_t* rpc, void* c)
 }
 
 
+static const char* defunct_gw_doc[2] = {
+    "Defunct gateway until speficied time (Unix timestamp).",
+    0
+};
+
+
+static void defunct_gw(rpc_t* rpc, void* c)
+{
+    unsigned int lcr_id, gw_id, until;
+
+    if (rpc->scan(c, "ddd", &lcr_id, &gw_id, &until) < 3) {
+	rpc->fault(c, 400, "lcr_id, gw_id, and timestamp parameters required");
+	return;
+    }
+
+    if (rpc_defunct_gw(lcr_id, gw_id, until) == 0) {
+	rpc->fault(c, 400, "parameter value error (see syslog)");
+    }
+    
+    return;
+}
+
+
 rpc_export_t lcr_rpc[] = {
     {"lcr.reload", reload, reload_doc, 0},
     {"lcr.dump_gws", dump_gws, dump_gws_doc, 0},
     {"lcr.dump_rules", dump_rules, dump_rules_doc, 0},
+    {"lcr.defunct_gw", defunct_gw, defunct_gw_doc, 0},
     {0, 0, 0, 0}
 };