ConnMan network manager
 help / color / Atom feed
* [PATCH] service: Let PreferredTechnologies overrule connected service sorting
@ 2021-06-21  7:20 Daniel Wagner
  2021-07-02  7:18 ` Daniel Wagner
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Wagner @ 2021-06-21  7:20 UTC (permalink / raw)
  To: connman; +Cc: 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).

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(-)

diff --git a/src/service.c b/src/service.c
index 20917a8923a4..f64ba7031e8c 100644
--- a/src/service.c
+++ b/src/service.c
@@ -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;
-- 
2.32.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] service: Let PreferredTechnologies overrule connected service sorting
  2021-06-21  7:20 [PATCH] service: Let PreferredTechnologies overrule connected service sorting Daniel Wagner
@ 2021-07-02  7:18 ` Daniel Wagner
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Wagner @ 2021-07-02  7:18 UTC (permalink / raw)
  To: connman

On Mon, Jun 21, 2021 at 09:20:37AM +0200, Daniel Wagner wrote:
> 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.

Patch applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-21  7:20 [PATCH] service: Let PreferredTechnologies overrule connected service sorting Daniel Wagner
2021-07-02  7:18 ` Daniel Wagner

ConnMan network manager

Archives are clonable:
	git clone --mirror https://lore.kernel.org/connman/0 connman/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 connman connman/ https://lore.kernel.org/connman \
		connman@lists.linux.dev
	public-inbox-index connman

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/dev.linux.lists.connman


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git