Commit Graph

21088 Commits

Author SHA1 Message Date
Thomas Haller
23b0655ceb keyfile: merge IPv4 and IPv6 version of DNS parser 2018-04-19 09:36:41 +02:00
Thomas Haller
3b8e9a3ea6 keyfile: fix memleak parsing dns values 2018-04-19 09:36:41 +02:00
Thomas Haller
584a06e4e8 keyfile: optimize parsing of addresses/routes in keyfile reader
With this, parsing the properties address/route (for both IPv4/IPv6)
has a runtime complexity of O(n*ln(n)).

Previously, parsing these properties was O(1), but the constant factor
was very high because for each address/route x ipv4/ipv6 combination we would
search about 2*1001 times whether there is a matching value.
Now the runtime complexity is O(n*ln(n)) for each of these 4 properties
where n is the number of entries in the keyfile.

Also note, that we only have 4 properties for which the parsing has
this complexity. Hence, parsing the entire keyfile is still O(n) + 4*O(n*ln(n))
which reduces to O(n*ln(n)). So, parsing the entire keyfile is still benign
and the logarithmic factor comes merely from sorting (which is fast).

Now, the number of supported addresses/routes is no longer limited
to 1000 (as before). Now we would accept all keys up from 0 up to
G_MAXINT32.

Like before, indexes will be automatically adjusted and gaps in the
numbering are accepted. That is convenient, if the user edits the
keyfile manually and deletes some lines. And we anyway must not change
behavior.

  $ multitime -n 200 -s 0 -q ./src/settings/plugins/keyfile/tests/test-keyfile
  # build with -O2 --without-more-asserts
  # before:
                Mean                Std.Dev.    Min         Median      Max
    real        0.290+/-0.0000      0.013       0.275       0.289       0.418
    user        0.284+/-0.0000      0.010       0.267       0.284       0.331
  # after:
                Mean                Std.Dev.    Min         Median      Max
    real        0.101+/-0.0000      0.002       0.099       0.100       0.118
    user        0.096+/-0.0000      0.003       0.091       0.096       0.113
    sys         0.004+/-0.0000      0.002       0.001       0.004       0.009
2018-04-19 09:36:41 +02:00
Thomas Haller
8d93017b16 keyfile/tests: extend test for parsing routes/addresses
Keyfile supports both route*/address* and routes*/addresses*
fields at the same time. Extend the tests, that they are read
all as expected.
2018-04-19 09:36:41 +02:00
Thomas Haller
8f967d0281 keyfile: minor cleanup parsing IP addresses/routes 2018-04-19 09:36:41 +02:00
Thomas Haller
1636e6411b keyfile: fix freeing connection in error path of nm_keyfile_read()
Fixes: 04df4edf48
2018-04-19 09:36:41 +02:00
Thomas Haller
6ff613c21f keyfile/tests: add test reading VPN profile 2018-04-19 09:36:41 +02:00
Beniamino Galvani
21d3f16809 core: unexport dbus-objects on dispose
When the D-Bus name is already taken, NM crashes in the following
way. That's because disposed object are not unexported when quitting
and so they linger in the bus-manager's list of exported objects,
causing an invalid access when a neighboring item is accessed. Instead
of just clearing the path, fully unexport the object.

