After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 664562 - captive wifi portal support for GNetworkMonitor
captive wifi portal support for GNetworkMonitor
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: network
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
: 730876 (view as bug list)
Depends on:
Blocks: 691080 725148
 
 
Reported: 2011-11-22 13:50 UTC by Dan Winship
Modified: 2014-12-08 08:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gio: add network connectivity state to GNetworkMonitor (10.40 KB, patch)
2014-12-03 17:39 UTC, Bastien Nocera
none Details | Review
gio: Add GNetworkMonitor impl based on NetworkManager (11.73 KB, patch)
2014-12-03 17:39 UTC, Bastien Nocera
none Details | Review
gio: Add GNetworkMonitor impl based on NetworkManager (12.76 KB, patch)
2014-12-03 17:41 UTC, Bastien Nocera
none Details | Review
gio: add network connectivity state to GNetworkMonitor (10.46 KB, patch)
2014-12-03 17:51 UTC, Bastien Nocera
reviewed Details | Review
gio: Add GNetworkMonitor impl based on NetworkManager (12.76 KB, patch)
2014-12-03 17:51 UTC, Bastien Nocera
none Details | Review
gio: Add GNetworkMonitor impl based on NetworkManager (12.88 KB, patch)
2014-12-03 18:13 UTC, Bastien Nocera
none Details | Review
gio: Correct the "available in" for GNetworkMonitor (1.69 KB, patch)
2014-12-04 11:32 UTC, Bastien Nocera
committed Details | Review
gio: add network connectivity state to GNetworkMonitor (10.70 KB, patch)
2014-12-04 11:32 UTC, Bastien Nocera
accepted-commit_now Details | Review
gio: Add GNetworkMonitor impl based on NetworkManager (12.88 KB, patch)
2014-12-04 11:32 UTC, Bastien Nocera
none Details | Review
gio: Add GNetworkMonitor impl based on NetworkManager (13.62 KB, patch)
2014-12-04 22:32 UTC, Bastien Nocera
reviewed Details | Review
gio: Add GNetworkMonitor impl based on NetworkManager (13.62 KB, patch)
2014-12-05 14:40 UTC, Bastien Nocera
none Details | Review
gio: add network connectivity state to GNetworkMonitor (10.73 KB, patch)
2014-12-05 16:26 UTC, Bastien Nocera
committed Details | Review
gio: Add GNetworkMonitor impl based on NetworkManager (13.16 KB, patch)
2014-12-05 16:26 UTC, Bastien Nocera
committed Details | Review

Description Dan Winship 2011-11-22 13:50:27 UTC
GNetworkMonitor needs to be able to indicate "you are online but stuck behind a captive portal that wants to you log in / pay / accept ToS". This probably requires some sort of extension-pointing; either implementing our own test by using libsoup in glib-networking, or else piggybacking on NetworkManager/ConnMan/etc's existing tests.
Comment 1 Pavel Simerda 2013-01-21 16:59:11 UTC
I was thinking about creating a connectivity status library that would use NetworkManager by default and Netlink if it's not available. The latter part could be pretty much based on NetworkManager's NMPlatform while the first is simple dbus interfacing.
Comment 2 Dan Winship 2013-01-21 17:35:09 UTC
Yeah, GNetworkMonitor already uses netlink to check connectivity. It just doesn't try to deal with captive portal detection. And I think we're fine with requiring NM to be around to figure that out.
Comment 3 Simon McVittie 2013-09-04 12:02:34 UTC
A NetworkManager GNetworkMonitor with this information would be great to have. It seems reasonable to expect that non-NM users need to implement a GNetworkMonitor for similar information.

