Commit Graph

112 Commits

Author SHA1 Message Date
Thomas Haller
10c0632df0 device: fix taking over device after modifying external connection
For externally managed interfaces, we create an in-memory connection
and keep the device with sys-iface-state=external.

When the user actively modifies the connection, we persist it to
storage. But we also must take over managing the device.

One problem is that nm_device_reapply() errors out if the device
is still activating. It's unclear how to reapply the connection
while the device is in the process of activation. So, if the user
modifies the created connection very quickly, reapplying the settings
will fail.

https://bugzilla.redhat.com/show_bug.cgi?id=1462223
2017-06-19 14:57:48 +02:00
Thomas Haller
b84da25713 core: fix registering notify-flags hook in NMActiveConnection
We react on changes to NMSettingsConnection.flags, so that we can update
from an external activation to a managed one.

However, previously we would only register the _settings_connection_notify_flags
callback during _set_settings_connection(). So, if via constructor properties
we first set PROP_SETTINGS_CONNECTION and later PROP_ACTIVATION_TYPE, we wouldn't
register the callback.
2017-06-19 14:28:00 +02:00
Lubomir Rintel
35d7c93405 active-connection: log the connection context 2017-03-24 12:42:09 +01:00
Lubomir Rintel
ed552c732c logging: log device and connection along with the message 2017-03-24 12:42:09 +01:00
Lubomir Rintel
40ffb962be libnm/active-connection: track reason for state changes
Note that the reason tracking starts as soon as the object exists (which
is immediately after GDBusObject is created), not when the asynchronous
NMObject initialization finishes. That is so that we the reason changes
in between are not lost.

The vpn-connection should probably be doing the same.
2017-03-17 10:21:19 +01:00
Lubomir Rintel
8b649a8c84 active-connection: emit a StateChanged signal on state changes
It includes a reason code that makes it possible for the clients to be
more reasonable about error messages.

The reason code is essentially copied from the VPN, plus three more
reasons that were useful for non-VPN connections.
2017-03-17 10:21:19 +01:00
Thomas Haller
850c977953 device: track system interface state in NMDevice
When deciding whether to touch a device we sometimes look at whether
the active connection is external/assumed. In many cases however,
there is no active connection around (e.g. while moving the device
from state unmanaged to disconnected before assuming).
So in most cases we instead look at the device-state-reason to decide
whether to touch the interface (see nm_device_state_reason_check()).

Often it's desirable to have no state and passing data as function
arguments. However, the state reason has to be passed along several hops
(e.g. a queued state change). Or a change to a master/slave can affect
the slave/master, where we pass on the state reason. Or an intermediate
event might invalidate a previous state reason. Passing the state
whether to touch a device or not as a state-reason is cumbersome
and limited.

Instead, the device should be aware of whats going on. Add a
sys-iface-state with:
  - SYS_IFACE_STATE_EXTERNAL: meaning, NM should not touch it
  - SYS_IFACE_STATE_ASSUME: meaning, NM is gracefully taking over
  - SYS_IFACE_STATE_MANAGED: meaning, the device is managed by NM
  - SYS_IFACE_STATE_REMOVED: the device no longer exists

This replaces most checks of nm_device_state_reason_check() and
nm_active_connection_get_activation_type() by instead looking at
the sys-iface-state of the device.

This patch probably has still issues, but the previous behavior was
not very clear either. We will need to identify those issues in future
tests and tweak the behavior. At least, now there is one flag that
describes how to behave.
2017-03-16 18:27:33 +01:00
Thomas Haller
7a5e0c7fd7 core: once activated an assumed connection make it NM_ACTIVATION_TYPE_MANAGED 2017-03-16 18:27:33 +01:00
Thomas Haller
bde6782591 core: upgrade EXTERNAL activation type when user saves connection
An EXTERNAL activation type comes with a nm-generated, volatile,
in-memory connection. When the user actively modifies that connection, we
shall mark the active connection as fully managed.
2017-03-16 18:27:33 +01:00
Thomas Haller
bed2fa1bec core: track external activations types in the active-connection
We need a distinction between external activations and assuming
connections. The former shall have the meaning of devices that are
*not* managed by NetworkManager, the latter are configurations that
are gracefully taken over after restart (but fully managed).

Express that in the activation-type of the active connection.

