[sr-dev] git:master:0a6a750a: permissions: trusted_cleanup_interval

Victor Seva linuxmaniac at torreviejawireless.org
Mon Nov 15 10:35:58 CET 2021


Module: kamailio
Branch: master
Commit: 0a6a750a96b620b3024acd391436a94def3133e1
URL: https://github.com/kamailio/kamailio/commit/0a6a750a96b620b3024acd391436a94def3133e1

Author: Victor Seva <linuxmaniac at torreviejawireless.org>
Committer: Victor Seva <linuxmaniac at torreviejawireless.org>
Date: 2021-11-15T10:35:54+01:00

permissions: trusted_cleanup_interval

cleanup old data of trusted hash_table by timer function.

---

Modified: src/modules/permissions/permissions.c
Modified: src/modules/permissions/permissions.h
Modified: src/modules/permissions/trusted.c

---

Diff:  https://github.com/kamailio/kamailio/commit/0a6a750a96b620b3024acd391436a94def3133e1.diff
Patch: https://github.com/kamailio/kamailio/commit/0a6a750a96b620b3024acd391436a94def3133e1.patch

---

diff --git a/src/modules/permissions/permissions.c b/src/modules/permissions/permissions.c
index 12ab2d889a..d5655206e4 100644
--- a/src/modules/permissions/permissions.c
+++ b/src/modules/permissions/permissions.c
@@ -61,6 +61,7 @@ static char* perm_deny_suffix = ".deny";
 /* for allow_trusted and allow_address function */
 str perm_db_url = {NULL, 0};                    /* Don't connect to the database by default */
 int perm_reload_delta = 5;
+int perm_trusted_table_interval = 60;
 
 /* for allow_trusted function */
 int perm_db_mode = DISABLE_CACHE;               /* Database usage mode: 0=no cache, 1=cache */
@@ -188,6 +189,7 @@ static param_export_t params[] = {
 	{"max_subnets",        PARAM_INT, &_perm_max_subnets    },
 	{"load_backends",      PARAM_INT, &_perm_load_backends  },
 	{"reload_delta",       PARAM_INT, &perm_reload_delta    },
+	{"trusted_cleanup_interval", PARAM_INT, &perm_trusted_table_interval },
 	{0, 0, 0}
 };
 
diff --git a/src/modules/permissions/permissions.h b/src/modules/permissions/permissions.h
index 2a417ffd58..c08666a1c0 100644
--- a/src/modules/permissions/permissions.h
+++ b/src/modules/permissions/permissions.h
@@ -60,6 +60,7 @@ extern str perm_mask_col;      /* Name of mask column */
 extern str perm_port_col;      /* Name of port column */
 extern int perm_peer_tag_mode; /* Matching mode */
 extern int perm_reload_delta;  /* seconds between RPC reloads */
+extern int perm_trusted_table_interval; /* interval of timer to clean old trusted data */
 
 /* backends to be loaded */
 #define PERM_LOAD_ADDRESSDB	(1<<0)
diff --git a/src/modules/permissions/trusted.c b/src/modules/permissions/trusted.c
index 7714a32461..49e871a125 100644
--- a/src/modules/permissions/trusted.c
+++ b/src/modules/permissions/trusted.c
@@ -166,6 +166,7 @@ int reload_trusted_table(void)
 	return 1;
 }
 
+void perm_ht_timer(unsigned int ticks, void *);
 
 /*
  * Initialize data structures
@@ -224,6 +225,9 @@ int init_trusted(void)
 			goto error;
 		}
 
+		if(register_timer(perm_ht_timer, NULL, perm_trusted_table_interval) < 0)
+			goto error;
+
 		perm_dbf.close(perm_db_handle);
 		perm_db_handle = 0;
 	}
@@ -280,6 +284,22 @@ int init_child_trusted(int rank)
 }
 
 
+void perm_ht_timer(unsigned int ticks, void *param) {
+	if(perm_rpc_reload_time == NULL)
+		return;
+
+	if(*perm_rpc_reload_time != 0
+			&& *perm_rpc_reload_time > time(NULL) - perm_trusted_table_interval)
+			return;
+
+	LM_DBG("cleaning old trusted table\n");
+	if (*perm_trust_table == perm_trust_table_1) {
+		empty_hash_table(perm_trust_table_2);
+	} else {
+		empty_hash_table(perm_trust_table_1);
+	}
+}
+
 /*
  * Close connections and release memory
  */




More information about the sr-dev mailing list