Commit graph

10111 commits

Author SHA1 Message Date
Thomas Haller
490911c6fa platform: assert() for valid item in nm_platform_link_get_all()
Coverity thinks that item might be NULL, but actually it
cannot. Unclear how to avoid the false positive.

(cherry picked from commit 62d4dba74b)
2017-12-12 11:21:05 +01:00
Thomas Haller
99eef7a2ea platform: fix crash hashing NMPlatformTfilter and NMPlatformQdisc
@kind might be NULL. There are 3 forms of the hash-update functions for
string: str(), str0(), and strarr().

- str0() is when the string might be NULL.
- str() does not allow the string to be NULL
- strarr() is like str(), except it adds a G_STATIC_ASSERT()
  that the argument is a C array.

The reason why a difference between str() and str0() exists, is
because str0() hashes NULL different from a "" or any other string.
This has an overhead, because it effectively must hash another bit
of information that tells whether a string was passed or not.

The reason is, that hashing a tupple of two strings should always
yield a different hash value, even for "aa",""; "a","a"; "","aa",
where naive concatentation would yield identical hash values in all
three cases.

Fixes: e75fc8279b
(cherry picked from commit 27e8fffdb8)
2017-12-12 11:21:05 +01:00
Thomas Haller
1bb6b3a79f core: avoid dereferencing NULL in nm_utils_resolve_conf_parse()
Found by coverity.

Fixes: 8f1ef161f4
(cherry picked from commit a7087b1f05)
2017-12-12 11:21:05 +01:00
Thomas Haller
387377d8fc core: fix uninialized boolean variable in reset_autoconnect_all()
It's not critical, because at worst we get a false-positive that
something changed.

Found by coverity.

Fixes: 4e7b05de79
(cherry picked from commit fbc6008260)
2017-12-12 11:21:05 +01:00
Thomas Haller
d6e7857389 platform/tests: fix memleaks in tests
Fixes: 0b0fb045bc
(cherry picked from commit 5201121a1b)
2017-12-11 21:04:58 +01:00
Lubomir Rintel
35e86a0cef device: ensure simple action sdata is a NUL-terminated bytestring
(cherry picked from commit 9639a176ff)
2017-12-11 19:53:09 +01:00
Lubomir Rintel
775893fc00 ifcfg-rh: add tc support
Format:

  QDISC1=ingress
  QDISC2="root handle 1234: fq_codel"
  FILTER1="parent ffff: matchall action simple sdata Input"
  FILTER2="parent 1234: matchall action simple sdata Output"

(cherry picked from commit 902bbfdb18)
2017-12-11 19:53:09 +01:00
Lubomir Rintel
626bf76972 device: set traffic filters when device comes up
(cherry picked from commit 8bffb2c750)
2017-12-11 19:53:09 +01:00
Thomas Haller
014b50fcbe platform: fix TC to-string/hash/cmp functions to include the action
Also add a define NM_PLATFORM_ACTION_KIND_SIMPLE. It makes the
uses of "simple" grepable.

(cherry picked from commit fe3d7209e7)
2017-12-11 19:53:09 +01:00
Lubomir Rintel
97eeadb990 platform: add support for traffic filters
(cherry picked from commit b0fd3ecbaf)
2017-12-11 19:53:09 +01:00
Lubomir Rintel
e881d0ab33 keyfile/tests: test tc traffic filter reading and writing
(cherry picked from commit bc471c8e7a)
2017-12-11 19:43:37 +01:00
Lubomir Rintel
f8da7febbc device: set qdiscs when device comes up
(cherry picked from commit e4bdb21909)
2017-12-11 19:34:31 +01:00
Lubomir Rintel
bb50e73626 keyfile/tests: test tc qdisc reading and writing
(cherry picked from commit 8547387942)
2017-12-11 19:06:28 +01:00
Lubomir Rintel
ea532fd527 platform/tests: tests qdisc caching behavior
Just the most rudimentary tests.

(cherry picked from commit 0b0fb045bc)
2017-12-11 19:00:51 +01:00
Lubomir Rintel
f29db02aac platform: add support for queueing disciplines
(cherry picked from commit ff9f27eb12)
2017-12-11 19:00:46 +01:00
Thomas Haller
0dbcbbcd86 platform: add <linux/tc_act/tc_defact.h> header
We're going to need that one for TC filter & action support.

<linux/tc_act/tc_defact.h> was moved to user-space API only in 2013
by commit 5bc3db5c9ca8407f52918b6504d3b27230defedc. Our travis CI currently
fails to build due to that.

Re-implement the header.

(cherry picked from commit 82befe3c40)
2017-12-11 19:00:44 +01:00
Thomas Haller
c38ed3afa5 platform: merge nm_platform_*_delete() delete functions
It only makes sense to call delete() with NMPObjects that
we obtained from the platform cache. Otherwise, if we didn't
get it from the cache in the first place, we wouldn't know
what to delete.

Hence, the input argument is (almost) always an NMPObject
in the first place. That is different from add(), where
we might create a new specific NMPlatform* instance on the
stack. For add() it makes slightly more sense to have different
functions depending on the type. For delete(), it doesn't.

(cherry picked from commit 7573594a21)
2017-12-11 19:00:41 +01:00
Lubomir Rintel
3db46feb16 platform/nmp-object: (trivial) keep enum ordered by a numeric value
(cherry picked from commit 44be0dfca7)
2017-12-11 18:56:48 +01:00
Lubomir Rintel
cb4c51f014 platform/linux: stringify also NLMSG_* in logs
(cherry picked from commit ffe89f86e0)
2017-12-11 18:56:47 +01:00
Lubomir Rintel
f7df4f0cde platform/trivial: s/ADDRROUTE/OBJECT/ for the cache lookup
It's going to be useful for other objects that have a type (of course)
and an ifindex.

