Skip to contentSkip to conversation

service: Let PreferredTechnologies overrule connected service sorting

PATCH In review Daniel Wagner 1 participant 2 messages Jun 21, 2021 – Jul 2, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 service: Let PreferredTechnologies overrule connected service sorting

When both services are in either READY or ONLINE state ConnMan will always return either the service in ONLINE state (this is the correct behavior) or when both services are in ONLINE state service_a first. PreferredTechnologies is ignored in this case.

For configuration such as

PreferredTechnologies = ethernet,wifi
SingleConnectedTechnology = true

ConnMan would almost never sort Ethernet before WiFi, as WiFi is likely to be in the ONLINE state. Hence the WiFi would stay on forever even though the Ethernet cable is plugged in (again).

Place the service_compare_preferred() after the service->oder logic as this is used for split VPN setups which has higher priority in the sorting.

As we place this call inside the 'is_connected' section where both service are in either READY or ONLINE state, it overrules the existing logic where the ONLINE service is preferred over the READY.
---

Just a resend on the new mailing list.

 src/service.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)
src/service.c +27 -13
index 20917a8923a4..f64ba7031e8c 100644
@@ -5316,6 +5316,25 @@ static gint service_compare_vpn(struct connman_service *a,
 	return service_compare(transport, service);
 }
 
+static gint service_compare_preferred(struct connman_service *service_a,
+					struct connman_service *service_b)
+{
+	unsigned int *tech_array;
+	int i;
+
+	tech_array = connman_setting_get_uint_list("PreferredTechnologies");
+	if (tech_array) {
+		for (i = 0; tech_array[i]; i++) {
+			if (tech_array[i] == service_a->type)
+				return -1;
+
+			if (tech_array[i] == service_b->type)
+				return 1;
+		}
+	}
+	return 0;
+}
+
 static gint service_compare(gconstpointer a, gconstpointer b)
 {
 	struct connman_service *service_a = (void *) a;
@@ -5346,6 +5365,10 @@ static gint service_compare(gconstpointer a, gconstpointer b)
 
 		if (service_a->order < service_b->order)
 			return 1;
+
+		rval = service_compare_preferred(service_a, service_b);
+		if (rval)
+			return rval;
 	}
 
 	if (state_a != state_b) {
@@ -5376,20 +5399,11 @@ static gint service_compare(gconstpointer a, gconstpointer b)
 		return 1;
 
 	if (service_a->type != service_b->type) {
-		unsigned int *tech_array;
-		int i;
-
-		tech_array = connman_setting_get_uint_list(
-						"PreferredTechnologies");
-		if (tech_array) {
-			for (i = 0; tech_array[i]; i++) {
-				if (tech_array[i] == service_a->type)
-					return -1;
+		int rval;
 
-				if (tech_array[i] == service_b->type)
-					return 1;
-			}
-		}
+		rval = service_compare_preferred(service_a, service_b);
+		if (rval)
+			return rval;
 
 		if (service_a->type == CONNMAN_SERVICE_TYPE_ETHERNET)
 			return -1;
Signature · 1 line
2.32.0
#1 lore raw
Quoted 14 lines · Daniel Wagner

When both services are in either READY or ONLINE state ConnMan will always return either the service in ONLINE state (this is the correct behavior) or when both services are in ONLINE state service_a first. PreferredTechnologies is ignored in this case.

For configuration such as

PreferredTechnologies = ethernet,wifi
SingleConnectedTechnology = true

ConnMan would almost never sort Ethernet before WiFi, as WiFi is likely to be in the ONLINE state. Hence the WiFi would stay on forever even though the Ethernet cable is plugged in (again).

Quoted 7 lines

Place the service_compare_preferred() after the service->oder logic as this is used for split VPN setups which has higher priority in the sorting.

As we place this call inside the 'is_connected' section where both service are in either READY or ONLINE state, it overrules the existing logic where the ONLINE service is preferred over the READY.

Patch applied.