Commit graph

22000 commits

Author SHA1 Message Date
Thomas Haller
69ce5def41 libnm: minor cleanup releasing setting from NMConnection
There are two callers that are concerned with disconnecting/releasing a
setting:

 - _setting_release_hfr() (formerly _setting_release())

 - _nm_connection_add_setting() for the @s_old setting

Compared to one caller that connects/adds a setting (_nm_connection_add_setting()).

Refactor the two callers to use the same helper function
(_setting_release()) so that the implementation of how to release a
setting is at one place.

This patch was originally done when adding another signal to NMSetting.
That did not happen (yet), but the refactoring still makes sense.
2019-01-22 16:30:23 +01:00
Thomas Haller
021564c069 libnm: fix unregistering signal handler of NMConnection from NMSetting
Seems we didn't actually unregister the signal handlers. Ups.

Fixes: dfba4ce1e1
2019-01-22 16:30:23 +01:00
Thomas Haller
08a0f682e1 libnm: always call clear_secrets() function for all properties
And merge it with the version that uses no flags.

Previously, clear_secrets(_with_flags()) was only implemented
by NMSettingVpn. All other settings would only consider GObject-based
properties.

As we will add secrets that have no GObject property, call the virtual
function always, so that the setting can hook into this (for WireGuard
peers).
2019-01-22 16:30:23 +01:00
Thomas Haller
2210d4514e libnm: merge _nm_setting_clear_secrets() and *_with_flags() 2019-01-22 16:30:23 +01:00
Thomas Haller
d2388250d6 libnm: fix secret-name parameter in NMSettingClearSecretsWithFlagsFn for VPN
The secret name should be the one that we can pass to nm_setting_get_secret_flags().
It's wrong to call the function repeatedly with secret-name "secrets".

Probably nobody cared anyway about the name. nm_connection_clear_secrets_with_func()
is used to clear secrets based on the flags, not the secret-name.

Fixes: 2b2404bbef
2019-01-22 16:30:23 +01:00
Thomas Haller
3a915a0205 libnm: support nm_setting_duplicate() for non-GObject base properties
Add a hook so that we can overwrite the property info.

Yes, this is an API/ABI change for NMSettingClass, which is in a
header file. But this is not API that we want to support. Users must
not use this. Alternatively, I could hook the callback into
NMSettInfoSetting, but either works.
2019-01-22 16:30:23 +01:00
Thomas Haller
f5a86dee43 libnm/trivial: rename local variable 2019-01-22 16:30:23 +01:00
Thomas Haller
6f8c7b580d platform: add @replace_peers argument to nm_platform_link_wireguard_change()
The caller may not wish to replace existing peers, but only update/add
the peers explicitly passed to nm_platform_link_wireguard_change().

I think that is in particular interesting, because for the most part
NetworkManager will configure the same set of peers over and over again
(whenever we resolve the DNS name of an IP endpoint of the WireGuard
peer).

At that point, it seems disruptive to drop all peers and re-add them
again. Setting @replace_peers to %FALSE allows to only update/add.
2019-01-22 16:30:23 +01:00
Thomas Haller
78ce4307c0 platform: add and use nm_sock_addr_union_to_string()
We still don't use getnameinfo(). This is used for logging,
where we want to see a string representation that is as close
as possible to the actual bytes (to spot differences). It should
not be obfuscated by a libc function out of our control.

Also fix the notation for the IPv6 scope ID to use the common '%'
character.
2019-01-22 16:30:23 +01:00
Thomas Haller
32749cea99 platform: support missing endpoint in _wireguard_create_change_nlmsgs() 2019-01-22 16:30:23 +01:00
Thomas Haller
977b033d12 platform: improve API of sockaddr handling
Add cmp/hash functions that correctly honor the well known fields, instead
of doing memcmp/memcpy of the entire sockaddr structure.

