diff options
author | William <william@blackhats.net.au> | 2025-03-27 11:20:36 +1000 |
---|---|---|
committer | William <william@blackhats.net.au> | 2025-05-07 13:15:51 +1000 |
commit | 4acba2b3ecef7c1482b3cd25e35773947d80e2c6 (patch) | |
tree | 800482e66fca02634adc3d85ab538188e608d154 /plugins/check_fping.c | |
parent | 35d957fa5c07660e0fc1254edd3aa625576504c2 (diff) | |
download | monitoring-plugins-4acba2b3ecef7c1482b3cd25e35773947d80e2c6.tar.gz |
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.
Diffstat (limited to 'plugins/check_fping.c')
-rw-r--r-- | plugins/check_fping.c | 33 |
1 files changed, 22 insertions, 11 deletions
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) { | |||
79 | server = strscpy(server, config.server_name); | 79 | server = strscpy(server, config.server_name); |
80 | 80 | ||
81 | char *option_string = ""; | 81 | char *option_string = ""; |
82 | char *fping_prog = NULL; | ||
83 | |||
82 | /* compose the command */ | 84 | /* compose the command */ |
85 | #ifdef PATH_TO_FPING6 | ||
86 | if (address_family != AF_INET && is_inet6_addr(server)) { | ||
87 | fping_prog = strdup(PATH_TO_FPING6); | ||
88 | } else { | ||
89 | xasprintf(&option_string, "%s-4 ", option_string); | ||
90 | fping_prog = strdup(PATH_TO_FPING); | ||
91 | } | ||
92 | #else | ||
93 | if (address_family != AF_INET) { | ||
94 | // -4 / -6 must be set explicitly as when a host has dual stack | ||
95 | // if we don't specify -4 then fping selects ipv6 which can mess | ||
96 | // with some checks. | ||
97 | xasprintf(&option_string, "%s-6 ", option_string); | ||
98 | } else { | ||
99 | xasprintf(&option_string, "%s-4 ", option_string); | ||
100 | } | ||
101 | |||
102 | fping_prog = strdup(PATH_TO_FPING); | ||
103 | #endif | ||
104 | |||
83 | if (config.target_timeout) { | 105 | if (config.target_timeout) { |
84 | xasprintf(&option_string, "%s-t %d ", option_string, config.target_timeout); | 106 | xasprintf(&option_string, "%s-t %d ", option_string, config.target_timeout); |
85 | } | 107 | } |
@@ -99,17 +121,6 @@ int main(int argc, char **argv) { | |||
99 | xasprintf(&option_string, "%s-R ", option_string); | 121 | xasprintf(&option_string, "%s-R ", option_string); |
100 | } | 122 | } |
101 | 123 | ||
102 | char *fping_prog = NULL; | ||
103 | #ifdef PATH_TO_FPING6 | ||
104 | if (address_family != AF_INET && is_inet6_addr(server)) { | ||
105 | fping_prog = strdup(PATH_TO_FPING6); | ||
106 | } else { | ||
107 | fping_prog = strdup(PATH_TO_FPING); | ||
108 | } | ||
109 | #else | ||
110 | fping_prog = strdup(PATH_TO_FPING); | ||
111 | #endif | ||
112 | |||
113 | char *command_line = NULL; | 124 | char *command_line = NULL; |
114 | xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, config.packet_size, config.packet_count, server); | 125 | xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, config.packet_size, config.packet_count, server); |
115 | 126 | ||