Commit graph

10105 commits

Author SHA1 Message Date
Francesco Giudici
53821a4b13 ifcfg-rh: tests: align json team configuration format to jansson one 2017-12-08 00:46:26 +01:00
Beniamino Galvani
a9b5079324 ifcfg-rh: use separate variables for DNS searches
DNS searches from the ipv4 and ipv6 settings were joined and written
to the same ifcfg-rh "DOMAIN" variable and so the connection read back
from disk was different from the one written.

Instead, introduce a separate variable for ipv6 searches; to preserve
backwards compatibility, still read the "DOMAIN" variable for ipv6
when ipv4 is disabled so that we don't lose DNS searches on upgrade.

https://bugzilla.redhat.com/show_bug.cgi?id=1517794
2017-12-07 09:58:09 +01:00
Francesco Giudici
993a726c4a ifcfg-rh: initialize watch descriptors to -1
This is now required as we instance inotify-helper only on need:
we have to init them to the unset value, otherwise...

	Thread 1 "NetworkManager" received signal SIGSEGV, Segmentation fault.
	nm_inotify_helper_remove_watch (self=0x0, wd=0) at src/settings/plugins/ifcfg-rh/nm-inotify-helper.c:100
	100		if (priv->ifd < 0)
	(gdb) backtrace
	#0  0x00007fffe35da6c0 in nm_inotify_helper_remove_watch (self=0x0, wd=0) at src/settings/plugins/ifcfg-rh/nm-inotify-helper.c:100
	#1  0x00007fffe35d45b1 in nm_inotify_helper_clear_watch (wd=0x7fffdc008628, helper=<optimized out>) at src/settings/plugins/ifcfg-rh/nm-inotify-helper.h:53
	#2  0x00007fffe35d45b1 in path_watch_stop (self=0x7fffdc0085f0) at src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c:223
	#3  0x00007fffe35d467c in filename_changed (object=0x7fffdc0085f0, pspec=<optimized out>, user_data=<optimized out>) at src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c:242
	#4  0x00007ffff61b230d in g_closure_invoke () at /lib64/libgobject-2.0.so.0
	#5  0x00007ffff61c498e in signal_emit_unlocked_R () at /lib64/libgobject-2.0.so.0
	#6  0x00007ffff61cd1a5 in g_signal_emit_valist () at /lib64/libgobject-2.0.so.0
	#7  0x00007ffff61cdb0f in g_signal_emit () at /lib64/libgobject-2.0.so.0
	#8  0x00007ffff61b6594 in g_object_dispatch_properties_changed () at /lib64/libgobject-2.0.so.0
	#9  0x00007ffff61b5f3e in g_object_notify_queue_thaw () at /lib64/libgobject-2.0.so.0
	#10 0x00007ffff61b7776 in g_object_new_internal () at /lib64/libgobject-2.0.so.0
	#11 0x00007ffff61b924d in g_object_new_valist () at /lib64/libgobject-2.0.so.0
	#12 0x00007ffff61b9691 in g_object_new () at /lib64/libgobject-2.0.so.0
	#13 0x00007fffe35d5018 in nm_ifcfg_connection_new (source=source@entry=0x0, full_path=full_path@entry=0x555555a9a590 "/etc/sysconfig/network-scripts/ifcfg-team3", error=error@entry=0x7fffffffdc30, out_ignore_error=out_ignore_error@entry=0x7fffffffdc2c) at src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-connection.c:429
	#14 0x00007fffe35d5e96 in update_connection (self=self@entry=0x555555a59ea0, source=source@entry=0x0, full_path=0x555555a9a590 "/etc/sysconfig/network-scripts/ifcfg-team3", connection=connection@entry=0x0, protect_existing_connection=protect_existing_connection@entry=0, protected_connections=protected_connections@entry=Python Exception <class 'gdb.error'> There is no member named keys.:
	0x555555a9fc00, error=0x0) at src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c:218
	#15 0x00007fffe35d7073 in read_connections (plugin=plugin@entry=0x555555a59ea0) at src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c:545
	#16 0x00007fffe35d72f1 in get_connections (config=0x555555a59ea0) at src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-plugin.c:581
	#17 0x00005555556bb513 in load_connections (self=0x555555a1a920) at src/settings/nm-settings.c:239
	#18 0x00005555556bb513 in nm_settings_start (self=0x555555a1a920, error=<optimized out>) at src/settings/nm-settings.c:1800
	#19 0x00005555555ada1f in nm_manager_start (self=0x555555a490c0, error=<optimized out>) at src/nm-manager.c:5262
	#20 0x00005555555851ae in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:417

Fixes: 31f2a46639
2017-12-07 02:48:45 +01:00
Thomas Haller
7661ad64ba all: use cast macros instead of C cast
When building with assertions, they nm_assert() for the
type. Otherwise, they are identical to a C cast.