ConnMan detects captive portals, but if I'm reading the source correctly, it seems to distinguish via the difference between "ready" and "online", both of which are treated as online states by <https://github.com/jukkar/connman-network-monitor/>. Unfortunately, according to the submitter of <http://cgit.freedesktop.org/telepathy/telepathy-mission-control/commit/?id=393d6c8b6e64c487c8a426443d3b285c35093dce>, "ready" can also mean "behind a proxy", which we want to treat as online (at least in applications with proxy support).
Comment 4 Dan Winship 2013-09-08 18:04:03 UTC
We don't generally want apps to think too hard about portals; they should mostly treat it the same as "not connected". There should be a single service (ie, the shell) that worries about informing the user about what's going on, rather than having every app simultaneously telling the user they need to log in.

We may want to expose it as a "partial connectivity" state though, especially since some portals will allow some traffic through, but block others.

(Currently GNetworkMonitor reports behind-a-portal as "connected", so we need GNetworkMonitor work either way.)
Comment 5 Matthew Barnes 2014-05-28 14:34:31 UTC
*** Bug 730876 has been marked as a duplicate of this bug. ***
Comment 6 Bastien Nocera 2014-12-03 17:39:28 UTC
Created attachment 292077 [details] [review]
gio: add network connectivity state to GNetworkMonitor

Add a property to GNetworkMonitor indicating the level of network
connectivity: none/local, limited, stuck behind a portal, or full.

The default implementation just returns none or full depending on the
value of is-available.
Comment 7 Bastien Nocera 2014-12-03 17:39:35 UTC
Created attachment 292078 [details] [review]
gio: Add GNetworkMonitor impl based on NetworkManager

Which implements the new GNetworkConnectivity property.
Comment 8 Bastien Nocera 2014-12-03 17:41:52 UTC
Created attachment 292079 [details] [review]
gio: Add GNetworkMonitor impl based on NetworkManager

Which implements the new GNetworkConnectivity property.
Comment 9 Bastien Nocera 2014-12-03 17:51:28 UTC
Created attachment 292084 [details] [review]
gio: add network connectivity state to GNetworkMonitor

Add a property to GNetworkMonitor indicating the level of network
connectivity: none/local, limited, stuck behind a portal, or full.

The default implementation just returns none or full depending on the
value of is-available.
Comment 10 Bastien Nocera 2014-12-03 17:51:34 UTC
Created attachment 292085 [details] [review]
gio: Add GNetworkMonitor impl based on NetworkManager

Which implements the new GNetworkConnectivity property.
Comment 11 Bastien Nocera 2014-12-03 18:13:09 UTC
Created attachment 292089 [details] [review]
gio: Add GNetworkMonitor impl based on NetworkManager

Which implements the new GNetworkConnectivity property.
Comment 12 Bastien Nocera 2014-12-03 18:18:47 UTC
Last version removes our NM monitor's handling of the "network-changed" signal, and instead we become a subclass of the netlink monitor, init it, and let it handle that signal. We only take care of the 2 properties which we can handle properly.
Comment 13 Matthias Clasen 2014-12-03 20:20:18 UTC
Review of attachment 292084 [details] [review]:

::: gio/gnetworkmonitor.c
@@ +134,3 @@
+  g_object_get (G_OBJECT (monitor), "connectivity", &connectivity, NULL);
+
+  if (connectivity == (GNetworkConnectivity) -1)

This looks questionable, given that the property type is enum, and -1 is not one of the enum values.
Suggest to add G_NETWORK_CONNECTIVITY_UNKNOWN or make the property an it with suitable range.

::: gio/gnetworkmonitor.h
@@ +70,3 @@
+GNetworkMonitor      *g_network_monitor_get_default           (void);
+
+GLIB_AVAILABLE_IN_2_32

