summaryrefslogtreecommitdiff
path: root/src/shared/socket-util.c
AgeCommit message (Collapse)Author
2015-06-11build-sys: split internal basic/ library from shared/Kay Sievers
basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/
2015-05-15socket-util: socket_address_parse() should not log errors on its ownLennart Poettering
Given that socket_address_parse() is mostly a "library" call it shouldn't log on its own, but leave that to its caller. This patch removes logging from the call in case IPv6 is not available but and IPv6 address shall be parsed. Instead a new call socket_address_parse_and_warn() is introduced which first invokes socket_address_parse() and then logs if necessary. This should fix "make check" on ipv6-less kernels: http://lists.freedesktop.org/archives/systemd-devel/2015-April/031385.html
2015-04-10shared: add formats-util.hRonny Chevalier
2015-03-13tree-wide: there is no ENOTSUP on linuxDavid Herrmann
Replace ENOTSUP by EOPNOTSUPP as this is what linux actually uses.
2015-03-11socket-util: refactor error handling in sockaddr_prettyZbigniew Jędrzejewski-Szmek
2015-03-10add REMOTE_ADDR and REMOTE_PORT for Accept=yesShawn Landden
2015-02-23remove unused includesThomas Hindoe Paaboel Andersen
This patch removes includes that are not used. The removals were found with include-what-you-use which checks if any of the symbols from a header is in use.
2015-02-20shared: handle unnamed sockets in socket_address_equal()Michal Schmidt
Make sure we don't inspect sun_path of unnamed sockets. Since we cannot know if two unnamed sockets' adresses refer to the same socket, just return false.
2015-02-20shared: avoid semi-duplicating socket_address_equal()Michal Schmidt
Just call socket_address_equal() from socket_address_matches_fd() instead of implementing similar comparing of addresses.
2015-02-20shared: use SocketAddress in socket_address_matches_fd()Michal Schmidt
Cleanup. No behavior change.
2015-02-20core, shared: in deserializing, match same files reached via different pathsMichal Schmidt
When dbus.socket is updated like this: -ListenStream=/var/run/dbus/system_bus_socket +ListenStream=/run/dbus/system_bus_socket ... and daemon-reload is performed, bad things happen. During deserialization systemd does not recognize that the two paths refer to the same named socket and replaces the socket file with a new one. As a result, applications hang when they try talking to dbus. Fix this by finding a match not only when the path names are equal, but also when they point to the same inode. In socket_address_equal() it is necessary to move the address size comparison into the abstract sockets branch. For path name sockets the comparison must not be done and for other families it is redundant (their sizes are constant and checked by socket_address_verify()). FIFOs and special files can also have multiple pathnames, so compare the inodes for them as well. Note that previously the pathname checks used streq_ptr(), but the paths cannot be NULL. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1186018
2014-11-28treewide: another round of simplificationsMichal Schmidt
Using the same scripts as in f647962d64e "treewide: yet more log_*_errno + return simplifications".
2014-11-28treewide: use log_*_errno whenever %m is in the format stringMichal Schmidt
If the format string contains %m, clearly errno must have a meaningful value, so we might as well use log_*_errno to have ERRNO= logged. Using: find . -name '*.[ch]' | xargs sed -r -i -e \ 's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/' Plus some whitespace, linewrap, and indent adjustments.
2014-11-28treewide: yet more log_*_errno + return simplificationsMichal Schmidt
Using: find . -name '*.[ch]' | while read f; do perl -i.mmm -e \ 'local $/; local $_=<>; s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg; print;' $f done And a couple of manual whitespace fixups.
2014-11-28treewide: more log_*_errno() conversionsMichal Schmidt
2014-11-28treewide: no need to negate errno for log_*_errno()Michal Schmidt
It corrrectly handles both positive and negative errno values.
2014-11-28treewide: auto-convert the simple cases to log_*_errno()Michal Schmidt
As a followup to 086891e5c1 "log: add an "error" parameter to all low-level logging calls and intrdouce log_error_errno() as log calls that take error numbers", use sed to convert the simple cases to use the new macros: find . -name '*.[ch]' | xargs sed -r -i -e \ 's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/' Multi-line log_*() invocations are not covered. And we also should add log_unit_*_errno().
2014-10-23socket-util: use IP address when hostname is not foundZbigniew Jędrzejewski-Szmek
socknameinfo_pretty() would fail for addresses without reverse DNS, but we do not want that to happen.
2014-08-15util: never use ether_ntoa(), since it formats with %x, not %02x, which ↵Lennart Poettering
makes ethernet addresses look funny
2014-08-13resolved: skip IPv6 LLMNR if IPv6 is not availableLennart Poettering
2014-08-12timesyncd: move the generic sockaddr_equal() call to socket-util.hLennart Poettering
2014-07-15shared/socket-util: add function to query remote addressZbigniew Jędrzejewski-Szmek
2014-07-10shared: split out in_addr related calls from socket-util.[ch] into its ↵Lennart Poettering
private in-addr-util.[ch] These are enough calls for a new file, and they are sufficiently different from the sockaddr-related calls, hence let's split this out.
2014-06-22fix in_addr_prefix_intersect for 32bitsMarc-Antoine Perennou
shifting from a non fixed number of bits >= to the size of the type leads to weird results, handle the special case of << 32 to fix it. This was causing a test failure from test-socket-util: Assertion 'in_addr_prefix_intersect(f, &ua, apl, &ub, bpl) == result' failed at /var/tmp/paludis/build/sys-apps-systemd-scm/work/systemd-scm/src/test/test-socket-util.c:147, function test_in_addr_prefix_intersect_one(). Aborting. Minimal reproducer: paludisbuild@Lou /tmp $ cat test.c static void test(unsigned m) { unsigned nm = 0xFFFFFFFFUL << (32-m); printf("%u: %x\n", m, nm); } int main (void) { test(1); test(0); return 0; } paludisbuild@Lou /tmp $ gcc -m32 -std=gnu99 test.c -o test32 paludisbuild@Lou /tmp $ ./test32 1: 80000000 0: ffffffff paludisbuild@Lou /tmp $ gcc -std=gnu99 test.c -o test64 paludisbuild@Lou /tmp $ ./test64 1: 80000000 0: 0
2014-06-18networkd: add a number of calls to manipulate in_addr_union structsLennart Poettering
2014-06-04socket: optionally remove sockets/FIFOs in the file system after useLennart Poettering
2014-05-15Remove unnecessary casts in printfsZbigniew Jędrzejewski-Szmek
No functional change expected :)
2014-02-19make gcc shut upLennart Poettering
If -flto is used then gcc will generate a lot more warnings than before, among them a number of use-without-initialization warnings. Most of them without are false positives, but let's make them go away, because it doesn't really matter.
2013-12-25shared: fix getpeername_pretty() for AF_UNIX socketsLennart Poettering
2013-12-25unit: include peer identity in description of per-connection ↵Lennart Poettering
socket-activated services
2013-12-24util: unify SO_PEERCRED/SO_PEERSEC invocationsLennart Poettering
Introduce new call getpeercred() which internally just uses SO_PEERCRED but checks if the returned data is actually useful due to namespace quirks.
2013-11-07socket: rework things to have only one sockaddr formatterLennart Poettering
2013-11-06socket-proxyd: rework to support multiple sockets and splice()-based ↵Lennart Poettering
zero-copy network IO This also drops --ignore-env, which can't really work anymore if we allow multiple fds. Also adds support for pretty printing of peer identities for debug purposes, and abstract namespace UNIX sockets. Also ensures that we never take more connections than a certain limit.
2013-11-06active: rework make_socket_fd() to be based on socket_address_listen()Lennart Poettering
Among other things this makes sure we set SO_REUSEADDR which is immensely useful.
2013-10-13ModernizationZbigniew Jędrzejewski-Szmek
Fixes minor leak in error path in device.c.
2013-09-26core: rework how we match mount units against each otherLennart Poettering
Previously to automatically create dependencies between mount units we matched every mount unit agains all others resulting in O(n^2) complexity. On setups with large amounts of mount units this might make things slow. This change replaces the matching code to use a hashtable that is keyed by a path prefix, and points to a set of units that require that path to be around. When a new mount unit is installed it is hence sufficient to simply look up this set of units via its own file system paths to know which units to order after itself. This patch also changes all unit types to only create automatic mount dependencies via the RequiresMountsFor= logic, and this is exposed to the outside to make things more transparent. With this change we still have some O(n) complexities in place when handling mounts, but that's currently unavoidable due to kernel APIs, and still substantially better than O(n^2) as before. https://bugs.freedesktop.org/show_bug.cgi?id=69740
2013-04-18move _cleanup_ attribute in front of the typeHarald Hoyer
http://lists.freedesktop.org/archives/systemd-devel/2013-April/010510.html
2013-04-11errno is positiveZbigniew Jędrzejewski-Szmek
Make sure we compare errno against positive error codes. The ones in hwclock.c and install.c can have an impact, the rest are unlikely to be hit or in code that isn't widely used. Also check that errno > 0, to help gcc know that we are returning a negative error code.
2013-03-29Always use errno > 0 to help gccZbigniew Jędrzejewski-Szmek
gcc thinks that errno might be negative, and functions could return something positive on error (-errno). Should not matter in practice, but makes an -O4 build much quieter.
2013-02-27systemd-activate: add a socket-activation test toolZbigniew Jędrzejewski-Szmek
2013-02-14honor SELinux labels, when creating and writing config filesHarald Hoyer
Also split out some fileio functions to fileio.c and provide a SELinux aware pendant in fileio-label.c see https://bugzilla.redhat.com/show_bug.cgi?id=881577
2013-02-13use strneq instead of strncmpThomas Hindoe Paaboel Andersen
2012-12-22socket: support socket activation of containersLennart Poettering
2012-12-17socket-util: added check of return valueMichal Sekletar
2012-11-13shared/socket-util: kill gcc warning about uninitialized variableZbigniew Jędrzejewski-Szmek
The warning was invalid, but distracting.
2012-10-30shared, core: do not always accept numbers in string lookupsMichal Schmidt
The behaviour of the common name##_from_string conversion is surprising. It accepts not only the strings from name##_table but also any number that falls within the range of the table. The order of items in most of our tables is an internal affair. It should not be visible to the user. I know of a case where the surprising numeric conversion leads to a crash. We will allow the direct numeric conversion only for the tables where the mapping of strings to numeric values has an external meaning. This holds for the following lookup tables: - netlink_family, ioprio_class, ip_tos, sched_policy - their numeric values are stable as they are defined by the Linux kernel interface. - log_level, log_facility_unshifted - the well-known syslog interface. We allow the user to use numeric values whose string names systemd does not know. For instance, the user may want to test a new kernel featuring a scheduling policy that did not exist when his systemd version was released. A slightly unpleasant effect of this is that the name##_to_string conversion cannot return pointers to constant strings anymore. The strings have to be allocated on demand and freed by the caller.
2012-10-03man: document behaviour of ListenStream= with only a port number in regards ↵Lennart Poettering
to IPv4/IPv6
2012-05-08util: split-out path-util.[ch]Kay Sievers
2012-04-12relicense to LGPLv2.1 (with exceptions)Lennart Poettering
We finally got the OK from all contributors with non-trivial commits to relicense systemd from GPL2+ to LGPL2.1+. Some udev bits continue to be GPL2+ for now, but we are looking into relicensing them too, to allow free copy/paste of all code within systemd. The bits that used to be MIT continue to be MIT. The big benefit of the relicensing is that closed source code may now link against libsystemd-login.so and friends.
2012-04-11split selinux label operations out of cgroup-util, socket-utilKay Sievers
This prevents linking of selinux and libdl for another 15 binaries.