[sr-dev] git:master: usrloc: detect lost tcp connnections on timer and set associated contact as expired
Daniel-Constantin Mierla
miconda at gmail.com
Wed Sep 4 09:58:12 CEST 2013
Module: sip-router
Branch: master
Commit: 72996942662b944b74e6632e1670c989402bf8af
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=72996942662b944b74e6632e1670c989402bf8af
Author: Vitaliy Aleksandrov <vitalik.voip at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: Wed Sep 4 09:56:28 2013 +0200
usrloc: detect lost tcp connnections on timer and set associated contact as expired
- new module parameter to control this feature: handle_lost_tcp
- at this moment it is not implemented for db only mode
---
modules/usrloc/ucontact.c | 1 +
modules/usrloc/ul_mod.c | 6 ++++++
modules/usrloc/ul_mod.h | 1 +
modules/usrloc/urecord.c | 32 +++++++++++++++++++++++++++++++-
modules/usrloc/usrloc.h | 2 ++
5 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/modules/usrloc/ucontact.c b/modules/usrloc/ucontact.c
index d1ae1f3..e7f8938 100644
--- a/modules/usrloc/ucontact.c
+++ b/modules/usrloc/ucontact.c
@@ -135,6 +135,7 @@ ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact, ucontact_info_t* _
c->reg_id = _ci->reg_id;
c->last_modified = _ci->last_modified;
c->last_keepalive = _ci->last_modified;
+ c->tcpconn_id = _ci->tcpconn_id;
#ifdef WITH_XAVP
ucontact_xavp_store(c);
#endif
diff --git a/modules/usrloc/ul_mod.c b/modules/usrloc/ul_mod.c
index 08126fd..7d88f67 100644
--- a/modules/usrloc/ul_mod.c
+++ b/modules/usrloc/ul_mod.c
@@ -161,6 +161,7 @@ int timer_interval = 60; /*!< Timer interval in seconds */
int db_mode = 0; /*!< Database sync scheme: 0-no db, 1-write through, 2-write back, 3-only db */
int use_domain = 0; /*!< Whether usrloc should use domain part of aor */
int desc_time_order = 0; /*!< By default do not enable timestamp ordering */
+int handle_lost_tcp = 0;
int ul_fetch_rows = 2000; /*!< number of rows to fetch from result */
int ul_hash_size = 9;
@@ -214,6 +215,7 @@ static param_export_t params[] = {
{"fetch_rows", INT_PARAM, &ul_fetch_rows },
{"hash_size", INT_PARAM, &ul_hash_size },
{"nat_bflag", INT_PARAM, &nat_bflag },
+ {"handle_lost_tcp", INT_PARAM, &handle_lost_tcp },
{"preload", STR_PARAM|USE_FUNC_PARAM, (void*)ul_preload_param},
{"db_update_as_insert", INT_PARAM, &ul_db_update_as_insert},
{"timer_procs", INT_PARAM, &ul_timer_procs},
@@ -387,6 +389,10 @@ static int mod_init(void)
return -1;
}
}
+
+ if (handle_lost_tcp && db_mode == DB_ONLY)
+ LM_WARN("handle_lost_tcp option makes nothing in DB_ONLY mode\n");
+
init_flag = 1;
return 0;
diff --git a/modules/usrloc/ul_mod.h b/modules/usrloc/ul_mod.h
index 2435b5e..0e61924 100644
--- a/modules/usrloc/ul_mod.h
+++ b/modules/usrloc/ul_mod.h
@@ -84,6 +84,7 @@ extern int ul_hash_size;
extern int ul_db_update_as_insert;
extern int ul_db_check_update;
extern int ul_keepalive_timeout;
+extern int handle_lost_tcp;
/*! nat branch flag */
extern unsigned int nat_bflag;
diff --git a/modules/usrloc/urecord.c b/modules/usrloc/urecord.c
index 93c8446..6423dd6 100644
--- a/modules/usrloc/urecord.c
+++ b/modules/usrloc/urecord.c
@@ -40,6 +40,7 @@
#include "../../dprint.h"
#include "../../ut.h"
#include "../../hashes.h"
+#include "../../tcp_conn.h"
#include "ul_mod.h"
#include "usrloc.h"
#include "utime.h"
@@ -221,6 +222,26 @@ void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c)
free_ucontact(_c);
}
+static inline int is_valid_tcpconn(ucontact_t *c)
+{
+ if (c->tcpconn_id == -1)
+ return 0; /* tcpconn_id is not present */
+ else
+ return 1; /* valid tcpconn_id */
+}
+
+static inline int is_tcp_alive(ucontact_t *c)
+{
+ struct tcp_connection *con = NULL;
+ int rc = 0;
+
+ if ((con = tcpconn_get(c->tcpconn_id, 0, 0, 0, 0))) {
+ tcpconn_put(con); /* refcnt-- */
+ rc = 1;
+ }
+
+ return rc;
+}
/*!
* \brief Expires timer for NO_DB db_mode
@@ -236,6 +257,11 @@ static inline void nodb_timer(urecord_t* _r)
ptr = _r->contacts;
while(ptr) {
+ if (handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) {
+ LM_DBG("tcp connection has been lost, expiring contact %.*s\n", ptr->c.len, ptr->c.s);
+ ptr->expires = UL_EXPIRED_TIME;
+ }
+
if (!VALID_CONTACT(ptr, act_time)) {
/* run callbacks for EXPIRE event */
if (exists_ulcb_type(UL_CONTACT_EXPIRE))
@@ -296,7 +322,6 @@ static inline void wt_timer(urecord_t* _r)
}
}
-
/*!
* \brief Write-back timer, used for WRITE_BACK db_mode
*
@@ -316,6 +341,11 @@ static inline void wb_timer(urecord_t* _r)
ptr = _r->contacts;
while(ptr) {
+ if (handle_lost_tcp && is_valid_tcpconn(ptr) && !is_tcp_alive(ptr)) {
+ LM_DBG("tcp connection has been lost, expiring contact %.*s\n", ptr->c.len, ptr->c.s);
+ ptr->expires = UL_EXPIRED_TIME;
+ }
+
if (!VALID_CONTACT(ptr, act_time)) {
/* run callbacks for EXPIRE event */
if (exists_ulcb_type(UL_CONTACT_EXPIRE)) {
diff --git a/modules/usrloc/usrloc.h b/modules/usrloc/usrloc.h
index 1cf70bb..30cf354 100644
--- a/modules/usrloc/usrloc.h
+++ b/modules/usrloc/usrloc.h
@@ -91,6 +91,7 @@ typedef struct ucontact {
unsigned int methods; /*!< Supported methods */
str instance; /*!< SIP instance value - gruu */
unsigned int reg_id; /*!< reg-id parameters */
+ int tcpconn_id; /* unique tcp connection id */
#ifdef WITH_XAVP
sr_xavp_t * xavp; /*!< per contact xavps */
#endif
@@ -116,6 +117,7 @@ typedef struct ucontact_info {
unsigned int methods; /*!< supported methods */
str instance; /*!< SIP instance value - gruu */
unsigned int reg_id; /*!< reg-id parameters */
+ int tcpconn_id;
#ifdef WITH_XAVP
sr_xavp_t * xavp; /*!< per contact xavps */
#endif
More information about the sr-dev
mailing list