From 4acba2b3ecef7c1482b3cd25e35773947d80e2c6 Mon Sep 17 00:00:00 2001 From: William Date: Thu, 27 Mar 2025 11:20:36 +1000 Subject: Improve handling of -4/-6 If fping is used with a target that has dual stack v4/v6, then due to the logic during command construction, ipv4 will never be checked as v6 is preferred by fping. This explicitly flags -4/-6 when it is requested by the user. --- plugins/check_fping.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'plugins/check_fping.c') diff --git a/plugins/check_fping.c b/plugins/check_fping.c index ec7abb67..1c2b7689 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -79,7 +79,29 @@ int main(int argc, char **argv) { server = strscpy(server, config.server_name); char *option_string = ""; + char *fping_prog = NULL; + /* compose the command */ +#ifdef PATH_TO_FPING6 + if (address_family != AF_INET && is_inet6_addr(server)) { + fping_prog = strdup(PATH_TO_FPING6); + } else { + xasprintf(&option_string, "%s-4 ", option_string); + fping_prog = strdup(PATH_TO_FPING); + } +#else + if (address_family != AF_INET) { + // -4 / -6 must be set explicitly as when a host has dual stack + // if we don't specify -4 then fping selects ipv6 which can mess + // with some checks. + xasprintf(&option_string, "%s-6 ", option_string); + } else { + xasprintf(&option_string, "%s-4 ", option_string); + } + + fping_prog = strdup(PATH_TO_FPING); +#endif + if (config.target_timeout) { xasprintf(&option_string, "%s-t %d ", option_string, config.target_timeout); } @@ -99,17 +121,6 @@ int main(int argc, char **argv) { xasprintf(&option_string, "%s-R ", option_string); } - char *fping_prog = NULL; -#ifdef PATH_TO_FPING6 - if (address_family != AF_INET && is_inet6_addr(server)) { - fping_prog = strdup(PATH_TO_FPING6); - } else { - fping_prog = strdup(PATH_TO_FPING); - } -#else - fping_prog = strdup(PATH_TO_FPING); -#endif - 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); -- cgit v1.2.3-74-g34f1 From a1472be88322140cf1f2fc39b9e1b654a86f8155 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 28 Mar 2025 12:40:35 +1000 Subject: Harden check with unspec --- plugins/check_fping.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/check_fping.c') diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 1c2b7689..cf9c2d1c 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -83,14 +83,14 @@ int main(int argc, char **argv) { /* compose the command */ #ifdef PATH_TO_FPING6 - if (address_family != AF_INET && is_inet6_addr(server)) { + if (address_family == AF_INET6 || (address_family == AF_UNSPEC && is_inet6_addr(server))) { fping_prog = strdup(PATH_TO_FPING6); } else { xasprintf(&option_string, "%s-4 ", option_string); fping_prog = strdup(PATH_TO_FPING); } #else - if (address_family != AF_INET) { + if (address_family == AF_INET6 || (address_family == AF_UNSPEC && is_inet6_addr(server))) { // -4 / -6 must be set explicitly as when a host has dual stack // if we don't specify -4 then fping selects ipv6 which can mess // with some checks. -- cgit v1.2.3-74-g34f1 From 58a34245110f12192d3b3e99198086c119a57418 Mon Sep 17 00:00:00 2001 From: William Date: Wed, 2 Apr 2025 10:50:56 +1000 Subject: Improve logic --- plugins/check_fping.c | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'plugins/check_fping.c') diff --git a/plugins/check_fping.c b/plugins/check_fping.c index cf9c2d1c..9dadcec7 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -81,27 +81,61 @@ int main(int argc, char **argv) { char *option_string = ""; char *fping_prog = NULL; - /* compose the command */ + /* First determine if the target is dualstack or ipv6 only. */ +#ifdef USE_IPV6 + bool server_is_inet6_addr = is_inet6_addr(server); +#else + bool server_is_inet6_addr = false; +#endif + + /* PATH_TO_FPING6 implies USE_IPV6 */ #ifdef PATH_TO_FPING6 - if (address_family == AF_INET6 || (address_family == AF_UNSPEC && is_inet6_addr(server))) { + /* + * If the user requested -6 OR the user made no assertion and the address is v6 or dualstack + * -> we use ipv6 + * If the user requested -4 OR the user made no assertion and the address is v4 ONLY + * -> we use ipv4 + */ + if (address_family == AF_INET6 || (address_family == AF_UNSPEC && server_is_inet6_addr)) { fping_prog = strdup(PATH_TO_FPING6); } else { xasprintf(&option_string, "%s-4 ", option_string); fping_prog = strdup(PATH_TO_FPING); } #else - if (address_family == AF_INET6 || (address_family == AF_UNSPEC && is_inet6_addr(server))) { - // -4 / -6 must be set explicitly as when a host has dual stack - // if we don't specify -4 then fping selects ipv6 which can mess - // with some checks. +#ifdef USE_IPV6 + /* + * If the user requested -6 OR the user made no assertion and the address is v6 or dualstack + * -> we use ipv6 + * If the user requested -4 OR the user made no assertion and the address is v4 ONLY + * -> we use ipv4 + */ + if (address_family == AF_INET6 || (address_family == AF_UNSPEC && server_is_inet6_addr)) { xasprintf(&option_string, "%s-6 ", option_string); } else { xasprintf(&option_string, "%s-4 ", option_string); } - +#else + /* + * If the user requested -6 + * -> warn that v6 is not available + * -> we use ipv4 + */ + if (address_family == AF_INET6) { + usage4(_("IPv6 support not available")); + } + /* + * Note here we still have to call with -4, else in the case of a dual stacked target + * we could potentially silently use ipv6 despite having just warned that it is not available + */ + xasprintf(&option_string, "%s-4 ", option_string); + /* end USE_IPV6 */ +#endif fping_prog = strdup(PATH_TO_FPING); + /* end PATH_TO_FPING6 */ #endif + /* compose the command */ if (config.target_timeout) { xasprintf(&option_string, "%s-t %d ", option_string, config.target_timeout); } -- cgit v1.2.3-74-g34f1 From 1fb9300a2f10d5c649df484e1b8d7550f9a5f846 Mon Sep 17 00:00:00 2001 From: William Date: Wed, 7 May 2025 13:17:47 +1000 Subject: Remove un-needed flags --- configure.ac | 7 ------- plugins/check_fping.c | 42 ------------------------------------------ 2 files changed, 49 deletions(-) (limited to 'plugins/check_fping.c') diff --git a/configure.ac b/configure.ac index fdc9b699..bd3de196 100644 --- a/configure.ac +++ b/configure.ac @@ -1524,17 +1524,10 @@ AC_PATH_PROG(PATH_TO_FPING6,fping6) AC_ARG_WITH(fping_command, ACX_HELP_STRING([--with-fping-command=PATH], [Path to fping command]), PATH_TO_FPING=$withval) -AC_ARG_WITH(fping6_command, - ACX_HELP_STRING([--with-fping6-command=PATH], - [Path to fping6 command]), PATH_TO_FPING6=$withval) - 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 x"$with_ipv6" != xno && test -n "$PATH_TO_FPING6"; then - AC_DEFINE_UNQUOTED(PATH_TO_FPING6,"$PATH_TO_FPING6",[path to fping6]) - fi else AC_MSG_WARN([Get fping from http://www.fping.com in order to make check_fping plugin]) fi diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 9dadcec7..e05056b2 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -82,28 +82,8 @@ int main(int argc, char **argv) { char *fping_prog = NULL; /* First determine if the target is dualstack or ipv6 only. */ -#ifdef USE_IPV6 bool server_is_inet6_addr = is_inet6_addr(server); -#else - bool server_is_inet6_addr = false; -#endif - /* PATH_TO_FPING6 implies USE_IPV6 */ -#ifdef PATH_TO_FPING6 - /* - * If the user requested -6 OR the user made no assertion and the address is v6 or dualstack - * -> we use ipv6 - * If the user requested -4 OR the user made no assertion and the address is v4 ONLY - * -> we use ipv4 - */ - if (address_family == AF_INET6 || (address_family == AF_UNSPEC && server_is_inet6_addr)) { - fping_prog = strdup(PATH_TO_FPING6); - } else { - xasprintf(&option_string, "%s-4 ", option_string); - fping_prog = strdup(PATH_TO_FPING); - } -#else -#ifdef USE_IPV6 /* * If the user requested -6 OR the user made no assertion and the address is v6 or dualstack * -> we use ipv6 @@ -115,25 +95,7 @@ int main(int argc, char **argv) { } else { xasprintf(&option_string, "%s-4 ", option_string); } -#else - /* - * If the user requested -6 - * -> warn that v6 is not available - * -> we use ipv4 - */ - if (address_family == AF_INET6) { - usage4(_("IPv6 support not available")); - } - /* - * Note here we still have to call with -4, else in the case of a dual stacked target - * we could potentially silently use ipv6 despite having just warned that it is not available - */ - xasprintf(&option_string, "%s-4 ", option_string); - /* end USE_IPV6 */ -#endif fping_prog = strdup(PATH_TO_FPING); - /* end PATH_TO_FPING6 */ -#endif /* compose the command */ if (config.target_timeout) { @@ -385,11 +347,7 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) { address_family = AF_INET; break; case '6': /* IPv6 only */ -#ifdef USE_IPV6 address_family = AF_INET6; -#else - usage(_("IPv6 support not available\n")); -#endif break; case 'c': get_threshold(optarg, rv); -- cgit v1.2.3-74-g34f1