Also, move the set function to nm_sock_addr_union_cpy() and
nm_sock_addr_union_cpy_untrusted(). This also gets it right
to ensure all bytes of the union are initialized (to zero).
2019-01-22 16:30:23 +01:00
Thomas Haller
744e11dc0d shared: add "struct in_addr" union member to NMIPAddr struct
NMIPAddr is a union of IPv4 and IPv6 addresses.

A lot of our internal API handles IPv4 as in_addr_t / guint32 / be32_t
types, as such the union field "addr4" is just a plain number. Possibly
the internal API should be all refactored to prefer "struct in_addr"
instead, but that is yet to be done.

Anyway, at a few places we will need also access to the IPv4 address in form of
a `struct in_addr`. Add an alias for that.

I am not too happy about the resulting naming. It would be nicer to have

    struct in_addr  addr4;
    struct in6_addr addr6;
    in_addr_t       s_addr4;

but for now, don't do such renaming.
2019-01-22 16:30:23 +01:00
Thomas Haller
035c4ad45d shared: suppress -Wstringop-truncation warning in nm_strndup_a()
The compiler is too smart for nm_strndup_a(). The code is correct,
suppress "-Wstringop-truncation" warning.
2019-01-22 16:30:23 +01:00
Lubomir Rintel
d7d2dafc1b libnm/manager: free the error correctly
Fixes: fbb038af5e
2019-01-21 17:21:35 +01:00
Lubomir Rintel
2ff54b8532 libnm-core/setting-ip-config: drop an unused variable
Upsets clang:

libnm-core/nm-setting-ip-config.c:2688:43: error: unused variable 'setting_class' [-Werror,-Wunused-variable]
        nm_auto_unref_gtypeclass NMSettingClass *setting_class = g_type_class_ref (NM_TYPE_SETTING_IP_CONFIG);

Fixes: a3d6976efc
2019-01-21 14:29:02 +01:00
Thomas Haller
c4eadb709c initrd/trivial: fix whitespace 2019-01-21 14:18:54 +01:00
Lubomir Rintel
125b9a5a5d initrd: make the default connection activatable on multiple devices
The ip=dhcp (without a device name given) and such should activate all
possible devices.

https://github.com/NetworkManager/NetworkManager/pull/284
2019-01-21 13:00:04 +01:00
Beniamino Galvani
58c4cd9cc9 supplicant: don't set PMF when the supplicant doesn't support it
When the supplicant does not support PMF we wrongly set
'ieee80211w=0', but since the option is not recognized the connection
fails. Don't set it when unsupported.

Fixes: a9ab50efb1
2019-01-17 09:40:29 +01:00
Thomas Haller
e7e0100062 shared: fix generic selection of integers in nm_strdup_int()
This fixes a test error, which aims to convert "unsigned long int" type,
but the generic type may not have been covered.

Don't select based on the gint32-like typedefs, but on the basic C
integer types.

Fixes: 8c2d58b237

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/108
2019-01-16 15:45:43 +01:00
Thomas Haller
3409a9750c libnm: merge branch 'th/libnm-settings-properties'
https://github.com/NetworkManager/NetworkManager/pull/279
2019-01-15 10:55:09 +01:00
Thomas Haller
19141ef770 libnm-core: reorder code in settings
Order the code in our common way. No other changes.

- ensure to include the main header first (directly after
  "nm-default.h").

- reorder function definitions: get_property(), set_property(),
  *_init(), *_new(), finalize(), *_class_init().
2019-01-15 09:55:24 +01:00
Thomas Haller
a3d6976efc libnm-core: cleanup NMSetting's class initialization
Unify the coding style for class-init functions in libnm-core.