Also, no longer use the settings NM_SETTINGS_CONNECTION_FLAGS_VOLATILE
flag to determine whether an assumed connection is "external". These
concepts are entirely orthogonal (although in pratice, external
activations are in-memory and flagged as volatile, but the inverse
is not necessarily true).

Also change match_connection_filter() to consider all connections.
Later, we only call nm_utils_match_connection() for the connection
we want to assume -- which will be a regular settings connection,
not a generated one.
2017-03-16 18:27:33 +01:00
Thomas Haller
fa015f2aab core/trivial: rename activation-type related checks for device and active-connection
nm_device_uses_assumed_connection() basically called
nm_active_connection_get_assumed() on the device.

Rename those functions to be closer to the activation-type
flags.

The concepts of "assume", "external", and "assume_or_external"
will make sense with the following commits.
2017-03-16 18:27:33 +01:00
Thomas Haller
3973f8ebcd active-connection: use activation-type for active connection instead of assumed flag 2017-03-16 18:27:33 +01:00
Thomas Haller
8a31e66d2c core: add activation-type property to active-connection
It is still unused, but will be useful to mark a connection
whether it is a full activation or assumed.
2017-03-16 18:27:33 +01:00
Thomas Haller
9e60de87f5 core: minor cleanups
Some minor changes that make the code more similar to what will
be done later for the related bug bgo#746440.
2017-03-16 18:27:33 +01:00
Thomas Haller
b1eeb00937 all: use "unsigned long" instead of "long unsigned" 2017-03-14 11:23:46 +01:00
Thomas Haller
e234673a4a device: refactor pending-action strings as named defines 2017-02-10 14:40:23 +01:00
Lubomir Rintel
8b9f3055bf active-connection: unhook the settings connection removed signal on dispose
Fixes: f0e3dfdace
(cherry picked from commit f541cef958)
2017-01-25 17:17:45 +01:00
Thomas Haller
e56d308ba5 core: avoid unexporting active-connection that is not exported
For better or worse, nm_exported_object_unexport() asserts that the
object is currently exported.

It's not clear that an active connection at this place is always
exported.

Fixes: f0e3dfdace
(cherry picked from commit c8a649b3de)
2017-01-24 16:19:41 +01:00
Lubomir Rintel
db6e8b21e4 active-connection: drop off the bus when the settings connection disappears
The active connection has an immutable connection property, but is
cleaned asynchronously by the manager after its settings connection is
done. Fine, let's remove it from the bus first though, so that we don't
hang there with a dangling object path.

(cherry picked from commit f0e3dfdace)
2017-01-24 16:19:40 +01:00
Thomas Haller
32dd257d31 exported-object: use NM_EXPORT_PATH_NUMBERED() macro 2017-01-03 15:40:17 +01:00
Lubomir Rintel
972e0d2803 all: rename the introspection data to use the interface paths in names
This makes it easier to install the files with proper names.
Also, it makes the makefile rules slightly simpler.

Lastly, the documentation is now generated into docs/api, which makes it
possible to get rid of the awkward relative file names in docbook.
2016-11-23 15:43:42 +01:00
Thomas Haller
44ecb41593 build: don't add subdirectories to include search path but require qualified include
Keep the include paths clean and separate. We use directories to group source
files together. That makes sense (I guess), but then we should use this
grouping also when including files. Thus require to #include files with their
path relative to "src/".

Also, we build various artifacts from the "src/" tree. Instead of having
individual CFLAGS for each artifact in Makefile.am, the CFLAGS should be
unified. Previously, the CFLAGS for each artifact differ and are inconsistent
in which paths they add to the search path. Fix the inconsistency by just
don't add the paths at all.
2016-11-21 14:26:37 +01:00
Thomas Haller
4d37f7a1e9 core: refactor private data in "src"
- use _NM_GET_PRIVATE() and _NM_GET_PRIVATE_PTR() everywhere.

- reorder statements, to have GObject related functions (init, dispose,
  constructed) at the bottom of each file and in a consistent order w.r.t.
  each other.

- unify whitespaces in signal and properties declarations.

- use NM_GOBJECT_PROPERTIES_DEFINE() and _notify()

- drop unused signal slots in class structures

