Commit graph

868 commits

Author SHA1 Message Date
Alfonso Sánchez-Beato
9c8275bedc
platform: use also statvfs() to check for udevd
Check whether or not there is a running udevd by using statvfs() on
"/sys" and use access() as a fallback. This is in line with what is
done by systemd [1] and helps in case NM is not really running in a
container but has been confined by a MAC so it does not have full
access to sysfs (access() returns EACCES).

[1] https://github.com/systemd/systemd/blob/v246/src/basic/stat-util.c#L132

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/639
2020-10-06 19:01:24 +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
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
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
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
Thomas Haller
d2c58bc64d
platform: set default values for NMPlatformLnkBridge if unspecified on netlink
Older kernels may not support or send all bridge options in the netlink
message. In case the parameter is missing, set the default value.

Note that there may be future cases where we need to encode whether
the option is present or not. Currently we don't express that.
2020-08-17 11:07:43 +02: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
Li-Hao Liao (Leon Liao)
3ba31aad58 platform: add the NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE status check
In some cases, the wow is not configured and the
NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE is set.
So, add the NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE status check.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/597
2020-08-06 11:02:54 +02:00
Beniamino Galvani
63a932b851 platform: do not rely on the presence of sriov_totalvfs sysfs file
The file doesn't exist for all interfaces that support SR-IOV. In
particular, netdevsim devices support SR-IOV but don't expose the
file.
2020-07-10 10:19:08 +02:00
Antonio Cardace
04878193f7
platform: parse route type from netlink messages
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-07-08 15:10:36 +02:00
Beniamino Galvani
d0d35aa278 platform: support creation of prio qdisc
Support the creation of parameterless 'prio' qdiscs. The kernel needs
a TCA_OPTIONS attribute initialized with default values. We currently
don't support modifying the qdisc parameters.
2020-07-08 09:43:06 +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
Sayed Shah
7337ab8959
all: fix typo in man pages
There should be a comma after 'Otherwise' and 'Currently'.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/560
2020-07-03 10:48:04 +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
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
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
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
0119fa8c3d shared: add nm_utils_invoke_on_timeout()
Add nm_utils_invoke_on_timeout() beside nm_utils_invoke_on_idle().
They are fundamentally similar, except one schedules an idle handler
and the other a timeout.

Also, use the current g_main_context_get_thread_default() as context
instead of the singleton instance. That is a change in behavior, but
the only caller of nm_utils_invoke_on_idle() is the daemon, which
doesn't use different main contexts. Anyway, to avoid anybody being
tripped up by this also change the order of arguments. It anyway
seems nicer to first pass the cancellable, and the callback and user
data as last arguments. It's more in line with glib's asynchronous
methods.

Also, in the unlikely case that the cancellable is already cancelled
from the start, always schedule an idle action to complete fast.

(cherry picked from commit cd5157a0c3)
2020-04-24 19:36:53 +02:00
Thomas Haller
52dbab7d07 all: use nm_clear_pointer() instead of g_clear_pointer()
g_clear_pointer() would always cast the destroy notify function
pointer to GDestroyNotify. That means, it lost some type safety, like

   GPtrArray *ptr_arr = ...

   g_clear_pointer (&ptr_arr, g_array_unref);

Since glib 2.58 ([1]), g_clear_pointer() is also more type safe. But
this is not used by NetworkManager, because we don't set
GLIB_VERSION_MIN_REQUIRED to 2.58.

[1] f9a9902aac

We have nm_clear_pointer() to avoid this issue for a long time (pre
1.12.0). Possibly we should redefine in our source tree g_clear_pointer()
as nm_clear_pointer(). However, I don't like to patch glib functions
with our own variant. Arguably, we do patch g_clear_error() in
such a manner. But there the point is to make the function inlinable.

Also, nm_clear_pointer() returns a boolean that indicates whether
anything was cleared. That is sometimes useful. I think we should
just consistently use nm_clear_pointer() instead, which does always
the preferable thing.

Replace:

   sed 's/\<g_clear_pointer *(\([^;]*\), *\([a-z_A-Z0-9]\+\) *)/nm_clear_pointer (\1, \2)/g' $(git grep -l g_clear_pointer) -i
2020-03-23 11:22:38 +01:00
Thomas Haller
6dcb4bd308 platform: use nm_streq() instead of strcmp() 2020-02-21 15:31:22 +01:00
Thomas Haller
acb397c995 platform: use binary search to lookup NMLinkType for devtype 2020-02-21 15:31:22 +01:00
Thomas Haller
19ad044359 platform: use binary search to lookup NMLinkType for rtnl_type 2020-02-21 15:31:22 +01:00
Thomas Haller
4f5e3765b0 platform: index LinkDesc array by NMLinkType
No need to iterate over the whole array, when we can just index
it by the link type that we look for.
2020-02-21 15:31:22 +01:00
Thomas Haller
cd31437024 shared: drop _STATIC variant of macros that define functions
Several macros are used to define function. They had a "_STATIC" variant,
to define the function as static.

