Commit Graph

30978 Commits

Author SHA1 Message Date
Thomas Haller
c5ec4ebd77 glib-aux: fix spurious semicolon after NM_STR_BUF_INIT() macros
It's wrong, and it breaks certain uses.

Fixes: 13d25f9d0b ('glib-aux: add support for starting with stack-allocated buffer in NMStrBuf')
2022-08-31 19:20:10 +02:00
Thomas Haller
98c3ac1480 checkpatch.pl: discourage g_str_hash()/g_direct_hash() and g_direct_equal()
- instead of g_str_hash()/g_direct_hash(), use our own functions
  nm_str_hash()/nm_direct_hash(). Those use siphash24 with a random
  seed.

- don't pass g_direct_equal() to GHashTable. When omitting the equal
  function, it falls back to direct pointer comparison, which is likely
  faster. In any case, it's consistent to not use g_direct_hash()
  when using pointer equality.

- instead of g_int_hash()/g_int64_hash()/g_double_hash(), use
  our nm_pint_hash()/nm_pint64_hash()/nm_pdouble_hash(). The latter
  two don't exist yet.
  The reason is that we want to use siphash24.
  Yes, our name differs from glib's. Our naming seems to make sense
  to me however, because we also have nm_pstr_hash(), nm_pdirect_hash()
  and even nm_ppdirect_hash() for following the pointers. Naming is hard.

- instead of g_int_equal()/g_int64_equal()/g_double_equal() use
  our nm_pint_equal()/nm_pint64_equal()/nm_pdouble_equal(). The latter
  two don't exist yet. The reason is purely naming consistency since
  our hash variants follow the other name.
2022-08-31 10:59:22 +02:00
Thomas Haller
6b74f3cc14 cloud-setup,glib-aux: use NULL instead of g_direct_equal() for hash tables 2022-08-31 09:47:48 +02:00
Thomas Haller
4c48864972 initrd: avoid duplicate file check and NULL pointer dereference in nmi_ibft_read()
- move the second g_file_test() inside the if-block. No need to check
  twice, if the file exists.

- load_one_nic() can return NULL. Use nm_g_hash_table_lookup() to avoid
  NULL pointer assertion.

- use cleanup attribute for "nic" variable, and explicitly pass
  ownership on with g_steal_pointer().
2022-08-31 09:42:23 +02:00
Adrian Freihofer
ff7c5f4024 device: load only required modules
Honor firewall-backend for modules loading and ip forwarding enabling as
well:
* iptables: do not load nftables modules
* nftables: do not load iptables modules
* none: do not load any modules and do not enable ip forwarding

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1356
2022-08-31 09:19:01 +02:00
Thomas Haller
b336b249f5 wifi: use GSource instead of source ID for Wi-Fi scan_kickoff_timeout 2022-08-30 10:09:23 +02:00
Thomas Haller
ade9e17664 wifi: allow explicit scans during AP/ADHOC modes
The user might still want to see the scan list, to decide whether to
stop the hotspot/ADHOC connection and connect to something else.

Allow explicit scans.
2022-08-30 09:58:03 +02:00
Thomas Haller
55767cf5c5 NEWS: update 2022-08-26 19:45:28 +02:00
Thomas Haller
7a0c2f8be9 release: bump version to 1.41.1 (development) 2022-08-26 19:28:11 +02:00
Ana Cabral
5d4802f7d8 release: bump version to 1.40.0 2022-08-26 16:41:39 +02:00
Ana Cabral
1ece234b24 NEWS: update 2022-08-26 16:26:18 +02:00
Ana Cabral
2652df3f47 NEWS: update 2022-08-26 16:17:40 +02:00
Thomas Haller
c4465b4df7 tests: merge branch 'th/test-client-no-pexpect' 2022-08-26 00:01:37 +02:00
Thomas Haller
36ad9855d1 tests: fix "test-client.py" for early python3 versions
ModuleNotFoundError was only introduced in later python 3 versions.
Use just "ImportError", which is the parent class anyway.

Fixes: f7e484c8ed ('tests: fix "test-client.py" ignoring missing "NM" module')
(cherry picked from commit 9902373c6d)
2022-08-26 00:01:12 +02:00
Thomas Haller
d6d76f900f tests: fix "test-client.py" ignoring missing "NM" module
Fixes: 8959083784 ('tests: skip test in "test-client.py" if the pexepect dependency is not available')
(cherry picked from commit f7e484c8ed)
2022-08-26 00:01:12 +02:00
Thomas Haller
3dc5943134 tests: skip test in "test-client.py" if the pexepect dependency is not available
(cherry picked from commit 8959083784)
2022-08-26 00:01:11 +02:00
Thomas Haller
9902373c6d tests: fix "test-client.py" for early python3 versions
ModuleNotFoundError was only introduced in later python 3 versions.
Use just "ImportError", which is the parent class anyway.

Fixes: f7e484c8ed ('tests: fix "test-client.py" ignoring missing "NM" module')
2022-08-26 00:00:14 +02:00
Thomas Haller
2b1f7cfff4 style: fix code formatting
Fixes: eec9efd989 ('glib-aux: fix nicks for zero flag in nm_utils_enum_to_str()')
(cherry picked from commit befbad7375)
2022-08-25 23:28:05 +02:00
Thomas Haller
befbad7375 style: fix code formatting
Fixes: eec9efd989 ('glib-aux: fix nicks for zero flag in nm_utils_enum_to_str()')
2022-08-25 23:27:36 +02:00
Thomas Haller
14633422e2 dhcp: merge branch 'bg/restart-dhcp-on-mac-change'
https://bugzilla.redhat.com/show_bug.cgi?id=2110000

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1343

(cherry picked from commit 7f40eb1b04)
2022-08-25 23:24:48 +02:00
Beniamino Galvani
5a49a2f6b2 device: restart DHCP when the MAC changes
If the MAC changes there is the possibility that the DHCP client will
not be able to renew the address because it uses the old MAC as
CHADDR. Depending on the implementation, the DHCP server might use
CHADDR (so, the old address) as the destination MAC for DHCP replies,
and those packets will be lost.

To avoid this problem, restart the DHCP client when the MAC changes.

https://bugzilla.redhat.com/show_bug.cgi?id=2110000
(cherry picked from commit 905adabdba)
2022-08-25 23:24:47 +02:00
Beniamino Galvani
2f8e4e2b06 core: log when dynamic IP configuration is restarted and why
(cherry picked from commit 6cd69fde33)
2022-08-25 23:24:46 +02:00
Thomas Haller
7f40eb1b04 dhcp: merge branch 'bg/restart-dhcp-on-mac-change'
https://bugzilla.redhat.com/show_bug.cgi?id=2110000

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1343
2022-08-25 23:21:41 +02:00
Beniamino Galvani
905adabdba device: restart DHCP when the MAC changes
If the MAC changes there is the possibility that the DHCP client will
not be able to renew the address because it uses the old MAC as
CHADDR. Depending on the implementation, the DHCP server might use
CHADDR (so, the old address) as the destination MAC for DHCP replies,
and those packets will be lost.

To avoid this problem, restart the DHCP client when the MAC changes.

https://bugzilla.redhat.com/show_bug.cgi?id=2110000
2022-08-25 23:19:13 +02:00
Beniamino Galvani
6cd69fde33 core: log when dynamic IP configuration is restarted and why 2022-08-25 23:18:53 +02:00
Lubomir Rintel
9d7e5a3b79 device: wait for carrier on unavailable device even when it gets a connection assumed
The test in question leaves the device with a master set, which caused a
connection to get assumed and therefore the previous fix didn't kick in.

Fixes-test: @restart_L2_only_lacp
Fixes: 5b7f8f3f70 ('device: wait for carrier even if it wasn't us who brought the device IFF_UP')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1348
(cherry picked from commit c183f10f65)
2022-08-25 23:16:13 +02:00
Lubomir Rintel
c183f10f65 device: wait for carrier on unavailable device even when it gets a connection assumed
The test in question leaves the device with a master set, which caused a
connection to get assumed and therefore the previous fix didn't kick in.

Fixes-test: @restart_L2_only_lacp
Fixes: 5b7f8f3f70 ('device: wait for carrier even if it wasn't us who brought the device IFF_UP')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1348
2022-08-25 23:15:24 +02:00
Thomas Haller
db89d0a6fd mptcp: merge branch 'th/mptcp-flags-changes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1346

(cherry picked from commit 2f0539b0b7)
2022-08-25 23:12:55 +02:00
Thomas Haller
b1a402b1fc glib-aux: fix nicks for zero flag in nm_utils_enum_to_str()
nm_utils_enum_to_str() can print flags, that is, combinations of
powers of two integers.

It also supports nicks, for certain flags.

When we have a nick for value zero, then that requires special
handling. Otherwise, that zero nick will always show up in the
string representation, although, it should only be used if the
enum value is exactly zero.

(cherry picked from commit eec9efd989)
2022-08-25 23:12:53 +02:00
Thomas Haller
56d0d35516 mptcp: rework "connection.mptcp-flags" for enabling MPTCP
1) The "enabled-on-global-iface" flag was odd. Instead, have only
and "enabled" flag and skip (by default) endpoints on interface
that have no default route. With the new flag "also-without-default-route",
this can be overruled. So previous "enabled-on-global-default" now is
the same as "enabled", and "enabled" from before behaves now like
"enabled,also-without-default-route".

2) What was also odd, as that the fallback default value for the flags
depends on "/proc/sys/net/mptcp/enabled". There was not one fixed
fallback default, instead the used fallback value was either
"enabled-on-global-iface,subflow" or "disabled".
Usually that is not a problem (e.g. the default value for
"ipv6.ip6-privacy" also depends on use_tempaddr sysctl). In this case
it is a problem, because the mptcp-flags (for better or worse) encode
different things at the same time.
Consider that the mptcp-flags can also have their default configured in
"NetworkManager.conf", a user who wants to switch the address flags
could previously do:

  [connection.mptcp]
  connection.mptcp-flags=0x32   # enabled-on-global-iface,signal,subflow

but then the global toggle "/proc/sys/net/mptcp/enabled" was no longer
honored. That means, MPTCP handling was always on, even if the sysctl was
disabled. Now, "enabled" means that it's only enabled if the sysctl
is enabled too. Now the user could write to "NetworkManager.conf"

  [connection.mptcp]
  connection.mptcp-flags=0x32   # enabled,signal,subflow

and MPTCP handling would still be disabled unless the sysctl
is enabled.

There is now also a new flag "also-without-sysctl", so if you want
to really enable MPTCP handling regardless of the sysctl, you can.
The point of that might be, that we still can configure endpoints,
even if kernel won't do anything with them. Then you could just flip
the sysctl, and it would start working (as NetworkManager configured
the endpoints already).

Fixes: eb083eece5 ('all: add NMMptcpFlags and connection.mptcp-flags property')
(cherry picked from commit c00873e08f)
2022-08-25 23:12:53 +02:00
Thomas Haller
2f0539b0b7 mptcp: merge branch 'th/mptcp-flags-changes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1346
2022-08-25 23:12:00 +02:00
Thomas Haller
eec9efd989 glib-aux: fix nicks for zero flag in nm_utils_enum_to_str()
nm_utils_enum_to_str() can print flags, that is, combinations of
powers of two integers.

It also supports nicks, for certain flags.

When we have a nick for value zero, then that requires special
handling. Otherwise, that zero nick will always show up in the
string representation, although, it should only be used if the
enum value is exactly zero.
2022-08-25 23:07:44 +02:00
Thomas Haller
c00873e08f mptcp: rework "connection.mptcp-flags" for enabling MPTCP
1) The "enabled-on-global-iface" flag was odd. Instead, have only
and "enabled" flag and skip (by default) endpoints on interface
that have no default route. With the new flag "also-without-default-route",
this can be overruled. So previous "enabled-on-global-default" now is
the same as "enabled", and "enabled" from before behaves now like
"enabled,also-without-default-route".

2) What was also odd, as that the fallback default value for the flags
depends on "/proc/sys/net/mptcp/enabled". There was not one fixed
fallback default, instead the used fallback value was either
"enabled-on-global-iface,subflow" or "disabled".
Usually that is not a problem (e.g. the default value for
"ipv6.ip6-privacy" also depends on use_tempaddr sysctl). In this case
it is a problem, because the mptcp-flags (for better or worse) encode
different things at the same time.
Consider that the mptcp-flags can also have their default configured in
"NetworkManager.conf", a user who wants to switch the address flags
could previously do:

  [connection.mptcp]
  connection.mptcp-flags=0x32   # enabled-on-global-iface,signal,subflow

but then the global toggle "/proc/sys/net/mptcp/enabled" was no longer
honored. That means, MPTCP handling was always on, even if the sysctl was
disabled. Now, "enabled" means that it's only enabled if the sysctl
is enabled too. Now the user could write to "NetworkManager.conf"

  [connection.mptcp]
  connection.mptcp-flags=0x32   # enabled,signal,subflow

and MPTCP handling would still be disabled unless the sysctl
is enabled.

There is now also a new flag "also-without-sysctl", so if you want
to really enable MPTCP handling regardless of the sysctl, you can.
The point of that might be, that we still can configure endpoints,
even if kernel won't do anything with them. Then you could just flip
the sysctl, and it would start working (as NetworkManager configured
the endpoints already).

Fixes: eb083eece5 ('all: add NMMptcpFlags and connection.mptcp-flags property')
2022-08-25 21:31:45 +02:00
Thomas Haller
04a97e4e85 std-aux: workaround maybe uninitialized warning with LTO on nm_ip_addr_is_null()
LTO without assertion enabled, thinks that certain code paths
result in uninitialized code. Technically, it's not wrong, in practice
those are only in cases where we already failed an assertion.

  In function 'nm_ip_addr_is_null',
      inlined from 'canonicalize_ip_binary' at src/libnm-core-impl/nm-setting-ip-config.c:67:21,
      inlined from 'nm_ip_route_set_next_hop_binary' at src/libnm-core-impl/nm-setting-ip-config.c:1062:23:
  ./src/libnm-glib-aux/nm-inet-utils.h:80:12: error: 'a' may be used uninitialized [-Werror=maybe-uninitialized]
     80 |     return IN6_IS_ADDR_UNSPECIFIED(&a.addr6);
        |            ^
  src/libnm-core-impl/nm-setting-ip-config.c: In function 'nm_ip_route_set_next_hop_binary':
  ./src/libnm-glib-aux/nm-inet-utils.h:73:14: note: 'a' declared here
     73 |     NMIPAddr a;
        |              ^

Try to workaround that by letting nm_utils_addr_family_to_size() always
return a non-zero size. This is ugly, because in the assertion case fail
we might now also get an additional memory corruption that could have
been avoided by returning zero. However, it probably doesn't matter, because
in this scenario we are already in a bad situation.

Fixes: b02aeaf2f3 ('glib-aux: fix various nm_ip_addr_*() functions for unaligned addresses')
2022-08-25 21:15:38 +02:00
Thomas Haller
97a2a566b4 glib-aux/trivial: rename function for consistency 2022-08-25 19:23:41 +02:00
Thomas Haller
d0e58f1aeb all: merge branch 'th/inet-utils'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1342
2022-08-25 19:06:22 +02:00
Thomas Haller
0e3ab2782a glib-aux: simplify nm_inet_parse_str() by using nm_inet_parse_bin() 2022-08-25 19:05:57 +02:00
Thomas Haller
b02aeaf2f3 glib-aux: fix various nm_ip_addr_*() functions for unaligned addresses
Most of our nm_ip_addr_*() functions take an opaque pointer, that
can be either in_addr_t, struct in6_addr or NMIPAddr.

They also tend to support that their argument pointer is not aligned.
The reason is not very strong, except that usually it's simple to
support and it allows the caller to use those low-level functions for
pointers of unknown alignment (e.g. from a package on the network).

