Commit graph

25087 commits

Author SHA1 Message Date
Thomas Haller
7d048f1a5b clients/tests: support replacing UUIDs in command text
We want to issue a nmcli command with the connection's UUID in the command
line. As the command line is stored to disk and compared, we cannot use UUIDs
that are randomly generated. Instead, we need to support replacing the text
in the command line.
2019-12-13 13:19:31 +01:00
Thomas Haller
52b89cb21b clients/tests: fix wrongly constructing command line string as tuple in TestNmcli
It had no bad effect, but the cmd was a tuple with one string, and not
a string.
2019-12-13 13:19:31 +01:00
Thomas Haller
48225add3a clients/tests: support string arguments to Util.replace_text() 2019-12-13 13:19:31 +01:00
Thomas Haller
ffc235c30d clients/tests: rename "replace_stdout" variable to "replace_uuids"
The variable name should say what it is, not what it is used for.
E.g. we would use the very same replacements for stderr. Rename
so that it can (by its name) used for different purposes.
2019-12-13 13:19:31 +01:00
Thomas Haller
4ea999ac94 gitlab-ci: fix generating "pages" after switching to Fedora 30 for main build
(cherry picked from commit c15682558c)
2019-12-13 11:48:25 +01:00
Alexey Kodanev
c95bdb21a7 nm-manager: restore passing correct size to sendfile in copy_lease()
Otherwise sendfile() fails with EINVAL when the file offset
is greater than zero (pos + size > max), always on the second
iteration.

Fixes: 0c6cd07ec8 ('nm-manager: remove lease file if copying dhclient lease fails')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/359
(cherry picked from commit 70ebdc7730)
2019-12-12 08:08:11 +01:00
Alexey Kodanev
70ebdc7730 nm-manager: restore passing correct size to sendfile in copy_lease()
Otherwise sendfile() fails with EINVAL when the file offset
is greater than zero (pos + size > max), always on the second
iteration.

Fixes: 0c6cd07ec8 ('nm-manager: remove lease file if copying dhclient lease fails')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/359
2019-12-12 08:07:20 +01:00
Beniamino Galvani
61d431a9e8 manager: forbid autoactivation of parent when it is blocked by user request
If a device is being autoactivated and requires a parent that is
blocked due to user request, the autoactivation attempt should fail
because NM shouldn't overrule the user decision.

https://bugzilla.redhat.com/show_bug.cgi?id=1765566
(cherry picked from commit f2dbf8fbc0)
2019-12-11 13:48:52 +01:00
Beniamino Galvani
f2dbf8fbc0 manager: forbid autoactivation of parent when it is blocked by user request
If a device is being autoactivated and requires a parent that is
blocked due to user request, the autoactivation attempt should fail
because NM shouldn't overrule the user decision.

https://bugzilla.redhat.com/show_bug.cgi?id=1765566
2019-12-11 13:46:57 +01:00
Beniamino Galvani
73a2557a6f merge: branch 'bg/mtu-reapply-rh1779162'
https://bugzilla.redhat.com/show_bug.cgi?id=1779162
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/356
(cherry picked from commit ce2cceef83)
2019-12-11 13:41:27 +01:00
Beniamino Galvani
1191eba15a device: always allow reapply of MTU from wired setting
Many device types take the MTU value from the wired setting; usually
they don't implement the can_reapply_change() method and so the MTU
can't be changed with the Reapply() API.

Instead of implementing the method for all such devices to support the
same property (adding a lot of duplicated code), add a check in
NMDevice to allow the reapply of MTU when we recognize that the device
uses the MTU from the wired setting.

Device types can still decide to implement can_reapply_change() and
support whatever properties they want, even from the wired setting.