Also make use of obj_properties, NM_GOBJECT_PROPERTIES_DEFINE(), and
_notify().
2019-01-15 09:55:24 +01:00
Thomas Haller
450a471dfe libnm: fix notifying "mac-address-randomization" property change
Fixes: 7f63c875f9
2019-01-15 09:55:23 +01:00
Thomas Haller
19aaa18fac all: merge branch 'th/alloca-cleanup'
https://github.com/NetworkManager/NetworkManager/pull/278
2019-01-15 09:53:40 +01:00
Thomas Haller
8c2d58b237 shared/tests: add test for nm_strdup_int() macro 2019-01-15 09:52:01 +01:00
Thomas Haller
3263cab596 all: add static assertion for maximumg alloca() allocated buffer
Add a compile time check that the buffer that we allocate on the stack
is reasonably small.
2019-01-15 09:52:01 +01:00
Thomas Haller
617bdbd8c2 all/trivial: rename NM_UTILS_LOOKUP_STR() to have "_A" suffix
NM_UTILS_LOOKUP_STR() uses alloca(). Partly to avoid the overhead of
malloc(), but more important because it's convenient to use. It does
not require to declare a varible to manage the lifetime of the heap
allocation.

It's quite safe, because the stack allocation is of a fixed size of only
a few bytes. Overall, I think the convenience that we get (resulting in
simpler code) outweighs the danger of stack allocation in this case. It's
still worth it.
However, as it uses alloca(), it still must not be used inside a (unbound)
loop and it is obviously a macro.

Rename the macros to have a _A() suffix. This should make the
peculiarities more apparent.
2019-01-15 09:52:01 +01:00
Thomas Haller
e18ff51d4f tests: don't use alloca() in tests
The only purpose of using alloca() to avoid the overhead of heap-allocation
and possible save a line in source code for managing/freeing the heap allocation.

For tests we don't care about performance, and (in this case)
the code does not get any shorter.

Avoid alloca() in tests, because alloca() is something to search for
when reviewing code for stack overflows. No need to have such false
positives show up in tests.
2019-01-15 09:52:01 +01:00
Thomas Haller
694533f529 shared: add nm_utils_strbuf_append_bin() helper
Add a version of nm_utils_strbuf_append_*() that does not care
about NUL terminate strings, but accept any binary data. That makes
it useful for writing a binary buffer.
2019-01-14 16:40:39 +01:00
Thomas Haller
cf30c9f07f libnm: merge branch 'th/add-and-activate2-api'
https://github.com/NetworkManager/NetworkManager/pull/275
2019-01-14 11:57:37 +01:00
Thomas Haller
fbb038af5e all: return output dictionary from "AddAndActivate2"
Add a "a{sv}" output argument to "AddAndActivate2" D-Bus API.
"AddAndActivate2" replaces "AddAndActivate" with more options.
It also has a dictionary argument to be forward compatible so that we
hopefully won't need an "AddAndActivate3". However, it lacked a similar
output dictionary. Add it for future extensibility. I think this is
really to workaround a shortcoming of D-Bus, which does provide strong
typing and type information about its API, but does not allow to extend
an existing API in a backward compatible manner. So we either resort to
Method(), Method2(), Method3() variants, or a catch-all variant with a
generic "a{sv}" input/output argument.

In libnm, rename "nm_client_add_and_activate_connection_options()" to
"nm_client_add_and_activate_connection2()". I think libnm API should have
an obvious correspondence with D-Bus API. Or stated differently, if
"AddAndActivateOptions" would be a better name, then the D-Bus API should
be renamed. We should prefer one name over the other, but regardless
of which is preferred, the naming for D-Bus and libnm API should
correspond.

In this case, I do think that AddAndActivate2() is a better name than
AddAndActivateOptions(). Hence I rename the libnm API.

Also, unless necessary, let libnm still call "AddAndActivate" instead of
"AddAndActivate2". Our backward compatibility works the way that libnm
requires a server version at least as new as itself. As such, libnm
theoretically could assume that server version is new enough to support
"AddAndActivate2" and could always use the more powerful variant.
However, we don't need to break compatibility intentionally and for
little gain. Here, it's easy to let libnm also handle old server API, by
continuing to use "AddAndActivate" for nm_client_add_and_activate_connection().
Note that during package update, we don't restart the currently running
NetworkManager instance. In such a scenario, it can easily happen that
nmcli/libnm is newer than the server version. Let's try a bit harder
to not break that.

