Age | Commit message (Collapse) | Author | Files | Lines |
|
Add a working init script as a base for distributions.
Fixes #2
|
|
Makes it a bit easier to read.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
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>
|
|
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>
|
|
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>
|
|
Acknowledge Diego Santa Cruz for contribution of PRs #31, #32 and #33.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
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>
|
|
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
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>
|
|
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
|
|
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
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>
|
|
Allows testing llmnrd behavior in presence of conflicts.
Updates #25
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
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>
|
|
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.
|
|
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Enable -Wextra, sort warning flags in CFLAGS_WARN alphabetically to
avoid adding duplicates.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
gzip and install the manpages for llmnrd and llmnr-query in the
Makefile's 'install' target.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Add rudimentary manpages for llmnrd and llmnr-query describing their
usage.
Fixes #14
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
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>
|
|
Acknowledge @tbetker for issues #22 and #23 and the patches provided
therein.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
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>
|
|
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
Use strncasecmp() from <strings.h> to compare the hostnames.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Make sure the hostname buffer is not accessed out of bounds.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
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>
|
|
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>
|
|
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
FreeBSD defines these in sys/cdefs.h
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
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>
|
|
Also change the description slightly and mention the LLMNR RFC number.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|
|
Also add a comment indicating the repurposing of the pkt struct.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
|