root/src/modules/ping_icmp.c

Revision b553f9a4d73487ee85e5cfedf2cd67352b4d5e6b, 19.3 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 3 years ago)

refs #340

This is a rather major change. Targets can now be hostnames in addition
to IP addresses so long as //checks/@resolve_targets is not false.

If a target is entered that does not look like an IP (inet_pton fails)
then the check is marked as needing resolution NP_RESOLVE.

A passive look-aside dns cache has been implemented in noit_check_resolver.c
that is used to power the whole system and some reasonably simply console
command have been provided:

show dns_cache [fqdn1 [fqdn2]] -- shows the state
dns_cache <fqdn> [fqdn2 [fqdn3]] -- submits for lookup
no dns_cache <fqdn> [fqdn2 [fqdn3]] -- purges from cache

The big change is that modules that relied on check->target to be an IP
address are going to explode when names are provided. Instead, modules
should now use target for the provided target (possibly a FQDN) and use
target_ip (check->target_ip or check.target_ip) for a resolved IP address
and also check for the case of empty string: (check->target_ip[0] == '\0')
for the case that resolution has failed. In lua, the target_ip will be
presented as nil in the case of failed name resolution.

I believe I've updated all necessary components of the system for this to
"just work" but people that have implemented their own check should update
them before they elect to use non-IP addresses as targets.

