Commit Graph

21088 Commits

Author SHA1 Message Date
Thomas Haller
f67303221b checkpoint: allow resetting the rollback timeout via D-Bus
This allows to adjust the timeout of an existing checkpoint.

The main usecase of checkpoints, is to have a fail-safe when
configuring the network remotely. By allowing to reset the timeout,
the user can perform a series of actions, and keep bumping the
timeout. That way, the entire series is still guarded by the same
checkpoint, but the user can start with short timeout, and
re-adjust the timeout as he goes along.

The libnm API only implements the async form (at least for now).
Sync methods are fundamentally wrong with D-Bus, and it's probably
not needed. Also, follow glib convenction, where the async form
doesn't have the _async name suffix. Also, accept a D-Bus path
as argument, not a NMCheckpoint instance. The libnm API should
not be more restricted than the underlying D-Bus API. It would
be cumbersome to require the user to lookup the NMCheckpoint
instance first, especially since libnm doesn't provide an efficient
or convenient lookup-by-path method. On the other hand, retrieving
the path from a NMCheckpoint instance is always possible.
2018-04-04 14:02:13 +02:00
Thomas Haller
ab8312a18e checkpoint: generate GIR information for NMCheckpointCreateFlags
Note that this changes API for checkpoint_create_async() in Python
via GIR. Previously it would require an integer argument, now a flags
argument. But this API is still unstable, it will be introduced with
1.12.
2018-04-04 14:02:13 +02:00
Thomas Haller
56500e5964 checkpoint: refactor setting error for lookup checkpoint failure
This changes the error reason in nm_checkpoint_manager_rollback()
from NM_MANAGER_ERROR_FAILED to NM_MANAGER_ERROR_INVALID_ARGUMENTS.
2018-04-04 14:02:13 +02:00
Thomas Haller
5c283356a1 checkpoint: allow overlapping checkpoints
Introduce a new flag NM_CHECKPOINT_CREATE_FLAG_ALLOW_OVERLAPPING
that allows the creation of overlapping checkpoints. Before, and
by default, checkpoints that reference a same device conflict,
and creating such a checkpoint failed.

Now, allow this. But during rollback automatically destroy all
overlapping checkpoints that were created after the checkpoint
that is about to rollback.

With this, you can create a series of checkpoints, and rollback them
individually. With the restriction, that if you once rolled back to an
older checkpoint, you no longer can roll"forward" to a younger one.

What this implies and what is new here, is that the checkpoint might be
automatically destroyed by NetworkManager before the timeout expires. When
the user later would try to manually destroy/rollback such a checkpoint, it
would fail because the checkpoint no longer exists.
2018-04-04 14:02:13 +02:00
Thomas Haller
e5fc9a307d checkpoint: don't let nm_checkpoint_new() fail
We already do error checking in nm_checkpoint_manager_create(). No need
to split it in two places. Let all error conditions be handled by
nm_checkpoint_manager_create() first, and then once we decide all is
good, nm_checkpoint_new() can no longer fail.
2018-04-04 14:02:13 +02:00
Thomas Haller
5fb65b7f96 checkpoint: let each checkpoint schedule its own timeout
Instead of scheduling one timeout only, let each checkpoint instance
individually schedule a timeout. This has some overhead, but glib
is supposed to make scheduling many timers efficient. Otherwise,
glib should be fixed.

This simplifies in my opinion the code, because it's up to each
checkpoint to maintain its own timeout.

