summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS4
-rw-r--r--THANKS.in1
-rw-r--r--plugins/check_dns.c2
-rw-r--r--plugins/t/check_dns.t22
4 files changed, 26 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 9462d7a..7be8048 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,10 @@
1This file documents the major additions and syntax changes between releases. 1This file documents the major additions and syntax changes between releases.
2 2
32.3 [...] 32.3 [...]
4 ENHANCEMENTS
5 check_dns: allow 'expected address' (-a) to be specified in CIDR notation
6 (IPv4 only).
7
4 FIXES 8 FIXES
5 Fix regression where check_dhcp was rereading response in a tight loop 9 Fix regression where check_dhcp was rereading response in a tight loop
6 10
diff --git a/THANKS.in b/THANKS.in
index 86767c4..ebc8155 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -355,3 +355,4 @@ Michael Melcher
355Sven Geggus 355Sven Geggus
356Thomas Kurschel 356Thomas Kurschel
357Yannick Charton 357Yannick Charton
358Nicolai Søborg
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 4067c14..5feafc8 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -308,7 +308,7 @@ ip_match_cidr(const char *addr, const char *cidr_ro)
308 mask = atoi(mask_c); 308 mask = atoi(mask_c);
309 309
310 /* https://www.cryptobells.com/verifying-ips-in-a-subnet-in-php/ */ 310 /* https://www.cryptobells.com/verifying-ips-in-a-subnet-in-php/ */
311 return ( ip2long(addr) & ~ ( ( 1 << ( 32 - mask ) ) - 1 ) ) == ( ip2long(subnet) >> (32 - mask) ) << (32 - mask); 311 return (ip2long(addr) & ~((1 << (32 - mask)) - 1)) == (ip2long(subnet) >> (32 - mask)) << (32 - mask);
312} 312}
313 313
314unsigned long 314unsigned long
diff --git a/plugins/t/check_dns.t b/plugins/t/check_dns.t
index 035e768..3dbb718 100644
--- a/plugins/t/check_dns.t
+++ b/plugins/t/check_dns.t
@@ -10,7 +10,7 @@ use NPTest;
10 10
11plan skip_all => "check_dns not compiled" unless (-x "check_dns"); 11plan skip_all => "check_dns not compiled" unless (-x "check_dns");
12 12
13plan tests => 16; 13plan tests => 19;
14 14
15my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/'; 15my $successOutput = '/DNS OK: [\.0-9]+ seconds? response time/';
16 16
@@ -23,7 +23,19 @@ my $hostname_valid = getTestParameter(
23my $hostname_valid_ip = getTestParameter( 23my $hostname_valid_ip = getTestParameter(
24 "NP_HOSTNAME_VALID_IP", 24 "NP_HOSTNAME_VALID_IP",
25 "The IP address of the valid hostname $hostname_valid", 25 "The IP address of the valid hostname $hostname_valid",
26 "66.118.156.50", 26 "130.133.8.40",
27 );
28
29my $hostname_valid_cidr = getTestParameter(
30 "NP_HOSTNAME_VALID_CIDR",
31 "An valid CIDR range containing $hostname_valid_ip",
32 "130.133.8.41/30",
33 );
34
35my $hostname_invalid_cidr = getTestParameter(
36 "NP_HOSTNAME_INVALID_CIDR",
37 "An valid CIDR range not containing $hostname_valid_ip",
38 "130.133.8.39/30",
27 ); 39 );
28 40
29my $hostname_valid_reverse = getTestParameter( 41my $hostname_valid_reverse = getTestParameter(
@@ -87,3 +99,9 @@ $res = NPTest->testCmd("./check_dns -H $hostname_valid_ip -a $hostname_valid_rev
87cmp_ok( $res->return_code, '==', 0, "Got expected fqdn"); 99cmp_ok( $res->return_code, '==', 0, "Got expected fqdn");
88like ( $res->output, $successOutput, "Output OK"); 100like ( $res->output, $successOutput, "Output OK");
89 101
102$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_valid_cidr -t 5");
103cmp_ok( $res->return_code, '==', 0, "Got expected address");
104
105$res = NPTest->testCmd("./check_dns -H $hostname_valid -a $hostname_invalid_cidr -t 5");
106cmp_ok( $res->return_code, '==', 2, "Got wrong address");
107like ( $res->output, "/^DNS CRITICAL.*expected '$hostname_invalid_cidr' but got '$hostname_valid_ip'".'$/', "Output OK");