Blame SOURCES/gnetworkmonitornm.patch

5c320d
From c48c984d39afeae84b0cad515f08f83c711fd9c4 Mon Sep 17 00:00:00 2001
5c320d
From: Philip Withnall <withnall@endlessm.com>
5c320d
Date: Thu, 13 Sep 2018 10:25:05 +0100
5c320d
Subject: [PATCH 1/9] gnetworkmonitornm: Set a GError properly on an error
5c320d
 handling path
5c320d
MIME-Version: 1.0
5c320d
Content-Type: text/plain; charset=UTF-8
5c320d
Content-Transfer-Encoding: 8bit
5c320d
5c320d
All the other initialisation failure paths set a GError, but this one
5c320d
didn’t. Set a GError to avoid breaking the invariant that returning
5c320d
FALSE should always have a GError set.
5c320d
5c320d
Signed-off-by: Philip Withnall <withnall@endlessm.com>
5c320d
5c320d
https://gitlab.gnome.org/GNOME/glib/issues/1523
5c320d
---
5c320d
 gio/gnetworkmonitornm.c | 2 ++
5c320d
 1 file changed, 2 insertions(+)
5c320d
5c320d
diff --git a/gio/gnetworkmonitornm.c b/gio/gnetworkmonitornm.c
5c320d
index 20a86571f..5bc8c925a 100644
5c320d
--- a/gio/gnetworkmonitornm.c
5c320d
+++ b/gio/gnetworkmonitornm.c
5c320d
@@ -309,6 +309,8 @@ g_network_monitor_nm_initable_init (GInitable     *initable,
5c320d
 
5c320d
   if (!name_owner)
5c320d
     {
5c320d
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
5c320d
+                   _("NetworkManager not running"));
5c320d
       g_object_unref (proxy);
5c320d
       return FALSE;
5c320d
     }
5c320d
-- 
5c320d
2.33.1
5c320d
5c320d
From d139986b1f213a7e1c1e3968ad2d8270f820bd57 Mon Sep 17 00:00:00 2001
5c320d
From: Antonio Larrosa <alarrosa@suse.com>
5c320d
Date: Tue, 12 Mar 2019 18:35:10 +0100
5c320d
Subject: [PATCH 2/9] Handle an UNKNOWN NetworkManager connectivity as NONE
5c320d
5c320d
nm_conn_to_g_conn already handles UNKNOWN like NONE (returning
5c320d
G_NETWORK_CONNECTIVITY_LOCAL in both cases). So in sync_properties
5c320d
we should also set new_connectivity to G_NETWORK_CONNECTIVITY_LOCAL
5c320d
for both NM_CONNECTIVITY_UNKNOWN and NM_CONNECTIVITY_NONE.
5c320d
5c320d
This has the added benefit that when NetworkManager returns the network
5c320d
connectivity is UNKNOWN, we set network_available to FALSE as it should
5c320d
be. Previously, there were cases in a laptop with no network access,
5c320d
that g_network_monitor_get_network_available returned true, which was
5c320d
wrong and is also fixed with this commit.
5c320d
---
5c320d
 gio/gnetworkmonitornm.c | 3 ++-
5c320d
 1 file changed, 2 insertions(+), 1 deletion(-)