Later we will also add a AdjustRollbackTimeout operation, which
allow to reschedule the timeout. It also seems slightly simpler,
if scheduling of the timeout is done by the NMCheckpoint instance
itself.
2018-04-04 14:02:13 +02:00
Thomas Haller
6f28749ad4 checkpoint: simplify device_checkpoint_create() to never fail
It never failed already. Don't pretend it could.
2018-04-04 14:02:13 +02:00
Thomas Haller
e6e0eb92b9 checkpoint: minor cleanup rolling back checkpoints 2018-04-04 14:02:13 +02:00
Thomas Haller
79458a558b checkpoint: don't explicitly track checkpoints in a GHashTable
We already have a GHashTable for exported objects. We can use
that if we want to look up by path efficiently.
2018-04-04 14:02:13 +02:00
Thomas Haller
63e3bff916 checkpoint: refactor nm_checkpoint_manager_create() to simplify creating device list
If no device paths are given, we can take the devices directly.
We don't need to first create a list of paths, and then
look them up by path again to add them to the list.
2018-04-04 14:02:13 +02:00
Thomas Haller
daf3d5cb53 checkpoint: skip unrealized devices in nm_checkpoint_manager_create()
We already do it for the case where no paths are provided.
2018-04-04 14:02:13 +02:00
Thomas Haller
6d6b389086 checkpoint/trivial: rename local variable @checkpoint_path
path is long enough and (in this context) it consistently
references the checkpoint "path".
2018-04-04 14:02:13 +02:00
Thomas Haller
45c24fb939 checkpoint/trivial: rename nm_checkpoint_manager_unref() to nm_checkpoint_manager_free()
NMCheckpointManager was added and is not ref-countable, because it
is not needed.

I still often like for such objects (that are not ref-countable),
that their destroy function is called "unref". Both for consistency,
and also if we would later add ref-counting to the object.

However, NMCheckpointManager keeps a pointer to NMManager. So, when
NMManager gets destroyed, it *MUST* destroy the NMCheckpointManager.
It cannot accept that the checkpoint manager outlives NMManager,
but the "unref" name suggests that somebody else might have still
a reference to this object keeping it alive. That is not the case.

Rename so that this is clear.

I would name it nm_checkpoint_manager_destroy(), but "destroy" already
has a meaning for NMCheckpoint instances, so use "free".
2018-04-04 14:02:13 +02:00
Thomas Haller
ffb492678e checkpoint: embed CList in NMCheckpoint instance
We don't need an external CheckpointItem, just to wrap the
CList instance. Embed it directly in NMCheckpoint.

Sure, that exposes the checkpoints_lst field in the (internal)
header file, hiding the private member less.
2018-04-04 14:02:13 +02:00
Thomas Haller
6f85d3e0b9 libnm: fix crash creating checkpoint during find_checkpoint_info()
Now that the D-Bus signals in server are reordered, creating
a checkpoint in libnm crashes:

  $ examples/python/gi/checkpoint.py create 4

    #0  0x00007ffff6d011ee in __strcmp_sse2_unaligned () at /lib64/libc.so.6
    #1  0x00007fffeb611c90 in find_checkpoint_info (manager=manager@entry=0x5555559e5110 [NMManager], path=0x7fffdc0092f0 "/org/freedesktop/NetworkManager/Checkpoint/6")
        at libnm/nm-manager.c:153
    #2  0x00007fffeb611d8f in checkpoint_added (manager=0x5555559e5110 [NMManager], checkpoint=checkpoint@entry=0x555555a122d0 [NMCheckpoint]) at libnm/nm-manager.c:1194
    #3  0x00007fffef7db929 in g_cclosure_marshal_VOID__OBJECTv (closure=0x5555559e4b30, return_value=<optimized out>, instance=<optimized out>, args=<optimized out>, marshal_data=<optimized out>, n_params=<optimized out>, param_types=0x5555559e2fc0) at gmarshal.c:2102
    #4  0x00007fffef7d8976 in _g_closure_invoke_va (closure=0x5555559e4b30, return_value=0x0, instance=0x5555559e5110, args=0x7fffffffc1c8, n_params=1, param_types=0x5555559e2fc0)
        at gclosure.c:867
    #5  0x00007fffef7f3ff4 in g_signal_emit_valist (instance=instance@entry=0x5555559e5110, signal_id=signal_id@entry=97, detail=0, var_args=var_args@entry=0x7fffffffc1c8) at gsignal.c:3300
    #6  0x00007fffef7f4b48 in g_signal_emit_by_name (instance=instance@entry=0x5555559e5110, detailed_signal=detailed_signal@entry=0x7fffffffc310 "checkpoint-added") at gsignal.c:3487
    #7  0x00007fffeb6156d1 in deferred_notify_cb (data=0x5555559e5110) at libnm/nm-object.c:219
    #8  0x00007fffeb615ae7 in object_property_maybe_complete (self=0x5555559e5110 [NMManager]) at libnm/nm-object.c:555
    #9  0x00007fffeb615e5d in object_created (obj=<optimized out>, path=<optimized out>, user_data=<optimized out>) at libnm/nm-object.c:576
    #10 0x00007fffeb61648b in handle_object_array_property (pi=<optimized out>, value=0x7fffdc075070, property_name=0x7fffeb67f117 "checkpoints", self=0x5555559e5110 [NMManager])
        at libnm/nm-object.c:671
    #11 0x00007fffeb61648b in handle_property_changed (self=self@entry=0x5555559e5110 [NMManager], dbus_name=<optimized out>, value=<optimized out>) at libnm/nm-object.c:740
    #12 0x00007fffeb6166e9 in properties_changed (proxy=<optimized out>, changed_properties=<optimized out>, invalidated_properties=<optimized out>, user_data=0x5555559e5110)
        at libnm/nm-object.c:772
    ...

