Commit graph

660 commits

Author SHA1 Message Date
Andrew Zaborowski
5d4dfcd8d2
platform: Drop nm_platform_wifi_get_{bssid,rate,quality}
These are unused now so remove them and revert most of
e0394689b3 which attempted to fix the same
issue of the platform wifi API not mapping well the nl80211 commands
resulting in redundant netlink commands being used.

In the wext driver there are still three individual getters for the
three values and nm_wifi_utils_get_station() uses either these or the
collective get_station method depending on the driver.
2020-11-19 13:38:07 +01:00
Andrew Zaborowski
e5a2520069
platform: Add a wifi_get_station utility
Merge nm_platform_wifi_get_bssid, nm_platform_wifi_get_quality,
nm_platform_wifi_get_rate into one utility, nm_platform_wifi_get_station
that uses the single NL80211_CMD_GET_STATION command dump when the
nl80211 driver is used.  With wext each function mapped to one ioctl
while with nl80211 all three can be obtained with one netlink command.
The new function should use the minimum number of calls with either
driver.
2020-11-19 13:38:06 +01:00
Antonio Cardace
ba2ee46254
platform: allow setting the MTU at link creation time
Add a parameter to the 'link_add()' virtual function so that
the MTU will be configured (via netlink) by the kernel when
creating the link.

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

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-11-02 17:23:05 +01:00
Thomas Haller
6c9a289451
core: cleanup IPv4/IPv6 checks using NM_IS_IPv4()
- we commonly use "int addr_family" as parameters to functions.
  But then inside the function, we often need to do something for
  IPv4 or IPv6 specifically. Instead of having lots of redundant
  "if (addr_family == AF_INET)" checks, prefer to have a variable
  IS_IPv4 and/or use NM_IS_IPv4() macro.

- don't make the "IS_IPv4" variable a gboolean but an int. gboolean
  is a typedef for int, so it's in practice exactly the same. However,
  we use "IS_IPv4" as index to arrays of length 2, where at position
  "1" we have the value related to IPv4. Using a gboolean to index
  an array is a bit odd. Maybe a "int" is preferable here.
  This is more about doing consistently one or the other. There are
  no strong reasons to prefer gboolean or int.
2020-10-30 16:52:59 +01:00
Thomas Haller
60da4cb494
platform: interpret metric_any for routes to accept offset for default metric
The DHCP client likes to order multiple default routes by adding
them with different, increasing metric.

To support that, let "metric_any" not completely disable the "metric"
field, but instead interpret it as an offset that should be added to
the default metric.
2020-10-23 17:11:55 +02:00
Thomas Haller
e155e4a153
platform: add NMPlatformIP4Address.ip4acd_not_ready flag
It is not yet used, but it will be used to mark instances that
are not supposed to be configured in platform, because ACD is
either still pending of failed.
2020-10-13 13:39:01 +02:00
Thomas Haller
422294974c
platform: fix handlng of NMPlatformIP4Address.use_ip4_broadcast_address to be considered for hash/cmp functions
This is an important field. The hash/cmp function cannot just honor
nm_platform_ip4_broadcast_address_from_addr().
2020-10-13 13:39:01 +02:00
Thomas Haller
28bbe2a798
shared,platform: take pointer to NMEtherAddr in NM_ETHER_ADDR_FORMAT_VAL() macro
It seems nicer to require a pointer than the plain struct.
2020-10-13 12:56:25 +02:00
Thomas Haller
dc559a9af7
platform/trivial: use in_addr_t type for address in nm_platform_ip4_address_get() 2020-10-01 17:35:14 +02:00
Thomas Haller
02ad6416fd
platform: add flags to NMPlatformIP[46]Route to allow overriding the route table and metric
When we (for example) receive a DHCP lease, we track the routes that
should be configured via NMPlatformIP[46]Route instances. Thus, this
structure does not only track the routes that are configured (and
cached in NMPlatform), but it is also used to track the routes that
we want to configure.

