rubydns 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -6
- data/README.md +48 -44
- data/{rakefile.rb → Rakefile} +2 -3
- data/bin/rd-dns-check +1 -1
- data/bin/rd-resolve-test +1 -1
- data/lib/rubydns.rb +2 -3
- data/lib/rubydns/chunked.rb +1 -1
- data/lib/rubydns/extensions/hexdump.rb +1 -1
- data/lib/rubydns/extensions/logger.rb +30 -0
- data/lib/rubydns/extensions/resolv.rb +1 -1
- data/lib/rubydns/extensions/string-1.8.rb +1 -1
- data/lib/rubydns/extensions/string-1.9.2.rb +1 -1
- data/lib/rubydns/extensions/string-1.9.3.rb +1 -1
- data/lib/rubydns/extensions/string.rb +1 -1
- data/lib/rubydns/handler.rb +1 -1
- data/lib/rubydns/message.rb +2 -1
- data/lib/rubydns/resolver.rb +22 -17
- data/lib/rubydns/server.rb +3 -5
- data/lib/rubydns/system.rb +1 -1
- data/lib/rubydns/transaction.rb +2 -2
- data/lib/rubydns/version.rb +2 -8
- data/rubydns.gemspec +33 -0
- data/test/examples/dropping-dns.rb +1 -1
- data/test/examples/fortune-dns.rb +1 -1
- data/test/examples/geoip-dns.rb +1 -1
- data/test/examples/soa-dns.rb +1 -1
- data/test/examples/test-dns-1.rb +1 -1
- data/test/examples/test-dns-2.rb +2 -5
- data/test/test_daemon.rb +21 -0
- data/test/test_passthrough.rb +21 -0
- data/test/test_resolver.rb +52 -0
- data/test/test_rules.rb +21 -0
- data/test/test_slow_server.rb +21 -0
- data/test/test_system.rb +21 -0
- data/test/test_truncation.rb +21 -0
- metadata +38 -25
- data/test/examples/GeoLiteCountry.dat +0 -0
- data/test/examples/log/DroppingDaemon.log +0 -107
- data/test/examples/log/FortuneDNS.log +0 -5
- data/test/examples/log/GeoIPDNSDaemon.log +0 -0
- data/test/examples/log/TestDaemon.log +0 -340
- data/test/examples/run/DroppingDaemon.pid +0 -1
- data/test/examples/run/GeoIPDNSDaemon.pid +0 -1
- data/test/log/BasicTestServer.log +0 -96
- data/test/log/SlowServer.log +0 -72
- data/test/log/TestPassthroughServer.log +0 -36
- data/test/log/TruncatedServer.log +0 -78
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,55 +1,52 @@
|
|
1
|
-
RubyDNS
|
2
|
-
=======
|
1
|
+
# RubyDNS
|
3
2
|
|
4
|
-
|
5
|
-
* Copyright (C) 2009, 2011 [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams/).
|
6
|
-
* [](http://travis-ci.org/ioquatix/rubydns)
|
3
|
+
RubyDNS is a high-performance DNS server which can be easily integrated into other projects or used as a stand-alone daemon (via RExec). By default it uses rule-based pattern matching. Results can be hard-coded, computed, fetched from a remote DNS server or fetched from a local cache, depending on requirements.
|
7
4
|
|
8
|
-
|
5
|
+
In addition, RubyDNS includes a high-performance asynchronous DNS resolver built on top of EventMachine. This module can be used by itself in client applications without using the full RubyDNS server stack.
|
9
6
|
|
10
|
-
|
7
|
+
For examples and documentation please see the main [project page][1].
|
11
8
|
|
12
|
-
|
9
|
+
[1]: http://www.oriontransfer.co.nz/gems/rubydns
|
13
10
|
|
14
|
-
|
11
|
+
[](http://travis-ci.org/ioquatix/rubydns)
|
15
12
|
|
16
|
-
|
13
|
+
## Installation
|
17
14
|
|
18
|
-
|
19
|
-
-------------
|
15
|
+
Add this line to your application's Gemfile:
|
20
16
|
|
21
|
-
|
17
|
+
gem 'rubydns'
|
22
18
|
|
23
|
-
|
24
|
-
require 'rubydns'
|
19
|
+
And then execute:
|
25
20
|
|
26
|
-
|
21
|
+
$ bundle
|
27
22
|
|
28
|
-
|
29
|
-
Name = Resolv::DNS::Name
|
30
|
-
IN = Resolv::DNS::Resource::IN
|
31
|
-
|
32
|
-
# For this exact address record, return an IP address
|
33
|
-
match("dev.mydomain.org", IN::A) do |transaction|
|
34
|
-
transaction.respond!("10.0.0.80")
|
35
|
-
end
|
23
|
+
Or install it yourself as:
|
36
24
|
|
37
|
-
|
38
|
-
offset = match_data[1].to_i
|
25
|
+
$ gem install rubydns
|
39
26
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
This is copied from `test/examples/test-dns-2.rb`. It has been simplified slightly.
|
30
|
+
|
31
|
+
require 'rubydns'
|
32
|
+
|
33
|
+
Name = Resolv::DNS::Name
|
34
|
+
IN = Resolv::DNS::Resource::IN
|
35
|
+
|
36
|
+
# Use upstream DNS for name resolution.
|
37
|
+
UPSTREAM = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])
|
38
|
+
|
39
|
+
def self.run
|
40
|
+
# Start the RubyDNS server
|
41
|
+
RubyDNS::run_server(:listen => INTERFACES) do
|
42
|
+
match("test.mydomain.org", IN::A) do |transaction|
|
43
|
+
transaction.respond!("10.0.0.80")
|
46
44
|
end
|
47
|
-
end
|
48
45
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
# Default DNS handler
|
47
|
+
otherwise do |transaction|
|
48
|
+
transaction.passthrough!(UPSTREAM)
|
49
|
+
end
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
@@ -59,8 +56,7 @@ After starting this server you can test it using dig:
|
|
59
56
|
dig @localhost dev.mydomain.org
|
60
57
|
dig @localhost google.com
|
61
58
|
|
62
|
-
Compatibility
|
63
|
-
-------------
|
59
|
+
## Compatibility
|
64
60
|
|
65
61
|
### Migrating from RubyDNS 0.3.x to 0.4.x ###
|
66
62
|
|
@@ -130,16 +126,24 @@ Once you call this, the transaction won't complete until you call either `transa
|
|
130
126
|
|
131
127
|
You can see a complete example in `test/test_slow_server.rb`.
|
132
128
|
|
133
|
-
|
134
|
-
|
129
|
+
## Contributing
|
130
|
+
|
131
|
+
1. Fork it
|
132
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
133
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
134
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
135
|
+
5. Create new Pull Request
|
136
|
+
|
137
|
+
### Desired Features
|
135
138
|
|
136
139
|
* Support for more features of DNS such as zone transfer.
|
137
140
|
* Support reverse records more easily.
|
138
141
|
|
139
|
-
License
|
140
|
-
|
142
|
+
## License
|
143
|
+
|
144
|
+
Released under the MIT license.
|
141
145
|
|
142
|
-
Copyright
|
146
|
+
Copyright, 2009, 2012, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
143
147
|
|
144
148
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
145
149
|
of this software and associated documentation files (the "Software"), to deal
|
data/{rakefile.rb → Rakefile}
RENAMED
data/bin/rd-dns-check
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# Copyright
|
2
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/bin/rd-resolve-test
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# Copyright
|
2
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rubydns.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -66,7 +66,7 @@ module RubyDNS
|
|
66
66
|
#
|
67
67
|
def self.run_server (options = {}, &block)
|
68
68
|
server = RubyDNS::Server.new(&block)
|
69
|
-
server.logger.info "Starting RubyDNS server (v#{RubyDNS::VERSION
|
69
|
+
server.logger.info "Starting RubyDNS server (v#{RubyDNS::VERSION})..."
|
70
70
|
|
71
71
|
options[:listen] ||= [[:udp, "0.0.0.0", 53], [:tcp, "0.0.0.0", 53]]
|
72
72
|
|
@@ -89,4 +89,3 @@ module RubyDNS
|
|
89
89
|
server.fire(:stop)
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
data/lib/rubydns/chunked.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module RubyDNS
|
22
|
+
# Logs an exception nicely.
|
23
|
+
def self.log_exception(logger, exception)
|
24
|
+
logger.error "#{exception.class}: #{exception.message}"
|
25
|
+
if exception.backtrace
|
26
|
+
Array(exception.backtrace).each { |at| logger.error at }
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rubydns/handler.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rubydns/message.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -35,6 +35,7 @@ module RubyDNS
|
|
35
35
|
data.force_encoding("BINARY")
|
36
36
|
end
|
37
37
|
|
38
|
+
# This may throw Resolv::DNS::DecodeError.
|
38
39
|
Message.decode(data)
|
39
40
|
end
|
40
41
|
end
|
data/lib/rubydns/resolver.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -111,12 +111,22 @@ module RubyDNS
|
|
111
111
|
end
|
112
112
|
|
113
113
|
def process_response!(response)
|
114
|
-
if
|
114
|
+
if Exception === response
|
115
|
+
@logger.warn "[#{@message.id}] Failure while processing response #{exception}!" if @logger
|
116
|
+
RubyDNS.log_exception(@logger, response) if @logger
|
117
|
+
|
118
|
+
try_next_server!
|
119
|
+
elsif response.tc != 0
|
115
120
|
@logger.warn "[#{@message.id}] Received truncated response!" if @logger
|
116
|
-
|
121
|
+
|
122
|
+
try_next_server!
|
123
|
+
elsif response.id != @message.id
|
124
|
+
@logger.warn "[#{@message.id}] Received response with incorrect message id: #{response.id}" if @request.logger
|
125
|
+
|
117
126
|
try_next_server!
|
118
127
|
else
|
119
128
|
@logger.warn "[#{@message.id}] Received valid response #{response.inspect}" if @logger
|
129
|
+
|
120
130
|
succeed response
|
121
131
|
end
|
122
132
|
end
|
@@ -175,13 +185,11 @@ module RubyDNS
|
|
175
185
|
def receive_data(data)
|
176
186
|
# Receiving response from remote DNS server...
|
177
187
|
message = RubyDNS::decode_message(data)
|
178
|
-
|
188
|
+
|
179
189
|
# The message id must match, and it can't be truncated:
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
@request.logger.warn "[#{@request.message.id}] Received response with incorrect message id: #{message.id}" if @request.logger
|
184
|
-
end
|
190
|
+
@request.process_response!(message)
|
191
|
+
rescue Resolv::DNS::DecodeError => error
|
192
|
+
@request.process_response!(error)
|
185
193
|
end
|
186
194
|
end
|
187
195
|
|
@@ -214,19 +222,16 @@ module RubyDNS
|
|
214
222
|
end
|
215
223
|
end
|
216
224
|
|
217
|
-
|
225
|
+
# If we have received more data than expected, should this be an error?
|
226
|
+
if @buffer.size >= (@length + 2)
|
218
227
|
data = @buffer.string.byteslice(2, @length)
|
219
228
|
|
220
229
|
message = RubyDNS::decode_message(data)
|
221
230
|
|
222
|
-
|
223
|
-
@request.process_response!(message)
|
224
|
-
else
|
225
|
-
@request.logger.warn "[#{@request.message.id}] Received response with incorrect message id: #{message.id}" if @request.logger
|
226
|
-
end
|
227
|
-
elsif @buffer.size > (@length + 2)
|
228
|
-
@request.try_next_server!
|
231
|
+
@request.process_response!(message)
|
229
232
|
end
|
233
|
+
rescue Resolv::DNS::DecodeError => error
|
234
|
+
@request.process_response!(error)
|
230
235
|
end
|
231
236
|
end
|
232
237
|
end
|
data/lib/rubydns/server.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -19,6 +19,7 @@
|
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
21
|
require 'rubydns/transaction'
|
22
|
+
require 'rubydns/extensions/logger'
|
22
23
|
|
23
24
|
module RubyDNS
|
24
25
|
|
@@ -213,10 +214,7 @@ module RubyDNS
|
|
213
214
|
transaction.errback do |response|
|
214
215
|
if Exception === response
|
215
216
|
@logger.error "Exception thrown while processing #{transaction}!"
|
216
|
-
@logger
|
217
|
-
if response.backtrace
|
218
|
-
Array(response.backtrace).each { |at| @logger.error at }
|
219
|
-
end
|
217
|
+
RubyDNS.log_exception(@logger, response)
|
220
218
|
else
|
221
219
|
@logger.error "Failure while processing #{transaction}!"
|
222
220
|
@logger.error "#{response.inspect}"
|
data/lib/rubydns/system.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
data/lib/rubydns/transaction.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright, 2009, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
2
|
#
|
3
3
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
4
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -124,7 +124,7 @@ module RubyDNS
|
|
124
124
|
case response
|
125
125
|
when RubyDNS::Message
|
126
126
|
yield response
|
127
|
-
when RubyDNS::
|
127
|
+
when RubyDNS::ResolutionFailure
|
128
128
|
failure!(:ServFail)
|
129
129
|
else
|
130
130
|
# This shouldn't ever happen, but if it does for some reason we shouldn't hang.
|