- drop unused header files for device factories
2016-10-04 09:50:56 +02:00
Thomas Haller
b2c0573f08 core/trivial: move code around
- get_property() should be imidiately before set_property().
- type_init() should be before constructing(), constructed()
  and type_new().
- dispose() and finalize() should be after object creation.
- at last follows class_init().
2016-10-03 12:04:49 +02:00
Thomas Haller
0aa3a6dbfb core: refactor private data for NMExportedObject and others 2016-10-03 12:04:14 +02:00
Thomas Haller
a83eb773ce all: modify line separator comments to be 80 chars wide
sed 's#^/\*\{5\}\*\+/$#/*****************************************************************************/#' $(git grep -l '\*\{5\}' | grep '\.[hc]$') -i
2016-10-03 12:01:15 +02:00
Beniamino Galvani
5754a05605 core: allow passing an applied connection to nm_act_request_new()
This is useful for the checkpoint/restore functionality to revert both
the applied and the settings connections.
2016-09-26 15:10:39 +02:00
Thomas Haller
f1beb01050 core: use define for signal name in nm_active_connection_set_device()
(cherry picked from commit 598bea3481)
2016-08-22 16:25:33 +02:00
Beniamino Galvani
adba47cb61 active-connection: don't weak-unref parent inside notify function 2016-07-07 17:14:38 +02:00
Thomas Haller
8e54cfdb27 all: move NM_AUTH_PERMISSION_* defines to "nm-common-macros.h" header 2016-06-01 19:06:35 +02:00
Thomas Haller
18019d55a1 active-connection: update D-Bus properties of active-connection when settings-connection changes
$ nmcli connection up my-connection
  Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/42)

  $ nmcli connection modify my-connection connection.id other-name

  $ nmcli -f connection.id connection show other-name
  connection.id: other-name

  $ nmcli -f GENERAL.CONNECTION device show enp0s25
  GENERAL.CONNECTION: my-connection

  $ nmcli connection down other-name
  Error: 'other-name' is not an active connection.
  Error: no active connection provided.

  $ nmcli connection down my-connection
  Connection 'my-connection' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)

When modifying a connection, NMActiveConnection must update the D-Bus
properties that belong to the settings-connection.
2016-04-14 12:25:41 +02:00
Thomas Haller
30b8842a48 settings: use NM_GOBJECT_PROPERTIES_DEFINE in NMSettings/NMSettingsConnection/NMActiveConnection 2016-04-14 12:17:35 +02:00
Lubomir Rintel
6e382ea91d active-connection: add parent active connection tracking
Make it possible to let active connection know about an active
connection it depends on and emit a signal when the parent is active.
2016-03-26 11:31:18 +01:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Thomas Haller
b96a40c2ec core: add version-id to NMActiveConnection
This field will be later used by NMDevice's Reapply and
GetAppliedConnection methods. The usecase is to first fetch
the currently applied connection, adjust it and reapply it.
Using the version-id, a concurrent modification can be detected
and Reapply can reject the invocation.
2016-02-16 11:24:49 +01:00
Thomas Haller
72255b71d7 utils: pass entire return statement to NM_UTILS_LOOKUP_DEFINE() 2016-02-01 14:20:26 +01:00
Thomas Haller
6c6ab10dea core/trivial: rename NM_UTILS_STRING_LOOKUP_TABLE* to NM_UTILS_LOOKUP*
Due to using a switch stetement, it is no longer only useful for looking
up strings, and it certainly doesn't use a table anymore.
2016-01-24 14:29:37 +01:00
Thomas Haller
3ed2488d74 utils: use NM_UTILS_STRING_LOOKUP_TABLE_ITEM() macro 2016-01-24 14:20:58 +01:00
Thomas Haller
7685961261 active-connection: improve logging in NMActiveConnection
- cleanup _NMLOG()
- implement state_to_string() based on NM_UTILS_STRING_LOOKUP_TABLE(),
  which prints unknown values as numeric
- add logging when setting device and state
- cleanup logging in check-master-ready to consistently
  print relevant information
- update logging in set_master() to match simpler logging
  format like set_device() and set_state().
2015-12-07 21:47:01 +01:00
Thomas Haller
ee4ec4e600 core: use define for NMDevice's "state-changed" signal name 2015-12-07 19:53:14 +01:00
Dan Williams
f2256af5bc core: allow multiple devices with the same interface name
But, of course, only one realized device can have the same
interface name at a time.

