summaryrefslogtreecommitdiff
path: root/src/platform/nm-linux-platform.c
Commit message (Collapse)AuthorAgeFilesLines
* all: move "src/" directory to "src/core/"Thomas Haller2021-02-041-9696/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | Currently "src/" mostly contains the source code of the daemon. I say mostly, because that is not true, there are also the device, settings, wwan, ppp plugins, the initrd generator, the pppd and dhcp helper, and probably more. Also we have source code under libnm-core/, libnm/, clients/, and shared/ directories. That is all confusing. We should have one "src" directory, that contains subdirectories. Those subdirectories should contain individual parts (libraries or applications), that possibly have dependencies on other subdirectories. There should be a flat hierarchy of directories under src/, which contains individual modules. As the name "src/" is already taken, that prevents any sensible restructuring of the code. As a first step, move "src/" to "src/core/". This gives space to reorganize the code better by moving individual components into "src/". For inspiration, look at systemd's "src/" directory. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/743
* udev/trivial: rename nm_udev_client_unref() to nm_udev_client_destory()Thomas Haller2021-02-031-1/+1
| | | | | | | | | | | | | | | | | | | | | NMUdevClient does not actually implement ref-counting, because it's not used. Still, the destroy function was named nm_udev_client_unref(), because theoretically then we could later, as the need arises, make the type ref-counted. Then unref function already had the right name. However, NMUdevClient also has a callback function that emits monitor events. Again for simplicity, this callback function cannot be reset, it can only be set once (in the constructor) and can also not be unset nor disabled. When the user of NMUdevClient is done with the instance and calls "unref", then it must be sure that the callback is no longer invoked afterwards. In practice that is already the case, but "unref" makes it sound as if somebody else could also still hold a reference -- in which case the user would have to first unset/disable the callback. Rename the function to "destroy()", so that it's clear that the instance is gone afterwards and that the callback will not be invoked anymore.
* wireguard: fix configuring larger number of allowed-ips on WireGuard linkThomas Haller2021-01-271-1/+1
| | | | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/640 Fixes: a5c894c35f56 ('platform: create wireguard netdev interface')
* platform: move "nm-platform-utils.[hc]" to "shared/nm-platform" libraryThomas Haller2021-01-151-1/+1
| | | | | By now it has no further dependencies on libnm-core or NetworkManager core. Make it part of "shared/nm-platform" library.
* platform: use NMOptionBool instead of NMTernaryThomas Haller2021-01-151-3/+4
| | | | NMTernary is a dependency for libnm-core. Avoid it.
* shared,platform: move "nmp-netns.[hc]" to shared/nm-platformThomas Haller2021-01-151-1/+1
|
* shared,platform: add "shared/nm-platform" libraryThomas Haller2021-01-151-1/+1
| | | | | | | | | | | | | | | | NetworkManager core is huge. We should try to split out parts that are independent. Platform code is already mostly independent. But due to having it under "src/", there is no strict separation/layering which determines the parts that can work independently. So, while the code is mostly independent (in practice), that is not obvious from looking at the source tree. It thus still contributes to cognitive load. Add a shared library "shared/nm-platform", which should have no dependencies on libnm-core or NetworkManager core. In a first step, move the netlink code there. More should follow.
* platform: avoid "-Wmaybe-uninitialized" warning in ip_route_add()Thomas Haller2021-01-081-10/+3
| | | | | | | | | | | | | | | | | When building without "more-asserts" and LTO enabled, we can get a warning about uninitalized "obj" variable: src/platform/nm-linux-platform.c: In function 'ip_route_add': src/platform/nm-platform.c:4761:24: warning: 'MEM[(struct NMPlatformIPRoute *)&obj + 24B].rt_source' may be used uninitialized in this function [-Wmaybe-uninitialized] 4761 | route->rt_source = nmp_utils_ip_config_source_round_trip_rtprot(route->rt_source); | ^ src/platform/nm-platform.h:2139:25: warning: 'BIT_FIELD_REF <MEM[(const struct NMPlatformIPRoute *)&obj + 24B], 8, 72>' may be used uninitialized in this function [-Wmaybe-uninitialized] 2139 | return r->table_any ? 254u /* RT_TABLE_MAIN */ | That is due to the "default" switch case which was unhandled when building without more-asserts". Avoid that by reworking the code.
* all: update deprecated SPDX license identifiersThomas Haller2021-01-051-1/+1
| | | | | | | | | | | | | | | | These SPDX license identifiers are deprecated ([1]). Update them. [1] https://spdx.org/licenses/ sed \ -e '1 s%^/\* SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+ \*/$%/* SPDX-License-Identifier: \1-or-later */%' \ -e '1,2 s%^\(--\|#\|//\) SPDX-License-Identifier: \(GPL-2.0\|LGPL-2.1\)+$%\1 SPDX-License-Identifier: \2-or-later%' \ -i \ $(git grep -l SPDX-License-Identifier -- \ ':(exclude)shared/c-*/' \ ':(exclude)shared/n-*/' \ ':(exclude)shared/systemd/src' \ ':(exclude)src/systemd/src')
* all: adjust imports to fix libc/linux headersThomas Haller2020-12-231-1/+3
| | | | | | | | | | | | | | | | Linux headers and some libc headers have overlapping defines for network types and functions. In the past years, glibc and linux headers were improved to cooperate so you could include either one, in any order. With musl and possibly some older glibc versions that doesn't work so well. Reorder and change includes to make it work better. Yes, this looks pretty random and unmotivated. The includes are changed in order to successfully build on various libc/kernel versions, with the goal of not using #if.
* all: explicit include <linux/if_{ether,infiniband,vlan}.h> as neededThomas Haller2020-12-221-0/+1
| | | | | | | | | | | | | | Currently libnm headers include <linux/if_{ether,infiniband,vlan}.h>. These are public headers, that means we drag in the linux header to all users of <NetworkManager.h>. Often the linux headers work badly together with certain headers from libc. Depending on the libc version, you have to order linux headers in the right order with respect to libc headers. We should do better about libnm headers. As a first step, assume that the linux headers don't get included by libnm, and explicitly include them where they are needed.
* wifi: use NMEtherAddr struct for bssidThomas Haller2020-11-191-5/+5
|
* platform: Drop nm_platform_wifi_get_{bssid,rate,quality}Andrew Zaborowski2020-11-191-24/+0
| | | | | | | | | | | These are unused now so remove them and revert most of e0394689b3463a1c0c7b0f162bb08327fca8e6f4 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.
* platform: Add a wifi_get_station utilityAndrew Zaborowski2020-11-191-0/+12
| | | | | | | | | | 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.
* platform: allow setting the MTU at link creation timeAntonio Cardace2020-11-021-0/+4
| | | | | | | | | | 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>
* platform: use also statvfs() to check for udevdAlfonso Sánchez-Beato2020-10-061-1/+24
| | | | | | | | | | | | 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
* platform: add flags to NMPlatformIP[46]Route to allow overriding the route ↵Thomas Haller2020-09-301-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* all: unify comment style for SPDX-License-Identifier tagThomas Haller2020-09-291-1/+1
| | | | | | | | | | 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')
* format: replace tabs for indentation in code commentsac/clang-formatThomas Haller2020-09-281-277/+277
| | | | | | | | | | | | 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]')
* all: reformat all with new clang-format styleAntonio Cardace2020-09-281-7573/+7729
| | | | | | | | | | | | 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>
* platform: add support for mcast_hash_max netlink attribute for bridgesSayed Shah2020-09-151-0/+4
| | | | | | Adding the mcast_hash_max property. The value must be the power of 2. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/624
* platform: workaround for old kernels that don't support ↵Thomas Haller2020-08-211-1/+11
| | | | | | | | 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.
* platform: use netlink for configuring bridge settingsSayed Shah2020-08-201-26/+37
| | | | | NMDeviceBridge is currently using sysfs. The plan is to use netlink in in the future
* platform: set default values for NMPlatformLnkBridge if unspecified on netlinkThomas Haller2020-08-171-0/+18
| | | | | | | | 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.
* platform: add support for configuring bridge settings via netlink (2)Sayed Shah2020-08-141-4/+48
| | | | | | | NMDeviceBridge is currently using sysfs. The plan is to use netlink in in the future. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/601
* platform: add support for configuring bridge settings via netlinkSayed Shah2020-08-071-0/+55
| | | | | NMDeviceBridge is currently using sysfs. The plan is to use netlink in in the future
* platform: add the NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE status checkLi-Hao Liao (Leon Liao)2020-08-061-1/+4
| | | | | | | | 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
* platform: do not rely on the presence of sriov_totalvfs sysfs fileBeniamino Galvani2020-07-101-16/+8
| | | | | | 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.
* platform: parse route type from netlink messagesAntonio Cardace2020-07-081-0/+1
| | | | https://bugzilla.redhat.com/show_bug.cgi?id=1821787
* platform: support creation of prio qdiscBeniamino Galvani2020-07-081-0/+4
| | | | | | 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.
* all: fix minor typosYuri Chornoivan2020-07-071-8/+8
| | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/565
* all: fix typo in man pagesSayed Shah2020-07-031-1/+1
| | | | | | | | 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
* platform: add support for local routesAntonio Cardace2020-06-161-4/+6
| | | | | | | Also update unit tests. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/407 https://bugzilla.redhat.com/show_bug.cgi?id=1821787
* platform: rework nm_platform_link_get_udi()Beniamino Galvani2020-06-121-14/+0
| | | | | Implement the function directly in nm-platform.c without virtual functions.
* tc: add support for tbf qdiscBeniamino Galvani2020-06-081-6/+86
| | | | Add support for Token Bucket Filter queueing discipline.
* tc: add support for sfq qdiscBeniamino Galvani2020-06-081-51/+78
| | | | Add support for Stochastic Fairness Queueing queueing discipline.
* platform: use ECHO flag for qdisc and filter requestsBeniamino Galvani2020-05-281-2/+2
| | | | | | | | | 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
* platform: don't use unsigned constants in _link_type_from_rtnl_type(), ↵Thomas Haller2020-05-241-6/+6
| | | | _link_type_from_devtype()
* platform: fix crash in binary search for _link_type_from_rtnl_type(), ↵Matthias Schiffer2020-05-241-6/+6
| | | | | | | | | | | | | | | _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: 19ad044359c4 ('platform: use binary search to lookup NMLinkType for rtnl_type') https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/515
* shared: add nm_utils_invoke_on_timeout()Thomas Haller2020-04-241-4/+4
| | | | | | | | | | | | | | | | | | | | 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 cd5157a0c38adb20eb290a145888703b3d09dd4f)
* all: use nm_clear_pointer() instead of g_clear_pointer()Thomas Haller2020-03-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] https://gitlab.gnome.org/GNOME/glib/-/commit/f9a9902aac826ab4aecc25f6eb533a418a4fa559 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
* platform: use nm_streq() instead of strcmp()Thomas Haller2020-02-211-4/+5
|
* platform: use binary search to lookup NMLinkType for devtypeThomas Haller2020-02-211-8/+70
|
* platform: use binary search to lookup NMLinkType for rtnl_typeThomas Haller2020-02-211-5/+77
|
* platform: index LinkDesc array by NMLinkTypeThomas Haller2020-02-211-63/+62
| | | | | No need to iterate over the whole array, when we can just index it by the link type that we look for.
* shared: drop _STATIC variant of macros that define functionsThomas Haller2020-02-131-2/+4
| | | | | | | | | | | | | | | | | | 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)
* shared/trivial: rename time related functions to use "nsec"/"msec" ↵Thomas Haller2020-02-101-1/+1
| | | | | | | abbreviation instead of "ns"/"ms" The "ns" abbreviation doesn't look too nice. We mostly use "nsec" at other places. Rename.
* platform: use IN6_IS_ADDR_UNSPECIFIED() to check for set IPv6 address in ↵Thomas Haller2020-01-281-6/+6
| | | | _nl_msg_new_link_set_linkinfo()
* platform: track IFA_BROADCAST address in NMPlatformIP4AddressThomas Haller2020-01-141-10/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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`.
* platform: add VRF supportBeniamino Galvani2020-01-141-0/+44
| | | | Add support for creating and parsing VRF links.