Skip to content

Commit

Permalink
service: Improve service sorting with more state checks
Browse files Browse the repository at this point in the history
[service] Improve service sorting with more state checks. JB#51404

Sort states also by the state and when checking for preference use it
for equal states only.

In case the VPN is split routed rely on the order set for the service.
This change makes the split routed VPNs to be arranged in the service
list to be after the transport instead of being after all the online
state services.

Also do some cleanup and allow VPNs to be set to be depending on each
other, the transport VPN must be non-split routed whereas the depending
VPN must be split routed.
  • Loading branch information
LaakkonenJussi committed Dec 2, 2020
1 parent 64acfda commit 72d5b49
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions connman/src/service.c
Expand Up @@ -751,8 +751,20 @@ static void set_vpn_dependency(struct connman_service *vpn_service)
}

switch (service->type) {
case CONNMAN_SERVICE_TYPE_VPN:
if (__connman_service_is_split_routing(service)) {
DBG("VPN as transport cannot be split routed");
return;
}

if (!__connman_service_is_split_routing(vpn_service)) {
DBG("non-split routed VPNs cannot depend on another");
return;
}
case CONNMAN_SERVICE_TYPE_WIFI:
/* fall through */
case CONNMAN_SERVICE_TYPE_CELLULAR:
/* fall through */
case CONNMAN_SERVICE_TYPE_ETHERNET:
break;
default:
Expand Down Expand Up @@ -6729,8 +6741,8 @@ static gint service_compare(gconstpointer a, gconstpointer b)
gint strength;

/* Compare availability first */
const gboolean a_available = is_available(service_a);
const gboolean b_available = is_available(service_b);
const gboolean a_available = is_available(service_a);
const gboolean b_available = is_available(service_b);

if (a_available && !b_available)
return -1;
Expand All @@ -6745,14 +6757,6 @@ static gint service_compare(gconstpointer a, gconstpointer b)
if (a_connected && b_connected) {
int preference;

if (!__connman_service_is_split_routing(service_a) &&
__connman_service_is_split_routing(service_b))
return -1;

if (__connman_service_is_split_routing(service_a) &&
!__connman_service_is_split_routing(service_b))
return 1;

if (service_a->type == CONNMAN_SERVICE_TYPE_VPN &&
service_b->type != CONNMAN_SERVICE_TYPE_VPN &&
service_a->depends_on &&
Expand All @@ -6771,10 +6775,13 @@ static gint service_compare(gconstpointer a, gconstpointer b)
service_b->depends_on);
}

/* Set as -1, 0 or 1, return value if preferred list is used */
preference = service_preferred_over(service_a, service_b);
if (preference)
return preference;
if (state_a == state_b) {
/* Return value only if preferred list is used. */
preference = service_preferred_over(service_a,
service_b);
if (preference)
return preference;
}

if (service_a->order > service_b->order)
return -1;
Expand All @@ -6798,9 +6805,24 @@ static gint service_compare(gconstpointer a, gconstpointer b)
if (b_connected)
return 1;

if (is_connecting(service_a))
if (is_connecting(service_a)) {
if (is_connecting(service_b))
goto statecmp;

return -1;
}

if (is_connecting(service_b)) {
if (is_connecting(service_a))
goto statecmp;

return 1;
}

statecmp:
if (state_a > state_b)
return -1;
if (is_connecting(service_b))
if (state_a < state_b)
return 1;
}

Expand Down

0 comments on commit 72d5b49

Please sign in to comment.