Changes as discussed in [1].

[1] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/37#note_79876
2019-01-14 11:56:18 +01:00
Thomas Haller
3ae5c9d595 core: cleanup error path in activation_add_done()
Don't return success from a nested code path. Handle all errors
first, and return early. Well, we cannot really return right away
because we need to handle the failure. So, at least, check for errors
and "goto fail".
2019-01-14 11:55:17 +01:00
Thomas Haller
2a6e7e917f shared: add nm_g_variant_ref() and nm_g_variant_unref() helpers
Akin to nm_g_object_ref() and nm_g_object_unref().
2019-01-14 11:55:17 +01:00
Beniamino Galvani
240e2bd9f8 dns: merge branch 'bg/dns-child-restart-issue105'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/105
2019-01-14 10:35:16 +01:00
Beniamino Galvani
e45636659b dns: fail the plugin when the rate limiter hits
If the child is respawning too fast, consider the plugin failed so
that upstream servers are written to resolv.conf until the plugin gets
restarted after the delay.
2019-01-14 10:02:48 +01:00
Beniamino Galvani
f2a2012733 dns: fix updating resolv.conf after dnsmasq process dies
When the dnsmasq process dies, two events are generated:

(1) a NM_DNS_PLUGIN_FAILED signal in nm-dns-dnsmasq.c:name_owner_changed()
(2) a NM_DNS_PLUGIN_CHILD_QUIT signal in nm-dns-plugin.c:from watch_cb()

Event (1) is handled by updating resolv.conf with upstream servers,
(2) by restarting the child process.

The order in which the two signals are received is not deterministic,
so when (1) comes after (2) the manager leaves upstream servers in
resolv.conf even if a dnsmasq instance is running.

When dnsmasq disappears from D-Bus and we know that the process is not
running, we should not emit a FAILED signal because the disappearing
is caused by the process termination, and that event is already
handled by the manager.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/105
2019-01-14 10:02:48 +01:00
Beniamino Galvani
9b0c1ef5d0 clients: merge branch 'bg/cli-dns-options-rh1665649'
https://bugzilla.redhat.com/show_bug.cgi?id=1665649
2019-01-12 22:57:56 +01:00
Beniamino Galvani
b11a20ded0 clients: remove the same dns-option before adding it
nmcli connection modify t ipv4.dns-options ndots:2
 nmcli connection modify t +ipv4.dns-options ndots:4

should set dns-options to 'ndots:4', so we must remove other
occurences of the same option before adding it, otherwise the setting
refuses to set the same option again.
2019-01-12 22:57:37 +01:00
Beniamino Galvani
bcb91f4f65 clients: fix appending to dns-property variable
Appending to the ipvx.dns-options property:

  nmcli connection modify con +ipv4.dns-options rotate

currently is buggy because it resets the list to contain only
'rotate'. The setter function should not clear the list.

https://bugzilla.redhat.com/show_bug.cgi?id=1665649
2019-01-12 22:57:37 +01:00
Beniamino Galvani
1f32e417a8 clients: unify IPv4 and IPv6 accessors for dns-search, dns-options 2019-01-12 22:57:37 +01:00
Beniamino Galvani
a9ab50efb1 supplicant: set optional PMF using global supplicant property
wpa_supplicant is going to change the global default for PMF from 0
(disabled) to 1 (optional) [1], so NM code needs to be adjusted to
work with all wpa_supplicant versions. Furthermore, it is better to
set optional PMF using the 'Pmf' property instead of the 'ieee80211w'
configuration option because the former better handles missing support
in driver [2].

