[sr-dev] git:alexh/dialog-sync-wip: dialog: Only allow strictly increasing states in DMQ sync

Alex Hermann alex at speakup.nl
Thu Sep 4 13:21:34 CEST 2014


Module: sip-router
Branch: alexh/dialog-sync-wip
Commit: 4a5e99771f0b76b6ddd7ecd129f46a73a3e0d1e8
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=4a5e99771f0b76b6ddd7ecd129f46a73a3e0d1e8

Author: Alex Hermann <alex at speakup.nl>
Committer: Alex Hermann <alex at speakup.nl>
Date:   Tue Aug 26 18:51:02 2014 +0200

dialog: Only allow strictly increasing states in DMQ sync

Catches most out-of-order sync messages.

---

 modules/dialog/dlg_dmq.c      |    8 +++++++-
 modules/dialog/dlg_handlers.c |    6 +++---
 modules/dialog/dlg_hash.h     |    3 ++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/modules/dialog/dlg_dmq.c b/modules/dialog/dlg_dmq.c
index 3ea532e..2b11453 100644
--- a/modules/dialog/dlg_dmq.c
+++ b/modules/dialog/dlg_dmq.c
@@ -212,7 +212,7 @@ int dlg_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp)
 				dlg_json_to_profiles(dlg, &prof_jdoc);
 				srjson_DestroyDoc(&prof_jdoc);
 			}
-			if (dlg->state == state) {
+			if (state == dlg->state) {
 				break;
 			}
 			/* intentional fallthrough */
@@ -222,6 +222,12 @@ int dlg_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp)
 				LM_ERR("dialog [%u:%u] not found\n", iuid.h_entry, iuid.h_id);
 				goto error;
 			}
+			if (state < dlg->state) {
+				LM_NOTICE("Ignoring backwards state change on dlg [%u:%u] with callid [%.*s] from state [%u] to state [%u]\n",
+					iuid.h_entry, iuid.h_id,
+					dlg->callid.len, dlg->callid.s, dlg->state, state);
+				break;
+			}
 			LM_DBG("State update dlg [%u:%u] with callid [%.*s] from state [%u] to state [%u]\n", iuid.h_entry, iuid.h_id,
 					dlg->callid.len, dlg->callid.s, dlg->state, state);
 			switch (state) {
diff --git a/modules/dialog/dlg_handlers.c b/modules/dialog/dlg_handlers.c
index af5385b..29e1350 100644
--- a/modules/dialog/dlg_handlers.c
+++ b/modules/dialog/dlg_handlers.c
@@ -570,7 +570,7 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param)
 	if (unref) dlg_unref(dlg, unref);
 
 done:
-	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state!=old_state) {
+	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state>old_state) {
 		dlg_dmq_replicate_action(DLG_DMQ_STATE, dlg, 0);
 	}
 
@@ -1393,7 +1393,7 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
 	}
 
 done:
-	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state!=old_state) {
+	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state>old_state) {
 		dlg_dmq_replicate_action(DLG_DMQ_STATE, dlg, 0);
 	}
 
@@ -1468,7 +1468,7 @@ void dlg_ontimeout(struct dlg_tl *tl)
 		dlg_unref(dlg, 1);
 	}
 
-	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state!=old_state) {
+	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state>old_state) {
 		dlg_dmq_replicate_action(DLG_DMQ_STATE, dlg, 0);
 	}
 
diff --git a/modules/dialog/dlg_hash.h b/modules/dialog/dlg_hash.h
index 66b86e0..426bad6 100644
--- a/modules/dialog/dlg_hash.h
+++ b/modules/dialog/dlg_hash.h
@@ -50,7 +50,8 @@
 #include "dlg_cb.h"
 
 
-/* states of a dialog */
+/* states of a dialog
+ * order is important, numbering must represent normal state stange flow */
 #define DLG_STATE_UNCONFIRMED  1 /*!< unconfirmed dialog */
 #define DLG_STATE_EARLY        2 /*!< early dialog */
 #define DLG_STATE_CONFIRMED_NA 3 /*!< confirmed dialog without a ACK yet */




More information about the sr-dev mailing list