Browse code

dialog: counters for keep alive tracking

Daniel-Constantin Mierla authored on 04/04/2016 04:05:55
Showing 2 changed files
... ...
@@ -14,8 +14,8 @@
14 14
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 15
  * GNU General Public License for more details.
16 16
  *
17
- * You should have received a copy of the GNU General Public License 
18
- * along with this program; if not, write to the Free Software 
17
+ * You should have received a copy of the GNU General Public License
18
+ * along with this program; if not, write to the Free Software
19 19
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 20
  *
21 21
  */
... ...
@@ -48,7 +48,7 @@
48 48
 /* events for dialog processing */
49 49
 #define DLG_EVENT_TDEL         1 /*!< transaction was destroyed */
50 50
 #define DLG_EVENT_RPL1xx       2 /*!< 1xx request */
51
-#define DLG_EVENT_RPL2xx       3 /*!< 2xx request */ 
51
+#define DLG_EVENT_RPL2xx       3 /*!< 2xx request */
52 52
 #define DLG_EVENT_RPL3xx       4 /*!< 3xx request */
53 53
 #define DLG_EVENT_REQPRACK     5 /*!< PRACK request */
54 54
 #define DLG_EVENT_REQACK       6 /*!< ACK request */
... ...
@@ -128,6 +128,8 @@ typedef struct dlg_cell
128 128
 	struct dlg_head_cbl  cbs;		/*!< dialog callbacks */
129 129
 	struct dlg_profile_link *profile_links; /*!< dialog profiles */
130 130
 	struct dlg_var       *vars;		/*!< dialog variables */
131
+	unsigned int         ka_src_counter;	/*!< keepalive src (caller) counter */
132
+	unsigned int         ka_dst_counter;	/*!< keepalive dst (callee) counter */
131 133
 } dlg_cell_t;
132 134
 
133 135
 
... ...
@@ -322,9 +324,9 @@ dlg_cell_t* dlg_get_by_iuid(dlg_iuid_t *diuid);
322 322
  * \brief Get dialog that correspond to CallId, From Tag and To Tag
323 323
  *
324 324
  * Get dialog that correspond to CallId, From Tag and To Tag.
325
- * See RFC 3261, paragraph 4. Overview of Operation:                 
326
- * "The combination of the To tag, From tag, and Call-ID completely  
327
- * defines a peer-to-peer SIP relationship between [two UAs] and is 
325
+ * See RFC 3261, paragraph 4. Overview of Operation:
326
+ * "The combination of the To tag, From tag, and Call-ID completely
327
+ * defines a peer-to-peer SIP relationship between [two UAs] and is
328 328
  * referred to as a dialog."
329 329
  * Note that the caller is responsible for decrementing (or reusing)
330 330
  * 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 );
458 458
  * \return 1 if dialog structure and message content matches, 0 otherwise
459 459
  */
