Commit graph

12953 commits

Author SHA1 Message Date
Thomas Haller
c3db3e0044
core: don't do anything if there are no changes in nm_settings_connection_update_timestamp()
Updating the timestamp marks the keyfile database as dirty. Avoid
that, if there is no change. Of course, nm_key_file_db_set_value()
itself already checks whether the are any changes, and does nothing
if there aren't.

Simply perform the check earlier, to do nothing.
2020-06-03 18:25:32 +02:00
Thomas Haller
6f3ae8a563
core: in periodic_update_active_connection_timestamps() use same timestamp
When performing  a synchronous action together (like iterating
over all settings and set the current timestamp), it's nicer
to pretend that all this would happen instantaneously. That means,
ensure we use the same timestamp throughout.

On a minor point, there really is no need to call time() multiple times.
2020-06-03 18:25:11 +02:00
Thomas Haller
968b444603
initrd: drop unused include of platform header 2020-06-03 18:08:37 +02:00
Thomas Haller
1c2d9581e9
initrd: use nm_streq()/NM_IN_STRSET() instead of strcmp()
Code like

»···»···if (strcmp (tag, "net.ifnames") == 0)
»···»···»···net_ifnames = strcmp (argument, "0") != 0;

is really hard to understand (at least to me). Compare to

»···»···if (nm_streq (tag, "net.ifnames"))
»···»···»···net_ifnames = !nm_streq (argument, "0");
2020-06-03 18:00:05 +02:00
Thomas Haller
0b23ae3158
device: reset original autoneg/speed/duplex setting on deactivate
The autoneg/speed ethtool settings are important. If they are wrong,
the device might not get any carrier. Having no carrier means that
you may be unable to activate a profile (because depending on
configuration, carrier is required to activate a profile).

Since activating profiles are the means to configure the link settings
in NetworkManager, and activating a profile can be hampered by wrong link
settings, it's important to reset the "correct" settings, when deactivating
a profile.

"Correct" in this case means to restore the settings that were present
before NM changed the settings. Presumably, these are the right once.

Beyond that, in the future it might make sense to support configuring
the default link settings per device. So that NM will always restore a
defined, configured, working state. The problem is that per-device
settings currently are only available via NetworkManager.conf, which
is rather inflexible.

Also, when you restart NetworkManager service, it leaves the interface
up but forgets the previous setting. That possibly could be fixed by
persisting the previous link state in /run. However, it's not
implemented yet.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/356
https://bugzilla.redhat.com/show_bug.cgi?id=1807171
2020-05-29 12:49:05 +02:00
Thomas Haller
23d0a76b16
device: inline nm_platform_ethtool_init_ring() function
nm_platform_ethtool_init_ring() only has one caller. It's simpler to
drop the function and implement it at the only place where it is needed.

Maybe there could be a place for a function to initialize NMEthtoolRingState,
one option after the other. However, at the moment there is only one
user, so don't implement it.

This fixes various minor issues:

- the function had a NMPlatform argument, although the argument
  is not used. Thus function merely operates on a NMEthtoolRingState
  instance and shouldn't have a nm_platform_*() name.

- nm_platform_ethtool_init_ring() returned a boolean, but all
  code paths (except assertion failures) returned success.

- as the function returned an error status, the caller was compelled
  to handle an error that could never happen.

- the option was specified by name, although we already have a more
  efficient way to express the option: the NMEthtoolID. Also, the
  caller already needed to resolve the name to the NMEthtoolID, so
  there was no need to again lookup the ID by name.
2020-05-29 12:49:04 +02:00
Thomas Haller
9c236416c8
device: only ready existing ethtool ring settings if needed
Imagine you have a veth device. That device supports certain offload features
(like "ethtool.feature-rx-checksum") but doesn't support any ring
options. Even trying to read the current ring settings will fail.

If you try to activate that profile, NMDevice previously would always
try to fetch the ring options and log a warning and extra debugging
messages:

  <trace> [1590511552.3943] ethtool[31]: ETHTOOL_GRINGPARAM, v: failed: Operation not supported
  <trace> [1590511552.3944] ethtool[31]: get-ring: failure getting ring settings
  <warn>  [1590511552.3944] device (v): ethtool: failure getting ring settings (cannot read)

It does so, although you didn't specify any ring settings and there
was no need to fetch the ring settings to begin with.

