dnsruby 1.33 → 1.34
Sign up to get free protection for your applications and to get access to all the features.
- data/html/created.rid +1 -1
- data/html/fr_method_index.html +83 -82
- data/lib/Dnsruby/Cache.rb +1 -1
- data/lib/Dnsruby/PacketSender.rb +11 -10
- data/lib/Dnsruby/Recursor.rb +13 -13
- data/lib/Dnsruby/Resolver.rb +6 -1
- data/lib/Dnsruby/code_mapper.rb +52 -41
- data/lib/Dnsruby/dnssec.rb +2 -2
- data/lib/Dnsruby/message.rb +13 -13
- data/lib/Dnsruby/resource/NSEC.rb +1 -1
- data/lib/Dnsruby/resource/RRSIG.rb +1 -1
- data/lib/Dnsruby/resource/resource.rb +73 -57
- data/lib/Dnsruby/select_thread.rb +5 -0
- data/lib/dnsruby.rb +2 -2
- data/test/tc_packet.rb +1 -2
- data/test/tc_rrset.rb +2 -2
- metadata +2 -2
data/lib/Dnsruby/Resolver.rb
CHANGED
@@ -365,6 +365,8 @@ module Dnsruby
|
|
365
365
|
@config.set_config_info(args[0][:config_info])
|
366
366
|
elsif (key==:nameserver)
|
367
367
|
set_config_nameserver(args[0][:nameserver])
|
368
|
+
elsif (key==:nameservers)
|
369
|
+
set_config_nameserver(args[0][:nameservers])
|
368
370
|
else
|
369
371
|
send(key.to_s+"=", args[0][key])
|
370
372
|
end
|
@@ -479,7 +481,10 @@ module Dnsruby
|
|
479
481
|
res.send(param.to_s+"=", instance_variable_get("@"+param.to_s))
|
480
482
|
end
|
481
483
|
end
|
482
|
-
|
484
|
+
|
485
|
+
def nameservers=(ns)
|
486
|
+
self.nameserver=(n)
|
487
|
+
end
|
483
488
|
def nameserver=(n)
|
484
489
|
@configured = true
|
485
490
|
@single_res_mutex.synchronize {
|
data/lib/Dnsruby/code_mapper.rb
CHANGED
@@ -26,16 +26,23 @@ module Dnsruby
|
|
26
26
|
class CodeMapper # :nodoc: all
|
27
27
|
include Comparable
|
28
28
|
|
29
|
-
@@
|
30
|
-
@@stringsdown = {}
|
31
|
-
@@values = {}
|
32
|
-
@@maxcode = {}
|
29
|
+
@@arrays = {}
|
33
30
|
|
34
31
|
attr_accessor :string, :code
|
35
32
|
alias to_code code
|
36
33
|
alias to_i code
|
37
34
|
alias to_string string
|
38
35
|
alias to_s string
|
36
|
+
|
37
|
+
class Arrays
|
38
|
+
attr_accessor :strings, :stringsdown, :values, :maxcode
|
39
|
+
def initialize
|
40
|
+
@strings = {}
|
41
|
+
@stringsdown = {}
|
42
|
+
@values = {}
|
43
|
+
@maxcode = 0
|
44
|
+
end
|
45
|
+
end
|
39
46
|
|
40
47
|
def CodeMapper.maxcode
|
41
48
|
return @maxcode
|
@@ -43,30 +50,28 @@ module Dnsruby
|
|
43
50
|
|
44
51
|
# Creates the CodeMapper from the defined constants
|
45
52
|
def CodeMapper.update
|
46
|
-
|
47
|
-
@@
|
48
|
-
@@stringsdown[self] = {}
|
49
|
-
@@values[self] = {}
|
50
|
-
@@maxcode[self] = 0
|
53
|
+
|
54
|
+
@@arrays[self] = Arrays.new
|
51
55
|
|
52
56
|
constants = self.constants - CodeMapper.constants
|
53
57
|
constants.each do |i|
|
54
|
-
@@
|
58
|
+
@@arrays[self].strings.store(i.to_s, const_get(i))
|
55
59
|
end
|
56
|
-
@@
|
57
|
-
@@
|
58
|
-
@@
|
59
|
-
@@
|
60
|
-
@@
|
60
|
+
@@arrays[self].maxcode = constants.length
|
61
|
+
@@arrays[self].values = @@arrays[self].strings.invert
|
62
|
+
@@arrays[self].stringsdown = Hash.new
|
63
|
+
@@arrays[self].strings.keys.each do |s|
|
64
|
+
@@arrays[self].stringsdown.store(s.downcase, @@arrays[self].strings[s])
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
64
68
|
# Add new a code to the CodeMapper
|
65
69
|
def CodeMapper.add_pair(string, code)
|
66
|
-
@@
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
+
array = @@arrays[self]
|
71
|
+
array.strings.store(string, code)
|
72
|
+
array.values=array.strings.invert
|
73
|
+
array.stringsdown.store(string.downcase, code)
|
74
|
+
array.maxcode+=1
|
70
75
|
end
|
71
76
|
|
72
77
|
def unknown_string(arg) #:nodoc: all
|
@@ -75,7 +80,7 @@ module Dnsruby
|
|
75
80
|
|
76
81
|
def unknown_code(arg) #:nodoc: all
|
77
82
|
# Be liberal in what you accept...
|
78
|
-
# raise ArgumentError.new("Code #{arg} not a member of #{self.class}")
|
83
|
+
# raise ArgumentError.new("Code #{arg} not a member of #{self.class}")
|
79
84
|
Classes.add_pair(arg.to_s, arg)
|
80
85
|
set_code(arg)
|
81
86
|
end
|
@@ -86,36 +91,42 @@ module Dnsruby
|
|
86
91
|
end
|
87
92
|
|
88
93
|
def initialize(arg) #:nodoc: all
|
94
|
+
array = @@arrays[self.class]
|
89
95
|
if (arg.kind_of?String)
|
90
96
|
arg.gsub!("_", "-")
|
91
|
-
|
92
|
-
|
97
|
+
code = array.stringsdown[arg.downcase]
|
98
|
+
if (code != nil)
|
99
|
+
@code = code
|
100
|
+
@string = array.strings.invert[@code]
|
93
101
|
else
|
94
102
|
unknown_string(arg)
|
95
103
|
end
|
96
104
|
elsif (arg.kind_of?Fixnum)
|
97
|
-
if (
|
98
|
-
|
105
|
+
if (array.values[arg] != nil)
|
106
|
+
@code = arg
|
107
|
+
@string = array.values[@code]
|
99
108
|
else
|
100
109
|
unknown_code(arg)
|
101
110
|
end
|
102
111
|
elsif (arg.kind_of?self.class)
|
103
|
-
|
112
|
+
@code = arg.code
|
113
|
+
@string = array.values[@code]
|
104
114
|
else
|
105
115
|
raise ArgumentError.new("Unknown argument #{arg} for #{self.class}")
|
106
116
|
end
|
107
117
|
end
|
108
118
|
|
119
|
+
def set_string(arg)
|
120
|
+
array = @@arrays[self.class]
|
121
|
+
@code = array.stringsdown[arg.downcase]
|
122
|
+
@string = array.strings.invert[@code]
|
123
|
+
end
|
124
|
+
|
109
125
|
def set_code(arg)
|
110
126
|
@code = arg
|
111
|
-
@string = @@
|
127
|
+
@string = @@arrays[self.class].values[@code]
|
112
128
|
end
|
113
|
-
|
114
|
-
def set_string(arg)
|
115
|
-
@code = @@stringsdown[self.class][arg.downcase]
|
116
|
-
@string = @@strings[self.class].invert[@code]
|
117
|
-
end
|
118
|
-
|
129
|
+
|
119
130
|
def inspect
|
120
131
|
return @string
|
121
132
|
end
|
@@ -124,7 +135,7 @@ module Dnsruby
|
|
124
135
|
if (arg.kind_of?String)
|
125
136
|
return arg
|
126
137
|
else
|
127
|
-
return @@
|
138
|
+
return @@arrays[self].values[arg]
|
128
139
|
end
|
129
140
|
end
|
130
141
|
|
@@ -132,7 +143,7 @@ module Dnsruby
|
|
132
143
|
if (arg.kind_of?Fixnum)
|
133
144
|
return arg
|
134
145
|
else
|
135
|
-
return @@
|
146
|
+
return @@arrays[self].stringsdown[arg.downcase]
|
136
147
|
end
|
137
148
|
end
|
138
149
|
|
@@ -145,16 +156,16 @@ module Dnsruby
|
|
145
156
|
end
|
146
157
|
|
147
158
|
def ==(other)
|
148
|
-
if other
|
149
|
-
if other
|
150
|
-
return true
|
159
|
+
if Fixnum === other
|
160
|
+
if other == @code
|
161
|
+
return true
|
151
162
|
end
|
152
|
-
elsif other
|
163
|
+
elsif String === other
|
153
164
|
if other == @string
|
154
165
|
return true
|
155
166
|
end
|
156
|
-
elsif other
|
157
|
-
if other == @code
|
167
|
+
elsif CodeMapper === other
|
168
|
+
if other.string == @string && other.code == @code
|
158
169
|
return true
|
159
170
|
end
|
160
171
|
end
|
@@ -165,7 +176,7 @@ module Dnsruby
|
|
165
176
|
# Return a regular expression which matches any codes or strings from the CodeMapper.
|
166
177
|
def self.regexp
|
167
178
|
# Longest ones go first, so the regex engine will match AAAA before A, etc.
|
168
|
-
return @@
|
179
|
+
return @@arrays[self].strings.keys.sort { |a, b| b.length <=> a.length }.join('|')
|
169
180
|
end
|
170
181
|
|
171
182
|
end
|
data/lib/Dnsruby/dnssec.rb
CHANGED
@@ -138,7 +138,7 @@ module Dnsruby
|
|
138
138
|
line = lastname.to_s + ((lastname.absolute?)?".":"") + " " + line
|
139
139
|
end
|
140
140
|
ds = RR.create(line)
|
141
|
-
if ((ds.type == Types
|
141
|
+
if ((ds.type == Types::DS) || (ds.type == Types::DNSKEY))
|
142
142
|
# assert(ds.name.absolute?)
|
143
143
|
Dnssec.add_trust_anchor(ds)
|
144
144
|
end
|
@@ -189,7 +189,7 @@ module Dnsruby
|
|
189
189
|
# First, just check there is something to validate!
|
190
190
|
found_sigs = false
|
191
191
|
msg.each_resource {|rr|
|
192
|
-
if (rr.type == Types
|
192
|
+
if (rr.type == Types::RRSIG)
|
193
193
|
found_sigs = true
|
194
194
|
end
|
195
195
|
}
|
data/lib/Dnsruby/message.rb
CHANGED
@@ -96,7 +96,7 @@ module Dnsruby
|
|
96
96
|
def rrset(name, type=Types.A, klass=Classes::IN)
|
97
97
|
rrs = select{|rr|
|
98
98
|
type_ok = (rr.type==type)
|
99
|
-
if (rr.type == Types
|
99
|
+
if (rr.type == Types::RRSIG)
|
100
100
|
type_ok = (rr.type_covered == type)
|
101
101
|
end
|
102
102
|
type_ok && (rr.klass == klass) && (rr.name.to_s.downcase == name.to_s.downcase)
|
@@ -115,7 +115,7 @@ module Dnsruby
|
|
115
115
|
end
|
116
116
|
ret = []
|
117
117
|
each do |rr|
|
118
|
-
next if (!include_opt && (rr.type == Types
|
118
|
+
next if (!include_opt && (rr.type == Types::OPT))
|
119
119
|
# if (type)
|
120
120
|
# next if ((rr.type == Types.RRSIG) && (type != Types.RRSIG) && (rr.type_covered != type))
|
121
121
|
# next if (rr.type != type)
|
@@ -124,8 +124,8 @@ module Dnsruby
|
|
124
124
|
# if this is an rrsig type, then :
|
125
125
|
# only include it if the type_covered is the type requested,
|
126
126
|
# OR if the type requested is an RRSIG
|
127
|
-
if (rr.type == Types
|
128
|
-
if ((rr.type_covered == type) || (type == Types
|
127
|
+
if (rr.type == Types::RRSIG)
|
128
|
+
if ((rr.type_covered == type) || (type == Types::RRSIG))
|
129
129
|
else
|
130
130
|
next
|
131
131
|
end
|
@@ -162,10 +162,10 @@ module Dnsruby
|
|
162
162
|
# update the counts itself, rather than the section worrying about it?
|
163
163
|
rrs_to_delete = []
|
164
164
|
each do |rr|
|
165
|
-
next if rr.rr_type == Types
|
165
|
+
next if rr.rr_type == Types::OPT
|
166
166
|
if ((rr.name.to_s.downcase == name.to_s.downcase) &&
|
167
167
|
((rr.type == type) ||
|
168
|
-
((rr.type == Types
|
168
|
+
((rr.type == Types::RRSIG) && (rr.type_covered == type)) ))
|
169
169
|
rrs_to_delete.push(rr)
|
170
170
|
end
|
171
171
|
end
|
@@ -200,8 +200,8 @@ module Dnsruby
|
|
200
200
|
@security_level = SecurityLevel.UNCHECKED
|
201
201
|
@security_error = nil
|
202
202
|
@cached = false
|
203
|
-
type = Types
|
204
|
-
klass = Classes
|
203
|
+
type = Types::A
|
204
|
+
klass = Classes::IN
|
205
205
|
if (args.length > 0)
|
206
206
|
name = args[0]
|
207
207
|
if (args.length > 1)
|
@@ -463,7 +463,7 @@ module Dnsruby
|
|
463
463
|
|
464
464
|
def get_opt
|
465
465
|
each_additional do |r|
|
466
|
-
if (r.type == Types
|
466
|
+
if (r.type == Types::OPT)
|
467
467
|
return r
|
468
468
|
end
|
469
469
|
end
|
@@ -531,7 +531,7 @@ module Dnsruby
|
|
531
531
|
retval = retval + "\n";
|
532
532
|
retval = retval + ";; ADDITIONAL SECTION (#{@header.arcount} record#{@header.arcount == 1 ? '' : 's'})\n";
|
533
533
|
each_additional { |rr|
|
534
|
-
if (rr.type != Types
|
534
|
+
if (rr.type != Types::OPT)
|
535
535
|
retval = retval + rr.to_s+ "\n"
|
536
536
|
end
|
537
537
|
}
|
@@ -602,7 +602,7 @@ module Dnsruby
|
|
602
602
|
o.header.arcount.times { |count|
|
603
603
|
start = msg.index
|
604
604
|
rr = msg.get_rr
|
605
|
-
if (rr.type == Types
|
605
|
+
if (rr.type == Types::TSIG)
|
606
606
|
if (count!=o.header.arcount-1)
|
607
607
|
Dnsruby.log.Error("Incoming message has TSIG record before last record")
|
608
608
|
raise DecodeError.new("TSIG record present before last record")
|
@@ -1109,8 +1109,8 @@ module Dnsruby
|
|
1109
1109
|
#
|
1110
1110
|
#If an IPv4 or IPv6 object is used then the type is set to PTR.
|
1111
1111
|
def initialize(*args)
|
1112
|
-
@qtype = Types
|
1113
|
-
@qclass = Classes
|
1112
|
+
@qtype = Types::A
|
1113
|
+
@qclass = Classes::IN
|
1114
1114
|
if (args.length > 0)
|
1115
1115
|
if (args.length > 1)
|
1116
1116
|
@qtype = Types.new(args[1])
|
@@ -145,7 +145,7 @@ module Dnsruby
|
|
145
145
|
type = Types.new((256 * window_number) + (8 * index) + i)
|
146
146
|
#Bits representing pseudo-types MUST be clear, as they do not appear
|
147
147
|
#in zone data. If encountered, they MUST be ignored upon being read.
|
148
|
-
if (!([Types
|
148
|
+
if (!([Types::OPT, Types::TSIG].include?(type)))
|
149
149
|
types.push(type)
|
150
150
|
end
|
151
151
|
end
|
@@ -52,7 +52,7 @@ module Dnsruby
|
|
52
52
|
return false
|
53
53
|
end
|
54
54
|
end
|
55
|
-
if (r.type == Types
|
55
|
+
if (r.type == Types::RRSIG)
|
56
56
|
new_pos = @rrs.length
|
57
57
|
@num_sigs += 1
|
58
58
|
end
|
@@ -61,13 +61,24 @@ module Dnsruby
|
|
61
61
|
end
|
62
62
|
|
63
63
|
#Add the RR to this RRSet
|
64
|
-
|
65
|
-
|
64
|
+
#Takes a copy of the RR by default. To suppress this, pass false
|
65
|
+
#as the second parameter.
|
66
|
+
def add(rin, do_clone = true)
|
67
|
+
if (rin.instance_of?RRSet)
|
66
68
|
ret = false
|
67
|
-
[
|
69
|
+
[rin.rrs, rin.sigs].each {|rr| ret = add(rr)}
|
68
70
|
return ret
|
69
71
|
end
|
70
|
-
r = RR.create(r.to_s) # clone the record
|
72
|
+
# r = RR.create(r.to_s) # clone the record
|
73
|
+
r = nil
|
74
|
+
if do_clone
|
75
|
+
Message::MessageDecoder.new(MessageEncoder.new {|msg|
|
76
|
+
msg.put_rr(rin, true)}.to_s) {|msg|
|
77
|
+
r = msg.get_rr
|
78
|
+
}
|
79
|
+
else
|
80
|
+
r = rin
|
81
|
+
end
|
71
82
|
if (@rrs.size() == 0) # && !(r.type == Types.RRSIG))
|
72
83
|
return privateAdd(r)
|
73
84
|
end
|
@@ -75,10 +86,10 @@ module Dnsruby
|
|
75
86
|
first = @rrs[0]
|
76
87
|
if (!r.sameRRset(first))
|
77
88
|
return false
|
78
|
-
# raise ArgumentError.new("record does not match rrset")
|
89
|
+
# raise ArgumentError.new("record does not match rrset")
|
79
90
|
end
|
80
91
|
|
81
|
-
if (!(r.type == Types
|
92
|
+
if (!(r.type == Types::RRSIG) && (!(first.type == Types::RRSIG)))
|
82
93
|
if (r.ttl != first.ttl) # RFC2181, section 5.2
|
83
94
|
if (r.ttl > first.ttl)
|
84
95
|
r.ttl=(first.ttl)
|
@@ -90,13 +101,13 @@ module Dnsruby
|
|
90
101
|
end
|
91
102
|
end
|
92
103
|
|
93
|
-
|
94
|
-
# return true
|
104
|
+
return privateAdd(r)
|
105
|
+
# return true
|
95
106
|
end
|
96
107
|
|
97
108
|
def <=>(other)
|
98
|
-
# return 1 if ((!other) || !(other.name) || !(other.type))
|
99
|
-
# return -1 if (!@name)
|
109
|
+
# return 1 if ((!other) || !(other.name) || !(other.type))
|
110
|
+
# return -1 if (!@name)
|
100
111
|
if (@name.canonical == other.name.canonical)
|
101
112
|
return @type.code <=> other.type.code
|
102
113
|
else
|
@@ -117,7 +128,7 @@ module Dnsruby
|
|
117
128
|
|
118
129
|
return_rrs = RRSet.new
|
119
130
|
canonical_rrs.keys.sort.each { |rdata|
|
120
|
-
return_rrs.add(canonical_rrs[rdata])
|
131
|
+
return_rrs.add(canonical_rrs[rdata], false)
|
121
132
|
}
|
122
133
|
return return_rrs
|
123
134
|
end
|
@@ -152,7 +163,7 @@ module Dnsruby
|
|
152
163
|
#Return the type of this RRSet
|
153
164
|
def type
|
154
165
|
if (@rrs[0])
|
155
|
-
|
166
|
+
return @rrs[0].type
|
156
167
|
end
|
157
168
|
return nil
|
158
169
|
end
|
@@ -173,7 +184,7 @@ module Dnsruby
|
|
173
184
|
end
|
174
185
|
def name
|
175
186
|
if (@rrs[0])
|
176
|
-
|
187
|
+
return @rrs[0].name
|
177
188
|
else
|
178
189
|
return nil
|
179
190
|
end
|
@@ -191,25 +202,27 @@ module Dnsruby
|
|
191
202
|
end
|
192
203
|
|
193
204
|
#Superclass for all Dnsruby resource records.
|
194
|
-
#
|
205
|
+
#
|
195
206
|
#Represents a DNS RR (resource record) [RFC1035, section 3.2]
|
196
|
-
#
|
197
|
-
#Use Dnsruby::RR::create(...) to create a new RR record.
|
198
|
-
#
|
207
|
+
#
|
208
|
+
#Use Dnsruby::RR::create(...) to create a new RR record.
|
209
|
+
#
|
199
210
|
# mx = Dnsruby::RR.create("example.com. 7200 MX 10 mailhost.example.com.")
|
200
|
-
#
|
201
|
-
# rr = Dnsruby::RR.create({:name => "example.com", :type => "MX", :ttl => 7200,
|
211
|
+
#
|
212
|
+
# rr = Dnsruby::RR.create({:name => "example.com", :type => "MX", :ttl => 7200,
|
202
213
|
# :preference => 10, :exchange => "mailhost.example.com"})
|
203
|
-
#
|
214
|
+
#
|
204
215
|
# s = rr.to_s # Get a String representation of the RR (in zone file format)
|
205
216
|
# rr_again = Dnsruby::RR.create(s)
|
206
|
-
#
|
217
|
+
#
|
207
218
|
class RR
|
208
219
|
|
209
220
|
# A regular expression which catches any valid resource record.
|
210
|
-
@@RR_REGEX = Regexp.new("^\\s*(\\S+)\\s*(\\d+)?\\s*(#{Classes.regexp +
|
221
|
+
@@RR_REGEX = Regexp.new("^\\s*(\\S+)\\s*(\\d+)?\\s*(#{Classes.regexp +
|
211
222
|
"|CLASS\\d+"})?\\s*(#{Types.regexp + '|TYPE\\d+'})?\\s*([\\s\\S]*)\$") #:nodoc: all
|
212
223
|
|
224
|
+
@@implemented_rr_map = nil
|
225
|
+
|
213
226
|
#The Resource's domain name
|
214
227
|
attr_reader :name
|
215
228
|
#The Resource type
|
@@ -239,13 +252,13 @@ module Dnsruby
|
|
239
252
|
alias :rr_type :type
|
240
253
|
|
241
254
|
def klass=(klass)
|
242
|
-
if (@type != Types
|
255
|
+
if (@type != Types::OPT)
|
243
256
|
@klass= Classes.new(klass)
|
244
257
|
else
|
245
|
-
|
246
|
-
|
258
|
+
if (klass.class == Classes)
|
259
|
+
@klass = klass
|
247
260
|
else
|
248
|
-
|
261
|
+
@klass = Classes.new("CLASS#{klass}")
|
249
262
|
end
|
250
263
|
end
|
251
264
|
end
|
@@ -258,7 +271,7 @@ module Dnsruby
|
|
258
271
|
return false
|
259
272
|
end
|
260
273
|
[rec, self].each { |rr|
|
261
|
-
if (rr.type == Types
|
274
|
+
if (rr.type == Types::RRSIG)
|
262
275
|
return ((@type == rr.type_covered) || (rec.type == rr.type_covered))
|
263
276
|
end
|
264
277
|
}
|
@@ -278,7 +291,7 @@ module Dnsruby
|
|
278
291
|
return
|
279
292
|
else
|
280
293
|
@rdata = args[0]
|
281
|
-
# print "Loading RR from #{args[0]}, class : #{args[0].class}\n"
|
294
|
+
# print "Loading RR from #{args[0]}, class : #{args[0].class}\n"
|
282
295
|
if (args[0].class == String)
|
283
296
|
from_string(args[0])
|
284
297
|
return
|
@@ -301,7 +314,7 @@ module Dnsruby
|
|
301
314
|
#Create a new RR from the hash. The name is required; all other fields are optional.
|
302
315
|
#Type defaults to ANY and the Class defaults to IN. The TTL defaults to 0.
|
303
316
|
#
|
304
|
-
#If the type is specified, then it is necessary to provide ALL of the resource record fields which
|
317
|
+
#If the type is specified, then it is necessary to provide ALL of the resource record fields which
|
305
318
|
#are specific to that record; i.e. for
|
306
319
|
#an MX record, you would need to specify the exchange and the preference
|
307
320
|
#
|
@@ -309,7 +322,7 @@ module Dnsruby
|
|
309
322
|
# rr = Dnsruby::RR.new_from_hash({:name => "example.com"})
|
310
323
|
# rr = Dnsruby::RR.new_from_hash({:name => "example.com", :type => Types.MX, :ttl => 10, :preference => 5, :exchange => "mx1.example.com"})
|
311
324
|
def RR.new_from_hash(inhash)
|
312
|
-
hash = inhash.clone
|
325
|
+
hash = inhash.clone
|
313
326
|
type = hash[:type] || Types::ANY
|
314
327
|
klass = hash[:klass] || Classes::IN
|
315
328
|
ttl = hash[:ttl] || 0
|
@@ -340,7 +353,7 @@ module Dnsruby
|
|
340
353
|
#
|
341
354
|
#All names must be fully qualified. The trailing dot (.) is optional.
|
342
355
|
#
|
343
|
-
#
|
356
|
+
#
|
344
357
|
# a = Dnsruby::RR.new_from_string("foo.example.com. 86400 A 10.1.2.3")
|
345
358
|
# mx = Dnsruby::RR.new_from_string("example.com. 7200 MX 10 mailhost.example.com.")
|
346
359
|
# cname = Dnsruby::RR.new_from_string("www.example.com 300 IN CNAME www1.example.com")
|
@@ -365,7 +378,7 @@ module Dnsruby
|
|
365
378
|
rrtype = $4 || '';
|
366
379
|
rdata = $5 || '';
|
367
380
|
|
368
|
-
if rdata
|
381
|
+
if rdata
|
369
382
|
rdata.gsub!(/\s+$/o, "")
|
370
383
|
end
|
371
384
|
|
@@ -397,7 +410,7 @@ module Dnsruby
|
|
397
410
|
rdata =~ /\\\#\s+(\d+)\s+(.*)$/o;
|
398
411
|
|
399
412
|
rdlength = $1.to_i;
|
400
|
-
hexdump = $2;
|
413
|
+
hexdump = $2;
|
401
414
|
hexdump.gsub!(/\s*/, "");
|
402
415
|
|
403
416
|
if hexdump.length() != rdlength*2
|
@@ -412,7 +425,7 @@ module Dnsruby
|
|
412
425
|
raise Exception, 'Expected RFC3597 representation of RDATA' unless rdata =~/\\\#\s+(\d+)\s+(.*)$/o;
|
413
426
|
|
414
427
|
rdlength = $1.to_i;
|
415
|
-
hexdump = $2;
|
428
|
+
hexdump = $2;
|
416
429
|
hexdump.gsub!(/\s*/o, "");
|
417
430
|
|
418
431
|
if hexdump.length() != rdlength*2
|
@@ -439,7 +452,7 @@ module Dnsruby
|
|
439
452
|
offset = args[6]
|
440
453
|
rdata = []
|
441
454
|
if (data != nil)
|
442
|
-
|
455
|
+
rdata = data[offset, rdlength]
|
443
456
|
end
|
444
457
|
|
445
458
|
record = nil
|
@@ -449,26 +462,29 @@ module Dnsruby
|
|
449
462
|
record.name = Name.create(name)
|
450
463
|
record.ttl = ttl
|
451
464
|
record.type = rrtype
|
452
|
-
record.klass = rrclass
|
465
|
+
record.klass = rrclass
|
453
466
|
|
454
467
|
return record
|
455
468
|
end
|
456
469
|
|
457
470
|
#Return an array of all the currently implemented RR types
|
458
471
|
def RR.implemented_rrs
|
459
|
-
|
472
|
+
if (!@@implemented_rr_map)
|
473
|
+
@@implemented_rr_map = ClassHash.keys.map {|k| Dnsruby::Types.to_string(k[0])}
|
474
|
+
end
|
475
|
+
return @@implemented_rr_map
|
460
476
|
end
|
461
477
|
|
462
478
|
private
|
463
479
|
def RR._get_subclass(name, rrtype, rrclass, ttl, rdata) #:nodoc: all
|
464
|
-
return unless (rrtype!=nil)
|
465
|
-
record = get_class(rrtype, rrclass).new(rdata)
|
480
|
+
return unless (rrtype!=nil)
|
481
|
+
record = get_class(rrtype, rrclass).new(rdata)
|
466
482
|
record.name = Name.create(name)
|
467
483
|
record.ttl = ttl
|
468
484
|
record.type = rrtype
|
469
|
-
record.klass = rrclass
|
485
|
+
record.klass = rrclass
|
470
486
|
return record
|
471
|
-
end
|
487
|
+
end
|
472
488
|
public
|
473
489
|
|
474
490
|
#Returns a string representation of the RR in zone file format
|
@@ -480,7 +496,7 @@ module Dnsruby
|
|
480
496
|
def rdata_to_string
|
481
497
|
if (@rdata && @rdata.length > 0)
|
482
498
|
return @rdata
|
483
|
-
else
|
499
|
+
else
|
484
500
|
return "no rdata"
|
485
501
|
end
|
486
502
|
end
|
@@ -497,12 +513,12 @@ module Dnsruby
|
|
497
513
|
|
498
514
|
def encode_rdata(msg, canonical=false) #:nodoc: all
|
499
515
|
# to be implemented by subclasses
|
500
|
-
raise EncodeError.new("#{self.class} is RR.")
|
516
|
+
raise EncodeError.new("#{self.class} is RR.")
|
501
517
|
end
|
502
518
|
|
503
519
|
def self.decode_rdata(msg) #:nodoc: all
|
504
520
|
# to be implemented by subclasses
|
505
|
-
raise DecodeError.new("#{self.class} is RR.")
|
521
|
+
raise DecodeError.new("#{self.class} is RR.")
|
506
522
|
end
|
507
523
|
|
508
524
|
def ==(other)
|
@@ -520,7 +536,7 @@ module Dnsruby
|
|
520
536
|
o_ivars.delete "@ttl" # RFC 2136 section 1.1
|
521
537
|
|
522
538
|
return s_ivars == o_ivars &&
|
523
|
-
s_ivars.collect {|name| self.instance_variable_get name} ==
|
539
|
+
s_ivars.collect {|name| self.instance_variable_get name} ==
|
524
540
|
o_ivars.collect {|name| other.instance_variable_get name}
|
525
541
|
end
|
526
542
|
|
@@ -529,7 +545,7 @@ module Dnsruby
|
|
529
545
|
end
|
530
546
|
|
531
547
|
def hash # :nodoc:
|
532
|
-
h = 0
|
548
|
+
h = 0
|
533
549
|
vars = self.instance_variables
|
534
550
|
vars.delete "@ttl"
|
535
551
|
vars.each {|name|
|
@@ -540,8 +556,8 @@ module Dnsruby
|
|
540
556
|
|
541
557
|
#Get an RR of the specified type and class
|
542
558
|
def self.get_class(type_value, class_value) #:nodoc: all
|
543
|
-
if (type_value == Types
|
544
|
-
|
559
|
+
if (type_value == Types::OPT)
|
560
|
+
return Class.new(OPT)
|
545
561
|
end
|
546
562
|
if (type_value.class == Class)
|
547
563
|
type_value = type_value.const_get(:TypeValue)
|
@@ -559,10 +575,10 @@ module Dnsruby
|
|
559
575
|
class_value = Classes.new(class_value).code
|
560
576
|
end
|
561
577
|
return ClassHash[[type_value, class_value]] ||
|
562
|
-
|
578
|
+
Generic.create(type_value, class_value)
|
563
579
|
end
|
564
580
|
return ret
|
565
|
-
end
|
581
|
+
end
|
566
582
|
|
567
583
|
|
568
584
|
#Create a new RR from the arguments, which can be either a String or a Hash.
|
@@ -572,17 +588,17 @@ module Dnsruby
|
|
572
588
|
# mx = Dnsruby::RR.create("example.com. 7200 MX 10 mailhost.example.com.")
|
573
589
|
# cname = Dnsruby::RR.create("www.example.com 300 IN CNAME www1.example.com")
|
574
590
|
# txt = Dnsruby::RR.create('baz.example.com 3600 HS TXT "text record"')
|
575
|
-
#
|
591
|
+
#
|
576
592
|
# rr = Dnsruby::RR.create({:name => "example.com"})
|
577
|
-
# rr = Dnsruby::RR.create({:name => "example.com", :type => "MX", :ttl => 10,
|
593
|
+
# rr = Dnsruby::RR.create({:name => "example.com", :type => "MX", :ttl => 10,
|
578
594
|
# :preference => 5, :exchange => "mx1.example.com"})
|
579
|
-
#
|
595
|
+
#
|
580
596
|
def RR.create(*args)
|
581
|
-
if (args.length == 1) && (args[0].class == String)
|
597
|
+
if (args.length == 1) && (args[0].class == String)
|
582
598
|
return new_from_string(args[0])
|
583
|
-
elsif (args.length == 1) && (args[0].class == Hash)
|
599
|
+
elsif (args.length == 1) && (args[0].class == Hash)
|
584
600
|
return new_from_hash(args[0])
|
585
|
-
else
|
601
|
+
else
|
586
602
|
return new_from_data(args)
|
587
603
|
end
|
588
604
|
end
|