5c320d
5c320d
diff --git a/gio/gnetworkmonitornm.c b/gio/gnetworkmonitornm.c
5c320d
index 5bc8c925a..4e2a35e8a 100644
5c320d
--- a/gio/gnetworkmonitornm.c
5c320d
+++ b/gio/gnetworkmonitornm.c
5c320d
@@ -167,7 +167,8 @@ sync_properties (GNetworkMonitorNM *nm,
5c320d
   nm_connectivity = g_variant_get_uint32 (v);
5c320d
   g_variant_unref (v);
5c320d
 
5c320d
-  if (nm_connectivity == NM_CONNECTIVITY_NONE)
5c320d
+  if (nm_connectivity == NM_CONNECTIVITY_UNKNOWN ||
5c320d
+      nm_connectivity == NM_CONNECTIVITY_NONE)
5c320d
     {
5c320d
       new_network_available = FALSE;
5c320d
       new_network_metered = FALSE;
5c320d
-- 
5c320d
2.33.1
5c320d
5c320d
From 5b4e6f9813cf90c690d8974635b0aeff8f5d2c5d Mon Sep 17 00:00:00 2001
5c320d
From: Fabrice Bellet <fabrice@bellet.info>
5c320d
Date: Mon, 29 Apr 2019 12:05:54 +0000
5c320d
Subject: [PATCH 3/9] gnetworkmonitornm: Fix network available detection
5c320d
5c320d
The network-available property can be asserted by querying the NMState
5c320d
describing the current overval network state, instead of the
5c320d
NMConnectivityState. The advantage of the NMState is that is reflects
5c320d
immediately the network state modification, while the connectivity
5c320d
state is tested at a fixed frequency.
5c320d
---
5c320d
 gio/gnetworkmonitornm.c | 39 ++++++++++++++++++++++++++++++++++++---
5c320d
 1 file changed, 36 insertions(+), 3 deletions(-)
5c320d
5c320d
diff --git a/gio/gnetworkmonitornm.c b/gio/gnetworkmonitornm.c
5c320d
index 4e2a35e8a..7bb480f54 100644
5c320d
--- a/gio/gnetworkmonitornm.c
5c320d
+++ b/gio/gnetworkmonitornm.c
5c320d
@@ -52,6 +52,19 @@ typedef enum {
5c320d
   NM_CONNECTIVITY_FULL
5c320d
 } NMConnectivityState;
5c320d
 
5c320d
+/* Copied from https://developer.gnome.org/libnm-util/stable/libnm-util-NetworkManager.html#NMState;
5c320d
+ * used inline to avoid a NetworkManager dependency from GLib. */
5c320d
+typedef enum {
5c320d
+  NM_STATE_UNKNOWN          = 0,
5c320d
+  NM_STATE_ASLEEP           = 10,
5c320d
+  NM_STATE_DISCONNECTED     = 20,
5c320d
+  NM_STATE_DISCONNECTING    = 30,
5c320d
+  NM_STATE_CONNECTING       = 40,
5c320d
+  NM_STATE_CONNECTED_LOCAL  = 50,
5c320d
+  NM_STATE_CONNECTED_SITE   = 60,
5c320d
+  NM_STATE_CONNECTED_GLOBAL = 70,
5c320d
+} NMState;
5c320d
+
5c320d
 struct _GNetworkMonitorNMPrivate
5c320d
 {
5c320d
   GDBusProxy *proxy;
5c320d
@@ -155,11 +168,19 @@ sync_properties (GNetworkMonitorNM *nm,
5c320d
                  gboolean           emit_signals)
5c320d
 {
5c320d
   GVariant *v;
5c320d
+  NMState nm_state;
5c320d
   NMConnectivityState nm_connectivity;
5c320d
   gboolean new_network_available;
5c320d
   gboolean new_network_metered;
5c320d
   GNetworkConnectivity new_connectivity;
5c320d
 
5c320d
+  v = g_dbus_proxy_get_cached_property (nm->priv->proxy, "State");
5c320d
+  if (!v)
5c320d
+    return;
5c320d
+
5c320d
+  nm_state = g_variant_get_uint32 (v);
5c320d
+  g_variant_unref (v);
5c320d
+
5c320d
   v = g_dbus_proxy_get_cached_property (nm->priv->proxy, "Connectivity");
5c320d
   if (!v)
5c320d
     return;
5c320d
@@ -167,14 +188,26 @@ sync_properties (GNetworkMonitorNM *nm,
5c320d
   nm_connectivity = g_variant_get_uint32 (v);
5c320d
   g_variant_unref (v);
5c320d
 
5c320d
-  if (nm_connectivity == NM_CONNECTIVITY_UNKNOWN ||
5c320d
-      nm_connectivity == NM_CONNECTIVITY_NONE)
5c320d
+  if (nm_state <= NM_STATE_CONNECTED_LOCAL)
5c320d
     {
5c320d
       new_network_available = FALSE;
5c320d
       new_network_metered = FALSE;
5c320d
       new_connectivity = G_NETWORK_CONNECTIVITY_LOCAL;
5c320d
     }
5c320d
-  else
5c320d
+  else if (nm_state <= NM_STATE_CONNECTED_SITE)
5c320d
+    {
5c320d
+      new_network_available = FALSE;
5c320d
+      new_network_metered = FALSE;
5c320d
+      if (nm_connectivity == NM_CONNECTIVITY_PORTAL)
5c320d
+        {
5c320d
+          new_connectivity = G_NETWORK_CONNECTIVITY_PORTAL;
5c320d
+        }
5c320d
+      else
5c320d
+        {
5c320d
+          new_connectivity = G_NETWORK_CONNECTIVITY_LIMITED;
5c320d
+        }
5c320d
+    }
5c320d
+  else /* nm_state == NM_STATE_CONNECTED_FULL */
5c320d
     {
5c320d
 
5c320d
       /* this is only available post NM 1.0 */
5c320d
-- 
5c320d
2.33.1
5c320d
5c320d
From 96fba295771d600e4f0f522400b2fb9b1ff42cee Mon Sep 17 00:00:00 2001
5c320d
From: Philip Withnall <withnall@endlessm.com>
5c320d
Date: Fri, 31 May 2019 11:19:07 +0100
5c320d
Subject: [PATCH 4/9] gnetworkmonitornm: Consider NM_STATE_CONNECTED_SITE to be
5c320d
 available
5c320d
5c320d
`NM_STATE_CONNECTED_SITE` is documented to mean that a default route is
5c320d
available, but that the internet connectivity check failed. A default
5c320d
route being available is compatible with the documentation for
5c320d
GNetworkMonitor:network-available, which should be true if the system
5c320d
has a default route for at least one of IPv4 and IPv6.
5c320d
5c320d
https://developer.gnome.org/NetworkManager/stable/nm-dbus-types.html
5c320d
5c320d
Signed-off-by: Philip Withnall <withnall@endlessm.com>
5c320d
5c320d
Fixes: #1788
5c320d
---
5c320d
 gio/gnetworkmonitornm.c | 2 +-
5c320d
 1 file changed, 1 insertion(+), 1 deletion(-)
5c320d
5c320d
diff --git a/gio/gnetworkmonitornm.c b/gio/gnetworkmonitornm.c
5c320d
index 7bb480f54..9013fd49c 100644
5c320d
--- a/gio/gnetworkmonitornm.c
5c320d
+++ b/gio/gnetworkmonitornm.c
5c320d
@@ -196,7 +196,7 @@ sync_properties (GNetworkMonitorNM *nm,
5c320d
     }
5c320d
   else if (nm_state <= NM_STATE_CONNECTED_SITE)
5c320d
     {
5c320d
-      new_network_available = FALSE;
5c320d
+      new_network_available = TRUE;
5c320d
       new_network_metered = FALSE;
5c320d
       if (nm_connectivity == NM_CONNECTIVITY_PORTAL)
5c320d
         {
5c320d
-- 
5c320d
2.33.1
5c320d
5c320d
From 74e5f472c838115f0ba19ac501805cb5b2ca837f Mon Sep 17 00:00:00 2001
5c320d
From: Bastien Nocera <hadess@hadess.net>
5c320d
Date: Mon, 29 Jul 2019 17:25:21 +0200
5c320d
Subject: [PATCH 5/9] gnetworkmonitornm: Disconnect g-signal from proxy
5c320d
5c320d
So that we're sure never to receive a signal if something is keeping the
5c320d
proxy alive.
5c320d
---
5c320d
 gio/gnetworkmonitornm.c | 12 ++++++++++--
5c320d
 1 file changed, 10 insertions(+), 2 deletions(-)
5c320d
5c320d
diff --git a/gio/gnetworkmonitornm.c b/gio/gnetworkmonitornm.c
5c320d
index 9013fd49c..52073fac9 100644
5c320d
--- a/gio/gnetworkmonitornm.c
5c320d
+++ b/gio/gnetworkmonitornm.c
5c320d
@@ -68,6 +68,7 @@ typedef enum {
5c320d
 struct _GNetworkMonitorNMPrivate
5c320d
 {
5c320d
   GDBusProxy *proxy;
5c320d
+  guint signal_id;
5c320d
 
5c320d
   GNetworkConnectivity connectivity;
5c320d
   gboolean network_available;
5c320d
@@ -360,8 +361,8 @@ g_network_monitor_nm_initable_init (GInitable     *initable,
5c320d
       return FALSE;
5c320d
     }
5c320d
 
5c320d
-  g_signal_connect (G_OBJECT (proxy), "g-signal",
5c320d
-                    G_CALLBACK (proxy_signal_cb), nm);
5c320d
+  nm->priv->signal_id = g_signal_connect (G_OBJECT (proxy), "g-signal",
5c320d
+                                          G_CALLBACK (proxy_signal_cb), nm);
5c320d
   nm->priv->proxy = proxy;
5c320d
   sync_properties (nm, FALSE);
5c320d
 
5c320d
@@ -373,6 +374,13 @@ g_network_monitor_nm_finalize (GObject *object)
5c320d
 {
5c320d
   GNetworkMonitorNM *nm = G_NETWORK_MONITOR_NM (object);
5c320d
 
5c320d
+  if (nm->priv->proxy != NULL &&
5c320d
+      nm->priv->signal_id != 0)
5c320d
+    {
5c320d
+      g_signal_handler_disconnect (nm->priv->proxy,
5c320d
+                                   nm->priv->signal_id);
5c320d
+      nm->priv->signal_id = 0;
5c320d
+    }
5c320d
   g_clear_object (&nm->priv->proxy);
5c320d
 
5c320d
   G_OBJECT_CLASS (g_network_monitor_nm_parent_class)->finalize (object);
5c320d
-- 
5c320d
2.33.1
5c320d
5c320d
From eeaf1de6e695afd971d67137caa8e39e1c1267df Mon Sep 17 00:00:00 2001
5c320d
From: Bastien Nocera <hadess@hadess.net>
5c320d
Date: Mon, 29 Jul 2019 17:26:20 +0200
5c320d
Subject: [PATCH 6/9] gnetworkmonitornm: Arguments to g-signal's callback are
5c320d
 const
5c320d
5c320d
---
5c320d
 gio/gnetworkmonitornm.c | 4 ++--
5c320d
 1 file changed, 2 insertions(+), 2 deletions(-)
5c320d
5c320d
diff --git a/gio/gnetworkmonitornm.c b/gio/gnetworkmonitornm.c
5c320d
index 52073fac9..479653a51 100644
5c320d
--- a/gio/gnetworkmonitornm.c
5c320d
+++ b/gio/gnetworkmonitornm.c
5c320d
@@ -268,8 +268,8 @@ update_cached_property (GDBusProxy   *proxy,
5c320d
 
5c320d
 static void
5c320d
 proxy_signal_cb (GDBusProxy        *proxy,
5c320d
-                 gchar             *sender_name,
5c320d
-                 gchar             *signal_name,
5c320d
+                 const gchar       *sender_name,
5c320d
+                 const gchar       *signal_name,
5c320d
                  GVariant          *parameters,
5c320d
                  GNetworkMonitorNM *nm)
5c320d
 {
5c320d
-- 
5c320d
2.33.1
5c320d
5c320d
From 46d70700c85e4419942c8a3d08bd0bf842702c4a Mon Sep 17 00:00:00 2001
5c320d
From: Bastien Nocera <hadess@hadess.net>
5c320d
Date: Mon, 29 Jul 2019 17:26:47 +0200
5c320d
Subject: [PATCH 7/9] gnetworkmonitornm: Remove double-space
5c320d
5c320d
---
5c320d
 gio/gnetworkmonitornm.c | 2 +-
5c320d
 1 file changed, 1 insertion(+), 1 deletion(-)
5c320d
5c320d
diff --git a/gio/gnetworkmonitornm.c b/gio/gnetworkmonitornm.c
5c320d
index 479653a51..5a36a0ba1 100644
5c320d
--- a/gio/gnetworkmonitornm.c
5c320d
+++ b/gio/gnetworkmonitornm.c
5c320d
@@ -391,7 +391,7 @@ g_network_monitor_nm_class_init (GNetworkMonitorNMClass *nl_class)
5c320d
 {
5c320d
   GObjectClass *gobject_class = G_OBJECT_CLASS (nl_class);
5c320d
 
5c320d
-  gobject_class->finalize  = g_network_monitor_nm_finalize;
5c320d
+  gobject_class->finalize = g_network_monitor_nm_finalize;
5c320d
   gobject_class->get_property = g_network_monitor_nm_get_property;
5c320d
 
5c320d
   g_object_class_override_property (gobject_class, PROP_NETWORK_AVAILABLE, "network-available");
5c320d
-- 
5c320d
2.33.1
5c320d
5c320d
From 72291aac3dac7a8ed4c85eb41608f3f5f9ad7681 Mon Sep 17 00:00:00 2001
5c320d
From: Julian Andres Klode <julian.klode@canonical.com>
5c320d
Date: Tue, 12 Oct 2021 12:01:50 +0200
5c320d
Subject: [PATCH 8/9] gnetworkmonitornm: Stop using removed PropertiesChanged
5c320d
 signal
5c320d
5c320d
Use the org.freedesktop.DBus.Properties interface to listen
5c320d
to PropertiesChanged signals on /org/freedesktop/NetworkManager.
5c320d
5c320d
NetworkManager used to provide its own legacy PropertiesChanged
5c320d
signal, but that was dropped in
5c320d
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/853
5c320d
5c320d
This requires NetworkManager >= 1.2 (2016)
5c320d
5c320d
Fixes: #2505
5c320d
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1946196
5c320d
---
5c320d
 gio/gnetworkmonitornm.c | 29 +++++++----------------------
5c320d
 1 file changed, 7 insertions(+), 22 deletions(-)
5c320d
5c320d
diff --git a/gio/gnetworkmonitornm.c b/gio/gnetworkmonitornm.c
5c320d
index 5a36a0ba1..6a6d1d666 100644
5c320d
--- a/gio/gnetworkmonitornm.c
5c320d
+++ b/gio/gnetworkmonitornm.c
5c320d
@@ -267,29 +267,14 @@ update_cached_property (GDBusProxy   *proxy,
5c320d
 }
5c320d
 
5c320d
 static void
5c320d
-proxy_signal_cb (GDBusProxy        *proxy,
5c320d
-                 const gchar       *sender_name,
5c320d
-                 const gchar       *signal_name,
5c320d
-                 GVariant          *parameters,
5c320d
-                 GNetworkMonitorNM *nm)
5c320d
+proxy_properties_changed_cb (GDBusProxy        *proxy,
5c320d
+                             GVariant          *changed_properties,
5c320d
+                             GStrv              invalidated_properties,
5c320d
+                             GNetworkMonitorNM *nm)
5c320d
 {
5c320d
-  GVariant *asv;
5c320d
   GVariantDict *dict;
5c320d
 
5c320d
-  if (g_strcmp0 (signal_name, "PropertiesChanged") != 0)
5c320d
-    return;
5c320d
-
5c320d
-  g_variant_get (parameters, "(@a{sv})", &asv;;
5c320d
-  if (!asv)
5c320d
-    return;
5c320d
-
5c320d
-  dict = g_variant_dict_new (asv);
5c320d
-  g_variant_unref (asv);
5c320d
-  if (!dict)
5c320d
-    {
5c320d
-      g_warning ("Failed to handle PropertiesChanged signal from NetworkManager");
5c320d
-      return;
5c320d
-    }
5c320d
+  dict = g_variant_dict_new (changed_properties);
5c320d
 
5c320d
   update_cached_property (nm->priv->proxy, "Connectivity", dict);
5c320d
 
5c320d
@@ -361,8 +346,8 @@ g_network_monitor_nm_initable_init (GInitable     *initable,
5c320d
       return FALSE;
5c320d
     }
5c320d
 
5c320d
-  nm->priv->signal_id = g_signal_connect (G_OBJECT (proxy), "g-signal",
5c320d
-                                          G_CALLBACK (proxy_signal_cb), nm);
5c320d
+  nm->priv->signal_id = g_signal_connect (G_OBJECT (proxy), "g-properties-changed",
5c320d
+                                          G_CALLBACK (proxy_properties_changed_cb), nm);
5c320d
   nm->priv->proxy = proxy;
5c320d
   sync_properties (nm, FALSE);
5c320d
 
5c320d
-- 
5c320d
2.33.1
5c320d
5c320d
From 3bafff71d7588285763f603b23c830722a2169d1 Mon Sep 17 00:00:00 2001
5c320d
From: Julian Andres Klode <julian.klode@canonical.com>
5c320d
Date: Tue, 12 Oct 2021 17:31:42 +0200
5c320d
Subject: [PATCH 9/9] gnetworkmonitornm: Do not re-update cached property
5c320d
5c320d
GDBusProxy already takes care of updating the cached property
5c320d
before emitting the signal, so there is no need to do this
5c320d
a second time ourselves.
5c320d
---
5c320d
 gio/gnetworkmonitornm.c | 22 ----------------------
5c320d
 1 file changed, 22 deletions(-)
5c320d
5c320d
diff --git a/gio/gnetworkmonitornm.c b/gio/gnetworkmonitornm.c
5c320d
index 6a6d1d666..a8040fb36 100644
5c320d
--- a/gio/gnetworkmonitornm.c
5c320d
+++ b/gio/gnetworkmonitornm.c
5c320d
@@ -252,34 +252,12 @@ sync_properties (GNetworkMonitorNM *nm,
5c320d
     }
5c320d
 }
5c320d
 
5c320d
-static void
5c320d
-update_cached_property (GDBusProxy   *proxy,
5c320d
-                        const char   *property_name,
5c320d
-                        GVariantDict *dict)
5c320d
-{
5c320d
-  GVariant *v;
5c320d
-
5c320d
-  v = g_variant_dict_lookup_value (dict, property_name, NULL);
5c320d
-  if (!v)
5c320d
-    return;
5c320d
-  g_dbus_proxy_set_cached_property (proxy, property_name, v);
5c320d
-  g_variant_unref (v);
5c320d
-}
5c320d
-
5c320d
 static void
5c320d
 proxy_properties_changed_cb (GDBusProxy        *proxy,
5c320d
                              GVariant          *changed_properties,
5c320d
                              GStrv              invalidated_properties,
5c320d
                              GNetworkMonitorNM *nm)
5c320d
 {
5c320d
-  GVariantDict *dict;
5c320d
-
5c320d
-  dict = g_variant_dict_new (changed_properties);
5c320d
-
5c320d
-  update_cached_property (nm->priv->proxy, "Connectivity", dict);
5c320d
-
5c320d
-  g_variant_dict_unref (dict);
5c320d
-
5c320d
   sync_properties (nm, TRUE);
5c320d
 }
5c320d
 
5c320d
-- 
5c320d
2.33.1