diff options
Diffstat (limited to 'plugins-root/check_icmp.d')
| -rw-r--r-- | plugins-root/check_icmp.d/check_icmp_helpers.c | 142 | ||||
| -rw-r--r-- | plugins-root/check_icmp.d/check_icmp_helpers.h | 73 |
2 files changed, 215 insertions, 0 deletions
diff --git a/plugins-root/check_icmp.d/check_icmp_helpers.c b/plugins-root/check_icmp.d/check_icmp_helpers.c new file mode 100644 index 00000000..8f6d7362 --- /dev/null +++ b/plugins-root/check_icmp.d/check_icmp_helpers.c | |||
| @@ -0,0 +1,142 @@ | |||
| 1 | #include "./config.h" | ||
| 2 | #include "states.h" | ||
| 3 | #include <math.h> | ||
| 4 | #include <netinet/in.h> | ||
| 5 | #include "./check_icmp_helpers.h" | ||
| 6 | #include "../../plugins/netutils.h" | ||
| 7 | |||
| 8 | check_icmp_config check_icmp_config_init() { | ||
| 9 | check_icmp_config tmp = { | ||
| 10 | .source_ip = NULL, | ||
| 11 | |||
| 12 | .order_mode = false, | ||
| 13 | .mos_mode = false, | ||
| 14 | .rta_mode = false, | ||
| 15 | .pl_mode = false, | ||
| 16 | .jitter_mode = false, | ||
| 17 | .score_mode = false, | ||
| 18 | |||
| 19 | .min_hosts_alive = -1, | ||
| 20 | .icmp_data_size = DEFAULT_PING_DATA_SIZE, | ||
| 21 | .icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN, | ||
| 22 | .pkt_interval = DEFAULT_PKT_INTERVAL, | ||
| 23 | .target_interval = 0, | ||
| 24 | .crit = {.pl = DEFAULT_CRIT_PL, | ||
| 25 | .rta = DEFAULT_CRIT_RTA, | ||
| 26 | .jitter = 50.0, | ||
| 27 | .mos = 3.0, | ||
| 28 | .score = 70.0}, | ||
| 29 | .warn = {.pl = DEFAULT_WARN_PL, | ||
| 30 | .rta = DEFAULT_WARN_RTA, | ||
| 31 | .jitter = 40.0, | ||
| 32 | .mos = 3.5, | ||
| 33 | .score = 80.0}, | ||
| 34 | .pid = {}, | ||
| 35 | .mode = MODE_RTA, | ||
| 36 | .timeout = DEFAULT_TIMEOUT, | ||
| 37 | .ttl = DEFAULT_TTL, | ||
| 38 | |||
| 39 | .packets = DEFAULT_NUMBER_OF_PACKETS, | ||
| 40 | .number_of_targets = 0, | ||
| 41 | .hosts = NULL, | ||
| 42 | }; | ||
| 43 | return tmp; | ||
| 44 | } | ||
| 45 | |||
| 46 | ping_target ping_target_init() { | ||
| 47 | ping_target tmp = { | ||
| 48 | .rtmin = INFINITY, | ||
| 49 | |||
| 50 | .jitter_min = INFINITY, | ||
| 51 | |||
| 52 | .rta_status = STATE_OK, | ||
| 53 | .jitter_status = STATE_OK, | ||
| 54 | .mos_status = STATE_OK, | ||
| 55 | .score_status = STATE_OK, | ||
| 56 | .pl_status = STATE_OK, | ||
| 57 | .order_status = STATE_OK, | ||
| 58 | }; | ||
| 59 | |||
| 60 | return tmp; | ||
| 61 | } | ||
| 62 | |||
| 63 | check_icmp_state check_icmp_state_init() { | ||
| 64 | check_icmp_state tmp = {.icmp_sent = 0, .icmp_lost = 0, .icmp_recv = 0, .targets_down = 0}; | ||
| 65 | |||
| 66 | return tmp; | ||
| 67 | } | ||
| 68 | |||
| 69 | rta_host_create_wrapper rta_host_create(char *name, struct sockaddr_storage *address) { | ||
| 70 | struct sockaddr_in *sin; | ||
| 71 | struct sockaddr_in6 *sin6; | ||
| 72 | if (address_family == AF_INET) { | ||
| 73 | sin = (struct sockaddr_in *)address; | ||
| 74 | } else { | ||
| 75 | sin6 = (struct sockaddr_in6 *)address; | ||
| 76 | } | ||
| 77 | |||
| 78 | rta_host_create_wrapper result = { | ||
| 79 | .errorcode = OK, | ||
| 80 | }; | ||
| 81 | |||
| 82 | /* disregard obviously stupid addresses | ||
| 83 | * (I didn't find an ipv6 equivalent to INADDR_NONE) */ | ||
| 84 | if (((address_family == AF_INET && | ||
| 85 | (sin->sin_addr.s_addr == INADDR_NONE || sin->sin_addr.s_addr == INADDR_ANY))) || | ||
| 86 | (address_family == AF_INET6 && (sin6->sin6_addr.s6_addr == in6addr_any.s6_addr))) { | ||
| 87 | result.errorcode = ERROR; | ||
| 88 | return result; | ||
| 89 | } | ||
| 90 | |||
| 91 | // TODO: Maybe add the following back in as a sanity check for the config | ||
| 92 | // /* no point in adding two identical IP's, so don't. ;) */ | ||
| 93 | // struct sockaddr_in *host_sin; | ||
| 94 | // struct sockaddr_in6 *host_sin6; | ||
| 95 | // struct rta_host *host = host_list; | ||
| 96 | |||
| 97 | // while (host) { | ||
| 98 | // host_sin = (struct sockaddr_in *)&host->saddr_in; | ||
| 99 | // host_sin6 = (struct sockaddr_in6 *)&host->saddr_in; | ||
| 100 | |||
| 101 | // if ((address_family == AF_INET && host_sin->sin_addr.s_addr == sin->sin_addr.s_addr) || | ||
| 102 | // (address_family == AF_INET6 && | ||
| 103 | // host_sin6->sin6_addr.s6_addr == sin6->sin6_addr.s6_addr)) { | ||
| 104 | // if (debug) { | ||
| 105 | // printf("Identical IP already exists. Not adding %s\n", name); | ||
| 106 | // } | ||
| 107 | // return -1; | ||
| 108 | // } | ||
| 109 | // host = host->next; | ||
| 110 | // } | ||
| 111 | |||
| 112 | /* add the fresh ip */ | ||
| 113 | ping_target host = ping_target_init(); | ||
| 114 | |||
| 115 | /* set the values. use calling name for output */ | ||
| 116 | host.name = strdup(name); | ||
| 117 | |||
| 118 | /* fill out the sockaddr_storage struct */ | ||
| 119 | if (address_family == AF_INET) { | ||
| 120 | struct sockaddr_in *host_sin = (struct sockaddr_in *)&host.saddr_in; | ||
| 121 | host_sin->sin_family = AF_INET; | ||
| 122 | host_sin->sin_addr.s_addr = sin->sin_addr.s_addr; | ||
| 123 | } else { | ||
| 124 | struct sockaddr_in6 *host_sin6 = (struct sockaddr_in6 *)&host.saddr_in; | ||
| 125 | host_sin6->sin6_family = AF_INET6; | ||
| 126 | memcpy(host_sin6->sin6_addr.s6_addr, sin6->sin6_addr.s6_addr, | ||
| 127 | sizeof host_sin6->sin6_addr.s6_addr); | ||
| 128 | } | ||
| 129 | |||
| 130 | result.host = host; | ||
| 131 | |||
| 132 | return result; | ||
| 133 | } | ||
| 134 | |||
| 135 | check_icmp_target_container check_icmp_target_container_init() { | ||
| 136 | check_icmp_target_container tmp = { | ||
| 137 | .name = NULL, | ||
| 138 | .number_of_targets = 0, | ||
| 139 | .target_list = NULL, | ||
| 140 | }; | ||
| 141 | return tmp; | ||
| 142 | } | ||
diff --git a/plugins-root/check_icmp.d/check_icmp_helpers.h b/plugins-root/check_icmp.d/check_icmp_helpers.h new file mode 100644 index 00000000..49f720ec --- /dev/null +++ b/plugins-root/check_icmp.d/check_icmp_helpers.h | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "../../lib/states.h" | ||
| 4 | #include <netinet/in_systm.h> | ||
| 5 | #include <netinet/in.h> | ||
| 6 | #include <netinet/ip.h> | ||
| 7 | #include <netinet/ip6.h> | ||
| 8 | #include <netinet/ip_icmp.h> | ||
| 9 | #include <netinet/icmp6.h> | ||
| 10 | #include <arpa/inet.h> | ||
| 11 | |||
| 12 | typedef struct rta_host { | ||
| 13 | unsigned short id; /* id in **table, and icmp pkts */ | ||
| 14 | char *name; /* arg used for adding this host */ | ||
| 15 | char *msg; /* icmp error message, if any */ | ||
| 16 | struct sockaddr_storage saddr_in; /* the address of this host */ | ||
| 17 | struct sockaddr_storage error_addr; /* stores address of error replies */ | ||
| 18 | unsigned long long time_waited; /* total time waited, in usecs */ | ||
| 19 | unsigned int icmp_sent, icmp_recv, icmp_lost; /* counters */ | ||
| 20 | unsigned char icmp_type, icmp_code; /* type and code from errors */ | ||
| 21 | unsigned short flags; /* control/status flags */ | ||
| 22 | |||
| 23 | double rta; /* measured RTA */ | ||
| 24 | double rtmax; /* max rtt */ | ||
| 25 | double rtmin; /* min rtt */ | ||
| 26 | |||
| 27 | double jitter; /* measured jitter */ | ||
| 28 | double jitter_max; /* jitter rtt maximum */ | ||
| 29 | double jitter_min; /* jitter rtt minimum */ | ||
| 30 | |||
| 31 | double EffectiveLatency; | ||
| 32 | double mos; /* Mean opinion score */ | ||
| 33 | double score; /* score */ | ||
| 34 | |||
| 35 | unsigned int last_tdiff; | ||
| 36 | unsigned int last_icmp_seq; /* Last ICMP_SEQ to check out of order pkts */ | ||
| 37 | unsigned char pl; /* measured packet loss */ | ||
| 38 | |||
| 39 | mp_state_enum rta_status; // check result for RTA checks | ||
| 40 | mp_state_enum jitter_status; // check result for Jitter checks | ||
| 41 | mp_state_enum mos_status; // check result for MOS checks | ||
| 42 | mp_state_enum score_status; // check result for score checks | ||
| 43 | mp_state_enum pl_status; // check result for packet loss checks | ||
| 44 | mp_state_enum order_status; // check result for packet order checks | ||
| 45 | |||
| 46 | struct rta_host *next; | ||
| 47 | } ping_target; | ||
| 48 | |||
| 49 | ping_target ping_target_init(); | ||
| 50 | |||
| 51 | typedef struct { | ||
| 52 | char *name; | ||
| 53 | ping_target *target_list; | ||
| 54 | unsigned int number_of_targets; | ||
| 55 | } check_icmp_target_container; | ||
| 56 | |||
| 57 | check_icmp_target_container check_icmp_target_container_init(); | ||
| 58 | |||
| 59 | typedef struct { | ||
| 60 | unsigned int icmp_sent; | ||
| 61 | unsigned int icmp_recv; | ||
| 62 | unsigned int icmp_lost; | ||
| 63 | unsigned short targets_down; | ||
| 64 | } check_icmp_state; | ||
| 65 | |||
| 66 | check_icmp_state check_icmp_state_init(); | ||
| 67 | |||
| 68 | typedef struct { | ||
| 69 | int errorcode; | ||
| 70 | ping_target host; | ||
| 71 | } rta_host_create_wrapper; | ||
| 72 | |||
| 73 | rta_host_create_wrapper rta_host_create(char *name, struct sockaddr_storage *address); | ||
