diff options
| -rwxr-xr-x | .github/mock.sh | 2 | ||||
| -rw-r--r-- | SUPPORT | 2 | ||||
| -rw-r--r-- | plugins-root/check_icmp.c | 307 | ||||
| -rw-r--r-- | plugins/check_curl.c | 10 |
4 files changed, 210 insertions, 111 deletions
diff --git a/.github/mock.sh b/.github/mock.sh index ea4f7f3d..8f84756c 100755 --- a/.github/mock.sh +++ b/.github/mock.sh | |||
| @@ -59,7 +59,7 @@ mkdir -p "${SRCRPM_DIR}" "${RPM_DIR}" | |||
| 59 | dnf -y --setopt="tsflags=nodocs" install rpmdevtools && \ | 59 | dnf -y --setopt="tsflags=nodocs" install rpmdevtools && \ |
| 60 | spectool -g -C ${SOURCE_DIR} ${SPEC_FILE} && \ | 60 | spectool -g -C ${SOURCE_DIR} ${SPEC_FILE} && \ |
| 61 | mock --init && \ | 61 | mock --init && \ |
| 62 | { mock --no-clean --spec ${SPEC_FILE} --sources=${SOURCE_DIR} --result=${SRCRPM_DIR} --build || \ | 62 | { mock --no-clean --spec ${SPEC_FILE} --sources=${SOURCE_DIR} --result=${SRCRPM_DIR} --buildsrpm || \ |
| 63 | { cat ${SRCRPM_DIR}/{root,build}.log; exit 1; } } && \ | 63 | { cat ${SRCRPM_DIR}/{root,build}.log; exit 1; } } && \ |
| 64 | { mock --no-clean --sources=${SOURCE_DIR} --result=${RPM_DIR} --rebuild "${SRCRPM_DIR}"/${SRC_RPM} || \ | 64 | { mock --no-clean --sources=${SOURCE_DIR} --result=${RPM_DIR} --rebuild "${SRCRPM_DIR}"/${SRC_RPM} || \ |
| 65 | { cat ${RPM_DIR}/{root,build}.log; exit 1; } } | 65 | { cat ${RPM_DIR}/{root,build}.log; exit 1; } } |
| @@ -8,7 +8,7 @@ support offerings. | |||
| 8 | 8 | ||
| 9 | There are two mailing lists associated with Monitoring Plugins development: | 9 | There are two mailing lists associated with Monitoring Plugins development: |
| 10 | 'help' (mailto:help@monitoring-plugins.org), and 'devel' | 10 | 'help' (mailto:help@monitoring-plugins.org), and 'devel' |
| 11 | (mailto:help@monitoring-plugins.org). Unless you are fairly | 11 | (mailto:devel@monitoring-plugins.org). Unless you are fairly |
| 12 | certain you have found a bug or that you are requesting a new feature, | 12 | certain you have found a bug or that you are requesting a new feature, |
| 13 | please direct support requests to 'help'. | 13 | please direct support requests to 'help'. |
| 14 | 14 | ||
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index 960ab8f1..dcaceddb 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
| @@ -64,6 +64,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 64 | #include <netinet/ip_icmp.h> | 64 | #include <netinet/ip_icmp.h> |
| 65 | #include <netinet/icmp6.h> | 65 | #include <netinet/icmp6.h> |
| 66 | #include <arpa/inet.h> | 66 | #include <arpa/inet.h> |
| 67 | #include <math.h> | ||
| 67 | 68 | ||
| 68 | /** sometimes undefined system macros (quite a few, actually) **/ | 69 | /** sometimes undefined system macros (quite a few, actually) **/ |
| 69 | #ifndef MAXTTL | 70 | #ifndef MAXTTL |
| @@ -272,8 +273,9 @@ static void crash(const char *fmt, ...) { | |||
| 272 | vprintf(fmt, ap); | 273 | vprintf(fmt, ap); |
| 273 | va_end(ap); | 274 | va_end(ap); |
| 274 | 275 | ||
| 275 | if (errno) | 276 | if (errno) { |
| 276 | printf(": %s", strerror(errno)); | 277 | printf(": %s", strerror(errno)); |
| 278 | } | ||
| 277 | puts(""); | 279 | puts(""); |
| 278 | 280 | ||
| 279 | exit(3); | 281 | exit(3); |
| @@ -282,8 +284,9 @@ static void crash(const char *fmt, ...) { | |||
| 282 | static const char *get_icmp_error_msg(unsigned char icmp_type, unsigned char icmp_code) { | 284 | static const char *get_icmp_error_msg(unsigned char icmp_type, unsigned char icmp_code) { |
| 283 | const char *msg = "unreachable"; | 285 | const char *msg = "unreachable"; |
| 284 | 286 | ||
| 285 | if (debug > 1) | 287 | if (debug > 1) { |
| 286 | printf("get_icmp_error_msg(%u, %u)\n", icmp_type, icmp_code); | 288 | printf("get_icmp_error_msg(%u, %u)\n", icmp_type, icmp_code); |
| 289 | } | ||
| 287 | switch (icmp_type) { | 290 | switch (icmp_type) { |
| 288 | case ICMP_UNREACH: | 291 | case ICMP_UNREACH: |
| 289 | switch (icmp_code) { | 292 | switch (icmp_code) { |
| @@ -392,8 +395,9 @@ static int handle_random_icmp(unsigned char *packet, struct sockaddr_storage *ad | |||
| 392 | return 0; | 395 | return 0; |
| 393 | } | 396 | } |
| 394 | 397 | ||
| 395 | if (debug) | 398 | if (debug) { |
| 396 | printf("handle_random_icmp(%p, %p)\n", (void *)&p, (void *)addr); | 399 | printf("handle_random_icmp(%p, %p)\n", (void *)&p, (void *)addr); |
| 400 | } | ||
| 397 | 401 | ||
| 398 | /* only handle a few types, since others can't possibly be replies to | 402 | /* only handle a few types, since others can't possibly be replies to |
| 399 | * us in a sane network (if it is anyway, it will be counted as lost | 403 | * us in a sane network (if it is anyway, it will be counted as lost |
| @@ -413,8 +417,9 @@ static int handle_random_icmp(unsigned char *packet, struct sockaddr_storage *ad | |||
| 413 | * to RFC 792). If it isn't, just ignore it */ | 417 | * to RFC 792). If it isn't, just ignore it */ |
| 414 | memcpy(&sent_icmp, packet + 28, sizeof(sent_icmp)); | 418 | memcpy(&sent_icmp, packet + 28, sizeof(sent_icmp)); |
| 415 | if (sent_icmp.icmp_type != ICMP_ECHO || ntohs(sent_icmp.icmp_id) != pid || ntohs(sent_icmp.icmp_seq) >= targets * packets) { | 419 | if (sent_icmp.icmp_type != ICMP_ECHO || ntohs(sent_icmp.icmp_id) != pid || ntohs(sent_icmp.icmp_seq) >= targets * packets) { |
| 416 | if (debug) | 420 | if (debug) { |
| 417 | printf("Packet is no response to a packet we sent\n"); | 421 | printf("Packet is no response to a packet we sent\n"); |
| 422 | } | ||
| 418 | return 0; | 423 | return 0; |
| 419 | } | 424 | } |
| 420 | 425 | ||
| @@ -429,8 +434,9 @@ static int handle_random_icmp(unsigned char *packet, struct sockaddr_storage *ad | |||
| 429 | icmp_lost++; | 434 | icmp_lost++; |
| 430 | host->icmp_lost++; | 435 | host->icmp_lost++; |
| 431 | /* don't spend time on lost hosts any more */ | 436 | /* don't spend time on lost hosts any more */ |
| 432 | if (host->flags & FLAG_LOST_CAUSE) | 437 | if (host->flags & FLAG_LOST_CAUSE) { |
| 433 | return 0; | 438 | return 0; |
| 439 | } | ||
| 434 | 440 | ||
| 435 | /* source quench means we're sending too fast, so increase the | 441 | /* source quench means we're sending too fast, so increase the |
| 436 | * interval and mark this packet lost */ | 442 | * interval and mark this packet lost */ |
| @@ -488,10 +494,11 @@ int main(int argc, char **argv) { | |||
| 488 | /* get calling name the old-fashioned way for portability instead | 494 | /* get calling name the old-fashioned way for portability instead |
| 489 | * of relying on the glibc-ism __progname */ | 495 | * of relying on the glibc-ism __progname */ |
| 490 | ptr = strrchr(argv[0], '/'); | 496 | ptr = strrchr(argv[0], '/'); |
| 491 | if (ptr) | 497 | if (ptr) { |
| 492 | progname = &ptr[1]; | 498 | progname = &ptr[1]; |
| 493 | else | 499 | } else { |
| 494 | progname = argv[0]; | 500 | progname = argv[0]; |
| 501 | } | ||
| 495 | 502 | ||
| 496 | /* now set defaults. Use progname to set them initially (allows for | 503 | /* now set defaults. Use progname to set them initially (allows for |
| 497 | * superfast check_host program when target host is up */ | 504 | * superfast check_host program when target host is up */ |
| @@ -534,10 +541,12 @@ int main(int argc, char **argv) { | |||
| 534 | 541 | ||
| 535 | /* support "--help" and "--version" */ | 542 | /* support "--help" and "--version" */ |
| 536 | if (argc == 2) { | 543 | if (argc == 2) { |
| 537 | if (!strcmp(argv[1], "--help")) | 544 | if (!strcmp(argv[1], "--help")) { |
| 538 | strcpy(argv[1], "-h"); | 545 | strcpy(argv[1], "-h"); |
| 539 | if (!strcmp(argv[1], "--version")) | 546 | } |
| 547 | if (!strcmp(argv[1], "--version")) { | ||
| 540 | strcpy(argv[1], "-V"); | 548 | strcpy(argv[1], "-V"); |
| 549 | } | ||
| 541 | } | 550 | } |
| 542 | 551 | ||
| 543 | /* Parse protocol arguments first */ | 552 | /* Parse protocol arguments first */ |
| @@ -545,14 +554,16 @@ int main(int argc, char **argv) { | |||
| 545 | while ((arg = getopt(argc, argv, opts_str)) != EOF) { | 554 | while ((arg = getopt(argc, argv, opts_str)) != EOF) { |
| 546 | switch (arg) { | 555 | switch (arg) { |
| 547 | case '4': | 556 | case '4': |
| 548 | if (address_family != -1) | 557 | if (address_family != -1) { |
| 549 | crash("Multiple protocol versions not supported"); | 558 | crash("Multiple protocol versions not supported"); |
| 559 | } | ||
| 550 | address_family = AF_INET; | 560 | address_family = AF_INET; |
| 551 | break; | 561 | break; |
| 552 | case '6': | 562 | case '6': |
| 553 | #ifdef USE_IPV6 | 563 | #ifdef USE_IPV6 |
| 554 | if (address_family != -1) | 564 | if (address_family != -1) { |
| 555 | crash("Multiple protocol versions not supported"); | 565 | crash("Multiple protocol versions not supported"); |
| 566 | } | ||
| 556 | address_family = AF_INET6; | 567 | address_family = AF_INET6; |
| 557 | #else | 568 | #else |
| 558 | usage(_("IPv6 support not available\n")); | 569 | usage(_("IPv6 support not available\n")); |
| @@ -579,9 +590,10 @@ int main(int argc, char **argv) { | |||
| 579 | if (size >= (sizeof(struct icmp) + sizeof(struct icmp_ping_data)) && size < MAX_PING_DATA) { | 590 | if (size >= (sizeof(struct icmp) + sizeof(struct icmp_ping_data)) && size < MAX_PING_DATA) { |
| 580 | icmp_data_size = size; | 591 | icmp_data_size = size; |
| 581 | icmp_pkt_size = size + ICMP_MINLEN; | 592 | icmp_pkt_size = size + ICMP_MINLEN; |
| 582 | } else | 593 | } else { |
| 583 | usage_va("ICMP data length must be between: %lu and %lu", sizeof(struct icmp) + sizeof(struct icmp_ping_data), | 594 | usage_va("ICMP data length must be between: %lu and %lu", sizeof(struct icmp) + sizeof(struct icmp_ping_data), |
| 584 | MAX_PING_DATA - 1); | 595 | MAX_PING_DATA - 1); |
| 596 | } | ||
| 585 | break; | 597 | break; |
| 586 | case 'i': | 598 | case 'i': |
| 587 | pkt_interval = get_timevar(optarg); | 599 | pkt_interval = get_timevar(optarg); |
| @@ -601,8 +613,9 @@ int main(int argc, char **argv) { | |||
| 601 | break; | 613 | break; |
| 602 | case 't': | 614 | case 't': |
| 603 | timeout = strtoul(optarg, NULL, 0); | 615 | timeout = strtoul(optarg, NULL, 0); |
| 604 | if (!timeout) | 616 | if (!timeout) { |
| 605 | timeout = 10; | 617 | timeout = 10; |
| 618 | } | ||
| 606 | break; | 619 | break; |
| 607 | case 'H': | 620 | case 'H': |
| 608 | add_target(optarg); | 621 | add_target(optarg); |
| @@ -709,18 +722,22 @@ int main(int argc, char **argv) { | |||
| 709 | default: | 722 | default: |
| 710 | crash("Address family not supported"); | 723 | crash("Address family not supported"); |
| 711 | } | 724 | } |
| 712 | if ((icmp_sock = socket(address_family, SOCK_RAW, icmp_proto)) != -1) | 725 | if ((icmp_sock = socket(address_family, SOCK_RAW, icmp_proto)) != -1) { |
| 713 | sockets |= HAVE_ICMP; | 726 | sockets |= HAVE_ICMP; |
| 714 | else | 727 | } else { |
| 715 | icmp_sockerrno = errno; | 728 | icmp_sockerrno = errno; |
| 729 | } | ||
| 716 | 730 | ||
| 717 | if (source_ip) | 731 | if (source_ip) { |
| 718 | set_source_ip(source_ip); | 732 | set_source_ip(source_ip); |
| 733 | } | ||
| 719 | 734 | ||
| 720 | #ifdef SO_TIMESTAMP | 735 | #ifdef SO_TIMESTAMP |
| 721 | if (setsockopt(icmp_sock, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on))) | 736 | if (setsockopt(icmp_sock, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on))) { |
| 722 | if (debug) | 737 | if (debug) { |
| 723 | printf("Warning: no SO_TIMESTAMP support\n"); | 738 | printf("Warning: no SO_TIMESTAMP support\n"); |
| 739 | } | ||
| 740 | } | ||
| 724 | #endif // SO_TIMESTAMP | 741 | #endif // SO_TIMESTAMP |
| 725 | 742 | ||
| 726 | /* now drop privileges (no effect if not setsuid or geteuid() == 0) */ | 743 | /* now drop privileges (no effect if not setsuid or geteuid() == 0) */ |
| @@ -746,16 +763,18 @@ int main(int argc, char **argv) { | |||
| 746 | /* return -1; */ | 763 | /* return -1; */ |
| 747 | /* } */ | 764 | /* } */ |
| 748 | } | 765 | } |
| 749 | if (!ttl) | 766 | if (!ttl) { |
| 750 | ttl = 64; | 767 | ttl = 64; |
| 768 | } | ||
| 751 | 769 | ||
| 752 | if (icmp_sock) { | 770 | if (icmp_sock) { |
| 753 | result = setsockopt(icmp_sock, SOL_IP, IP_TTL, &ttl, sizeof(ttl)); | 771 | result = setsockopt(icmp_sock, SOL_IP, IP_TTL, &ttl, sizeof(ttl)); |
| 754 | if (debug) { | 772 | if (debug) { |
| 755 | if (result == -1) | 773 | if (result == -1) { |
| 756 | printf("setsockopt failed\n"); | 774 | printf("setsockopt failed\n"); |
| 757 | else | 775 | } else { |
| 758 | printf("ttl set to %u\n", ttl); | 776 | printf("ttl set to %u\n", ttl); |
| 777 | } | ||
| 759 | } | 778 | } |
| 760 | } | 779 | } |
| 761 | 780 | ||
| @@ -763,18 +782,24 @@ int main(int argc, char **argv) { | |||
| 763 | * (nothing will break if they do), but some anal plugin maintainer | 782 | * (nothing will break if they do), but some anal plugin maintainer |
| 764 | * will probably add some printf() thing here later, so it might be | 783 | * will probably add some printf() thing here later, so it might be |
| 765 | * best to at least show them where to do it. ;) */ | 784 | * best to at least show them where to do it. ;) */ |
| 766 | if (warn.pl > crit.pl) | 785 | if (warn.pl > crit.pl) { |
| 767 | warn.pl = crit.pl; | 786 | warn.pl = crit.pl; |
| 768 | if (warn.rta > crit.rta) | 787 | } |
| 788 | if (warn.rta > crit.rta) { | ||
| 769 | warn.rta = crit.rta; | 789 | warn.rta = crit.rta; |
| 770 | if (warn_down > crit_down) | 790 | } |
| 791 | if (warn_down > crit_down) { | ||
| 771 | crit_down = warn_down; | 792 | crit_down = warn_down; |
| 772 | if (warn.jitter > crit.jitter) | 793 | } |
| 794 | if (warn.jitter > crit.jitter) { | ||
| 773 | crit.jitter = warn.jitter; | 795 | crit.jitter = warn.jitter; |
| 774 | if (warn.mos < crit.mos) | 796 | } |
| 797 | if (warn.mos < crit.mos) { | ||
| 775 | warn.mos = crit.mos; | 798 | warn.mos = crit.mos; |
| 776 | if (warn.score < crit.score) | 799 | } |
| 800 | if (warn.score < crit.score) { | ||
| 777 | warn.score = crit.score; | 801 | warn.score = crit.score; |
| 802 | } | ||
| 778 | 803 | ||
| 779 | #ifdef HAVE_SIGACTION | 804 | #ifdef HAVE_SIGACTION |
| 780 | sig_action.sa_sigaction = NULL; | 805 | sig_action.sa_sigaction = NULL; |
| @@ -791,8 +816,9 @@ int main(int argc, char **argv) { | |||
| 791 | signal(SIGTERM, finish); | 816 | signal(SIGTERM, finish); |
| 792 | signal(SIGALRM, finish); | 817 | signal(SIGALRM, finish); |
| 793 | #endif /* HAVE_SIGACTION */ | 818 | #endif /* HAVE_SIGACTION */ |
| 794 | if (debug) | 819 | if (debug) { |
| 795 | printf("Setting alarm timeout to %u seconds\n", timeout); | 820 | printf("Setting alarm timeout to %u seconds\n", timeout); |
| 821 | } | ||
| 796 | alarm(timeout); | 822 | alarm(timeout); |
| 797 | 823 | ||
| 798 | /* make sure we don't wait any longer than necessary */ | 824 | /* make sure we don't wait any longer than necessary */ |
| @@ -863,11 +889,13 @@ static void run_checks(void) { | |||
| 863 | for (i = 0; i < packets; i++) { | 889 | for (i = 0; i < packets; i++) { |
| 864 | for (t = 0; t < targets; t++) { | 890 | for (t = 0; t < targets; t++) { |
| 865 | /* don't send useless packets */ | 891 | /* don't send useless packets */ |
| 866 | if (!targets_alive) | 892 | if (!targets_alive) { |
| 867 | finish(0); | 893 | finish(0); |
| 894 | } | ||
| 868 | if (table[t]->flags & FLAG_LOST_CAUSE) { | 895 | if (table[t]->flags & FLAG_LOST_CAUSE) { |
| 869 | if (debug) | 896 | if (debug) { |
| 870 | printf("%s is a lost cause. not sending any more\n", table[t]->name); | 897 | printf("%s is a lost cause. not sending any more\n", table[t]->name); |
| 898 | } | ||
| 871 | continue; | 899 | continue; |
| 872 | } | 900 | } |
| 873 | 901 | ||
| @@ -886,15 +914,17 @@ static void run_checks(void) { | |||
| 886 | printf("time_passed: %u final_wait: %u max_completion_time: %llu\n", time_passed, final_wait, max_completion_time); | 914 | printf("time_passed: %u final_wait: %u max_completion_time: %llu\n", time_passed, final_wait, max_completion_time); |
| 887 | } | 915 | } |
| 888 | if (time_passed > max_completion_time) { | 916 | if (time_passed > max_completion_time) { |
| 889 | if (debug) | 917 | if (debug) { |
| 890 | printf("Time passed. Finishing up\n"); | 918 | printf("Time passed. Finishing up\n"); |
| 919 | } | ||
| 891 | finish(0); | 920 | finish(0); |
| 892 | } | 921 | } |
| 893 | 922 | ||
| 894 | /* catch the packets that might come in within the timeframe, but | 923 | /* catch the packets that might come in within the timeframe, but |
| 895 | * haven't yet */ | 924 | * haven't yet */ |
| 896 | if (debug) | 925 | if (debug) { |
| 897 | printf("Waiting for %u micro-seconds (%0.3f msecs)\n", final_wait, (float)final_wait / 1000); | 926 | printf("Waiting for %u micro-seconds (%0.3f msecs)\n", final_wait, (float)final_wait / 1000); |
| 927 | } | ||
| 898 | wait_for_reply(icmp_sock, final_wait); | 928 | wait_for_reply(icmp_sock, final_wait); |
| 899 | } | 929 | } |
| 900 | } | 930 | } |
| @@ -955,8 +985,9 @@ static int wait_for_reply(int sock, u_int t) { | |||
| 955 | continue; /* timeout for this one, so keep trying */ | 985 | continue; /* timeout for this one, so keep trying */ |
| 956 | } | 986 | } |
| 957 | if (n < 0) { | 987 | if (n < 0) { |
| 958 | if (debug) | 988 | if (debug) { |
| 959 | printf("recvfrom_wto() returned errors\n"); | 989 | printf("recvfrom_wto() returned errors\n"); |
| 990 | } | ||
| 960 | free(packet.buf); | 991 | free(packet.buf); |
| 961 | return n; | 992 | return n; |
| 962 | } | 993 | } |
| @@ -1003,8 +1034,9 @@ static int wait_for_reply(int sock, u_int t) { | |||
| 1003 | ntohs(packet.icp->icmp_seq) >= targets * packets)) || | 1034 | ntohs(packet.icp->icmp_seq) >= targets * packets)) || |
| 1004 | (address_family == PF_INET6 && (ntohs(packet.icp6->icmp6_id) != pid || packet.icp6->icmp6_type != ICMP6_ECHO_REPLY || | 1035 | (address_family == PF_INET6 && (ntohs(packet.icp6->icmp6_id) != pid || packet.icp6->icmp6_type != ICMP6_ECHO_REPLY || |
| 1005 | ntohs(packet.icp6->icmp6_seq) >= targets * packets))) { | 1036 | ntohs(packet.icp6->icmp6_seq) >= targets * packets))) { |
| 1006 | if (debug > 2) | 1037 | if (debug > 2) { |
| 1007 | printf("not a proper ICMP_ECHOREPLY\n"); | 1038 | printf("not a proper ICMP_ECHOREPLY\n"); |
| 1039 | } | ||
| 1008 | handle_random_icmp(buf + hlen, &resp_addr); | 1040 | handle_random_icmp(buf + hlen, &resp_addr); |
| 1009 | continue; | 1041 | continue; |
| 1010 | } | 1042 | } |
| @@ -1012,15 +1044,17 @@ static int wait_for_reply(int sock, u_int t) { | |||
| 1012 | /* this is indeed a valid response */ | 1044 | /* this is indeed a valid response */ |
| 1013 | if (address_family == PF_INET) { | 1045 | if (address_family == PF_INET) { |
| 1014 | memcpy(&data, packet.icp->icmp_data, sizeof(data)); | 1046 | memcpy(&data, packet.icp->icmp_data, sizeof(data)); |
| 1015 | if (debug > 2) | 1047 | if (debug > 2) { |
| 1016 | printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n", (unsigned long)sizeof(data), ntohs(packet.icp->icmp_id), | 1048 | printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n", (unsigned long)sizeof(data), ntohs(packet.icp->icmp_id), |
| 1017 | ntohs(packet.icp->icmp_seq), packet.icp->icmp_cksum); | 1049 | ntohs(packet.icp->icmp_seq), packet.icp->icmp_cksum); |
| 1050 | } | ||
| 1018 | host = table[ntohs(packet.icp->icmp_seq) / packets]; | 1051 | host = table[ntohs(packet.icp->icmp_seq) / packets]; |
| 1019 | } else { | 1052 | } else { |
| 1020 | memcpy(&data, &packet.icp6->icmp6_dataun.icmp6_un_data8[4], sizeof(data)); | 1053 | memcpy(&data, &packet.icp6->icmp6_dataun.icmp6_un_data8[4], sizeof(data)); |
| 1021 | if (debug > 2) | 1054 | if (debug > 2) { |
| 1022 | printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n", (unsigned long)sizeof(data), ntohs(packet.icp6->icmp6_id), | 1055 | printf("ICMP echo-reply of len %lu, id %u, seq %u, cksum 0x%X\n", (unsigned long)sizeof(data), ntohs(packet.icp6->icmp6_id), |
| 1023 | ntohs(packet.icp6->icmp6_seq), packet.icp6->icmp6_cksum); | 1056 | ntohs(packet.icp6->icmp6_seq), packet.icp6->icmp6_cksum); |
| 1057 | } | ||
| 1024 | host = table[ntohs(packet.icp6->icmp6_seq) / packets]; | 1058 | host = table[ntohs(packet.icp6->icmp6_seq) / packets]; |
| 1025 | } | 1059 | } |
| 1026 | 1060 | ||
| @@ -1051,8 +1085,9 @@ static int wait_for_reply(int sock, u_int t) { | |||
| 1051 | } | 1085 | } |
| 1052 | 1086 | ||
| 1053 | /* Check if packets in order */ | 1087 | /* Check if packets in order */ |
| 1054 | if (host->last_icmp_seq >= packet.icp->icmp_seq) | 1088 | if (host->last_icmp_seq >= packet.icp->icmp_seq) { |
| 1055 | host->order_status = STATE_CRITICAL; | 1089 | host->order_status = STATE_CRITICAL; |
| 1090 | } | ||
| 1056 | } | 1091 | } |
| 1057 | host->last_tdiff = tdiff; | 1092 | host->last_tdiff = tdiff; |
| 1058 | 1093 | ||
| @@ -1061,10 +1096,14 @@ static int wait_for_reply(int sock, u_int t) { | |||
| 1061 | host->time_waited += tdiff; | 1096 | host->time_waited += tdiff; |
| 1062 | host->icmp_recv++; | 1097 | host->icmp_recv++; |
| 1063 | icmp_recv++; | 1098 | icmp_recv++; |
| 1064 | if (tdiff > (unsigned int)host->rtmax) | 1099 | |
| 1100 | if (tdiff > (unsigned int)host->rtmax) { | ||
| 1065 | host->rtmax = tdiff; | 1101 | host->rtmax = tdiff; |
| 1066 | if (tdiff < (unsigned int)host->rtmin) | 1102 | } |
| 1103 | |||
| 1104 | if ((host->rtmin == INFINITY) || (tdiff < (unsigned int)host->rtmin)) { | ||
| 1067 | host->rtmin = tdiff; | 1105 | host->rtmin = tdiff; |
| 1106 | } | ||
| 1068 | 1107 | ||
| 1069 | if (debug) { | 1108 | if (debug) { |
| 1070 | char address[INET6_ADDRSTRLEN]; | 1109 | char address[INET6_ADDRSTRLEN]; |
| @@ -1142,9 +1181,10 @@ static int send_icmp_ping(int sock, struct rta_host *host) { | |||
| 1142 | icp->icmp_seq = htons(host->id++); | 1181 | icp->icmp_seq = htons(host->id++); |
| 1143 | icp->icmp_cksum = icmp_checksum((uint16_t *)buf, (size_t)icmp_pkt_size); | 1182 | icp->icmp_cksum = icmp_checksum((uint16_t *)buf, (size_t)icmp_pkt_size); |
| 1144 | 1183 | ||
| 1145 | if (debug > 2) | 1184 | if (debug > 2) { |
| 1146 | printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n", (unsigned long)sizeof(data), | 1185 | printf("Sending ICMP echo-request of len %lu, id %u, seq %u, cksum 0x%X to host %s\n", (unsigned long)sizeof(data), |
| 1147 | ntohs(icp->icmp_id), ntohs(icp->icmp_seq), icp->icmp_cksum, host->name); | 1186 | ntohs(icp->icmp_id), ntohs(icp->icmp_seq), icp->icmp_cksum, host->name); |
| 1187 | } | ||
| 1148 | } else { | 1188 | } else { |
| 1149 | struct icmp6_hdr *icp6 = (struct icmp6_hdr *)buf; | 1189 | struct icmp6_hdr *icp6 = (struct icmp6_hdr *)buf; |
| 1150 | addrlen = sizeof(struct sockaddr_in6); | 1190 | addrlen = sizeof(struct sockaddr_in6); |
| @@ -1216,8 +1256,9 @@ static int recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr * | |||
| 1216 | #endif | 1256 | #endif |
| 1217 | 1257 | ||
| 1218 | if (!*timo) { | 1258 | if (!*timo) { |
| 1219 | if (debug) | 1259 | if (debug) { |
| 1220 | printf("*timo is not\n"); | 1260 | printf("*timo is not\n"); |
| 1261 | } | ||
| 1221 | return 0; | 1262 | return 0; |
| 1222 | } | 1263 | } |
| 1223 | 1264 | ||
| @@ -1230,13 +1271,15 @@ static int recvfrom_wto(int sock, void *buf, unsigned int len, struct sockaddr * | |||
| 1230 | errno = 0; | 1271 | errno = 0; |
| 1231 | gettimeofday(&then, &tz); | 1272 | gettimeofday(&then, &tz); |
| 1232 | n = select(sock + 1, &rd, &wr, NULL, &to); | 1273 | n = select(sock + 1, &rd, &wr, NULL, &to); |
| 1233 | if (n < 0) | 1274 | if (n < 0) { |
| 1234 | crash("select() in recvfrom_wto"); | 1275 | crash("select() in recvfrom_wto"); |
| 1276 | } | ||
| 1235 | gettimeofday(&now, &tz); | 1277 | gettimeofday(&now, &tz); |
| 1236 | *timo = get_timevaldiff(&then, &now); | 1278 | *timo = get_timevaldiff(&then, &now); |
| 1237 | 1279 | ||
| 1238 | if (!n) | 1280 | if (!n) { |
| 1239 | return 0; /* timeout */ | 1281 | return 0; /* timeout */ |
| 1282 | } | ||
| 1240 | 1283 | ||
| 1241 | slen = sizeof(struct sockaddr_storage); | 1284 | slen = sizeof(struct sockaddr_storage); |
| 1242 | 1285 | ||
| @@ -1281,15 +1324,19 @@ static void finish(int sig) { | |||
| 1281 | double R; | 1324 | double R; |
| 1282 | 1325 | ||
| 1283 | alarm(0); | 1326 | alarm(0); |
| 1284 | if (debug > 1) | 1327 | if (debug > 1) { |
| 1285 | printf("finish(%d) called\n", sig); | 1328 | printf("finish(%d) called\n", sig); |
| 1329 | } | ||
| 1286 | 1330 | ||
| 1287 | if (icmp_sock != -1) | 1331 | if (icmp_sock != -1) { |
| 1288 | close(icmp_sock); | 1332 | close(icmp_sock); |
| 1289 | if (udp_sock != -1) | 1333 | } |
| 1334 | if (udp_sock != -1) { | ||
| 1290 | close(udp_sock); | 1335 | close(udp_sock); |
| 1291 | if (tcp_sock != -1) | 1336 | } |
| 1337 | if (tcp_sock != -1) { | ||
| 1292 | close(tcp_sock); | 1338 | close(tcp_sock); |
| 1339 | } | ||
| 1293 | 1340 | ||
| 1294 | if (debug) { | 1341 | if (debug) { |
| 1295 | printf("icmp_sent: %u icmp_recv: %u icmp_lost: %u\n", icmp_sent, icmp_recv, icmp_lost); | 1342 | printf("icmp_sent: %u icmp_recv: %u icmp_lost: %u\n", icmp_sent, icmp_recv, icmp_lost); |
| @@ -1310,8 +1357,9 @@ static void finish(int sig) { | |||
| 1310 | rta = 0; | 1357 | rta = 0; |
| 1311 | status = STATE_CRITICAL; | 1358 | status = STATE_CRITICAL; |
| 1312 | /* up the down counter if not already counted */ | 1359 | /* up the down counter if not already counted */ |
| 1313 | if (!(host->flags & FLAG_LOST_CAUSE) && targets_alive) | 1360 | if (!(host->flags & FLAG_LOST_CAUSE) && targets_alive) { |
| 1314 | targets_down++; | 1361 | targets_down++; |
| 1362 | } | ||
| 1315 | } else { | 1363 | } else { |
| 1316 | pl = ((host->icmp_sent - host->icmp_recv) * 100) / host->icmp_sent; | 1364 | pl = ((host->icmp_sent - host->icmp_recv) * 100) / host->icmp_sent; |
| 1317 | rta = (double)host->time_waited / host->icmp_recv; | 1365 | rta = (double)host->time_waited / host->icmp_recv; |
| @@ -1444,32 +1492,39 @@ static void finish(int sig) { | |||
| 1444 | } | 1492 | } |
| 1445 | 1493 | ||
| 1446 | /* this is inevitable */ | 1494 | /* this is inevitable */ |
| 1447 | if (!targets_alive) | 1495 | if (!targets_alive) { |
| 1448 | status = STATE_CRITICAL; | 1496 | status = STATE_CRITICAL; |
| 1497 | } | ||
| 1449 | if (min_hosts_alive > -1) { | 1498 | if (min_hosts_alive > -1) { |
| 1450 | if (hosts_ok >= min_hosts_alive) | 1499 | if (hosts_ok >= min_hosts_alive) { |
| 1451 | status = STATE_OK; | 1500 | status = STATE_OK; |
| 1452 | else if ((hosts_ok + hosts_warn) >= min_hosts_alive) | 1501 | } else if ((hosts_ok + hosts_warn) >= min_hosts_alive) { |
| 1453 | status = STATE_WARNING; | 1502 | status = STATE_WARNING; |
| 1503 | } | ||
| 1454 | } | 1504 | } |
| 1455 | printf("%s - ", status_string[status]); | 1505 | printf("%s - ", status_string[status]); |
| 1456 | 1506 | ||
| 1457 | host = list; | 1507 | host = list; |
| 1458 | while (host) { | 1508 | while (host) { |
| 1459 | 1509 | if (debug) { | |
| 1460 | if (debug) | ||
| 1461 | puts(""); | 1510 | puts(""); |
| 1511 | } | ||
| 1512 | |||
| 1462 | if (i) { | 1513 | if (i) { |
| 1463 | if (i < targets) | 1514 | if (i < targets) { |
| 1464 | printf(" :: "); | 1515 | printf(" :: "); |
| 1465 | else | 1516 | } else { |
| 1466 | printf("\n"); | 1517 | printf("\n"); |
| 1518 | } | ||
| 1467 | } | 1519 | } |
| 1520 | |||
| 1468 | i++; | 1521 | i++; |
| 1522 | |||
| 1469 | if (!host->icmp_recv) { | 1523 | if (!host->icmp_recv) { |
| 1470 | status = STATE_CRITICAL; | 1524 | status = STATE_CRITICAL; |
| 1471 | host->rtmin = 0; | 1525 | host->rtmin = 0; |
| 1472 | host->jitter_min = 0; | 1526 | host->jitter_min = 0; |
| 1527 | |||
| 1473 | if (host->flags & FLAG_LOST_CAUSE) { | 1528 | if (host->flags & FLAG_LOST_CAUSE) { |
| 1474 | char address[INET6_ADDRSTRLEN]; | 1529 | char address[INET6_ADDRSTRLEN]; |
| 1475 | parse_address(&host->error_addr, address, sizeof(address)); | 1530 | parse_address(&host->error_addr, address, sizeof(address)); |
| @@ -1481,55 +1536,66 @@ static void finish(int sig) { | |||
| 1481 | printf("%s", host->name); | 1536 | printf("%s", host->name); |
| 1482 | /* rta text output */ | 1537 | /* rta text output */ |
| 1483 | if (rta_mode) { | 1538 | if (rta_mode) { |
| 1484 | if (status == STATE_OK) | 1539 | if (status == STATE_OK) { |
| 1485 | printf(" rta %0.3fms", host->rta / 1000); | 1540 | printf(" rta %0.3fms", host->rta / 1000); |
| 1486 | else if (status == STATE_WARNING && host->rta_status == status) | 1541 | } else if (status == STATE_WARNING && host->rta_status == status) { |
| 1487 | printf(" rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)warn.rta / 1000); | 1542 | printf(" rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)warn.rta / 1000); |
| 1488 | else if (status == STATE_CRITICAL && host->rta_status == status) | 1543 | } else if (status == STATE_CRITICAL && host->rta_status == status) { |
| 1489 | printf(" rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)crit.rta / 1000); | 1544 | printf(" rta %0.3fms > %0.3fms", (float)host->rta / 1000, (float)crit.rta / 1000); |
| 1545 | } | ||
| 1490 | } | 1546 | } |
| 1547 | |||
| 1491 | /* pl text output */ | 1548 | /* pl text output */ |
| 1492 | if (pl_mode) { | 1549 | if (pl_mode) { |
| 1493 | if (status == STATE_OK) | 1550 | if (status == STATE_OK) { |
| 1494 | printf(" lost %u%%", host->pl); | 1551 | printf(" lost %u%%", host->pl); |
| 1495 | else if (status == STATE_WARNING && host->pl_status == status) | 1552 | } else if (status == STATE_WARNING && host->pl_status == status) { |
| 1496 | printf(" lost %u%% > %u%%", host->pl, warn.pl); | 1553 | printf(" lost %u%% > %u%%", host->pl, warn.pl); |
| 1497 | else if (status == STATE_CRITICAL && host->pl_status == status) | 1554 | } else if (status == STATE_CRITICAL && host->pl_status == status) { |
| 1498 | printf(" lost %u%% > %u%%", host->pl, crit.pl); | 1555 | printf(" lost %u%% > %u%%", host->pl, crit.pl); |
| 1556 | } | ||
| 1499 | } | 1557 | } |
| 1558 | |||
| 1500 | /* jitter text output */ | 1559 | /* jitter text output */ |
| 1501 | if (jitter_mode) { | 1560 | if (jitter_mode) { |
| 1502 | if (status == STATE_OK) | 1561 | if (status == STATE_OK) { |
| 1503 | printf(" jitter %0.3fms", (float)host->jitter); | 1562 | printf(" jitter %0.3fms", (float)host->jitter); |
| 1504 | else if (status == STATE_WARNING && host->jitter_status == status) | 1563 | } else if (status == STATE_WARNING && host->jitter_status == status) { |
| 1505 | printf(" jitter %0.3fms > %0.3fms", (float)host->jitter, warn.jitter); | 1564 | printf(" jitter %0.3fms > %0.3fms", (float)host->jitter, warn.jitter); |
| 1506 | else if (status == STATE_CRITICAL && host->jitter_status == status) | 1565 | } else if (status == STATE_CRITICAL && host->jitter_status == status) { |
| 1507 | printf(" jitter %0.3fms > %0.3fms", (float)host->jitter, crit.jitter); | 1566 | printf(" jitter %0.3fms > %0.3fms", (float)host->jitter, crit.jitter); |
| 1567 | } | ||
| 1508 | } | 1568 | } |
| 1569 | |||
| 1509 | /* mos text output */ | 1570 | /* mos text output */ |
| 1510 | if (mos_mode) { | 1571 | if (mos_mode) { |
| 1511 | if (status == STATE_OK) | 1572 | if (status == STATE_OK) { |
| 1512 | printf(" MOS %0.1f", (float)host->mos); | 1573 | printf(" MOS %0.1f", (float)host->mos); |
| 1513 | else if (status == STATE_WARNING && host->mos_status == status) | 1574 | } else if (status == STATE_WARNING && host->mos_status == status) { |
| 1514 | printf(" MOS %0.1f < %0.1f", (float)host->mos, (float)warn.mos); | 1575 | printf(" MOS %0.1f < %0.1f", (float)host->mos, (float)warn.mos); |
| 1515 | else if (status == STATE_CRITICAL && host->mos_status == status) | 1576 | } else if (status == STATE_CRITICAL && host->mos_status == status) { |
| 1516 | printf(" MOS %0.1f < %0.1f", (float)host->mos, (float)crit.mos); | 1577 | printf(" MOS %0.1f < %0.1f", (float)host->mos, (float)crit.mos); |
| 1578 | } | ||
| 1517 | } | 1579 | } |
| 1580 | |||
| 1518 | /* score text output */ | 1581 | /* score text output */ |
| 1519 | if (score_mode) { | 1582 | if (score_mode) { |
| 1520 | if (status == STATE_OK) | 1583 | if (status == STATE_OK) { |
| 1521 | printf(" Score %u", (int)host->score); | 1584 | printf(" Score %u", (int)host->score); |
| 1522 | else if (status == STATE_WARNING && host->score_status == status) | 1585 | } else if (status == STATE_WARNING && host->score_status == status) { |
| 1523 | printf(" Score %u < %u", (int)host->score, (int)warn.score); | 1586 | printf(" Score %u < %u", (int)host->score, (int)warn.score); |
| 1524 | else if (status == STATE_CRITICAL && host->score_status == status) | 1587 | } else if (status == STATE_CRITICAL && host->score_status == status) { |
| 1525 | printf(" Score %u < %u", (int)host->score, (int)crit.score); | 1588 | printf(" Score %u < %u", (int)host->score, (int)crit.score); |
| 1589 | } | ||
| 1526 | } | 1590 | } |
| 1591 | |||
| 1527 | /* order statis text output */ | 1592 | /* order statis text output */ |
| 1528 | if (order_mode) { | 1593 | if (order_mode) { |
| 1529 | if (status == STATE_OK) | 1594 | if (status == STATE_OK) { |
| 1530 | printf(" Packets in order"); | 1595 | printf(" Packets in order"); |
| 1531 | else if (status == STATE_CRITICAL && host->order_status == status) | 1596 | } else if (status == STATE_CRITICAL && host->order_status == status) { |
| 1532 | printf(" Packets out of order"); | 1597 | printf(" Packets out of order"); |
| 1598 | } | ||
| 1533 | } | 1599 | } |
| 1534 | } | 1600 | } |
| 1535 | host = host->next; | 1601 | host = host->next; |
| @@ -1542,8 +1608,9 @@ static void finish(int sig) { | |||
| 1542 | i = 0; | 1608 | i = 0; |
| 1543 | host = list; | 1609 | host = list; |
| 1544 | while (host) { | 1610 | while (host) { |
| 1545 | if (debug) | 1611 | if (debug) { |
| 1546 | puts(""); | 1612 | puts(""); |
| 1613 | } | ||
| 1547 | 1614 | ||
| 1548 | if (rta_mode) { | 1615 | if (rta_mode) { |
| 1549 | if (host->pl < 100) { | 1616 | if (host->pl < 100) { |
| @@ -1593,17 +1660,19 @@ static void finish(int sig) { | |||
| 1593 | } | 1660 | } |
| 1594 | 1661 | ||
| 1595 | if (min_hosts_alive > -1) { | 1662 | if (min_hosts_alive > -1) { |
| 1596 | if (hosts_ok >= min_hosts_alive) | 1663 | if (hosts_ok >= min_hosts_alive) { |
| 1597 | status = STATE_OK; | 1664 | status = STATE_OK; |
| 1598 | else if ((hosts_ok + hosts_warn) >= min_hosts_alive) | 1665 | } else if ((hosts_ok + hosts_warn) >= min_hosts_alive) { |
| 1599 | status = STATE_WARNING; | 1666 | status = STATE_WARNING; |
| 1667 | } | ||
| 1600 | } | 1668 | } |
| 1601 | 1669 | ||
| 1602 | /* finish with an empty line */ | 1670 | /* finish with an empty line */ |
| 1603 | puts(""); | 1671 | puts(""); |
| 1604 | if (debug) | 1672 | if (debug) { |
| 1605 | printf("targets: %u, targets_alive: %u, hosts_ok: %u, hosts_warn: %u, min_hosts_alive: %i\n", targets, targets_alive, hosts_ok, | 1673 | printf("targets: %u, targets_alive: %u, hosts_ok: %u, hosts_warn: %u, min_hosts_alive: %i\n", targets, targets_alive, hosts_ok, |
| 1606 | hosts_warn, min_hosts_alive); | 1674 | hosts_warn, min_hosts_alive); |
| 1675 | } | ||
| 1607 | 1676 | ||
| 1608 | exit(status); | 1677 | exit(status); |
| 1609 | } | 1678 | } |
| @@ -1616,8 +1685,9 @@ static u_int get_timevaldiff(struct timeval *early, struct timeval *later) { | |||
| 1616 | gettimeofday(&now, &tz); | 1685 | gettimeofday(&now, &tz); |
| 1617 | later = &now; | 1686 | later = &now; |
| 1618 | } | 1687 | } |
| 1619 | if (!early) | 1688 | if (!early) { |
| 1620 | early = &prog_start; | 1689 | early = &prog_start; |
| 1690 | } | ||
| 1621 | 1691 | ||
| 1622 | /* if early > later we return 0 so as to indicate a timeout */ | 1692 | /* if early > later we return 0 so as to indicate a timeout */ |
| 1623 | if (early->tv_sec > later->tv_sec || (early->tv_sec == later->tv_sec && early->tv_usec > later->tv_usec)) { | 1693 | if (early->tv_sec > later->tv_sec || (early->tv_sec == later->tv_sec && early->tv_usec > later->tv_usec)) { |
| @@ -1634,10 +1704,11 @@ static int add_target_ip(char *arg, struct sockaddr_storage *in) { | |||
| 1634 | struct sockaddr_in *sin, *host_sin; | 1704 | struct sockaddr_in *sin, *host_sin; |
| 1635 | struct sockaddr_in6 *sin6, *host_sin6; | 1705 | struct sockaddr_in6 *sin6, *host_sin6; |
| 1636 | 1706 | ||
| 1637 | if (address_family == AF_INET) | 1707 | if (address_family == AF_INET) { |
| 1638 | sin = (struct sockaddr_in *)in; | 1708 | sin = (struct sockaddr_in *)in; |
| 1639 | else | 1709 | } else { |
| 1640 | sin6 = (struct sockaddr_in6 *)in; | 1710 | sin6 = (struct sockaddr_in6 *)in; |
| 1711 | } | ||
| 1641 | 1712 | ||
| 1642 | /* disregard obviously stupid addresses | 1713 | /* disregard obviously stupid addresses |
| 1643 | * (I didn't find an ipv6 equivalent to INADDR_NONE) */ | 1714 | * (I didn't find an ipv6 equivalent to INADDR_NONE) */ |
| @@ -1654,8 +1725,9 @@ static int add_target_ip(char *arg, struct sockaddr_storage *in) { | |||
| 1654 | 1725 | ||
| 1655 | if ((address_family == AF_INET && host_sin->sin_addr.s_addr == sin->sin_addr.s_addr) || | 1726 | if ((address_family == AF_INET && host_sin->sin_addr.s_addr == sin->sin_addr.s_addr) || |
| 1656 | (address_family == AF_INET6 && host_sin6->sin6_addr.s6_addr == sin6->sin6_addr.s6_addr)) { | 1727 | (address_family == AF_INET6 && host_sin6->sin6_addr.s6_addr == sin6->sin6_addr.s6_addr)) { |
| 1657 | if (debug) | 1728 | if (debug) { |
| 1658 | printf("Identical IP already exists. Not adding %s\n", arg); | 1729 | printf("Identical IP already exists. Not adding %s\n", arg); |
| 1730 | } | ||
| 1659 | return -1; | 1731 | return -1; |
| 1660 | } | 1732 | } |
| 1661 | host = host->next; | 1733 | host = host->next; |
| @@ -1700,10 +1772,11 @@ static int add_target_ip(char *arg, struct sockaddr_storage *in) { | |||
| 1700 | host->score_status = 0; | 1772 | host->score_status = 0; |
| 1701 | host->pl_status = 0; | 1773 | host->pl_status = 0; |
| 1702 | 1774 | ||
| 1703 | if (!list) | 1775 | if (!list) { |
| 1704 | list = cursor = host; | 1776 | list = cursor = host; |
| 1705 | else | 1777 | } else { |
| 1706 | cursor->next = host; | 1778 | cursor->next = host; |
| 1779 | } | ||
| 1707 | 1780 | ||
| 1708 | cursor = host; | 1781 | cursor = host; |
| 1709 | targets++; | 1782 | targets++; |
| @@ -1777,8 +1850,9 @@ static int add_target(char *arg) { | |||
| 1777 | 1850 | ||
| 1778 | /* this is silly, but it works */ | 1851 | /* this is silly, but it works */ |
| 1779 | if (mode == MODE_HOSTCHECK || mode == MODE_ALL) { | 1852 | if (mode == MODE_HOSTCHECK || mode == MODE_ALL) { |
| 1780 | if (debug > 2) | 1853 | if (debug > 2) { |
| 1781 | printf("mode: %d\n", mode); | 1854 | printf("mode: %d\n", mode); |
| 1855 | } | ||
| 1782 | continue; | 1856 | continue; |
| 1783 | } | 1857 | } |
| 1784 | break; | 1858 | break; |
| @@ -1793,10 +1867,12 @@ static void set_source_ip(char *arg) { | |||
| 1793 | 1867 | ||
| 1794 | memset(&src, 0, sizeof(src)); | 1868 | memset(&src, 0, sizeof(src)); |
| 1795 | src.sin_family = address_family; | 1869 | src.sin_family = address_family; |
| 1796 | if ((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE) | 1870 | if ((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE) { |
| 1797 | src.sin_addr.s_addr = get_ip_address(arg); | 1871 | src.sin_addr.s_addr = get_ip_address(arg); |
| 1798 | if (bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1) | 1872 | } |
| 1873 | if (bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1) { | ||
| 1799 | crash("Cannot bind to IP address %s", arg); | 1874 | crash("Cannot bind to IP address %s", arg); |
| 1875 | } | ||
| 1800 | } | 1876 | } |
| 1801 | 1877 | ||
| 1802 | /* TODO: Move this to netutils.c and also change check_dhcp to use that. */ | 1878 | /* TODO: Move this to netutils.c and also change check_dhcp to use that. */ |
| @@ -1811,8 +1887,9 @@ static in_addr_t get_ip_address(const char *ifname) { | |||
| 1811 | 1887 | ||
| 1812 | ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0'; | 1888 | ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0'; |
| 1813 | 1889 | ||
| 1814 | if (ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1) | 1890 | if (ioctl(icmp_sock, SIOCGIFADDR, &ifr) == -1) { |
| 1815 | crash("Cannot determine IP address of interface %s", ifname); | 1891 | crash("Cannot determine IP address of interface %s", ifname); |
| 1892 | } | ||
| 1816 | 1893 | ||
| 1817 | memcpy(&ip, &ifr.ifr_addr, sizeof(ip)); | 1894 | memcpy(&ip, &ifr.ifr_addr, sizeof(ip)); |
| 1818 | #else | 1895 | #else |
| @@ -1835,47 +1912,57 @@ static u_int get_timevar(const char *str) { | |||
| 1835 | u_int i, d; /* integer and decimal, respectively */ | 1912 | u_int i, d; /* integer and decimal, respectively */ |
| 1836 | u_int factor = 1000; /* default to milliseconds */ | 1913 | u_int factor = 1000; /* default to milliseconds */ |
| 1837 | 1914 | ||
| 1838 | if (!str) | 1915 | if (!str) { |
| 1839 | return 0; | 1916 | return 0; |
| 1917 | } | ||
| 1840 | len = strlen(str); | 1918 | len = strlen(str); |
| 1841 | if (!len) | 1919 | if (!len) { |
| 1842 | return 0; | 1920 | return 0; |
| 1921 | } | ||
| 1843 | 1922 | ||
| 1844 | /* unit might be given as ms|m (millisec), | 1923 | /* unit might be given as ms|m (millisec), |
| 1845 | * us|u (microsec) or just plain s, for seconds */ | 1924 | * us|u (microsec) or just plain s, for seconds */ |
| 1846 | p = '\0'; | 1925 | p = '\0'; |
| 1847 | u = str[len - 1]; | 1926 | u = str[len - 1]; |
| 1848 | if (len >= 2 && !isdigit((int)str[len - 2])) | 1927 | if (len >= 2 && !isdigit((int)str[len - 2])) { |
| 1849 | p = str[len - 2]; | 1928 | p = str[len - 2]; |
| 1850 | if (p && u == 's') | 1929 | } |
| 1930 | if (p && u == 's') { | ||
| 1851 | u = p; | 1931 | u = p; |
| 1852 | else if (!p) | 1932 | } else if (!p) { |
| 1853 | p = u; | 1933 | p = u; |
| 1854 | if (debug > 2) | 1934 | } |
| 1935 | if (debug > 2) { | ||
| 1855 | printf("evaluating %s, u: %c, p: %c\n", str, u, p); | 1936 | printf("evaluating %s, u: %c, p: %c\n", str, u, p); |
| 1937 | } | ||
| 1856 | 1938 | ||
| 1857 | if (u == 'u') | 1939 | if (u == 'u') { |
| 1858 | factor = 1; /* microseconds */ | 1940 | factor = 1; /* microseconds */ |
| 1859 | else if (u == 'm') | 1941 | } else if (u == 'm') { |
| 1860 | factor = 1000; /* milliseconds */ | 1942 | factor = 1000; /* milliseconds */ |
| 1861 | else if (u == 's') | 1943 | } else if (u == 's') { |
| 1862 | factor = 1000000; /* seconds */ | 1944 | factor = 1000000; /* seconds */ |
| 1863 | if (debug > 2) | 1945 | } |
| 1946 | if (debug > 2) { | ||
| 1864 | printf("factor is %u\n", factor); | 1947 | printf("factor is %u\n", factor); |
| 1948 | } | ||
| 1865 | 1949 | ||
| 1866 | i = strtoul(str, &ptr, 0); | 1950 | i = strtoul(str, &ptr, 0); |
| 1867 | if (!ptr || *ptr != '.' || strlen(ptr) < 2 || factor == 1) | 1951 | if (!ptr || *ptr != '.' || strlen(ptr) < 2 || factor == 1) { |
| 1868 | return i * factor; | 1952 | return i * factor; |
| 1953 | } | ||
| 1869 | 1954 | ||
| 1870 | /* time specified in usecs can't have decimal points, so ignore them */ | 1955 | /* time specified in usecs can't have decimal points, so ignore them */ |
| 1871 | if (factor == 1) | 1956 | if (factor == 1) { |
| 1872 | return i; | 1957 | return i; |
| 1958 | } | ||
| 1873 | 1959 | ||
| 1874 | d = strtoul(ptr + 1, NULL, 0); | 1960 | d = strtoul(ptr + 1, NULL, 0); |
| 1875 | 1961 | ||
| 1876 | /* d is decimal, so get rid of excess digits */ | 1962 | /* d is decimal, so get rid of excess digits */ |
| 1877 | while (d >= factor) | 1963 | while (d >= factor) { |
| 1878 | d /= 10; | 1964 | d /= 10; |
| 1965 | } | ||
| 1879 | 1966 | ||
| 1880 | /* the last parenthesis avoids floating point exceptions. */ | 1967 | /* the last parenthesis avoids floating point exceptions. */ |
| 1881 | return ((i * factor) + (d * (factor / 10))); | 1968 | return ((i * factor) + (d * (factor / 10))); |
| @@ -1885,15 +1972,16 @@ static u_int get_timevar(const char *str) { | |||
| 1885 | static int get_threshold(char *str, threshold *th) { | 1972 | static int get_threshold(char *str, threshold *th) { |
| 1886 | char *p = NULL, i = 0; | 1973 | char *p = NULL, i = 0; |
| 1887 | 1974 | ||
| 1888 | if (!str || !strlen(str) || !th) | 1975 | if (!str || !strlen(str) || !th) { |
| 1889 | return -1; | 1976 | return -1; |
| 1977 | } | ||
| 1890 | 1978 | ||
| 1891 | /* pointer magic slims code by 10 lines. i is bof-stop on stupid libc's */ | 1979 | /* pointer magic slims code by 10 lines. i is bof-stop on stupid libc's */ |
| 1892 | p = &str[strlen(str) - 1]; | 1980 | p = &str[strlen(str) - 1]; |
| 1893 | while (p != &str[1]) { | 1981 | while (p != &str[1]) { |
| 1894 | if (*p == '%') | 1982 | if (*p == '%') { |
| 1895 | *p = '\0'; | 1983 | *p = '\0'; |
| 1896 | else if (*p == ',' && i) { | 1984 | } else if (*p == ',' && i) { |
| 1897 | *p = '\0'; /* reset it so get_timevar(str) works nicely later */ | 1985 | *p = '\0'; /* reset it so get_timevar(str) works nicely later */ |
| 1898 | th->pl = (unsigned char)strtoul(p + 1, NULL, 0); | 1986 | th->pl = (unsigned char)strtoul(p + 1, NULL, 0); |
| 1899 | break; | 1987 | break; |
| @@ -1903,13 +1991,16 @@ static int get_threshold(char *str, threshold *th) { | |||
| 1903 | } | 1991 | } |
| 1904 | th->rta = get_timevar(str); | 1992 | th->rta = get_timevar(str); |
| 1905 | 1993 | ||
| 1906 | if (!th->rta) | 1994 | if (!th->rta) { |
| 1907 | return -1; | 1995 | return -1; |
| 1996 | } | ||
| 1908 | 1997 | ||
| 1909 | if (th->rta > MAXTTL * 1000000) | 1998 | if (th->rta > MAXTTL * 1000000) { |
| 1910 | th->rta = MAXTTL * 1000000; | 1999 | th->rta = MAXTTL * 1000000; |
| 1911 | if (th->pl > 100) | 2000 | } |
| 2001 | if (th->pl > 100) { | ||
| 1912 | th->pl = 100; | 2002 | th->pl = 100; |
| 2003 | } | ||
| 1913 | 2004 | ||
| 1914 | return 0; | 2005 | return 0; |
| 1915 | } | 2006 | } |
| @@ -1925,8 +2016,9 @@ static int get_threshold(char *str, threshold *th) { | |||
| 1925 | * @param[in] mode Determines whether this a threshold for rta, packet_loss, jitter, mos or score (exclusively) | 2016 | * @param[in] mode Determines whether this a threshold for rta, packet_loss, jitter, mos or score (exclusively) |
| 1926 | */ | 2017 | */ |
| 1927 | static bool get_threshold2(char *str, size_t length, threshold *warn, threshold *crit, threshold_mode mode) { | 2018 | static bool get_threshold2(char *str, size_t length, threshold *warn, threshold *crit, threshold_mode mode) { |
| 1928 | if (!str || !length || !warn || !crit) | 2019 | if (!str || !length || !warn || !crit) { |
| 1929 | return false; | 2020 | return false; |
| 2021 | } | ||
| 1930 | 2022 | ||
| 1931 | // p points to the last char in str | 2023 | // p points to the last char in str |
| 1932 | char *p = &str[length - 1]; | 2024 | char *p = &str[length - 1]; |
| @@ -1999,8 +2091,9 @@ unsigned short icmp_checksum(uint16_t *p, size_t n) { | |||
| 1999 | } | 2091 | } |
| 2000 | 2092 | ||
| 2001 | /* mop up the occasional odd byte */ | 2093 | /* mop up the occasional odd byte */ |
| 2002 | if (n == 1) | 2094 | if (n == 1) { |
| 2003 | sum += *((uint8_t *)p - 1); | 2095 | sum += *((uint8_t *)p - 1); |
| 2096 | } | ||
| 2004 | 2097 | ||
| 2005 | sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ | 2098 | sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ |
| 2006 | sum += (sum >> 16); /* add carry */ | 2099 | sum += (sum >> 16); /* add carry */ |
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 8ea73ce1..748201e8 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
| @@ -818,8 +818,11 @@ int check_http(void) { | |||
| 818 | 818 | ||
| 819 | /* cookie handling */ | 819 | /* cookie handling */ |
| 820 | if (cookie_jar_file != NULL) { | 820 | if (cookie_jar_file != NULL) { |
| 821 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookie_jar_file), "CURLOPT_COOKIEJAR"); | 821 | /* enable reading cookies from a file, and if the filename is an empty string, only enable the curl cookie engine */ |
| 822 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookie_jar_file), "CURLOPT_COOKIEFILE"); | 822 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookie_jar_file), "CURLOPT_COOKIEFILE"); |
| 823 | /* now enable saving cookies to a file, but only if the filename is not an empty string, since writing it would fail */ | ||
| 824 | if (*cookie_jar_file) | ||
| 825 | handle_curl_option_return_code(curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookie_jar_file), "CURLOPT_COOKIEJAR"); | ||
| 823 | } | 826 | } |
| 824 | 827 | ||
| 825 | /* do the request */ | 828 | /* do the request */ |
| @@ -1912,7 +1915,7 @@ void print_help(void) { | |||
| 1912 | printf(" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents")); | 1915 | printf(" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents")); |
| 1913 | printf(" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,")); | 1916 | printf(" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,")); |
| 1914 | printf(" %s\n", _("1.2 = TLSv1.2, 1.3 = TLSv1.3). With a '+' suffix, newer versions are also accepted.")); | 1917 | printf(" %s\n", _("1.2 = TLSv1.2, 1.3 = TLSv1.3). With a '+' suffix, newer versions are also accepted.")); |
| 1915 | printf(" %s\n", _("Note: SSLv2 and SSLv3 are deprecated and are usually disabled in libcurl")); | 1918 | printf(" %s\n", _("Note: SSLv2, SSLv3, TLSv1.0 and TLSv1.1 are deprecated and are usually disabled in libcurl")); |
| 1916 | printf(" %s\n", "--sni"); | 1919 | printf(" %s\n", "--sni"); |
| 1917 | printf(" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); | 1920 | printf(" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); |
| 1918 | # if LIBCURL_VERSION_NUM >= 0x071801 | 1921 | # if LIBCURL_VERSION_NUM >= 0x071801 |
| @@ -2011,6 +2014,9 @@ void print_help(void) { | |||
| 2011 | printf(" %s\n", _("Send HAProxy proxy protocol v1 header (CURLOPT_HAPROXYPROTOCOL).")); | 2014 | printf(" %s\n", _("Send HAProxy proxy protocol v1 header (CURLOPT_HAPROXYPROTOCOL).")); |
| 2012 | printf(" %s\n", "--cookie-jar=FILE"); | 2015 | printf(" %s\n", "--cookie-jar=FILE"); |
| 2013 | printf(" %s\n", _("Store cookies in the cookie jar and send them out when requested.")); | 2016 | printf(" %s\n", _("Store cookies in the cookie jar and send them out when requested.")); |
| 2017 | printf(" %s\n", _("Specify an empty string as FILE to enable curl's cookie engine without saving")); | ||
| 2018 | printf(" %s\n", _("the cookies to disk. Only enabling the engine without saving to disk requires")); | ||
| 2019 | printf(" %s\n", _("handling multiple requests internally to curl, so use it with --onredirect=curl")); | ||
| 2014 | printf("\n"); | 2020 | printf("\n"); |
| 2015 | 2021 | ||
| 2016 | printf(UT_WARN_CRIT); | 2022 | printf(UT_WARN_CRIT); |
