Merge branch 'schweikert:develop' into develop

pull/291/head
lordrasmus 1 year ago committed by GitHub
commit 5809fa8cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,30 @@
.*.swp
*.tar.gz
*~
src/*.gcno
src/*.gcda
src/*.gcov
src/tags
.deps
Makefile
Makefile.in
aclocal.m4
autom4te.cache
compile
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
depcomp
install-sh
missing
src/*.o
src/fping
src/fping6
stamp-h1
doc/fping.8
doc/fping6.8
ci/build

@ -5,7 +5,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-20.04]
os: [ubuntu-20.04, ubuntu-22.04]
steps:
- name: Checkout repository
uses: actions/checkout@v2

@ -1,9 +1,11 @@
#!/usr/bin/perl -w
use Test::Command tests => 12;
use Test::Command tests => 18;
# -u show targets that are unreachable
# -v show version
# -x shows if >=N hosts are reachable or not
# -X exits true immediately when N hosts are found
# fping -u
{
@ -36,3 +38,19 @@ $cmd->exit_is_num(1);
$cmd->stdout_is_eq("Not enough hosts reachable (required: 2, reachable: 1)\n");
$cmd->stderr_is_eq("");
}
# fping -X
{
my $cmd = Test::Command->new(cmd => "fping -X 1 --generate 127.0.0.0/29");
$cmd->exit_is_num(0);
$cmd->stdout_is_eq("Enough hosts reachable (required: 1, reachable: 1)\n");
$cmd->stderr_is_eq("");
}
# fping -X
{
my $cmd = Test::Command->new(cmd => "fping -X 2 --generate 8.8.0.0/29");
$cmd->exit_is_num(1);
$cmd->stdout_is_eq("Not enough hosts reachable (required: 2, reachable: 0)\n");
$cmd->stderr_is_eq("");
}

@ -9,19 +9,19 @@ plan tests => 3;
{
my $cmd = Test::Command->new(cmd => "fping -c 2 -Q 1 -N 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{CHART fping\.127_0_0_1_packets '' 'FPing Packets for host 127\.0\.0\.1' packets '127.0.0.1' fping\.packets line 110020 1
$cmd->stdout_like(qr{CHART fping\.127_0_0_1_packets '' 'FPing Packets' packets '127.0.0.1' fping\.packets line 110020 1
DIMENSION xmt sent absolute 1 1
DIMENSION rcv received absolute 1 1
BEGIN fping\.127_0_0_1_packets
SET xmt = 1
SET rcv = 1
END
CHART fping\.127_0_0_1_quality '' 'FPing Quality for host 127\.0\.0\.1' percentage '127.0.0.1' fping\.quality area 110010 1
CHART fping\.127_0_0_1_quality '' 'FPing Quality' percentage '127.0.0.1' fping\.quality area 110010 1
DIMENSION returned '' absolute 1 1
BEGIN fping\.127_0_0_1_quality
SET returned = 100
END
CHART fping\.127_0_0_1_latency '' 'FPing Latency for host 127\.0\.0\.1' ms '127.0.0.1' fping\.latency area 110000 1
CHART fping\.127_0_0_1_latency '' 'FPing Latency' ms '127.0.0.1' fping\.latency area 110000 1
DIMENSION min minimum absolute 1 1000000
DIMENSION max maximum absolute 1 1000000
DIMENSION avg average absolute 1 1000000

@ -4,7 +4,24 @@ dnl Minimum Autoconf version required.
AC_PREREQ(2.59)
AC_INIT([fping],[5.1])
AC_GNU_SOURCE
m4_ifdef([AC_AUTOCONF_VERSION],[AC_USE_SYSTEM_EXTENSIONS], [AC_GNU_SOURCE])
# Detect Operatingsystem
AC_CANONICAL_TARGET
only_clock_realtime=no
case "${target}" in
*darwin*)
only_clock_realtime=yes
;;
*freebsd*)
only_clock_realtime=yes
;;
*openbsd*)
only_clock_realtime=yes
;;
esac
dnl --disable-ipv4
AC_ARG_ENABLE([ipv4],
@ -43,13 +60,13 @@ dnl Test if --enable-timestamp is explicitely enabled and make an error if this
AS_IF([test "x$enable_timestamp" = "xyes" -a "x$have_so_timestamp" = "xno"], [
AC_MSG_ERROR([--enable-timestamp not supported on this platform])
])
AS_IF([test "x$only_clock_realtime" = "xyes"], [AC_DEFINE(ONLY_CLOCK_REALTIME, [1], [ONLY_CLOCK_REALTIME is defined])])
AC_ARG_ENABLE([safe-limits],
AS_HELP_STRING([--enable-safe-limits], [Restrict timing parameters (-i, -p) within "safe" limits]))
AS_IF([test "x$enable_safe_limits" = "xyes"], [
AC_DEFINE(FPING_SAFE_LIMITS, [1], [safe limits should be enforced])])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AM_MAINTAINER_MODE
@ -59,7 +76,7 @@ dnl Checks for programs.
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CC_STDC
m4_version_prereq([2.70],,[AC_PROG_CC_STDC])
AC_PROG_CPP
AC_PROG_INSTALL

@ -0,0 +1,16 @@
FROM ubuntu:20.04
# Base
RUN apt-get update && apt-get install -y \
build-essential \
automake \
m4
# Add source code
COPY ./ /app
# Compile
WORKDIR /app
RUN autoreconf --install
RUN ./configure && make && make install
ENTRYPOINT ["fping"]

@ -97,10 +97,7 @@ Show elapsed (round-trip) time of packets.
=item B<-f>, B<--file>
Read list of targets from a file. This option can only be used by the root
user. Regular users should pipe in the file via stdin:
$ fping < targets_file
Read list of targets from a file.
=item B<-g>, B<--generate> I<addr/mask>
@ -154,7 +151,7 @@ to print hostnames in the output.
=item B<-N>, B<--netdata>
Format output for netdata (-l -Q are required). See: L<http://my-netdata.io/>
Format output for netdata (-l -Q are required). See: L<https://netdata.cloud/>
=item B<-o>, B<--outage>
@ -232,6 +229,11 @@ Print B<fping> version information.
Given a list of hosts, this mode checks if number of reachable hosts is >= N
and exits true in that case.
=item B<-X>, B<--fast-reachable>=I<N>
Given a list of hosts, this mode immediately exits true once N alive hosts
have been found.
=back
=head1 EXAMPLES

@ -118,15 +118,16 @@ extern int h_errno;
/*** Constants ***/
#if HAVE_SO_TIMESTAMPNS
#define CLOCKID CLOCK_REALTIME
#endif
/* CLOCK_MONTONIC starts under macOS, OpenBSD and FreeBSD with undefined positive point and can not be use
* see github PR #217
* The configure script detect the predefined operating systems an set CLOCK_REALTIME using over ONLY_CLOCK_REALTIME variable
*/
#if HAVE_SO_TIMESTAMPNS || ONLY_CLOCK_REALTIME
#define CLOCKID CLOCK_REALTIME
#endif
#if !defined(CLOCKID)
#if defined(CLOCK_MONOTONIC) && !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
#if defined(CLOCK_MONOTONIC)
#define CLOCKID CLOCK_MONOTONIC
#else
#define CLOCKID CLOCK_REALTIME
@ -327,7 +328,7 @@ int generate_flag = 0; /* flag for IP list generation */
int verbose_flag, quiet_flag, stats_flag, unreachable_flag, alive_flag;
int elapsed_flag, version_flag, count_flag, loop_flag, netdata_flag;
int per_recv_flag, report_all_rtts_flag, name_flag, addr_flag, backoff_flag, rdns_flag;
int multif_flag, timeout_flag;
int multif_flag, timeout_flag, fast_reachable;
int outage_flag = 0;
int timestamp_flag = 0;
int random_data_flag = 0;
@ -512,6 +513,7 @@ int main(int argc, char **argv)
{ "version", 'v', OPTPARSE_NONE },
{ "top", 'k', OPTPARSE_NONE },
{ "reachable", 'x', OPTPARSE_REQUIRED },
{ "fast-reachable", 'X', OPTPARSE_REQUIRED },
#if defined(DEBUG) || defined(_DEBUG)
{ NULL, 'z', OPTPARSE_REQUIRED },
#endif
@ -726,6 +728,12 @@ int main(int argc, char **argv)
usage(1);
break;
case 'X':
if (!(min_reachable = (unsigned int)atoi(optparse_state.optarg)))
usage(1);
fast_reachable = 1;
break;
case 'f':
filename = optparse_state.optarg;
break;
@ -987,13 +995,17 @@ int main(int argc, char **argv)
int opt = 1;
if (socket4 >= 0) {
if (setsockopt(socket4, SOL_SOCKET, SO_TIMESTAMPNS, &opt, sizeof(opt))) {
perror("setting SO_TIMESTAMPNS option");
if (setsockopt(socket4, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt))) {
perror("setting SO_TIMESTAMPNS and SO_TIMESTAMP option");
}
}
}
#ifdef IPV6
if (socket6 >= 0) {
if (setsockopt(socket6, SOL_SOCKET, SO_TIMESTAMPNS, &opt, sizeof(opt))) {
perror("setting SO_TIMESTAMPNS option (IPv6)");
if (setsockopt(socket6, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt))) {
perror("setting SO_TIMESTAMPNS and SO_TIMESTAMP option (IPv6)");
}
}
}
#endif
@ -1658,7 +1670,7 @@ void print_netdata(void)
h = table[i];
if (!sent_charts) {
printf("CHART fping.%s_packets '' 'FPing Packets for host %s' packets '%s' fping.packets line 110020 %.0f\n", h->name, h->host, h->host, report_interval / 1e9);
printf("CHART fping.%s_packets '' 'FPing Packets' packets '%s' fping.packets line 110020 %.0f\n", h->name, h->host, report_interval / 1e9);
printf("DIMENSION xmt sent absolute 1 1\n");
printf("DIMENSION rcv received absolute 1 1\n");
}
@ -1669,7 +1681,7 @@ void print_netdata(void)
printf("END\n");
if (!sent_charts) {
printf("CHART fping.%s_quality '' 'FPing Quality for host %s' percentage '%s' fping.quality area 110010 %.0f\n", h->name, h->host, h->host, report_interval / 1e9);
printf("CHART fping.%s_quality '' 'FPing Quality' percentage '%s' fping.quality area 110010 %.0f\n", h->name, h->host, report_interval / 1e9);
printf("DIMENSION returned '' absolute 1 1\n");
/* printf("DIMENSION lost '' absolute 1 1\n"); */
}
@ -1686,7 +1698,7 @@ void print_netdata(void)
printf("END\n");
if (!sent_charts) {
printf("CHART fping.%s_latency '' 'FPing Latency for host %s' ms '%s' fping.latency area 110000 %.0f\n", h->name, h->host, h->host, report_interval / 1e9);
printf("CHART fping.%s_latency '' 'FPing Latency' ms '%s' fping.latency area 110000 %.0f\n", h->name, h->host, report_interval / 1e9);
printf("DIMENSION min minimum absolute 1 1000000\n");
printf("DIMENSION max maximum absolute 1 1000000\n");
printf("DIMENSION avg average absolute 1 1000000\n");
@ -1948,15 +1960,13 @@ int receive_packet(int64_t wait_time,
reply_buf,
reply_buf_len
};
struct msghdr recv_msghdr = {
reply_src_addr,
reply_src_addr_len,
&msg_iov,
1,
&msg_control,
sizeof(msg_control),
0
};
struct msghdr recv_msghdr = {0};
recv_msghdr.msg_name = reply_src_addr;
recv_msghdr.msg_namelen = reply_src_addr_len;
recv_msghdr.msg_iov = &msg_iov;
recv_msghdr.msg_iovlen = 1;
recv_msghdr.msg_control = &msg_control;
recv_msghdr.msg_controllen = sizeof(msg_control);
#if HAVE_SO_TIMESTAMPNS
struct cmsghdr *cmsg;
#endif
@ -2083,7 +2093,7 @@ int decode_icmp_ipv4(
if (!using_sock_dgram4) {
struct ip *ip = (struct ip *)reply_buf;
#if defined(__alpha__) && __STDC__ && !defined(__GLIBC__) && !defined(__NetBSD__)
#if defined(__alpha__) && __STDC__ && !defined(__GLIBC__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
/* The alpha headers are decidedly broken.
* Using an ANSI compiler, it provides ip_vhl instead of ip_hl and
* ip_v. So, to get ip_hl, we mask off the bottom four bits.
@ -2419,6 +2429,9 @@ int wait_for_reply(int64_t wait_time)
/* print "is alive" */
if (h->num_recv == 1) {
num_alive++;
if (fast_reachable && num_alive >= min_reachable)
finish_requested = 1;
if (verbose_flag || alive_flag) {
printf("%s", h->host);
@ -2962,5 +2975,6 @@ void usage(int is_error)
fprintf(out, " -u, --unreach show targets that are unreachable\n");
fprintf(out, " -v, --version show version\n");
fprintf(out, " -x, --reachable=N shows if >=N hosts are reachable or not\n");
fprintf(out, " -X, --fast-reachable=N exits true immediately when N hosts are found\n");
exit(is_error);
}

@ -41,6 +41,7 @@
#include "options.h"
#include "fping.h"
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
@ -81,7 +82,7 @@ unsigned int seqmap_add(unsigned int host_nr, unsigned int ping_count, int64_t t
* 0, so will be seen as expired */
next_value = &seqmap_map[seqmap_next_id];
if (timestamp - next_value->ping_ts < SEQMAP_TIMEOUT_IN_NS) {
fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%ld, host_nr=%d, ping_count=%d, seqmap_next_id=%d)\n",
fprintf(stderr, "fping error: not enough sequence numbers available! (expire_timeout=%" PRId64 ", host_nr=%d, ping_count=%d, seqmap_next_id=%d)\n",
SEQMAP_TIMEOUT_IN_NS, host_nr, ping_count, seqmap_next_id);
exit(4);
}

Loading…
Cancel
Save