Avoid this extra logging by only fetching the ring option when they
are actually required.
2020-05-29 12:49:04 +02:00
Beniamino Galvani
49305559dc core: clear IPv6 kernel token when deactivating a device
Clear the IPv6 kernel token when deactivating a device.
2020-05-28 18:38:27 +02:00
Beniamino Galvani
1d6b9953ad device: set accept_ra to 1 when changing IPv6 kernel token
Setting the kernel token is not strictly necessary as the IPv6 address
is generated in userspace by NetworkManager. However it is convenient
for users to see that the value set in the profile is also set in the
kernel, to confirm that everything is working as expected.

The kernel allows setting a token only when 'accept_ra' is 1:
temporarily flip it if necessary. Unfortunately this will also
generate an additional Router Solicitation from kernel, but this is
not a big issue.
2020-05-28 18:38:27 +02:00
Beniamino Galvani
d689380cfc team: support operation without D-Bus
When D-Bus is not available, detect that teamd is ready by watching
the presence of the unix domain socket instead of the D-Bus name.

https://bugzilla.redhat.com/show_bug.cgi?id=1784363
2020-05-28 18:31:38 +02:00
Beniamino Galvani
7ac72f8655 team: ensure that teamd is running for assumed devices
When a team device is assumed, we skip stage1 and imply that teamd is
already running. If this doesn't happen (for example because teamd was
manually stopped or because the interface was created in the initrd),
the team interface will continue processing traffic but will not react
to changes in the environment (e.g. carrier changes). Ensure that
teamd is running for assumed devices.
2020-05-28 18:31:38 +02:00
Thomas Haller
655fd1ebd8
ifcfg-rh: support persisting 802-1x.pin and pin-flags property 2020-05-28 18:05:15 +02:00
Beniamino Galvani
53aa5bd207 platform: add tc tests 2020-05-28 17:25:31 +02:00
Beniamino Galvani
9064502834 platform: rework qdisc synchronization
Rework qdisc synchronization. The previous implementation added all
known qdiscs and removed unneeded ones from platform; this had some
problems:

 - kernel doesn't allow to add (with exclusive flag) a qdisc if one
   with the same parent already exists;

 - if we use the replace flag instead of add, then it becomes possible
   to add a new qdisc with the same parent of an existing one. However
   if the existing qdisc is of the same kind, kernel will try to to
   change() it, which fails for some qdiscs (e.g. sfq).

 - kernel doesn't allow to delete a qdisc with handle of zero because
   that is the default qdisc and can only be replaced;

Fix that.
2020-05-28 17:25:22 +02:00
Beniamino Galvani
9a4578c8f9 platform: use ECHO flag for qdisc and filter requests
By default the kernel sends back events notification to all other
process except the one that requested the change, unless the ECHO flag
is used. See [1], [2].

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/sched/sch_api.c?h=v5.6#n979
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/core/rtnetlink.c?h=v5.6#n706
2020-05-28 17:25:22 +02:00
Beniamino Galvani
3957d40f54 initrd: don't generate new connections for rd.znet
The rd.znet specifies the s390 parameters of an existing
connection. If no matching connection exists, we should not create a
new one.

https://bugzilla.redhat.com/show_bug.cgi?id=1840287
2020-05-28 14:34:44 +02:00
Beniamino Galvani
eff0e0d123
device: add mechanism to call stage1 for external or assumed devices
Usually stage1 is skipped for external or assumed devices. Add a
mechanism to call stage1 for all devices, similarly to what was
already done for stage2.
2020-05-27 15:49:02 +02:00
Thomas Haller
b6b6639c7c
ifcfg-rh: fix handling "802-1x.{phase2-,}ca-path" in ifcfg-rh settings plugin
https://bugzilla.redhat.com/show_bug.cgi?id=1840210
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/448
2020-05-27 10:26:07 +02:00
Thomas Haller
650c550ab5
platform: don't use unsigned constants in _link_type_from_rtnl_type(), _link_type_from_devtype() 2020-05-24 12:16:04 +02:00
Matthias Schiffer
2b54202089
platform: fix crash in binary search for _link_type_from_rtnl_type(), _link_type_from_devtype()
When searching an element that is lower than the first list element (for
example RTNL type "batadv"), imax will be -1 after the last iteration.

Use int instead of unsigned to make the termination condition imin > imax
work in this case. This fixes NetworkManager crashing due to an
out-of-bounds array access whenever interfaces of such types exist.

Fixes: 19ad044359 ('platform: use binary search to lookup NMLinkType for rtnl_type')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/515
2020-05-24 12:15:40 +02:00
Thomas Haller
0533ab3c79
all: avoid (soon to be) deprecated API instead of nm_setting_option*() 2020-05-22 15:58:09 +02:00
Thomas Haller
618ae93b94
libnm: rename nm_setting_gendata_*() API to nm_setting_option_*()
We are going to expose some of this API in libnm.