Note that each interface in wpa_supplicant has its own copy of global
configuration and so 'global' options must still be set on each
interface. So, let's set Pmf=1 when each interface gets created and
override it with ieee80211w={0,2} if needed during association.

[1] http://lists.infradead.org/pipermail/hostap/2018-November/039009.html
[2] http://lists.infradead.org/pipermail/hostap/2019-January/039215.html

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/104
2019-01-12 22:46:48 +01:00
Thomas Haller
4d2b324b52 libnm: merge branch 'th/libnm-setting-compare'
https://github.com/NetworkManager/NetworkManager/pull/277
2019-01-11 11:51:00 +01:00
Thomas Haller
3846976eb6 libnm,core: accept failure to _nm_setting_get_property() in _log_connection_get_property()
_log_connection_get_property() is a hack, as it cannot meaningfully print complex
properties. Also, it uses _nm_setting_get_property() which can only work with GObject
base properties.

Don't assert against _nm_setting_get_property() returning success. Eventually
we should replace _nm_setting_get_property() by something better. But for the moment,
it's fine to being unable to print a property value.
2019-01-11 11:50:25 +01:00
Thomas Haller
d2f0e16ccd libnm: add _nm_sett_info_setting_get_property_info() helper 2019-01-11 11:50:25 +01:00
Thomas Haller
2e7aba2b46 libnm/trivial: rename sett-info getters 2019-01-11 11:50:25 +01:00
Thomas Haller
d61cfc1774 libnm: assert in _nm_setting_aggregate() that we handle secret-flags
Curreently all aggregate types only care about secrets.

The check for secets is done by checking for NM_SETTING_PARAM_SECRET
flag. Assert that this check is suitable to identify a secret.
2019-01-11 11:50:15 +01:00
Thomas Haller
885c872d5a libnm: rework compare_property() implementation for NMSetting
NMSetting's compare_property() has and had two callers:
nm_setting_compare() and nm_setting_diff().

compare_property() accepts a NMSettingCompareFlags argument, but
at the same time, both callers have another complex (and
inconsistent!) set of pre-checks for shortcuting the call of
compare_property(): should_compare_prop().

Merge should_compare_prop() into compare_property(). This way,
nm_setting_compare() and nm_setting_diff() has less additional
code, and are simpler to follow. Especially nm_setting_compare()
is now trivial. And nm_setting_diff() is still complicated, but
not related to the question how the property compares or whether
it should be compared at all.

If you want to know whether it should be compared, all you need to do
now is follow NMSettingClass.compare_property().

This changes function pointer NMSettingClass.compare_property(),
which is public API. However, no user can actually use this (and shall
not!), because _nm_setting_class_commit_full() etc. is private API. A
user outside of libnm-core cannot create his/her own subclasses of
NMSetting, and never could in the past. So, this API/ABI change doesn't
matter.
2019-01-11 11:48:47 +01:00
Thomas Haller
5aace3dfea libnm: unify handling whether to compare properties in NMSetting
nm_setting_compare() and nm_setting_diff() both call the virtual
function compare_property(). But their check for determining whether
to call the virtual function differs.

In a first step, merge the implementations so that the check is clearly
similar in both cases.
2019-01-11 11:48:47 +01:00
Thomas Haller
290dbf1170 libnm/tests: add tests for comparing settings with different secret-flags
The flags NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS and
NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS act on the secret flags
to decide whether to ignore a secret.

But there was not test how this behaved, if the two settings had
differing flags.
2019-01-11 11:48:47 +01:00
Thomas Haller
a75372cc59 libnm: mark wifi.cloned-mac-address GObject property inferrable
ethernet.cloned-mac-address is also marked as inferrable. I think the concept
of NM_SETTING_PARAM_INFERRABLE is fundamentally wrong just like the entire
assume approach. Anyway, if ethernet's property is inferrable, so should
be Wi-Fi's.
2019-01-11 11:48:06 +01:00