summaryrefslogtreecommitdiff
path: root/src/basic/socket-util.h
Commit message (Collapse)AuthorAgeFilesLines
* socket-util: introduce CMSG_FIND_AND_COPY_DATA()Yu Watanabe2023-04-161-0/+5
| | | | | | | | | | | | The cmd(3) man page says about CMSG_DATA(): > The pointer returned cannot be assumed to be suitably aligned for > accessing arbitrary payload data types. Applications should not cast > it to a pointer type matching the payload, but should instead use > memcpy(3) to copy data to or from a suitably declared object. Hence, if we want to use unaligned data in cmsg, we need to copy it before use. That's typically important for reading timestamps in RISCV32, as the time_t is 64bit and size_t is 32bit on the system.
* tree-wide: replace __alignof__() with alignof()Yu Watanabe2023-04-141-1/+1
| | | | Addresses https://github.com/systemd/systemd/pull/27254#discussion_r1165267046.
* socket-util: add one missing parenYu Watanabe2023-04-141-1/+1
| | | | Follow-up for b6256af75e0609e451198ed90c293efd50827ab3.
* socket-util: tighten aignment check for CMSG_TYPED_DATA()Lennart Poettering2023-04-131-0/+7
| | | | | | | | | | | | | Apparently CMSG_DATA() alignment is very much undefined. Which is quite an ABI fuck-up, but we need to deal with this. CMSG_TYPED_DATA() already checks alignment of the specified pointer. Let's also check matching alignment of the underlying structures, which we already can do at compile-time. See: #27241 (This does not fix #27241, but should catch such errors already at compile-time instead of runtime)
* socket-util: fix socket_get_family()Lennart Poettering2023-03-101-1/+1
| | | | Function didn't actually return anything useful. Quite a shame.
* src/shared/: split AF_UNIX/AF_VSOCK address parsing into src/basic/Luca Boccassi2023-01-051-0/+6
| | | | | We'll use it from libsystemd0 later, but AF_INET/6 requires some netlink calls and thus the additional library dependency
* socket-util: add CMSG_TYPED_DATA() as type-safe wrapper around CMSG_DATA()Lennart Poettering2022-12-081-6/+8
|
* basic/socket-util: rename fd_inc_rcvbuf → fd_increase_rxbufZbigniew Jędrzejewski-Szmek2022-06-301-1/+1
| | | | See previous commit for justification.
* socket-util: add new connect_unix_path() helperLennart Poettering2022-05-141-0/+2
| | | | | | | | | This is a short helper for connecting to AF_UNIX sockets in the file system. It works around the 108ch limit of sockaddr_un, and supports "at" style fds. This doesn't come with a test of its own, but the next patch will add that.
* socket-util: don't reference field by macro parameter nameLennart Poettering2022-05-091-2/+2
| | | | | Let's avoid ambigituies here. (Interesting that the current users compiled at all, in fact)
* tree-wide: add a space after if, switch, for, and whileYu Watanabe2022-04-011-1/+1
|
* socket-util: add helper for generically initializing sockaddr_union from ↵Lennart Poettering2021-11-221-0/+2
| | | | in_addr_union
* util: define initializer for 'struct ucred' that properly invalidates all fieldsLennart Poettering2021-10-111-0/+3
| | | | | i.e. let's make sure to invalid uid/gid to UID_INVAID + GID_INVALID instead of zero.
* socket-util: const-ify iov parameter in send_one_fd_iov_saLuca Boccassi2021-09-201-1/+1
|
* sysctl-util: make sysctl_write_ip_property() a wrapper around sysctl_write()Lennart Poettering2021-09-151-3/+4
| | | | | | | | It does the same stuff, let's use the same codepaths as much as we can. And while we are at it, let's generate good error codes in case we are called with unsupported parameters/let's validate stuff more that might originate from user input.
* tree-wide: fix typoYu Watanabe2021-09-051-1/+1
|
* socket-util: introduce CMSG_SPACE_TIMEVAL/TIMESPEC macro to support ↵Yu Watanabe2021-08-301-0/+22
| | | | | | additional 64bit timeval or timespec Fixes #20482 and #20564.
* Drop the text argument from assert_not_reached()Zbigniew Jędrzejewski-Szmek2021-08-031-1/+1
| | | | | | | | | | | | | | | | | In general we almost never hit those asserts in production code, so users see them very rarely, if ever. But either way, we just need something that users can pass to the developers. We have quite a few of those asserts, and some have fairly nice messages, but many are like "WTF?" or "???" or "unexpected something". The error that is printed includes the file location, and function name. In almost all functions there's at most one assert, so the function name alone is enough to identify the failure for a developer. So we don't get much extra from the message, and we might just as well drop them. Dropping them makes our code a tiny bit smaller, and most importantly, improves development experience by making it easy to insert such an assert in the code without thinking how to phrase the argument.
* socket-util: split out checking valid character for ifname into ↵Yu Watanabe2021-06-231-0/+1
| | | | ifname_valid_char()
* basic/socket-util: add hint to silence gcc's maybe-unitialized warningZbigniew Jędrzejewski-Szmek2021-03-311-1/+2
| | | | | | | | [59/1551] Compiling C object src/basic/libbasic.a.p/socket-util.c.o ../src/basic/socket-util.c: In function ‘socket_get_mtu’: ../src/basic/socket-util.c:1393:16: warning: ‘mtu’ may be used uninitialized in this function [-Wmaybe-uninitialized] 1393 | *ret = (size_t) mtu; | ^~~~~~~~~~~~
* socket-util: add helper for checking if IPv6 is enabledLennart Poettering2021-03-051-0/+1
|
* socket-util: fix indentationLennart Poettering2021-02-151-3/+3
|
* tree-wide: use -EINVAL for enum invalid valuesZbigniew Jędrzejewski-Szmek2021-02-101-1/+1
| | | | | | | | | As suggested in https://github.com/systemd/systemd/pull/11484#issuecomment-775288617. This does not touch anything exposed in src/systemd. Changing the defines there would be a compatibility break. Note that tests are broken after this commit. They will be fixed in the next one.
* socket-util: add common API for querying socket MTULennart Poettering2020-12-071-0/+2
|
* socket-util: add getsockopt_int() helperLennart Poettering2020-12-071-0/+13
|
* socket-util: add sockopt helper for controlling IP_RECVFRAGSIZELennart Poettering2020-12-071-0/+4
|
* socket-util: make several socket_set_xxx() functions inlineYu Watanabe2020-12-041-5/+17
|
* socket-util: add sockaddr_in_addr() helperLennart Poettering2020-12-021-0/+1
| | | | | This extracts the IP address (as union in_addr_union) from a socket address (i.e. a struct sockaddr).
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* tree-wide: add helper for IPv4/IPv6 sockoptsLennart Poettering2020-09-111-1/+8
| | | | | | | | | | A variety of sockopts exist both for IPv4 and IPv6 but require a different pair of sockopt level/option number. Let's add helpers for these that internally determine the right sockopt to call. This should shorten code that generically wants to support both ipv4 + ipv6 and for the first time adds correct support for some cases where we only called the ipv4 versions, and not the ipv6 options.
* basic: convert ifname_valid_full() to take flags and allow numeric interfacesZbigniew Jędrzejewski-Szmek2020-09-101-2/+7
|
* util: introduce fd_set_{snd,rcv}buf()Yu Watanabe2020-09-091-2/+8
|
* util: introduce SOCKADDR_LEN() macroYu Watanabe2020-09-041-0/+29
|
* socket-util: add generic socket_pass_pktinfo() helperLennart Poettering2020-05-271-0/+2
| | | | | The helper turns on the protocol specific "packet info" structure cmsg for three relevant protocols we know.
* tree-wide: make sure our control buffers are properly alignedLennart Poettering2020-05-071-0/+11
| | | | | | | | | | | | | We always need to make them unions with a "struct cmsghdr" in them, so that things properly aligned. Otherwise we might end up at an unaligned address and the counting goes all wrong, possibly making the kernel refuse our buffers. Also, let's make sure we initialize the control buffers to zero when sending, but leave them uninitialized when reading. Both the alignment and the initialization thing is mentioned in the cmsg(3) man page.
* socket-util: introduce type-safe, dereferencing wrapper CMSG_FIND_DATA ↵Lennart Poettering2020-04-231-0/+8
| | | | | | | around cmsg_find() let's take this once step further, and add type-safety to cmsg_find(), and imply the CMSG_DATA() macro for finding the cmsg payload.
* socket-util: add recvmsg_safe() wrapper that handles MSG_CTRUNCLennart Poettering2020-04-231-0/+2
|
* util-lib: move things that parse ifnames to shared/Zbigniew Jędrzejewski-Szmek2020-01-111-10/+4
| | | | | | | | | In subsequent commits, calls to if_nametoindex() will be replaced by a wrapper that falls back to alternative name resolution over netlink. netlink support requires libsystemd (for sd-netlink), and we don't want to add any functions that require netlink in basic/. So stuff that calls if_nametoindex() for user supplied interface names, and everything that depends on that, needs to be moved.
* util: introduce ifname_valid_full()Yu Watanabe2019-12-161-1/+4
|
* tree-wide: drop netinet/ether.h from socket-util.h and sd-netlink.hYu Watanabe2019-07-241-1/+1
|
* socket-util.h: include string.hChen Qi2019-05-171-0/+1
| | | | | Fix the following compile error: src/basic/socket-util.h:187:30: error: implicit declaration of function 'strnlen'; did you mean 'strlen'? [-Werror=implicit-function-declaration]
* socket-util: add wrappers for binding socket to ifindex/ifnameLennart Poettering2019-03-181-0/+3
| | | | | | | | | | | socket_bind_to_ifindex() uses the the SO_BINDTOIFINDEX sockopt of kernel 5.0, with a fallback to SO_BINDTODEVICE on older kernels. socket_bind_to_ifname() is a trivial wrapper around SO_BINDTODEVICE, the only benefit of using it instead of SO_BINDTODEVICE directly is that it determines the size of the interface name properly so that it also works for unbinding. Moreover, it's an attempt to unify our invocations of the sockopt with a size of strlen(ifname) rather than strlen(ifname)+1...
* util: drop missing.h from socket-util.hYu Watanabe2018-12-061-5/+6
|
* basic/socket-util: use c-escaping to print unprintable socket pathsZbigniew Jędrzejewski-Szmek2018-11-301-1/+1
| | | | | | | | | | | | | | | | | We are pretty careful to reject abstract sockets that are too long to fit in the address structure as a NUL-terminated string. And since we parse sockets as strings, it is not possible to embed a NUL in the the address either. But we might receive an external socket (abstract or not), and we want to be able to print its address in all cases. We would call socket_address_verify() and refuse to print various sockets that the kernel considers legit. Let's do the strict verification only in case of socket addresses we parse and open ourselves, and do less strict verification when printing addresses of existing sockets, and use c-escaping to print embedded NULs and such. More tests are added. This should make LGTM happier because on FIXME comment is removed.
* tree-wide: introduce setsockopt_int() helper and make use of it everywhereLennart Poettering2018-10-181-0/+7
| | | | | | As suggested by @heftig: https://github.com/systemd/systemd/commit/6d5e65f6454212cd400d0ebda34978a9f20cc26a#commitcomment-30938667
* socket-util: include trailing NUL byte in SOCKADDR_UN_LEN() count for fs socketsLennart Poettering2018-10-151-1/+1
| | | | This is what unix(7) recommends, hence do so.
* socket-util: add sockaddr_un_set_path() helperLennart Poettering2018-10-151-0/+2
| | | | | | Properly initializing sun_path from foreign data is not easy, given the size constraints, and NUL confusion. Let's add a helper function for this.
* socket-util: add new sockaddr_un_unlink() helperLennart Poettering2018-10-151-1/+6
| | | | | | | | | The helper is supposed to properly handle cases where .sun_path does not contain a NUL byte, and thus copies out the path suffix a NUL as necessary. This also reworks the more specific socket_address_unlink() to be a wrapper around the more generic sockaddr_un_unlink()
* socket-util: Introduce send_one_fd_iov() and receive_one_fd_iov()Filipe Brandenburger2018-08-021-1/+9
| | | | | | | | | | These take a struct iovec to send data together with the passed FD. The receive function returns the FD through an output argument. In case data is received, but no FD is passed, the receive function will set the output argument to -1 explicitly. Update code in dynamic-user to use the new helpers.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-4/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.