Commit graph

21971 commits

Author SHA1 Message Date
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
Thomas Haller
20a738c92f libnm: fix NM_SETTING_DIFF_RESULT_IN_B_DEFAULT flag for nm_setting_diff()
This is public API, but if it was used, it was very wrong.
Cannot help but fix it.

Fixes: 68bc95c12f
2019-01-10 13:43:51 +01:00
Thomas Haller
157644f200 libnm: fix nm_setting_diff() for ignore-reapply-immediately comparison
This bug had no effect, because NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY
has only one user, and it's used there in combination with
nm_setting_compare(). No caller passed this flag to nm_setting_diff().

Fixes: c9b3617c35
2019-01-10 13:43:51 +01:00
Thomas Haller
b44a9ef7f7 libnm: fix nm_setting_compare() for fuzzy comparison
Fixes: b1ebbf4c80
2019-01-10 13:43:51 +01:00
Francesco Giudici
46726ecdde merge: branch 'fg/assume_bridge-rh1593939'
Improve assuming bridges on startup.

https://bugzilla.redhat.com/show_bug.cgi?id=1593939

https://github.com/NetworkManager/NetworkManager/pull/266
2019-01-10 09:52:21 +01:00
Francesco Giudici
abc40618f1 device: when assuming a bridge ignore stp options if stp is disabled
When STP is disabled, the bridge parameters 'priority', 'forward-delay',
'hello-time' and 'max-age' are irrelevant.
We already skip them when loading a connection profile from a ifcfg file.
Do the same when generating a connection from a configured device, in
order to possibly assume the connection.
2019-01-10 09:52:02 +01:00
Francesco Giudici
ede6b65abf device: use bool instead of gboolean in the bridge options struct
just to save some bytes of memory (gboolean --> typef gint)
2019-01-10 09:52:02 +01:00
Francesco Giudici
30d9744534 device: always enforce bridge properties limits
...also when the connection is created at NetworkManager
startup to map an already configured bridge.
Ensure the device has configuration values that fall inside
NetworkManager boundaries, otherwise map the value with a default.
2019-01-10 09:52:02 +01:00
Francesco Giudici
0f6fe2a38a core: move bridge port min/max/default values to core-internal
We have bridge min/max/default values in core-internal. Do the same
for bridge port ones.
We will soon use those values to enforce limits when assuming a
bridge port configuration.
2019-01-10 09:52:02 +01:00
Francesco Giudici
cad905fce2 core: remove NM_SETTING_PARAM_INFERRABLE flag from bridge-port.path-cost
In NetworkManager we have a default port path-cost equal to 100.
In the linux kernel the default port cost depends upon the interface
speed: 2 for 10Gb, 4 for 1Gb, 19 for 100Mb and 100 for 10Mb (or when the
interface speed is not available, like current virtio_net driver).
Allow NetworkManager to assume bridge port connections also when the
path-cost differs: this will allow us to assume bridge ports created
outside NetworkManager (e.g. in initrd) that will likely have a different
"cost" value.
2019-01-10 09:52:02 +01:00
Thomas Haller
eae86a4823 platform: merge branch 'th/wireguard-pt2'
Add platform code to configure WireGuard links.

https://github.com/NetworkManager/NetworkManager/pull/274
2019-01-09 16:48:32 +01:00
Thomas Haller
a5c894c35f platform: create wireguard netdev interface
The netlink code for WG_CMD_SET_DEVICE is strongly inspired by
WireGuard ([1]) and systemd ([2]).

Currently, nm_platform_link_wireguard_change() always aims to reset
all peers and allowed-ips settings. I think that should be improved
in the future, to support only partial updates.

