All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/3] iwd: Ensure hidden services connectable after removed
@ 2021-10-01 15:29 VAUTRIN Emmanuel (Canal Plus Prestataire)
  2021-10-04  7:06 ` Daniel Wagner
  0 siblings, 1 reply; 3+ messages in thread
From: VAUTRIN Emmanuel (Canal Plus Prestataire) @ 2021-10-01 15:29 UTC (permalink / raw)
  To: connman

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 961d53196207..9bd27e90c346 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)
+		err = 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);
+			}
+		}
 	}
 }
 
@@ -1659,6 +1692,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);
 }
@@ -2042,6 +2076,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

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

* Re: [PATCH 3/3] iwd: Ensure hidden services connectable after removed
  2021-10-01 15:29 [PATCH 3/3] iwd: Ensure hidden services connectable after removed VAUTRIN Emmanuel (Canal Plus Prestataire)
@ 2021-10-04  7:06 ` Daniel Wagner
  2021-10-04  9:22   ` VAUTRIN Emmanuel (Canal Plus Prestataire)
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Wagner @ 2021-10-04  7:06 UTC (permalink / raw)
  To: VAUTRIN Emmanuel (Canal Plus Prestataire); +Cc: connman

On Fri, Oct 01, 2021 at 03:29:16PM +0000, VAUTRIN Emmanuel (Canal Plus Prestataire) wrote:
> 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 961d53196207..9bd27e90c346 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)
> +		err = 0;

You could do a 'return 0' here.


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

* RE: [PATCH 3/3] iwd: Ensure hidden services connectable after removed
  2021-10-04  7:06 ` Daniel Wagner
@ 2021-10-04  9:22   ` VAUTRIN Emmanuel (Canal Plus Prestataire)
  0 siblings, 0 replies; 3+ messages in thread
From: VAUTRIN Emmanuel (Canal Plus Prestataire) @ 2021-10-04  9:22 UTC (permalink / raw)
  To: Daniel Wagner; +Cc: connman

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

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

end of thread, other threads:[~2021-10-04  9:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 15:29 [PATCH 3/3] iwd: Ensure hidden services connectable after removed VAUTRIN Emmanuel (Canal Plus Prestataire)
2021-10-04  7:06 ` Daniel Wagner
2021-10-04  9:22   ` VAUTRIN Emmanuel (Canal Plus Prestataire)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.