(cherry picked from commit 93ac0e455b)
2017-12-11 18:56:41 +01:00
Lubomir Rintel
d3abc7aed1 ifcfg-rh: drop unused functions
Perhaps a cargo cult leftover.

(cherry picked from commit b49c7e026f)
2017-12-11 18:56:20 +01:00
Lubomir Rintel
b65955148a ifcfg-rh: drop unused and confusing error arguments
(cherry picked from commit 17462a5a5f)
2017-12-11 18:56:13 +01:00
Thomas Haller
5ee3c8912f settings: mark the connection as UNSAVED if it was modified in-memory
(cherry picked from commit 023ce50d21)
2017-12-11 18:49:29 +01:00
Thomas Haller
1702531ce5 settings: for persist-mode KEEP do not ever save the connection to disk
KEEP means to don't do anything, really.

(cherry picked from commit e8299e30b8)
2017-12-11 18:49:28 +01:00
Thomas Haller
70873b541c settings: fix clearing nm-generated/volatile flags of connection
There are a few cases where we don't want to clear a potential
nm-generated/volatile flag, but only mark the connection as
unsaved.

Otherwise, we wrongly end up clearing these flags and the connection
is wrongly not NM_DEVICE_SYS_IFACE_STATE_EXTERNAL.

Fixes: 35dc6421de
(cherry picked from commit 7044febf97)
2017-12-11 12:14:57 +01:00
Thomas Haller
9c6f8ae2d5 core: fix typo for logging of NMSettingsConnectionFlags "nm-generated"
Fixes: c3dd5d8df2
(cherry picked from commit 45ad3ec886)
2017-12-11 09:57:35 +01:00
Francesco Giudici
000e02f56a ifcfg-rh: tests: align json team configuration format to jansson one
(cherry picked from commit 53821a4b13)
2017-12-08 02:18:01 +01:00
Beniamino Galvani
b2a9e2f326 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
(cherry picked from commit a9b5079324)
2017-12-07 10:00:22 +01:00
Francesco Giudici
55321009df 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
(cherry picked from commit 993a726c4a)
2017-12-07 06:53:12 +01:00
Thomas Haller
ceeeb51e1d 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.

(cherry picked from commit 7661ad64ba)
2017-12-06 10:44:44 +01:00
Colin Walters
4bd3069b68 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
(cherry picked from commit 3f6bef47f3)
2017-12-06 10:44:44 +01:00
Thomas Haller
a0a4722432 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.

(cherry picked from commit 35dc6421de)
2017-12-06 09:35:43 +01:00
Thomas Haller
9834c39b73 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.

(cherry picked from commit cfced599ca)
2017-12-06 09:35:43 +01:00
Thomas Haller
4c432ec6a6 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).

(cherry picked from commit 4c84f74326)
2017-12-06 09:35:43 +01:00
Thomas Haller
446c86f4be 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().

(cherry picked from commit ccc93639a0)
2017-12-06 09:35:43 +01:00
Thomas Haller
ab24d5356c 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.

(cherry picked from commit 545e3111c8)
2017-12-06 09:35:43 +01:00
Thomas Haller
e3d81c167c 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.

(cherry picked from commit 4549bd07a1)
2017-12-06 09:35:43 +01:00
Thomas Haller
1c071d388c 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.

(cherry picked from commit 0e1abe5ef3)
2017-12-06 09:35:43 +01:00
Thomas Haller
586e225000 settings: add "connection-flags-changed" signal to connection
We will need to subscribe to changes to "flags" from NMManager.

(cherry picked from commit e704e827c4)
2017-12-06 09:35:43 +01:00
Thomas Haller
32f460af37 settings: block autoconnect of volatile connections
(cherry picked from commit c385cc5107)
2017-12-06 09:35:43 +01:00
Thomas Haller
5f308bc47a settings: move delete call to separate function
(cherry picked from commit 4f819ee435)
2017-12-06 09:35:43 +01:00
Thomas Haller
c7c76c1f32 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.

(cherry picked from commit 1fd5c52eaf)
2017-12-06 09:35:43 +01:00
Thomas Haller
4334069b10 ifcfg-rh: add and use nm_inotify_helper_clear_watch() helper
(cherry picked from commit a3074ee911)
2017-12-06 09:35:43 +01:00
Thomas Haller
6217a97700 ifcfg-rh: move nm-inotify-helper to ifcfg-rh plugin
The helper is only used by ifcfg-rh. Move it to the plugin.

(cherry picked from commit 8e172eb984)
2017-12-06 09:32:27 +01:00
Thomas Haller
e5f41b763a 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.

(cherry picked from commit 31f2a46639)
2017-12-06 09:32:27 +01:00
Thomas Haller
2bff4dd1a6 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.

(cherry picked from commit 8a675f3d13)
2017-12-06 09:32:27 +01:00
Thomas Haller
aaf0973c26 settings: unify settings-update API (drop internal _update())
(cherry picked from commit 141dfd600c)
2017-12-06 09:32:27 +01:00
Thomas Haller
570056af7b settings: unify settings-update API (rename and merge)
(cherry picked from commit 776c5f3893)
2017-12-06 09:32:27 +01:00
Thomas Haller
8b8bb297f7 settings: unify settings-update API (nm_settings_connection_replace_settings())
(cherry picked from commit 9a4225ac96)
2017-12-06 09:32:27 +01:00
Thomas Haller
a703aba62c settings: unify settings-update API (nm_settings_connection_commit_changes())
(cherry picked from commit 1425be0397)
2017-12-06 09:32:27 +01:00