That is, because NetworkManager now first emits signals that the checkpoint
object was created, before answering the D-Bus request. That makes more
sense, but leads to this crash.

The ugliness of how libnm handles object visibility is considerable.
libnm hides objects until they are fully initialized. So, when
the async create-checkpoint operation returns, the object might not
yet be ready to be exposed. We need to delay the result. It would be
better if the API would simply return the created path.
2018-04-04 14:02:13 +02:00
Thomas Haller
4c67e0d5ec libnm: minor cleanup of nm_manager_get_device_by_path() 2018-04-04 14:02:13 +02:00
Thomas Haller
21b262f268 device/trival: rename NMIwdManagerPrivate.nm_manager field to "manager"
Similar cases of such a field are named "manager". Also,
internal names shall not have an "nm" prefix, contrary
to names in a header file, which shall have such a prefix.
2018-04-04 14:02:13 +02:00
Thomas Haller
8de522fad0 core: add macro for iterating CList of devices of NMManager
I find it slightly nicer and explict. Also, the list elements
are strictly speaking private, we should better not explicitly
use them outside of NMManager/NMDevice. The macro hides this.
2018-04-04 14:02:13 +02:00
Thomas Haller
a399e2b8ff core: drop unused nm_dbus_utils_g_value_set_object_path_array() function 2018-04-04 14:02:13 +02:00
Thomas Haller
03b1a1011f checkpoint: rework getting NM_CHECKPOINT_DEVICES property 2018-04-04 14:02:13 +02:00
Thomas Haller
b0f02075de core: add nm_dbus_utils_g_value_set_object_path_from_hash() helper 2018-04-04 14:02:13 +02:00
Beniamino Galvani
cc1920d714 core: merge branch 'bg/restart-assume-rh1551958'
https://bugzilla.redhat.com/show_bug.cgi?id=1551958
2018-04-04 13:36:59 +02:00
Beniamino Galvani
346064189a core: remove @indicated argument of nm_utils_match_connection()
It is not needed anymore.
2018-04-04 13:34:38 +02:00
Beniamino Galvani
f0357b8f6c manager: relax checks for assuming connections after restart
Instead of generating a connection and checking whether it is
compatible with the connection indicated in the state file, just pick
the indicated connection after a basic check of compatibility with the
device.