Fix a few cases for that.
2022-08-25 19:05:55 +02:00
Thomas Haller
232df1c08d glib-aux/tests: test nm_ip_addr_is_site_local() 2022-08-25 19:05:53 +02:00
Thomas Haller
08eff4c46e glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
  `nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.

- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
  of our wrapper is chosen to be familiar with the libc underlying
  function. With this, also name functions that are about string
  representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
  `nm_inet6_*()`. For example, `nm_inet_parse_str()`,
  `nm_inet_is_normalized()`.

<<<<

  R() {
     git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
  }

  R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX          NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
  R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX          NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
  R NM_UTILS_INET_ADDRSTRLEN                   NM_INET_ADDRSTRLEN
  R _nm_utils_inet4_ntop                       nm_inet4_ntop
  R _nm_utils_inet6_ntop                       nm_inet6_ntop
  R _nm_utils_ip4_get_default_prefix           nm_ip4_addr_get_default_prefix
  R _nm_utils_ip4_get_default_prefix0          nm_ip4_addr_get_default_prefix0
  R _nm_utils_ip4_netmask_to_prefix            nm_ip4_addr_netmask_to_prefix
  R _nm_utils_ip4_prefix_to_netmask            nm_ip4_addr_netmask_from_prefix
  R nm_utils_inet4_ntop_dup                    nm_inet4_ntop_dup
  R nm_utils_inet6_ntop_dup                    nm_inet6_ntop_dup
  R nm_utils_inet_ntop                         nm_inet_ntop
  R nm_utils_inet_ntop_dup                     nm_inet_ntop_dup
  R nm_utils_ip4_address_clear_host_address    nm_ip4_addr_clear_host_address
  R nm_utils_ip4_address_is_link_local         nm_ip4_addr_is_link_local
  R nm_utils_ip4_address_is_loopback           nm_ip4_addr_is_loopback
  R nm_utils_ip4_address_is_zeronet            nm_ip4_addr_is_zeronet
  R nm_utils_ip4_address_same_prefix           nm_ip4_addr_same_prefix
  R nm_utils_ip4_address_same_prefix_cmp       nm_ip4_addr_same_prefix_cmp
  R nm_utils_ip6_address_clear_host_address    nm_ip6_addr_clear_host_address
  R nm_utils_ip6_address_same_prefix           nm_ip6_addr_same_prefix
  R nm_utils_ip6_address_same_prefix_cmp       nm_ip6_addr_same_prefix_cmp
  R nm_utils_ip6_is_ula                        nm_ip6_addr_is_ula
  R nm_utils_ip_address_same_prefix            nm_ip_addr_same_prefix
  R nm_utils_ip_address_same_prefix_cmp        nm_ip_addr_same_prefix_cmp
  R nm_utils_ip_is_site_local                  nm_ip_addr_is_site_local
  R nm_utils_ipaddr_is_normalized              nm_inet_is_normalized
  R nm_utils_ipaddr_is_valid                   nm_inet_is_valid
  R nm_utils_ipx_address_clear_host_address    nm_ip_addr_clear_host_address
  R nm_utils_parse_inaddr                      nm_inet_parse_str
  R nm_utils_parse_inaddr_bin                  nm_inet_parse_bin
  R nm_utils_parse_inaddr_bin_full             nm_inet_parse_bin_full
  R nm_utils_parse_inaddr_prefix               nm_inet_parse_with_prefix_str
  R nm_utils_parse_inaddr_prefix_bin           nm_inet_parse_with_prefix_bin
  R test_nm_utils_ip6_address_same_prefix      test_nm_ip_addr_same_prefix

  ./contrib/scripts/nm-code-format.sh -F
2022-08-25 19:05:51 +02:00
Thomas Haller
d65feb26e5 glib-aux: move inet related helpers to "nm-inet-utils.h" 2022-08-25 19:05:51 +02:00
Thomas Haller
f23e43b18a glib-aux: add "libnm-glib-aux/nm-inet-utils.h" 2022-08-25 19:05:46 +02:00
Wen Liang
a5d8f8321f dns: merge branch "wl/dns"
https://bugzilla.redhat.com/show_bug.cgi?id=2120763

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1344
2022-08-25 12:46:45 -04:00
Wen Liang
6058445aea dns: kill pending dnsmasq process when mode is not 'dnsmasq'
When NM starts, if `main.dns` is not `dnsmasq`, then the pending dnsmasq
process should be killed by NM.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1344
2022-08-25 12:31:48 -04:00
Wen Liang
9b3a96f821 dnsmasq: silently ignore if pid file is not existed when killing 2022-08-25 10:56:47 -04:00
Thomas Haller
89367de3eb bond: merge branch 'ff/fix_bond_typo'
https://bugs.launchpad.net/network-manager/+bug/1987001
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1072

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1347

(cherry picked from commit 2af8645f71)
2022-08-25 15:40:18 +02:00
Fernando Fernandez Mancera
f693bc6b71 libnm-utils: fix typo in bond ad_select bandwidth mode
The correct spelling is `bandwidth` instead of `bandwith`.

https://bugs.launchpad.net/network-manager/+bug/1987001

Fixes: 32870d8233 ('libnm-utils: convert string bond opts to int')
(cherry picked from commit 5f3237acab)
2022-08-25 15:40:18 +02:00
Fernando Fernandez Mancera
1b704e2f42 bond: fix missing assignment of lp_interval_has
The variable `lp_interval` was being assigned instead of
`lp_interval_has`. The `lp_interval` bond option was not being set
correctly.

https://bugs.launchpad.net/network-manager/+bug/1987001

Fixes: e064eb9d13 ('bond: use netlink to set bond options')
(cherry picked from commit 7d4307e8df)
2022-08-25 15:40:17 +02:00
Thomas Haller
2af8645f71 bond: merge branch 'ff/fix_bond_typo'
https://bugs.launchpad.net/network-manager/+bug/1987001
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1072

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1347
2022-08-25 15:37:59 +02:00
Fernando Fernandez Mancera
5f3237acab libnm-utils: fix typo in bond ad_select bandwidth mode
The correct spelling is `bandwidth` instead of `bandwith`.

https://bugs.launchpad.net/network-manager/+bug/1987001

Fixes: 32870d8233 ('libnm-utils: convert string bond opts to int')
2022-08-25 15:34:30 +02:00