Commit graph

140 commits

Author SHA1 Message Date
Johannes Zink
3165d9a2de ethtool: introduce EEE support
Some Applications require to explicitly enable or disable EEE.
Therefore introduce EEE (Energy Efficient Ethernet) support with:

 * ethtool.eee on/off

Unit test case included.

Signed-off-by: Johannes Zink <j.zink@pengutronix.de>
2023-11-03 15:41:21 +00:00
Thomas Haller
86db3df6ac
core: honor ID_NET_MANAGED_BY="org.freedesktop.NetworkManager" to manage device
If ID_NET_MANAGED_BY= attribute is set, we have an indication who is
responsible for the device. If this is set to anything but
"org.freedesktop.NetworkManager", then the device is unmanaged.

The effect is the same as setting NM_UNMANAGED= attribute. NM_UNMANAGED=
takes precedence over this setting.

See-also: https://github.com/systemd/systemd/issues/29768
See-also: https://github.com/systemd/systemd/pull/29782
2023-11-02 10:55:03 +01:00
Thomas Haller
175865c8d3
core: refactor nm_platform_link_get_unmanaged() to return ternary value
It seems easier to understand this way and to implement.

Next, another udev property will be honored. In light of that, the
change makes more sense.
2023-11-02 10:55:02 +01:00
Beniamino Galvani
c3e538e1cd platform: support ethtool channels properties
Support setting the ethtool channels properties in platform via
ETHTOOL_GCHANNELS and ETHTOOL_SCHANNELS ioctls.
2023-10-18 06:53:07 +00:00
Javier Sánchez Parra
b38e8c053b platform: add netlink support for bridge port options
sysfs is deprecated and kernel will not add new bridge port options to
sysfs. Netlink is a stable API and therefore is the right method to
communicate with kernel in order to set the link options.
2023-10-09 12:25:45 +00:00
Emmanuel Grumbach
3476135911 platform: remove CSME related code
Remove all the code that was added for the CSME coexistence.
The Intel WiFi team can't commit on when, if at all, this feature will
be completely integrated and tested in the NetworkManager.
The preferred solution for now is the solution that involves the kernel
only.
Remove the code that was merged so far.
2023-09-25 11:46:24 +00:00
Thomas Haller
5ff1468717
all: ensure signendess for arguments of NM_{MIN,MAX,CLAMP}() macros matches 2023-08-07 09:24:36 +02:00
Thomas Haller
f727c233c4
platform: rename NMP_SYSCTL_PATHID_NETDIR() to have "_A" suffix
The macro uses g_alloca(). Using alloca() is potentially dangerous. For
example, it must never be used in an unbounded loop. This should be
immediately obvious from the name, so we don't accidentally use them
in the wrong context.

All other alloca() macros should have such a prefix already. And they
always have to be macros, because you couldn't use alloca() to return
memory from a function.
2023-06-26 15:15:49 +02:00
Thomas Haller
b8b74f4000
libnm-base: move nmp_utils_new_infiniband_name() to nm_net_devname_infiniband() 2023-05-30 08:52:17 +02:00
Fernando Fernandez Mancera
e200b16291 platform: add support to prio property in bond ports 2023-05-03 10:43:58 +02:00
Fernando Fernandez Mancera
bb435674b5 platform: add netlink support for bond port options
sysfs is deprecated and kernel will not add new bond port options to
sysfs. Netlink is a stable API and therefore is the right method to
communicate with kernel in order to set the link options.
2023-05-03 09:55:45 +02:00
Beniamino Galvani
1399aa925d wifi: skip no-ir channels when determining AP channel
If the automatically selected channel for an AP is set as NO-IR in the
current regulatory domain, the hotspot connection will fail to
start. NO-IR means that any mechanisms that initiate radiation are not
permitted on this channel, this includes sending probe requests or
modes of operation that require beaconing such as AP. Skip channels
with the NO-IR flag.
2023-03-28 09:46:11 +02:00
Corentin Noël
5d28a0dd89
doc: replace all (allow-none) annotations by (optional) and/or (nullable)
The (allow-none) annotation is deprecated since a long time now, it is better to
use (nullable) and/or (optional) which clarifies what it means with the (out)
annotation.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1551
2023-03-27 11:49:43 +02:00
Thomas Haller
1feaf427d2
platform: rework handling of failed routes during nm_platform_ip_route_sync()
Previously, there was "temporary-not-available" mechanism in NML3Cfg,
which aimed to handle IPv6 routes with prefsrc. Theoretically, that
mechanism may have been extended to other use-cases, like IPv4 routes
with prefsrc. What it attempted to handle, is the inability to configure
such routes, unless the respective prefsrc address is configured and
non-tentative.  However, the address that we are waiting for, could also
be on another interface, so that mechanism wasn't applicable. This is
now replaced by _routes_watch_ip_addrs(). It seems there isn't anything
useful left for the "temporary-not-available" mechanism and it can go,
except...

