Commit b3012e59 authored by Ghislain MARY's avatar Ghislain MARY

Fix bug 0001348: Incorrect handling of DNS SRV results.

parent 1f566bdc
......@@ -319,11 +319,28 @@ static belle_sip_dns_srv_t *srv_elect_one(belle_sip_list_t *srv_list){
if (rand_number>=srv->cumulative_weight)
return srv;
}
/*we should not reach this line*/
belle_sip_warning("srv_elect_one(): should not happen.");
return (belle_sip_dns_srv_t*)srv_list->data;
}
/*
* Order an SRV list with entries having the same priority according to their weight
*/
static belle_sip_list_t *srv_elect(belle_sip_list_t **srv_list) {
belle_sip_list_t *result = NULL;
while (*srv_list != NULL) {
belle_sip_list_t *it;
belle_sip_dns_srv_t *entry = srv_elect_one(*srv_list);
result = belle_sip_list_append(result, belle_sip_object_ref(entry));
it = belle_sip_list_find(*srv_list, entry);
if (it) {
*srv_list = belle_sip_list_remove_link(*srv_list, it);
belle_sip_free(it);
}
}
return result;
}
/*
* this function will return a list of SRV, with only one SRV record per priority.
*/
......@@ -332,7 +349,7 @@ static belle_sip_list_t *srv_select_by_weight(belle_sip_list_t *srv_list){
belle_sip_list_t *elem;
belle_sip_dns_srv_t *prev_srv=NULL;
belle_sip_list_t *result=NULL;
for (elem=srv_list;elem!=NULL;elem=elem->next){
belle_sip_dns_srv_t *srv=(belle_sip_dns_srv_t*)elem->data;
if (prev_srv){
......@@ -343,15 +360,14 @@ static belle_sip_list_t *srv_select_by_weight(belle_sip_list_t *srv_list){
same_prio=belle_sip_list_insert_sorted(same_prio,srv,srv_sort_weight);
}else{
if (same_prio){
result=belle_sip_list_append(result,belle_sip_object_ref(srv_elect_one(same_prio)));
same_prio=NULL;
result=belle_sip_list_concat(result,srv_elect(&same_prio));
}
}
}
prev_srv=srv;
}
if (same_prio){
result=belle_sip_list_append(result,belle_sip_object_ref(srv_elect_one(same_prio)));
result=belle_sip_list_concat(result,srv_elect(&same_prio));
}
if (result){
belle_sip_list_free_with_data(srv_list,belle_sip_object_unref);
......
......@@ -551,6 +551,14 @@ static void register_dns_srv_tls(void){
if (req) belle_sip_object_unref(req);
}
static void register_dns_load_balancing(void) {
belle_sip_request_t *req;
io_error_count = 0;
req = try_register_user_at_domain(stack, prov, "TCP", 1, "tester", client_auth_domain, "sip:belle-sip.net;transport=tcp", 1);
CU_ASSERT_TRUE(io_error_count == 0);
if (req) belle_sip_object_unref(req);
}
test_t register_tests[] = {
{ "Stateful UDP", stateful_register_udp },
......@@ -572,7 +580,8 @@ test_t register_tests[] = {
{ "TLS connection too long", test_connection_too_long_tls },
{ "TLS connection to TCP server", test_tls_to_tcp },
{ "Register with DNS SRV failover TCP", register_dns_srv_tcp },
{ "Register with DNS SRV failover TLS", register_dns_srv_tls }
{ "Register with DNS SRV failover TLS", register_dns_srv_tls },
{ "Register with DNS load-balancing", register_dns_load_balancing }
};
test_suite_t register_test_suite = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment