Commit graph

12521 commits

Author SHA1 Message Date
Beniamino Galvani
9a1bbef1b4 dhcp: nettools: move to failed state if event dispatch fails
(cherry picked from commit 45521b1b38)
2020-02-11 09:28:27 +01:00
Beniamino Galvani
a0c209b653 team: ignore bus name appearance when killing teamd
If we are currently killing teamd, we are not interested in knowing
when it becomes ready.

(cherry picked from commit 554e9be5b0)
2020-02-11 09:21:35 +01:00
Beniamino Galvani
77635adb50 team: ignore bus name appearance if we can't determine process id
If the GetConnectionUnixProcessID() call fails, the process that
registered on the bus has died and we should ignore the name
appearance event.

(cherry picked from commit e94d76382c)
2020-02-11 09:21:33 +01:00
Thomas Haller
c1417087c8 platform: fix GCC warning about zero-length array in nmp_utils_ethtool_get_permanent_address()
GCC 10 complains about accesses to elements of zero-length arrays that
overlap other members of the same object:

  src/platform/nm-platform-utils.c: In function ‘nmp_utils_ethtool_get_permanent_address’:
  src/platform/nm-platform-utils.c:854:29: error: array subscript 0 is outside the bounds of an interior zero-length array ‘__u8[0]’ {aka ‘unsigned char[0]’} [-Werror=zero-length-bounds]
    854 |  if (NM_IN_SET (edata.e.data[0], 0, 0xFF)) {
  ./shared/nm-glib-aux/nm-macros-internal.h:731:20: note: in definition of macro ‘_NM_IN_SET_EVAL_N’

Fix this warning.

(cherry picked from commit d892a35395)
2020-02-10 13:34:33 +01:00
Thomas Haller
286bb2f029 platform: fix GCC warning about zero-length array in ethtool_get_stringset()
GCC 10 complains about accesses to elements of zero-length arrays that
overlap other members of the same object:

 src/platform/nm-platform-utils.c: In function ‘ethtool_get_stringset’:
 src/platform/nm-platform-utils.c:355:27: error: array subscript 0 is outside the bounds of an interior zero-length array ‘__u32[0]’ {aka ‘unsigned int[0]’} [-Werror=zero-length-bounds]
   355 |  len = sset_info.info.data[0];
       |        ~~~~~~~~~~~~~~~~~~~^~~
 In file included from src/platform/nm-platform-utils.c:12:
 /usr/include/linux/ethtool.h:647:8: note: while referencing ‘data’
   647 |  __u32 data[0];
       |        ^~~~

Fix this warning.

(cherry picked from commit 16e1e44c5e)
2020-02-10 13:34:33 +01:00
Thomas Haller
273fcf51bd Revert "platform: fix GCC warning about zero-lenght array (2)"
This reverts commit 5076fc0ca0.

(cherry picked from commit 0931c4f2ea)
2020-02-10 13:34:33 +01:00
Thomas Haller
f140e21689 Revert "platform: fix GCC warning about zero-lenght array (1)"
I think this solution is not right, because "char buf" is not guaranteed
to have the correct alignment. Revert, and solve it differently.

This reverts commit 6345a66153.

(cherry picked from commit 1fd7e45139)
2020-02-10 13:34:33 +01:00
Beniamino Galvani
a1b0edd24b ovs: wait that link disappears before continuing with deactivation
When we deactivate a virtual device, we usually schedule the deletion
of the link in an idle handler. That action will be executed at a
later time when the device is already in the disconnected state.

Similarly, for ovs interfaces we send the deletion command to the
ovsdb and then proceed to the disconnected state.

However, in the first case there is the guarantee that the link will
be deleted at some point, while for ovs interfaces it may happen that
ovs decides to reuse the same link if there is an addition
queued. Since reusing the same link confuses NM, let's implement
deactivate_async() for ovs-interfaces and wait that the link actually
goes away before proceeding.

https://bugzilla.redhat.com/show_bug.cgi?id=1782701
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/402
(cherry picked from commit 623a1e1f99)
2020-02-05 22:32:52 +01:00
Beniamino Galvani
c02b0181cf platform: fix GCC warning about zero-lenght array (2)
GCC 10 complains about accesses to elements of zero-length arrays that
overlap other members of the same object:

  src/platform/nm-platform-utils.c: In function ‘nmp_utils_ethtool_get_permanent_address’:
  src/platform/nm-platform-utils.c:854:29: error: array subscript 0 is outside the bounds of an interior zero-length array ‘__u8[0]’ {aka ‘unsigned char[0]’} [-Werror=zero-length-bounds]
    854 |  if (NM_IN_SET (edata.e.data[0], 0, 0xFF)) {
  ./shared/nm-glib-aux/nm-macros-internal.h:731:20: note: in definition of macro ‘_NM_IN_SET_EVAL_N’

Fix this warning.

(cherry picked from commit 5076fc0ca0)
2020-02-03 15:31:30 +01:00
Beniamino Galvani
a7c1b324fd platform: fix GCC warning about zero-lenght array (1)
GCC 10 complains about accesses to elements of zero-length arrays that
overlap other members of the same object:

 src/platform/nm-platform-utils.c: In function ‘ethtool_get_stringset’:
 src/platform/nm-platform-utils.c:355:27: error: array subscript 0 is outside the bounds of an interior zero-length array ‘__u32[0]’ {aka ‘unsigned int[0]’} [-Werror=zero-length-bounds]
   355 |  len = sset_info.info.data[0];
       |        ~~~~~~~~~~~~~~~~~~~^~~
 In file included from src/platform/nm-platform-utils.c:12:
 /usr/include/linux/ethtool.h:647:8: note: while referencing ‘data’
   647 |  __u32 data[0];
       |        ^~~~

Fix this warning.

(cherry picked from commit 6345a66153)
2020-02-03 15:31:28 +01:00
Beniamino Galvani
7ba2040caa all: remove wrong CURL option initialization
curl_multi_setopt() accepts CURLMOPT_* options, not CURLOPT_*
ones. Found by GCC 10:

clients/cloud-setup/nm-http-client.c:700:38: error: implicit conversion from ‘enum <anonymous>’ to ‘CURLMoption’ [-Werror=enum-conversion]
  700 |    curl_multi_setopt (priv->mhandle, CURLOPT_VERBOSE, 1);

Fixes: 69f048bf0c ('cloud-setup: add tool for automatic IP configuration in cloud')
(cherry picked from commit c11ac34f4c)
2020-02-03 15:31:18 +01:00
Beniamino Galvani
d2354387d9 ndisc: remove upper bound for IPv6 autoconfiguration timeout
As it is possible to configure an arbitrarily large DHCP timeout, it
should be possible to also set a large timeout for IPv6
autoconfiguration. Currently the timeout can only be changed via
sysctl. Leave the lower bound because the default kernel sysctl value
is 3 * 4 = 12 seconds and so without the lower limit the default
timeout would change from 30 to 12 seconds for every user, which seems
a big change and could possibly break users' setup.

https://bugzilla.redhat.com/show_bug.cgi?id=1795957
(cherry picked from commit d8e1f4c8ef)
2020-01-30 15:43:18 +01:00
Beniamino Galvani
6c1daa4fa9 device: accept new leases in NM_DEVICE_IP_STATE_DONE
If the current lease expires, we start the grace period in which the
clients starts again from the INIT DHCP state (i.e. sending DISCOVER
messages). If it is able to obtain a new lease, it must be accepted or
otherwise the client will not renew it.

(cherry picked from commit df75c21b4d)
2020-01-30 15:43:16 +01:00
Beniamino Galvani
5182ca8782 dhcp: introduce EXTENDED state for renewals
Currently the DHCP client reports the BOUND state not only when the
lease is obtained initially but also when it is renewed. Having a
different state for the renewal will be used by NMDevice in the next
patch to determine whether the lease needs to be accept()ed or not.

(cherry picked from commit a4ddb56923)
2020-01-30 15:42:58 +01:00
Beniamino Galvani
4505c25270 dhcp: derive the grace period duration from the timeout property
Currently the duration of the DHCP grace period (in which we try to
acquire a new lease after expiration) is hardcoded to 480
seconds. That value seems arbitrary and too long for the default
configuration. Since we already have a property that allows the user
to configure how long NM should try to get the lease initially, it
makes sense to use it also for retries after lease expirations.

In particular, setting the ipvx.dhcp-timeout to a high value extends
also the grace period to a very long time, potentially forever.

(cherry picked from commit aee78ca788)
2020-01-30 15:42:56 +01:00
Beniamino Galvani
4b32506f5e device: change return type of get_dhcp_timeout()
(cherry picked from commit d0caad7a8d)
2020-01-30 15:42:55 +01:00
Beniamino Galvani
66d90dc382 device: move code around
(cherry picked from commit 70f1ee0ffb)
2020-01-30 15:42:54 +01:00
Thomas Haller
26d6ac5385 supplicant: fix memory corruption with wrong argument to NM_SUPPLICANT_INTERFACE_GROUP_FORMATION_FAILURE signal
The signal is unused (and should be removed).

Still, the parameter passed to g_signal_emit() is a C string, not a
GVariant. I think as there are no subscribers, glib wouldn't actually
do anything with the arguments. Though, I am not sure whether glib still
tries to initialize a GValue with a GVariant type, leading to a crash.

Fixes: f05b7a78c9 ('supplicant: Track P2P Group information, creation and destruction')
(cherry picked from commit c106008091)
2020-01-30 11:44:10 +01:00
Beniamino Galvani
82f1129005 manager: check for master existence before realizing the device
If we find out that no compatible master connection exists, we
shouldn't realize the slave in the first place.

(cherry picked from commit ab57b575a0)
2020-01-29 16:47:36 +01:00
Beniamino Galvani
51d7941b0e manager: skip activation of a virtual device if master is missing
Don't realize a virtual device if the master is missing because in
such case the autoactivation can't start and a stale link will be
created.

(cherry picked from commit 336bfcabc4)
2020-01-29 16:47:34 +01:00
Antonio Cardace
11c989bb04 nm-device: add new pending action to keep the device busy when in between states
Add a 'in-state-change' pending action to be sure the device always has a
pending when transitioning between states (this prevents callbacks to mark
startup as complete while running _set_state_full()).

This is needed as during the 'failed'->'disconnected' the pending action 'activation-*'
for the device is removed resulting in an empty pending_actions list which then
triggers 'check_if_startup_complete()' that will find no pending action and mark
startup as complete even if the device could have been activated with another connection.

https://bugzilla.redhat.com/show_bug.cgi?id=1759956
(cherry picked from commit f583aec806)
2020-01-29 12:02:52 +01:00
Beniamino Galvani
6f66ff845f dhcp: don't add server-id option to the parameter request list
The option is mandatory in the replies from server and so we don't
need to ask for it. dhclient doesn't do it either. But especially, it
seems that requesting the option causes some broken server
implementations to send duplicate instances of the option.

So, remove the option from the parameter request list of the internal
nettools and systemd DHCP implementation.

(cherry picked from commit 541db78259)
2020-01-25 11:43:53 +01:00
Thomas Haller
86b2858019 initrd/cmdline: minor style cleanups
(cherry picked from commit 9f95b797f1)
2020-01-14 16:45:41 +01:00
Lubomir Rintel
9fddb395d5 initrd/cmdline: obey rd.iscsi.ibft
Do process the connections from the iBFT block if the rd.iscsi.ibft or
rd.iscsi.ibft=1 argument is present.

This is supposed to fix what was originally reported by Kairui Song
<kasong@redhat.com> here: https://github.com/dracutdevs/dracut/pull/697

(cherry picked from commit 39e1e723de)
2020-01-14 16:45:41 +01:00
Lubomir Rintel
7ffac26a49 initrd/ibft-reader: don't set con.interface-name in iBFT connections
If an argument in form ip=eth0:ibft is specified, we'd first create a
wired connection with con.interface-name and then proceed completing it
from the iBFT block. At that point we also add the MAC address, so the
interface-name is no longer necessary..

Worse even, for VLAN connections, it results in an attempt to create
a VLAN with the same name as the parent wired device. Ooops.

Let's just drop it. MAC address is guarranteed to be there and does the
right thing for both plain wired devices as well as VLANs.

(cherry picked from commit 59ead70952)
2020-01-14 16:45:41 +01:00
Beniamino Galvani
92b382e2f8 dhcp: nettools: handle 'retracted' event as 'expired'
The 'retracted' event is emitted when the client receives a NAK in the
rebooting, requesting, renewing or rebinding state, while 'expired'
means that the client wasn't able to renew the lease before expiry.

In both cases the old lease is no longer valid and n-dhcp4 keep trying
to get a lease, so the two events should be handlded in the same way.

Note that the systemd client doesn't have a 'retracted' event and
considers all NAKs as 'expired' events.

(cherry picked from commit 2523000b36)
2020-01-09 09:47:57 +01:00
Thomas Haller
568c19f07d device/wifi: fix memleak parsing SSID arguments for "RequestScan"
Oddly enough, valgrind was not complaining about this leak...

Fixes: 87b2d783b6 ('core: accept 'ssids':aay option in RequestScan() dictionary parameter')
(cherry picked from commit 5ed1edc02a)
2020-01-08 12:16:11 +01:00
Antonio Cardace
6d58932875 platform/linux: add support for /31 prefixes on IPv4 point-to-point links
Previously NetworkManager would wrongly add a broadcast address for the
network prefix that would collide with the IP address of the host on
the other end of the point-to-point link thus exhausting the IP address
space of the /31 network and preventing communication between the two
nodes.

Configuring a /31 address before this commit:
	IP addr -> 10.0.0.0/31, broadcast addr -> 10.0.0.1

If 10.0.0.1 is configured as a broadcast address the communication
with host 10.0.0.1 will not be able to take place.

Configuring a /31 address after this commit:
	IP addr -> 10.0.0.0/31, no broadcast address

Thus 10.0.0.0/31 and 10.0.0.1/31 are able to correctly communicate.

See RFC-3021. https://tools.ietf.org/html/rfc3021

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/295

https://bugzilla.redhat.com/show_bug.cgi?id=1764986
(cherry picked from commit fa144b5ae9)
2020-01-07 17:15:25 +01:00
Thomas Haller
4b1053da91 core: add and indicate NM_CAPABILITY_OVS capability on D-Bus
https://bugzilla.redhat.com/show_bug.cgi?id=1785147
(cherry picked from commit 785da51d83)
2019-12-24 14:37:46 +01:00
Beniamino Galvani
46ad3aa4f3 dhcp: nettools: start from init-reboot phase when reusing address
If we know the address used previously, also tell the client to start
from the init-reboot phase, so that it will start with a DHCP request
instead of a discover.

(cherry picked from commit 6af6f70d81)
2019-12-23 16:45:44 +01:00
Beniamino Galvani
bee319bf94 dhcp: nettools: fix parsing of classless routes option
Fixes: 6adade6f21 ('dhcp: add nettools dhcp4 client')
(cherry picked from commit dd3114deb0)
2019-12-23 16:45:43 +01:00
Beniamino Galvani
09597c105e dhcp: test parsing of domain-search option
Add a test for the parsing of the the domain-search option.

(cherry picked from commit c9fbdf3cb0)
2019-12-23 16:45:41 +01:00
Beniamino Galvani
fc41827874 dhcp: nettools: check return value of g_file_set_contents()
Found by covscan:

 NetworkManager-1.22.0/src/dhcp/nm-dhcp-nettools.c:945: check_return:
 Calling "g_file_set_contents" without checking return value (as is
 done elsewhere 16 out of 20 times).

Fixes: 9f89516928 ('dhcp: nettools: read/write lease files')
(cherry picked from commit cfc418f887)
2019-12-18 10:04:36 +01:00
Beniamino Galvani
ea22135384 dhcp: nettools: fix parsing of search domains option
'first' was never modified and so the dot was never added.

Fixes: 6adade6f21 ('dhcp: add nettools dhcp4 client')

https://bugzilla.redhat.com/show_bug.cgi?id=1783981
(cherry picked from commit 9aa00a8a14)
2019-12-17 14:35:05 +01:00
Thomas Haller
809d70ee64 all: fix wrong "gs_free GError *" declarations
This is a bug and leads either to a leak or a crash.

(cherry picked from commit 4a3ca7115a)
2019-12-16 17:45:18 +01:00
Beniamino Galvani
944ff9f9dc manager: create a virtual device only if the connection can autoconnect
The autoconnection for virtual devices currently works in two
phases. First we detect that there is suitable profile that can
autoconnect and we realize the device. Then, when the device becomes
'disconnected', autoconnect kicks in and starts the activation.

However, if autoconnect is blocked for a device, currently we do step
1 without step 2, leaving a stale interface around. Fix this by also
checking that autoconnect is not blocked during step 1.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/360
(cherry picked from commit 6c716912eb)
2019-12-15 09:37:25 +01:00
Beniamino Galvani
f1d4853927 device: don't reapply IP configuration if the ifindex is missing
Assertions will fail in ip_config_merge_and_apply() if the device
doesn't have an ifindex. Reproducible with:

 $ nmcli connection add type ovs-bridge ifname ovs0 ipv4.method disabled ipv6.method disabled
 Connection 'ovs-bridge-ovs0' (1d5e794b-10ad-4b2b-aa7c-5ca7e34b0a55) successfully added

 $ nmcli device reapply ovs0
 Error: Reapplying connection to device '(null)' (/org/freedesktop/NetworkManager/Devices/16) failed: Remote peer disconnected

 $ journalctl -u NetworkManager -e
 ...
 NetworkManager[73824]: nm_ip4_config_add_dependent_routes: assertion 'ifindex > 0' failed
 systemd[1]: NetworkManager.service: Main process exited, code=dumped, status=5/TRAP
 ...

(cherry picked from commit 6d6e1402dc)
2019-12-14 21:05:54 +01:00
Beniamino Galvani
3381299562 ovs: check state before starting ip configuration after link change
When the link becomes available, check that the device is in the
ip-config state before starting ip configuration. Also, reset the
'waiting_for_interface' flag when the device deactivates.

https://bugzilla.redhat.com/show_bug.cgi?id=1781165
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/358
(cherry picked from commit 0738c10445)
2019-12-14 21:05:53 +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
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
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
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
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
7e8a5d98e3 settings: assert that we don't leak error variable in impl_settings_load_connections()
(cherry picked from commit e0569ee575)
2019-12-09 09:55:16 +01:00