Class: Dnsruby::RR
- Inherits:
-
Object
- Object
- Dnsruby::RR
- Includes:
- Comparable
- Defined in:
- lib/dnsruby/resource/A.rb,
lib/dnsruby/resource/DS.rb,
lib/dnsruby/resource/IN.rb,
lib/dnsruby/resource/KX.rb,
lib/dnsruby/resource/MX.rb,
lib/dnsruby/resource/PX.rb,
lib/dnsruby/resource/RP.rb,
lib/dnsruby/resource/RR.rb,
lib/dnsruby/resource/RT.rb,
lib/dnsruby/resource/APL.rb,
lib/dnsruby/resource/CAA.rb,
lib/dnsruby/resource/CDS.rb,
lib/dnsruby/resource/DLV.rb,
lib/dnsruby/resource/HIP.rb,
lib/dnsruby/resource/LOC.rb,
lib/dnsruby/resource/NXT.rb,
lib/dnsruby/resource/OPT.rb,
lib/dnsruby/resource/SOA.rb,
lib/dnsruby/resource/SPF.rb,
lib/dnsruby/resource/SRV.rb,
lib/dnsruby/resource/TXT.rb,
lib/dnsruby/resource/URI.rb,
lib/dnsruby/resource/X25.rb,
lib/dnsruby/resource/AAAA.rb,
lib/dnsruby/resource/CERT.rb,
lib/dnsruby/resource/GPOS.rb,
lib/dnsruby/resource/ISDN.rb,
lib/dnsruby/resource/NSAP.rb,
lib/dnsruby/resource/NSEC.rb,
lib/dnsruby/resource/SVCB.rb,
lib/dnsruby/resource/TKEY.rb,
lib/dnsruby/resource/TLSA.rb,
lib/dnsruby/resource/TSIG.rb,
lib/dnsruby/resource/AFSDB.rb,
lib/dnsruby/resource/DHCID.rb,
lib/dnsruby/resource/HINFO.rb,
lib/dnsruby/resource/HTTPS.rb,
lib/dnsruby/resource/MINFO.rb,
lib/dnsruby/resource/NAPTR.rb,
lib/dnsruby/resource/NSEC3.rb,
lib/dnsruby/resource/RRSIG.rb,
lib/dnsruby/resource/SSHFP.rb,
lib/dnsruby/resource/DNSKEY.rb,
lib/dnsruby/resource/CDNSKEY.rb,
lib/dnsruby/resource/generic.rb,
lib/dnsruby/resource/IPSECKEY.rb,
lib/dnsruby/resource/NSEC3PARAM.rb,
lib/dnsruby/resource/domain_name.rb,
lib/dnsruby/resource/generic_cache.rb,
lib/dnsruby/resource/generic_constants.rb
Defined Under Namespace
Modules: EmptyUpdateData, GenericCache, GenericConstantInspection, GenericRegistryChanges, IN Classes: ANY, CAA, CDNSKEY, CDS, CERT, CNAME, DHCID, DLV, DNAME, DNSKEY, DS, DomainName, GPOS, Generic, HINFO, HIP, HTTPS, IPSECKEY, ISDN, KX, LOC, MB, MG, MINFO, MR, MX, NAPTR, NS, NSAP, NSEC, NSEC3, NSEC3PARAM, NXT, OPT, PTR, RP, RRSIG, RT, SOA, SPF, SSHFP, SVCB, TKEY, TSIG, TXT, URI, X25
Constant Summary collapse
- ClassInsensitiveTypes =
{ Types::NS => NS, Types::CNAME => CNAME, Types::DNAME => DNAME, Types::URI => URI, Types::DS => DS, Types::CDS => CDS, Types::DNSKEY => DNSKEY, Types::CDNSKEY => CDNSKEY, Types::SOA => SOA, Types::PTR => PTR, Types::HINFO => HINFO, Types::MINFO => MINFO, Types::MX => MX, Types::TXT => TXT, Types::ISDN => ISDN, Types::MB => MB, Types::MG => MG, Types::MR => MR, Types::NAPTR => NAPTR, Types::NSAP => NSAP, Types::OPT => OPT, Types::RP => RP, Types::RT => RT, Types::X25 => X25, Types::KX => KX, Types::SPF => SPF, Types::CERT => CERT, Types::LOC => LOC, Types::TSIG => TSIG, Types::TKEY => TKEY, Types::ANY => ANY, Types::RRSIG => RRSIG, Types::NSEC => NSEC, Types::NSEC3 => NSEC3, Types::NSEC3PARAM => NSEC3PARAM, Types::DLV => DLV, Types::SSHFP => SSHFP, Types::IPSECKEY => IPSECKEY, Types::HIP => HIP, Types::DHCID => DHCID, Types::GPOS => GPOS, Types::NXT => NXT, Types::CAA => CAA, }
- @@RR_REGEX =
A regular expression which catches any valid resource record.
Regexp.new("^\\s*((?:\\\\.|\\S)+)\\s*(\\d+)?\\s*(#{Classes.regexp + "|CLASS\\d+"})?\\s*(#{Types.regexp + '|TYPE\\d+'})?\\s*([\\s\\S]*)\$")
- @@implemented_rr_map =
nil
Instance Attribute Summary collapse
-
#klass ⇒ Object
The Resource class.
-
#name ⇒ Object
The Resource's domain name.
-
#rdata ⇒ Object
The Resource data section.
-
#ttl ⇒ Object
The Resource Time-To-Live.
-
#type ⇒ Object
(also: #rr_type)
The Resource type.
Class Method Summary collapse
-
.decode_rdata(msg) ⇒ Object
:nodoc: all.
-
.empty_update_record(name, type, klass) ⇒ Object
:nodoc: all.
-
.empty_update_type?(type, klass) ⇒ Boolean
:nodoc: all.
-
.find_class(type_value, class_value) ⇒ Object
:nodoc: all.
-
.get_class(type_value, class_value) ⇒ Object
Get an RR of the specified type and class.
- .get_num(bytes) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #clone ⇒ Object
-
#encode_rdata(msg, canonical = false) ⇒ Object
:nodoc: all.
-
#eql?(other) ⇒ Boolean
:nodoc:.
-
#from_data(data) ⇒ Object
:nodoc: all.
-
#from_hash(hash) ⇒ Object
:nodoc: all.
-
#from_string(input) ⇒ Object
:nodoc: all.
-
#hash ⇒ Object
:nodoc:.
- #init_defaults ⇒ Object
-
#rdata_to_string ⇒ Object
Get a string representation of the data section of the RR (in zone file format).
- #rdlength ⇒ Object
-
#sameRRset(rec) ⇒ Object
Determines if two Records could be part of the same RRset.
-
#to_s ⇒ Object
Returns a string representation of the RR in zone file format.
-
#validate_decoded_rdata ⇒ Object
Some formats depend on the actual RR class, which is assigned after the format-specific decoder runs (notably ANY/NONE UPDATE markers).
Instance Attribute Details
#klass ⇒ Object
The Resource class
47 48 49 |
# File 'lib/dnsruby/resource/RR.rb', line 47 def klass @klass end |
#name ⇒ Object
The Resource's domain name
41 42 43 |
# File 'lib/dnsruby/resource/RR.rb', line 41 def name @name end |
#rdata ⇒ Object
The Resource data section
53 54 55 |
# File 'lib/dnsruby/resource/RR.rb', line 53 def rdata @rdata end |
#ttl ⇒ Object
The Resource Time-To-Live
50 51 52 |
# File 'lib/dnsruby/resource/RR.rb', line 50 def ttl @ttl end |
#type ⇒ Object Also known as: rr_type
The Resource type
44 45 46 |
# File 'lib/dnsruby/resource/RR.rb', line 44 def type @type end |
Class Method Details
.decode_rdata(msg) ⇒ Object
:nodoc: all
366 367 368 369 |
# File 'lib/dnsruby/resource/RR.rb', line 366 def self.decode_rdata(msg) #:nodoc: all # to be implemented by subclasses raise DecodeError.new("#{self.class} is RR.") end |
.empty_update_record(name, type, klass) ⇒ Object
:nodoc: all
314 315 316 317 318 319 320 |
# File 'lib/dnsruby/resource/RR.rb', line 314 def self.empty_update_record(name, type, klass) #:nodoc: all raise ArgumentError, 'Invalid empty UPDATE record type or class' unless empty_update_type?(type, klass) record_class = get_class(type, klass) record = record_class <= RR::DomainName ? record_class.new(Name.new([])) : record_class.new record.name, record.type, record.klass, record.ttl, record.rdata = name, type, klass, 0, '' record.extend(EmptyUpdateData) end |
.empty_update_type?(type, klass) ⇒ Boolean
:nodoc: all
308 309 310 311 312 |
# File 'lib/dnsruby/resource/RR.rb', line 308 def self.empty_update_type?(type, klass) #:nodoc: all code = Types.new(type).code [Classes::ANY, Classes::NONE].include?(Classes.new(klass)) && code > 0 && code != Types::OPT && !(128..254).cover?(code) end |
.find_class(type_value, class_value) ⇒ Object
:nodoc: all
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/dnsruby/resource/RR.rb', line 398 def self.find_class(type_value, class_value) # :nodoc: all if !! (ret = ClassHash[[type_value, class_value]]) return ret elsif !! (ret = GenericCache.find(type_value, class_value)) return ret elsif !! (val = ClassInsensitiveTypes[type_value]) klass = Class.new(val) klass.const_set(:TypeValue, type_value) klass.const_set(:ClassValue, class_value) return klass else return GenericCache.factory(type_value, class_value) do Generic.create(type_value, class_value) end end end |
.get_class(type_value, class_value) ⇒ Object
Get an RR of the specified type and class
416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/dnsruby/resource/RR.rb', line 416 def self.get_class(type_value, class_value) #:nodoc: all if type_value == Types::OPT return Class.new(OPT) elsif type_value.class == Class type_value = type_value.const_get(:TypeValue) return find_class(type_value, Classes.to_code(class_value)) else type_value = (type_value.class == Types) ? type_value.code : Types.new(type_value).code class_value = (class_value.class == Classes) ? class_value.code : Classes.new(class_value).code return find_class(type_value, class_value) end end |
.get_num(bytes) ⇒ Object
453 454 455 456 457 458 459 460 461 |
# File 'lib/dnsruby/resource/RR.rb', line 453 def self.get_num(bytes) ret = 0 shift = (bytes.length - 1) * 8 bytes.each_byte do |byte| ret += byte.to_i << shift shift -= 8 end ret end |
Instance Method Details
#<=>(other) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/dnsruby/resource/RR.rb', line 24 def <=>(other) # return 1 if ((!other) || !(other.name) || !(other.type)) # return -1 if (!@name) if @name.canonical == other.name.canonical @type.code != other.type.code ? (@type.code <=> other.type.code) : (@rdata <=> other.rdata) else @name <=> other.name end end |
#==(other) ⇒ Object
380 381 382 383 384 385 386 |
# File 'lib/dnsruby/resource/RR.rb', line 380 def ==(other) return false unless self.class == other.class fields = equality_fields fields == other.equality_fields && fields.all? do |field| instance_variable_get(field) == other.instance_variable_get(field) end end |
#clone ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/dnsruby/resource/RR.rb', line 76 def clone encoded = MessageEncoder.new { |encoder| encoder.put_rr(self, true) }.to_s copy = MessageDecoder.new(encoded).get_rr [:@dnsruby_received_at, :@dnsruby_authenticated_expiration, :@dnsruby_learned_trust].each do |field| copy.instance_variable_set(field, instance_variable_get(field)) if instance_variable_defined?(field) end copy end |
#encode_rdata(msg, canonical = false) ⇒ Object
:nodoc: all
361 362 363 364 |
# File 'lib/dnsruby/resource/RR.rb', line 361 def encode_rdata(msg, canonical=false) #:nodoc: all # to be implemented by subclasses raise EncodeError.new("#{self.class} is RR.") end |
#eql?(other) ⇒ Boolean
:nodoc:
388 389 390 |
# File 'lib/dnsruby/resource/RR.rb', line 388 def eql?(other) #:nodoc: self == other end |
#from_data(data) ⇒ Object
:nodoc: all
351 352 353 354 |
# File 'lib/dnsruby/resource/RR.rb', line 351 def from_data(data) #:nodoc: all # to be implemented by subclasses raise NotImplementedError.new end |
#from_hash(hash) ⇒ Object
:nodoc: all
130 131 132 133 134 |
# File 'lib/dnsruby/resource/RR.rb', line 130 def from_hash(hash) #:nodoc: all hash.keys.each do |param| send("#{param}=", hash[param]) end end |
#from_string(input) ⇒ Object
:nodoc: all
356 357 358 359 |
# File 'lib/dnsruby/resource/RR.rb', line 356 def from_string(input) #:nodoc: all # to be implemented by subclasses # raise NotImplementedError.new end |
#hash ⇒ Object
:nodoc:
392 393 394 395 396 |
# File 'lib/dnsruby/resource/RR.rb', line 392 def hash # :nodoc: equality_fields.inject(0) do |hash_value, field| hash_value ^ instance_variable_get(field).hash end end |
#init_defaults ⇒ Object
103 104 105 |
# File 'lib/dnsruby/resource/RR.rb', line 103 def init_defaults # Default to do nothing end |
#rdata_to_string ⇒ Object
Get a string representation of the data section of the RR (in zone file format)
347 348 349 |
# File 'lib/dnsruby/resource/RR.rb', line 347 def rdata_to_string (@rdata && @rdata.length > 0) ? @rdata : 'no rdata' end |
#rdlength ⇒ Object
55 56 57 |
# File 'lib/dnsruby/resource/RR.rb', line 55 def rdlength rdata.length end |
#sameRRset(rec) ⇒ Object
Determines if two Records could be part of the same RRset. This compares the name, type, and class of the Records; the ttl and rdata are not compared.
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/dnsruby/resource/RR.rb', line 89 def sameRRset(rec) if @klass != rec.klass || @name.downcase != rec.name.downcase return false elsif (rec.type == Types.RRSIG) && (@type == Types.RRSIG) return rec.type_covered == self.type_covered end [rec, self].each do |rr| if rr.type == Types::RRSIG return (@type == rr.type_covered) || (rec.type == rr.type_covered) end end @type == rec.type end |
#to_s ⇒ Object
Returns a string representation of the RR in zone file format
341 342 343 344 |
# File 'lib/dnsruby/resource/RR.rb', line 341 def to_s s = name ? (name.to_s(true) + "\t") : '' s << [ttl, klass, type, rdata_to_string].map(&:to_s).join("\t") end |
#validate_decoded_rdata ⇒ Object
Some formats depend on the actual RR class, which is assigned after the format-specific decoder runs (notably ANY/NONE UPDATE markers).
279 280 |
# File 'lib/dnsruby/resource/RR.rb', line 279 def validate_decoded_rdata #:nodoc: all end |