(cherry picked from commit 9339d3310e)
2019-12-11 13:40:30 +01:00
Beniamino Galvani
1aedf60244 infiniband: allow reapply of MTU
(cherry picked from commit ceeefa82c5)
2019-12-11 13:40:29 +01:00
Beniamino Galvani
ce2cceef83 merge: branch 'bg/mtu-reapply-rh1779162'
https://bugzilla.redhat.com/show_bug.cgi?id=1779162
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/356
2019-12-11 13:36:15 +01:00
Beniamino Galvani
9339d3310e device: always allow reapply of MTU from wired setting
Many device types take the MTU value from the wired setting; usually
they don't implement the can_reapply_change() method and so the MTU
can't be changed with the Reapply() API.

Instead of implementing the method for all such devices to support the
same property (adding a lot of duplicated code), add a check in
NMDevice to allow the reapply of MTU when we recognize that the device
uses the MTU from the wired setting.

Device types can still decide to implement can_reapply_change() and
support whatever properties they want, even from the wired setting.
2019-12-11 13:35:35 +01:00
Beniamino Galvani
ceeefa82c5 infiniband: allow reapply of MTU 2019-12-11 13:35:35 +01:00
Thomas Haller
76240cbe2b core/auth: merge branch 'th/polkit-root-only'
https://bugzilla.redhat.com/show_bug.cgi?id=1762011

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/357

(cherry picked from commit 218fd9e1fc)
2019-12-11 13:13:05 +01:00
Thomas Haller
096da3a046 config: print config warnings during NetworkManager --print-config
(cherry picked from commit fd8c8ffe0d)
2019-12-11 13:13:05 +01:00
Thomas Haller
74d0571cb4 config: emit warning about invalid main.auth-polkit setting
(cherry picked from commit 8f96d3cb0c)
2019-12-11 13:13:05 +01:00
Thomas Haller
e7e0909d44 config: add nm_config_data_get_warnings() to get additional warnings about wrong configuration
No additional warnings are implemented yet.

(cherry picked from commit 8d20b9363b)
2019-12-11 13:13:05 +01:00
Thomas Haller
62c9d8c109 config: return GPtrArray with warnings from internal read_entire_config() function
The underlying GPtrArray that we use to construct the list of warnings
is more useful than the strv array. For the internal function, don't
let it return the strv array but instead take (and fill) the warnings
as GPtrArray. There is no difference in practice, because also
previously we would always create an empty GPtrArray.

(cherry picked from commit 6998c5f129)
2019-12-11 13:13:05 +01:00
Thomas Haller
a0a5b0b2f5 core: add main.auth-polkit option "root-only"
We always build with PolicyKit support enabled, because it has no
additional dependencies, beside some D-Bus calls.

However, in NetworkManager.conf the user could configure
"main.auth-polkit" to disable PolicyKit. However, previously it would
only allow to disable PolicyKit while granting access to all users.

I think it's useful to have an option that disables PolicyKit and grants
access only to root. I think we should not go too far in implementing
our own authorization mechanisms beside PolicyKit (e.g. you cannot
disable PolicyKit and grant access based on group membership of the
user). However, disabling PolicyKit can be useful sometimes, and it's
simple to implement a "root-only" setup.

Note one change is that when NetworkManager now runs without a D-Bus
connection (in initrd), it would deny all non-root requests. Previously
it would grant access. I think there should be little difference in
practice, because if we have no D-Bus we also don't have any requests to
authenticate.

(cherry picked from commit 6d7446e52f)
2019-12-11 13:13:05 +01:00
Thomas Haller
d27fcd0754 build/meson: allow configuring default for main.auth-polkit setting
We always build PolicyKit support, because it merely depends on some
D-Bus calls. However, there are two things to configure:

 - the default value for main.auth-polkit in NetworkManager.conf. This
   is now called "-Dconfig_auth_polkit_default=$VAL".

 - whether to install the policy file. This is called "-Dpolkit=$VAL".

These settings are mostly independent, so add "config_auth_polkit_default" to
make the default explicitly configurable.

