summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2020-09-10llmnrd: create pid file when daemonizing, and remove it on exitDiego Santa Cruz2-1/+40
The path of the pid file is /run/llmnrd/pid by default but can be changed via the PIDFILE make variable. Fixes #18 Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>
2020-09-10llmnrd: add command line option to log to syslog instead of stdioDiego Santa Cruz4-7/+59
When llmnrd daemonizes stdout and stderr are redirected to /dev/null and all logs are lost. This adds a cli option -s / --syslog to send the logs to syslog instead. Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>
2020-09-10llmnrd: exit gracefully on select() EINTRTobias Klauser1-2/+3
If a signal was caught, select returns with errno set to EINTR. The signal handler already set llmnrd_running = false. This will also make sure the log message moved by commit a1a821814101 ("llmnrd: only async signal safe functions may be called in signal handler") will get logged correctly in all cases and the process will exit gracefully. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2020-09-10README.md: add Diego Santa Cruz to authorsTobias Klauser1-0/+1
Acknowledge Diego Santa Cruz for contribution of PRs #31, #32 and #33. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2020-09-10llmnrd: only async signal safe functions may be called in signal handlerDiego Santa Cruz1-1/+2
Signal handlers may only call async signal safe functions and logging is certainly not async signal safe, so move the log message to the main loop. While at it change "Interrupt" for "Signal" in the message which is more appropriate. Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>
2020-03-28llmnr: fix ifindex typeTobias Klauser1-1/+1
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2020-03-28llmnrd: don't exit on SO_BINDTODEVICE failureJon Franklin4-12/+17
The -i option requires running llmnrd as root for SO_BINDTODEVICE to work. Packets are still filtered based on interface because only rtnl messages for addresses of the specified interface are considered in iface_nlmsg_change_addr. Instead log a warning only if SO_BINDTODEVICE fails. Signed-off-by: Jon Franklin <jvfranklin@gmail.com> [tk: small adjustments to commit message, check return value of iface_init] Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2019-02-03llmnrd: set stdout to line bufferingmpvader1-0/+2
The log output of llmnrd works well when operated from a terminal; but not when its stdout is piped to a log-file or -tool; due to buffering: By default, stdout is buffered (line buffered if connected to a terminal), and stderr is unbuffered. [1] Changing stdout to line buffering fixes this. [1] https://www.gnu.org/software/libc/manual/html_node/Buffering-Concepts.html
2019-01-29llmnrd v0.6v0.6Tobias Klauser1-2/+2
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2019-01-29doc: fix typo in llmnr-query manpageTobias Klauser1-1/+1
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2018-02-16llmnrd: ignore queries with TC bit setTobias Klauser1-2/+2
As per RFC 4795, section 2.1.1: The 'TC' bit MUST NOT be set in an LLMNR query and, if set, is ignored by an LLMNR responder. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2018-02-13llmnr-query: add option to set conflict bit in LLMNR header flagsTobias Klauser1-4/+11
Allows testing llmnrd behavior in presence of conflicts. Updates #25 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2018-02-12make: remove CROSS_COMPILE variableTobias Klauser2-4/+5
As a side effect of commit 21b5fc75be0a ("Makefile: assign CC conditionally") which came in via PR #24, the CROSS_COMPILE make variable is no longer taken into account because CC is always defined by make itself. Instead of working around this with dirty hacks, just suggest setting CC to the corresponding cross-compiler. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2018-02-11Makefile: assign CC conditionallympvader1-1/+1
Only assign CC if its not yet defined. The Yocto SDK sets CC as an env variable, including --sysroot and various other parameters. This change fixes the Makefile for using with Yocto SDK.
2017-10-18llmnrd v0.5v0.5Tobias Klauser1-1/+1
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-03-16make: add -Wextra to CFLAGS_WARN, sort additional warning flagsTobias Klauser1-4/+14
Enable -Wextra, sort warning flags in CFLAGS_WARN alphabetically to avoid adding duplicates. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-03-07make: install manpages in 'install' targetTobias Klauser2-0/+14
gzip and install the manpages for llmnrd and llmnr-query in the Makefile's 'install' target. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-03-07doc: add manpages for llmnrd and llmnr-queryTobias Klauser2-0/+78
Add rudimentary manpages for llmnrd and llmnr-query describing their usage. Fixes #14 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-28llmnrd: Update copyright in version informationTobias Klauser1-1/+1
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-28llmnrd: Poll hostnameTobias Klauser3-3/+39
Poll "/proc/sys/kernel/hostname" and update the hostname when it was changed. systemd has a similar mechanism. Note that the hostname is not polled if it has been provided on the command line, or if "/proc/sys/kernel/hostname" cannot be opened. Patch contributed by @tbetker Fixes #23 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-28README.md: Acknowledge @tbetkerTobias Klauser1-2/+3
Acknowledge @tbetker for issues #22 and #23 and the patches provided therein. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-28llmnr-query: Fix missing NULL byteTobias Klauser1-3/+4
If the domain name in the response is <len> <octets> <00>, the code copies 'len' octets to name[], but does not add a terminating NULL character. The same may happen in the "compression" case. Fix this by adding a NULL byte in both cases. Patch constributed by @tbetker. Fixes #22 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-10llmnrd v0.4v0.4Tobias Klauser1-1/+1
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-10llmnrd: Fix typo in commentTobias Klauser1-1/+1
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-09llmnr-query: Allocate receive buffer large enoughTobias Klauser1-1/+4
If an LLMNR response exceeds 128 bytes, it will get truncated. This leads to out-of-bounds read access during parsing and causes garbage data to be printed. Fix it by allocating the buffer large enough (according to RFC). Possible future improvment would be to consider the link MTU size to save some memory. Fixes #21 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-09llmnr-query: Fix two cases where misaliged access could occurTobias Klauser1-10/+12
Two places where a misaliged could occur were missed in commit 7f719d2 ("llmnr-query: Extract LLMNR packet data in an alignment-safe way"). Fix them now. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-08debian: remove debian packaging filesTobias Klauser9-76/+0
There is now an official package in the Debian package repository [1] which should be used instead of locally built packages. Drop the local packaging file which anyway no longer match the version in Debian. [1] https://packages.debian.org/sid/llmnrd Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-08llmnr-query: Extract LLMNR packet data in an alignment-safe wayTobias Klauser2-7/+24
Follow commit 9bec6fb9 ("Fix misaligned memory access") for llmnr-query and extract values from the response packets in a way that doesn't cause unaligned memory access on architectures that don't support it. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-08llmnr-query: Account for terminating NULL byte in address string bufferTobias Klauser1-1/+2
If the IPv6 address in the reply is 48 bytes long, inet_ntop() would overflow the addr buffer. Account for the terminating NULL byte. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-08iface: Merge duplicate codeTobias Klauser2-20/+10
Call iface_recv() from iface_rtnl_enumerate() instead of open-coding it. Reorder code a bit to avoid duplication. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-08llmnrd: Use strncasecmp() instead of open-coding itTobias Klauser1-11/+3
Use strncasecmp() from <strings.h> to compare the hostnames. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-08llmnrd: Check query name length against LLMNR_LABEL_MAX_SIZETobias Klauser1-1/+2
Make sure the hostname buffer is not accessed out of bounds. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-07llmnrd: compare full hostname in query, fix off-by-one errorTobias Klauser1-2/+8
When checking whether the hostname matches, llmnrd does not consider the last character of the hostnames, leading to the following incorrect behavior: $ ./llmnrd -H foobar Starting llmnrd on port 5355, hostname foobar ... $ ./llmnr-query foobaZ LLMNR query: foobaZ IN ANY LLMNR response: foobar IN A 10.42.0.42 (TTL 30) Fix it by considering the full hostname. Also do only convert alphabetic characters to lowercase using tolower(3), since its behavior is undefined for any other characters. Fixes #21 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-02-07socket: ignore EADDRINUSE when joining multicast groupTobias Klauser1-6/+16
If an interface is configured with multiple addresses, llmnrd tries to join the LLMNR multicast group for each address instead of once per interface. Ideally llmnrd should track whether the group is already joined but since the kernel tells us that the group is already joined, just omit the error message on EADDRINUSE. This fixes the following error case: $ ip address add 2001:db8:1::/48 dev eth0 $ ./llmnrd -6 Starting llmnrd on port 5355, hostname foobar Added IPv4 address 127.0.0.1 on interface lo Added IPv4 address 10.42.0.42 on interface eth0 Added IPv6 address ::1 on interface lo Added IPv6 address 2001:db8:1:: on interface eth1 Error: Failed to join IPv6 multicast group on interface eth1: Address already in use Added IPv6 address fe80::xxxx:xxxx:xxxx:xxxx on interface eth0 Reference: #21 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-25llmnrd v0.3v0.3Tobias Klauser1-1/+1
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-13illmnr-query: Add const qualifier to name variableTobias Klauser1-1/+1
This fixes the following GCC warning: llmnr-query.c:345:12: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-13util: Add printf format GCC attribute to panic() functionTobias Klauser2-2/+8
This fixes the following GCC warning: util.h:55:2: warning: function might be possible candidate for ‘gnu_printf’ format attribute [-Wsuggest-attribute=format] Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-13make: Enable additional GCC warningsTobias Klauser1-1/+6
Enable some sensible GCC warnings for default build. The list of flags was based on the flags from the nftables source. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-10llmnrd: Correct IPv6 check in llmnr_respond()Tobias Klauser1-1/+1
Implement the check whether IPv6 is enabled properly, checking the bool variable llmnr_ipv6 < 0 doesn't make sense. Found by the coverity scanner (CID 159830). Fixes: e9cd5a6826f1 ("llmnrd: merge rtnl interface event loop into main select() loops") Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-10llmnrd: merge rtnl interface event loop into main select() loopsTobias Klauser6-178/+116
Instead of spawming a thread for the sole purpose of watching the rtnl for (presumably) seldom events, just merge the select() for all sockets together in one single main loop. This reduces unnecessary complexity and makes llmnrd no longer require any locking. It also allows us to handle signals in a thread-safe manner (as there aren't any ;) and thus the race condition on exit reported in #20 Closes #20 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-09make: Append instead of override CPPFLAGS and CFLAGS passed by userTobias Klauser1-6/+7
Distribution build scripts commonly assume the CPPFLAGS, CFLAGS and LDFLAGS passed via command line or environment to be appended to the base set of flags defined in the Makefile. Follow this assumption instead of overriding the already defined values. Also treat these three variables entriely independently instead of appending CPPFLAGS to CFLAGS. Reported-by: @pali Really-fixes: #17 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-09make: don't show echo commands in verbose modeTobias Klauser1-8/+13
Avoid echoing the CC/LD string in verbose mode, just show the plain commands: $ make Q= gcc -W -Wall -DVERSION_STRING=\"v0.2.1\" -DGIT_VERSION=\""(git id v0.2.1-6-gab7cd2fc9043)"\" -O2 -o llmnr.o -c llmnr.c gcc -W -Wall -DVERSION_STRING=\"v0.2.1\" -DGIT_VERSION=\""(git id v0.2.1-6-gab7cd2fc9043)"\" -O2 -o iface.o -c iface.c gcc -W -Wall -DVERSION_STRING=\"v0.2.1\" -DGIT_VERSION=\""(git id v0.2.1-6-gab7cd2fc9043)"\" -O2 -o socket.o -c socket.c gcc -W -Wall -DVERSION_STRING=\"v0.2.1\" -DGIT_VERSION=\""(git id v0.2.1-6-gab7cd2fc9043)"\" -O2 -o util.o -c util.c gcc -W -Wall -DVERSION_STRING=\"v0.2.1\" -DGIT_VERSION=\""(git id v0.2.1-6-gab7cd2fc9043)"\" -O2 -o llmnrd.o -c llmnrd.c gcc -o llmnrd llmnr.o iface.o socket.o util.o llmnrd.o -lpthread gcc -W -Wall -DVERSION_STRING=\"v0.2.1\" -DGIT_VERSION=\""(git id v0.2.1-6-gab7cd2fc9043)"\" -O2 -o llmnr-query.o -c llmnr-query.c gcc -o llmnr-query util.o llmnr-query.o Also consider $(Q) for the clean and install targets. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-07make: Support CPPFLAGS in MakefileHEADmasterTobias Klauser1-2/+3
Currently Makefile ignores CPPFLAGS and so any defines passed via environment/command line ignored. E.g. running make CPPFLAGS="-D_FORTIFY_SOURCE=2" does not compile llmnrd with buffer overflow checks. Fix it by considering CPPFLAGS in the Makefile and appending them to CFLAGS. Closes #17 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-07llmnrd: Don't busy wait in receive loopTobias Klauser1-6/+2
There is no need to have a timeout for select(2) to check llmnr_running periodically. It can just block until a packet is received and will be interrupted by any terminating signal. Closes #19 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-06compiler: Avoid redefinitions of __unused and __packedTobias Klauser1-2/+6
FreeBSD defines these in sys/cdefs.h Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-06llmnr-query: Add support for FreeBSD and DarwinTobias Klauser1-2/+34
Make llmnr-query work on FreeBSD and Darwin by using sendmsg() to send UDP packets. Using sendto() doesn't seem to work for IPv6 sockets. Also specify the size of the corresponding sockaddr type, not of sockaddr_storage. Tested on FreeBSD 11.0, Mac OS X 10.11. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-06llmnr-query: Update copyrightTobias Klauser1-3/+3
Also change the description slightly and mention the LLMNR RFC number. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2017-01-06llmnr-query: Only calculate query length if send was successfulTobias Klauser1-2/+3
Also add a comment indicating the repurposing of the pkt struct. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2016-12-22llmnrd v0.2.1v0.2.1Tobias Klauser1-1/+1
Bugfix release to create source packages without debian packaging information. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2016-12-22build: Add release targetTobias Klauser1-0/+15
Add a release target to the Makefile (akin to the one from netsniff-ng) in order to streamline the release process. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>