https://bugzilla.redhat.com/show_bug.cgi?id=1551958
2018-04-04 13:34:38 +02:00
Beniamino Galvani
eb8257dea5 core: properly initialize stable dhcp client-id
Fixes: 62a7863979
2018-04-01 16:28:47 +02:00
Javier Arteaga
56e79a4e07 platform: move genl_ctrl_resolve to nm-netlink.c
Move genl_ctrl_resolve out of the wifi code so it can be reused by other
interfaces based on genetlink.

https://mail.gnome.org/archives/networkmanager-list/2018-March/msg00044.html
2018-03-30 22:09:04 +02:00
AsciiWolf
ddc2c5f215 po: update Czech translation
https://github.com/NetworkManager/NetworkManager/pull/84
2018-03-30 22:01:50 +02:00
Thomas Haller
4d2e52e1f1 core: drop obsolete typedef for NMExportedObject
It doesn't exist anymore.
2018-03-30 22:00:15 +02:00
Lubomir Rintel
f84f0ce4f9 manager: drop an unused variable
src/nm-manager.c:5857:36: error: unused variable 'object' [-Werror,-Wunused-variable]
        gs_unref_object NMExportedObject *object = NULL;
                                          ^
2018-03-30 17:05:28 +02:00
Beniamino Galvani
d169cde872 libnm: don't use GTK-Doc comment in nm-autoptr.h
It generates the following warning:

libnm/nm-autoptr.h:25: Error: NM: identifier not found on the first line:
 * Note that you might use this header with older versions of libnm

Fixes: ff8e563365
2018-03-28 17:51:36 +02:00
Thomas Haller
a187585222 contrib/nm-live-vm: remove nm-live-vm scripts
They were not (notably) touched in more than 3 years.
I doubt anybody is using them.

Also, nowadays we have contrib/rpm to build NetworkManager
packages for Fedora/RPM. We have copr, we have automated CI
in CentOS CI and beaker.

Also, nowadays it should be easy to spawn a a fedora image
in a container or tools like vagrant.

I think there are better alternatives. Drop the scripts.
2018-03-27 11:13:41 +02:00
Thomas Haller
b2edcdc939 shared/nm-glib: add compat implementation for g_autofree
Eventually, we should replace our uses of libgsystem's gsystem-local-alloc.h
by glib's g_auto*. As a first tiny step, add a compat implementation for g_autofree,
so that we could at least go ahead and use it instead of gs_free.

https://bugzilla.gnome.org/show_bug.cgi?id=794294
2018-03-27 10:36:12 +02:00
Thomas Haller
ff8e563365 libnm: add nm-autoptr.h header
"nm-autoptr.h" is done in a way that allows you to copy the header
in your source tree to support older versions of libnm, that didn't
contain the header yet. For example, we might want to use it in
network-manager-applet, but we don't want to bump the libnm dependency
to 1.11.2+ only to get this functionality.

Note that G_DEFINE_AUTOPTR_CLEANUP_FUNC() was added in glib 2.43.4,
and requires compiler support for the cleanup attribute. The compiler
support is taken as given, because we rely on it already. However,
NetworkManager and network-manager-applet still don't depend on a glib
version recent enough to provide these macros. To actually use them
(*inside*) NetworkManager/network-manager-applet, we either would have
to bump the glib minimal dependency, or reimplement g_autoptr in
/shared/nm-utils/nm-glib.h compat header.

https://bugzilla.gnome.org/show_bug.cgi?id=794294
2018-03-27 10:36:12 +02:00
Thomas Haller
759f2bcedb core: merge branch 'th/dbus-cache-properties'
https://github.com/NetworkManager/NetworkManager/pull/82
2018-03-27 10:27:17 +02:00
Thomas Haller
e49a32936c all: use nm_utils_hash_keys_to_array() 2018-03-27 09:58:00 +02:00
Thomas Haller
cd48bc74b6 config: cleanup fields in NMGlobalDnsConfig
- consistently set options, searches, domains fields to %NULL,
  if there are no values.

- in nm_global_dns_config_update_checksum(), ensure that we uniquely
  hash values. E.g. a config with "searches[a], options=[b]" should
  hash differently from "searches=[ab], options=[]".

