Browse code

dialog: Only allow strictly increasing states in DMQ sync

Catches most out-of-order sync messages.

Alex Hermann authored on 26/08/2014 16:51:02
Showing 3 changed files
... ...
@@ -212,7 +212,7 @@ int dlg_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp)
212 212
 				dlg_json_to_profiles(dlg, &prof_jdoc);
213 213
 				srjson_DestroyDoc(&prof_jdoc);
214 214
 			}
215
-			if (dlg->state == state) {
215
+			if (state == dlg->state) {
216 216
 				break;
217 217
 			}
218 218
 			/* intentional fallthrough */
... ...
@@ -222,6 +222,12 @@ int dlg_dmq_handle_msg(struct sip_msg* msg, peer_reponse_t* resp)
222 222
 				LM_ERR("dialog [%u:%u] not found\n", iuid.h_entry, iuid.h_id);
223 223
 				goto error;
224 224
 			}
225
+			if (state < dlg->state) {
226
+				LM_NOTICE("Ignoring backwards state change on dlg [%u:%u] with callid [%.*s] from state [%u] to state [%u]\n",
227
+					iuid.h_entry, iuid.h_id,
228
+					dlg->callid.len, dlg->callid.s, dlg->state, state);
229
+				break;
230
+			}
225 231
 			LM_DBG("State update dlg [%u:%u] with callid [%.*s] from state [%u] to state [%u]\n", iuid.h_entry, iuid.h_id,
226 232
 					dlg->callid.len, dlg->callid.s, dlg->state, state);
227 233
 			switch (state) {
... ...
@@ -570,7 +570,7 @@ static void dlg_onreply(struct cell* t, int type, struct tmcb_params *param)
570 570
 	if (unref) dlg_unref(dlg, unref);
571 571
 
572 572
 done:
573
-	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state!=old_state) {
573
+	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state>old_state) {
574 574
 		dlg_dmq_replicate_action(DLG_DMQ_STATE, dlg, 0);
575 575
 	}
576 576
 
... ...
@@ -1393,7 +1393,7 @@ void dlg_onroute(struct sip_msg* req, str *route_params, void *param)
1393 1393
 	}
1394 1394
 
1395 1395
 done:
1396
-	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state!=old_state) {
1396
+	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state>old_state) {
1397 1397
 		dlg_dmq_replicate_action(DLG_DMQ_STATE, dlg, 0);
1398 1398
 	}
1399 1399
 
... ...
@@ -1468,7 +1468,7 @@ void dlg_ontimeout(struct dlg_tl *tl)
1468 1468
 		dlg_unref(dlg, 1);
1469 1469
 	}
1470 1470
 
1471
-	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state!=old_state) {
1471
+	if(dlg_enable_dmq && (dlg->iflags & DLG_IFLAG_DMQ_SYNC) && new_state>old_state) {
1472 1472
 		dlg_dmq_replicate_action(DLG_DMQ_STATE, dlg, 0);
1473 1473
 	}
1474 1474
 
... ...
@@ -50,7 +50,8 @@
50 50
 #include "dlg_cb.h"
51 51
 
52 52
 
53
-/* states of a dialog */
53
+/* states of a dialog
54
+ * order is important, numbering must represent normal state stange flow */
54 55
 #define DLG_STATE_UNCONFIRMED  1 /*!< unconfirmed dialog */
55 56
 #define DLG_STATE_EARLY        2 /*!< early dialog */
56 57
 #define DLG_STATE_CONFIRMED_NA 3 /*!< confirmed dialog without a ACK yet */