Petr Vorel [Mon, 12 Aug 2024 12:39:55 +0000 (14:39 +0200)]
Increase maximum -b value to 65507
Correct definitions: maximum theoretical IPv4 packet size and minimum
IPv4 header size (previously probably IPv6 size was used).
Because fping does not know ahead whether address is IPv4 or IPv6 assume
IPv4. Previously fping allowed only 65488, but real maximum for IPv4 on
Linux is 65507 (IPv6 would allow 65527 follow the current approach and
allow smaller value than reachable for IPv6).
Update test affected by this change. While at this, test 65508 (one
above the limit) instead of 65509.
Erik Auerswald [Sun, 11 Aug 2024 14:56:48 +0000 (16:56 +0200)]
CI: use File::Temp to create temporary directory
Before, ci/test-11-unpriv.pl used a hard-coded file name of
/tmp/fping.copy to create an unprivileged copy of fping. This
file was not deleted after it was no longer used.
Now, the unprivileged fping copy is created in a temporary
directory that is deleted after all tests from the file.
Erik Auerswald [Mon, 29 Jul 2024 17:38:16 +0000 (19:38 +0200)]
fix -k, --fwmark with setuid fping executable
* Setting the SO_MARK socket option requires root privileges (or
CAP_NET_ADMIN), thus temporarily elevate privileges for this
operation, if possible, by using the p_setsockopt() function.
This allows to use -k, --fwmark with setuid fping.
* Adjust README.md since setuid now works for -k, --fwmark.
* Remove "sudo" from testing -k since it is no longer needed.
* Test failure of setting firewall mark without privileges or
capabilities for both IPv4 and IPv6.
Erik Auerswald [Sun, 28 Jul 2024 18:36:01 +0000 (20:36 +0200)]
basic test for -d, --rdns
Usually, -d gives the same result as -n. Test this.
When the target is a name that resolves to an IP, but the IP
does not resolve to the same name or any name at all, the
output differs. This is harder to test, because this is
usually seen as a misconfiguration, so leave this out for now.
Erik Auerswald [Sun, 28 Jul 2024 18:27:09 +0000 (20:27 +0200)]
more tests with reply source != target
The tests for --check-source verify that Echo reply packets
from a source IP that was not used as the target of the Echo
request are not accepted. It does so for default fping, for
use with -c, and for use with -C. Test if the source address
is really printed without --check-source, but with -c or -C.
Erik Auerswald [Sun, 28 Jul 2024 17:55:13 +0000 (19:55 +0200)]
test --print-tos with an IPv6 target
Currently, --print-tos only works with IPv4. In contrast
to IPv4, IPv6 raw sockets do not provide access to the
raw IP packet. Thus the method used to access the TOS
byte value of an IPv4 packet does not work for the TC byte
value of an IPv6 packet. This results in always generating
'(TOS unknown)' for IPv6 targets.
Erik Auerswald [Sun, 28 Jul 2024 16:04:18 +0000 (18:04 +0200)]
Document that -a and -u are overridden by -c and -C
The other way around was already documented in commit ae0bc2380462878466f19aa45c7d38774f4b6e3f, but GitHub
pull request #337 by Moritz Lenz implies that this is
insufficient.
Erik Auerswald [Fri, 12 Jul 2024 18:34:57 +0000 (20:34 +0200)]
new option --check-source
Using the new option --check-source discards Echo reply packets
sourced from an address that is different from the specified target
address. This can be useful on busy monitoring hosts, because it
is possible that two fping processes running at he same time use
the same ICMP Echo Reply Identifier for ICMP Echo messages sent to
different hosts.
Erik Auerswald [Sun, 7 Jul 2024 14:30:23 +0000 (16:30 +0200)]
fix off-by-one error in generator limit
This commit does not add tests that verify the exact limit,
because pinging 100000 localhost addresses takes over 15
minutes on my PC. I have tested this fix manually.
Erik Auerswald [Sun, 7 Jul 2024 13:41:35 +0000 (15:41 +0200)]
also apply generator limit to use with CIDR
As described in GH issue #299, the MAX_GENERATE+1 limit is only
applied when using an address range, not when using CIDR. This
commit changes this to always honor the generator limit.
* refactor target address generation to use the same new function
for both range and CIDR notation
* check the limit for addresses to generate in the new function
* document the generator limit in "fping --help" output
* document the generator limit in the fping man page
* test that the address generation limit applies when using CIDR
notation
Erik Auerswald [Sun, 23 Jun 2024 16:57:18 +0000 (18:57 +0200)]
ci: skip an unreliable test on macOS
Sometimes, this test fails on macOS, at least on the GitHub CI.
It looks as if the fping process is killed before it produces
the required output. This test works reliably on GNU/Linux, so
keep it, but skip it when running on macOS.
Erik Auerswald [Sun, 23 Jun 2024 15:19:13 +0000 (17:19 +0200)]
ci: test timestamp plausibility
Some changes of fping resulted in some systems reporting
implausible timestamps, see, e.g., GH issue #203. This
commit adds a simplistic plausability check for timestamps
in Unix time format: they need to be greater or equal to 1000000000 (2001-09-09 03:46:40+02:00).
Erik Auerswald [Sun, 19 May 2024 15:54:37 +0000 (17:54 +0200)]
test error when binding to wrong local address
Test "fping -S" with both IPv4 and IPv6 addresses not configured
on local interfaces using addresses reserved for documentation.
Check the fping error message, but accept any system generated
additional information. This additional information differs
between operation systems.
Erik Auerswald [Sun, 19 May 2024 15:42:31 +0000 (17:42 +0200)]
test help output during normal option parsing
The existing test for "fping -h" triggers the special code path
for only one option, either -h or --help, that is handled before
normal option parsing.
Erik Auerswald [Tue, 30 Apr 2024 15:55:30 +0000 (17:55 +0200)]
Print cumulative stats with -Q SECS,cumulative
With -Q SECS, fping emits information for the just finished
interval. This is good for long-running fping processes where
one would like to get an update on recent results, ignoring
missing responses from older intervals. This seems appropriate
for use with other software like netdata or smokeping.
But for short(er)-running fping processes, e.g., during a change
window, it may be more interesting to get a status update since
the beginning of the change window, i.e., the start of fping.
Adding a comma followed by the keyword "cumulative" to -Q SECS
(i.e., -Q SECS,cumulative) changes the interim reports to output
the current per system overall statistics, unless -N is used, too.
The new syntax is documented in fping.pod and added to fping -h
output.
Four tests are added:
1. Characters after SECS are ignored as before.
2. Unknown keywords are ignored as before.
2. Adding ",cumulative" changes -Q output.
3. Adding ",cumulative" also affects the additional -o output.
Remove the 'fping -X 2 --generate 8.8.0.0/29' test, because it
is currently failing on the MacOS runner. Also, I am not sure that
it is a good idea to ping the IPs 8.8.0.1 and 8.8.0.2 and rely on
them being up.
Erik Auerswald [Sat, 17 Feb 2024 16:34:57 +0000 (17:34 +0100)]
use function stats_reset_interval()
Git commit bb8d71ef27f673f25c7e1648ea982c27bb61ac0d from 2020 among many
other things introduced the function stats_reset_interval() to reset the
*_i interval (or split) host statistics, but did not use it. This commit
replaces the open coded reset of interval stats inside print_host_splits()
and print_netdata() with calling stats_reset_interval().
Erik Auerswald [Sat, 17 Feb 2024 16:21:32 +0000 (17:21 +0100)]
typo fixes pertaining to ICMP for IPv6 sockets
As mentioned in issue #300, error messages pertaining to
socket creation may not be printed. But they should be
corrected anyway, just as the comments. Having correct
error messages also makes a fix for issue #300 more
obvious, because the messages itself would not change.
Erik Auerswald [Wed, 7 Feb 2024 18:36:48 +0000 (19:36 +0100)]
Decouple -a/-u effects from -c
As described in issue #295, the option combinations "-c N -u"
and "-c N -a" inadvertently have the same effect as "-c N -q".
Prevent this by first acting on -c, which includes disabling
either -a or -u, if -c is given, before acting on -a/-u.
Erik Auerswald [Wed, 7 Feb 2024 18:31:42 +0000 (19:31 +0100)]
Move description of -i MSEC to probing options
The -i MSEC, --interval=MSEC option does not directly affect
the output format, but rather the probe generation, i.e., the
minimum time between probes. Thus it is more fitting to list
it under "probing options" than under "output options".
Erik Auerswald [Tue, 6 Feb 2024 20:55:09 +0000 (21:55 +0100)]
Test ping to "all IPv6 nodes" multicast address
Any Echo Response packet uses a different source address than
used for the target, because it is not allowed to use a multicast
address as source. This results in extra output in a specific
format on standard error.
This should work, because IPv6 requires multicast support, and
every IPv6 node is supposed to join the "all nodes" multicast
group, including the node the test runs on. It at least works
on my Ubuntu 20.04 LTS system.
Erik Auerswald [Tue, 6 Feb 2024 20:52:31 +0000 (21:52 +0100)]
Test edge cases of -f and -g
* -f with non-existing file
* -f with input file containing comment and empty line
* -g with non-numeric address in "CIDR" format
* -g with one non-numeric address in start resp. end position
* -g with one IPv6 address in start resp. end position
Erik Auerswald [Tue, 9 Jan 2024 11:40:46 +0000 (12:40 +0100)]
Defensive coding: guard against a division by zero
In the function print_per_system_stats(), if packets have been
lost, the number of sent packets is checked to be positive before
dividing by it. If no packets have been lost, this is not checked.
Either the existing check is not needed, or both code paths need
the check.
The function print_per_system_splits() is quite similar to
print_per_system_stats(), and has the equivalent guards against a
division by zero in both code paths, not just one of them.
In the spirit of defensive coding, I think it is better to be safe
and add the missing guard against a division by zero.
Erik Auerswald [Mon, 8 Jan 2024 08:35:49 +0000 (09:35 +0100)]
Test examples from man page
The man page gives two examples combining -C and -q, but
these combinations are not yet tested. Add tests to help
ensure the documented examples continue to work.
Erik Auerswald [Mon, 8 Jan 2024 08:15:04 +0000 (09:15 +0100)]
Add longer test for -Q SECS
The statistics printed every SECS seconds show the results
since the the last report, not since the beginning. Also,
every report starts with a timestamp.
Erik Auerswald [Mon, 8 Jan 2024 08:12:09 +0000 (09:12 +0100)]
Test edge case behavior of "fping -g"
* wrong number or kind of arguments fails and prints usage;
* an empty range silently pings nothing and fping returns 1;
* a too large range fails with an error message;
* a zero CIDR prefix length fails with an error message.
Khem Raj [Mon, 29 Aug 2022 22:41:51 +0000 (15:41 -0700)]
fping: Initialize msghdr struct in a portable way
Initializing the structure assuming glibc layout results in
compile errors on musl, therefore do partial intialization and then
assigning the members individually.
Erik Auerswald [Sun, 30 Jan 2022 12:30:05 +0000 (13:30 +0100)]
Improve -Q documentation
The `-Q, --squiet=SECS` option does not replace the summary
statistics of `-q, --quiets`, but adds interval summary
statistics every SECS seconds to the output.
Erik Auerswald [Sun, 30 Jan 2022 12:10:29 +0000 (13:10 +0100)]
Improve -d and -n documentation
* Adjust `fping.pod` entries for `-d, --rdns` and `-n, --name`:
* The code performs reverse DNS lookups on the given targets,
not on source addresses from ICMP Echo Responses or ICMP
error messages. Adjust the `-d` description to reflect this.
* The sentence describing `-n` seems incomplete, so provide a
completion in similar spirit to `-d`.
* Add `-d, --rdns` to `-h, --help` output since `-d` and `-n` are
no longer equivalent.