summaryrefslogtreecommitdiff
path: root/src/platform/nm-netlink.h
AgeCommit message (Collapse)AuthorFilesLines
2021-01-15shared,platform: add "shared/nm-platform" libraryThomas Haller1-616/+0
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.
2021-01-05all: update deprecated SPDX license identifiersThomas Haller1-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')
2020-09-29all: unify comment style for SPDX-License-Identifier tagThomas Haller1-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')
2020-09-28format: replace tabs for indentation in code commentsThomas Haller1-6/+6
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-28all: reformat all with new clang-format styleAntonio Cardace1-332/+325
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-04-24platform: simplify static assert in _nl_static_assert_tb()Thomas Haller1-9/+5
2019-10-01all: manually drop code comments with file descriptionThomas Haller1-2/+1
2019-09-10all: SPDX header conversionLubomir Rintel1-14/+1
$ find * -type f |xargs perl contrib/scripts/spdx.pl $ git rm contrib/scripts/spdx.pl
2019-06-11all: drop emacs file variables from source filesThomas Haller1-1/+0
We no longer add these. If you use Emacs, configure it yourself. Also, due to our "smart-tab" usage the editor anyway does a subpar job handling our tabs. However, on the upside every user can choose whatever tab-width he/she prefers. If "smart-tabs" are used properly (like we do), every tab-width will work. No manual changes, just ran commands: F=($(git grep -l -e '-\*-')) sed '1 { /\/\* *-\*- *[mM]ode.*\*\/$/d }' -i "${F[@]}" sed '1,4 { /^\(#\|--\|dnl\) *-\*- [mM]ode/d }' -i "${F[@]}" Check remaining lines with: git grep -e '-\*-' The ultimate purpose of this is to cleanup our files and eventually use SPDX license identifiers. For that, first get rid of the boilerplate lines.
2019-04-18shared: split C-only helper "shared/nm-std-aux" utils out of "shared/nm-utils"Thomas Haller1-1/+1
"shared/nm-utils" contains general purpose utility functions that only depend on glib (and extend glib with some helper functions). We will also add code that does not use glib, hence it would be good if the part of "shared/nm-utils" that does not depend on glib, could be used by these future projects. Also, we use the term "utils" everywhere. While that covers the purpose and content well, having everything called "nm-something-utils" is not great. Instead, call this "nm-std-aux", inspired by "c-util/c-stdaux". (cherry picked from commit b434b9ec0794fc62a2469445d17debf645ba24cc)
2019-02-22platform/netlink: cleanup nlmsg_append() and add nlmsg_append_struct() macroThomas Haller1-1/+7
2019-02-22platform/netlink: add nla_data_as() macroThomas Haller1-0/+14
This macro casts the return pointer and asserts that the netlink attribute is suitably large.
2019-02-22platform/netlink: add nla_get_be64() helperThomas Haller1-0/+8
2019-02-22platform/netlink: require valid nla argument for nla_get_u64()Thomas Haller1-1/+9
nla_get_u64() was unlike all other nla_get_u*() implementations, in that it would allow for a missing/invalid nla argument, and return 0. Don't do this. For one, don't behave different than other getters. Also, there really is no space to report errors. Hence, the caller must make sure that the attribute is present and suitable -- like for other nla_get_*() functions. None of the callers relied on being able to pass NULL attribute. Also, inline the function and use unaligned_read_ne64(). That is our preferred way for reading unaligned data, not memcpy().
2019-02-22platform/netlink: add assertions for nla_get_*() functionsThomas Haller1-8/+28
These are only nm_assert(), meaning on non-DEBUG builds they are not enabled. Callers are supposed to first check that the netlink attribute is suitable. Hence, we just assert.
2019-02-22platform/netlink: cleanup nla_memcpy()Thomas Haller1-1/+18
- use size_t arguments for the memory sizes. While sizes from netlink API currently are int typed and inherrently limited, use the more appropriate data type. - rename the arguments. The "count" is really the size of the destination buffer. - return how many bytes we wanted to write (like g_strlcpy()). That makes more sense than how many bytes we actually wrote because previously, we could not detect truncation. Anyway, none of the callers cared about the return-value either way.
2019-02-22platform/trivial: coding style fixes/whitespaceThomas Haller1-33/+33
2019-02-22platform/netlink: add nla_parse* macros that safely determine the max-typeThomas Haller1-6/+66
The common idiom is to stack allocate the tb array. Hence, the maxtype is redundant. Add macros that autodetect the maxtype based on the C type infomation. Also, there is a static assertion that the size of the policy (if provided) matches.
2019-02-22platform/netlink: fix return value of nla_get_s8()Thomas Haller1-1/+1
2019-02-11all: minor coding style fixes (space before parentheses)Thomas Haller1-4/+4
2019-01-09netlink: add nla_put() helpers to set integersThomas Haller1-0/+18
2019-01-09netlink: don't heap allocate struct ucred during nla_recv()Thomas Haller1-2/+5
Instead, fill a preallocated output buffer provided by the caller.
2018-12-27core: move netlink errors to nm-errno.hThomas Haller1-58/+0
No other changes (yet).
2018-10-10platform/netlink: fix overrun in attribute iteration in nla_ok()Thomas Haller1-1/+1
See-also: https://github.com/thom311/libnl/commit/123dc07bcc3f402a500edf370d2000e171c91b34 See-also: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1045b03e07d85f3545118510a587035536030c1c
2018-09-12platform/netlink: cleanup error number handlingThomas Haller1-16/+32
Rename variables for the error number. Commonly the naming is: - errno: the error number from <errno.h> itself - errsv: a copy of errno - nlerr: a netlink error number - err: an error code, but not a errno/errsv and not a netlink error number. (cherry picked from commit f4de941d98d4329f652d419dc5fd47bc39700f44)
2018-09-07platform/netlink: drop nlmsg_alloc_inherit() functionThomas Haller1-2/+0
It's only used internally, and it seems not very useful to have. As it is confusing to have multiple functions for doing something similar, drop it -- since it's not really used. I also cannot imagine a good use-case for it.
2018-09-07platform/netlink: fix nl_errno() to get absolute error number valueThomas Haller1-1/+1
2018-06-29platform: change temp variable name in NLA_PUT_TYPE()Beniamino Galvani1-2/+2
__tmp clashes with htole16() on s390x. Fixes: 4120ad243198095ad4629982c849802c3a8b5f5c https://github.com/NetworkManager/NetworkManager/pull/151
2018-06-26netlink: add signed 8-bit and 32-bit accessorsLubomir Rintel1-0/+18
2018-06-15platform: add support for wake-on-wlanSimon Fels1-0/+3
Co-authored-by: Alfonso Sanchez-Beato <alfonso.sanchez-beato@canonical.com>
2018-04-18all: replace "it's" with "its" where neededBeniamino Galvani1-1/+1
2018-03-30platform: move genl_ctrl_resolve to nm-netlink.cJavier Arteaga1-15/+17
Move genl_ctrl_resolve out of the wifi code so it can be reused by other interfaces based on genetlink. https://mail.gnome.org/archives/networkmanager-list/2018-March/msg00044.html
2018-03-20core/platform: add support for TUN/TAP netlink support and various cleanupThomas Haller1-0/+9
Kernel recently got support for exposing TUN/TAP information on netlink [1], [2], [3]. Add support for it to the platform cache. The advantage of using netlink is that querying sysctl bypasses the order of events of the netlink socket. It is out of sync and racy. For example, platform cache might still think that a tun device exists, but a subsequent lookup at sysfs might fail because the device was deleted in the meantime. Another point is, that we don't get change notifications via sysctl and that it requires various extra syscalls to read the device information. If the tun information is present on netlink, put it into the cache. This bypasses checking sysctl while we keep looking at sysctl for backward compatibility until we require support from kernel. Notes: - we had two link types NM_LINK_TYPE_TAP and NM_LINK_TYPE_TUN. This deviates from the model of how kernel treats TUN/TAP devices, which makes it more complicated. The link type of a NMPlatformLink instance should match what kernel thinks about the device. Point in case, when parsing RTM_NETLINK messages, we very early need to determine the link type (_linktype_get_type()). However, to determine the type of a TUN/TAP at that point, we need to look into nested netlink attributes which in turn depend on the type (IFLA_INFO_KIND and IFLA_INFO_DATA), or even worse, we would need to look into sysctl for older kernel vesions. Now, the TUN/TAP type is a property of the link type NM_LINK_TYPE_TUN, instead of determining two different link types. - various parts of the API (both kernel's sysctl vs. netlink) and NMDeviceTun vs. NMSettingTun disagree whether the PI is positive (NM_SETTING_TUN_PI, IFLA_TUN_PI, NMPlatformLnkTun.pi) or inverted (NM_DEVICE_TUN_NO_PI, IFF_NO_PI). There is no consistent way, but prefer the positive form for internal API at NMPlatformLnkTun.pi. - previously NMDeviceTun.mode could not change after initializing the object. Allow for that to happen, because forcing some properties that are reported by kernel to not change is wrong, in case they might change. Of course, in practice kernel doesn't allow the device to ever change its type, but the type property of the NMDeviceTun should not make that assumption, because, if it actually changes, what would it mean? - note that as of now, new netlink API is not yet merged to mainline Linus tree. Shortcut _parse_lnk_tun() to not accidentally use unstable API for now. [1] https://bugzilla.redhat.com/show_bug.cgi?id=1277457 [2] https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git/commit/?id=1ec010e705934c8acbe7dbf31afc81e60e3d828b [3] https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=118eda77d6602616bc523a17ee45171e879d1818 https://bugzilla.redhat.com/show_bug.cgi?id=1547213 https://github.com/NetworkManager/NetworkManager/pull/77
2018-03-09platform: print error message from netlink extended ackBeniamino Galvani1-1/+12
From v4.12 the kernel appends some attributes to netlink acks containing a textual description of the error and other fields (see commit [1]). Parse those attributes and print the error message. Examples: platform-linux: netlink: recvmsg: error message from kernel: Network is unreachable (101) "Nexthop has invalid gateway" for request 12 platform-linux: netlink: recvmsg: error message from kernel: Invalid argument (22) "Local address cannot be multicast" for request 21 [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2d4bc93368f5a0ddb57c8c885cdad9c9b7a10ed5
2018-02-21platform: cleanup error handling in event_handler_recvmsgs()Thomas Haller1-8/+3
Now that we cleaned up nl_recv(), we have full control over which error variables are returned when. We no longer need to check "errno" directly, and we no longer need the NLE_USER_* workaround.
2018-02-21netlink: use glib allocator functions for nlmsg_alloc*()Thomas Haller1-2/+2
Glib is not out of memory safe, meaning it always aborts the program when an allocation fails. It is not possible to meaningfully handle out of memory when using glib. Replace all allocation functions for netlink message with their glib counter part and remove the NULL checks.
2018-02-21netlink: simplify netlink callback handlingThomas Haller1-37/+12
With libnl3, each socket has it's own callback structure. One would often take that callback structure, clone it, modify it and invoke a receive operation with it. We don't need this complexity. We got rid of all default handlers, hence, by default all callbacks are unset. The only callbacks that are set, are those that we specify immediately before invoking the receive operation. Just pass the callback structure at that point. Also, no more ref-counting, and cloning of the callback structure. It is so simple, just stack allocate one if you need it.
2018-02-21netlink: drop redundant nl_recvmsgs_report() functionThomas Haller1-3/+1
The only difference between nl_recvmsgs_report() and nl_recvmsgs() is the return value on success. libnl3 couldn't change that for backward compatibility reasons. We can merge them.
2018-02-21netlink: drop unused callback typesThomas Haller1-20/+0
2018-02-21netlink: refactor error numbers from netlinkThomas Haller1-29/+39
Originally, these were error numbers from libnl3. These error numbers are separate from errno, which is unfortunate, because sometimes we care about the native errno returned from kernel. Now, refactor them so that the error numbers are in the shared realm of errno, but failures from kernel or underlying API are still returned via their native errno. - NLE_INVAL doesn't exist anymore. Passing invalid arguments to a function is commonly a bug. g_return_*(NLE_BUG) is the right answer to that. - NLE_NOMEM and NLE_AGAIN is replaced by their errno counterparts. - drop several error numbers. If nobody cares about these numbers, there is no reason to have a specific error number for them. NLE_UNSPEC is sufficient.
2018-02-21netlink: drop libnl3 dependencyThomas Haller1-29/+471
From libnl3, we only used the helper function to parse/generate netlink messages and the socket functions to send/receive messages. We don't need an external dependency to do that, it is simple enough. Drop the libnl3 dependency, and replace all missing code by directly copying it from libnl3 sources. At this point, I mostly tried to import the required bits to make it working with few modifications. Note that this increases the binary size of NetworkManager by 4736 bytes for contrib/rpm build on x86_64. In the future, we can simplify the code further. A few modifications from libnl3 are: - netlink errors NLE_* are now in the domain or regular errno. The distinction of having to bother with two kinds of error number domains was annoying. - parts of the callback handling is copied partially and unused parts are dropped. Especially, the verbose/debug handlers are not used. In following commits, the callback handling will be significantly simplified. - the complex handling of seleting ports was simplified. We now always let kernel choose the right port automatically.
2018-02-21netlink: move nl_nlmsghdr_to_str() to netlink headerThomas Haller1-0/+4
2018-01-15platform: move genl functions to nm-netlink.cThomas Haller1-0/+17
So they can be reused outside of wifi, like for implementing wireguard support.
2018-01-15platform: move netlink functions to nm-netlink.hThomas Haller1-0/+44
2018-01-15platform: add nm-netlink.h for netlink related helper functionsThomas Haller1-0/+24
Especially useful, because we don't link against libnl-genl-3.so but re-implement generic netlink support. Such code should go there so it can be used by various components.