Also, where possible, don't cast at all, but adjust
the type instead.

Also, there were a few missing casts.
2017-12-06 10:34:28 +01:00
Colin Walters
3f6bef47f3 tree-wide: cast after g_object_ref() for proposed GLib patch
This fixes the build with related bug https://bugzilla.gnome.org/show_bug.cgi?id=790697

https://mail.gnome.org/archives/networkmanager-list/2017-December/msg00005.html
2017-12-06 10:34:28 +01:00
Beniamino Galvani
0decb9eac6 device: restore original dynamic IPv6 configuration on reapply 2017-12-06 09:53:18 +01:00
Beniamino Galvani
7217ec09e3 device: restore original dynamic IPv4 configuration on reapply
The dynamic IPv4 configuration from DHCP/PPP/... and WWAN is stored in
priv->{dev,wwan}_ip4_config; when the user removes externally an
address or a route, we prune it from those configurations. Therefore
such addresses and routes can't be restored on a device reapply.

Introduce an AppliedConfig structure that stores both the original and
the current (after external changes) configuration so that we can
restore the original one on reapply.
2017-12-06 09:53:18 +01:00
Beniamino Galvani
898b978e36 device: remove 'force_restart' argument from reactivate functions
It is now unused.

https://bugzilla.gnome.org/show_bug.cgi?id=790061
2017-12-06 09:53:18 +01:00
Beniamino Galvani
f4cbed3d4f device: don't force a restart of IP configuration on reapply
Restarting the IP configuration removes addresses and routes for a
short time breaking connectivity. The reapply process should have the
minimal impact possible.

https://bugzilla.gnome.org/show_bug.cgi?id=790061
2017-12-06 09:53:18 +01:00
Beniamino Galvani
e5a8aba225 core: add non-destructive ip config intersect function
Add a new function to compute the intersection between 2 IP
configurations without modifying them.
2017-12-06 09:53:18 +01:00
Beniamino Galvani
eae63475d9 core: add generic functions for set operations 2017-12-06 09:53:18 +01:00
Beniamino Galvani
4cbf594779 core: add nm_ipX_config_clone() 2017-12-06 09:53:18 +01:00
Beniamino Galvani
057744b722 core: drop unused macro argument 2017-12-06 09:53:18 +01:00
Thomas Haller
35dc6421de settings: support setting a connection as volatile via Update2()
Extend the Update2 flags to allow marking a connection as volatile.
Making a connection as volatile means that the connection stays alive
as long as an active connection references it.

It is correct that Update2() returns before the connection is actually
deleted. It might take an arbitrary long time until the volatile
mechanism cleans up the connection.

Also add two more IN_MEMORY flags: "detached" and "only".

The existing NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY would not detach nor
delete the possible file on disk. That is, the mode only changes what NM
thinks is the current content of the connection profile. It would not delete
the file on disk nor would it detach the profile in-memory from the file.
As such, later persisting the connection again to disk would overwrite
the file, and deleting the profile, would delete the file.

Now add two new IN_MEMORY modes.

NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY_DETACH is like making the connection
in-memory only, but forgetting that there might be any profile on disk.
That means, a later Delete() would not delete the file. Similarly, a
later Update2() that persists the connection again, would not overwrite
the existing file on disk, instead it would choose a new file name.

On the other hand, NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY_ONLY would delete
a potential file from disk right away.

It's clear that "volatile" only makes sense with either "in-memory-detached"
or "in-memory-only". That is, the file on disk should be deleted right away
(before the in-memory part is garbage collected) or the file on disk should
be forgotten.
2017-12-05 20:18:10 +01:00
Thomas Haller
cfced599ca settings: delete volatile connection and support setting the volatile flag
Previously, we would only set a connection as volatile before
adding it to manager. As we never would set it volatile last on,
there was no need to handle deletion.

Now support that. Watch the volatile flag, and if the connection
has currently not active connection that keeps it alive, delete
it in an idle handler.
2017-12-05 19:57:25 +01:00
Thomas Haller
4c84f74326 manager/trivial: reorder declarations at beginning of file
First, define structs. Then forward declare functions. Reorder code
to have a certain order that is also used by other files (or should
be).
2017-12-05 19:57:25 +01:00
Thomas Haller
ccc93639a0 settings: let invisible connection not autoconnect according to is_blocked() function
Previously, NMPolicy would explicitly check whether the connection is not visible,
to skip autoconnect.