We want to log a warning when we are unable to configure a route. Also,
in the future we might want to know when the IP configuration is
degradated due to inability to configure the desired routes (a condition
that  we might want to expose to the user, not only via logging; or we
may want to react on that).

However, with prefsrc routes we don't know right away whether the
inability to configure the route right away indicates an actual problem,
or whether that will resolve itself (e.g. after the address passes
DAD/ACD, after we received an DHCP lease or after the address was
configured on another interface).  Consequently, to know whether the
current inability to configure such a route is a problem, we need to
know the larger context.  nm_platform_ip_route_sync() does not have that
context.

Instead, nm_platform_ip_route_sync() needs only do debug log about
failure to configure routes. It  will now also  return all the failed
routes to NML3Cfg, which can decide whether that is a problem.

This reworks the previous "temporary-not-available" mechanism to track
the state of the failed routes, to eventually decide whether there is an
actual problem (and log about it).

Another problem this solves is that since commit ('platform: always
reconfigure IP routes even if removed externally'), we will eagerly
re-try to configure the same route over and over. We cannot just spam
the log with warnings about the same failure on every commit. We need to
remember that we already logged about the problem and rate limit
warnings otherwise. This is what the new mechanism also achieves.

Indeed, all this is mostly for the sole benefit of logging better
warnings (and not duplicated).
2023-03-21 15:58:55 +01:00
Thomas Haller
9564fc34fd
platform: log extack_msg for failures in nm_platform_ip_route_sync() 2023-03-21 15:58:52 +01:00
Thomas Haller
89efd94a08
platform: cleanup error handling in nm_platform_ip_route_sync()
Unindent the if-else blocks.
2023-03-21 15:58:50 +01:00
Thomas Haller
7fa63c23b4
platform,l3cfg: remove force-commit flag for addresses/routes
We no longer need this. We now always force-commit routes and addresses.
See the previous commit.
2023-03-21 15:58:43 +01:00
Thomas Haller
6fadba5560
platform: don't add onlink route to gateway in nm_platform_ip_route_sync()
Kernel rejects adding routes that have a gateway, if there is no direct
(onlink) route to that gateway. The exact conditions are non-trivial due
to the complexities of routing, but that's it basically.

Anyway. In NetworkManager we don't want to have such non-obvious
interdependencies. If the user configures a route with a gateway, but
"forgets" to configure a direct route to the gateway, we don't assume
that the user configured the wrong route. Instead, we assume the user
forgot to configure the additional route and add it automatically.  That
is for convenience, but also because (as said) the rules for this are
non-trivial. Moreover, it's problematic to report an error in routing
during activation.  Should we fail activation altogether? Should we just
log an error and otherwise silently proceed? Logging is not a sensible
behavior that the (possibly non-human) user can meaningfully handle. So
we instead try to make it work.

Previously, nm_platform_ip_route_sync() had the workaround of when we
failed to configure a route and it looked like it might be due to the
missing onlink route, we would add a suitable /32 / /128 route. The
problem is that we want that NML3Cfg is aware of what routes we want to
configure. The lower layer nm_platform_ip_route_sync() adding additional
routes makes that difficult (maybe nm_platform_ip_route_sync() could
return the additional routes that it added, but it doesn't).

The better solution seems to be that
nm_l3_config_data_add_dependent_onlink_routes() adds the required routes
in NML3Cfg during commit. This is done since commit 4073211595
('Revert "l3cfg: do not add dependent routes for non-default routes"').

Further, since commit ('platform: always reconfigure IP routes even if
removed externally') we also always try to re-add the routes we want,
regardless of whether they appear to be deleted by the user.

So a suitable onlink route really should be always there, and there is
no more need for this workaround.
2023-03-21 15:58:42 +01:00
Thomas Haller
7d6c1a0f43
platform: fix assertion in _ip_route_add() to return correct error code 2023-03-21 15:58:40 +01:00
Fernando Fernandez Mancera
c6487c240c bonding: add support to ns_ip6_target option
This is the IPv6 equivalent of arp_ip_target option. It requires
arp_interval set and allow the user to specify up to 16 IPv6 addresses
as targets. By default, the list is empty.
2023-03-06 15:06:41 +01:00
Fernando Fernandez Mancera
6cde20fecc bonding: add support to lacp_active option
The valid values for this option are 0 (off) and 1 (on). By default the
value is 1 (on). Please notice that this option is only compatible with
802.3AD mode.
2023-03-06 15:05:46 +01:00
Fernando Fernandez Mancera
ddd2fd46b0 bonding: add support to arp_missed_max option
The new arp_missed_max option valid range is 0-255 where value 0 means
not set. Please notice that this option is not compatible with 802.3AD,
balance-tlb and balance-alb modes.
2023-03-06 15:04:54 +01:00
Fernando Fernandez Mancera
8dd18d91b2 platform: compare arp_ip_targets_num before arp_ip_target values
We must first check whether a->arp_ip_targets_num and
b->arp_ip_targets_num are identical. Otherwise, this accesses
potentially uninitialized values.

Fixes: f900f7bc2c ('platform: add netlink support for bond link')
2023-03-06 14:25:55 +01:00
Beniamino Galvani
e02fd76d9f platform: support changing link properties
Add support in platform for changing the newly introduced link
properties.
2023-03-02 16:51:16 +01:00
Beniamino Galvani
babe2bacd3 platform: rename link_change() to link_change_extra()
There are many functions to replace properties of a link
(link_set_address, link_set_mtu, link_set_name, link_change,
etc.). Eventually, they will be replaced by a function that does
everything and removes all the code duplication.

That function will be named link_change(); rename the current
link_change() to link_change_extra().
2023-03-02 16:51:16 +01:00
Vladislav Tsisyk
6de0bb6a86
bridge: set vlan_filtering and vlan_default_pvid via netlink
This commit changes setting values of said attributes from writing string to
sysfs to sending Netlink message.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1499
2023-03-01 11:39:01 +01:00
Thomas Haller
9bb47d07d9
platform: minor refactoring of temporary-not-available routes
This will be used also for IPv4 addresses. Rename and make the function
more generally useful.
2023-02-28 12:13:45 +01:00
Thomas Haller
eca8ebef18
platform: get extack_msg innm_platform_ip_route_sync()
Request the extack_msg for nm_platform_ip_route_add() call. Note that we (currently)
don't do anything with it, however requesting it has no downsides. That is, the
message already is heap allocated in the lower layers, so this only affects whether
it will be returned up to nm_platform_ip_route_sync().
2023-02-28 12:12:08 +01:00
Thomas Haller
d755b50808
platform: return extack message from add address/route operations 2023-02-28 12:08:07 +01:00
Thomas Haller
4ccca2b5bd
platform,core: better handle onlink flag for ECMP routes
The onlink flag is part of each next hop.

When NetworkManager configures ECMP routes, we won't support that. All
next hops of an ECMP route must share the same onlink flag. That is fine
and fixed by this commit.

What is not fine, is that we don't track the rtnh_flags flags in
NMPlatformIP4RtNextHop, and consequently our nmp_object_id_cmp() is
wrong.

Fixes: 5b5ce42682 ('nm-netns: track ECMP routes')
(cherry picked from commit 6ed966258c)
2023-02-07 14:26:45 +01:00
Thomas Haller
5579fca916
platform: allow setting multi_idx instance for NMPlatform
The major point of NMDedupMultiIndex is that it can de-duplicate
the objects. It thus makes sense the everybody is using the same
instance. Make the multi-idx instance of NMPlatform configurable.

This is not used outside of unit tests, because the daemon currently
always creates one platform instance and everybody then re-uses the
instance of the platform.

While this is (currently) only used by tests, and that the performance
optimization of de-duplicating is irrelevant for tests, this is still
useful. The test can then check whether two separate NMPlatform objects
shared the same instance and whether it was de-duplicated.
2023-01-19 08:56:21 +01:00
Thomas Haller
0d458dbf07
platform: avoid printing raw pointer values in log 2023-01-19 08:56:21 +01:00
Thomas Haller
3cd02b6ed6
libnm,platform: fix range for "weight" property of next hops for routes
In kernel, the valid range for the weight is 1-256 (on netlink this is
expressed as u8 in rtnh_hops, ranging 0-255).

We need an additional value, to represent

- unset weight, for non-ECMP routes in kernel.

- in libnm API, to express routes that should not be merged as ECMP
  routes (the default).

Extend the type in NMPlatformIP4Route.weight to u16, and fix the code
for the special handling of the numeric range.

Also the libnm API needs to change. Modify the type of the attribute on
D-Bus from "b" to "u", to use a 32 bit integer. We use 32 bit, because
we already have common code to handle 32 bit unsigned integers, despite
only requiring 257 values. It seems better to stick to a few data types
(u32) instead of introducing more, only because the range is limited.

Co-Authored-By: Fernando Fernandez Mancera <ffmancera@riseup.net>

Fixes: 1bbdecf5e1 ('platform: manage ECMP routes')
2023-01-17 14:05:13 +01:00
Beniamino Galvani
b669a3ae46 platform: support VTI6 tunnels 2022-12-21 14:04:44 +01:00
Beniamino Galvani
1cf8df2f35 platform: support VTI tunnels 2022-12-21 14:04:43 +01:00
Beniamino Galvani
cf11884a85 macsec: fix tracking of parent ifindex
For MACsec interfaces, kernel announces the parent ifindex in the
generic IFLA_LINK netlink attribute, which we save in
NMPlatformLink.parent. There is no need to have a dedicate member in
NMPlatformLnkMacsec.

The dedicate member was never set and during a restart of
NetworkManager the parent of the MACsec device could be unset leading
to a failed assertion:

  act_stage2_config: assertion 'parent' failed

Fixes: 85103656e9 ('platform: add support for macsec links')

https://bugzilla.redhat.com/show_bug.cgi?id=2122564
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1481
2022-12-15 16:30:29 +01:00
Beniamino Galvani
bd24e0b274 platform: support VLAN protocol
Add support for the "protocol" attribute of VLAN links.
2022-12-14 11:33:03 +01:00
Wen Liang
e8618f03d7
support loopback interface
Support managing the loopback interface through NM as the users want to
set the proper mtu for loopback interface when forwarding the packets.
Additionally, the IP addresses, DNS, route and routing rules are also
allowed to configure for the loopback connection profiles.

https://bugzilla.redhat.com/show_bug.cgi?id=2060905
2022-11-23 20:51:22 +01:00
Thomas Haller
2afadee27f
platform: workaround build error in nm_platform_ip4_route_hash_update() with old clang
clang-3.4.2-9.el7 does not like nesting NM_MAX() macro inside nm_hash_update_vals() macro.
Workaround by using MAX() instead. NM_MAX() uses an expression statement and NM_UNIQ()
to evaluate the arguments only once. We don't need that here and glib's MAX() suffices.

    CC       src/libnm-platform/src_libnm_platform_libnm_platform_la-nm-platform.lo
  ../src/libnm-platform/nm-platform.c:8247:53: error: in-class initializer for static data member is not a constant expression
                                      (guint8) NM_MAX(obj->weight, 1u));
                                                      ^
  ../src/libnm-std-aux/nm-std-aux.h:399:40: note: expanded from macro 'NM_MAX'
  #define NM_MAX(a, b) __NM_MAX(NM_UNIQ, a, NM_UNIQ, b)
                                         ^
  ../src/libnm-std-aux/nm-std-aux.h:402:39: note: expanded from macro '__NM_MAX'
          typeof(a) NM_UNIQ_T(A, aq) = (a);                                              \
                                        ^
  ../src/libnm-glib-aux/nm-hash-utils.h:124:36: note: expanded from macro 'nm_hash_update_vals'
          NM_HASH_COMBINE_VALS(_val, __VA_ARGS__);      \
                                     ^

Fixes: 8cc41d41fe ('platform: add NM_PLATFORM_IP_ROUTE_CMP_TYPE_ECMP_ID for comparing ECMP base route')
2022-11-23 16:28:34 +01:00
Thomas Haller
48d7d1d78e
platform: drop inline cmp() wrappers around "full" versions
We sometimes have functions foo() and foo_full(), in which case
foo() has fewer arguments and just calls foo_full(). The "full"
function here is the more powerful one, and foo() is implemented
in terms of the former.

nm_platform_ip4_route_cmp_full() and m_platform_ip4_route_cmp() inverted
that pattern. The "_full" there stands for the full comparison, to not
allowing to select the comparison type.

That inconsistency is ugly. Also, these wrappers were used at only few
places. Let's drop them.

While at it, also drop nm_platform_qdisc_cmp() and rename
nm_platform_qdisc_cmp_full(). Here cmp()/cmp_full() followed the common
pattern foo()/foo_full(), but it's still hardly used and unnecessary.
2022-11-21 17:56:48 +01:00
Thomas Haller
8cc41d41fe platform: add NM_PLATFORM_IP_ROUTE_CMP_TYPE_ECMP_ID for comparing ECMP base route 2022-11-21 17:46:34 +01:00
Fernando Fernandez Mancera
151b2bed36 platform: pass extra_hops to ip_route_add function
When adding a new route we need to consider it contains extra nexthops
i.e it is a ECMP route. As we cannot modify the NMPObject once created,
we need to pass the extra nexthops as an argument.

We cannot use the original NMPObject because normalization is happening
during when adding the route.
2022-11-21 11:19:19 +01:00
Fernando Fernandez Mancera
1bbdecf5e1 platform: manage ECMP routes
When reading from netlink an ECMP IPv4 route, we need to parse the
multiple nexthops. In order to do that, we are introducing
NMPlatformIP4RtNextHop struct.

The first nexthop information will be kept at the original
NMPlatformIP4Route and the new property n_nexthops will indicate how
many nexthops we need to consider.
2022-11-21 11:18:03 +01:00
Beniamino Galvani
3f84ee27a0 platform: add mechanism to report removed IPv6 addresses that failed DAD 2022-10-26 08:54:29 +02:00
Fernando Fernandez Mancera
3871c670ab bond: fix arp_all_target option when arp_interval is disabled
The bond option arp_all_target can be set even if arp_interval is
disabled.

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

Fixes: e064eb9d13 ('bond: use netlink to set bond options')
2022-09-27 13:52:22 +02:00
Thomas Haller
dbd2df3d13
all: use nm_hash_vals()/nm_hash_val() where it's shorter 2022-09-23 15:21:09 +02:00
Thomas Haller
c43fe3d33d
platform: move NMPlatformIP[46]Address to "nmp-plobj.c"
Later, we should move all such objects. And we should rename
the API to have a unique prefix, like "NMPPlObjIP[4]Address".

This is just a first step that introduces more inconsistencies than it
solves. It will get better afterwards.
2022-09-23 11:43:36 +02:00
Thomas Haller
dd2e1bc1cd
platform: simplify ifindex-to-string helper
This changes a few places where we might have looked up the ifname in
NMPlatform to only print the ifindex. Since the ifindex is the real identifier,
and the logfile is already full of lines that associate the ifname with the ifindex,
this is fine.
2022-09-23 11:43:33 +02:00
Thomas Haller
c28dd78c05 platform: use signed int for NMPlatformLnkBond.primary
On netlink API, the attribute is indeed u32. However, this is an ifindex
which in most other kernel APIs and in NetworkManager code is a signed
integer. Note that of course kernel would only ever assign numbers that
are valid ifindexes, thus in the suitable range.
2022-09-13 10:31:05 +02:00
Thomas Haller
bd6e60f2dc
platform: simplify nm_platform_ip_route_get_prune_list() to not reuse variables
This optimization seems unnecessary. Just initialize a new route struct
and use it. The advantage is that we can have the variable in the scope
closer to where it's used, and don't need to think about what happens
outside the scope.
2022-09-08 19:43:59 +02:00