Browse Source

dialog: counters for keep alive tracking

Daniel-Constantin Mierla 9 years ago
parent
commit
2ea8b13277
2 changed files with 35 additions and 20 deletions
  1. 20 17
      modules/dialog/dlg_hash.h
  2. 15 3
      modules/dialog/dlg_req_within.c

+ 20 - 17
modules/dialog/dlg_hash.h

@@ -14,8 +14,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -48,7 +48,7 @@
 /* events for dialog processing */
 #define DLG_EVENT_TDEL         1 /*!< transaction was destroyed */
 #define DLG_EVENT_RPL1xx       2 /*!< 1xx request */
-#define DLG_EVENT_RPL2xx       3 /*!< 2xx request */ 
+#define DLG_EVENT_RPL2xx       3 /*!< 2xx request */
 #define DLG_EVENT_RPL3xx       4 /*!< 3xx request */
 #define DLG_EVENT_REQPRACK     5 /*!< PRACK request */
 #define DLG_EVENT_REQACK       6 /*!< ACK request */
@@ -128,6 +128,8 @@ typedef struct dlg_cell
 	struct dlg_head_cbl  cbs;		/*!< dialog callbacks */
 	struct dlg_profile_link *profile_links; /*!< dialog profiles */
 	struct dlg_var       *vars;		/*!< dialog variables */
+	unsigned int         ka_src_counter;	/*!< keepalive src (caller) counter */
+	unsigned int         ka_dst_counter;	/*!< keepalive dst (callee) counter */
 } dlg_cell_t;
 
 
@@ -322,9 +324,9 @@ dlg_cell_t* dlg_get_by_iuid(dlg_iuid_t *diuid);
  * \brief Get dialog that correspond to CallId, From Tag and To Tag
  *
  * Get dialog that correspond to CallId, From Tag and To Tag.
- * See RFC 3261, paragraph 4. Overview of Operation:                 
- * "The combination of the To tag, From tag, and Call-ID completely  
- * defines a peer-to-peer SIP relationship between [two UAs] and is 
+ * See RFC 3261, paragraph 4. Overview of Operation:
+ * "The combination of the To tag, From tag, and Call-ID completely
+ * defines a peer-to-peer SIP relationship between [two UAs] and is
  * referred to as a dialog."
  * Note that the caller is responsible for decrementing (or reusing)
  * the reference counter by one again iff a dialog has been found.
@@ -458,9 +460,10 @@ struct mi_root * mi_terminate_dlgs(struct mi_root *cmd_tree, void *param );
  * \return 1 if dialog structure and message content matches, 0 otherwise
  */
 static inline int match_dialog(dlg_cell_t *dlg, str *callid,
-							   str *ftag, str *ttag, unsigned int *dir) {
+		str *ftag, str *ttag, unsigned int *dir)
+{
 	if (dlg->tag[DLG_CALLEE_LEG].len == 0) {
-        // dialog to tag is undetermined ATM.
+		// dialog to tag is undetermined ATM.
 		if (*dir==DLG_DIR_DOWNSTREAM) {
 			if (dlg->callid.len == callid->len &&
 				dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
@@ -485,9 +488,9 @@ static inline int match_dialog(dlg_cell_t *dlg, str *callid,
 
 				*dir = DLG_DIR_UPSTREAM;
 				return 1;
-			} else if (dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
-					   strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
-					   strncmp(dlg->callid.s, callid->s, callid->len)==0) {
+			} else if (dlg->tag[DLG_CALLER_LEG].len == ftag->len
+					&& strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0
+					&& strncmp(dlg->callid.s, callid->s, callid->len)==0) {
 
 				*dir = DLG_DIR_DOWNSTREAM;
 				return 1;
@@ -525,10 +528,10 @@ static inline int match_dialog(dlg_cell_t *dlg, str *callid,
 				*dir = DLG_DIR_UPSTREAM;
 				return 1;
 			} else if (dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
-					   dlg->tag[DLG_CALLEE_LEG].len == ttag->len &&
-					   strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
-					   strncmp(dlg->tag[DLG_CALLEE_LEG].s, ttag->s, ttag->len)==0 &&
-					   strncmp(dlg->callid.s, callid->s, callid->len)==0) {
+						dlg->tag[DLG_CALLEE_LEG].len == ttag->len &&
+						strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
+						strncmp(dlg->tag[DLG_CALLEE_LEG].s, ttag->s, ttag->len)==0 &&
+						strncmp(dlg->callid.s, callid->s, callid->len)==0) {
 
 				*dir = DLG_DIR_DOWNSTREAM;
 				return 1;
@@ -537,8 +540,8 @@ static inline int match_dialog(dlg_cell_t *dlg, str *callid,
 			 * runs on 200ok but with initial INVITE that has no to-tag */
 			if(ttag->len==0 && dlg->state==DLG_STATE_CONFIRMED_NA
 					&& dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
-					   strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
-					   strncmp(dlg->callid.s, callid->s, callid->len)==0) {
+						strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
+						strncmp(dlg->callid.s, callid->s, callid->len)==0) {
 
 				*dir = DLG_DIR_DOWNSTREAM;
 				return 1;

+ 15 - 3
modules/dialog/dlg_req_within.c

@@ -239,7 +239,8 @@ void bye_reply_cb(struct cell* t, int type, struct tmcb_params* ps){
 
 
 /* callback function to handle responses to the keep-alive request */
-void dlg_ka_cb(struct cell* t, int type, struct tmcb_params* ps){
+void dlg_ka_cb_all(struct cell* t, int type, struct tmcb_params* ps, int dir)
+{
 
 	dlg_cell_t* dlg;
 	dlg_iuid_t *iuid = NULL;
@@ -281,6 +282,17 @@ done:
 	dlg_iuid_sfree(iuid);
 }
 
+/* callback function to handle responses to the keep-alive request to src */
+void dlg_ka_cb_src(struct cell* t, int type, struct tmcb_params* ps)
+{
+	dlg_ka_cb_all(t, type, ps, DLG_CALLER_LEG);
+}
+
+/* callback function to handle responses to the keep-alive request to dst */
+void dlg_ka_cb_dst(struct cell* t, int type, struct tmcb_params* ps)
+{
+	dlg_ka_cb_all(t, type, ps, DLG_CALLEE_LEG);
+}
 
 static inline int build_extra_hdr(struct dlg_cell * cell, str *extra_hdrs,
 		str *str_hdr)
@@ -440,10 +452,10 @@ int dlg_send_ka(dlg_cell_t *dlg, int dir)
 
 	if(dir==DLG_CALLEE_LEG && dlg_lreq_callee_headers.len>0) {
 		set_uac_req(&uac_r, &met, &dlg_lreq_callee_headers, NULL, di,
-				TMCB_LOCAL_COMPLETED, dlg_ka_cb, (void*)iuid);
+				TMCB_LOCAL_COMPLETED, dlg_ka_cb_dst, (void*)iuid);
 	} else {
 		set_uac_req(&uac_r, &met, NULL, NULL, di, TMCB_LOCAL_COMPLETED,
-				dlg_ka_cb, (void*)iuid);
+				(dir==DLG_CALLEE_LEG)?dlg_ka_cb_dst:dlg_ka_cb_src, (void*)iuid);
 	}
 	result = d_tmb.t_request_within(&uac_r);