diff options
Diffstat (limited to 'plugins-root/check_icmp.d/check_icmp_helpers.c')
-rw-r--r-- | plugins-root/check_icmp.d/check_icmp_helpers.c | 142 |
1 files changed, 142 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 | } | ||