Commit graph

14738 commits

Author SHA1 Message Date
Thomas Haller
94e23ebba5
platform: simplify accessing ethtool_link_settings.link_mode_masks in set_link_settings_new() 2021-09-06 10:07:14 +02:00
Thomas Haller
c3d0249859
linux-headers: update nl802154.h kernel header
Taken from "include/net/nl802154.h", Linux 5.14,
7d2a07b769330c34b4deabeed939325c77a7ec2f, Aug 30, 2021.
2021-09-06 10:00:36 +02:00
Thomas Haller
aadcd0935e
linux-headers: add ethtool.h kernel header
Taken from Linux 5.14, 7d2a07b769330c34b4deabeed939325c77a7ec2f,
Aug 30, 2021.
2021-09-06 10:00:36 +02:00
Thomas Haller
1d019308f4
glib-aux: fix compiler error using thread-local for _nm_utils_to_string_buffer
On CentOS 7, gcc.x86_64 0:4.8.5-44.el7 fails compilation:

  In file included from ./src/libnm-glib-aux/nm-default-glib.h:69:0,
                   from ./src/libnm-glib-aux/nm-default-glib-i18n-lib.h:13,
                   from src/libnm-core-aux-extern/nm-libnm-core-aux.c:6:
  ./src/libnm-glib-aux/nm-shared-utils.h:1051:1: error: '__thread' before 'extern'
   _nm_thread_local extern char _nm_utils_to_string_buffer[2096];
   ^

Fixes: fb94903444 ('glib-aux: mark _nm_utils_to_string_buffer at thread-local')
2021-09-06 09:38:23 +02:00
Thomas Haller
c950517cda
l3cfg/trivial: rename "NM_L3_ACD_DEFEND_TYPE_NONE" to "_NM_L3_ACD_DEFEND_TYPE_NONE"
This value is only used internally. It's not part of the public API of
NML3Cfg, and not a value that users could/should set.
2021-09-01 23:25:45 +02:00
Thomas Haller
0dac741e5a
l3cfg: simplify creating l3cd for NML3IPv4LL 2021-08-31 16:49:58 +02:00
Thomas Haller
149e66305f
l3cfg: various minor cleanup to NML3Cfg/NML3ConfigData 2021-08-31 16:49:47 +02:00
Thomas Haller
5a4124f738
core: refactor nm_utils_ipv6_addr_set_stable_privacy() to not fail
It's great to have functions that cannot fail, because it allows to
skip any error handling.

_set_stable_privacy() as it was could not fail, so the only reason why
nm_utils_ipv6_addr_set_stable_privacy() could fail is because the DAD
counter exhausted.

Also, it will be useful to have a function that does not do the counter
check, where the caller wants to handle that differently.

Rename some functions, and make the core nm_utils_ipv6_addr_set_stable_privacy()
not failable.
2021-08-31 16:49:46 +02:00
Thomas Haller
4b6e119010
all: pass pointer to "struct NMUtilsIPv6IfaceId" to functions instead of struct
While NMUtilsIPv6IfaceId is only 8 bytes large, it seems unidiomatic to
pass the plain struct around.

With a "const NMUtilsIPv6IfaceId *" argument it is more clear what the
meaning of this is.

Change to use pointers.
2021-08-31 16:49:46 +02:00
Thomas Haller
bcd2c99aab
platform: require RTA_PREF support in kernel
The preference for IPv6 routes was added in kernel v4.1,
22 June 2015. It is even in latest RHEL7 kernels.

Drop trying to be compatible with such old kernels.
2021-08-31 16:41:57 +02:00
Thomas Haller
eb1c266280
platform: require extended IFA_FLAGS support in kernel
We use extended IFA_FLAGS for IFA_F_MANAGETEMPADDR (IPv6) and
IFA_F_NOPREFIXROUTE (IPv4 and IPv6).