The name "gendata" (for "generic data") is not very suited. Instead,
call the public API nm_setting_option_*(). This also brings no naming
conflict, because currently no API exists with such naming.

Rename the internal API, so that it matches the API that we are going
to expose next.
2020-05-22 15:58:08 +02:00
Thomas Haller
dcb4ed2cb1
ethtool: add and use _NM_ETHTOOL_ID_FEATURE_AS_IDX() macro 2020-05-22 15:58:08 +02:00
Thomas Haller
1f4b190934
platform: make states of NMEthtoolCoalesceState indexed by ethtool_id
We already have NMEthtoolID to handle coalesce options in a way that is
convenient programmatically. That is, we can iterate over all valid
coalesce options (it's just an integer) and use that in a more generic
way.

If NMEthtoolCoalesceState names all fields explicitly, we need explicit
code that names each coalesce option. Especially since NMEthtoolCoalesceState
is an internal and intermediate data structure, this is cumbersome
and unnecessary.

Thereby it also fixes the issue that nm_platform_ethtool_init_coalesce() has a
NMPlatform argument without actually needing it.
nm_platform_ethtool_init_coalesce() does not operate on a NMPlatform
instance, and should not have the appearance of being a method of
NMPlatform.
2020-05-22 15:58:08 +02:00
Thomas Haller
1f5f840818
device: in _ethtool_coalesce_set() only fetch current coalesce settings if needed
In the common case, the user doesn't set any coalesce options. Avoid always
fetching the current settings, unless they are actually needed.
2020-05-22 15:58:01 +02:00
Thomas Haller
94a603a1bc
platform/trivial: rename NMEthtoolCoalesceState variables to "coalesce"
All other users name a similar variable "coalesce" (or "coalesce_new",
"coalesce_old"). Rename the variables, to don't use different names for
similar uses.
2020-05-22 15:58:01 +02:00
Thomas Haller
adcb935089
ifcfg-rh: avoid setting empty "-C/-K/-G" options for ethtool settings
If no options are set, we should not generate -C/-K/-G options
without parameter.
2020-05-22 15:58:01 +02:00
Antonio Cardace
2ce0e714b6
nm-device: apply ethtool ring settings when activating a connection
nm-device now applies ethtool ring settings during stage 2 "device
config" of the connection activation.

ring settings will be then restored (according to what the state
was before the connection got activated on the device) when the
connection is deactivated during the device cleanup.

One thing to be noted is that unset ring settings (in the profile)
will not be touched at all by NetworkManager so that if the NIC driver
sets some default values these will be preserved unless specifically
overridden by the connection profile.

https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-20 10:55:02 +02:00
Antonio Cardace
2d2c111304
platform: add support for ring settings using ioctl()
https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-20 10:55:02 +02:00
Antonio Cardace
e04e5a5c2a
ifcfg-rh: add support for ethtool ring settings
Also update unit tests.

https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-20 10:55:01 +02:00
Thomas Haller
12063d6cb6
platform: simplify NMEthtoolCoalesceState to only track one state
Only in one moment we need the old and requested settings together:
during _ethtool_coalesce_set(). But for that we shouldn't track both
states in "NMEthtoolCoalesceState".

Simplify "NMEthtoolCoalesceState" to only contain one set of options.
By tracking less state, the code becomes simpler, because you don't
need to wonder where the old and requested state is used.
2020-05-20 10:54:57 +02:00
Beniamino Galvani
02ea74c920 core: signal parent-active only when the parent AC is activated
The parent-active signal is used by the manager to determine when the
parent active-connection is ready and a connection that depend on it
can proceed.

The AC state could transition from ACTIVATING directly to
DEACTIVATING; in such case we should not emit the signal but instead
just stop watching the parent AC.

Fixes: 6e382ea91d ('active-connection: add parent active connection tracking')
https://bugzilla.redhat.com/show_bug.cgi?id=1778073
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/510
2020-05-19 21:40:51 +02:00
Beniamino Galvani
3e2b723532 device: use the nm-shared firewalld zone in shared mode
When the interface is in IPv4 or IPv6 shared mode and the user didn't
specify an explicit zone, use the nm-shared one.

Note that masquerade is still done through iptables direct calls
because at the moment it is not possible for a firewalld zone to do
masquerade based on the input interface.

The firewalld zone is needed on systems where firewalld is using the
nftables backend and the 'iptables' binary uses the iptables API
(instead of the nftables one). On such systems, even if the traffic is
allowed in iptables by our direct rules, it can still be dropped in
nftables by firewalld.
2020-05-15 19:06:24 +02:00
Beniamino Galvani
fa4fbd3333 ip-tunnel: set ip6gretap MAC address when creating the link 2020-05-15 09:48:25 +02:00
Beniamino Galvani
0494a84878 ip-tunnel: set cloned-mac-address only for layer2 tunnel devices
For ip-tunnel modes that encapsulate layer2 packets (gretap and
ip6gretap) we allow the presence of an ethernet setting in the
connection and honor the cloned-mac-address specified in it.

For all other modes, the ethernet setting is removed during
normalization, but a value different from 'preserve' could be set via
global default.

The kernel doesn't allow setting a MAC for layer3 devices, don't do
it.
2020-05-15 09:48:25 +02:00
Thomas Haller
0f22f77b1c
shared: support stripping whitespace from nm_utils_buf_utf8safe_unescape()
When parsing user input if is often convenient to allow stripping whitespace.
Especially with escaped strings, the user could still escape the whitespace,
if the space should be taken literally.

Add support for that to nm_utils_buf_utf8safe_unescape().

Note that this is not the same as calling g_strstrip() before/after
unescape. That is, because nm_utils_buf_utf8safe_unescape() correctly
preserves escaped whitespace. If you call g_strstrip() before/after
the unescape, you don't know whether the whitespace is escaped.
2020-05-13 10:28:04 +02:00
Antonio Cardace
e2be41cbbe
nm-device: apply ethtool coalesce settings when activating a connection
nm-device now applies ethtool coalesce settings during stage 2 "device
config" of the connection activation.

Coalesce settings will be then restored (according to what the state
was before the connection got activated on the device) when the
connection is deactivated during the device cleanup.

One thing to be noted is that unset coalesce settings (in the profile)
will not be touched at all by NetworkManager so that if the NIC driver
sets some default values these will be preserved unless specifically
overridden by the connection profile.

https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-13 10:15:23 +02:00
Antonio Cardace
d8f551cf4a
platform: add support for coalesce settings using ioctl()
https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-13 10:15:23 +02:00
Antonio Cardace
4fce8b3efb
ifcfg-rh: add support for ethtool coalesce settings
Also update unit tests.

https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-13 10:15:23 +02:00
Antonio Cardace
b0240db068
ethtool: add coalesce settings
This is the initial support for coalesce settings and only allows
getting/setting, nothing is yet implemented in nm-device.

Also add unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-13 10:15:23 +02:00
Sven Schwermer
99efe69f68
wwan: Set MTU based on what ModemManager exposes
Signed-off-by: Sven Schwermer <sven.schwermer@disruptive-technologies.com>
2020-05-13 10:07:33 +02:00
Thomas Haller
1c216ca3be
wifi: drop extra conditions in nm_wifi_utils_parse_ies() and use NM_SET_OUT()
NM_SET_OUT() macro already has an "if" condition to only do
anything if the output pointer is not NULL.

As such, we don't need to check first. In practice, this only reorders
the checks, which the compiler may anyway do.

Note that above the checks are still relevant, because we want to
avoid the more expensive parsing, if we don't care about the result.
2020-05-12 14:41:09 +02:00
Thomas Haller
b7a2e73bd2
core: add FIXME(release-blocker) comments for match.kernel-command-line behavior
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/431#note_490830
2020-05-12 09:39:51 +02:00
Thomas Haller
b533bef8cd
ovs: enable trace logging not only with NM_MORE_LOGGING
The logging is useful. Always compile it in.
2020-05-08 14:24:14 +02:00
Thomas Haller
2929392855
all: use "int/char" instead of "gint/gchar" typedefs
This is also recommended by our checkpatch.pl script.
2020-05-08 12:56:29 +02:00
Thomas Haller
6044fce960
bridge: refactor definition of options array to use a macro and C99 designated initializer
Yes, it's a macro and it's more lines of code.

But I think this is much easier to read and to maintain.
2020-05-08 08:02:51 +02:00
Thomas Haller
7c22710c17
libnm: use boolean values for range of NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE in slave_options 2020-05-08 08:02:51 +02:00
Thomas Haller
bfcfdc2955
libnm: adjust bridge defines NM_BRIDGE_VLAN_STATS_ENABLED_DEF 2020-05-08 08:02:51 +02:00
Thomas Haller
f34144f70b
libnm: adjust bridge defines NM_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL_* 2020-05-08 08:02:51 +02:00
Thomas Haller
55311c6a6a
libnm: adjust bridge defines NM_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT_* 2020-05-08 08:02:51 +02:00