The dns subsystem supports both IPv4 and IPv6, but currently prefers IPv4
addresses if any are present.

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #include "noit_defines.h"
34
35 #include <stdio.h>
36 #include <unistd.h>
37 #include <netdb.h>
38 #include <errno.h>
39 #include <fcntl.h>
40 #ifdef HAVE_SYS_FILIO_H
41 #include <sys/filio.h>
42 #endif
43 #ifdef HAVE_NETINET_IN_SYSTM_H
44 #include <netinet/in_systm.h>
45 #endif
46 #include <netinet/in.h>
47 #include <netinet/ip.h>
48 #include <netinet/ip_icmp.h>
49 #include <math.h>
50 #ifndef MAXFLOAT
51 #include <float.h>
52 #define MAXFLOAT FLT_MAX
53 #endif
54
55 #include "noit_module.h"
56 #include "noit_check.h"
57 #include "noit_check_tools.h"
58 #include "utils/noit_log.h"
59
60 #define PING_INTERVAL 2000 /* 2000ms = 2s */
61 #define PING_COUNT    5
62
63 struct check_info {
64   int check_no;
65   int check_seq_no;
66   int seq;
67   int32_t expected_count;
68   float *turnaround;
69   eventer_t timeout_event;
70 };
71 struct ping_session_key {
72   void  *addr_of_check; /* ticket #288 */
73   uuid_t checkid;
74 };
75 struct ping_payload {
76   void  *addr_of_check; /* ticket #288 */
77   uuid_t checkid;
78   u_int32_t generation;   
79   struct timeval whence;
80   int    check_no;
81   int    check_pack_no;
82   int    check_pack_cnt;
83 };
84 struct ping_closure {
85   noit_module_t *self;
86   noit_check_t *check;
87   void *payload;
88   int payload_len;
89 };
90 static noit_log_stream_t nlerr = NULL;
91 static noit_log_stream_t nldeb = NULL;
92 static int in_cksum(u_short *addr, int len);
93
94 typedef struct  {
95   int ipv4_fd;
96   int ipv6_fd;
97   noit_hash_table *in_flight;
98 } ping_icmp_data_t;
99
100 static int ping_icmp_config(noit_module_t *self, noit_hash_table *options) {
101   return 0;
102 }
103 static int ping_icmp_is_complete(noit_module_t *self, noit_check_t *check) {
104   int i;
105   struct check_info *data;
106   data = (struct check_info *)check->closure;
107   for(i=0; i<data->expected_count; i++)
108     if(data->turnaround[i] < 0.0) {
109       noitL(nldeb, "ping_icmp: %s %d is still outstanding.\n",
110             check->target_ip, i);
111       return 0;
112     }
113   return 1;
114 }
115 static void ping_icmp_log_results(noit_module_t *self, noit_check_t *check) {
116   struct check_info *data;
117   double avail, min = MAXFLOAT, max = 0.0, avg = 0.0, cnt;
118   int avail_needed = 100;
119   const char *config_val = NULL;
120   int i, points = 0;
121   char human_buffer[256];
122   stats_t current;
123   struct timeval duration;
124
125   noit_check_stats_clear(&current);
126
127   data = (struct check_info *)check->closure;
128   for(i=0; i<data->expected_count; i++) {
129     if(data->turnaround[i] >= 0.0) {
130       points++;
131       avg += data->turnaround[i];
132       if(data->turnaround[i] > max) max = data->turnaround[i];
133       if(data->turnaround[i] < min) min = data->turnaround[i];
134     }
135   }
136   if(points == 0) {
137     min = 0.0 / 0.0;
138     max = 0.0 / 0.0;
139   }
140   cnt = data->expected_count;
141   avail = (float)points /cnt;
142   avg /= (float)points;
143
144   if(noit_hash_retr_str(check->config, "avail_needed", strlen("avail_needed"),
145                         &config_val))
146     avail_needed = atoi(config_val);
147
148   snprintf(human_buffer, sizeof(human_buffer),
149            "cnt=%d,avail=%0.0f,min=%0.4f,max=%0.4f,avg=%0.4f",
150            (int)cnt, 100.0*avail, min, max, avg);
151   noitL(nldeb, "ping_icmp(%s) [%s]\n", check->target_ip, human_buffer);
152
153   gettimeofday(&current.whence, NULL);
154   sub_timeval(current.whence, check->last_fire_time, &duration);
155   current.duration = duration.tv_sec * 1000 + duration.tv_usec / 1000;
156   current.available = (avail > 0.0) ? NP_AVAILABLE : NP_UNAVAILABLE;
157   current.state = (avail < ((float)avail_needed / 100.0)) ? NP_BAD : NP_GOOD;
158   current.status = human_buffer;
159   noit_stats_set_metric(&current, "count",
160                         METRIC_INT32, &data->expected_count);
161   avail *= 100.0;
162   noit_stats_set_metric(&current, "available", METRIC_DOUBLE, &avail);
163   noit_stats_set_metric(&current, "minimum",
164                         METRIC_DOUBLE, avail > 0.0 ? &min : NULL);
165   noit_stats_set_metric(&current, "maximum",
166                         METRIC_DOUBLE, avail > 0.0 ? &max : NULL);
167   noit_stats_set_metric(&current, "average",
168                         METRIC_DOUBLE, avail > 0.0 ? &avg : NULL);
169   noit_check_set_stats(self, check, &current);
170 }
171 static int ping_icmp_timeout(eventer_t e, int mask,
172                              void *closure, struct timeval *now) {
173   struct ping_closure *pcl = (struct ping_closure *)closure;
174   struct ping_session_key k;
175   struct check_info *data;
176   ping_icmp_data_t *ping_data;
177
178   if(!NOIT_CHECK_KILLED(pcl->check) && !NOIT_CHECK_DISABLED(pcl->check)) {
179     ping_icmp_log_results(pcl->self, pcl->check);
180   }
181   data = (struct check_info *)pcl->check->closure;
182   data->timeout_event = NULL;
183   pcl->check->flags &= ~NP_RUNNING;
184   ping_data = noit_module_get_userdata(pcl->self);
185   k.addr_of_check = pcl->check;
186   uuid_copy(k.checkid, pcl->check->checkid);
187   noit_hash_delete(ping_data->in_flight, (const char *)&k, sizeof(k),
188                    free, NULL);
189   free(pcl);
190   return 0;
191 }
192 static int ping_icmp_handler(eventer_t e, int mask,
193                              void *closure, struct timeval *now) {
194   noit_module_t *self = (noit_module_t *)closure;
195   ping_icmp_data_t *ping_data;
196   struct check_info *data;
197   char packet[1500];
198   int packet_len = sizeof(packet);
199   union {
200    struct sockaddr_in  in4;
201    struct sockaddr_in6 in6;
202   } from;
203   unsigned int from_len;
204   struct ip *ip = (struct ip *)packet;
205   struct icmp *icp;
206   struct ping_payload *payload;
207
208   ping_data = noit_module_get_userdata(self);
209   while(1) {
210     struct ping_session_key k;
211     int inlen, iphlen;
212     void *vcheck;
213     noit_check_t *check;
214     struct timeval tt;
215
216     from_len = sizeof(from);
217
218     inlen = recvfrom(e->fd, packet, packet_len, 0,
219                      (struct sockaddr *)&from, &from_len);
220     gettimeofday(now, NULL); /* set it, as we care about accuracy */
221
222     if(inlen < 0) {
223       if(errno == EAGAIN || errno == EINTR) break;
224       noitLT(nlerr, now, "ping_icmp recvfrom: %s\n", strerror(errno));
225       break;
226     }
227     iphlen = ip->ip_hl << 2;
228     if((inlen-iphlen) != (sizeof(struct icmp)+sizeof(struct ping_payload))) {
229       noitLT(nldeb, now,
230              "ping_icmp bad size: %d+%d\n", iphlen, inlen-iphlen);
231       continue;
232     }
233     icp = (struct icmp *)(packet + iphlen);
234     payload = (struct ping_payload *)(icp + 1);
235     if(icp->icmp_type != ICMP_ECHOREPLY) {
236       continue;
237     }
238     if(icp->icmp_id != (((vpsized_uint)self) & 0xffff)) {
239       noitLT(nlerr, now,
240                "ping_icmp not sent from this instance (%d:%d) vs. %lu\n",
241                icp->icmp_id, ntohs(icp->icmp_seq),
242                (unsigned long)(((vpsized_uint)self) & 0xffff));
243       continue;
244     }
245     check = NULL;
246     k.addr_of_check = payload->addr_of_check;
247     uuid_copy(k.checkid, payload->checkid);
248     if(noit_hash_retrieve(ping_data->in_flight,
249                           (const char *)&k, sizeof(k),
250                           &vcheck))
251       check = vcheck;
252
253     /* make sure this check is from this generation! */
254     if(!check) {
255       char uuid_str[37];
256       uuid_unparse_lower(payload->checkid, uuid_str);
257       noitLT(nldeb, now,
258              "ping_icmp response for unknown check '%s'\n", uuid_str);
259       continue;
260     }
261     if(check->generation != payload->generation) {
262       noitLT(nldeb, now,
263              "ping_icmp response in generation gap\n");
264       continue;
265     }
266     data = (struct check_info *)check->closure;
267
268     /* If there is no timeout_event, the check must have completed.
269      * We have nothing to do. */
270     if(!data->timeout_event) continue;
271
272     /* Sanity check the payload */
273     if(payload->check_no != data->check_no) continue;
274     if(payload->check_pack_cnt != data->expected_count) continue;
275     if(payload->check_pack_no < 0 ||
276        payload->check_pack_no >= data->expected_count) continue;
277
278     sub_timeval(*now, payload->whence, &tt);
279     data->turnaround[payload->check_pack_no] =
280       (float)tt.tv_sec + (float)tt.tv_usec / 1000000.0;
281     if(ping_icmp_is_complete(self, check)) {
282       ping_icmp_log_results(self, check);
283       eventer_remove(data->timeout_event);
284       free(data->timeout_event->closure);
285       eventer_free(data->timeout_event);
286       data->timeout_event = NULL;
287       check->flags &= ~NP_RUNNING;
288       k.addr_of_check = check;
289       uuid_copy(k.checkid, check->checkid);
290       noit_hash_delete(ping_data->in_flight, (const char *)&k,
291                        sizeof(k), free, NULL);
292     }
293   }
294   return EVENTER_READ;
295 }
296
297 static int ping_icmp_init(noit_module_t *self) {
298   socklen_t on;
299   struct protoent *proto;
300   ping_icmp_data_t *data;
301
302   data = malloc(sizeof(*data));
303   data->in_flight = calloc(1, sizeof(*data->in_flight));
304   data->ipv4_fd = data->ipv6_fd = -1;
305
306   if ((proto = getprotobyname("icmp")) == NULL) {
307     noitL(noit_error, "Couldn't find 'icmp' protocol\n");
308     return -1;
309   }
310
311   data->ipv4_fd = socket(AF_INET, SOCK_RAW, proto->p_proto);
312   if(data->ipv4_fd < 0) {
313     noitL(noit_error, "ping_icmp: socket failed: %s\n",
314           strerror(errno));
315   }
316   else {
317     socklen_t slen = sizeof(on);
318     if(getsockopt(data->ipv4_fd, SOL_SOCKET, SO_SNDBUF, &on, &slen) == 0) {
319       if(on <= 0) on = 1024;
320       while(on < (1 << 20)) {
321         on <<= 1;
322         if(setsockopt(data->ipv4_fd, SOL_SOCKET, SO_SNDBUF,
323                       &on, sizeof(on)) != 0) {
324           on >>= 1;
325           break;
326         }
327       }
328       noitL(noit_debug, "ping_icmp: send buffer set to %d\n", on);
329     }
330     else
331       noitL(noit_error, "Cannot get sndbuf size: %s\n", strerror(errno));
332
333     if(eventer_set_fd_nonblocking(data->ipv4_fd)) {
334       close(data->ipv4_fd);
335       data->ipv4_fd = -1;
336       noitL(noit_error,
337             "ping_icmp: could not set socket non-blocking: %s\n",
338             strerror(errno));
339     }
340   }
341   if(data->ipv4_fd >= 0) {
342     eventer_t newe;
343     newe = eventer_alloc();
344     newe->fd = data->ipv4_fd;
345     newe->mask = EVENTER_READ;
346     newe->callback = ping_icmp_handler;
347     newe->closure = self;
348     eventer_add(newe);
349   }
350
351   data->ipv6_fd = socket(AF_INET6, SOCK_RAW, proto->p_proto);
352   if(data->ipv6_fd < 0) {
353     noitL(noit_error, "ping_icmp: socket failed: %s\n",
354           strerror(errno));
355   }
356   else {
357     if(eventer_set_fd_nonblocking(data->ipv6_fd)) {
358       close(data->ipv6_fd);
359       data->ipv6_fd = -1;
360       noitL(noit_error,
361             "ping_icmp: could not set socket non-blocking: %s\n",
362                strerror(errno));
363     }
364   }
365   if(data->ipv6_fd >= 0) {
366     eventer_t newe;
367     newe = eventer_alloc();
368     newe->fd = data->ipv6_fd;
369     newe->mask = EVENTER_READ;
370     newe->callback = ping_icmp_handler;
371     newe->closure = self;
372     eventer_add(newe);
373   }
374
375   noit_module_set_userdata(self, data);
376   return 0;
377 }
378
379 static int ping_icmp_real_send(eventer_t e, int mask,
380                                void *closure, struct timeval *now) {
381   struct ping_closure *pcl = (struct ping_closure *)closure;
382   struct ping_session_key k;
383   struct icmp *icp;
384   struct ping_payload *payload;
385   ping_icmp_data_t *data;
386   void *vcheck;
387   int i;
388
389   data = noit_module_get_userdata(pcl->self);
390   icp = (struct icmp *)pcl->payload;
391   payload = (struct ping_payload *)(icp + 1);
392   k.addr_of_check = payload->addr_of_check;
393   uuid_copy(k.checkid, payload->checkid);
394
395   if(pcl->check->target_ip[0] == '\0') goto cleanup;
396
397   if(!noit_hash_retrieve(data->in_flight, (const char *)&k, sizeof(k),
398                          &vcheck)) {
399     noitLT(nldeb, now, "ping check no longer active, bailing\n");
400     goto cleanup;
401   }
402
403   noitLT(nldeb, now, "ping_icmp_real_send(%s)\n", pcl->check->target_ip);
404   gettimeofday(&payload->whence, NULL); /* now isn't accurate enough */
405   icp->icmp_cksum = in_cksum(pcl->payload, pcl->payload_len);
406   if(pcl->check->target_family == AF_INET) {
407     struct sockaddr_in sin;
408     memset(&sin, 0, sizeof(sin));
409     sin.sin_family = AF_INET;
410     memcpy(&sin.sin_addr,
411            &pcl->check->target_addr.addr, sizeof(sin.sin_addr));
412     i = sendto(data->ipv4_fd,
413                pcl->payload, pcl->payload_len, 0,
414                (struct sockaddr *)&sin, sizeof(sin));
415   }
416   else if(pcl->check->target_family == AF_INET6) {
417     struct sockaddr_in6 sin;
418     memset(&sin, 0, sizeof(sin));
419     sin.sin6_family = AF_INET6;
420     memcpy(&sin.sin6_addr,
421            &pcl->check->target_addr.addr6, sizeof(sin.sin6_addr));
422     i = sendto(data->ipv6_fd,
423                pcl->payload, pcl->payload_len, 0,
424                (struct sockaddr *)&sin, sizeof(sin));
425   }
426   if(i != pcl->payload_len) {
427     noitLT(nlerr, now, "Error sending ICMP packet to %s(%s): %s\n",
428              pcl->check->target, pcl->check->target_ip, strerror(errno));
429   }
430  cleanup:
431   free(pcl->payload);
432   free(pcl);
433   return 0;
434 }
435 static void ping_check_cleanup(noit_module_t *self, noit_check_t *check) {
436   struct check_info *ci = (struct check_info *)check->closure;
437   if(ci) {
438     if(ci->timeout_event) {
439       eventer_remove(ci->timeout_event);
440       free(ci->timeout_event->closure);
441       eventer_free(ci->timeout_event);
442       ci->timeout_event = NULL;
443     }
444     if(ci->turnaround) free(ci->turnaround);
445   }
446 }
447 static int ping_icmp_send(noit_module_t *self, noit_check_t *check) {
448   struct timeval when, p_int;
449   struct icmp *icp;
450   struct ping_payload *payload;
451   struct ping_closure *pcl;
452   struct check_info *ci = (struct check_info *)check->closure;
453   int packet_len, i;
454   eventer_t newe;
455   const char *config_val;
456   ping_icmp_data_t *ping_data;
457   struct ping_session_key *k;
458
459   int interval = PING_INTERVAL;
460   int count = PING_COUNT;
461
462   if(noit_hash_retr_str(check->config, "interval", strlen("interval"),
463                         &config_val))
464     interval = atoi(config_val);
465   if(noit_hash_retr_str(check->config, "count", strlen("count"),
466                         &config_val))
467     count = atoi(config_val);
468
469   check->flags |= NP_RUNNING;
470   ping_data = noit_module_get_userdata(self);
471   k = calloc(1, sizeof(*k));
472   k->addr_of_check = check;
473   uuid_copy(k->checkid, check->checkid);
474   if(!noit_hash_store(ping_data->in_flight, (const char *)k, sizeof(*k),
475                       check)) {
476     free(k);
477   }
478   noitL(nldeb, "ping_icmp_send(%p,%s,%d,%d)\n",
479         self, check->target_ip, interval, count);
480
481   /* remove a timeout if we still have one -- we should unless someone
482    * has set a lower timeout than the period.
483    */
484   if(ci->timeout_event) {
485     eventer_remove(ci->timeout_event);
486     free(ci->timeout_event->closure);
487     eventer_free(ci->timeout_event);
488     ci->timeout_event = NULL;
489   }
490
491   gettimeofday(&when, NULL);
492   memcpy(&check->last_fire_time, &when, sizeof(when));
493
494   /* Setup some stuff used in the loop */
495   p_int.tv_sec = interval / 1000;
496   p_int.tv_usec = (interval % 1000) * 1000;
497   packet_len = sizeof(*icp) + sizeof(*payload);
498
499   /* Prep holding spots for return info */
500   ci->expected_count = count;
501   if(ci->turnaround) free(ci->turnaround);
502   ci->turnaround = malloc(count * sizeof(*ci->turnaround));
503
504   ++ci->check_no;
505   for(i=0; i<count; i++) {
506     /* Negative means we've not received a response */
507     ci->turnaround[i] = -1.0;
508
509     newe = eventer_alloc();
510     newe->callback = ping_icmp_real_send;
511     newe->mask = EVENTER_TIMER;
512     memcpy(&newe->whence, &when, sizeof(when));
513     add_timeval(when, p_int, &when); /* Next one is a bit later */
514
515     icp = calloc(1,packet_len);
516     payload = (struct ping_payload *)(icp + 1);
517
518     icp->icmp_type = ICMP_ECHO;
519     icp->icmp_code = 0;
520     icp->icmp_cksum = 0;
521     icp->icmp_seq = htons(ci->seq++);
522     icp->icmp_id = (((vpsized_uint)self) & 0xffff);
523
524     payload->addr_of_check = check;
525     uuid_copy(payload->checkid, check->checkid);
526     payload->generation = check->generation;
527     payload->check_no = ci->check_no;
528     payload->check_pack_no = i;
529     payload->check_pack_cnt = count;
530
531     pcl = calloc(1, sizeof(*pcl));
532     pcl->self = self;
533     pcl->check = check;
534     pcl->payload = icp;
535     pcl->payload_len = packet_len;
536
537     newe->closure = pcl;
538     eventer_add(newe);
539   }
540   newe = eventer_alloc();
541   newe->mask = EVENTER_TIMER;
542   gettimeofday(&when, NULL);
543   p_int.tv_sec = check->timeout / 1000;
544   p_int.tv_usec = (check->timeout % 1000) * 1000;
545   add_timeval(when, p_int, &newe->whence);
546   pcl = calloc(1, sizeof(*pcl));
547   pcl->self = self;
548   pcl->check = check;
549   newe->closure = pcl;
550   newe->callback = ping_icmp_timeout;
551   eventer_add(newe);
552   ci->timeout_event = newe;
553
554   return 0;
555 }
556 static int ping_icmp_initiate_check(noit_module_t *self, noit_check_t *check,
557                                     int once, noit_check_t *cause) {
558   if(!check->closure) check->closure = calloc(1, sizeof(struct check_info));
559   INITIATE_CHECK(ping_icmp_send, self, check);
560   return 0;
561 }
562
563 /*
564  *      I N _ C K S U M
565  *          This is from Mike Muuss's Public Domain code.
566  * Checksum routine for Internet Protocol family headers (C Version)
567  *
568  */
569 static int in_cksum(u_short *addr, int len)
570 {
571   register int nleft = len;
572   register u_short *w = addr;
573   register u_short answer;
574   register int sum = 0;
575
576   /*
577    *  Our algorithm is simple, using a 32 bit accumulator (sum),
578    *  we add sequential 16 bit words to it, and at the end, fold
579    *  back all the carry bits from the top 16 bits into the lower
580    *  16 bits.
581    */
582   while( nleft > 1 )  {
583     sum += *w++;
584     nleft -= 2;
585   }
586
587   /* mop up an odd byte, if necessary */
588   if( nleft == 1 ) {
589     u_short  u = 0;
590
591     *(u_char *)(&u) = *(u_char *)w ;
592     sum += u;
593   }
594
595   /*
596    * add back carry outs from top 16 bits to low 16 bits
597    */
598   sum = (sum >> 16) + (sum & 0xffff);  /* add hi 16 to low 16 */
599   sum += (sum >> 16);      /* add carry */
600   answer = ~sum;        /* truncate to 16 bits */
601   return (answer);
602 }
603
604 static int ping_icmp_onload(noit_image_t *self) {
605   nlerr = noit_log_stream_find("error/ping_icmp");
606   nldeb = noit_log_stream_find("debug/ping_icmp");
607   if(!nlerr) nlerr = noit_stderr;
608   if(!nldeb) nldeb = noit_debug;
609   eventer_name_callback("ping_icmp/timeout", ping_icmp_timeout);
610   eventer_name_callback("ping_icmp/handler", ping_icmp_handler);
611   eventer_name_callback("ping_icmp/send", ping_icmp_real_send);
612   return 0;
613 }
614 #include "ping_icmp.xmlh"
615 noit_module_t ping_icmp = {
616   {
617     NOIT_MODULE_MAGIC,
618     NOIT_MODULE_ABI_VERSION,
619     "ping_icmp",
620     "ICMP based host availability detection",
621     ping_icmp_xml_description,
622     ping_icmp_onload
623   },
624   ping_icmp_config,
625   ping_icmp_init,
626   ping_icmp_initiate_check,
627   ping_check_cleanup
628 };
629
Note: See TracBrowser for help on using the browser.