These flags for IPv4 were added to kernel 3.14, 30 March, 2014.
The flag for IPv4 was added to kernel 4.4, 11 January 2016.
Even latest RHEL-7 kernels have backport for IFA_F_NOPREFIXROUTE
for IPv4 (rh#1221311).

Drop this. The backward compatibility code paths are likely broken
anyway, and add considerable complexity.
2021-08-31 16:41:57 +02:00
Thomas Haller
b2b50eba1b
platform: require IFLA_INET6_ADDR_GEN_MODE support in kernel
This is supported since kernel 3.17, dated 5 October, 2014. Drop the backward
compatibility for that.

It's very hard to sensibly support a mode where we set the interface up,
but prevent kernel from enabling IPv6. We would hack around that by disabling
IPv6 altogether.

But these code paths are not tested and likely make no sense. And it's hard
to implement a sensible behavior in this case anyway.
2021-08-31 16:41:57 +02:00
Thomas Haller
98ed0e9858
platform: rename "user_ipv6ll" API to "inet6_addr_gen_mode"
The term "user_ipv6ll" is confusing and not something somebody familiar
with kernel or `ip -d link` would understand.

Also, it maps a boolean to addr-gen-mode "none" or "eui64", although
there are 2 more address generation modes in kernel.

Don't abstract the underlying API, and name things as they are in
kernel.
2021-08-31 16:41:57 +02:00
Thomas Haller
0d0f532b12
device: setup firewall zone inside stage3_ip_config_start()
nm_device_activate_schedule_stage3_ip_config_start() should only... schedule.
2021-08-31 16:41:57 +02:00
Thomas Haller
ff7231afd5
device/ppp: rework IP config result handling for NMDevicePpp
NMDevice's act_stage3_ip_config_start() has an out parameter,
so that an NMIPConfig object can be returned. That is (luckily)
not used much, and it's fundamentally flawed. We want that
the start method becomes simpler and idempotent. That argument
is problematic there.

Instead, of the result is already ready, postpone the activation
and process the return on an idle handler.

Why not use nm_device_set_dev2_ip_config() to pass the configuration?
Good question, who knows? For now, just mimic the previous behavior.
Usually the IP configuration would be announced late, so we can just
do that artificially by scheduling an idle action.
2021-08-31 16:41:57 +02:00
Thomas Haller
798e56ac44
device/wwan: don't pass device class to nm_modem_stage3_ip4_config_start()
The idea, that callers to nm_modem_stage3_ip4_config_start() pass
a NMDeviceClass, which then might invoke a virtual function on
the class is really bad.

nm_modem_stage3_ip4_config_start() should indicate what the caller
should do.

The main problem is, that act_stage3_ip_config_start() is not supposed
to be called by anybody except NMDevice. It's an internal hook, not for
NMModem's concern.
2021-08-31 16:41:53 +02:00
Thomas Haller
31b74aab34
device: minor cleanup of dispatching function in nm_device_activate_schedule_ip_config_timeout() 2021-08-31 16:40:45 +02:00
Thomas Haller
fb94903444
glib-aux: mark _nm_utils_to_string_buffer at thread-local
We possibly should refactor our code to no use _nm_utils_to_string_buffer,
but instead always provide a suitable (stack allocated?) buffer.

Until that is done, make the buffer thread local so that it avoids
the most obvious problem (of resulting in non-thread-safe code).
2021-08-31 16:40:45 +02:00
Thomas Haller
98e476fe4d
platform: avoid global buffer for nm_platform_link_inet6_addrgenmode2str() 2021-08-31 16:40:29 +02:00
Thomas Haller
cc38b36f8c
platform: add nm_clear_nmp_object_up_cast(), nmp_object_ref_set_up_cast() helpers
It can be convenient to track a NMPObject in form of their down-cast
pointers. When doing that, it's useful to have clear/ref-set helpers
that operate on such pointers and up-cast first.
2021-08-31 16:34:02 +02:00
Thomas Haller
92ba45727b
platform/trivial: code style fix for NMPCacheIdType enum 2021-08-31 16:34:02 +02:00
Thomas Haller
ca2b02bf98
platform: add NM_PLATFORM_IP[46]_ROUTE_INIT() helper macros 2021-08-31 16:34:02 +02:00
Thomas Haller
c39859d240
libnm/tests: replace NM_PRAGMA_WARNING_DISABLE() by _nm_unused 2021-08-31 16:34:02 +02:00
Thomas Haller
5e54cb5845
std-aux: let nm_assert() macros return a TRUE value
For most purposes, this makes no difference. But it allows
to write something like:

  if (   ptr
      && nm_assert(check_ptr(ptr))
      && other_check(ptr))
      ...
2021-08-31 16:34:02 +02:00
Thomas Haller
a8929bbfc3
Revert "build: add way to keep unused symbols when linking NetworkManager"
This approach does not seem to work with clang 3.4 (rhel-7). Instead,
make sure we actually use the symbol in NetworkManager so that it gets
preserved for the OVS device plugin.

This reverts commit 684f2acffe.
2021-08-31 13:31:42 +02:00
Thomas Haller
6bd506dfb8
core: use nm-sudo symbols in NetworkManager binary for plugin
The two nm-sudo helper functions are only used by the OVS device plugin,
but they are part of NetworkManager core binary.

This is done commonly, where the NetworkManager binary has symbols that
are used by the plugins. But in this case, NetworkManager itself doesn't
use the symbols. That will case the linker to drop them.

A previous solution for that was commit 684f2acffe ('build: add way to
keep unused symbols when linking NetworkManager'), but that doesn't seem
to work with clang 3.4 (rhel-7).

Instead, actually use the symbol so that it cannot be dropped.
2021-08-31 13:30:36 +02:00
Thomas Haller
10e0c4261e
format: reformat code with clang-format-12.0.1-1.fc34
The formatting produced by clang-format depends on the version of the
tool. The version that we use is the one of the current Fedora release.

Fedora 34 recently updated clang (and clang-tools-extra) from version
12.0.0 to 12.0.1. This brings some changes.

Update the formatting.
2021-08-30 13:14:00 +02:00
Thomas Haller
01fd4b7d2c
initrd: fix crash parsing plain '=' without key
./src/nm-initrd-generator/nm-initrd-generator  -s -- =

Fixes: ecc074b2f8 ('initrd: add command line parser')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/776
2021-08-30 09:15:19 +02:00
Thomas Haller
553721eed7
initrd/tests: add _parse_no_con() macro 2021-08-30 09:14:34 +02:00
Thomas Haller
eafa88d438
core: fix crash for duplicate seen-bssid
This happens if there are duplicate BSSIDs for a profile in
"/var/lib/NetworkManager/seen-bssid" file.

  #0  c_list_unlink_stale (what=0x555555bc8768) at ./src/c-list/src/c-list.h:160
  #1  _seen_bssid_entry_free (data=0x555555bc8750) at src/core/settings/nm-settings-connection.c:98
  #2  0x00007ffff77e834a in g_hash_table_insert_node
      (hash_table=hash_table@entry=0x555555afa9e0 = {...}, node_index=node_index@entry=6, key_hash=key_hash@entry=967604099, new_key=new_key@entry=0x555555bc8750, new_value=new_value@entry=0x555555bc8750, keep_new_key=keep_new_key@entry=0, reusing_key=0) at ../glib/ghash.c:1352
  #3  0x00007ffff77e88f0 in g_hash_table_insert_internal (keep_new_key=0, value=0x555555bc8750, key=0x555555bc8750, hash_table=0x555555afa9e0 = {...}) at ../glib/ghash.c:1600
  #4  g_hash_table_insert (hash_table=0x555555afa9e0 = {...}, key=key@entry=0x555555bc8750, value=value@entry=0x555555bc8750) at ../glib/ghash.c:1629
  #5  0x000055555586c5e1 in _nm_settings_connection_register_kf_dbs (self=self@entry=0x555555bbf5a0, kf_db_timestamps=<optimized out>, kf_db_seen_bssids=<optimized out>)
      at src/core/settings/nm-settings-connection.c:2382
  #6  0x00005555555b7e19 in _connection_changed_update
      (self=self@entry=0x555555b1d0c0, sett_conn_entry=sett_conn_entry@entry=0x555555b60390, connection=0x555555b953f0, sett_flags=sett_flags@entry=NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, sett_mask=sett_mask@entry=_NM_SETTINGS_CONNECTION_INT_FLAGS_PERSISTENT_MASK, update_reason=update_reason@entry=(NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS | NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET)) at src/core/settings/nm-settings.c:1080
  #7  0x00005555555b8b5a in _connection_changed_process_one
      (self=self@entry=0x555555b1d0c0, sett_conn_entry=0x555555b60390, allow_add_to_no_auto_default=allow_add_to_no_auto_default@entry=0, sett_flags=sett_flags@entry=NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, sett_mask=_NM_SETTINGS_CONNECTION_INT_FLAGS_PERSISTENT_MASK,
      sett_mask@entry=NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, override_sett_flags=override_sett_flags@entry=1, update_reason=(NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS | NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET)) at src/core/settings/nm-settings.c:1304
  #8  0x00005555555b8c5e in _connection_changed_process_all_dirty
      (self=self@entry=0x555555b1d0c0, allow_add_to_no_auto_default=allow_add_to_no_auto_default@entry=0, sett_flags=sett_flags@entry=NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, sett_mask=sett_mask@entry=NM_SETTINGS_CONNECTION_INT_FLAGS_NONE, override_sett_flags=override_sett_flags@entry=1, update_reason=update_reason@entry=(NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS | NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS | NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET)) at src/core/settings/nm-settings.c:1325
  #9  0x00005555555b8d40 in _plugin_connections_reload (self=self@entry=0x555555b1d0c0) at src/core/settings/nm-settings.c:1448
  #10 0x00005555555bddb5 in nm_settings_start (self=0x555555b1d0c0, error=error@entry=0x7fffffffe278) at src/core/settings/nm-settings.c:3892
  #11 0x000055555560013d in nm_manager_start (self=self@entry=0x555555b19060, error=error@entry=0x7fffffffe278) at src/core/nm-manager.c:6961
  #12 0x0000555555594b27 in main (argc=<optimized out>, argv=<optimized out>) at src/core/main.c:496

Fixes: 8278719840 ('settings: limit number of seen-bssids and preserve order')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/787
2021-08-30 08:19:00 +02:00
Thomas Haller
1ff2d13b7d
platform: workaround -Wmaybe-uninitialized with LTO
With LTO builds, it assumes that the assertion-failed code-paths
can be reached, and thus a warning gets emitted:

  In function nmp_cache_lookup,
      inlined from nm_platform_lookup at src/libnm-platform/nm-platform.c:3377:12,
      inlined from nm_platform_lookup_object at ./src/libnm-platform/nmp-object.h:975:12:
  src/libnm-platform/nmp-object.h:742:46: error: lookup.cache_id_type may be used uninitialized [-Werror=maybe-uninitialized]
    742 |     return nmp_cache_lookup_all(cache, lookup->cache_id_type, &lookup->selector_obj);
        |                                              ^
  ./src/libnm-platform/nmp-object.h: In function nm_platform_lookup_object:
  ./src/libnm-platform/nmp-object.h:972:15: note: lookup declared here
    972 |     NMPLookup lookup;
        |               ^
2021-08-27 09:54:20 +02:00
Thomas Haller
80cab06a14
ifcfg-rh/tests: fix unused variable warning in "test-ifcfg-rh.c"
Fixes: 556d76d570 ('ifcfg-rh/tests: refactor and cleanup ifcfg-rh unit tests')
2021-08-26 23:31:14 +02:00
Thomas Haller
556d76d570
ifcfg-rh/tests: refactor and cleanup ifcfg-rh unit tests
"test-ifcfg-rh.c" is huge, with lots of repeated, verbose code.
Refactor the code by using some helper macros so that the line noise
is smaller and we can easier see what is happening.

- use nmtst_connection_assert_setting() instead of
  nm_connection_get_setting*(), followed by an assertion.

- use _nm_connection_new_setting() instead of multiple lines to
  create and add the setting.

- drop all explicit unref/free and use cleanup macro.

- unify some variable names.

- drop some useless comments. In particular, comments were used as
  visual separators because the code is verbose and hard to read. The
  solution to verbose and hard to read is not more code/comments, the
  solution is clearer, conciser code.
2021-08-26 23:05:26 +02:00
Thomas Haller
f30def0e00
tests: add nmtst_connection_assert_setting() helper 2021-08-26 23:05:25 +02:00
Thomas Haller
a30fd66a85
tests: add nmtst_gbytes_from_arr(), nmtst_gbytes_from_str() helpers 2021-08-26 23:05:24 +02:00
Thomas Haller
0d9435d5d9
libnm: add _nm_connection_new_setting() helper 2021-08-26 23:05:22 +02:00
Thomas Haller
bf13ec2df2
libnm: avoid printing NULL string at NMSettingBondPort.verify()
printf() is not guaranteed to properly handle NULL string,
although glibc will print "(null)".

Avoid that by not printing the currently set value. The error
message is anyway already very long.
2021-08-26 23:05:20 +02:00
Thomas Haller
222c070412
libnm,core: drop internal function _nm_connection_get_setting_bond_port()
These type-specific getters are not very useful. _nm_connection_get_setting() is
better because the setting type is a parameter so they can be used more generically.
Have less code and use generic helpers.
2021-08-26 23:05:19 +02:00
Thomas Haller
e3924a3ab6
ifcfg-rh: refactor write_bond_port_setting() and always write queue-id
- the writer/reader should be lossless. There is a difference
  on whether a NMConnection has/hasn't a NMSettingBondPort instance.
  If we thus have a NMSettingBondPort, we must always encode that
  in the ifcfg file, by writing BOND_PORT_QUEUE_ID=0. Otherwise,
  the reader will not create the setting.

- it's really not the task of the writer to validate what it writes.
  All these write_bridge_port_setting() really should not fail. They
  should serialize the setting as good as they can. And if they cannot,
  it's probably a bug in the writer (by not being lossless).
  write_bond_port_setting() did not ever fail. It should not ever fail.
  So don't let the function return a potential failure, and don't
  handle a failure that should never happen.
2021-08-26 23:05:18 +02:00
Thomas Haller
f15498eda3
ifcfg-rh: cleanup make_bond_port_setting()
- use svGetValue() instead of svGetValueStr(). The difference is that
  svGetValueStr() coerces "" to NULL. "" is not a valid value, but we
  want to parse the value and print an warning message about it. Also,
  the presence of the variable determines whether we add the bond-port
  setting or not.

- don't use nm_clear_g_free(). @value_to_free is gs_free, it will be
  cleared automatically.

- use g_object_set() instead of nm_g_object_set_property_uint(). The
  latter is our own implementation that does error checking (e.g., that
  the value is in range (0..2^16-1). But we already ensured that to
  be the case. So just call g_object_set(), it cannot fail and if it
  would, we want the assertion failure that it would cause.

- queue_id should be a "guint". It is always true on Linux/glib that
  sizeof(guint) >= sizeof(guint32), the opposite theoretically might not
  be true.
  But later we use the variable in the variadic function g_object_set(),
  where it should be guint.

- the errno from _nm_utils_ascii_str_to_uint64() isn't very useful for
  logging. It's either ERANGE or EINVAL, and logging the numeric values
  of these error codes isn't gonna help the user. We could stringify
  with nm_strerror_native(errno), but that message is also not very
  useful. Just say that the string is not a number.
2021-08-26 23:05:17 +02:00
Thomas Haller
a15d991d49
core: rename variable in commit_port_options()
Our NMSetting variables are almost always called "s_$SOMETHING".
2021-08-26 23:05:16 +02:00
Thomas Haller
1d920d2634
core: use _nm_connection_ensure_setting() in controller_update_port_connection() 2021-08-26 23:05:15 +02:00
Thomas Haller
1d0e526b03
core: use larger buffer for string in commit_port_options()
Use sizeof(queue_id_str), so we don't rely on _MAX_QUEUE_ID_STR_LEN
being the correct size for the string.

Also, let's create an excessively large buffer. True, the previous size
should have always be enough, so in practice there is no difference.

But what if it were not? Should we try to handle an error? How? Just asserting
or report a failure? But we don't because the error cannot happen, can't
it?
Don't answer any of these questions, but by making the string buffer
larger, it's even less likely that these questions become relevant.
If for some reason nm_device_get_iface() gives a long string, then we
don't care and let kernel reject the invalid interface name.
2021-08-26 23:05:14 +02:00
Thomas Haller
047d2c1d92
all: prefer g_snprintf() over snprintf()
While both functions are basically the same, the majority of the time
we use g_snprintf(). There is no strong reason to prefer one or the
other, but let's keep using one variant.
2021-08-26 23:05:13 +02:00
Thomas Haller
e2bd2f3f91
tui: fix order of includes in "nmt-page-bond-port.c"
Headers should be included in a particular order. See the CONTRIBUTING
file.
2021-08-26 23:05:12 +02:00
Gris Ge
9958510f28
bond: add support of queue_id of bond port
Introduced `NMSettingBondPort` to hold the new setting class with single
property `NM_SETTING_BOND_PORT_QUEUE_ID`.

For dbus interface, please use `bond-port` as setting name and
`queue-id` as property name.

Unit test cases for ifcfg reader and writer included.

Signed-off-by: Gris Ge <fge@redhat.com>

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/952
2021-08-26 23:04:31 +02:00
Thomas Haller
83ee8bd82a
core: sort includes in "src/core/nm-manager.c"
This will be linked by CONTRIBUTING.md file as an example how to do it.
Sorting includes by name is a sensible default-choice, so do it.
2021-08-26 14:43:32 +02:00
Thomas Haller
101a7cb56d
tests: improve documentation how to generate files for "/test-client.py" 2021-08-26 13:47:04 +02:00
Thomas Haller
beeff19f6c
libnm: cleanup nm_utils_check_virtual_device_compatibility() 2021-08-25 08:19:57 +02:00
Christian Glombek
9c2d835e5c
libnm: allow addition of wireless connections to bonds in nm_utils_check_virtual_device_compatibility()
https://gitlab.gnome.org/GNOME/network-manager-applet/-/issues/140

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/969
2021-08-25 08:19:01 +02:00