The behavior of not forcefully exporting objects on quit was added in
f9ee20a7b2 ("core: explicitly unexport objects when we're done with
them"), but such behavior doesn't seem to be needed by the stated
goal.

 <error> [1524062008.1886] bus-manager: fatal failure to acquire D-Bus service "org.freedesktop.NetworkManager" (3). Service already taken
 <trace> [1524062008.2327] config: state: success writing state file "/var/lib/NetworkManager/NetworkManager.state"
 <trace> [1524062008.2338] dns-mgr: stopping...
 <info>  [1524062008.2344] exiting (error)
 <debug> [1524062008.2628] disposing NMManager singleton (0xce587e0)
 <trace> [1524062008.2640] dns-mgr: disposing
 <debug> [1524062008.2651] disposing NMDnsManager singleton (0xceb8b50)
 <debug> [1524062008.2666] disposing NMFirewallManager singleton (0xceb62b0)
 <debug> [1524062008.2709] disposing NMHostnameManager singleton (0xce7b370)
 <trace> [1524062008.2722] dbus-object[0xce70f40]: unexport: "/org/freedesktop/NetworkManager/AgentManager"
 ==16381== Invalid write of size 8
 ==16381==    at 0x42F511: c_list_unlink_stale (c-list.h:158)
 ==16381==    by 0x42F511: c_list_unlink (c-list.h:171)
 ==16381==    by 0x42F511: _nm_dbus_manager_obj_unexport (nm-dbus-manager.c:1135)
 ==16381==    by 0x4C5E35: nm_dbus_object_unexport (nm-dbus-object.c:165)
 ==16381==    by 0x5C01E9: dispose (nm-agent-manager.c:1634)
 ==16381==    by 0x6636F37: g_object_unref (gobject.c:3303)
 ==16381==    by 0x4BDC89: _nm_singleton_instance_destroy (nm-core-utils.c:138)
 ==16381==    by 0x400FA85: _dl_fini (in /usr/lib64/ld-2.27.so)
 ==16381==    by 0x7F806AB: __run_exit_handlers (in /usr/lib64/libc-2.27.so)
 ==16381==    by 0x7F807DB: exit (in /usr/lib64/libc-2.27.so)
 ==16381==    by 0x41DA34: main (main.c:463)
 ==16381==  Address 0xce706a0 is 48 bytes inside a block of size 176 free'd
 ==16381==    at 0x4C2EDAC: free (vg_replace_malloc.c:530)
 ==16381==    by 0x6ACA3E1: g_free (gmem.c:194)
 ==16381==    by 0x6AE2572: g_slice_free1 (gslice.c:1136)
 ==16381==    by 0x66550AE: g_type_free_instance (gtype.c:1943)
 ==16381==    by 0x4505F8: dispose (nm-manager.c:6867)
 ==16381==    by 0x6636F37: g_object_unref (gobject.c:3303)
 ==16381==    by 0x4BDC89: _nm_singleton_instance_destroy (nm-core-utils.c:138)
 ==16381==    by 0x400FA85: _dl_fini (in /usr/lib64/ld-2.27.so)
 ==16381==    by 0x7F806AB: __run_exit_handlers (in /usr/lib64/libc-2.27.so)
 ==16381==    by 0x7F807DB: exit (in /usr/lib64/libc-2.27.so)
 ==16381==    by 0x41DA34: main (main.c:463)
 ==16381==  Block was alloc'd at
 ==16381==    at 0x4C2DBAB: malloc (vg_replace_malloc.c:299)
 ==16381==    by 0x6ACA2D5: g_malloc (gmem.c:99)
 ==16381==    by 0x6AE1E36: g_slice_alloc (gslice.c:1025)
 ==16381==    by 0x6AE247C: g_slice_alloc0 (gslice.c:1051)
 ==16381==    by 0x6654E09: g_type_create_instance (gtype.c:1848)
 ==16381==    by 0x66376C7: g_object_new_internal (gobject.c:1799)
 ==16381==    by 0x6638E14: g_object_new_with_properties (gobject.c:1967)
 ==16381==    by 0x66399D0: g_object_new (gobject.c:1639)
 ==16381==    by 0x5D6F18: nm_settings_new (nm-settings.c:1897)
 ==16381==    by 0x4514B4: constructed (nm-manager.c:6489)
 ==16381==    by 0x66378FA: g_object_new_internal (gobject.c:1839)
 ==16381==    by 0x6638E14: g_object_new_with_properties (gobject.c:1967)

https://github.com/NetworkManager/NetworkManager/pull/96
2018-04-19 09:29:25 +02:00
Beniamino Galvani
9967f099dd merge: branch 'bg/n-acd-rh1507864'
Rework the IPv4 duplicate address detection to use code from n-acd [1].

[1] https://github.com/nettools/n-acd

https://bugzilla.redhat.com/show_bug.cgi?id=1507864
2018-04-18 15:33:43 +02:00
Beniamino Galvani
3886cc8e0c core: rename 'arping' to 'acd'
Now that the ACD functionality is no longer using arping, rename
nm-arping-manager to nm-acd-manager and other occurences of arping as
well.
2018-04-18 15:22:34 +02:00
Beniamino Galvani
f2e143f002 libnm-core: fix documentation for dad-timeout property 2018-04-18 15:22:32 +02:00
Beniamino Galvani
943a12c6e3 ifcfg-rh: persist ipv4.dad-timeout without rounding
Introduce a new ifcfg-rh variable ACD_TIMEOUT that stores the exact
value of ipv4.dad-timeout without rounding. We still write the
initscripts-compatible ARPING_WAIT variable, and read it when
ACD_TIMEOUT is missing.
2018-04-18 15:22:28 +02:00
Beniamino Galvani
df488184a8 arping: print IP address conflicts
Print a warning whenever we find a IP conflict on the network. In the
future we may export a flag on the device or send a signal so that
clients can notify the user of the conflict.
2018-04-18 15:22:25 +02:00
Beniamino Galvani
ac8618c78f arping: slightly simplify logging
Don't return an error from nm_arping_manager_start_probe() since it is
currently useless and the arping-manager already prints the failure
reason. Also, drop a log print from add_address().
2018-04-18 15:22:23 +02:00
Beniamino Galvani
9f79ae685d arping: use n-acd
NMArpingManager previously spawned an arping process for each
probed/announced address and watched it. This has the disadvantage of
being inefficient and also that for small timeouts we can't be sure
that arping actually started the probe.

Switch to an implementation that doesn't need to spawn external
processes, by using the n-acd code [1] currently imported in our
source tree. The long term plan is that n-acd will become a shared
library we can link against.

The file is still called nm-arping-manager for lazyness, even if a
better name would be nm-acd-manager.

[1] https://github.com/nettools/n-acd/

https://bugzilla.redhat.com/show_bug.cgi?id=1507864
2018-04-18 15:22:21 +02:00
Beniamino Galvani
7ac93a03b0 build: meson: link NM against n-acd 2018-04-18 15:22:18 +02:00
Beniamino Galvani
29a04f54a6 build: autotools: link NM against n-acd 2018-04-18 15:22:16 +02:00
Beniamino Galvani
19876b4cfe shared: drop duplicate c-list.h header
Use the one from the project just imported.
2018-04-18 15:22:14 +02:00
Beniamino Galvani
5f8737bdd5 shared: fix nmtst_main_loop_run()
If the main loop is quit before the timeout expires, we leave the
timeout source running on the main loop context. Since we usually
create the main loop using the default context, the source will fire
on the next main loop we create during the test.

Therefore, destroy the timeout source if it is still active.

Fixes: 766f31507b
2018-04-18 15:22:12 +02:00
Beniamino Galvani
8c3023d471 n-acd: use CLOCK_MONOTONIC timers on older kernels
The README states that a kernel >= 3.0 is enough, however
CLOCK_BOOTTIME is only available since kernel 3.15.

Fall back to CLOCK_MONOTONIC when CLOCK_BOOTTIME is not available.

See: https://github.com/nettools/n-acd/pull/3

Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
2018-04-18 15:22:10 +02:00
Beniamino Galvani
8a01bdc2d1 Merge commit '23cbce4bc9c70fc33d3413fc1b9a5f3303498036' as 'shared/n-acd'
Imported n-acd code with command:

  git subtree add --prefix shared/n-acd git@github.com:nettools/n-acd.git a68b55992dd7b38bdb9dbbdba4a9284ff2c2cce3 --squash

To update the library use:

  git subtree pull --prefix shared/n-acd git@github.com:nettools/n-acd.git master --squash
2018-04-18 15:21:26 +02:00
Beniamino Galvani
23cbce4bc9 Squashed 'shared/n-acd/' content from commit a68b55992
git-subtree-dir: shared/n-acd
git-subtree-split: a68b55992dd7b38bdb9dbbdba4a9284ff2c2cce3
2018-04-18 15:21:19 +02:00
Beniamino Galvani
b16b4a4362 Merge commit 'afe2594a7799d3113470c40664c6eda88b83c7e5' as 'shared/c-list'
Imported c-list code with command:

  git subtree add --prefix shared/c-list/ git@github.com:c-util/c-list.git master --squash

To update the library use:

  git subtree pull --prefix shared/c-list/ git@github.com:c-util/c-list.git master --squash
2018-04-18 15:20:40 +02:00
Beniamino Galvani
afe2594a77 Squashed 'shared/c-list/' content from commit 317aa1c65
git-subtree-dir: shared/c-list
git-subtree-split: 317aa1c65743ff528a27542f6785d29a05cc6e0c
2018-04-18 15:20:33 +02:00
Beniamino Galvani
579f17cfee Merge commit '1ea09eb549dbd910ea593e01fb6f746ae20b4beb' as 'shared/c-siphash'
Imported c-siphash code with command:

  git subtree add --prefix shared/c-siphash/ git@github.com:c-util/c-siphash.git master --squash

To update the library use:

  git subtree pull --prefix shared/c-siphash/ git@github.com:c-util/c-siphash.git master --squash
2018-04-18 15:20:01 +02:00
Beniamino Galvani
1ea09eb549 Squashed 'shared/c-siphash/' content from commit 24e301e32
git-subtree-dir: shared/c-siphash
git-subtree-split: 24e301e32939be88744a9d0f81d18d9b7b8f4e37
2018-04-18 15:19:58 +02:00
Beniamino Galvani
aca671fff0 all: replace "it's" with "its" where needed 2018-04-18 14:14:07 +02:00
Thomas Haller
b01ebd7399 core: merge branch 'th/manager-cleanup'
https://github.com/NetworkManager/NetworkManager/pull/91
2018-04-18 14:08:43 +02:00
Thomas Haller
c3fb02641a device: set device's sys-iface-state only shortly before activating device
During _new_active_connection() we just create the NMActiveConnection
instance to proceed with authorization. The caller might not even
authorize, so we must not touch the device yet.

Do that only later.
2018-04-18 07:55:15 +02:00
Thomas Haller
9fe4239f33 manager: some refactoring of error paths to return early
Often, functions perform a series of steps, and when they fail,
they bail out. It's simpler if the code is structured that way,
so you can read it from top to bottom and whenever something is
wrong, either return directly (or goto a cleanup label at the
bottom).
2018-04-18 07:55:15 +02:00
Thomas Haller
5c4a6e9b6d manager: ensure valid specific_object path is passed to _new_active_connection()
From the D-Bus layer, no specific-object is represented by "/". We
should early on normalize such values to NULL, and not expect or
handle them later (like during _new_active_connection()).
2018-04-18 07:55:15 +02:00
Thomas Haller
10753c3616 manager: merge VPN handling into _new_active_connection()
Merge _new_vpn_active_connection() into _new_active_connection(). It was the
only caller, and it is simpler to have all the code visible at one place.

That also shows, that the device argument is ignored and not handled.
Ensure that no device is specified for VPN type activations.
2018-04-18 07:55:15 +02:00
Thomas Haller
0458e4bb28 manager: use cleanup attribute in impl_manager_add_and_activate_connection() and related
Also, in _add_and_activate_auth_done(), always steal the connection
from active's user-data. Otherwise, the lifetime of the connection
is extended until active gets destroyed. For example, if we would leak
active, we would also leak connection that way.
2018-04-18 07:55:15 +02:00
Thomas Haller
3e3d53ce69 manager: add is-vpn argument to _new_active_connection() and avoid searching existing activations
- pass is-vpn to _new_active_connection(). It is confusing that _new_active_connection()
  would re-determine whether a connection is a VPN type, although that was already
  established previously. The confusing part is: will they come to the
  same result? Why? What if not?
  Instead pass it as argument and assert that we got it right.

- the check for existing connections should look whether there is an existing
  active connection of type NMVpnConnection. Instead, what matters is,
  - do we have a connection of type VPN (otherwise, don't even bother
    to search for existing-ac)
  - is the connection already active?
  Checking whether the connection is already active, and ask backwards
  whether it's of type NMVpnConnection is odd, maybe even wrong in
  some cases.
2018-04-18 07:55:15 +02:00
Thomas Haller
7fcdca29b6 manager: add _connection_is_vpn() helper to unify checks for VPN type 2018-04-18 07:55:15 +02:00
Thomas Haller
bdc622fd31 manager/trivial: rename boolean variable "vpn" to "is_vpn" 2018-04-18 07:55:15 +02:00
Thomas Haller
bac7a2821f core: cleanup NMManager's validate_activation_request()
- there are only two callers of validate_activation_request(). One of them,
  might already lookup the device before calling the validate function.
  Safe to looking up again. But this is not only an optimization, more importantly,
  it feels odd to first lookup a device, and then later look it up again. Are
  we guaranteed to use the same path? Why? Just avoid that question.
- re-order some error checking for missing device, so that it is clearer.
- use cleanup attribute to handle return value and drop the "goto error".
2018-04-18 07:55:15 +02:00
Thomas Haller
aa86327e45 core: cleanup code by using nm_auth_is_subject_in_acl_set_error() 2018-04-18 07:55:15 +02:00
Thomas Haller
f94167d8b1 core: add nm_auth_is_subject_in_acl_set_error() helper 2018-04-18 07:55:15 +02:00
Thomas Haller
1a33ab17de core: downgrade assertion to nm_assert()
It can be easily verified, that these assertions should not ever fail.
Disable in production builds.
2018-04-18 07:55:15 +02:00
Thomas Haller
580a11da3a core: minor cleanup of handling specific-object in NMActiveConnection
- use nm_assert() for something that ~really~ always should be given.
- use nm_streq0() and nm_clear_g_free().
2018-04-18 07:55:15 +02:00
Thomas Haller
476208d223 core: don't explicitly set D-Bus path properties to "/"
NMDBusObject already gets this right, by calling nm_dbus_utils_get_property(),
which calls g_dbus_gvalue_to_gvariant(), which correctly converts NULL
object paths to "/".

We already rely on that elsewhere. No need for this workaround.
2018-04-18 07:55:15 +02:00
Thomas Haller
5284690f18 core: use nm_utils_dbus_normalize_object_path() to cleanup D-Bus argument 2018-04-18 07:55:15 +02:00
Thomas Haller
34bbcc70b8 core: sort D-Bus paths in nm_dbus_utils_g_value_set_object_path_from_hash() 2018-04-18 07:55:15 +02:00
Thomas Haller
6ec4dfce69 libnm-core: improve documentation for autoconnect and autoconnect-slaves properties 2018-04-18 07:55:15 +02:00
Thomas Haller
56a3f3bba9 shared: add nm_utils_dbus_normalize_object_path() helper 2018-04-18 07:55:15 +02:00
Thomas Haller
be9a5ab308 shared: add nm_utils_strv_sort() helper 2018-04-18 07:55:15 +02:00
Thomas Haller
458b422468 shared: add NM_CAST_STRV_*() helper macros 2018-04-18 07:55:15 +02:00
Thomas Haller
a99d51cb50 auth-manager: fix potential issue iterating modified CList in _dbus_new_proxy_cb()
In the loop, we invoke callbacks. What the callbacks do, is out of control
of NMAuthManager. For example, they could cancel or schedule new
requests. Especially, cancelling invalidate the stored @safe pointer.

Fix that, by always iterate from the start of the list.

Fixes: d0563f0733
2018-04-18 07:51:29 +02:00
Beniamino Galvani
0fa57069ad auth-manager: fix processing calls in _dbus_new_proxy_cb()
In the first loop, the element is removed only when the callback is
executed. The second loop never removes the current element. Use the
for_each macro for both.

Fixes: d0563f0733
2018-04-17 16:22:34 +02:00