summaryrefslogtreecommitdiffstats
path: root/src/basic/socket-util.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: make use of errno_or_else() everywhereLennart Poettering2019-07-111-1/+1
|
* tree-wide: replace if_indextoname() with format_ifname()Yu Watanabe2019-05-291-2/+2
|
* basic/socket-util: put a limit on the loop to flush connectionsZbigniew Jędrzejewski-Szmek2019-04-231-1/+9
| | | | Follow-up for #12346.
* basic/socket-util: fix typo and reword commentZbigniew Jędrzejewski-Szmek2019-04-231-7/+7
| | | | | Comment bike-shedding might be the ultimate form of procrastination, but I can't stop myself. :)
* socket-util: make sure flush_accept() doesn't hang on unexpected EOPNOTSUPPLennart Poettering2019-04-181-2/+15
| | | | | | | | | | So apparently there are two reasons why accept() can return EOPNOTSUPP: because the socket is not a listening stream socket (or similar), or because the incoming TCP connection for some reason wasn't acceptable to the host. THe latter should be a transient error, as suggested on accept(2). The former however should be considered fatal for flush_accept(). Let's fix this by explicitly checking whether the socket is a listening socket beforehand.
* tree-wide: port users over to use new ERRNO_IS_ACCEPT_AGAIN() callLennart Poettering2019-04-101-6/+7
|
* socket-util: add wrappers for binding socket to ifindex/ifnameLennart Poettering2019-03-181-0/+36
| | | | | | | | | | | 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: split out memcmp()/memset() related calls into memory-util.[ch]Lennart Poettering2019-03-131-1/+1
| | | | Just some source rearranging.
* socket-util: re-implement socket_address_parse_netlink() by using ↵Yu Watanabe2019-02-211-6/+15
| | | | | | | | | extract_first_word() This drops support of trailing white space when a multicast group is specified. Fixes one of issues in #11738.
* socket-util: Let's trick out ubsan when it validate struct ↵Lennart Poettering2018-12-041-4/+9
| | | | | | | | | | | sockaddr_un.sun_path[] Linux is stupid and sometimes returns a "struct sockaddr_un" that is longer than its fields, as it NUL terminates .sun_path[] even if it has full length. ubsan detects this, rightfully. Since this is a Linux misdesign let's trick out ubsan a bit. Fixes: #11024
* socket-util: break lines in sockaddr_pretty() signatureLennart Poettering2018-12-041-1/+7
| | | | It's soo long, let's make this more readable.
* socket-util: shorten code a bitLennart Poettering2018-12-041-8/+4
|
* basic/socket-util: use c-escaping to print unprintable socket pathsZbigniew Jędrzejewski-Szmek2018-11-301-27/+43
| | | | | | | | | | | | | | | | | 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.
* shared/socket-util: do not print empty CIDZbigniew Jędrzejewski-Szmek2018-11-301-6/+6
| | | | That's just ugly.
* tree-wide: use setsockopt_int() moreYu Watanabe2018-10-181-8/+11
|
* socket-util: tighten socket_address_verify() checks a bitLennart Poettering2018-10-151-8/+17
|
* socket-util: tweak commenting in socket_address_get_path()Lennart Poettering2018-10-151-0/+4
| | | | | Let's make clear explicitly that there's always a NUL byte following the path, and how.
* socket-util: add sockaddr_un_set_path() helperLennart Poettering2018-10-151-0/+44
| | | | | | 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-address: document socket address parsing size restrictions in a commentLennart Poettering2018-10-151-2/+8
|
* socket-util: use structured initializationLennart Poettering2018-10-151-2/+3
|
* socket-util: add new sockaddr_un_unlink() helperLennart Poettering2018-10-151-15/+24
| | | | | | | | | 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: attempt SO_RCVBUFFORCE/SO_SNDBUFFORCE only if ↵Franck Bui2018-09-141-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | SO_RCVBUF/SO_SNDBUF fails Both SO_SNDBUFFORCE and SO_RCVBUFFORCE requires capability 'net_admin'. If this capability is not granted to the service the first attempt to increase the recv/snd buffers (via sd_notify()) with SO_RCVBUFFORCE/SO_SNDBUFFORCE will fail, even if the requested size is lower than the limit enforced by the kernel. If apparmor is used, the DENIED logs for net_admin will show up. These log entries are seen as red warning light, because they could indicate that a program has been hacked and tries to compromise the system. It would be nicer if they can be avoided without giving services (relying on sd_notify) net_admin capability or dropping DENIED logs for all such services via their apparmor profile. I'm not sure if sd_notify really needs to forcibly increase the buffer sizes, but at least if the requested size is below the kernel limit, the capability (hence the log entries) should be avoided. Hence let's first ask politely for increasing the buffers and only if it fails then ignore the kernel limit if we have sufficient privileges.
* util: do not use stack frame for parsing arbitrary inputsYu Watanabe2018-08-221-4/+12
| | | | | | | | This replaces strndupa() by strndup() in socket_address_parse(), as input string may be too long. Fixes issue 10007 by ClusterFuzz-External: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10007
* socket-util: Introduce send_one_fd_iov() and receive_one_fd_iov()Filipe Brandenburger2018-08-021-20/+77
| | | | | | | | | | 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: drop MSG_NOSIGNAL flag from recvmsg() invocationsLennart Poettering2018-06-201-1/+1
| | | | | | | | MSG_NOSIGNAL is only defined for sendmsg(), not for recvmsg(), hence let's drop it's use, in particular as it appears to create problems on older kernels. See: https://lists.freedesktop.org/archives/systemd-devel/2018-June/040869.html
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+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.
* 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.
* socket-util: rename parse_socket_address_bind_ipv6_only_or_bool() to ↵Yu Watanabe2018-05-311-1/+1
| | | | | | | socket_address_bind_ipv6_only_or_bool_from_string() Hence, we can define config_parse_socket_bind() by using DEFINE_CONFIG_PARSE_ENUM() macro.
* tree-wide: drop spurious newlines (#8764)Lennart Poettering2018-04-191-2/+0
| | | | | | | | Double newlines (i.e. one empty lines) are great to structure code. But let's avoid triple newlines (i.e. two empty lines), quadruple newlines, quintuple newlines, …, that's just spurious whitespace. It's an easy way to drop 121 lines of code, and keeps the coding style of our sources a bit tigther.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* tree-wide: use TAKE_PTR() and TAKE_FD() macrosYu Watanabe2018-04-051-2/+1
|
* macro: introduce TAKE_PTR() macroLennart Poettering2018-03-221-2/+1
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* Merge pull request #8143 from yuwata/drop-unused-funcYu Watanabe2018-02-101-13/+0
|\ | | | | Drop several unused functions
| * socket-util: drop getnameinfo_pretty()Yu Watanabe2018-02-101-13/+0
| |
* | basic/socket-util: drop use of NI_IDN_USE_STD3_ASCII_RULESZbigniew Jędrzejewski-Szmek2018-02-091-1/+1
|/ | | | | | | The only use of socknameinfo_pretty() is in src/journal-remote/journal-remote.c, to determine the output filename. Replaces #8120.
* socket-util: fix getpeergroups() assert(fd) (#8080)Vito Caputo2018-02-031-1/+1
| | | | | Don't assert on zero-value fds. Fixes #8075.
* log: minimize includes in log.hLennart Poettering2018-01-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | log.h really should only include the bare minimum of other headers, as it is really pulled into pretty much everything else and already in itself one of the most basic pieces of code we have. Let's hence drop inclusion of: 1. sd-id128.h because it's entirely unneeded in current log.h 2. errno.h, dito. 3. sys/signalfd.h which we can replace by a simple struct forward declaration 4. process-util.h which was needed for getpid_cached() which we now hide in a funciton log_emergency_level() instead, which nicely abstracts the details away. 5. sys/socket.h which was needed for struct iovec, but a simple struct forward declaration suffices for that too. Ultimately this actually makes our source tree larger (since users of the functionality above must now include it themselves, log.h won't do that for them), but I think it helps to untangle our web of includes a tiny bit. (Background: I'd like to isolate the generic bits of src/basic/ enough so that we can do a git submodule import into casync for it)
* socket-util: use parse_ip_port() for parsing IP portsLennart Poettering2018-01-051-20/+15
| | | | | Let's unify some code here, and also use parse_ip_port() for all our IP port parsing needs in socket_address_parse().
* socket-util: slight rework of getpeersec()Lennart Poettering2018-01-041-20/+11
| | | | | | | | | | Let's call getsockopt() in a loop, so that we can deal correctly with the label changing while we are trying to read it. (also, while we are at it, let's make sure that there's always one trailing NUL byte at the end of the buffer, after all SO_PEERSEC has zero documentation, and multiple implementing backends, hence let's better be safe than sorry)
* tree-wide: use {pid,uid,gid}_is_valid() where appropriateLennart Poettering2018-01-041-7/+5
| | | | | | Also, drop UID/GID validity checks from getpeercred() as the kernel will never pass us invalid UID/GID on userns, but the overflow UID/GID instead. Add a comment about this.
* socket-util: add new getpeergroups() callLennart Poettering2018-01-041-0/+33
| | | | | It's a wrapper around the new SO_PEERGROUPS sockopt, similar in style as getpeersec() and getpeercred().
* Merge pull request #7759 from yuwata/dbus-apiLennart Poettering2018-01-031-0/+12
|\ | | | | DBus-API: add more options in transient units
| * socket-util: introduce parse_socket_address_bind_ipv6_only_or_bool()Yu Watanabe2018-01-011-0/+12
| |
* | socket-util: clarify why sockaddr_port returns unsigned rather than uint16_tLennart Poettering2017-12-261-4/+7
|/
* socket-util: add socket_address_type_{from,to}_string()Yu Watanabe2017-12-231-0/+11
|
* tree-wide: make use of new STRLEN() macro everywhere (#7639)Lennart Poettering2017-12-141-1/+1
| | | | | Let's employ coccinelle to do this for us. Follow-up for #7625.
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* Merge pull request #6974 from keszybz/clean-up-definesLennart Poettering2017-10-041-1/+1
|\ | | | | Clean up define definitions
| * build-sys: use #if Y instead of #ifdef Y everywhereZbigniew Jędrzejewski-Szmek2017-10-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The advantage is that is the name is mispellt, cpp will warn us. $ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/" $ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;' $ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g' $ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g' + manual changes to meson.build squash! build-sys: use #if Y instead of #ifdef Y everywhere v2: - fix incorrect setting of HAVE_LIBIDN2
* | tree-wide: use IN_SET macro (#6977)Yu Watanabe2017-10-041-1/+1
|/