[1] https://git.zx2c4.com/WireGuard/tree/contrib/examples/embeddable-wg-library/wireguard.c?id=5e99a6d43fe2351adf36c786f5ea2086a8fe7ab8#n1073
[2] 04ca4d191b/src/network/netdev/wireguard.c (L48)
2019-01-09 16:46:41 +01:00
Thomas Haller
7b935c8940 device: use NM_IN_STRSET() in nm_connection_is_virtual() 2019-01-09 16:46:41 +01:00
Thomas Haller
fb79c79d87 netlink: add nla_put() helpers to set integers 2019-01-09 16:46:41 +01:00
Thomas Haller
7a105c2191 netlink: don't require a callback argument in nl_recvmsgs() 2019-01-09 16:46:41 +01:00
Thomas Haller
0713a6996c platform: track wireguard endpoint as sockaddr struct
We need to track the IPv6 endpoint as struct sockaddr_in6, so that
we have access to the scope-id.
2019-01-09 16:46:41 +01:00
Thomas Haller
2e48f6419f netlink: don't heap allocate struct ucred during nla_recv()
Instead, fill a preallocated output buffer provided by the caller.
2019-01-09 16:46:41 +01:00
Thomas Haller
e5fb1dd6e7 netlink: track ucred via a boolean field in struct nl_msg
Also, accept NULL in nlmsg_set_creds() to clear the set credentials.
2019-01-09 16:46:41 +01:00
Thomas Haller
fce3243f12 shared/trivial: rename nm_utils_mem_all_zero() to nm_utils_memeqzero()
in systemd/systemd, systemd/casync, and rustyrussel/ccan (github) this
function is called "memeqzero()". Rename, to use a more popular name.
2019-01-09 16:46:41 +01:00
Thomas Haller
af67b4520f shared: refactor nm_utils_mem_all_zero() to use memcmp() 2019-01-09 16:46:41 +01:00
Thomas Haller
aab3e14883 shared: add nm_utils_getpagesize() and use it in netlink code
Since we already cached the result of getpagesize() in a static variable (at
two places), move the code to nm-shared-utils, so it is reusable.

