/usr/share/zonecheck/test/connectivity.rb is in zonecheck 3.0.5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | # ZCTEST 1.0
# $Id: connectivity.rb,v 1.24 2010/06/07 08:51:25 chabannf Exp $
#
# CONTACT : zonecheck@nic.fr
# AUTHOR : Stephane D'Alu <sdalu@nic.fr>
#
# CREATED : 2002/08/02 13:58:17
# REVISION : $Revision: 1.24 $
# DATE : $Date: 2010/06/07 08:51:25 $
#
# CONTRIBUTORS: (see also CREDITS file)
#
#
# LICENSE : GPL v3
# COPYRIGHT : AFNIC (c) 2003
#
# This file is part of ZoneCheck.
#
# ZoneCheck is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# ZoneCheck is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ZoneCheck; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#####
#
# WARN:
# - 'chk_icmp' contains system dependant 'ping' command
# although -q and -c option seems to be fairly standard,
# unfortunately 'ping' is not part of POSIX
#
# OPEN:
# - 'chk_udp' perhaps used a SOA request instead of a 'server status'
# in case the tested DNS uses view
#
# BUGFIX:
# - chk_udp: recvfrom reject datagram bigger than the requested size
# instead of copying the beginning
# using the NResolv::DNS::UDPSize instead of 1 byte
#
require 'framework'
require 'timeout'
module CheckNetworkAddress
##
## Check nameserver connectivity (ICMP, UDP, TCP)
##
## - as request are directly made to the DNS (no CacheManager)
## the tests won't be affected by the transport flags
##
class Connectivity < Test
with_msgcat 'test/connectivity.%s'
def initialize(*args)
super(*args)
@ping4_cmd = const('ping4')
@ping6_cmd = const('ping6')
end
#-- Checks --------------------------------------------------
# DESC: Test TCP connectivity with DNS server
def chk_tcp(ns, ip)
# The idea is to open a TCP connection
# if no one is listening => Errno::ECONNREFUSED
# if there is a firewal (timeout) => Errno::EINVAL
# Errno::ECONNRESET
# The total timeout has been forced to 8 seconds
# as with the chk_udp test
msg_dr = Dnsruby::Message::new(@domain.name.to_s,"ANY")
rawmsg_dr = msg_dr.encode()
sock = nil
begin
timeout(8) {
sock = TCPSocket::new(ip.to_s, 53)
sock.write([rawmsg_dr.length].pack('n'))
sock.write(rawmsg_dr)
lenhdr = sock.read(2)
return false if lenhdr.nil? || lenhdr.size != 2
len = lenhdr.unpack('n')[0]
reply = sock.read(len)
}
true
rescue Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EINVAL,
TimeoutError
false
ensure
sock.close unless sock.nil?
end
end
# DESC: Test UDP connectivity with DNS server
def chk_udp(ns, ip)
# The idea is to send 25 'query' concerning the domain in 5 seconds
# if we received one answer within 8 seconds (dont care about
# its content, we consider it sucessful)
msg_dr = Dnsruby::Message::new(@domain.name.to_s,"ANY")
rawmsg_dr = msg_dr.encode()
sock = nil
thr = nil
begin
case ip
when Dnsruby::IPv4
protocol = Socket::AF_INET
when Dnsruby::IPv6
protocol = Socket::AF_INET6
else
protocol = nil
raise ArgumentError, 'Argument should be an address'
end
sock = UDPSocket::new(protocol)
sock.connect(ip.to_s, 53)
thr = Thread::new {
(1..25).each { sock.write(rawmsg_dr) ; sleep(0.2) }
}
timeout(8) { sock.recv(512) }
true
rescue Errno::ECONNREFUSED, TimeoutError
false
ensure
thr.kill unless thr.nil?
sock.close unless sock.nil?
end
end
# DESC: Test if host is alive (watch for firewall)
def chk_icmp(ns, ip)
# Build ping command
ping_tmpl = case ip
when Dnsruby::IPv4 then @ping4_cmd
when Dnsruby::IPv6 then @ping6_cmd
else raise 'INTERNAL: Unknown address format'
end
ping_cmd = ping_tmpl % [ ip.to_s ]
# Do ping
dbgmsg(ns, ip) { "Executing: #{ping_cmd}" }
system(ping_cmd)
end
end
end
|