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