Module: kamailio Branch: master Commit: 18b7337ad4b868a84d4cb70abb37a3d4ba16a428 URL: https://github.com/kamailio/kamailio/commit/18b7337ad4b868a84d4cb70abb37a3d4...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2021-09-10T11:12:01+02:00
usrloc: added db_clean_tcp parameter
- if set, tcp contacts are deleted before loading location table at start time - it is very common that end points use only tcp client connections, on restart those connections are lost and corresponding contacts are useless
---
Modified: src/modules/usrloc/doc/usrloc_admin.xml Modified: src/modules/usrloc/udomain.c Modified: src/modules/usrloc/usrloc_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/18b7337ad4b868a84d4cb70abb37a3d4... Patch: https://github.com/kamailio/kamailio/commit/18b7337ad4b868a84d4cb70abb37a3d4...
---
diff --git a/src/modules/usrloc/doc/usrloc_admin.xml b/src/modules/usrloc/doc/usrloc_admin.xml index 25124abcc1..66dae44913 100644 --- a/src/modules/usrloc/doc/usrloc_admin.xml +++ b/src/modules/usrloc/doc/usrloc_admin.xml @@ -1517,6 +1517,29 @@ modparam("usrloc", "load_rank", 1) </example> </section>
+ <section id="usrloc.p.db_clean_tcp"> + <title><varname>db_clean_tcp</varname> (int)</title> + <para> + If set to 1, when &kamailio; starts it removes the contacts with + transport TCP, TLS or WSS, no longer loading them. Useful when + end points do not listen for incoming connections on contact address, + which is quite common (end point use only tcp client connections). + On restart, connections are lost, therefore the corresponding + contact records become useless. + </para> + <para> + Default value is <quote>0</quote> (do not clean tcp contacts). + </para> + <example> + <title><varname>db_clean_tcp</varname> parameter usage</title> + <programlisting format="linespecific"> +... +modparam("usrloc", "db_clean_tcp", 1) +... + </programlisting> + </example> + </section> + </section>
<section> diff --git a/src/modules/usrloc/udomain.c b/src/modules/usrloc/udomain.c index 204ddfd29f..4025cc549e 100644 --- a/src/modules/usrloc/udomain.c +++ b/src/modules/usrloc/udomain.c @@ -45,6 +45,7 @@ #include "urecord.h"
extern int ul_rm_expired_delay; +extern int ul_db_clean_tcp;
#ifdef STATISTICS static char *build_stat_name( str* domain, char *var_name) @@ -372,6 +373,52 @@ static inline ucontact_info_t* dbrow2info(db_val_t *vals, str *contact, int rcon return &ci; }
+/*! + * \brief Delete all location records with tcp connection + * + * \param _c database connection + * \param _d loaded domain + * \return 0 on success, -1 on failure + */ +int uldb_delete_tcp_records(db1_con_t* _c, udomain_t* _d) +{ + db_key_t keys[2]; + db_op_t ops[2]; + db_val_t vals[2]; + int nr_keys = 0; + + LM_DBG("delete location tcp records\n"); + + keys[nr_keys] = &ul_con_id_col;; + ops[nr_keys] = OP_GT; + vals[nr_keys].type = DB1_INT; + vals[nr_keys].nul = 0; + vals[nr_keys].val.int_val = 0; + nr_keys++; + + if (ul_db_srvid != 0) { + keys[nr_keys] = &ul_srv_id_col; + ops[nr_keys] = OP_EQ; + vals[nr_keys].type = DB1_INT; + vals[nr_keys].nul = 0; + vals[nr_keys].val.int_val = server_id; + nr_keys++; + } + + if (ul_dbf.use_table(_c, _d->name) < 0) { + LM_ERR("sql use_table failed\n"); + return -1; + } + + + if (ul_dbf.delete(_c, keys, ops, vals, nr_keys) < 0) { + LM_ERR("deleting from database failed\n"); + return -1; + } + + return 0; +} +
/*! * \brief Load all records from a udomain @@ -400,6 +447,10 @@ int preload_udomain(db1_con_t* _c, udomain_t* _d) urecord_t* r; ucontact_t* c;
+ if(ul_db_clean_tcp!=0) { + uldb_delete_tcp_records(_c, _d); + } + columns[0] = &ul_user_col; columns[1] = &ul_contact_col; columns[2] = &ul_expires_col; diff --git a/src/modules/usrloc/usrloc_mod.c b/src/modules/usrloc/usrloc_mod.c index 733c16a3ff..5668586733 100644 --- a/src/modules/usrloc/usrloc_mod.c +++ b/src/modules/usrloc/usrloc_mod.c @@ -176,6 +176,7 @@ int ul_desc_time_order = 0; /*!< By default do not enable timestamp ordering int ul_handle_lost_tcp = 0; /*!< By default do not remove contacts before expiration time */ int ul_close_expired_tcp = 0; /*!< By default do not close TCP connections for expired contacts */ int ul_skip_remote_socket = 0; /*!< By default do not skip remote socket */ +int ul_db_clean_tcp = 0; /*!< Clean TCP/TLS/WSS contacts in DB before loading records */
int ul_fetch_rows = 2000; /*!< number of rows to fetch from result */ int ul_hash_size = 10; @@ -263,6 +264,7 @@ static param_export_t params[] = { {"ka_loglevel", PARAM_INT, &ul_ka_loglevel}, {"ka_logmsg", PARAM_STR, &ul_ka_logmsg}, {"load_rank", PARAM_INT, &ul_load_rank}, + {"db_clean_tcp", PARAM_INT, &ul_db_clean_tcp}, {0, 0, 0} };