Browse code

dispatcher: check reload delta in functions building new routing structure

(cherry picked from commit 76c273ecaa76f031ce9892acd895b4eacf4de17e)

Daniel-Constantin Mierla authored on 24/01/2022 10:32:31
Showing 1 changed files
... ...
@@ -945,6 +945,16 @@ static int ds_warn_fixup(void **param, int param_no)
945 945
 
946 946
 static int ds_reload(sip_msg_t *msg)
947 947
 {
948
+	if(ds_rpc_reload_time==NULL) {
949
+		LM_ERR("not ready for reload\n");
950
+		return -1;
951
+	}
952
+	if(*ds_rpc_reload_time!=0 && *ds_rpc_reload_time > time(NULL) - ds_reload_delta) {
953
+		LM_ERR("ongoing reload\n");
954
+		return -1;
955
+	}
956
+	*ds_rpc_reload_time = time(NULL);
957
+
948 958
 	if(!ds_db_url.s) {
949 959
 		if(ds_load_list(dslistfile) != 0)
950 960
 			LM_ERR("Error reloading from list\n");
... ...
@@ -1801,6 +1811,18 @@ static void dispatcher_rpc_add(rpc_t *rpc, void *ctx)
1801 1811
 	str dest;
1802 1812
 	str attrs = STR_NULL;
1803 1813
 
1814
+	if(ds_rpc_reload_time==NULL) {
1815
+		LM_ERR("Not ready for rebuilding destinations list\n");
1816
+		rpc->fault(ctx, 500, "Not ready for reload");
1817
+		return;
1818
+	}
1819
+	if(*ds_rpc_reload_time!=0 && *ds_rpc_reload_time > time(NULL) - ds_reload_delta) {
1820
+		LM_ERR("ongoing reload\n");
1821
+		rpc->fault(ctx, 500, "Ongoing reload");
1822
+		return;
1823
+	}
1824
+	*ds_rpc_reload_time = time(NULL);
1825
+
1804 1826
 	flags = 0;
1805 1827
 
1806 1828
 	nparams = rpc->scan(ctx, "dS*dS", &group, &dest, &flags, &attrs);
... ...
@@ -1832,6 +1854,18 @@ static void dispatcher_rpc_remove(rpc_t *rpc, void *ctx)
1832 1854
 	int group;
1833 1855
 	str dest;
1834 1856
 
1857
+	if(ds_rpc_reload_time==NULL) {
1858
+		LM_ERR("Not ready for rebuilding destinations list\n");
1859
+		rpc->fault(ctx, 500, "Not ready for reload");
1860
+		return;
1861
+	}
1862
+	if(*ds_rpc_reload_time!=0 && *ds_rpc_reload_time > time(NULL) - ds_reload_delta) {
1863
+		LM_ERR("ongoing reload\n");
1864
+		rpc->fault(ctx, 500, "Ongoing reload");
1865
+		return;
1866
+	}
1867
+	*ds_rpc_reload_time = time(NULL);
1868
+
1835 1869
 	if(rpc->scan(ctx, "dS", &group, &dest) < 2) {
1836 1870
 		rpc->fault(ctx, 500, "Invalid Parameters");
1837 1871
 		return;