- in nm_global_dns_config_to_dbus(), reuse the sorted domain list.
  We already have it, and it guarantees a consistent ordering of
  fields.

- in global_dns_domain_from_dbus(), fix memleaks if D-Bus strdict
  contains duplicate entries.
2018-03-27 09:58:00 +02:00
Thomas Haller
0f1dc3bca3 config/trivial: rename dns_config local variable
The variable serves a similar purpose, but is called "dns",
"conf", and "dns_config". Choose one name: "dns_config".
2018-03-27 09:58:00 +02:00
Thomas Haller
938d9a82cf shared: add nm_utils_hash_keys_to_array() helper 2018-03-27 09:58:00 +02:00
Thomas Haller
d7b1a911d9 wifi: rework tracking of wifi-aps to use CList
- no longer track APs in a hash table with their exported path
  as key. The exported path is already tracked by NMDBusManager's
  lookup index, so we can reuse that for fast lookup by path. Otherwise,
  track the APs in a CList per device.

- as we now track APs in a CList, their order is well defined.
  We no longer need to sort APs and obsoletes nm_wifi_aps_get_sorted()
  and simplifies nm_wifi_aps_find_first_compatible().
2018-03-27 09:58:00 +02:00
Thomas Haller
9fafd26f68 core: rework lookup for exported objects by path to use index
We already track an index of exported objects in NMDBusManager.
Actually, that index was unused previously. We either could drop
it, or use it. Let's use it.
2018-03-27 09:58:00 +02:00
Thomas Haller
199f2df50f manager: convert hwaddr to binary once in find_device_by_permanent_hw_addr()
For comparing MAC addresses, they anyway have to be normalized
to binary. Convert it once outside the loop and pass the binary
form to nm_utils_hwaddr_matches(). Otherwise, we need to re-convert
it every time.
2018-03-27 09:58:00 +02:00
Thomas Haller
4a705e1a0c core: track devices in manager via embedded CList
Instead of using a GSList for tracking the devices, use a CList.
I think a CList is in most cases the more suitable data structure
then GSList:

 - you can find out in O(1) whether the object is linked. That
   is nice, for example to assert in NMDevice's destructor that
   the object was unlinked, and we will use that later in
   nm_manager_get_device_by_path().
 - you can unlink the element in O(1) and you can unlink the
   element without having access to the link's head
 - Contrary to GSList, this does not require an extra slice
   allocation for the link node. It quite possibliy consumes
   slightly less memory because the CList structure is embedded
   in a struct that we already allocate. Even if slice allocation
   would be perfect to only consume 2*sizeof(gpointer) for the link
   note, it would at most be as-good as CList. Quite possibly,
   there is an overhead though.
 - CList possibly has better memory locality, because the link
   structure and the data are close to each other.

Something which could be seen as disavantage, is that with CList
one device can only be tracked in one NMManager instance at a time.
But that is fine. There exists only one NMManager instance for now,
and even if we would ever introduce multiple managers, we probably
would not associate one NMDevice instance with multiple managers.

The advantages are arguably not huge, but CList is IMHO clearly the
more suited data structure. No need to stick to a suboptimal data
structure for the job. Refactor it.
2018-03-27 09:49:43 +02:00
Thomas Haller
987c584bb5 core/dbus: manually inline helper function to emit InterfacesAdded signal 2018-03-26 19:35:26 +02:00
Thomas Haller
640736ff65 core/dbus: cache variants for D-Bus exported properties
GVariant is immutable and can nicely be shared and cached.
Cache the property variants. This makes getting the properties
faster, at the expense of using some extra memory.