Also, use sysconf() instead of getpagesize(), like suggested by `man
getpagesize`.
2019-01-09 16:46:41 +01:00
Thomas Haller
6ae04654f7 shared: avoid compiler warning in nm_strndup_a()
Using strncpy() in the macro directly can result in a compiler warning.
We don't want to replace this with memcpy(), because strncpy() aborts
on the first NUL and fills the rest with NUL. Since nm_strndup_a() is a
replacement for g_strndup(), we want to do that here as well.

    In file included from ../shared/nm-default.h:294,
                     from ../libnm-core/nm-utils.c:22:
    ../libnm-core/nm-utils.c: In function nm_sock_addr_endpoint_new:
    ../shared/nm-utils/nm-shared-utils.h:281:4: error: strncpy output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
        strncpy (_s, _str, _len); \
        ^~~~~~~~~~~~~~~~~~~~~~~~
    ../libnm-core/nm-utils.c:154:26: note: in expansion of macro nm_strndup_a
      host = _parse_endpoint (nm_strndup_a (200, endpoint, l_endpoint - 1, &host_clone),
                              ^~~~~~~~~~~~
    ../libnm-core/nm-utils.c:152:15: note: length computed here
      l_endpoint = strlen (endpoint) + 1;
                   ^~~~~~~~~~~~~~~~~
2019-01-09 16:46:41 +01:00
Thomas Haller
1cd167c774 platform: fix hash/cmp for NMPObjectLnkWireGuard
It's totally bogus.

Luckily, NMPlatformLnkVlan is smaller than NMPlatformLnkWireGuard, hence there
was no crash, just wrong results.

Fixes: 0827d4c2e4
2019-01-09 16:46:41 +01:00
Lubomir Rintel
c8560bcc4a po: translations from the Red Hat translators 2019-01-08 19:06:56 +01:00
Lubomir Rintel
a8c58baffc po: update-po for the translations that are going to be updated
Just so that we get a nicer diff when pulling from the Red Hat Zanata.
2019-01-08 19:06:56 +01:00
Thomas Haller
4d1b8edb73 libnm/tests: compare D-Bus and keyfile serialization in roundtrip-conversion test 2019-01-08 16:16:18 +01:00
Thomas Haller
e844984a34 dhcp: merge branch 'th/dhcp-client-id-infiniband-rh1658057'
- fix DHCP client-id generatation on infiniband devices
- change default ipv4.dhcp-client-id of internal DHCP plugin to "mac"

https://bugzilla.redhat.com/show_bug.cgi?id=1658057
https://bugzilla.redhat.com/show_bug.cgi?id=1661165

https://github.com/NetworkManager/NetworkManager/pull/263
2019-01-08 07:29:59 +01:00
Thomas Haller
1ffa40872f contrib/rpm: remove unused 00-server-dhcp-client-id.conf configuration snippet
Now that the default for the internal client is "mac", we don't need
this snippet anymore. Drop it.

Don't renumber the source files but leave the gap at Source3. Everytime
we add config snippets the numbers need to be shuffled, so don't fill
the gap and maybe use it in the future.

https://bugzilla.redhat.com/show_bug.cgi?id=1661165
2019-01-07 17:13:23 +01:00
Thomas Haller
cfd696cc3c dhcp: default ipv4.dhcp-client-id of internal plugin to "mac"
The "ipv4.dhcp-client-id" is configurable per-profile and the default
value can be overwritten via connection defaults in NetworkManager.conf.

For "dhclient" DHCP plugin, the ultimate default for "ipv4.dhcp-client-id"
is determined by dhclient itself, or possibly by user configuration from
"/etc/dhcp".

For the "internal" DHCP plugin, the default must be decided by
NetworkManager. Also, the default here is important, as we preferably
won't change it anymore. That is because a changing the client-id
will result in different IP addresses after upgrade of NetworkManager
version. That should be avoided.

Still, change it now. If a downstream does not want this, it either needs
to patch the sources or add a configuration snippet like:

    [connection-internal-dhcp-client-id-duid]
    match-device=dhcp-plugin:internal
    ipv4.dhcp-client-id=duid

The reason to change from the previous default "duid" to "mac" are the
following:

- "duid" is an RFC 4361 compatible client-id ([1]) and "mac" is defined
in RFC 2132.

- "duid" cannot (easily) be predicated a-priori as it is a hash of the
interface-name and "/etc/machine-id". In particular in cloud and server
environments, admins often prefer "mac" as they do know the MAC address
and pre-configure the DHCP server accordingly.

- with "dhclient" plugin, the default is decided by dhclient package or
user configuration in "/etc/dhcp". However, in fact the default is often
"client-identifier hardware" (for example on RHEL/CentOS).

- for RHEL/CentOS we require a way to select "mac" as default. That was
done by installing a configuration snippet via the NetworkManager-config-server
package. It's confusing to have the default depend on a package. Avoid
that. Also, users required "mac" in certain scenarios, but no users
explicitly asked for "duid" as default.

- our "duid" implementation generates a 32 bit IAID based on a hash of the
interface-name, and only 8 bytes entropy that contains a hash
of "/etc/machine-id". The point is, that is not a lot of entropy to
avoid conflicting client-ids. Another point is, that the choosen algorithm
for "duid" is suitable for RFC 4361, but it's only one of many possibly
implementations. Granted, each possibility has up and downsides but selecting
one of them as default seems wrong (given that it has obvious downsides
already). For "mac" there is only one straight-forward way to implement
it.

- RFC 7844 (Anonymity Profiles for DHCP Clients) is not yet supported by
NetworkManager. But we should not select a default client-id which
counteracts anonymit. Choosing "mac" does not reveal information which
is not already exposed.

[1] https://tools.ietf.org/html/rfc4361#section-4

https://bugzilla.redhat.com/show_bug.cgi?id=1661165
2019-01-07 17:05:17 +01:00
Thomas Haller
2ef9a089eb dhcp: move nm_utils_dhcp_client_id_mac() to "nm-core-utils.c"
We will need it outside of "src/devices/nm-device.c".
2019-01-07 17:05:17 +01:00