(cherry picked from commit c21c6bc0be)
2019-12-11 13:13:05 +01:00
Thomas Haller
218fd9e1fc core/auth: merge branch 'th/polkit-root-only'
https://bugzilla.redhat.com/show_bug.cgi?id=1762011

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/357
2019-12-11 13:10:22 +01:00
Thomas Haller
fd8c8ffe0d config: print config warnings during NetworkManager --print-config 2019-12-11 11:52:05 +01:00
Thomas Haller
8f96d3cb0c config: emit warning about invalid main.auth-polkit setting 2019-12-11 11:52:05 +01:00
Thomas Haller
8d20b9363b config: add nm_config_data_get_warnings() to get additional warnings about wrong configuration
No additional warnings are implemented yet.
2019-12-11 11:52:05 +01:00
Thomas Haller
6998c5f129 config: return GPtrArray with warnings from internal read_entire_config() function
The underlying GPtrArray that we use to construct the list of warnings
is more useful than the strv array. For the internal function, don't
let it return the strv array but instead take (and fill) the warnings
as GPtrArray. There is no difference in practice, because also
previously we would always create an empty GPtrArray.
2019-12-11 11:52:05 +01:00
Thomas Haller
6d7446e52f core: add main.auth-polkit option "root-only"
We always build with PolicyKit support enabled, because it has no
additional dependencies, beside some D-Bus calls.

However, in NetworkManager.conf the user could configure
"main.auth-polkit" to disable PolicyKit. However, previously it would
only allow to disable PolicyKit while granting access to all users.

I think it's useful to have an option that disables PolicyKit and grants
access only to root. I think we should not go too far in implementing
our own authorization mechanisms beside PolicyKit (e.g. you cannot
disable PolicyKit and grant access based on group membership of the
user). However, disabling PolicyKit can be useful sometimes, and it's
simple to implement a "root-only" setup.

Note one change is that when NetworkManager now runs without a D-Bus
connection (in initrd), it would deny all non-root requests. Previously
it would grant access. I think there should be little difference in
practice, because if we have no D-Bus we also don't have any requests to
authenticate.
2019-12-11 11:52:05 +01:00
Thomas Haller
c21c6bc0be build/meson: allow configuring default for main.auth-polkit setting
We always build PolicyKit support, because it merely depends on some
D-Bus calls. However, there are two things to configure:

 - the default value for main.auth-polkit in NetworkManager.conf. This
   is now called "-Dconfig_auth_polkit_default=$VAL".

 - whether to install the policy file. This is called "-Dpolkit=$VAL".

These settings are mostly independent, so add "config_auth_polkit_default" to
make the default explicitly configurable.
2019-12-11 11:52:05 +01:00
Thomas Haller
2534be89a1 nm-manager: remove lease file if copying dhclient lease fails
- also use nm_auto_close and nm_close().

(cherry picked from commit 0c6cd07ec8)
2019-12-11 10:07:12 +01:00
Alexey Kodanev
abeaf6ffc3 nm-manager: fix selinux label for dhclient lease file from initramfs
When moving a lease file from initramfs directory to NetworkManager
run directory, SELinux label for that file retains tmpfs_t type.

Fix it by using sendfile() instead of rename(). That way, the
lease file will have the default type: NetworkManager_var_run_t.
Since we take ownership of the lease file, also drop it from the
old location.

* Before the patch:
ls -Z /var/run/NetworkManager/dhclient-*.lease
system_u:object_r:tmpfs_t:s0 dhclient-13162c00-abfb-4e28-bbfb-170187ddd044-ens3.lease

* After:
ls -Z /var/run/NetworkManager/dhclient-*.lease
system_u:object_r:NetworkManager_var_run_t:s0 dhclient-f47d1908-67ae-49c6-bd5e-19a690d85526-ens3.lease