Tested with https://tratt.net/laurie/src/multitime/

  $ multitime -n 200 -s 0 bash -c 'echo -n .; exec busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects &>/dev/null'
  #                     Mean                Std.Dev.    Min         Median      Max
  # real(before)        0.013+/-0.0000      0.001       0.012       0.013       0.019
  # real(after)         0.013+/-0.0000      0.002       0.011       0.012       0.034

  $ multitime -n 100 -s 0 bash -c 'for i in {1..5}; do busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects &>/dev/null & done; wait; echo -n .'
  #                     Mean                Std.Dev.    Min         Median      Max
  # real(before)        0.040+/-0.0000      0.002       0.037       0.040       0.049
  # real(after)         0.037+/-0.0000      0.002       0.034       0.036       0.045

  $ multitime -n 30 -s 0 bash -c 'for i in {1..100}; do busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects &>/dev/null & done; wait; echo -n .'
  #                     Mean                Std.Dev.    Min         Median      Max
  # real(before)        0.704+/-0.0000      0.016       0.687       0.701       0.766
  # real(after)         0.639+/-0.0000      0.013       0.622       0.637       0.687

  $ multitime -n 200 -s 0 bash -c 'echo -n .; exec nmcli &>/dev/null'
  #                     Mean                Std.Dev.    Min         Median      Max
  # real(before)        0.092+/-0.0000      0.005       0.081       0.092       0.119
  # real(after)         0.092+/-0.0000      0.005       0.080       0.091       0.123

  $ multitime -n 100 -s 0 bash -c 'for i in {1..5}; do nmcli &>/dev/null & done; wait; echo -n .'
  #                     Mean                Std.Dev.    Min         Median      Max
  # real(before)        0.436+/-0.0000      0.043       0.375       0.424       0.600
  # real(after)         0.413+/-0.0000      0.022       0.380       0.410       0.558

  $ multitime -n 20 -s 0 bash -c 'for i in {1..100}; do nmcli &>/dev/null & done; wait; echo -n .'
  #                     Mean                Std.Dev.    Min         Median      Max
  # real(before)        8.796+/-0.1070      0.291       8.073       8.818       9.247
  # real(after)         8.736+/-0.0893      0.243       8.017       8.780       9.101

The time savings are small, but that is because caching mostly speeds up
the GetManagedObjects calls, and that is only a small part of the entire
nmcli call from client side.
2018-03-26 19:35:26 +02:00
Francesco Giudici
0ed5cd5442 libnm-core: trivial: fix indentation 2018-03-26 18:03:07 +02:00
Thomas Haller
dee6dd6e4e platform: reorder failure checks in nm_platform_ip_route_sync()
Move handling non-NM_IP_CONFIG_SOURCE_USER routes first. These are
routes that were added manually by the user in the connection.

Note that there is no change in behavior, because of how
_err_inval_due_to_ipv6_tentative_pref_src() would only accept
user routes already.
2018-03-26 16:56:05 +02:00
Thomas Haller
9ff6134814 ndisc/trivial: indentation and add "const" to auto variable 2018-03-26 13:13:19 +02:00
Thomas Haller
fc813d1c9e libnm: don't use deprecated tags for GOobject introspection
https://bugzilla.gnome.org/show_bug.cgi?id=744250
https://bugzilla.gnome.org/show_bug.cgi?id=794658
2018-03-26 12:50:43 +02:00
Jiří Klimeš
a751398785 libnm-glib: do not use deprecated Gtk-Doc Type: and Virtual: tags
Signed-off-by: Jiří Klimeš <jklimes@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=744250
2018-03-26 12:46:22 +02:00
Jiří Klimeš
aea3593a43 libnm: don't use deprecated tags for GOobject introspection
Top level tags are deprecated in favour of identifier annotations.
https://mail.gnome.org/archives/commits-list/2013-October/msg03220.html
https://wiki.gnome.org/action/show/Projects/GObjectIntrospection/Annotations?action=show&redirect=GObjectIntrospection%2FAnnotations#Type_signature

Signed-off-by: Jiří Klimeš <jklimes@redhat.com>

https://bugzilla.gnome.org/show_bug.cgi?id=744250
2018-03-26 12:46:22 +02:00