This commit effectively reverts most of:

1b37cd0340
core: allow ActiveConnections to be created without a device

But it's not easy to do a separate revert of that code due to
interdependencies with nm-manager.c.

Creating devices when they are defined by a connection also makes
makes it possible to require the NMDevice to be present when
activating it, which means we can remove a bunch of code from
NMManager that had to handle software devices not existing yet at
the time of the activation request.

But it also means we must be more careful when finding master
interfaces during slave activation, since we cannot simply match
by interface name alone.  Instead we must find the master which
matches both the interface name and can control slaves of the type
which is being activated.
2015-12-04 12:16:41 +01:00
Dan Williams
4dbaac4ba2 core: create devices first and realize them later
Unrealized devices aren't backed by kernel resources and so won't know
all of their attributes.  That means three things:

1) they must update their attributes when they become realized
2) they must clear those attributes when unrealized
3) they must be looser in checking compatible connections until
they are realized

This requires that the setup() function be split into two parts, start & finish,
because finish must be run after add_device()

Also, we can simplify whether to pay attention to 'recheck-assume', which
is now dependent on priv->is_nm_owned, because the only case where NM should
*not* listen for the 'recheck-assume' signal is when the device is a
software device created by NM itself.  That logic was previously spread
across the callers of add_device() but is now consolidated into
nm-manager.c::device_realized() and nm-device.c::nm_device_create_and_realize().
2015-12-04 12:16:40 +01:00
Lubomir Rintel
06da353242 core: separate active and applied connection
Clone the connection upon activation. This makes it safe for the user
to modify the original connection while it is activated.

This involves several changes:

- NMActiveConnection gets @settings_connection and @applied_connection.
  To support add-and-activate, we constructing a NMActiveConnection with
  no connection set. Previously, we would set the "connection" field to
  a temporary NMConnection. Now NMManager piggybacks this temporary
  connection as object-data (TAG_ACTIVE_CONNETION_ADD_AND_ACTIVATE).

- get rid of the functions nm_active_connection_get_connection_type()
  and nm_active_connection_get_connection_uuid(). From their names
  it is unclear whether this returns the settings or applied connection.
  The (few) callers should figure that out themselves.

- rename nm_active_connection_get_id() to
  nm_active_connection_get_settings_connection_id(). This function
  is only used internally for logging.

- dispatcher calls now get two connections as well. The
  applied-connection is used for the connection data, while
  the settings-connection is used for the connection path.

- needs special handling for properties that apply immediately
  when changed (nm_device_reapply_settings_immediately()).

Co-Authored-By: Thomas Haller <thaller@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=724041
2015-09-18 17:32:11 +02:00
Thomas Haller
ad7cdfc766 logging: declare default logging macros in "nm-logging.h"
The logging macros _LOGD(), etc. are specific to each
file as they format the message according to their context.

Still, they were cumbersome to define and their implementation
was repeated over and over (slightly different at times).

Move the declaration of these macros to "nm-logging.h".
The source file now only needs to define _NMLOG(), and either
_NMLOG_ENABLED() or _NMLOG_DOMAIN.

This reduces code duplication and encourages a common implementation
and usage of these macros.
2015-08-20 11:15:13 +02:00
Thomas Haller
205bb86ead active-connection: log lifetime of NMActiveConenction 2015-08-13 10:06:43 +02:00
Thomas Haller
97c971b4e4 active-connection: make use of logging macro _LOGD() 2015-08-13 10:06:43 +02:00
Thomas Haller
c6cbd652ba active-connection: add logging macros _LOG*() 2015-08-13 10:06:43 +02:00
Dan Winship
c050fb7cd2 devices, active-connection: port to gdbus 2015-08-10 09:41:26 -04:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Dan Winship
c1dd3b6eed core: move D-Bus export/unexport into NMExportedObject
Move D-Bus export/unexport handling into NMExportedObject and remove
type-specific export/get_path methods (export paths are now specified
at the class level, and NMExportedObject handles the counters for all
exported types automatically).

Since all exportable objects now use the same get_path() method, we
can also add some helper methods to simplify get_property()
implementations for object-path and object-path-array properties.
2015-07-24 13:25:47 -04:00