From 5fd8191a50df6be712c9143ca6d73de7878f57d1 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 5 May 2025 22:52:56 +0200 Subject: WIP - check_icmp refactor 3 --- plugins-root/check_icmp.d/check_icmp_helpers.c | 25 +++++------ plugins-root/check_icmp.d/config.h | 58 +++++++++++++------------- 2 files changed, 43 insertions(+), 40 deletions(-) (limited to 'plugins-root/check_icmp.d') diff --git a/plugins-root/check_icmp.d/check_icmp_helpers.c b/plugins-root/check_icmp.d/check_icmp_helpers.c index 2efe6e59..2a521b04 100644 --- a/plugins-root/check_icmp.d/check_icmp_helpers.c +++ b/plugins-root/check_icmp.d/check_icmp_helpers.c @@ -10,8 +10,6 @@ unsigned int timeout = DEFAULT_TIMEOUT; check_icmp_config check_icmp_config_init() { check_icmp_config tmp = { - .source_ip = NULL, - .order_mode = false, .mos_mode = false, .rta_mode = false, @@ -20,10 +18,6 @@ check_icmp_config check_icmp_config_init() { .score_mode = false, .min_hosts_alive = -1, - .icmp_data_size = DEFAULT_PING_DATA_SIZE, - .icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN, - .pkt_interval = DEFAULT_PKT_INTERVAL, - .target_interval = 0, .crit = {.pl = DEFAULT_CRIT_PL, .rta = DEFAULT_CRIT_RTA, .jitter = 50.0, @@ -34,11 +28,18 @@ check_icmp_config check_icmp_config_init() { .jitter = 40.0, .mos = 3.5, .score = 80.0}, - .pid = {}, - .mode = MODE_RTA, + .ttl = DEFAULT_TTL, + .icmp_data_size = DEFAULT_PING_DATA_SIZE, + .icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN, + .pkt_interval = DEFAULT_PKT_INTERVAL, + .target_interval = 0, + .number_of_packets = DEFAULT_NUMBER_OF_PACKETS, + .source_ip = NULL, + + .sender_id = {}, - .packets = DEFAULT_NUMBER_OF_PACKETS, + .mode = MODE_RTA, .number_of_targets = 0, .targets = NULL, @@ -168,10 +169,10 @@ unsigned int ping_target_list_append(ping_target *list, ping_target *elem) { return result; } -void check_icmp_timeout_handler(int signal, siginfo_t * info, void *ucontext) { +void check_icmp_timeout_handler(int signal, siginfo_t *info, void *ucontext) { // Ignore unused arguments - (void) info; - (void) ucontext; + (void)info; + (void)ucontext; mp_subcheck timeout_sc = mp_subcheck_init(); timeout_sc = mp_set_subcheck_state(timeout_sc, socket_timeout_state); diff --git a/plugins-root/check_icmp.d/config.h b/plugins-root/check_icmp.d/config.h index deae9bec..3599c0f0 100644 --- a/plugins-root/check_icmp.d/config.h +++ b/plugins-root/check_icmp.d/config.h @@ -10,20 +10,38 @@ #include #include #include +#include #include "./check_icmp_helpers.h" /* threshold structure. all values are maximum allowed, exclusive */ -typedef struct threshold { +typedef struct { unsigned char pl; /* max allowed packet loss in percent */ unsigned int rta; /* roundtrip time average, microseconds */ double jitter; /* jitter time average, microseconds */ double mos; /* MOS */ double score; /* Score */ -} threshold; +} check_icmp_threshold; -typedef struct { - char *source_ip; +/* the different modes of this program are as follows: + * MODE_RTA: send all packets no matter what (mimic check_icmp and check_ping) + * MODE_HOSTCHECK: Return immediately upon any sign of life + * In addition, sends packets to ALL addresses assigned + * to this host (as returned by gethostbyname() or + * gethostbyaddr() and expects one host only to be checked at + * a time. Therefore, any packet response what so ever will + * count as a sign of life, even when received outside + * crit.rta limit. Do not misspell any additional IP's. + * MODE_ALL: Requires packets from ALL requested IP to return OK (default). + * MODE_ICMP: Default Mode + */ +typedef enum { + MODE_RTA, + MODE_HOSTCHECK, + MODE_ALL, + MODE_ICMP, +} check_icmp_execution_mode; +typedef struct { bool order_mode; bool mos_mode; bool rta_mode; @@ -32,18 +50,20 @@ typedef struct { bool score_mode; int min_hosts_alive; + check_icmp_threshold crit; + check_icmp_threshold warn; + + unsigned long ttl; unsigned short icmp_data_size; unsigned short icmp_pkt_size; unsigned int pkt_interval; unsigned int target_interval; - threshold crit; - threshold warn; - pid_t pid; + unsigned short number_of_packets; + char *source_ip; - int mode; - unsigned long ttl; + uint16_t sender_id; // PID of the main process, which is used as an ID in packets - unsigned short packets; + check_icmp_execution_mode mode; unsigned short number_of_targets; ping_target *targets; @@ -78,24 +98,6 @@ typedef struct icmp_ping_data { #define DEFAULT_TIMEOUT 10 #define DEFAULT_TTL 64 -/* the different modes of this program are as follows: - * MODE_RTA: send all packets no matter what (mimic check_icmp and check_ping) - * MODE_HOSTCHECK: Return immediately upon any sign of life - * In addition, sends packets to ALL addresses assigned - * to this host (as returned by gethostbyname() or - * gethostbyaddr() and expects one host only to be checked at - * a time. Therefore, any packet response what so ever will - * count as a sign of life, even when received outside - * crit.rta limit. Do not misspell any additional IP's. - * MODE_ALL: Requires packets from ALL requested IP to return OK (default). - * MODE_ICMP: implement something similar to check_icmp (MODE_RTA without - * tcp and udp args does this) - */ -#define MODE_RTA 0 -#define MODE_HOSTCHECK 1 -#define MODE_ALL 2 -#define MODE_ICMP 3 - #define DEFAULT_NUMBER_OF_PACKETS 5 #define PACKET_BACKOFF_FACTOR 1.5 -- cgit v1.2.3-74-g34f1