We have nm_settings_connection_autoconnect_is_blocked() function, that can do that.
The advantage is, that at various places we call nm_settings_connection_autoconnect_is_blocked()
to determine whether autoconnect is blocked. By declaring invisible connections
as blocked from autoconnect as well, we short-cut various autoconnection attempts,
that previoulsy only failed later during auto_activate_device().
2017-12-05 19:57:25 +01:00
Thomas Haller
545e3111c8 settings: remove accessor functions to connection flags
The accessor functions just look whether a certain flag is set. As these
functions have a different name then the flags, this is more confusing
then helpful. For example, if you want to know where the NM_GENERATED
flag matters, you had to know to grep for nm_settings_connection_get_nm_generated()
in addition to NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED.

The accessor function hid that the property was implemented as
a connection flag. For example, it was not immediately obvious
that nm_settings_connection_get_nm_generated() is the same
as having the NM_SETTINGS_CONNECTION_FLAGS_NM_GENERATED flag
set.

Drop them.
2017-12-05 19:57:25 +01:00
Thomas Haller
4549bd07a1 settings: refactor setting connection flags
It seems more idiomatic to have a mask+value argument, instead
of setting all flags at once. At least, other setters work this
way, so change it for consistency.
2017-12-05 19:57:25 +01:00
Thomas Haller
0e1abe5ef3 settings: track visible state as regular connection flags
We already need to re-emit the notify::flags signal.
It's cumbersome to do this for boolean properties, so
re-use the flags to also track the visibility state.
2017-12-05 19:57:25 +01:00
Thomas Haller
e704e827c4 settings: add "connection-flags-changed" signal to connection
We will need to subscribe to changes to "flags" from NMManager.
2017-12-05 19:57:25 +01:00
Thomas Haller
c385cc5107 settings: block autoconnect of volatile connections 2017-12-05 19:57:25 +01:00
Thomas Haller
4f819ee435 settings: move delete call to separate function 2017-12-05 19:57:24 +01:00
Thomas Haller
1fd5c52eaf settings: clear filename after deleting file from disk
It doesn't really matter, because in the next step we
are about to remove the connection.

However, once the connection is deleted from file, it's
clear that it has no more file-name.
2017-12-05 19:57:24 +01:00
Thomas Haller
a3074ee911 ifcfg-rh: add and use nm_inotify_helper_clear_watch() helper 2017-12-05 19:57:24 +01:00
Thomas Haller
8e172eb984 ifcfg-rh: move nm-inotify-helper to ifcfg-rh plugin
The helper is only used by ifcfg-rh. Move it to the plugin.
2017-12-05 19:57:24 +01:00
Thomas Haller
31f2a46639 ifcfg-rh: fix path_watch_stop() not to create inotify-helper
Commonly, we don't monitor files and hence don't need the inotify-helper
instance. We already access and construct the instance lazy, by
accessing the singleton getter only when needed.

However, path_watch_stop() would always access the singleton, hence
always create such an instance. In most cases there is nothing to clean,
and no such instance shall be created.
2017-12-05 19:57:24 +01:00
Thomas Haller
8a675f3d13 settings: pass new_connection to commit_changes() and fix ifnet
ifnet shall use the new_connection argument, not NM_CONNECTION(self).
Also, let the caller of the virtual function provide the right new_connection,
not having the virtual function figure that out.
2017-12-05 19:57:24 +01:00
Thomas Haller
141dfd600c settings: unify settings-update API (drop internal _update()) 2017-12-05 19:57:24 +01:00
Thomas Haller
776c5f3893 settings: unify settings-update API (rename and merge) 2017-12-05 19:57:24 +01:00
Thomas Haller
9a4225ac96 settings: unify settings-update API (nm_settings_connection_replace_settings()) 2017-12-05 19:57:24 +01:00
Thomas Haller
1425be0397 settings: unify settings-update API (nm_settings_connection_commit_changes()) 2017-12-05 19:57:24 +01:00
Thomas Haller
8bb95a8365 settings: add NM_SETTINGS_UPDATE2_FLAG_BLOCK_AUTOCONNECT flag 2017-12-05 19:57:24 +01:00
Thomas Haller
98ff1e291c core: clear autoconnect-blocked-reason USER_REQUEST when activating connection 2017-12-05 19:57:24 +01:00
Thomas Haller
98ee18d888 all: add new D-Bus API org.freedesktop.NetworkManager.Settings.Connection.Update2()
We already have Update(), UpdateUnsaved() and Save(), which serve
similar purposes. We will need a form of update with another argument.

Most notably, to block autoconnect while doing the update.

Other use cases could be to prevent reapplying connection.zone and
connection.metered, to to reapply all changes.

Instead of adding a specific update function that only serves that
new use-case, add a extensible Update2() function. It can be extended
to cope with future variants of update.
2017-12-05 11:50:52 +01:00
Thomas Haller
d26c749ea6 checkpoint: don't bypass settings-connection commit code on rollback
commit involves more then just replacing the setting and writing them
out. What? Dunno. It's complex.

