summaryrefslogtreecommitdiffstats
path: root/src/libsystemd/sd-netlink/netlink-socket.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* socket-util: make recvmsg_safe() handle MSG_TRUNC tooMike Yuan2024-09-041-8/+10
| | | | Also, unify MSG_TRUNC handling all across the codebase.
* socket-util: introduce netlink_socket_get_multicast_groups()Yu Watanabe2024-08-021-21/+6
| | | | No functional change. Preparation for later commits.
* Use hashmap_ensure_replace()Matteo Croce2024-06-281-7/+1
| | | | | | | Use the new function `hashmap_ensure_replace()` where we're using `hashmap_ensure_allocated()` and `hashmap_ensure_replace()`. Signed-off-by: Matteo Croce <teknoraver@meta.com>
* io-util: split out "struct iovec" related calls into their own .c/.h filesLennart Poettering2023-10-201-1/+1
| | | | | | | | | This is preparation for #28891, which adds a bunch more helpers around "struct iovec", at which point this really deserves its own .c/.h file. The idea is that we sooner or later can consider "struct iovec" as an entirely generic mechanism to reference some binary blob, and is the go-to type for this purpose whenever we need one.
* libsystemd: use _NEG_ macros, adjust some commentsZbigniew Jędrzejewski-Szmek2023-08-161-9/+7
| | | | No functional change.
* sd-netlink: append instead of prepend multipart messageYu Watanabe2022-11-261-9/+14
| | | | | | | | | | | | | | | | | | | | | | | Previously, e.g., networkd enumerated network interfaces with ifindex in a decreasing order, as sd-netlink inverses the order of the received multipart messages. Let's keep the order of the multipart messages. Hopefully this changes no behavior, as our code do not depend on the order of the received multipart messages. Before: === Nov 26 09:35:10 systemd[1]: Starting Network Configuration... Nov 26 09:35:11 systemd-networkd[36185]: wlp59s0: Saved new link: ifindex=3, iftype=ETHER(1), kind=n/a Nov 26 09:35:12 systemd-networkd[36185]: enp0s31f6: Saved new link: ifindex=2, iftype=ETHER(1), kind=n/a Nov 26 09:35:12 systemd-networkd[36185]: lo: Saved new link: ifindex=1, iftype=LOOPBACK(772), kind=n/a After: === Nov 26 09:45:18 systemd[1]: Starting Network Configuration... Nov 26 09:45:19 systemd-networkd[38372]: lo: Saved new link: ifindex=1, iftype=LOOPBACK(772), kind=n/a Nov 26 09:45:19 systemd-networkd[38372]: enp0s31f6: Saved new link: ifindex=2, iftype=ETHER(1), kind=n/a Nov 26 09:45:19 systemd-networkd[38372]: wlp59s0: Saved new link: ifindex=3, iftype=ETHER(1), kind=n/a
* sd-netlink: do not link non-multipart messagesYu Watanabe2022-11-261-33/+35
| | | | | | | | Previously, if a single packet contains multiple non-multipart messages, then the messages were linked and saved as a single entry, especially even if the messages has different serial numbers. Though, not sure if the kernel sends such packet. But at least for safety, let's link only multipart messages.
* sd-netlink: split out parse_message_one() from socket_read_message()Yu Watanabe2022-11-261-39/+60
| | | | | No functional change, just refactoring and preparation for later commits.
* sd-netlink: also manage received messages by serialYu Watanabe2022-11-261-0/+31
| | | | | Then, we can easily find the received message matching with requested serial.
* sd-netlink: reimplement received message queueYu Watanabe2022-11-261-31/+24
| | | | | By using OrderedSet and Hashmap, we can drop all memmove() calls. No functional changes, just refactoring.
* sd-netlink: introduce netlink_queue_received_message() and friendYu Watanabe2022-11-261-14/+41
| | | | No functional change, just refactoring.
* sd-netlink: fix possible use-after-freeYu Watanabe2022-11-261-27/+24
| | | | | | | When we receive a multi-part message and fail to parse it, then the prviously received message is freed with the _cleanup_ attribute, but still referenced by sd_netlink.rqueue_partial. That causes use-after-free when we receive another multi-part message.
* sd-netlink: return earlier when received invalid messageYu Watanabe2022-11-261-2/+7
|
* sd-netlink: allocate read buffer when necessaryYu Watanabe2022-11-261-1/+0
|
* sd-netlink: check received size in socket_recv_message()Yu Watanabe2022-11-261-14/+10
| | | | | No functional change, just refactoring and slightly shorten socket_read_message().
* sd-netlink: drop redundant 'else'Yu Watanabe2022-11-261-4/+2
|
* sd-netlink: always initialize return variable on successYu Watanabe2022-11-261-2/+7
|
* basic: rename util.h to logarithm.hZbigniew Jędrzejewski-Szmek2022-11-081-1/+0
| | | | | util.h is now about logarithms only, so we can rename it. Many files included util.h for no apparent reason… Those includes are dropped.
* sd-netlink: rename NLType and friendsYu Watanabe2022-08-051-1/+1
| | | | | | | | | | | | | | | | | In sd-netlink, we use 'type' for naming many variables with different type, and worst of all, function like `type_get_type()` exists. That makes the code hard to understood. Let's rename - NLType -> NLAPolicy - NLTypeSystem -> NLAPolicySet - NLTypeSystemUnion -> NLAPolicySetUnion - type_get_type() -> policy_get_type() - type_get_type_system() -> policy_get_policy_set(), and so on. This also changes the type of attribute taken by e.g. `sd_netlink_message_append_string()` from `unsigned short` -> `uint16_t` to make the variable size clearer.
* tree-wide: drop unnecessary inclusion of netlink-util.hYu Watanabe2022-07-231-1/+0
|
* libsystemd: export sd-netlinkZbigniew Jędrzejewski-Szmek2022-06-301-36/+0
| | | | | | | | | | | It was added originally in 65f568bbeb9b8c70200e44c19a797df3a0bfd485. The API is has stabilized pretty much, and generally follows the usual style for libsystemd. We've held it as a public-but-private library for almost 10 years, let's export it. sd_netlink_sendv() and sd_nfnl_nft_*() are excluded. libsystemd.so seems to grow by 12k.
* tree-wide: use ERRNO_IS_TRANSIENT()Yu Watanabe2021-11-301-5/+6
|
* tree-wide: use AF_NETLINK instead of PF_NETLINKYu Watanabe2021-10-181-1/+1
|
* sd-netlink: also check multicast group to find suitable match callbackYu Watanabe2021-09-291-2/+1
|
* sd-netlink: minor coding style fixesYu Watanabe2021-09-291-6/+4
|
* sd-netlink: drop sd_genl_family_t and introduce GenericNetlinkFamilyYu Watanabe2021-08-291-3/+3
| | | | | | | | | | | Kernel manages each genl family by its name, e.g. "nlctrl" or WG_GENL_NAME, and its ID (used for nlmsg_type) is determined dynamically when the corresponding module is loaded. This commit makes sd-netlink follow the same way; now, sd_genl_family_t is dropped, and sd_genl_message_new() takes a genl family name. Each genl family is resolved when it is used first time, and its information is stored in GenericNetlinkFamily.
* sd-netlink: rename variables, arguments, and functionsYu Watanabe2021-08-291-30/+30
| | | | Most changes are 'rtnl' -> 'nl' where the function is not only for rtnl.
* sd-netlink: do not trigger assertion by calling ↵Yu Watanabe2021-06-261-2/+2
| | | | | | | | | | | socket_broadcast_group_unref() with an arbitrary group number socket_broadcast_group_unref() is only called in netlink_slot_disconnect(), so the assertion should not be triggered as the match slot was successfully created. But, we usually design `_ref/unref()` functions as they can be called for any inputs. So, let's also follow the design rule here.
* sd-netlink: shorten code a bitYu Watanabe2021-06-261-39/+18
| | | | This also fixes comments, a log message, and coding style nits.
* alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()Lennart Poettering2021-05-191-9/+8
| | | | | | | | | | | | | | | | | | | | | | | | We recently started making more use of malloc_usable_size() and rely on it (see the string_erase() story). Given that we don't really support sytems where malloc_usable_size() cannot be trusted beyond statistics anyway, let's go fully in and rework GREEDY_REALLOC() on top of it: instead of passing around and maintaining the currenly allocated size everywhere, let's just derive it automatically from malloc_usable_size(). I am mostly after this for the simplicity this brings. It also brings minor efficiency improvements I guess, but things become so much nicer to look at if we can avoid these allocation size variables everywhere. Note that the malloc_usable_size() man page says relying on it wasn't "good programming practice", but I think it does this for reasons that don't apply here: the greedy realloc logic specifically doesn't rely on the returned extra size, beyond the fact that it is equal or larger than what was requested. (This commit was supposed to be a quick patch btw, but apparently we use the greedy realloc stuff quite a bit across the codebase, so this ends up touching *a*lot* of code.)
* sd-netlink: shorten things a bitZbigniew Jędrzejewski-Szmek2021-03-091-32/+16
|
* sd-netlink: use setsockopt_int() also for NETLINK_ADD/DROP_MEMBERSHIPZbigniew Jędrzejewski-Szmek2021-03-091-14/+4
| | | | | | We use 'unsigned' as the type, but netlink(7) says the type is 'int'. It doesn't really matter, since they are both the same size. Let's use our helper to shorten the code a bit.
* sd-netlink: add several assertionsYu Watanabe2020-12-181-1/+2
|
* sd-netlink: replace *messages[] -> **messagesYu Watanabe2020-12-181-1/+1
|
* sd-netlink: add sd_netlink_sendvFlorian Westphal2020-12-161-0/+25
| | | | | | | | | | | | | | nftables uses a transaction-based netlink model: one netlink write comes with multiple messages. A 'BEGIN' message to tell nf_tables/kernel that a new transaction starts. Then, one more messages to add/delete tables/chains/rules etc. Lastly, an END message that commits all changes. This function will be used to send all the individual messages that should make up a single transaction as a single write.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* networkd: clean up NETLINK_PKTINFO vs. SO_PASSCRED confusionLennart Poettering2020-05-271-5/+1
| | | | | | | | | We actually care for NETLINK_PKTINFO, not for SO_PASSCRED, hence when allocating the netlink socket, configure things accordingly. Tracked down by Benjamin Robin, see: https://github.com/systemd/systemd/pull/15571#issuecomment-633213747
* netlink: port to recvmsg_safe()Lennart Poettering2020-05-121-19/+20
| | | | | | | | | | | | | | | | | | This also makes sure the control buffer is properly aligned. This matters, as otherwise the control buffer might not be aligned and the cmsg buffer counting might be off. The incorrect alignment is becoming visible by using recvmsg_safe() as we suddenly notice the MSG_CTRUNC bit set because of this. That said, apparently this isn't enough to make this work on all kernels. Since I couldn't figure this out, we now add 1K to the buffer to be sure. We do this once already, also for a pktinfo structure (though an IPv4/IPv6) one. I am puzzled by this, but this shouldn't matter much. it works locally just fine, except for those ubuntu CI kernels... While we are at it, make some other changes too, to simplify and modernize the function.
* netlink socket correct check (#15720)gaurav2020-05-071-1/+1
|
* tree-wide: use cmsg_find() helper at various places where appropriateLennart Poettering2020-04-231-14/+8
|
* tree-wide: drop missing.hYu Watanabe2019-10-311-1/+0
|
* sd-netlink: save dynamic general netlink message typeYu Watanabe2019-10-141-5/+2
|
* sd-netlink: fix inverted log messageYu Watanabe2019-07-041-1/+1
|
* sd-netlink: do not use atomic reference countersZbigniew Jędrzejewski-Szmek2019-03-041-1/+0
| | | | | | Same as with the other users, any non-trivial use of the objects requires use from a single thread only or external locking. Using atomic operations just for reference counts is not useful.
* tree-wide: more IOVEC_MAKE() conversionsLennart Poettering2018-11-281-2/+2
|
* tree-wide: introduce setsockopt_int() helper and make use of it everywhereLennart Poettering2018-10-181-2/+2
| | | | | | As suggested by @heftig: https://github.com/systemd/systemd/commit/6d5e65f6454212cd400d0ebda34978a9f20cc26a#commitcomment-30938667
* tree-wide: add a single version of "static const int one = 1"Lennart Poettering2018-10-151-2/+2
| | | | | | | | | | All over the place we define local variables for the various sockopts that take a bool-like "int" value. Sometimes they are const, sometimes static, sometimes both, sometimes neither. Let's clean this up, introduce a common const variable "const_int_one" (as well as one matching "const_int_zero") and use it everywhere, all acorss the codebase.
* tree-wide: drop copyright headers from frequent contributorsZbigniew Jędrzejewski-Szmek2018-06-201-3/+0
| | | | | | | | Fixes #9320. for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms' done
* tree-wide: beautify remaining copyright statementsLennart Poettering2018-06-141-1/+1
| | | | | | Let's unify an beautify our remaining copyright statements, with a unicode ©. This means our copyright statements are now always formatted the same way. Yay.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.