Browse code

permissions: trusted_cleanup_interval

cleanup old data of trusted hash_table by timer function.

Victor Seva authored on 04/11/2021 14:11:12
Showing 3 changed files
... ...
@@ -61,6 +61,7 @@ static char* perm_deny_suffix = ".deny";
61 61
 /* for allow_trusted and allow_address function */
62 62
 str perm_db_url = {NULL, 0};                    /* Don't connect to the database by default */
63 63
 int perm_reload_delta = 5;
64
+int perm_trusted_table_interval = 60;
64 65
 
65 66
 /* for allow_trusted function */
66 67
 int perm_db_mode = DISABLE_CACHE;               /* Database usage mode: 0=no cache, 1=cache */
... ...
@@ -188,6 +189,7 @@ static param_export_t params[] = {
188 189
 	{"max_subnets",        PARAM_INT, &_perm_max_subnets    },
189 190
 	{"load_backends",      PARAM_INT, &_perm_load_backends  },
190 191
 	{"reload_delta",       PARAM_INT, &perm_reload_delta    },
192
+	{"trusted_cleanup_interval", PARAM_INT, &perm_trusted_table_interval },
191 193
 	{0, 0, 0}
192 194
 };
193 195
 
... ...
@@ -60,6 +60,7 @@ extern str perm_mask_col;      /* Name of mask column */
60 60
 extern str perm_port_col;      /* Name of port column */
61 61
 extern int perm_peer_tag_mode; /* Matching mode */
62 62
 extern int perm_reload_delta;  /* seconds between RPC reloads */
63
+extern int perm_trusted_table_interval; /* interval of timer to clean old trusted data */
63 64
 
64 65
 /* backends to be loaded */
65 66
 #define PERM_LOAD_ADDRESSDB	(1<<0)
... ...
@@ -166,6 +166,7 @@ int reload_trusted_table(void)
166 166
 	return 1;
167 167
 }
168 168
 
169
+void perm_ht_timer(unsigned int ticks, void *);
169 170
 
170 171
 /*
171 172
  * Initialize data structures
... ...
@@ -224,6 +225,9 @@ int init_trusted(void)
224 225
 			goto error;
225 226
 		}
226 227
 
228
+		if(register_timer(perm_ht_timer, NULL, perm_trusted_table_interval) < 0)
229
+			goto error;
230
+
227 231
 		perm_dbf.close(perm_db_handle);
228 232
 		perm_db_handle = 0;
229 233
 	}
... ...
@@ -280,6 +284,22 @@ int init_child_trusted(int rank)
280 284
 }
281 285
 
282 286
 
287
+void perm_ht_timer(unsigned int ticks, void *param) {
288
+	if(perm_rpc_reload_time == NULL)
289
+		return;
290
+
291
+	if(*perm_rpc_reload_time != 0
292
+			&& *perm_rpc_reload_time > time(NULL) - perm_trusted_table_interval)
293
+			return;
294
+
295
+	LM_DBG("cleaning old trusted table\n");
296
+	if (*perm_trust_table == perm_trust_table_1) {
297
+		empty_hash_table(perm_trust_table_2);
298
+	} else {
299
+		empty_hash_table(perm_trust_table_1);
300
+	}
301
+}
302
+
283 303
 /*
284 304
  * Close connections and release memory
285 305
  */