Fixes: f2fe6c03ee ('manager: don't treat the initramfs-configured DHCP connections as generated')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/353
(cherry picked from commit ce1f9e6eb9)
2019-12-11 10:07:11 +01:00
Thomas Haller
0c6cd07ec8 nm-manager: remove lease file if copying dhclient lease fails
- also use nm_auto_close and nm_close().
2019-12-11 10:05:00 +01:00
Alexey Kodanev
ce1f9e6eb9 nm-manager: fix selinux label for dhclient lease file from initramfs
When moving a lease file from initramfs directory to NetworkManager
run directory, SELinux label for that file retains tmpfs_t type.

Fix it by using sendfile() instead of rename(). That way, the
lease file will have the default type: NetworkManager_var_run_t.
Since we take ownership of the lease file, also drop it from the
old location.

* Before the patch:
ls -Z /var/run/NetworkManager/dhclient-*.lease
system_u:object_r:tmpfs_t:s0 dhclient-13162c00-abfb-4e28-bbfb-170187ddd044-ens3.lease

* After:
ls -Z /var/run/NetworkManager/dhclient-*.lease
system_u:object_r:NetworkManager_var_run_t:s0 dhclient-f47d1908-67ae-49c6-bd5e-19a690d85526-ens3.lease

Fixes: f2fe6c03ee ('manager: don't treat the initramfs-configured DHCP connections as generated')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/353
2019-12-11 09:58:45 +01:00
Thomas Haller
cf7662bc52 n-dhcp4/socket: use SO_REUSEADDR on UDP socket
Otherwise, other applications cannot bind to port 0.0.0.0:68 at the same time.
This is for example what dhclient wants to do. So even when running
dhclient on another, unrelated interface, it would fail to bind the UDP
socket and quit.

Note that also systemd-networkd's DHCPv4 client sets this socket option.
Presumably for the same reasons.

Signed-off-by: Thomas Haller <thaller@redhat.com>

https://github.com/nettools/n-dhcp4/pull/12
(cherry picked from commit 53b74bc614)
2019-12-11 09:25:05 +01:00
Thomas Haller
53b74bc614 n-dhcp4/socket: use SO_REUSEADDR on UDP socket
Otherwise, other applications cannot bind to port 0.0.0.0:68 at the same time.
This is for example what dhclient wants to do. So even when running
dhclient on another, unrelated interface, it would fail to bind the UDP
socket and quit.

Note that also systemd-networkd's DHCPv4 client sets this socket option.
Presumably for the same reasons.

Signed-off-by: Thomas Haller <thaller@redhat.com>

https://github.com/nettools/n-dhcp4/pull/12
2019-12-11 09:24:14 +01:00
Beniamino Galvani
d33bea21b7 cli: expose device D-Bus path
https://bugzilla.redhat.com/show_bug.cgi?id=1745574
(cherry picked from commit 622eef4882)
2019-12-10 17:58:56 +01:00
Beniamino Galvani
622eef4882 cli: expose device D-Bus path
https://bugzilla.redhat.com/show_bug.cgi?id=1745574
2019-12-10 17:57:10 +01:00
Thomas Haller
3d07708f59 doc: clarify default values for ipv4.mdns and ipv4.llmnr settings
LLMNR and mDNS settings can have their global default value configured
in "NetworkManager.conf".

Global default values should work the way that all regular values of the property
can be configured explicitly in the connection profile. The special "default" value
only indicates to allow lookup of the global default, but it should not have a
meaning of its own.

Note that if mDNS/LLMNR settings are left unspecified, we will set the
argument to SetLinkMulticastDNS() and SetLinkLLMNR() functions to "",
which means that systemd-resolved decides on a default. Also, depending
on the DNS plugin, the default value differs. This is all fine however.
In this case, the ultimate default value depends on other things (like
the DNS plugin), but each possible value is in fact explicitly
configurable. We also do that for "ipv6.ip6-privacy".

Anyway, cleanup the documentation a bit and try to better explain what
the default is.
2019-12-10 16:49:23 +01:00
Thomas Haller
a5779595ce all: merge branch 'th/polkit-permissions-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/355
2019-12-10 09:21:24 +01:00
Thomas Haller
cb755afa24 clients: in debug builds randomly use sync init of NMClient for testing
This affects nmtui and nm-cloud-setup, which use nmc_client_new_waitsync().
2019-12-10 09:17:17 +01:00
Thomas Haller
030e1472f4 cli: don't fetch permissions for NMClient in nmcli unless required
This avoids unnecessarily fetching permissions, which are not needed
most of the time.

During `nmcli general permissions` we require to fetch the permissions. This is
now solved better, because previously the code waited for any permissions to be
not UNKNOWN. That was a hack, because there are cases where all permissions would
be UNKNOWN (hidepid mount option) and nmcli would hang.

There is a downside too: for `nmcli general permissions` we now first
need to wait for NMClient to initialize, before starting to fetch
permissions. Previously, we would call GetPermissions() in parallel
with initializing NMClient. It now takes longer.
That should be fixed be refactoring the code in nmcli to not wait for
NMClient to be fully initialized, before requesting the permissions.
2019-12-10 09:17:17 +01:00
Thomas Haller
3035837aa8 cli: use nmc_client_new_async() instead of nm_client_new_async()
This will allow us to set construct parameters to the instance, like
NM_CLIENT_INSTANCE_FLAGS.
2019-12-10 09:17:17 +01:00
Thomas Haller
0046163201 nm-online: don't fetch permissions for NMClient in nm-online
nm-online doesn't care about the permissions. Don't fetch them.
2019-12-10 09:17:17 +01:00
Thomas Haller
0b5e72b90d nm-online: use nmc_client_new_async() instead of nm_client_new_async()
This will allow us to set construct parameters to the instance, like
NM_CLIENT_INSTANCE_FLAGS.
2019-12-10 09:17:17 +01:00
Thomas Haller
b78e5cf45c cloud-setup: don't fetch permissions for NMClient in nm-cloud-setup
nm-cloud-setup doesn't care about the permissions. Don't fetch them.
2019-12-10 09:17:17 +01:00
Thomas Haller
c5c7fffda8 cloud-setup: reuse nmc_client_new_waitsync() to create NMClient instance 2019-12-10 09:17:17 +01:00
Thomas Haller
b6c83d18e4 tui: don't fetch permissions for NMClient in nmtui
nmtui doesn't care about the permissions. Don't fetch them.
2019-12-10 09:17:17 +01:00
Thomas Haller
5859e9a53d tui: create NMClient instance via async init
Using sync init (nm_client_new()) has an overhead as it requires an internal
GMainContext to ensure preserving the order of D-Bus messages. Let's avoid
that by using the async init. Note that the difference here is that we will
iterate the caller's GMainContext while creating the instance. But that
is no problem for nmtui at that point.
2019-12-10 09:17:17 +01:00
Thomas Haller
9e10b4f699 shared: add nmc_client_new_waitsync() and nmc_client_new_async*() helpers
Benefits:

- nmc_client_new_async*() allows to set properties on the NMClient
  instance before calling g_async_initable_init_async().
  It also allows to subscribe to any signals (like NM_CLIENT_DEVICE_ADDED)
  before actually iterating the GMainContext. This is a sensible and
  supported thing to do!

- nmc_client_new_waitsync() iterates the GMainContext until the (async)
  initialization is complete. That is different from synchronous nm_client_new(),
  which does not iterate the caller's GMainContext, and hence needs an
  internal context to ensure the order of events is honored.

- nmc_client_new_waitsync() always returns the NMClient instance, even
  if initialization fails.
  That is useful if you need the nm_client_get_context_busy_watcher() instance
  to ensure all pending messages are completed.
2019-12-10 09:17:17 +01:00
Thomas Haller
3843e0c87d shared: add "shared/nm-libnm-aux" static library
We have "shared/nm-libnm-core-aux", which is shared code that can be used
by anybody (including libnm-core, src, libnm and clients).

We have "clients/common", which are helper function for clients. But
that implies that the code is inside "clients". I think it would be
useful to have auxiliary code that extends libnm, but is not only
usable by code in "clients". In other words, "shared/nm-libnm-aux"
is a better place than "clients/common", and I think most of the
functionality form "clients/common" should move there.
2019-12-10 09:17:17 +01:00