But let's not bypass the commit-changes function. That one is supposed
to get it right.
2017-12-05 11:50:52 +01:00
Thomas Haller
f73e78770e settings/trivial: rename update function in nm-settings-connection.c 2017-12-05 11:50:52 +01:00
Thomas Haller
ad9deb6968 settings: merge _replace_settings_full() into _commit_changes_full()
It's complicated what happens during a commit/replace/update (whatever
you call it).

It doesn't get simpler by spreading it out to various functions.
Let's have one large function (_commit_changes_full()) which does
all the steps necessary. There should be no alternative ways
how to update a connection.
2017-12-05 11:50:52 +01:00
Thomas Haller
7a0900be7c settings: always call _commit_changes_full() instead of _replace_settings_full()
All callers of _replace_settings_full() now use _commit_changes_full().
commit-changes should contain all the logic what to do when updating
a connection. Now, the connection might optionally be written to disk.
2017-12-05 11:50:52 +01:00
Thomas Haller
4fd5e6e1bb settings: in _commit_changes_full() mark the connection as saved before emitting signals
_commit_changes_full() calls _replace_settings_full() which already emits signals
about the changed connection. We should mark the connectin as saved earlier.

In fact, we can tell _replace_settings_full() to mark it as not-unsaved
via the persist-mode parameter.
2017-12-05 11:50:52 +01:00
Thomas Haller
9988f9dbbb settings: call replace-settings also without new settings
_replace_settings_full() does more then just replace the settings.
It at least also sets some flags, like saved/unsaved depending
on @persist_mode.

_replace_settings_full() also emits the "updated" signal. Note that
previously it would just return without signal if nm_connection_compare()
indicates that there is no difference. But the caller probably cares
about whether the user tries to change the connection at all, not
whether the change actually introduced a real difference in the
settings. Like, policy might re-set the autoconnect blocked flags.
But it should do so on every user-update, regardless of whether
a change was actually made.

It makes sense to call _replace_settings_full() with a @new_connection
of %NULL, to mean: just update the flags, but keep the current connection.

Extend _replace_settings_full() to allow for that.

Also, update update_auth_cb() to always call _replace_settings_full(),
even if no new connection is provided. In this case, only update
the connection flags accordingly.
2017-12-05 11:50:52 +01:00
Thomas Haller
3706fd17eb settings: refactor update_auth_cb() and prepare connection once
Note how nm_settings_connection_commit_changes() would call
prepare() a second time. Don't do that.

Also, move the prepare step earlier, and call _replace_settings_full()
without preparing the new connection again.
2017-12-05 11:50:52 +01:00
Thomas Haller
75f787d1da settings: split nm_settings_connection_commit_changes() to call it without preparing the new connection
Will be used next.
2017-12-05 11:50:52 +01:00
Thomas Haller
9531da8b3e settings: add persistent-mode argument for connection-replace
The current behavior of update_unsaved is confusing. Give the argument
an enum with a name that describes better what's happening. Also, it
makes the uses grep-able.
2017-12-05 11:50:52 +01:00
Thomas Haller
c3dd5d8df2 settings: log pretty names for settings-connection flags 2017-12-05 11:50:52 +01:00
Thomas Haller
c3d192b6a3 ifcfg-rh: avoid unnecessary string copies in add_one_wep_key() 2017-12-04 15:53:53 +01:00
Thomas Haller
5a857b3922 ifcfg-rh: use NM_IN_SET() macro in add_one_wep_key()
Evaluate strlen() only once.
2017-12-04 15:53:53 +01:00
Thomas Haller
da6394d572 ifcfg-rh: use NM_STRCHAR_ANY() macro in add_one_wep_key() 2017-12-04 15:53:53 +01:00
Beniamino Galvani
c6eb18ee05 ifcfg-rh: persist the wep key type
The wireless-security setting has a 'wep-key-type' property that is
used to specify the WEP key type and is needed because some keys could
be interpreted both as a passphrase or a hex/ascii key.

The ifcfg-rh plugin currently stores the key type implicitly: if
wep-key-type is 'passphrase' it uses the KEY_PASSPHRASE%d variable, if
it's 'key' the KEY%d variable and when it's 'unknown' it uses either
variables depending on the detected type (preferring 'key' in case
both are compatible).

This means that some connections will be read differently from how
they were written, because once the KEY (or KEY_PASSPHRASE) is read
there is no way to know whether the 'wep-key-type' property was 'key'
(or 'passphrase') or 'unknown'.

Fix this by persisting the key type explicitly in the file. The new
variable is redundant in most cases because the variables used for
keys also determine the key type.

https://bugzilla.redhat.com/show_bug.cgi?id=1518177
2017-12-04 15:53:53 +01:00
Thomas Haller
9b08f2c61d ifcfg-rh: only open network file once when parsing connection 2017-11-30 23:54:45 +01:00