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 2080
 		case DS_ALG_ROUNDROBIN: /* 4 - round robin */
2080 2081
 			hash = idx->last;
2081 2082
 			idx->last = (idx->last + 1) % idx->nr;
2083
+			ulast = 1;
2082 2084
 			break;
2083 2085
 		case DS_ALG_HASHAUTHUSER: /* 5 - hash auth username */
2084 2086
 			i = ds_hash_authusername(msg, &hash);
... ...
@@ -2090,6 +2092,7 @@ int ds_manage_routes(sip_msg_t *msg, ds_select_state_t *rstate)
2090 2092
 					/* No Authorization found: Use round robin */
2091 2093
 					hash = idx->last;
2092 2094
 					idx->last = (idx->last + 1) % idx->nr;
2095
+					ulast = 1;
2093 2096
 					break;
2094 2097
 				default:
2095 2098
 					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 2194
 		rstate->emode = 1;
2192 2195
 	}
2193 2196
 
2197
+	/* update last field for next select to point after the current active used */
2198
+	if(ulast) {
2199
+		idx->last = (hash + 1) % idx->nr;
2200
+	}
2201
+
2194 2202
 	LM_DBG("selected [%d-%d-%d/%d] <%.*s>\n", rstate->alg, rstate->setid,
2195 2203
 			rstate->umode, hash,
2196 2204
 			idx->dlist[hash].uri.len, idx->dlist[hash].uri.s);