diff --git a/src/modules/usrloc/doc/usrloc_admin.xml b/src/modules/usrloc/doc/usrloc_admin.xml index 25124abcc17..66dae449130 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) +
+ <varname>db_clean_tcp</varname> (int) + + 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. + + + Default value is 0 (do not clean tcp contacts). + + + <varname>db_clean_tcp</varname> parameter usage + +... +modparam("usrloc", "db_clean_tcp", 1) +... + + +
+
diff --git a/src/modules/usrloc/udomain.c b/src/modules/usrloc/udomain.c index 204ddfd29fd..4025cc549eb 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 733c16a3ff7..56685867335 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} };