connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Check for active pending requests from agent when connecting hidden WiFi
@ 2022-02-25 10:57 Jussi Laakkonen
  2022-02-25 10:57 ` [PATCH 1/2] agent: Add support to check for active pending requests Jussi Laakkonen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jussi Laakkonen @ 2022-02-25 10:57 UTC (permalink / raw)
  To: connman

Hidden services do not keep the pending call when connecting as that is
forwarded for agent to handle, if present. This patch set adds simple search
to agent.c that can be used in service.c via agent-connman.c to check if the
hidden service has a pending connect request.

It was noticed that two consecutive connect requests for a hidden service was
possible and this resulted in adding two separate requests when agent was
present. First requests was placed as the pending request on the agent and the
second one was allowed as well but it was put into the queue. And when time-out
happened on the first one then the duplicate request would have been sent.

UI components relying on D-Bus API should not have to deal with this, it is
better to handle this case on ConnMan side.

Jussi Laakkonen (2):
  agent: Add support to check for active pending requests
  service: Check if hidden service has a pending request

 include/agent.h     |  1 +
 src/agent-connman.c | 16 ++++++++++++++++
 src/agent.c         | 28 ++++++++++++++++++++++++++++
 src/connman.h       |  2 ++
 src/service.c       |  5 ++++-
 5 files changed, 51 insertions(+), 1 deletion(-)

-- 
2.30.2


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

* [PATCH 1/2] agent: Add support to check for active pending requests
  2022-02-25 10:57 [PATCH 0/2] Check for active pending requests from agent when connecting hidden WiFi Jussi Laakkonen
@ 2022-02-25 10:57 ` Jussi Laakkonen
  2022-02-25 10:58 ` [PATCH 2/2] service: Check if hidden service has a pending request on agent Jussi Laakkonen
  2022-02-27 17:58 ` [PATCH 0/2] Check for active pending requests from agent when connecting hidden WiFi Daniel Wagner
  2 siblings, 0 replies; 4+ messages in thread
From: Jussi Laakkonen @ 2022-02-25 10:57 UTC (permalink / raw)
  To: connman

This adds a simple search to agent.c that can be used via
agent-connman.c to check if there is a pending request for the service.
Both current active pending request for the agent is checked as well as
the list of the queries for the given user context.
---
 include/agent.h     |  1 +
 src/agent-connman.c | 16 ++++++++++++++++
 src/agent.c         | 28 ++++++++++++++++++++++++++++
 src/connman.h       |  2 ++
 4 files changed, 47 insertions(+)

diff --git a/include/agent.h b/include/agent.h
index 6961f7a1..27020203 100644
--- a/include/agent.h
+++ b/include/agent.h
@@ -71,6 +71,7 @@ int connman_agent_queue_message(void *user_context,
 				DBusMessage *msg, int timeout,
 				agent_queue_cb callback, void *user_data,
 				void *agent_data);
+bool connman_agent_queue_search(void *user_context, void *agent_data);
 
 void *connman_agent_get_info(const char *dbus_sender, const char **sender,
 							const char **path);
diff --git a/src/agent-connman.c b/src/agent-connman.c
index fca7cc1f..139a19fc 100644
--- a/src/agent-connman.c
+++ b/src/agent-connman.c
@@ -865,3 +865,19 @@ int __connman_agent_request_peer_authorization(struct connman_peer *peer,
 
 	return -EINPROGRESS;
 }
+
+bool __connman_agent_is_request_pending(struct connman_service *service,
+						const char *dbus_sender)
+{
+	void *agent;
+
+	/* Default agent will be returned if no dbus_sender */
+	agent = connman_agent_get_info(dbus_sender, NULL, NULL);
+
+	DBG("agent %p service %p", agent, service);
+
+	if (!service || !agent)
+		return false;
+
+	return connman_agent_queue_search(service, agent);
+}
diff --git a/src/agent.c b/src/agent.c
index d4f9add4..6a9eb1e0 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -257,6 +257,34 @@ int connman_agent_queue_message(void *user_context,
 	return err;
 }
 