460 460
 static inline int match_dialog(dlg_cell_t *dlg, str *callid,
461
-							   str *ftag, str *ttag, unsigned int *dir) {
461
+		str *ftag, str *ttag, unsigned int *dir)
462
+{
462 463
 	if (dlg->tag[DLG_CALLEE_LEG].len == 0) {
463
-        // dialog to tag is undetermined ATM.
464
+		// dialog to tag is undetermined ATM.
464 465
 		if (*dir==DLG_DIR_DOWNSTREAM) {
465 466
 			if (dlg->callid.len == callid->len &&
466 467
 				dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
... ...
@@ -485,9 +488,9 @@ static inline int match_dialog(dlg_cell_t *dlg, str *callid,
485 485
 
486 486
 				*dir = DLG_DIR_UPSTREAM;
487 487
 				return 1;
488
-			} else if (dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
489
-					   strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
490
-					   strncmp(dlg->callid.s, callid->s, callid->len)==0) {
488
+			} else if (dlg->tag[DLG_CALLER_LEG].len == ftag->len
489
+					&& strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0
490
+					&& strncmp(dlg->callid.s, callid->s, callid->len)==0) {
491 491
 
492 492
 				*dir = DLG_DIR_DOWNSTREAM;
493 493
 				return 1;
... ...
@@ -525,10 +528,10 @@ static inline int match_dialog(dlg_cell_t *dlg, str *callid,
525 525
 				*dir = DLG_DIR_UPSTREAM;
526 526
 				return 1;
527 527
 			} else if (dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
528
-					   dlg->tag[DLG_CALLEE_LEG].len == ttag->len &&
529
-					   strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
530
-					   strncmp(dlg->tag[DLG_CALLEE_LEG].s, ttag->s, ttag->len)==0 &&
531
-					   strncmp(dlg->callid.s, callid->s, callid->len)==0) {
528
+						dlg->tag[DLG_CALLEE_LEG].len == ttag->len &&
529
+						strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
530
+						strncmp(dlg->tag[DLG_CALLEE_LEG].s, ttag->s, ttag->len)==0 &&
531
+						strncmp(dlg->callid.s, callid->s, callid->len)==0) {
532 532
 
533 533
 				*dir = DLG_DIR_DOWNSTREAM;
534 534
 				return 1;
... ...
@@ -537,8 +540,8 @@ static inline int match_dialog(dlg_cell_t *dlg, str *callid,
537 537
 			 * runs on 200ok but with initial INVITE that has no to-tag */
538 538
 			if(ttag->len==0 && dlg->state==DLG_STATE_CONFIRMED_NA
539 539
 					&& dlg->tag[DLG_CALLER_LEG].len == ftag->len &&
540
-					   strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
541
-					   strncmp(dlg->callid.s, callid->s, callid->len)==0) {
540
+						strncmp(dlg->tag[DLG_CALLER_LEG].s, ftag->s, ftag->len)==0 &&
541
+						strncmp(dlg->callid.s, callid->s, callid->len)==0) {
542 542
 
543 543
 				*dir = DLG_DIR_DOWNSTREAM;
544 544
 				return 1;
... ...
@@ -239,7 +239,8 @@ void bye_reply_cb(struct cell* t, int type, struct tmcb_params* ps){
239 239
 
240 240
 
241 241
 /* callback function to handle responses to the keep-alive request */
242
-void dlg_ka_cb(struct cell* t, int type, struct tmcb_params* ps){
242
+void dlg_ka_cb_all(struct cell* t, int type, struct tmcb_params* ps, int dir)
243
+{
243 244
 
244 245
 	dlg_cell_t* dlg;
245 246
 	dlg_iuid_t *iuid = NULL;
... ...
@@ -281,6 +282,17 @@ done:
281 281
 	dlg_iuid_sfree(iuid);
282 282
 }
283 283
 
284
+/* callback function to handle responses to the keep-alive request to src */
285
+void dlg_ka_cb_src(struct cell* t, int type, struct tmcb_params* ps)
286
+{
287
+	dlg_ka_cb_all(t, type, ps, DLG_CALLER_LEG);
288
+}
289
+
290
+/* callback function to handle responses to the keep-alive request to dst */
291
+void dlg_ka_cb_dst(struct cell* t, int type, struct tmcb_params* ps)
292
+{
293
+	dlg_ka_cb_all(t, type, ps, DLG_CALLEE_LEG);
294
+}
284 295
 
285 296
 static inline int build_extra_hdr(struct dlg_cell * cell, str *extra_hdrs,
286 297
 		str *str_hdr)
... ...
@@ -440,10 +452,10 @@ int dlg_send_ka(dlg_cell_t *dlg, int dir)
440 440
 
441 441
 	if(dir==DLG_CALLEE_LEG && dlg_lreq_callee_headers.len>0) {
442 442
 		set_uac_req(&uac_r, &met, &dlg_lreq_callee_headers, NULL, di,
443
-				TMCB_LOCAL_COMPLETED, dlg_ka_cb, (void*)iuid);
443
+				TMCB_LOCAL_COMPLETED, dlg_ka_cb_dst, (void*)iuid);
444 444
 	} else {
445 445
 		set_uac_req(&uac_r, &met, NULL, NULL, di, TMCB_LOCAL_COMPLETED,
446
-				dlg_ka_cb, (void*)iuid);
446
+				(dir==DLG_CALLEE_LEG)?dlg_ka_cb_dst:dlg_ka_cb_src, (void*)iuid);
447 447
 	}
448 448
 	result = d_tmb.t_request_within(&uac_r);
449 449