Browse code

Merge 7ce815c2612d6277b55aabf6519c70a4ecec6502 into b3e8d03038402dec78b4845255f34862407983c9

Victor Seva authored on 14/11/2021 19:26:44 • GitHub committed on 14/11/2021 19:26:44
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)
... ...
@@ -59,7 +59,6 @@ int reload_trusted_table(void)
59 59
 	db_val_t* val;
60 60
 
61 61
 	struct trusted_list **new_hash_table;
62
-	struct trusted_list **old_hash_table;
63 62
 	int i;
64 63
 	int priority;
65 64
 
... ...
@@ -160,15 +159,14 @@ int reload_trusted_table(void)
160 159
 
161 160
 	perm_dbf.free_result(perm_db_handle, res);
162 161
 
163
-	old_hash_table = *perm_trust_table;
164 162
 	*perm_trust_table = new_hash_table;
165
-	empty_hash_table(old_hash_table);
166 163
 
167 164
 	LM_DBG("trusted table reloaded successfully.\n");
168 165
 
169 166
 	return 1;
170 167
 }
171 168
 
169
+void perm_ht_timer(unsigned int ticks, void *);
172 170
 
173 171
 /*
174 172
  * Initialize data structures
... ...
@@ -227,6 +225,9 @@ int init_trusted(void)
227 225
 			goto error;
228 226
 		}
229 227
 
228
+		if(register_timer(perm_ht_timer, NULL, perm_trusted_table_interval) < 0)
229
+			goto error;
230
+
230 231
 		perm_dbf.close(perm_db_handle);
231 232
 		perm_db_handle = 0;
232 233
 	}
... ...
@@ -283,6 +284,22 @@ int init_child_trusted(int rank)
283 284
 }
284 285
 
285 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
+
286 303
 /*
287 304
  * Close connections and release memory
288 305
  */