+bool connman_agent_queue_search(void *user_context, void *agent_data)
+{
+	struct connman_agent *agent = agent_data;
+	struct connman_agent_request *queue_data;
+	GList *iter;
+
+	DBG("user context %p agent %p", user_context, agent);
+
+	if (!agent || !user_context)
+		return false;
+
+	if (agent->pending && agent->pending->user_context == user_context) {
+		DBG("user context %p is pending for reply", user_context);
+		return true;
+	}
+
+	for (iter = agent->queue; iter; iter = iter->next) {
+		queue_data = iter->data;
+
+		if (queue_data && queue_data->user_context == user_context) {
+			DBG("user context %p is in queue", user_context);
+			return true;
+		}
+	}
+
+	return false;
+}
+
 static void set_default_agent(void)
 {
 	struct connman_agent *agent = NULL;
diff --git a/src/connman.h b/src/connman.h
index 909b53ae..33dbec69 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -126,6 +126,8 @@ int __connman_agent_request_peer_authorization(struct connman_peer *peer,
 						bool wps_requested,
 						const char *dbus_sender,
 						void *user_data);
+bool __connman_agent_is_request_pending(struct connman_service *service,
+						const char *dbus_sender);
 
 #include <connman/log.h>
 
-- 
2.30.2


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

* [PATCH 2/2] service: Check if hidden service has a pending request on agent
  2022-02-25 10:57 [PATCH 0/2] Check for active pending requests from agent when connecting hidden WiFi Jussi Laakkonen
  2022-02-25 10:57 ` [PATCH 1/2] agent: Add support to check for active pending requests Jussi Laakkonen
@ 2022-02-25 10:58 ` Jussi Laakkonen
  2022-02-27 17:58 ` [PATCH 0/2] Check for active pending requests from agent when connecting hidden WiFi Daniel Wagner
  2 siblings, 0 replies; 4+ messages in thread
From: Jussi Laakkonen @ 2022-02-25 10:58 UTC (permalink / raw)
  To: connman

Hidden (WiFi) services do not save the pending request to the service
struct and this utilizes agent-connman.c to check if there is a agent
request already set for the service. In such case this reports in
progress error back to the caller as with visible service.

Otherwise there would be a possibility to request connect for at least
twice for a hidden WiFi network. And when agent is in use this would
result in two requests to be sent, first one is the current active one
and the second would be waiting in agent queue, which in case of
time-out would be then be sent to the agent as a duplicate request.
---
 src/service.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/service.c b/src/service.c
index 1d2b78a6..f1abb963 100644
--- a/src/service.c
+++ b/src/service.c
@@ -4562,7 +4562,10 @@ static DBusMessage *connect_service(DBusConnection *conn,
 
 	DBG("service %p", service);
 
-	if (service->pending)
+	/* Hidden services do not keep the pending msg, check it from agent */
+	if (service->pending || (service->hidden &&
+				__connman_agent_is_request_pending(service,
+						dbus_message_get_sender(msg))))
 		return __connman_error_in_progress(msg);
 
 	index = __connman_service_get_index(service);
-- 
2.30.2


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

* Re: [PATCH 0/2] Check for active pending requests from agent when connecting hidden WiFi
  2022-02-25 10:57 [PATCH 0/2] Check for active pending requests from agent when connecting hidden WiFi Jussi Laakkonen
  2022-02-25 10:57 ` [PATCH 1/2] agent: Add support to check for active pending requests Jussi Laakkonen
  2022-02-25 10:58 ` [PATCH 2/2] service: Check if hidden service has a pending request on agent Jussi Laakkonen
@ 2022-02-27 17:58 ` Daniel Wagner
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Wagner @ 2022-02-27 17:58 UTC (permalink / raw)
  To: connman, Jussi Laakkonen; +Cc: Daniel Wagner

On Fri, 25 Feb 2022 12:57:58 +0200, Jussi Laakkonen wrote:
> Hidden services do not keep the pending call when connecting as that is
> forwarded for agent to handle, if present. This patch set adds simple search
> to agent.c that can be used in service.c via agent-connman.c to check if the
> hidden service has a pending connect request.
> 
> It was noticed that two consecutive connect requests for a hidden service was
> possible and this resulted in adding two separate requests when agent was
> present. First requests was placed as the pending request on the agent and the
> second one was allowed as well but it was put into the queue. And when time-out
> happened on the first one then the duplicate request would have been sent.
> 
> [...]

Applied, thanks!

I've removed the DBG() as they really looked like development DBGs.

[1/2] agent: Add support to check for active pending requests
      commit: 3d9b90e89f1ee44e3d8b1bcf52c9bd12f9078334
[2/2] service: Check if hidden service has a pending request on agent
      commit: a2d238c7bc515f2ce3113feb31d6c0e9067550b7

Best regards,
-- 
Daniel Wagner <wagi@monom.org>

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

end of thread, other threads:[~2022-02-27 17:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-25 10:57 [PATCH 0/2] Check for active pending requests from agent when connecting hidden WiFi Jussi Laakkonen
2022-02-25 10:57 ` [PATCH 1/2] agent: Add support to check for active pending requests Jussi Laakkonen
2022-02-25 10:58 ` [PATCH 2/2] service: Check if hidden service has a pending request on agent Jussi Laakkonen
2022-02-27 17:58 ` [PATCH 0/2] Check for active pending requests from agent when connecting hidden WiFi Daniel Wagner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).