Class: Matchd::Rule::Passthrough

Inherits:
Matchd::Rule show all
Defined in:
lib/matchd/rule/passthrough.rb

Constant Summary

Constants inherited from Matchd::Rule

NotImplementedError, REGEXP_MATCHER, REGEXP_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Matchd::Rule

#raw

Instance Method Summary collapse

Methods inherited from Matchd::Rule

#call, #match_name, #match_resource_classes, #matches?, parse_match, parse_resource_class

Constructor Details

#initialize(options) ⇒ Passthrough

Returns a new instance of Passthrough.

Parameters:

  • options (Hash)

Options Hash (options):

  • "resolver" (Array<Array>|Array<Hash>|Async::DNS::Resolver)

    List of passthrough DNS servers. See ‘Matchd::Glue::AsyncEndpoint` for more formats.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/matchd/rule/passthrough.rb', line 7

def initialize(options)
  super
  opts = options.fetch("passthrough")

  if opts.is_a?(Hash) && opts.key?("resolver")
    @resolver = opts["resolver"]
    @passthrough_options = Matchd::Helpers.extract_options(%w(force name), opts)
  else
    @resolver = opts
    @passthrough_options = {}
  end
end

Instance Attribute Details

#passthrough_optionsObject (readonly)

Returns the value of attribute passthrough_options.



20
21
22
# File 'lib/matchd/rule/passthrough.rb', line 20

def passthrough_options
  @passthrough_options
end

#resolverObject (readonly)

Returns the value of attribute resolver.



20
21
22
# File 'lib/matchd/rule/passthrough.rb', line 20

def resolver
  @resolver
end

Instance Method Details

#passthrough_resolverObject

Lazy convert the #resolver into somethinge we can pass to Async::DNS::Transaction#passthrough!



40
41
42
43
44
45
46
47
48
49
# File 'lib/matchd/rule/passthrough.rb', line 40

def passthrough_resolver
  case resolver
  when Async::DNS::Resolver
    resolver
  when "system", :system, nil
    Async::DNS::Resolver.new(Async::DNS::System.nameservers)
  else
    Async::DNS::Resolver.new(Matchd::Glue::AsyncEndpoint.parse(resolver))
  end
end

#visit!(server, _name, _resource_class, transaction) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/matchd/rule/passthrough.rb', line 22

def visit!(server, _name, _resource_class, transaction)
  transaction.passthrough!(passthrough_resolver, passthrough_options) do |response|
    server.logger.debug ";; Passthrough to upstream resolver"
    server.logger.debug ";; Question"
    server.logger.debug(*response.question.map { |q, r| "#{q}\t#{r}" })
    server.logger.debug ";; Answer"
    if response.answer.any?
      response.answer.each do |name_in_answer, ttl, record|
        server.logger.debug "#{name_in_answer}\t#{ttl}\t#{record.class}\t#{record.address if record.respond_to?(:address)}"
      end
    else
      server.logger.debug ";; Empty"
    end
  end
end