Commit graph

23097 commits

Author SHA1 Message Date
Thomas Haller
4e3955e6dd libnm: mark NMVariantAttributeSpec pointers as const
This actually allows the compiler/linker to mark the memory as read-only and any
modification will cause a segmentation fault.

I would also think that it allows the compiler to put the structure directly
beside the outer constant array (in which this pointer is embedded). That is good
locality-wise.
2019-05-07 20:58:17 +02:00
Thomas Haller
cc9f071676 libnm: cleanup _nm_utils_parse_tc_handle()
- g_ascii_strtoll() accepts leading spaces, but it leaves
  the end pointer at the first space after the digit. That means,
  we accepted "1: 0" but not "1 :0". We should either consistently
  accept spaces around the digits/colon or reject it.

- g_ascii_strtoll() accepts "\v" as a space (just like `man 3 isspace`
  comments that "\v" is a space in C and POSIX locale.
  For some reasons (unknown to me) g_ascii_isspace() does not treat
  "\v" as space. And neither does NM_ASCII_SPACES and
  nm_str_skip_leading_spaces().
  We should be consistent about what we consider spaces and what not.
  It's already odd to accept '\n' as spaces here, but well, lets do
  it for the sake of consistency (so that it matches with our
  understanding of ASCII spaces, albeit not POSIX's).

- don't use bogus error domains in "g_set_error (error, 1, 0, ..."
  That is a bug and we have NM_UTILS_ERROR exactly for error instances
  with unspecified domain and code.

- as before, accept a trailing ":" with omitted minor number.

- reject all unexpected characters. strtoll() accepts '+' / '-'
  and a "0x" prefix of the numbers (and leading POSIX spaces). Be
  strict here and only accepts NM_ASCII_SPACES, ':', and hexdigits.
  In particular, don't accept the "0x" prefix.

This parsing would be significantly simpler to implement, if we could
just strdup() the string, split the string at the colon delimiter and
use _nm_utils_ascii_str_to_int64() which gets leading/trailing spaces
right. But let's save the "overhead" of an additional alloc.
2019-05-07 20:58:17 +02:00
Thomas Haller
fac95d0062 libnm/tests: add test for _nm_utils_parse_tc_handle() 2019-05-07 20:58:17 +02:00
Thomas Haller
9d2623cceb shared: use nm_str_skip_leading_spaces() in _nm_utils_ascii_str_to_int64() 2019-05-07 20:58:17 +02:00
Lubomir Rintel
143f518ca0 modem/broadband: set the gsm.device-id in complete_connection()
This is the preferred way of associating the connection with a
particualr modem.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/138
2019-05-07 18:19:44 +02:00
Thomas Haller
7a5bf59e5f core: merge branch 'th/cache-state-keyfiles'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/134
2019-05-07 16:42:15 +02:00
Thomas Haller
8a78493de1 settings: cache keyfile databases for "timestamps" and "seen-bssids"
Only read the keyfile databases once and cache them for the remainder of
the program.

- this avoids the overhead of opening the file over and over again.

- it also avoids the data changing without us expecting it. The state
  files are internal and we don't support changing it outside of
  NetworkManager. So in the base case we read the same data over
  and over. In the worst case, we read different data but are not
  interested in handling the changes.

- only write the file when the content changes or before exiting
  (normally).

- better log what is happening.

- our state files tend to grow as we don't garbage collect old entries.
  Keeping this all in memory might be problematic. However, the right
  solution for this is that we come up with some form of garbage
  collection so that the state files are reaonsably small to begin with.
2019-05-07 16:41:21 +02:00
Thomas Haller
b0693863c1 shared: add NMKeyFileDB API
It will be used for "/var/lib/NetworkManager/seen-bssids" and
"/var/lib/NetworkManager/timestamps" which currently is implemented
in NMSettingConnection.
2019-05-07 16:41:21 +02:00
Thomas Haller
8c2fda7ca0 shared: add "shared/nm-glib-aux/nm-keyfile-aux.h" 2019-05-07 16:41:21 +02:00
Thomas Haller
8decdf2225 shared: add nm_log_level_from_syslog() helper to convert from syslog levels 2019-05-07 16:41:21 +02:00
Thomas Haller
4aba7d4696 core: use NM_SETTINGS_GET for singlton instead of nm_settings_get()
We have it, so use it. Also, we use a similar macro for other singletons.
2019-05-07 16:04:49 +02:00
Thomas Haller
4a078d5065 platform: merge branch 'th/ethtool-retry'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/133
2019-05-07 09:44:08 +02:00
Thomas Haller
856322562e platform/ethtool,mii: retry ioctl when interface name was renamed for ehttool/mii
ethtool/mii API is based on the ifname. As an interface can be renamed,
this API is inherently racy. We would prefer to use the ifindex instead.
The ifindex of a device cannot change (altough it can repeat, which opens a
different race *sigh*).

Anyway, we were already trying to minimize the race be resolving the
name from ifindex immediately before the call to ethtool/mii.

Do better than that. Now resolve the name before and after the call. If
the name changed in the meantime, we have an indication that a race
might have happend (but we cannot be sure).

Note that this can not catch every possible kind of rename race. If you are very
unlucky a swapping of names cannot be detected.

For getters this is relatively straight forward. Just retry when we
have an indication to fall victim to a race (up to a few times). Yes, we
still cannot be 100% sure, but this should be very reliable in practice.

For setters (that modify the device) we also retry. We do so under the
assumption that setting the same options multiple times has no bad effect.
Note that for setters the race of swapping interface names is particularly
bad. If we hit a very unlucky race condition, we might set the setting on
the wrong interface and there is nothing we can do about it. The retry only
ensures that eventually we will set it on the right interface.

Note that this involves one more if_indextoname() call for each operation (in
the common case when there is no renaming race). In cases where we make
multiple ioctl calls, we cache and reuse the information though. So, for such
calls the overhead is even smaller.
2019-05-07 09:41:19 +02:00
Thomas Haller
945620624a shared: add nm_malloc_maybe_a(), nm_malloc0_maybe_a() and nm_memdup_maybe_a() utils 2019-05-07 09:38:44 +02:00
Beniamino Galvani
4ed72fa658 device: fix reapply of MTU
When we set the MTU on the link we remember its previous source
(ip-config, parent-device or connection profile) and don't change it
again afterwards to avoid interfering with user's manual changes. The
only exceptions when we change it again are (1) if the parent device
MTU changes and (2) if the new MTU has higher priority than the one
previously set.

To allow a live reapply of the MTU property we also need to clear the
saved source, or the checks described above will prevent setting the
new value.

Fixes: 2f8917237f ('device: rework mtu priority handling')

https://bugzilla.redhat.com/show_bug.cgi?id=1702657
2019-05-06 10:19:19 +02:00
Beniamino Galvani
9ecbca4798 cli: merge branch 'bg/rh1702199'
Don't print blob certificates unless the '--show-secrets' option is
passed to nmcli; plus other related changes.

https://bugzilla.redhat.com/show_bug.cgi?id=1702199
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/122
2019-05-06 10:15:14 +02:00
Beniamino Galvani
c91aad4969 cli: hide certificate blobs unless --show-secrets is passed
This restores the behavior before commit 99711579ed.

Fixes: 99711579ed ('cli: add property type for 802-1x certificate properties (pt2)').
2019-05-06 10:10:00 +02:00
Beniamino Galvani
ec4a12ecdb cli: complete 802.1x certificate file names 2019-05-06 10:10:00 +02:00
Beniamino Galvani
eb724293c2 cli: allow completing filenames
Allow the completion function to indicate that the word should be
completed as a filename by the shell.
2019-05-06 10:10:00 +02:00
Beniamino Galvani
78b9448b69 cli: remove bluetooth completion code
The 'bt-type' property alias accepts values provided by
gen_func_bt_type(); instead the 'bluetooth.type' property can only be
set to [dun, panu, nap] and therefore it doesn't need special
handling.
2019-05-06 10:10:00 +02:00
Beniamino Galvani
eac15501b2 cli: parse escape sequences when reading an 802.1x private key
In this way it become possible to specify a filename that includes one
of the delimiters.
2019-05-06 10:10:00 +02:00
Beniamino Galvani
ee96387578 cli: fix setting private key password
Fixes: fe390556ab ('cli: add property type for 802-1x certificate properties (pt3)')
2019-05-06 10:10:00 +02:00
Beniamino Galvani
48ce3628c5 settings: fix failed assertion
Fix the following assertion failure:

  g_object_ref: assertion 'G_IS_OBJECT (object)' failed.

nm_settings_add_connection() can return a NULL connection.

Fixes: f034f17ff6 ('settings: keep the added connection alive for a bit longer')
2019-05-06 10:09:10 +02:00
Rodrigo Lledó
79d7991eaf po: update Spanish (es) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/135
2019-05-04 08:46:08 +02:00
Lubomir Rintel
0777a26fc1 release: bump version to 1.19.2-dev 2019-05-03 11:04:34 +02:00
Lubomir Rintel
e33a995db1 build: fix an out-of-tree build
make[3]: Entering directory 'NetworkManager/_build/sub'
    CC       clients/cli/nmcli-common.o
  cc1: error: ./clients/common: No such file or directory [-Werror=missing-include-dirs]
  cc1: all warnings being treated as errors

The only generated header in $builddir/clients/common is settings-docs.h
and only libnmc.la needs it. Include the directory on the command line
only when we know it exists.
2019-05-03 11:04:34 +02:00
Lubomir Rintel
54663b89dc NEWS: update 2019-05-03 11:04:34 +02:00
Thomas Haller
56d748eb84 device/wireguard: fix memleak for NMDeviceWireGuard
Fixes: 2148d09482 ('core/wireguard: add support for WireGuard peers')
2019-05-03 11:03:08 +02:00
Thomas Haller
d5a2b70909 platform/tests: workaround routing-rules test failure due to suppress_prefixlen on older kernels
On Ubuntu 14.04 kernel (4.4.0-146-generic, x86_64) this easily causes
test failures:

    make -j 8 src/platform/tests/test-route-linux \
    && while true; do \
        NMTST_SEED_RANDOM= ./tools/run-nm-test.sh src/platform/tests/test-route-linux -p /route/rule \
        || break; \
    done

outputs:

    ...
    /route/rule/1:
    nmtst: initialize nmtst_get_rand() with NMTST_SEED_RAND=22892021
    OK
    /route/rule/2: >>> failing...
    >>> no fuzzy match between: [routing-rule,0x205ab30,1,+alive,+visible; [6] 0: from all suppress_prefixlen 8 none]
    >>>                    and: [routing-rule,0x205c0c0,1,+alive,+visible; [6] 0: from all suppress_prefixlen -1579099242 none]
    **
    test:ERROR:src/platform/tests/test-route.c:1695:test_rule: code should not be reached
2019-05-02 09:28:31 +02:00
Rodrigo Lledó
0a0a8706f8 po: update Spanish (es) translation
Changing "Token" translation from "identificador" to "testigo" as discussed
in the GNOME Spanish Translation Team's mailing list.

Special thanks to Daniel Mustieles our coordinator.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/130
2019-05-01 13:59:19 +02:00
Yuri Chornoivan
4e1b1232d9 po: update Ukrainian (uk) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/128
2019-05-01 13:56:30 +02:00
Thomas Haller
da3750d758 libnm: merge branch 'th/libnm-setting-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/126
2019-05-01 13:46:50 +02:00
Thomas Haller
0d1b8ee92a libnm: unify property-to-dbus handling of NMSetting
Merge the function pointer get_func() into to_dbus_fcn().

Previously, get_func() as handled separately from to_dbus_fnc()
(formerly synth_func()). The notion was that synth-func would syntetize
properties that are D-Bus only. But that distinction does not seem
very helpful to me.

Instaed, we want to convert a property to D-Bus. Period. The
implementation should be handled uniformly. Hence, now that is
all done by property_to_dbus().

Note that property_to_dbus() is also called as default implementation
for compare-property. At least, for properties that are backed by a
GObject property.
2019-05-01 13:46:32 +02:00
Thomas Haller
bb7829cb37 libnm: rename function pointers of NMSettInfoProperty
The naming was not very clear. How does get_func(), synth_func()
and to_dbus() relate? What does synth_func() do anyway?

Answers:

- get_func() and synth_func() do very similar. They should be merged
  in a next step.
  synth_func() has the notion of "synthetize" a property for
  D-Bus. As such, these properties are a bit unusual in that they
  don't have a backing GObject property in the setting. But it'd
  rather treat such properties like other properties. The step
  in that direction will be to merge the to-dbus functions.

- to_dbus() converts a GValue of the GObject property go GVariant.
  It's a simplified form of get_func()/synth_func() and a better name
  is gprop_to_dbus_fcn().
  The same for gprop_from_dbus_fcn().

For now, just rename.
2019-05-01 13:46:32 +02:00
Thomas Haller
b1344b6b94 libnm: pass connection to compare_property() function
We have certain artificial properties that not only depend on one
property alone or that depend on a property in another(!) setting.

For that, we have synth_func.

Other than that, synth_func and get_func are really fundamentally
similar and should be merged. That is because the distinction whether a
property value is "synthetized" or just based on a plain property is
minor. It's better to have the general concept of "convert property to
GVariant" in one form only.

Note that compare_property() is by default implemented based
on get_func. Hence, if get_func and synth_func get merged,
compare_property() will also require access to the NMConnection.

Also it makes some sense: some properties are artificial and actually
stored in "another" setting of the connection. But still, the property
descriptor for the property is in this setting. The example is the
"bond.interface-name" which only exists on D-Bus. It's stored as
"connection.interface-name".
I don't really like to say "exists on D-Bus only". It's still a valid
property, despite in NMSetting it's stored somehow differently (or not
at all). So, this is also just a regular property for which we have a
property-info vtable.
Does it make sense to compare such properties? Maybe. But the point is that
compare_property() function needs sometimes access to the entire
connection. So add the argument.
2019-05-01 13:46:32 +02:00
Thomas Haller
3c810a8445 libnm: cleanup converting properties to GVariant
Always properly set NMSettInfoProperty.dbus_type, instead of leaving it
unspecified for GObject property based properties, and detect it each
time anew with variant_type_for_gtype().

Instead, autodetect and remember the dbus-type during _properties_override_add_struct().
For types that need special handling (GBytes, enums and flags) set a to_dbus() function.
This allows us to handle properties uniformly by either calling the to_dbus() function
or g_dbus_gvalue_to_gvariant().
2019-05-01 13:46:32 +02:00
Thomas Haller
7726f5b4a5 libnm: cleanup get_property_for_dbus()
- use cleanup attribute in get_property_for_dbus() and return early.

- use NM_FLAGS_HAS() macro in _nm_setting_to_dbus().

- in nm_setting_get_dbus_property_type() use g_return*() asserts
  instead of crash or hard asserts.

- return early from variant_type_for_gtype().
2019-05-01 13:46:32 +02:00
Thomas Haller
4853be52af shared: add nm_g_variant_take_ref() util 2019-05-01 13:46:32 +02:00
Lubomir Rintel
19bf820de3 merge: branch 'lr/tc-attrs'
https://github.com/NetworkManager/NetworkManager/pull/338
2019-04-30 16:09:06 +02:00
Lubomir Rintel
900292147d tc/tfilter: add mirred action 2019-04-30 15:59:41 +02:00
Lubomir Rintel
1efe982e39 tc/qdisc: add support for fq_codel attributes 2019-04-30 15:59:41 +02:00
Lubomir Rintel
7574b722a6 merge: branch 'lr/dispatcher-split'
https://github.com/NetworkManager/NetworkManager/pull/253
2019-04-30 15:53:59 +02:00
Lubomir Rintel
14eaf6a40b contrib/rpm: provide NetworkManager-dispatcher
This is a provide packages that install dispatcher scripts should depend
on. It will make it easier to keep track of them and possibly split out
the dispatcher into an optional package if not needed.
2019-04-29 16:57:07 +02:00
Lubomir Rintel
c4f1fac35d contrib/rpm: (trivial) move some %files around, remove a duplicate
Just a cosmetic thing.
2019-04-29 16:57:07 +02:00
Lubomir Rintel
35a428f168 dispatcher: look for the scripts in /usr/lib as well
This makes it possible for packages that ship dispatcher scripts to use
the correct location.
2019-04-29 16:57:07 +02:00
Lubomir Rintel
3fc41cd6d5 src/dispatcher: do not monitor dispatcher scripts
The monitors have been in place since the dispatcher has been introduced.
They need the daemon to do extra work know where the files are supposed to
be. It seems to me the complexity is not worth it.

Let's remove them now, making it easier to modify the dispatcher to look
for scripts in other places.
2019-04-26 22:07:30 +02:00
Lubomir Rintel
a95b674c39 build: install dispatcher dirs in /usr
The dispatcher looks there for scripts now. This actually doesn't break
the RPM build, since it doesn't mind extra empty directories in
buildroot. Good.
2019-04-26 22:07:30 +02:00
Thomas Haller
5aff6fc83b cli,libnm: merge branch 'th/cli-team-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/121
2019-04-25 09:32:20 +02:00
Thomas Haller
df769c8dfd ifcfg-rh: support serializaing all possible values for ethernet.s390-options (OPTIONS)
While the keys of s390-options are from a well-behaving set of names
(that is enforced by nm_connection_verify()), the values are arbitrary
strings.

Our settings plugin must be able to express all values of a connection,
hence we need to support escapes.
2019-04-25 09:26:35 +02:00
Thomas Haller
0a8f11639a libnm: refactor implementation of "ethernet.s390-options" property
- the previous implementation of nm_setting_wired_get_s390_option()
  returned the elements in an arbitrary order (because it just iterated
  idx times over the unsorted hash table).

- the API for "s390-options" suggests both accessing by index and by
  name. Storing the options in a hash-table is not optimal for lookup
  by index. It also requires us to sort the elements over and over
  again.
  Use instead a sorted array. Note that add/remove of course requires to
  move the elements (and has thus O(n)).

- "s390-options" are very seldomly set. We shouldn't pay the price in every
  NMSettingWired to allocate a GHashTable and deal with it.

- don't assert in nm_setting_wired_add_s390_option() and
  nm_setting_wired_remove_s390_option() that the key is valid.
  ifcfg-rh reader understandably does not want to implement additional
  logic to pre-validate the key, so any invalid keys would trigger an
  assertion failure. We have verify() for this purpose.
2019-04-25 09:22:51 +02:00