This should probably be a separate bugfix (GLIB_AVAILABLE_IN_ALL -> GLIB_AVAILABLE_IN_2_32)
Comment 14 Bastien Nocera 2014-12-04 10:36:20 UTC
(In reply to comment #13)
> Review of attachment 292084 [details] [review]:
> 
> ::: gio/gnetworkmonitor.c
> @@ +134,3 @@
> +  g_object_get (G_OBJECT (monitor), "connectivity", &connectivity, NULL);
> +
> +  if (connectivity == (GNetworkConnectivity) -1)
> 
> This looks questionable, given that the property type is enum, and -1 is not
> one of the enum values.
> Suggest to add G_NETWORK_CONNECTIVITY_UNKNOWN or make the property an it with
> suitable range.

This is trying to catch the fact that the monitor module we're using might not implement the connectivity property. I reworked this differently, using g_object_get_property().

> ::: gio/gnetworkmonitor.h
> @@ +70,3 @@
> +GNetworkMonitor      *g_network_monitor_get_default           (void);
> +
> +GLIB_AVAILABLE_IN_2_32
> 
> This should probably be a separate bugfix (GLIB_AVAILABLE_IN_ALL ->
> GLIB_AVAILABLE_IN_2_32)

Sure.
Comment 15 Bastien Nocera 2014-12-04 11:24:19 UTC
(In reply to comment #14)
> (In reply to comment #13)
> > Review of attachment 292084 [details] [review] [details]:
> > 
> > ::: gio/gnetworkmonitor.c
> > @@ +134,3 @@
> > +  g_object_get (G_OBJECT (monitor), "connectivity", &connectivity, NULL);
> > +
> > +  if (connectivity == (GNetworkConnectivity) -1)
> > 
> > This looks questionable, given that the property type is enum, and -1 is not
> > one of the enum values.
> > Suggest to add G_NETWORK_CONNECTIVITY_UNKNOWN or make the property an it with
> > suitable range.
> 
> This is trying to catch the fact that the monitor module we're using might not
> implement the connectivity property. I reworked this differently, using
> g_object_get_property().

Actually, it cannot be done like that. I tried using g_param_spec_get_redirect_target() but given that the base network monitor interface already implements this in exactly the same way in that patch, we would always have something implementing "connectivity" whatever the platform. So this fallback is just unnecessary.
Comment 16 Bastien Nocera 2014-12-04 11:32:09 UTC
Created attachment 292119 [details] [review]
gio: Correct the "available in" for GNetworkMonitor

They were marked as available in all versions when the main interface
was actually added in glib 2.32.
Comment 17 Bastien Nocera 2014-12-04 11:32:16 UTC
Created attachment 292120 [details] [review]
gio: add network connectivity state to GNetworkMonitor

Add a property to GNetworkMonitor indicating the level of network
connectivity: none/local, limited, stuck behind a portal, or full.

The default implementation just returns none or full depending on the
value of is-available.
Comment 18 Bastien Nocera 2014-12-04 11:32:22 UTC
Created attachment 292122 [details] [review]
gio: Add GNetworkMonitor impl based on NetworkManager

Which implements the new GNetworkConnectivity property.
Comment 19 Pavel Simerda 2014-12-04 16:56:14 UTC
Nowadays we detect captive portals with dnssec-trigger (daemon) in distributions that use it becase dnssec-trigger (panel) needs to ask the user whether he wants to enter hotspot signon mode. For dnssec-trigger, the hotspot signon mode is currently implemented as a permissive mode where DNSSEC is turned off.

If I understand correctly, when the integration between dnssec-trigger and NetworkManager reaches the level that NM will know the status od dnssec-trigger and will update its status accordingly, gnome network monitor will handle that, right?
Comment 20 Bastien Nocera 2014-12-04 17:13:55 UTC
(In reply to comment #19)
> Nowadays we detect captive portals with dnssec-trigger (daemon) in
> distributions that use it becase dnssec-trigger (panel) needs to ask the user
> whether he wants to enter hotspot signon mode. For dnssec-trigger, the hotspot
> signon mode is currently implemented as a permissive mode where DNSSEC is
> turned off.
> 
> If I understand correctly, when the integration between dnssec-trigger and
> NetworkManager reaches the level that NM will know the status od dnssec-trigger
> and will update its status accordingly, gnome network monitor will handle that,
> right?

The code above doesn't care one bit how it's implemented. This isn't a system API, it's an application API, and knowing how the portal was detected is therefore uninteresting. So the answer to your question is yes. It will handle it. And it's GNetworkMonitor, not GNOME's.
Comment 21 Matthias Clasen 2014-12-04 17:46:05 UTC
Review of attachment 292119 [details] [review]:

sure
Comment 22 Matthias Clasen 2014-12-04 17:48:26 UTC
Review of attachment 292120 [details] [review]:

Looks good to me.
Comment 23 Matthias Clasen 2014-12-04 17:51:28 UTC
Review of attachment 292122 [details] [review]:

is the idea that we use this implementation by default ? or only in applications that specifically care about portals ? if so, which ones are those ?
Comment 24 Bastien Nocera 2014-12-04 21:21:23 UTC
(In reply to comment #23)
> Review of attachment 292122 [details] [review]:
> 
> is the idea that we use this implementation by default ?

Yes.

> or only in
> applications that specifically care about portals ? if so, which ones are those
> ?

This is useful for applications to inform the user that they're not fully connected to the internet for example. I agree that the "portal" step isn't that useful for applications, except that it's a good idea for applications that use the network to get as much context as possible. If you have an application opened and you connect to the network, you'll see the status transitioning from "access to local network", "portal", full internet access". This means that you can get yourself ready in the "portal" case for when you get to "full internet access", for example.

It could be useful to show the connection level in gnome-control-center as well. It's not so useful in gnome-shell, obviously, as you need more plumbing to show the captive portal window, etc. so it's better to talk to NM directly.
Comment 25 Bastien Nocera 2014-12-04 22:32:45 UTC
Created attachment 292155 [details] [review]
gio: Add GNetworkMonitor impl based on NetworkManager

Which implements the new GNetworkConnectivity property.
Comment 26 Bastien Nocera 2014-12-04 22:34:39 UTC
Updated patch removes a stray debug print, and fixes the fact that NM doesn't follow standard D-Bus spec for properties.
Comment 27 Bastien Nocera 2014-12-04 23:02:48 UTC
Dan, one thing about the GNetworkConnectivity enum I didn't really like:
There's no difference between 1) not connected to any network, cable unplugged, wifi off and 2) cable plugged in to a local LAN with no way out to the internet, as far as GNetworkConnectivity is concerned.

Applications would need to combine network-available and connectivity to get that information, eg:
1) network_available == FALSE && connectivity == LOCAL
2) network_available == TRUE && connectivity == LOCAL

Should we add a new enum member that combines this information so applications can just monitor "connectivity"?
Comment 28 Dan Winship 2014-12-05 14:22:19 UTC
Comment on attachment 292155 [details] [review]
gio: Add GNetworkMonitor impl based on NetworkManager

>+G_DEFINE_TYPE_WITH_CODE (GNetworkMonitorNm, g_network_monitor_nm, G_TYPE_NETWORK_MONITOR_NETLINK,

The normal GLib/Gtk+ capitalization rule (retroactively defined so as to be compatible with the most existing symbols) is "two-letter acronyms have both letters capitalized [IO, UI, IP, etc], longer acronyms are initial caps only". So "GNetworkMonitorNM".

>+  v = g_dbus_proxy_get_cached_property (nm->priv->proxy, "PrimaryConnection");

Does it need to keep track of network-available itself? Can't it just let the base class do it?

Note that only a connection that has the default route can be PrimaryConnection, so if you have a connection that intentionally configures only link-local connectivity, and that's the only active connection, then there will be no PrimaryConnection.

>+  if (primary_connection == NULL ||
>+      *primary_connection == '\0' ||

object-path-valued properties can't be "". (Or is that just a dbus-glib-ism?) Either way, when there's no PrimaryConnection, NM will set the property to "/".

>+  dict = g_variant_dict_new (asv);
>+  if (!dict) {
>+    g_warning ("Failed to handle PropertiesChanged signal from NetworkManager");
>+    return;
>+  }

brace style

>+struct _GNetworkMonitorNmClass {
>+  GNetworkMonitorNetlinkClass parent_class;
>+
>+  /*< private >*/
>+  /* Padding for future expansion */
>+  gpointer padding[8];

You don't need that since it's not an exported type.
Comment 29 Dan Winship 2014-12-05 14:36:08 UTC
(In reply to comment #26)
> Updated patch removes a stray debug print, and fixes the fact that NM doesn't
> follow standard D-Bus spec for properties.

Yeah, that will be fixed once the daemon is ported to GDBus.

(In reply to comment #27)
> Dan, one thing about the GNetworkConnectivity enum I didn't really like:
> There's no difference between 1) not connected to any network, cable unplugged,
> wifi off and 2) cable plugged in to a local LAN with no way out to the
> internet, as far as GNetworkConnectivity is concerned.

I think the reason I didn't distinguish those is because in order to get it right, you have to be able to recognize that virbr0 isn't "a local LAN with no way out to the internet" (unless it has a physical device as one of its slaves...). Maybe this is something NM should be figuring out for you. (Though it's too late for that to happen in NM 1.0 at this point.)
Comment 30 Bastien Nocera 2014-12-05 14:40:59 UTC
Created attachment 292191 [details] [review]
gio: Add GNetworkMonitor impl based on NetworkManager

Which implements the new GNetworkConnectivity property.
Comment 31 Bastien Nocera 2014-12-05 14:42:08 UTC
(In reply to comment #28)
> (From update of attachment 292155 [details] [review])
> >+G_DEFINE_TYPE_WITH_CODE (GNetworkMonitorNm, g_network_monitor_nm, G_TYPE_NETWORK_MONITOR_NETLINK,
> 
> The normal GLib/Gtk+ capitalization rule (retroactively defined so as to be
> compatible with the most existing symbols) is "two-letter acronyms have both
> letters capitalized [IO, UI, IP, etc], longer acronyms are initial caps only".
> So "GNetworkMonitorNM".

Done.

> >+  v = g_dbus_proxy_get_cached_property (nm->priv->proxy, "PrimaryConnection");
> 
> Does it need to keep track of network-available itself? Can't it just let the
> base class do it?

I wanted to be sure that the status would be synchronised, and to help with comment 27.

> Note that only a connection that has the default route can be
> PrimaryConnection, so if you have a connection that intentionally configures
> only link-local connectivity, and that's the only active connection, then there
> will be no PrimaryConnection.
> 
> >+  if (primary_connection == NULL ||
> >+      *primary_connection == '\0' ||
> 
> object-path-valued properties can't be "". (Or is that just a dbus-glib-ism?)
> Either way, when there's no PrimaryConnection, NM will set the property to "/".

I've removed the PrimaryConnection handling, and I'm only using NM's connectivity property, which is more fine-grained than our version.

> >+  dict = g_variant_dict_new (asv);
> >+  if (!dict) {
> >+    g_warning ("Failed to handle PropertiesChanged signal from NetworkManager");
> >+    return;
> >+  }
> 
> brace style

Fixed.

> >+struct _GNetworkMonitorNmClass {
> >+  GNetworkMonitorNetlinkClass parent_class;
> >+
> >+  /*< private >*/
> >+  /* Padding for future expansion */
> >+  gpointer padding[8];
> 
> You don't need that since it's not an exported type.

Removed.
Comment 32 Bastien Nocera 2014-12-05 14:45:28 UTC
(In reply to comment #29)
> (In reply to comment #26)
> > Updated patch removes a stray debug print, and fixes the fact that NM doesn't
> > follow standard D-Bus spec for properties.
> 
> Yeah, that will be fixed once the daemon is ported to GDBus.

That's fine, I should have tested it, is all.

> (In reply to comment #27)
> > Dan, one thing about the GNetworkConnectivity enum I didn't really like:
> > There's no difference between 1) not connected to any network, cable unplugged,
> > wifi off and 2) cable plugged in to a local LAN with no way out to the
> > internet, as far as GNetworkConnectivity is concerned.
> 
> I think the reason I didn't distinguish those is because in order to get it
> right, you have to be able to recognize that virbr0 isn't "a local LAN with no
> way out to the internet" (unless it has a physical device as one of its
> slaves...). Maybe this is something NM should be figuring out for you. (Though
> it's too late for that to happen in NM 1.0 at this point.)

That's an edge case, probably. I think NM should be handling this, the question is whether we want to expand the enum right now, or try and do that later and have it be in the wrong order.
Comment 33 Dan Winship 2014-12-05 15:02:00 UTC
(In reply to comment #32)
> > I think the reason I didn't distinguish those is because in order to get it
> > right, you have to be able to recognize that virbr0 isn't "a local LAN with no
> > way out to the internet" (unless it has a physical device as one of its
> > slaves...). Maybe this is something NM should be figuring out for you. (Though
> > it's too late for that to happen in NM 1.0 at this point.)
> 
> That's an edge case, probably.

Well, it's not. virbr0 is always up on Fedora, so if you treat "virbr0 is up but doesn't have default route" the same as "eth0 is up but doesn't have default route", then you'll never report the "absolutely no connectivity" case.

> I think NM should be handling this, the question
> is whether we want to expand the enum right now, or try and do that later and
> have it be in the wrong order.

You could leave a hole in the numbering...
Comment 34 Bastien Nocera 2014-12-05 16:26:42 UTC
Created attachment 292201 [details] [review]
gio: add network connectivity state to GNetworkMonitor

Add a property to GNetworkMonitor indicating the level of network
connectivity: none/local, limited, stuck behind a portal, or full.

The default implementation just returns none or full depending on the
value of is-available.
Comment 35 Bastien Nocera 2014-12-05 16:26:50 UTC
Created attachment 292202 [details] [review]
gio: Add GNetworkMonitor impl based on NetworkManager

Which implements the new GNetworkConnectivity property.
Comment 36 Bastien Nocera 2014-12-05 16:29:16 UTC
Comment 30 wasn't actually an updated patch... I also added a hole in the enum numbering. Good to go?
Comment 37 Dan Winship 2014-12-05 16:32:01 UTC
yup
Comment 38 Bastien Nocera 2014-12-05 16:39:41 UTC
Attachment 292119 [details] pushed as ed68d80 - gio: Correct the "available in" for GNetworkMonitor
Attachment 292201 [details] pushed as 8d08b82 - gio: add network connectivity state to GNetworkMonitor
Attachment 292202 [details] pushed as 485a690 - gio: Add GNetworkMonitor impl based on NetworkManager
Comment 39 Fan, Chun-wei 2014-12-08 03:09:34 UTC
Hi,

I was wondering whether a header or a define was missed, as I am getting a compilation error on G_TYPE_NETWORK_CONNECTIVITY (undeclared indentifier), or did I miss something, after commit 8d08b82?

With blessings, thank you!
Comment 40 Dan Winship 2014-12-08 08:28:57 UTC
That would imply that gioenumtypes.[ch] need to be rebuilt, to pick up the new enum in gioenums.h. Maybe the dependencies are wrong in the win32 build so that doesn't happen automatically?
Comment 41 Fan, Chun-wei 2014-12-08 08:51:50 UTC
Hello Dan,

Yup, the Visual Studio build does not re-generate gioenumtypes.[ch] as that is normally distributed with the tarball.  Perhaps I should add a custom build step to do that?  So doing so would fix this-my fault, should have thought about this earlier:|

With blessings, thank you!