Browse code

dispatcher: skip inactive destinations for pointing next to be used record

Daniel-Constantin Mierla authored on 12/08/2019 18:15:17
Showing 1 changed files
... ...
@@ -2023,6 +2023,7 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
2023 2023
 	int i;
2024 2024
 	unsigned int hash;
2025 2025
 	ds_set_t *idx = NULL;
2026
+	int ulast = 0;
2026 2027
 
2027 2028
 	if(msg == NULL) {
2028 2029
 		LM_ERR("bad parameters\n");
... ...
@@ -2079,6 +2080,7 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
2079 2079
 		case DS_ALG_ROUNDROBIN: /* 4 - round robin */
2080 2080
 			hash = idx->last;
2081 2081
 			idx->last = (idx->last + 1) % idx->nr;
2082
+			ulast = 1;
2082 2083
 			break;
2083 2084
 		case DS_ALG_HASHAUTHUSER: /* 5 - hash auth username */
2084 2085
 			i = ds_hash_authusername(msg, &hash);
... ...
@@ -2090,6 +2092,7 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
2090 2090
 					/* No Authorization found: Use round robin */
2091 2091
 					hash = idx->last;
2092 2092
 					idx->last = (idx->last + 1) % idx->nr;
2093
+					ulast = 1;
2093 2094
 					break;
2094 2095
 				default:
2095 2096
 					LM_ERR("can't get authorization hash\n");
... ...
@@ -2191,6 +2194,11 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
2191 2191
 		rstate->emode = 1;
2192 2192
 	}
2193 2193
 
2194
+	/* update last field for next select to point after the current active used */
2195
+	if(ulast) {
2196
+		idx->last = (hash + 1) % idx->nr;
2197
+	}
2198
+
2194 2199
 	LM_DBG("selected [%d-%d-%d/%d] <%.*s>\n", rstate->alg, rstate->setid,
2195 2200
 			rstate->umode, hash,
2196 2201
 			idx->dlist[hash].uri.len, idx->dlist[hash].uri.s);