connman.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: "VAUTRIN Emmanuel (Canal Plus Prestataire)" <Emmanuel.VAUTRIN@cpexterne.org>
To: Daniel Wagner <wagi@monom.org>
Cc: "connman@lists.linux.dev" <connman@lists.linux.dev>
Subject: RE: [PATCH 3/3] iwd: Ensure hidden services connectable after removed
Date: Mon, 4 Oct 2021 09:22:37 +0000	[thread overview]
Message-ID: <MRZP264MB15445D45BD54C00DE768979093AE9@MRZP264MB1544.FRAP264.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20211004070611.usnxi6bbmkfanxs6@beryllium.lan>

Hidden services shall always be connectable, even after been removed.
When a hidden service is removed, the associated iwd network stays as
known and thus shall be connected as a visible network.
---
 plugins/iwd.c | 71 +++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 54 insertions(+), 17 deletions(-)

diff --git a/plugins/iwd.c b/plugins/iwd.c
index 4d009c3515a8..a3c0ec6bba2f 100644
--- a/plugins/iwd.c
+++ b/plugins/iwd.c
@@ -140,6 +140,7 @@ struct iwd_station {
 	bool scanning;
 
 	GHashTable *hidden_aps;
+	GHashTable *hidden_networks;
 	struct hidden_params *hidden;
 	bool postpone_hidden;
 };
@@ -646,6 +647,37 @@ static void hidden_params_free(gpointer data)
 	g_free(hidden);
 }
 
+static int connect_hidden(struct iwd_station *iwds)
+{
+	struct iwd_network *iwdn;
+	char *ssid_security;
+	int err = 0;
+
+	ssid_security = g_strdup_printf("%s_%s",
+				iwds->hidden->ssid, iwds->hidden->security);
+	iwdn = g_hash_table_lookup(iwds->hidden_networks, ssid_security);
+	if (iwdn) {
+		err = connman_network_connect_hidden(iwdn->network,
+				iwds->hidden->identity,
+				iwds->hidden->passphrase,
+				iwds->hidden->user_data);
+		iwds->hidden->user_data = NULL;
+		if (err == -EINPROGRESS)
+			return 0;
+	} else if (!g_dbus_proxy_method_call(iwds->proxy,
+			"ConnectHiddenNetwork",
+			hidden_network_connect_append,
+			cm_hidden_network_connect_cb,
+			iwds->hidden, hidden_params_free)) {
+		err = -EIO;
+	}
+
+	if (err)
+		iwds->hidden = NULL;
+
+	return err;
+}
+
 static void cm_device_scan_cb(DBusMessage *message, void *user_data)
 {
 	const char *path = user_data;
@@ -669,13 +701,7 @@ static void cm_device_scan_cb(DBusMessage *message, void *user_data)
 		iwds->hidden = NULL;
 	} else {
 		iwds->postpone_hidden = false;
-		if (!g_dbus_proxy_method_call(iwds->proxy,
-				"ConnectHiddenNetwork",
-				hidden_network_connect_append,
-				cm_hidden_network_connect_cb,
-				iwds->hidden, hidden_params_free)) {
-			iwds->hidden = NULL;
-		}
+		connect_hidden(iwds);
 	}
 }
 
@@ -740,15 +766,7 @@ static int cm_device_scan(struct connman_device *device,
 			return 0;
 		}
 
-		if (!g_dbus_proxy_method_call(iwds->proxy,
-				"ConnectHiddenNetwork",
-				hidden_network_connect_append,
-				cm_hidden_network_connect_cb,
-				hidden, hidden_params_free)) {
-			iwds->hidden = NULL;
-			return -EIO;
-		}
-		return 0;
+		return connect_hidden(iwds);
 	}
 }
 
@@ -1298,8 +1316,23 @@ static void network_property_change(GDBusProxy *proxy, const char *name,
 
 		iwdkn = g_hash_table_lookup(known_networks,
 					iwdn->known_network);
-		if (iwdkn)
+		if (iwdkn) {
 			update_auto_connect(iwdkn);
+
+			if (iwdkn->hidden) {
+				struct iwd_station *iwds;
+				char *ssid_security;
+
+				iwds = g_hash_table_lookup(stations, iwdn->iwdd->path);
+				if (!iwds)
+					return;
+
+				ssid_security = g_strdup_printf("%s_%s",
+					iwdkn->name, security_remap(iwdkn->type));
+				g_hash_table_replace(iwds->hidden_networks,
+					ssid_security, iwdn);
+			}
+		}
 	}
 }
 
@@ -1658,6 +1691,7 @@ static void station_free(gpointer data)
 	g_free(iwds->path);
 	g_free(iwds->connected_network);
 	g_hash_table_destroy(iwds->hidden_aps);
+	g_hash_table_destroy(iwds->hidden_networks);
 	g_free(iwds->hidden);
 	g_free(iwds);
 }
@@ -2041,6 +2075,9 @@ static void create_station(GDBusProxy *proxy)
 	iwds->hidden_aps = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
 			hidden_ap_free);
 
+	iwds->hidden_networks = g_hash_table_new_full(g_str_hash, g_str_equal,
+			g_free, NULL);
+
 	iwds->hidden = NULL;
 	iwds->postpone_hidden = false;
 
-- 
2.25.1


------------------------------------------------------------------------------------------------
> +     if (err == -EINPROGRESS)
> +             err = 0;
> 
> You could do a 'return 0' here.
Indeed, Daniel, you are right.

Best Regards,

Emmanuel

      reply	other threads:[~2021-10-04  9:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01 15:29 VAUTRIN Emmanuel (Canal Plus Prestataire)
2021-10-04  7:06 ` Daniel Wagner
2021-10-04  9:22   ` VAUTRIN Emmanuel (Canal Plus Prestataire) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MRZP264MB15445D45BD54C00DE768979093AE9@MRZP264MB1544.FRAP264.PROD.OUTLOOK.COM \
    --to=emmanuel.vautrin@cpexterne.org \
    --cc=connman@lists.linux.dev \
    --cc=wagi@monom.org \
    --subject='RE: [PATCH 3/3] iwd: Ensure hidden services connectable after removed' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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