This is also the case with the "rt_source" field, which represents the
NMIPConfigSource enum for routes that we want to configure, but
for routes in the cache it corresponds to rtm_protocol.

Note that NMDhcpClient creates NMIP4Config instances, which tracks the
routes as NMPlatformIP4Route instances. Previously, NMDhcpClient didn't
have any way to leave the table/metric undecided, but this information
isn't part of the DHCP lease tself. Instead, NMDevice knows the table/metric
to use. This has various problems:

  - NMDhcpClient needs to know the table/metric, for no other purpose
    than to set the value when creating the NMIP4Config instance for the
    lease. We first pass the information down, only so that it can be
    returned with the lease information.

  - during reapply or when connectivity check changes, the effectively
    used table/metric can change. Previously, we would have to
    re-generate the NMIP4Config instances.

Improve that by allowing to leave the table/metric undecided. Higher
layers can decide the effective metric to use.
2020-09-30 09:49:21 +02:00
Thomas Haller
88071abb43
all: unify comment style for SPDX-License-Identifier tag
Our coding style recommends C style comments (/* */) instead of C++
(//). Also, systemd (which we partly fork) uses C style comments for
the SPDX-License-Identifier.

Unify the style.

  $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
2020-09-29 16:50:53 +02:00
Thomas Haller
740b092fda
format: replace tabs for indentation in code comments
sed -i \
     -e 's/^'$'\t'' \*/     */g' \
     -e 's/^'$'\t\t'' \*/         */g' \
     -e 's/^'$'\t\t\t'' \*/             */g' \
     -e 's/^'$'\t\t\t\t'' \*/                 */g' \
     -e 's/^'$'\t\t\t\t\t'' \*/                     */g' \
     -e 's/^'$'\t\t\t\t\t\t'' \*/                         */g' \
     -e 's/^'$'\t\t\t\t\t\t\t'' \*/                             */g' \
     $(git ls-files -- '*.[hc]')
2020-09-28 16:07:52 +02:00
Antonio Cardace
328fb90f3e
all: reformat all with new clang-format style
Run:

    ./contrib/scripts/nm-code-format.sh -i
    ./contrib/scripts/nm-code-format.sh -i

Yes, it needs to run twice because the first run doesn't yet produce the
final result.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-28 16:07:51 +02:00
Thomas Haller
62f2c5a879
platform: refactor nm_platform_ip6_address_get() function to accept pointer instead of "struct in6_addr"
While C is fine with accepting structs as function arguments,
we usually don't do that for IPv6 addresses. Accept a pointer
instead.
2020-09-24 09:43:54 +02:00
Thomas Haller
dea59122e7
shared: move nm_utils_hwaddr_ntoa_buf() to shared/ as _nm_utils_hwaddr_ntoa()
The name is better as it mirrors nm_utils_hwaddr_aton(). Also, move
it to shared/ so it can be reused (and inlined).
2020-09-23 13:57:37 +02:00
Thomas Haller
f295e1313a
core: use _nm_utils_inet4_ntop() instead of nm_utils_inet4_ntop()
nm_utils_inet4_ntop() is public API of libnm. Also, it accepts a
%NULL buffer to use a static buffer. That is error prone and we
should not use such convenience behavior for our own code.
2020-09-15 15:08:02 +02:00
Sayed Shah
518187e8db platform: add support for mcast_hash_max netlink attribute for bridges
Adding the mcast_hash_max property. The value must be the power of 2.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/624
2020-09-15 13:41:29 +02:00
Thomas Haller
94fbc7bdba
platform: add nm_platform_ip6_address_match() 2020-09-11 16:18:40 +02:00
Thomas Haller
f81360bbbf
platform: add nm_platform_ip4_address_addr_to_hash() helper
This will only have one particular use, from NNL3Cfg. However, it seems
general enough to place it in "nm-platform.h".
2020-09-03 11:39:39 +02:00
Thomas Haller
80c0de7217
platform: workaround for old kernels that don't support IFLA_BR_VLAN_STATS_ENABLED
The kernel of Ubuntu 16.04 doesn't support IFLA_BR_VLAN_STATS_ENABLED.
If we want to run on such old kernels (which we probably do), we need to
detect that, and act accordingly.
2020-08-21 13:59:50 +02:00
Thomas Haller
9a5e8f1ea6
platform: use defines from libnm-core for setting defaults values for nm_platform_lnk_bridge_default 2020-08-21 13:59:47 +02:00
Thomas Haller
fdef0e8c62
platform: fix default for bridge setting "mcast_snooping"
The value defaults to TRUE. Also, use the #define for it.

Fixes: 58847f85a4 ('platform: use netlink for configuring bridge settings'):
2020-08-21 13:59:40 +02:00
Sayed Shah
58847f85a4 platform: use netlink for configuring bridge settings
NMDeviceBridge is currently using sysfs. The plan is to use netlink in
in the future
2020-08-20 14:03:10 -04:00
Sayed Shah
80c93b0e5e
platform: add support for configuring bridge settings via netlink (2)
NMDeviceBridge is currently using sysfs. The plan is to use netlink in
in the future.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/601
2020-08-14 21:26:10 +02:00
Sayed Shah
adf0420258
platform: add support for configuring bridge settings via netlink
NMDeviceBridge is currently using sysfs. The plan is to use netlink in
in the future
2020-08-07 13:20:54 +02:00
Thomas Haller
6bf5f014c8
shared: change NM_SWAP() macro to take pointer arguments
This makes the macro more function like. Also, taking a pointer
makes it a bit clearer that this possibly changes the value.

Of course, it's not a big difference to before, but this
form seems slightly preferable to me.
2020-08-06 18:12:01 +02:00
Thomas Haller
695ce608ba
l3cfg: add nm_l3_config_data_add_dependent_routes() 2020-07-31 08:53:06 +02:00
Thomas Haller
5ccfa38565
platform: move full-sync parameter away from nm_platform_ip_address_sync()
This parameter really affects whether a candidate in @addresses_prune will be
considered or not. Since we already construct the prune list separately, this
parameter is at the wrong place.

This requires us to re-implement nm_platform_lookup_clone(). While the
function has a predicate callback that we could use for this purpose,
I will later add a separate predicate argument to
nm_platform_ip_address_get_prune_list(). When that happens, it would
be cumbersome to chain the two function pointers. Instead, reimplement
nm_platform_lookup_clone().
2020-07-31 08:53:06 +02:00
Thomas Haller
dadfc3abd5
platform: allow injecting the list of addresses to prune
Follow the pattern of nm_platform_ip_route_sync(), which also accepts
the list of addresses that are potential candidates for removal.

This allows the caller to carefully construct the list of addresses
which are possibly removed, so that sync (possibly) only adds new
addresses.
2020-07-31 08:53:05 +02:00
Thomas Haller
0acb577320
platform: minor cleanup in nm_platform_ip_address_sync()
The known address must not have a zero lifetime,
because we filter those addresses out first.
2020-07-31 08:53:05 +02:00
Thomas Haller
dca62c06fd
platform: merge nm_platform_ip_address_sync() implementations
It is beneficial to have both address families side by side.

A lot of operations are exactly the same, so it's preferable to see
that. Especially in the cases where they differ, it's preferable to see
how they differ (and why).
2020-07-31 08:53:05 +02:00
Thomas Haller
83bc1e8d60
platform: use NM_CMP_*() macros in nm_platform_ip[46]_address_pretty_sort_cmp()
They ensure to consistently return -1, 0, 1. Also, I think they are
easier to understand.

What is in general hard to understand, whether a comparison sorts
ascending or descending. The macros maybe make that easier too, but it's
still confusing. That's why we have a test.
2020-07-24 16:10:04 +02:00
Thomas Haller
d7608f32a6
platform: add nm_platform_ip[46]_address_pretty_sort_cmp()
This is the code from _addresses_sort_cmp() in "nm-ip[46]-config.h"
and will replace it soon.
2020-07-24 16:10:04 +02:00
Antonio Cardace
3e5fc04df3
core: add dependent local routes configured by kernel
Pre-generate routes in the local table that are configured
by kernel when an ip-address is assigned to an interface.

This helps NM taking into account routes that are not to be deleted
when a connection is reapplied (or deactivated) on an interface instead of only
ignoring (when pruning) IPv6 routes having metric 0 and routes belonging
to the local table having 'kernel' as proto.

https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-07-08 18:01:55 +02:00
Thomas Haller
a83622f7d0
platform: skip metric-0 IPv6 routes in nm_platform_ip_route_sync()
@routes are the list of routes we want to configure. This contains
routes from DHCP and manual routes in the profile. It also contains
externally present routes, including the metric=0 routes in the local
table.

Trying to add an IPv6 route with metric zero adds instead a route with
metric 1024.

Usually, we wouldn't do that, because that route was present externally,
so it possibly is still present (in the platform cache) during sync and
we skip the addition. However, there is a race where the external route
might just disappear and we'd add a route with metric 1024.

Avoid that.
2020-07-08 17:18:44 +02:00
Antonio Cardace
9ecc27f6d3
platform: do not prune kernel added routes
IPv6 routes having metric 0 and routes having rt_source == kernel
are entirely managed by kernel, NM should not try to remove them.

https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-07-08 15:10:36 +02:00
Antonio Cardace
d67ad4c86b
platform: always display route type when calling nmp_object_to_string()
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-07-08 15:10:35 +02:00
Thomas Haller
1b408e243d
core: fix treating route metric zero of IPv6 routes special
Userspace cannot add IPv6 routes with metric 0. Trying to do that, will
be coerced by kernel to route metric 1024. For IPv4 this is different,
and metric zero is commonly allowed.

However, kernel itself can add IPv6 routes with metric zero:

  # ip -6 route show table local
  local fe80::2029:c7ff:fec9:698a dev v proto kernel metric 0 pref medium

That means, we must not treat route metric zero special for most cases.
Only, when we want to add routes (based on user configuration), we must
coerce a route metric of zero to 1024.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/563
2020-07-07 16:14:58 +02:00
Yuri Chornoivan
4e33f8cd89
all: fix minor typos
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/565
2020-07-07 11:33:46 +02:00
Antonio Cardace
5d0d13f570
platform: add support for local routes
Also update unit tests.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/407
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-06-16 10:01:22 +02:00
Beniamino Galvani
755e894b91 platform: add nm_platform_link_get_path()
Add a function to obtain the link path as exported by the ID_PATH udev
property.
2020-06-12 16:04:06 +02:00
Beniamino Galvani
3d9e2650c1 platform: rework nm_platform_link_get_unmanaged()
Split out the code to get udev properties. It will be reused in the next
commit.
2020-06-12 16:04:06 +02:00
Beniamino Galvani
2f21a52eeb platform: rework nm_platform_link_get_udi()
Implement the function directly in nm-platform.c without virtual
functions.
2020-06-12 16:04:05 +02:00
Beniamino Galvani
934777120b tc: add support for tbf qdisc
Add support for Token Bucket Filter queueing discipline.
2020-06-08 15:31:42 +02:00
Beniamino Galvani
b22b4f9101 tc: add support for sfq qdisc
Add support for Stochastic Fairness Queueing queueing discipline.
2020-06-08 15:31:42 +02:00
Thomas Haller
7ecc1cfaaf
platform: assert struct alignment of NMPlatformIPRoute/NMPlatformIPAddress type 2020-06-05 15:14:30 +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
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
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