Commit Graph

112 Commits

Author SHA1 Message Date
Dan Winship
6fcc1deee0 core: add an NMExportedObject base class
Add NMExportedObject, make it the base class of all D-Bus-exported
types, and move the nm-properties-changed-signal logic into it. (Also,
make NMSettings use the same properties-changed code as everything
else, which it was not previously doing, presumably for historical
reasons).

(This is mostly just shuffling code around at this point, but
NMExportedObject will be more important in the gdbus port, since
gdbus-codegen doesn't do a very good job of supporting objects that
export multiple interfaces [as each NMDevice subclass does, for
example], so we will need more glue/helper code in NMExportedObject
then.)
2015-07-24 13:25:47 -04:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Lubomir Rintel
4078834999 active-connection: fail the activation if the master AC disconnect
The master may not have successfully activated even though we know the device
already.
2015-06-24 18:20:47 +02:00
Beniamino Galvani
04d5804dd5 nm-manager: add 'metered' property
This introduces a global metered property which makes easier for
clients to obtain the metered status of the current primary
connection.
2015-06-09 18:23:19 +02:00
Dan Winship
3bfb163a74 all: consistently include config.h
config.h should be included from every .c file, and it should be
included before any other include. Fix that.

(As a side effect of how I did this, this also changes us to
consistently use "config.h" rather than <config.h>. To the extent that
it matters [which is not much], quotes are more correct anyway, since
we're talking about a file in our own build tree, not a system
include.)
2014-11-13 17:18:42 -05:00
Jiří Klimeš
9ed96e15eb build: add the compatibility header for g_clear_pointer()
Necessary for GLib < 2.34
2014-11-07 17:10:39 +01:00
Dan Williams
b11798a196 vpn/core: move VPN gateway route between devices when routing changes 2014-11-06 21:17:34 -06:00
Ryan Lortie
07dba25404 core: add PrimaryConnectionType property to NMManager (bgo #739080)
This will provide an extremely easy way for applications to find out
what type of connection the system is currently using.  They might want
to do this to avoid using data if a phone is on a 3G connection, for
example.

Having this as a separate property provides at least two advantages:

 1) it reduces code complexity for those wanting only this one simple
    piece of information

 2) we could allow access to this property (but nothing else) to
    privilege-separated applications in the future

This patch adds the missing nm_active_connection_get_connection_type()
which was in the header file but never actually implemented.

https://bugzilla.gnome.org/show_bug.cgi?id=739080
2014-10-23 13:39:08 -05:00
Dan Winship
4779d96685 core: lie about NMActiveConnection:state in new connections
NMActiveConnections start out in state "unknown", but then quickly
switch to "activating". Unfortunately, it's sometimes possible for
this to be externally visible. Fix this by lying and saying that state
is "activating" during the initial "unknown" stage (though not if the
state changes to "unknown" later on).

(Actually changing the initial state to "activating" breaks things
because some code depends on there being a transition into the
"activating" state.)
2014-10-19 09:27:47 -04:00
Thomas Haller
eabe7d856c auth: rework polkit autorization to use DBUS interface directly
This makes NetworkManager independent of <polkit/polkit.h>
development headers and libpolkit-gobject-1.so library.
Instead communicate directly with polkit using its DBUS
interface.

PolicyKit support is now always compiled in. You can control
polkit authorization with the configuration option
  [main]
  auth-polkit=yes|no

If the configure option is omitted, a build time default
value is used. This default value can be set with the
configure option --enable-polkit.

This commit adds a new class NMAuthManager that reimplements the
relevant DBUS client parts. It takes source code from the polkit
library.

https://bugzilla.gnome.org/show_bug.cgi?id=734146

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-29 13:51:11 +02:00
Thomas Haller
05494423de auth: rename file nm-manager-auth.* to nm-auth-utils.*
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-09-29 13:00:11 +02:00
Jiří Klimeš
c9b9229c2e core: do not assert when a device is enslaved externally
Test case:
 # ip link add name BR type bridge
 # brctl addif BR eth0