I think those macros should not try to abstract entirely what they do.
They should not accept the function scope as argument (or have two
variants per scope). This also because it might make sense to add
additional __attribute__(()) to the function. That only works, if
the macro does not pretend to *not* define a plain function.

Instead, embrace what the function does and let the users place the
function scope as they see fit.

This also follows what is already done with

    static NM_CACHED_QUARK_FCN ("autoconnect-root", autoconnect_root_quark)
2020-02-13 17:17:07 +01:00
Thomas Haller
8b63b229dd shared/trivial: rename time related functions to use "nsec"/"msec" abbreviation instead of "ns"/"ms"
The "ns" abbreviation doesn't look too nice. We mostly use "nsec" at other
places. Rename.
2020-02-10 19:11:50 +01:00
Thomas Haller
06d6de95d6 platform: use IN6_IS_ADDR_UNSPECIFIED() to check for set IPv6 address in _nl_msg_new_link_set_linkinfo() 2020-01-28 11:17:41 +01:00
Thomas Haller
71d5550547 platform: track IFA_BROADCAST address in NMPlatformIP4Address
- track the broadcast address in NMPlatformIP4Address. For addresses
  that we receive from kernel and that we cache in NMPlatform, this
  allows us to show the additional information. For example, we
  can see it in debug logging.

- when setting the address, we still mostly generate our default
  broadcast address. This is done in the only relevant caller
  nm_platform_ip4_address_sync(). Basically, we merely moved setting
  the broadcast address to the caller.
  That is, because no callers explicitly set the "use_ip4_broadcast_address"
  flag (yet). However, in the future some caller might want to set an explicit
  broadcast address.

In practice, we currently don't support configuring special broadcast
addresses in NetworkManager. Instead, we always add the default one with
"address|~netmask" (for plen < 31).

Note that a main point of IFA_BROADCAST is to add a broadcast route to
the local table. Also note that kernel anyway will add such a
"address|~netmask" route, that is regardless whether IFA_BROADCAST is
set or not. Hence, setting it or not makes very little difference for
normal broadcast addresses -- because kernel tends to add this route either
way. It would make a difference if NetworkManager configured an unusual
IFA_BROADCAST address or an address for prefixes >= 31 (in which cases
kernel wouldn't add them automatically). But we don't do that at the
moment.

So, while what NM does has little effect in practice, it still seems
more correct to add the broadcast address, only so that you see it in
`ip addr show`.
2020-01-14 16:09:24 +01:00
Beniamino Galvani
7c73c6a038 platform: add VRF support
Add support for creating and parsing VRF links.
2020-01-14 09:49:01 +01:00
Thomas Haller
7848c165a1 platform: don't use GIOChannel to watch plain file descriptor for netlink socket 2020-01-13 15:46:04 +01:00
Thomas Haller
4972ba0957 platform: use NM_MAKE_STRV() in NMLinuxPlatform:constucted() 2020-01-13 15:46:04 +01:00
Thomas Haller
f30ae56608 platform: implement link_macvlan_add via nm_platform_link_add() 2020-01-09 10:42:32 +01:00
Thomas Haller
1ffdca6331 platform: implement link_macsec_add via nm_platform_link_add() 2020-01-09 10:42:32 +01:00
Thomas Haller
14b5627633 platform: implement link_ipip_add via nm_platform_link_add() 2020-01-09 10:42:32 +01:00
Thomas Haller
16fd8ddf95 platform: implement link_ip6gre_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
bfd74974dc platform: implement link_ip6tnl_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
8b417300ca platform: implement link_6lowpan_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
d3963e4ac7 platform: implement link_vxlan_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
62b9d8ee33 platform: implement link_vlan_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
4029f9cd2e platform: implement link_sit_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
385764398e platform: implement link_gre_add via nm_platform_link_add() 2020-01-09 10:42:31 +01:00
Thomas Haller
792118558c platform: add parent argument to nm_platform_link_add()
This is to set the IFLA_LINK parameter.
2020-01-09 10:42:31 +01:00
Thomas Haller
4a743aba65 platform: extend nm_platform_link_add() to accept type specific extra parameter
This will be used to unify all link-add implementation.
2020-01-09 10:42:31 +01:00
Antonio Cardace
fa144b5ae9 platform/linux: add support for /31 prefixes on IPv4 point-to-point links
Previously NetworkManager would wrongly add a broadcast address for the
network prefix that would collide with the IP address of the host on
the other end of the point-to-point link thus exhausting the IP address
space of the /31 network and preventing communication between the two
nodes.

Configuring a /31 address before this commit:
	IP addr -> 10.0.0.0/31, broadcast addr -> 10.0.0.1

If 10.0.0.1 is configured as a broadcast address the communication
with host 10.0.0.1 will not be able to take place.

Configuring a /31 address after this commit:
	IP addr -> 10.0.0.0/31, no broadcast address

Thus 10.0.0.0/31 and 10.0.0.1/31 are able to correctly communicate.

See RFC-3021. https://tools.ietf.org/html/rfc3021

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/295

https://bugzilla.redhat.com/show_bug.cgi?id=1764986
2020-01-07 16:52:18 +01:00