From 1187374e745af310a2e346ab1df5250d07c65a69 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle Date: Wed, 11 Jun 2025 13:11:04 +0200 Subject: Remove unused FPING6 variable --- configure.ac | 1 - 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac index bd3de196..ae704361 100644 --- a/configure.ac +++ b/configure.ac @@ -1519,7 +1519,6 @@ then fi AC_PATH_PROG(PATH_TO_FPING,fping) -AC_PATH_PROG(PATH_TO_FPING6,fping6) AC_ARG_WITH(fping_command, ACX_HELP_STRING([--with-fping-command=PATH], -- cgit v1.2.3-74-g34f1 From 88683af1da8baae6b252795ab5d85a48e9cd3e63 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle Date: Wed, 11 Jun 2025 17:09:27 +0200 Subject: Implement autoconf logic for fping version detection --- configure.ac | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index ae704361..bec50cb4 100644 --- a/configure.ac +++ b/configure.ac @@ -1523,10 +1523,44 @@ AC_PATH_PROG(PATH_TO_FPING,fping) AC_ARG_WITH(fping_command, ACX_HELP_STRING([--with-fping-command=PATH], [Path to fping command]), PATH_TO_FPING=$withval) -if test -n "$PATH_TO_FPING" -then +if test -n "$PATH_TO_FPING"; then AC_DEFINE_UNQUOTED(PATH_TO_FPING,"$PATH_TO_FPING",[path to fping]) EXTRAS="$EXTRAS check_fping\$(EXEEXT)" + + if test -z "$($PATH_TO_FPING --version)" ; then + AC_MSG_NOTICE([failed to get version of fping]) + else + FPING_MAJOR_VERSION="$($PATH_TO_FPING --version | sed 's/.*fping: Version //' | sed 's/\..*//')" + FPING_MINOR_VERSION="$($PATH_TO_FPING --version | sed 's/.*fping: Version //' | sed 's/.*\.//')" + + if test $FPING_MAJOR_VERSION -eq 5 ; then + if test $FPING_MINOR_VERSION -ge 3 ; then + AC_DEFINE(FPING_VERSION_5_3_OR_HIGHER, "true", [fping is of version 5.3 or higher]) + AC_MSG_NOTICE([fping is of version 5.3 or higher]) + AC_DEFINE(FPING_VERSION_5_2_OR_HIGHER, "true", [fping is of version 5.2 or higher]) + AC_MSG_NOTICE([fping is of version 5.2 or higher]) + elif test $FPING_MINOR_VERSION -ge 2 ; then + AC_DEFINE(FPING_VERSION_5_2_OR_HIGHER, "true", [fping is of version 5.2 or higher]) + AC_MSG_NOTICE([fping is of version 5.2 or higher]) + else + AC_MSG_NOTICE([fping is of a version lower then 5.2]) + fi + + elif $FPING_MAJOR_VERSION > 5 ; then + AC_DEFINE(FPING_VERSION_5_2_OR_HIGHER, "true", [fping is of version 5.2 or higher]) + AC_MSG_NOTICE([fping is of version 5.2 or higher]) + AC_DEFINE(FPING_VERSION_5_3_OR_HIGHER, "true", [fping is of version 5.2 or higher]) + AC_MSG_NOTICE([fping is of version 5.3 or higher]) + fi + + if test "`fping --version | sed 's/.*fping: Version //'`" = "5.2" ; then + AC_DEFINE(FPING_VERSION, "5.2", [the version of fping available]) + AC_MSG_NOTICE([fping version: 5.2]) + elif test "`fping --version | sed 's/.*fping: Version //'`" = "5.3"; then + AC_DEFINE(FPING_VERSION, "5.3", [the version of fping available]) + AC_MSG_NOTICE([fping version: 5.3]) + fi + fi else AC_MSG_WARN([Get fping from http://www.fping.com in order to make check_fping plugin]) fi -- cgit v1.2.3-74-g34f1 From 7247fc656a1f475159b7879cc3c3b798e03c1a33 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle Date: Thu, 12 Jun 2025 11:13:59 +0200 Subject: Implement new fping options for fping 5.2 and 5.3 fping 5.2 and 5.3 add some new useful command line options which this commit add to check_fping. These are: * --fwmark - sets a firewall mark in the packages to make them identifiable (fping 5.2) * --icmp-timestamp - fping uses ICMP timestamp instead of ICMP Echo (fping 5.2) * --check-source - fping discards replies which originate not from the target address (fping 5.2) The fping release notes describe theses options ( https://github.com/schweikert/fping/releases ) in a little bit more detail. Currently the help display for those options is only shown when fping was available in the appropriate version during compilation. --- plugins/check_fping.c | 80 +++++++++++++++++++++++++++++++++++++----- plugins/check_fping.d/config.h | 24 +++++++++++++ 2 files changed, 96 insertions(+), 8 deletions(-) diff --git a/plugins/check_fping.c b/plugins/check_fping.c index e05056b2..4d328a01 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -117,8 +117,26 @@ int main(int argc, char **argv) { xasprintf(&option_string, "%s-R ", option_string); } + if (config.fwmark_set) { + xasprintf(&option_string, "%s--fwmark %u ", option_string, config.fwmark); + } + + if (config.icmp_timestamp) { + xasprintf(&option_string, "%s--icmp-timestamp ", option_string); + } + + if (config.check_source) { + xasprintf(&option_string, "%s--check-source ", option_string); + } + char *command_line = NULL; - xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, config.packet_size, config.packet_count, server); + + if (config.icmp_timestamp) { + // no paket size settable for ICMP timestamp + xasprintf(&command_line, "%s %s -c %d %s", fping_prog, option_string, config.packet_count, server); + } else { + xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, config.packet_size, config.packet_count, server); + } if (verbose) { printf("%s\n", command_line); @@ -275,13 +293,35 @@ mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double c /* process command-line arguments */ check_fping_config_wrapper process_arguments(int argc, char **argv) { - static struct option longopts[] = { - {"hostname", required_argument, 0, 'H'}, {"sourceip", required_argument, 0, 'S'}, {"sourceif", required_argument, 0, 'I'}, - {"critical", required_argument, 0, 'c'}, {"warning", required_argument, 0, 'w'}, {"alive", no_argument, 0, 'a'}, - {"bytes", required_argument, 0, 'b'}, {"number", required_argument, 0, 'n'}, {"target-timeout", required_argument, 0, 'T'}, - {"interval", required_argument, 0, 'i'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, - {"help", no_argument, 0, 'h'}, {"use-ipv4", no_argument, 0, '4'}, {"use-ipv6", no_argument, 0, '6'}, - {"dontfrag", no_argument, 0, 'M'}, {"random", no_argument, 0, 'R'}, {0, 0, 0, 0}}; + enum { + FWMARK_OPT = CHAR_MAX + 1, + ICMP_TIMESTAMP_OPT, + CHECK_SOURCE_OPT, + }; + static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, + {"sourceip", required_argument, 0, 'S'}, + {"sourceif", required_argument, 0, 'I'}, + {"critical", required_argument, 0, 'c'}, + {"warning", required_argument, 0, 'w'}, + {"alive", no_argument, 0, 'a'}, + {"bytes", required_argument, 0, 'b'}, + {"number", required_argument, 0, 'n'}, + {"target-timeout", required_argument, 0, 'T'}, + {"interval", required_argument, 0, 'i'}, + {"verbose", no_argument, 0, 'v'}, + {"version", no_argument, 0, 'V'}, + {"help", no_argument, 0, 'h'}, + {"use-ipv4", no_argument, 0, '4'}, + {"use-ipv6", no_argument, 0, '6'}, + {"dontfrag", no_argument, 0, 'M'}, + {"random", no_argument, 0, 'R'}, + // only available with fping version >= 5.3 + {"fwmark", required_argument, NULL, FWMARK_OPT}, + // only available with fping version >= 5.3 + {"icmp-timestamp", no_argument, NULL, ICMP_TIMESTAMP_OPT}, + {"check-source", no_argument, NULL, CHECK_SOURCE_OPT}, + + {0, 0, 0, 0}}; char *rv[2]; rv[PL] = NULL; @@ -409,6 +449,20 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) { case 'M': result.config.dontfrag = true; break; + case FWMARK_OPT: + if (is_intpos(optarg)) { + result.config.fwmark = (unsigned int)atol(optarg); + result.config.fwmark_set = true; + } else { + usage(_("fwmark must be a positive integer")); + } + break; + case ICMP_TIMESTAMP_OPT: + result.config.icmp_timestamp = true; + break; + case CHECK_SOURCE_OPT: + result.config.check_source = true; + break; } } @@ -496,6 +550,16 @@ void print_help(void) { printf(" %s\n", _("set the Don't Fragment flag")); printf(" %s\n", "-R, --random"); printf(" %s\n", _("random packet data (to foil link data compression)")); +#ifdef FPING_VERSION_5_2_OR_HIGHER + printf(" %s\n", "--fwmark=INTEGER"); + printf(" %s\n", _("set the routing mark to INTEGER (fping option)")); +# ifdef FPING_VERSION_5_3_OR_HIGHER + printf(" %s\n", "--icmp-timestamp"); + printf(" %s\n", _("use ICMP Timestamp instead of ICMP Echo (fping option)")); + printf(" %s\n", "--check-source"); + printf(" %s\n", _("discard replies not from target address (fping option)")); +# endif +#endif printf(UT_VERBOSE); printf("\n"); printf(" %s\n", _("THRESHOLD is ,%% where is the round trip average travel time (ms)")); diff --git a/plugins/check_fping.d/config.h b/plugins/check_fping.d/config.h index a0697bf3..6d28382a 100644 --- a/plugins/check_fping.d/config.h +++ b/plugins/check_fping.d/config.h @@ -29,6 +29,21 @@ typedef struct { bool cpl_p; int wpl; bool wpl_p; + + // only available with fping version >= 5.2 + // for a given uint _fwmark_ fping sets _fwmark_ as a firewall mark + // in the pakets + unsigned int fwmark; + bool fwmark_set; + + + // only available with fping version >= 5.3 + // Setting icmp_timestamp tells fping to use ICMP Timestamp (ICMP type 13) instead + // of ICMP Echo + bool icmp_timestamp; + + // Setting check_source lets fping discard replies which are not from the target address + bool check_source; } check_fping_config; check_fping_config check_fping_config_init() { @@ -53,6 +68,15 @@ check_fping_config check_fping_config_init() { .cpl_p = false, .wpl = 0, .wpl_p = false, + + // only available with fping version >= 5.2 + .fwmark = 0, + .fwmark_set = false, // just to be deterministic + + // only available with fping version >= 5.3 + .icmp_timestamp = false, + .check_source = false, + }; return tmp; } -- cgit v1.2.3-74-g34f1 From f2c6ce08e3da320d044564352faedd78eb76f1a1 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle Date: Thu, 12 Jun 2025 11:19:42 +0200 Subject: check_fping: small style improvement --- plugins/check_fping.c | 4 ++-- plugins/check_fping.d/config.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 4d328a01..c1e7dd17 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -132,7 +132,7 @@ int main(int argc, char **argv) { char *command_line = NULL; if (config.icmp_timestamp) { - // no paket size settable for ICMP timestamp + // no packet size settable for ICMP timestamp xasprintf(&command_line, "%s %s -c %d %s", fping_prog, option_string, config.packet_count, server); } else { xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, config.packet_size, config.packet_count, server); @@ -346,7 +346,7 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) { argc--; } - while (1) { + while (true) { int option_index = getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:M:R:46", longopts, &option); if (option_index == -1 || option_index == EOF || option_index == 1) { diff --git a/plugins/check_fping.d/config.h b/plugins/check_fping.d/config.h index 6d28382a..d95e9ded 100644 --- a/plugins/check_fping.d/config.h +++ b/plugins/check_fping.d/config.h @@ -32,7 +32,7 @@ typedef struct { // only available with fping version >= 5.2 // for a given uint _fwmark_ fping sets _fwmark_ as a firewall mark - // in the pakets + // in the packets unsigned int fwmark; bool fwmark_set; -- cgit v1.2.3-74-g34f1 From 19f409ac559278cd8623e2d5875818938f648996 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle Date: Thu, 12 Jun 2025 13:26:55 +0200 Subject: Remove unnecessary newline --- plugins/check_fping.c | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/check_fping.c b/plugins/check_fping.c index c1e7dd17..5db6b9aa 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -320,7 +320,6 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) { // only available with fping version >= 5.3 {"icmp-timestamp", no_argument, NULL, ICMP_TIMESTAMP_OPT}, {"check-source", no_argument, NULL, CHECK_SOURCE_OPT}, - {0, 0, 0, 0}}; char *rv[2]; -- cgit v1.2.3-74-g34f1 From a669b2531d3b01aeb5b3e39c28bf2e6816fb14af Mon Sep 17 00:00:00 2001 From: Lorenz Kästle Date: Thu, 12 Jun 2025 13:33:50 +0200 Subject: Remove options if fping version is too low and die directly --- plugins/check_fping.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 5db6b9aa..8018e06d 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -315,11 +315,15 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) { {"use-ipv6", no_argument, 0, '6'}, {"dontfrag", no_argument, 0, 'M'}, {"random", no_argument, 0, 'R'}, - // only available with fping version >= 5.3 +#ifdef FPING_VERSION_5_2_OR_HIGHER + // only available with fping version >= 5.2 {"fwmark", required_argument, NULL, FWMARK_OPT}, +# ifdef FPING_VERSION_5_3_OR_HIGHER // only available with fping version >= 5.3 {"icmp-timestamp", no_argument, NULL, ICMP_TIMESTAMP_OPT}, {"check-source", no_argument, NULL, CHECK_SOURCE_OPT}, +# endif +#endif {0, 0, 0, 0}}; char *rv[2]; -- cgit v1.2.3-74-g34f1