Monitoring external master/slave changes was intruduced by
08e0cfb484.
2014-09-26 11:17:57 +02:00
Dan Winship
3ddce74803 libnm: rename NetworkManager.h and NetworkManagerVPN.h
"NetworkManager.h"'s name (and non-standard capitalization) suggest
that it's some sort of high-level super-important header, but it's
really just low-level D-Bus stuff. Rename it to "nm-dbus-interface.h"
and likewise "NetworkManagerVPN.h" to "nm-vpn-dbus-interface.h"
2014-08-01 14:34:40 -04:00
Dan Winship
b28f6526c2 core: fill in nm-types.h, clean out other headers
Clean up some of the cross-includes between headers (which made it so
that, eg, if you included NetworkManagerUtils.h in a test program, you
would need to build the test with -I$(top_srcdir)/src/platform, and if
you included nm-device.h you'd need $(POLKIT_CFLAGS)) by moving all
GObject struct definitions for src/ and src/settings/ into nm-types.h
(which already existed to solve the NMDevice/NMActRequest circular
references).

Update various .c files to explicitly include the headers they used to
get implicitly, and remove some now-unnecessary -I options from
Makefiles.
2014-07-23 10:56:26 -04:00
Thomas Haller
3789e45428 core: ensure boolean properties for nm_active_connection_set_default[6]() are either TRUE or FALSE
Since @is_default is compared using ==, we should ensure that the
boolean properties are always either TRUE or FALSE.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-06-20 17:56:06 +02:00
Dan Winship
aa1dce6da2 all: remove remaining GParamSpec name/blurb strings
Remove all remaining GParamSpec name and blurb strings (and fix
indentation while we're there), and add G_PARAM_STATIC_STRINGS to all
paramspecs that were lacking it.
2014-06-19 17:45:03 -04:00
Thomas Haller
a16faa3985 core: add parameter to ignore error in add/remove pending action
Add a parameter to nm_device_add_pending_action() to silently
accept adding duplicate actions.

Same for nm_device_remove_pending_action(), to silently ignore
removing non-pending actions.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-05-01 22:06:52 +02:00
Thomas Haller
b69f624c98 core: implement function nm_active_connection_get_uuid()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-03-05 21:15:20 +01:00
Thomas Haller
950cb2c44f core: rename function nm_active_connection_get_name() to nm_active_connection_get_id()
Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-03-05 21:15:20 +01:00
Jiří Klimeš
28bd3cab28 core: add 'type' and 'id' property for NMActiveConnection (rh #1061822)
https://bugzilla.redhat.com/show_bug.cgi?id=1061822
2014-03-05 16:17:13 +01:00
Dan Williams
e19f48ec26 core: better ignore deactivations before a new activation starts (rh #1058843)
When a new activation request comes in and the device is already
activated, two NMActRequests will exist for the device in parallel.
The old one handles de-activation of the device and is then disposed,
while the new one waits until the device is de-activated and then
takes over and starts the new activation.

Both requests are watching device state, and the new request may
mis-interpret the de-activation states and clean up its device pointer,
leading to assertion failures when the new activation starts.

To fix this (and because NMVPNConnection *does* always want to see
de-activation events from the device) remove the code that tries to
ignore de-activation from NMActiveConnection's device state handler.

Instead, have NMActRequest skip any reaction to device state changes
unless it is the current activation request on the device.  The VPN
code always wants to see the device's state, so it doesn't need this
check.
2014-02-25 18:03:03 -06:00
Dan Winship
3fb13c63c3 core: don't block startup on assumed connections
If we are assuming a connection at startup, the NMManager:startup
state doesn't need to wait for that activation to complete, since the
underlying device isn't going to change its configuration as a result
of it.

(In particular, NM considers virbr0 to be stalled at
NM_DEVICE_STATE_IP_CONFIG when it assumes it, since if it has no real
slaves, it won't yet have carrier. But this shouldn't block startup.)
2014-02-13 16:40:12 -05:00
Dan Winship
26cfe9f5ce core: fix master deactivation
NMActiveConnection was categorizing all deactivation of master
connections as "failure", and NMActRequest was deactivating all of the
master's slaves with REASON_DEPENDENCY_FAILED no matter what the real
reason was.

In fact, NMActiveConnection only needs to handle the cases where the
master fails before enslaving the device; any failure after that point
will be caught by existing master/slave checks in NMDevice. So update
the code accordingly (and remove the master_failed code from
NMVpnConnection entirely, since no master supports having VPN slaves).
2014-01-23 15:16:09 -05:00
Dan Winship
f642e88afd core: add IP/DHCP config properties to o.fd.NM.Connection.Active
Add IP and DHCP config properties to the D-Bus ActiveConnection
objects.

For device connections, this is redundant with the properties already
on the Device object, but for VPN connections, this information was
not previously available.
2013-12-19 11:49:50 -05:00
Thomas Haller
b6ef165cfe core: fix NMActiveConnection to properly add/remove pending action "activation"
When a new activation request is received, NetworkManager creates a new
NMActiveConnection to track that request.  The device may already be activated,
in which case NetworkManager stops the old activation and starts the new one,
but both exist in parallel for a short period of time.  If the old
NMActiveConnection is activating and already has a pending 'activation'
action, when the new NMActiveConnection adds its own 'activating' action,
they will clash.  This is fixed by making each NMActiveConnection's activation
pending action uniquely named.

This fixes a g_warning with the following back trace:

  #0  0x000000328224edfd in g_logv () from /lib64/libglib-2.0.so.0
  #1  0x000000328224efe2 in g_log () from /lib64/libglib-2.0.so.0
  #2  0x000000328224f2e6 in g_warn_message () from /lib64/libglib-2.0.so.0
  #3  0x0000000000440aee in nm_device_add_pending_action (device=0x14002e0, action=0x50704a "activation") at devices/nm-device.c:7172
  #4  0x000000000047525c in nm_active_connection_set_device (self=0x141b3c0, device=0x14002e0) at nm-active-connection.c:364
  #5  0x0000000000475ec1 in set_property (object=0x141b3c0, prop_id=11, value=0x7fff7ff36c20, pspec=0x1405f70) at nm-active-connection.c:647
  #6  0x0000003282615d3e in g_object_newv () from /lib64/libgobject-2.0.so.0
  #7  0x00000032826162e6 in g_object_new_valist () from /lib64/libgobject-2.0.so.0
  #8  0x0000003282616654 in g_object_new () from /lib64/libgobject-2.0.so.0
  #9  0x0000000000474193 in nm_act_request_new (connection=0x13bb0e0, specific_object=0x0, subject=0x1447740, device=0x14002e0) at nm-activation-request.c:376
  #10 0x000000000048e477 in _new_active_connection (self=0x13e8060, connection=0x13bb0e0, specific_object=0x0, device=0x14002e0, subject=0x1447740, error=0x7fff7ff36f90) at nm-manager.c:2947
  #11 0x000000000048ed77 in impl_manager_activate_connection (self=0x13e8060, connection_path=0x134d590 "/org/freedesktop/NetworkManager/Settings/9", device_path=0x134d550 "/org/freedesktop/NetworkManager/Devices/1",
      specific_object_path=0x0, context=0x143a9b0) at nm-manager.c:3206
  #12 0x00000000004876c8 in dbus_glib_marshal_nm_manager_VOID__BOXED_BOXED_BOXED_POINTER (closure=0x7fff7ff37220, return_value=0x0, n_param_values=5, param_values=0x1448830, invocation_hint=0x0,
      marshal_data=0x48e9dd <impl_manager_activate_connection>) at nm-manager-glue.h:189
  #13 0x0000003284a0d6a9 in object_registration_message () from /lib64/libdbus-glib-1.so.2
  #14 0x000000348ea1ce66 in _dbus_object_tree_dispatch_and_unlock () from /lib64/libdbus-1.so.3
  #15 0x000000348ea0fa31 in dbus_connection_dispatch () from /lib64/libdbus-1.so.3
  #16 0x0000003284a0acc5 in message_queue_dispatch () from /lib64/libdbus-glib-1.so.2
  #17 0x0000003282247df6 in g_main_context_dispatch () from /lib64/libglib-2.0.so.0
  #18 0x0000003282248148 in g_main_context_iterate.isra.22 () from /lib64/libglib-2.0.so.0
  #19 0x000000328224854a in g_main_loop_run () from /lib64/libglib-2.0.so.0
  #20 0x000000000042c6c0 in main (argc=1, argv=0x7fff7ff379b8) at main.c:629

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-12-18 12:36:04 -06:00
Jiří Klimeš
b0fb239df3 core: clear device on NMActiveConnection when the connection is DEACTIVATED 2013-12-12 14:55:26 -06:00
Dan Williams
2556aa32ed core: ensure 'activation' pending action encompasses full activation process
The NMActiveConnection class tracks the full activation request, and internal
activation requests go through the same process as external ones, including
some authentication.  Sometimes that means activation is scheduled, control
returns to the mainloop, and then the activation proceeds from an idle
handler.

Unfortunately, that means that adding a pending "activation" action from
nm-device.c doesn't always work, since there is a short window between when
the activation is started in nm-manager.c (in nm_manager_activate_connection())
and when the device actually changes state.  Inside that window, the pending
actions may drop to zero, and startup will be declared complete before the
device actually starts activating.

Instead, ensure that the pending action is added when the internal activation
is actually started (eg, when NMActiveConnection receives the NMDevice object).
2013-12-12 11:16:51 -06:00
Dan Winship
f3c2851c2b settings: port NMAgentManager, etc, to use NMAuthSubject
Rather than explicitly passing around a UID and a flag saying whether
or not it's relevant.

(This also fixes a bug where the wrong UID was being recorded in
nm-settings-connection.c::auth_start(), which caused problems such as
agent-owned secrets not getting saved because of a perceived UID
mismatch.)
2013-12-03 16:39:45 -05:00
Dan Williams
61744d41bb core: add nm_active_connection_[get|set]_assumed()
Various code during the activation paths will want to know whether
the connection is assumed or not, so that it doesn't do stuff that
touches the device.
2013-11-08 16:46:44 -06:00
Dan Williams
b3c0756f79 trivial: add logging for ActiveConnection master-ready tracking 2013-10-31 14:55:32 -05:00
Dan Williams
1b37cd0340 core: allow ActiveConnections to be created without a device
The device may not be created yet (in the case of software devices)
when the ActiveConnection is created; in that case we still want to
proceed with authorization for the connection, but we'll create the
device when authorization is complete.
2013-10-31 14:15:09 -05:00
Dan Williams
a7bab4015e core: have ActiveConnection track device state instead of subclasses
Both NMActRequest and NMVPNConnection need to track their device's state,
so instead of both subclasses having to do so, consolidate that code into
the superclass.
2013-10-31 14:15:08 -05:00
Dan Williams
087e1dfbb9 core: indicate via a property when master connections are ready for slaves
Add a 'master-ready' property to NMActiveConnection that NMDevice can
watch for to indicate that the master connection/device is ready to accept
slaves.  Since the slave device's ActiveConnection is already tracking
its master connection, and since ActiveConnections don't enter the
ACTIVATING state until their device is ready for slaves, it's pretty
trivial to implement this property.
2013-10-31 14:15:08 -05:00
Dan Williams
ae116d847e core: allow ActiveConnection connection to be changed
For the case of AddAndActivate, which needs to set the final connection
after authentication is done and NMSettings has returned the final
connection.
2013-10-31 14:15:08 -05:00
Dan Williams
8252357dd1 core: watch master ActiveConnections and follow master deactivation 2013-10-31 14:15:08 -05:00
Dan Williams
3bb2b158cd core: switch NMActiveConnection master to an NMActiveConnection instead of NMDevice
We need to track the master active connection, since it may require authentication
or other operations to complete before the device actually starts activating.
2013-10-31 14:15:08 -05:00
Dan Williams
4237df8c21 core: allow active connection 'master' to be set after object creation
We want to create the object earlier now, and figuring out the master is
a lot of code that we don't want to run before creating the object.  The
master still must be set before exporting the object over D-Bus though,
as before.
2013-10-31 14:15:08 -05:00
Dan Williams
4b8cd481dc core: add authorization code to NMActiveConnection
In preparation for killing PendingActivation; copy and rework the
PendingActivation authorization code for NMActiveConnection.
2013-10-31 14:15:08 -05:00
Dan Williams
0e595abcf3 core: pass NMAuthSubject around activation paths instead of uid + dbus sender 2013-10-31 14:15:08 -05:00
Dan Williams
f6f626de34 core: ensure active connection has a device before exporting it 2013-10-31 14:15:07 -05:00
Dan Williams
6413241ff2 core: handle NULL object paths in NMActiveConnection
NM uses "/" to mean a NULL object path, since you can't pass
NULL object paths through D-Bus.  The AC code didn't handle that
and we'll soon be passing object paths from D-Bus into it.
2013-10-31 14:15:07 -05:00
Pavel Šimerda
5affa446aa core: remove assume from nm-activation-request
Whether an active connection is assumed or connected from scratch is
only important during nm_device_activate(). When the activation process
is set up, there's no difference from any other active connection.

Acked-by: Dan Winship <danw@gnome.org>
Acked-by: Thomas Haller <thaller@redhat.com>
2013-08-22 22:06:47 +02:00
Dan Winship
5a223b9089 core: make nm-properties-changed-signal always export the right properties
Change the way that nm-properties-changed-signal works, and parse the
dbus-binding-tool-generated info to get the exact list of properties
that it's expected to export.

This makes NM_PROPERTY_PARAM_NO_EXPORT unnecessary, and also fixes the
problem of properties like NMDevice:hw-address being exported on
classes where it shouldn't be.
2013-05-20 16:38:33 -03:00
Dan Williams
04cb58eacd core: convert the DBus manager to a single-ref object
It's created very, very early and never needs to be unrefed
by anything except the main() function.
2013-05-20 16:38:33 -03:00
Dan Williams
3c7f267fb9 core: use wrappers for DBus object registration/unregistration
When providing a service on the bus daemon and a private connection,
we'll need to track objects so we can register them with the
private connection too.  Thus all registration/unregistration
calls have to go through the NMDBusManager, not straight to
dbus-glib.
2013-04-08 10:55:37 -05:00
Dan Williams
aa5013cf2d core: fix duplicating (not removing) active connections
This is a regression introduced by reworked active connections tracking:
7258dd270f core: add the NM_ACTIVE_CONNECTION_STATE_DEACTIVATED state
59420add04 core: track active connections directly in the manager

Because nm-manager.c:active_connection_state_changed() postpones active
connection removal to an idle handler (to be able to receive last property
change notifications), we also need to ensure that NM_ACTIVE_CONNECTION_STATE_DEACTIVATED
state is not changed again in the meantime in nm-activation-request.c:device_state_changed().
After the NMActRequest was deactivated (which is a terminal state) it was still
listening to state changes of its child NMDevice which could be starting a
new activation request.  Thus the new activation's NMDevice state would cause
the old activation request's state to change from DEACTIVATED.  To fix this
stop listening to the child NMDevice when DEACTIVATED becuase there's no point
to doing so anyway.

Reproducer:
Just activate already active connection by clicking it in nm-applet or
run 'nmcli con up id <connnection name>' several times, and then check
active connections with 'nmcli c s'.
2013-02-11 11:48:11 -06:00
Dan Williams
6ddc25dcab core: handle some connection timestamp updating in NMActiveConnection
Handle it in the base active connection class instead of in separate
places for the device and the VPN cases.
2012-12-17 17:01:10 -06:00
Dan Williams
84603c2380 core: move most activation request logic to the active connection class
We'll want to use NMActiveConnection more in the manager and also fold
the PendingActivation functionality into it.  All this functionality
applies to the VPN connections too, so it makes sense to have it all
in the base class instead of both NMActRequest and NMVPNConnection.
2012-12-17 17:01:10 -06:00
Jiří Klimeš
8fde1b1d2a core: add nm_active_connection_get_name() for easy access to connection name 2012-09-24 10:38:18 +02:00
Dan Williams
33d0cff3e4 core: use active connection dependency master instead of manually setting it
We already have the master device kept in the active connection, so
we can just use that instead of having the Policy determine and set
it manually.  This also should allow slaves to auto-activate their
master connections if the master is able to activate.
2012-03-01 17:40:18 -06:00