mirror of
https://github.com/cmur2/dyndnsd.git
synced 2025-08-08 08:33:56 +02:00
Compare commits
15 Commits
v2.1.1
...
dyndnsd-2.
Author | SHA1 | Date | |
---|---|---|---|
3f150ad065 | |||
09aa2b127c | |||
618b2c823d | |||
ae62744cc9 | |||
3a9c2d65fb | |||
8976ff5bbe | |||
0c4c38cc6b | |||
0cec44893d | |||
![]() |
33b8325a92 | ||
![]() |
186c79814f | ||
![]() |
cb3977b553 | ||
c112b211a0 | |||
b597ecb15e | |||
c73c09f311 | |||
88133edc1a |
12
.rubocop.yml
12
.rubocop.yml
@@ -1,9 +1,6 @@
|
||||
AllCops:
|
||||
TargetRubyVersion: '2.3'
|
||||
|
||||
Gemspec/OrderedDependencies:
|
||||
Enabled: false
|
||||
|
||||
Layout/EmptyLineAfterGuardClause:
|
||||
Enabled: false
|
||||
|
||||
@@ -56,9 +53,6 @@ Style/Documentation:
|
||||
Style/FormatStringToken:
|
||||
Enabled: false
|
||||
|
||||
Style/FrozenStringLiteralComment:
|
||||
Enabled: false
|
||||
|
||||
Style/GuardClause:
|
||||
Enabled: false
|
||||
|
||||
@@ -74,6 +68,9 @@ Style/HashTransformValues:
|
||||
Style/IdenticalConditionalBranches:
|
||||
Enabled: false
|
||||
|
||||
Style/IfUnlessModifier:
|
||||
Enabled: false
|
||||
|
||||
Style/InverseMethods:
|
||||
Enabled: false
|
||||
|
||||
@@ -85,3 +82,6 @@ Style/RescueModifier:
|
||||
|
||||
Style/SymbolArray:
|
||||
Enabled: false
|
||||
|
||||
Style/TrailingCommaInArrayLiteral:
|
||||
Enabled: false
|
||||
|
20
CHANGELOG.md
20
CHANGELOG.md
@@ -1,5 +1,25 @@
|
||||
# Changelog
|
||||
|
||||
## 2.3.1 (July 27, 2020)
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
||||
- Fix annoying error message `log writing failed. can't be called from trap context` on shutdown by not attempting to log redundant information there
|
||||
|
||||
## 2.3.0 (July 20, 2020)
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
||||
- Allow enabling debug logging
|
||||
- Add updater that uses [DNS zone transfers via AXFR (RFC5936)](https://tools.ietf.org/html/rfc5936) to allow any secondary nameserver(s) to fetch the zone contents after (optionally) receiving a [DNS NOTIFY (RFC1996)](https://tools.ietf.org/html/rfc1996) request
|
||||
|
||||
## 2.2.0 (March 6, 2020)
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
||||
- Refactor gemspec based on [recommendations](https://piotrmurach.com/articles/writing-a-ruby-gem-specification/) so tests are now excluded from gem and binaries move to `./exe` directory
|
||||
- Adopt Ruby 2.3 frozen string literals for source code potentially reducing memory consumption
|
||||
|
||||
## 2.1.1 (March 1, 2020)
|
||||
|
||||
IMPROVEMENTS:
|
||||
|
2
Gemfile
2
Gemfile
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gemspec
|
||||
|
95
README.md
95
README.md
@@ -1,19 +1,24 @@
|
||||
# dyndnsd.rb
|
||||
|
||||
[](https://travis-ci.org/cmur2/dyndnsd) [](https://depfu.com/github/cmur2/dyndnsd)
|
||||
[](https://travis-ci.org/cmur2/dyndnsd) [](https://depfu.com/github/cmur2/dyndnsd)
|
||||
|
||||
A small, lightweight and extensible DynDNS server written with Ruby and Rack.
|
||||
|
||||
**Note:** a newer version of dyndnsd.rb is available on [branch master](https://github.com/cmur2/dyndnsd), see also the [changelog](https://github.com/cmur2/dyndnsd/blob/master/CHANGELOG.md).
|
||||
|
||||
## Description
|
||||
|
||||
dyndnsd.rb aims to implement a small [DynDNS-compliant](https://help.dyn.com/remote-access-api/) server in Ruby supporting IPv4 and IPv6 addresses. It has an integrated user and hostname database in it's configuration file that is used for authentication and authorization. Besides talking the DynDNS protocol it is able to invoke a so-called *updater*, a small Ruby module that takes care of supplying the current hostname => ip mapping to a DNS server.
|
||||
dyndnsd.rb aims to implement a small [DynDNS-compliant](https://help.dyn.com/remote-access-api/) server in Ruby supporting IPv4 and IPv6 addresses. It has an integrated user and hostname database in its configuration file that is used for authentication and authorization. Besides talking the DynDNS protocol it is able to invoke a so-called *updater*, a small Ruby module that takes care of supplying the current hostname => ip mapping to a DNS server.
|
||||
|
||||
There is currently one updater shipped with dyndnsd.rb `command_with_bind_zone` that writes out a zone file in BIND syntax onto the current system and invokes a user-supplied command afterwards that is assumed to trigger the DNS server (not necessarily BIND since it's zone files are read by other DNS servers, too) to reload it's zone configuration.
|
||||
There are currently two updaters shipped with dyndnsd.rb:
|
||||
- `zone_transfer_server` that uses [DNS zone transfers via AXFR (RFC5936)](https://tools.ietf.org/html/rfc5936) to allow any secondary nameserver(s) to fetch the zone contents after (optionally) receiving a [DNS NOTIFY (RFC1996)](https://tools.ietf.org/html/rfc1996) request
|
||||
- `command_with_bind_zone` that writes out a zone file in BIND syntax onto the current system and invokes a user-supplied command afterwards that is assumed to trigger the DNS server (not necessarily BIND since its zone files are read by other DNS servers, too) to reload its zone configuration
|
||||
|
||||
Because of the mechanisms used, dyndnsd.rb is known to work only on \*nix systems.
|
||||
|
||||
See the [changelog](CHANGELOG.md) before upgrading. The older version 1.x of dyndnsd.rb is still available on [branch dyndnsd-1.x](https://github.com/cmur2/dyndnsd/tree/dyndnsd-1.x).
|
||||
|
||||
|
||||
## General Usage
|
||||
|
||||
Install the gem:
|
||||
@@ -25,14 +30,16 @@ Create a configuration file in YAML format somewhere:
|
||||
```yaml
|
||||
# listen address and port
|
||||
host: "0.0.0.0"
|
||||
port: "80"
|
||||
# optional: drop priviliges in case you want to but you may need sudo for external commands
|
||||
port: 80
|
||||
# optional: drop privileges in case you want to but you may need sudo for external commands
|
||||
user: "nobody"
|
||||
group: "nogroup"
|
||||
# logfile is optional, logs to STDOUT else
|
||||
# logfile is optional, logs to STDOUT otherwise
|
||||
logfile: "dyndnsd.log"
|
||||
# interal database file
|
||||
# internal database file
|
||||
db: "db.json"
|
||||
# enable debug mode?
|
||||
debug: false
|
||||
# all hostnames are required to be cool-name.example.org
|
||||
domain: "example.org"
|
||||
# configure the updater, here we use command_with_bind_zone, params are updater-specific
|
||||
@@ -60,15 +67,61 @@ Run dyndnsd.rb by:
|
||||
|
||||
dyndnsd /path/to/config.yaml
|
||||
|
||||
## Using dyndnsd.rb with [NSD](https://www.nlnetlabs.nl/nsd/)
|
||||
|
||||
NSD is a nice opensource, authoritative-only, low-memory DNS server that reads BIND-style zone files (and converts them into it's own database) and has a simple config file.
|
||||
## Using dyndnsd.rb with any nameserver via DNS zone transfers (AXFR)
|
||||
|
||||
A feature NSD is lacking is the [Dynamic DNS update](https://tools.ietf.org/html/rfc2136) functionality BIND offers but one can fake it using the following dyndnsd.rb config:
|
||||
By using [DNS zone transfers via AXFR (RFC5936)](https://tools.ietf.org/html/rfc5936) any secondary nameserver can retrieve the DNS zone contents from dyndnsd.rb and serve them to clients.
|
||||
To speedup propagation after changes dyndnsd.rb can issue a [DNS NOTIFY (RFC1996)](https://tools.ietf.org/html/rfc1996) to inform the nameserver that the DNS zone contents changed and should be fetched even before the time indicated in the SOA record is up.
|
||||
Currently dyndnsd.rb does not support any authentication for incoming DNS zone transfer requests so it should be isolated from the internet on these ports.
|
||||
|
||||
This approach has several advantages:
|
||||
- dyndnsd.rb can be used in *hidden primary* fashion isolated from client's DNS traffic and does not need to implement full nameserver features
|
||||
- any existing, production-grade, caching, geo-replicated nameserver setup can be used to pull DNS zone contents from the *hidden primary* dyndnsd.rb and serve it to clients
|
||||
- any nameserver(s) and dyndnsd.rb do not need to be located on the same host
|
||||
|
||||
Example dyndnsd.rb configuration:
|
||||
|
||||
```yaml
|
||||
host: "0.0.0.0"
|
||||
port: "8245" # the DynDNS.com alternative HTTP port
|
||||
port: 8245 # the DynDNS.com alternative HTTP port
|
||||
db: "/opt/dyndnsd/db.json"
|
||||
domain: "dyn.example.org"
|
||||
updater:
|
||||
name: "zone_transfer_server"
|
||||
params:
|
||||
# endpoint(s) to listen for incoming zone transfer (AXFR) requests, default 0.0.0.0@53
|
||||
server_listens:
|
||||
- 127.0.0.1@5300
|
||||
# where to send DNS NOTIFY request(s) to on zone content change
|
||||
send_notifies:
|
||||
- '127.0.0.1'
|
||||
# TTL for all records in the zone (in seconds)
|
||||
zone_ttl: 300 # 5m
|
||||
# zone's NS record(s) (at least one)
|
||||
zone_nameservers:
|
||||
- "dns.example.org."
|
||||
# info for zone's SOA record
|
||||
zone_email_address: "admin.example.org."
|
||||
# zone's additional A/AAAA records
|
||||
zone_additional_ips:
|
||||
- "127.0.0.1"
|
||||
users:
|
||||
foo:
|
||||
password: "secret"
|
||||
hosts:
|
||||
- foo.example.org
|
||||
```
|
||||
|
||||
|
||||
## Using dyndnsd.rb with [NSD](https://www.nlnetlabs.nl/projects/nsd/about/)
|
||||
|
||||
NSD is a nice, open source, authoritative-only, low-memory DNS server that reads BIND-style zone files (and converts them into its own database) and has a simple configuration file.
|
||||
|
||||
A feature NSD is lacking is the [Dynamic DNS update (RFC2136)](https://tools.ietf.org/html/rfc2136) functionality BIND offers but one can fake it using the following dyndnsd.rb configuration:
|
||||
|
||||
```yaml
|
||||
host: "0.0.0.0"
|
||||
port: 8245 # the DynDNS.com alternative HTTP port
|
||||
db: "/opt/dyndnsd/db.json"
|
||||
domain: "dyn.example.org"
|
||||
updater:
|
||||
@@ -93,12 +146,15 @@ users:
|
||||
|
||||
Start dyndnsd.rb before NSD to make sure the zone file exists else NSD complains.
|
||||
|
||||
|
||||
## Using dyndnsd.rb with X
|
||||
|
||||
Please provide ideas if you are using dyndnsd.rb with other DNS servers :)
|
||||
|
||||
|
||||
## Advanced topics
|
||||
|
||||
|
||||
### Update URL
|
||||
|
||||
The update URL you want to tell your clients (humans or scripts ^^) consists of the following
|
||||
@@ -111,10 +167,11 @@ where:
|
||||
* USER and PASSWORD are needed for HTTP Basic Auth and valid combinations are defined in your config.yaml
|
||||
* DOMAIN should match what you defined in your config.yaml as domain but may be anything else when using a webserver as proxy
|
||||
* PORT depends on your (webserver/proxy) settings
|
||||
* HOSTNAMES is a required list of comma separated FQDNs (they all have to end with your config.yaml domain) the user wants to update
|
||||
* HOSTNAMES is a required list of comma-separated FQDNs (they all have to end with your config.yaml domain) the user wants to update
|
||||
* MYIP is optional and the HTTP client's IP address will be used if missing
|
||||
* MYIP6 is optional but if present also requires presence of MYIP
|
||||
|
||||
|
||||
### IP address determination
|
||||
|
||||
The following rules apply:
|
||||
@@ -123,23 +180,26 @@ The following rules apply:
|
||||
* use any IP address provided via the X-Real-IP header e.g. when used behind HTTP reverse proxy such as nginx, or
|
||||
* use any IP address used by the connecting HTTP client
|
||||
|
||||
If you want to provide an additional IPv6 address as myip6 parameter the myip parameter containing an IPv4 address has to be present, too! No automatism is applied then.
|
||||
If you want to provide an additional IPv6 address as myip6 parameter, the myip parameter containing an IPv4 address has to be present, too! No automatism is applied then.
|
||||
|
||||
|
||||
### SSL, multiple listen ports
|
||||
|
||||
Use a webserver as a proxy to handle SSL and/or multiple listen addresses and ports. DynDNS.com provides HTTP on port 80 and 8245 and HTTPS on port 443.
|
||||
|
||||
|
||||
### Init scripts
|
||||
|
||||
The [Debian 6 init.d script](init.d/debian-6-dyndnsd) assumes that dyndnsd.rb is installed into the system ruby (no RVM support) and the config.yaml is at /opt/dyndnsd/config.yaml. Modify to your needs.
|
||||
|
||||
|
||||
### Monitoring
|
||||
|
||||
For monitoring dyndnsd.rb uses the [metriks](https://github.com/eric/metriks) framework and exposes several metrics like the number of unauthenticated requests, requests that did (not) update a hostname, etc. By default the most important metrics are shown in the [proctitle](https://github.com/eric/metriks#proc-title-reporter) but you can also configure a [Graphite](https://graphiteapp.org/) backend for central monitoring or the [textfile_reporter](https://github.com/prometheus/node_exporter/#textfile-collector) which outputs Graphite-style metrics that are also compatible with Prometheus to a file.
|
||||
|
||||
```yaml
|
||||
host: "0.0.0.0"
|
||||
port: "8245" # the DynDNS.com alternative HTTP port
|
||||
port: 8245 # the DynDNS.com alternative HTTP port
|
||||
db: "/opt/dyndnsd/db.json"
|
||||
domain: "dyn.example.org"
|
||||
# configure the Graphite backend to be used instead of proctitle
|
||||
@@ -172,14 +232,16 @@ users:
|
||||
password: "ihavenohosts"
|
||||
```
|
||||
|
||||
|
||||
### Tracing (experimental)
|
||||
|
||||
For tracing dyndnsd.rb is instrumented using the [OpenTracing](http://opentracing.io/) framework and will emit span tracing data for the most important operations happening during the request/response cycle. Using a middleware for Rack allows handling incoming OpenTracing span information properly.
|
||||
For tracing, dyndnsd.rb is instrumented using the [OpenTracing](http://opentracing.io/) framework and will emit span tracing data for the most important operations happening during the request/response cycle. Using a middleware for Rack allows handling incoming OpenTracing span information properly.
|
||||
|
||||
Currently only one OpenTracing-compatible tracer implementation named [CNCF Jaeger](https://github.com/jaegertracing/jaeger) can be configured to use with dyndnsd.rb.
|
||||
|
||||
```yaml
|
||||
host: "0.0.0.0"
|
||||
port: "8245" # the DynDNS.com alternative HTTP port
|
||||
port: 8245 # the DynDNS.com alternative HTTP port
|
||||
db: "/opt/dyndnsd/db.json"
|
||||
domain: "dyn.example.org"
|
||||
# enable and configure tracing using the (currently only) tracer jaeger
|
||||
@@ -210,6 +272,7 @@ users:
|
||||
password: "ihavenohosts"
|
||||
```
|
||||
|
||||
|
||||
## License
|
||||
|
||||
dyndnsd.rb is licensed under the Apache License, Version 2.0. See LICENSE for more information.
|
||||
|
2
Rakefile
2
Rakefile
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/gem_tasks'
|
||||
require 'rspec/core/rake_task'
|
||||
require 'rubocop/rake_task'
|
||||
|
@@ -1,4 +0,0 @@
|
||||
|
||||
require 'dyndnsd'
|
||||
|
||||
Dyndnsd::Daemon.run!
|
@@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
||||
|
||||
require 'dyndnsd/version'
|
||||
require_relative 'lib/dyndnsd/version'
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'dyndnsd'
|
||||
@@ -9,29 +8,37 @@ Gem::Specification.new do |s|
|
||||
s.summary = 'dyndnsd.rb'
|
||||
s.description = 'A small, lightweight and extensible DynDNS server written with Ruby and Rack.'
|
||||
s.author = 'Christian Nicolai'
|
||||
s.email = 'chrnicolai@gmail.com'
|
||||
|
||||
s.homepage = 'https://github.com/cmur2/dyndnsd'
|
||||
s.license = 'Apache-2.0'
|
||||
s.metadata = {
|
||||
'bug_tracker_uri' => "#{s.homepage}/issues",
|
||||
'changelog_uri' => "#{s.homepage}/blob/master/CHANGELOG.md",
|
||||
'source_code_uri' => s.homepage
|
||||
}
|
||||
|
||||
s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
||||
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
||||
s.files = `git ls-files -z`.split("\x0").select do |f|
|
||||
f.match(%r{^(init.d|lib)/})
|
||||
end
|
||||
s.require_paths = ['lib']
|
||||
s.bindir = 'exe'
|
||||
s.executables = ['dyndnsd']
|
||||
s.extra_rdoc_files = Dir['README.md', 'CHANGELOG.md', 'LICENSE']
|
||||
|
||||
s.required_ruby_version = '>= 2.3'
|
||||
|
||||
s.add_runtime_dependency 'rack', '~> 2.0'
|
||||
s.add_runtime_dependency 'json'
|
||||
s.add_runtime_dependency 'async-dns', '~> 1.2.0'
|
||||
s.add_runtime_dependency 'jaeger-client', '~> 0.10.0'
|
||||
s.add_runtime_dependency 'metriks'
|
||||
s.add_runtime_dependency 'opentracing', '~> 0.5.0'
|
||||
s.add_runtime_dependency 'rack', '~> 2.0'
|
||||
s.add_runtime_dependency 'rack-tracer', '~> 0.9.0'
|
||||
s.add_runtime_dependency 'jaeger-client', '~> 0.10.0'
|
||||
|
||||
s.add_development_dependency 'bundler'
|
||||
s.add_development_dependency 'bundler-audit', '~> 0.7.0'
|
||||
s.add_development_dependency 'rack-test'
|
||||
s.add_development_dependency 'rake'
|
||||
s.add_development_dependency 'rspec'
|
||||
s.add_development_dependency 'rack-test'
|
||||
s.add_development_dependency 'rubocop', '~> 0.80.0'
|
||||
s.add_development_dependency 'bundler-audit', '~> 0.6.0'
|
||||
s.add_development_dependency 'rubocop', '~> 0.81.0'
|
||||
s.add_development_dependency 'solargraph'
|
||||
end
|
||||
|
6
exe/dyndnsd
Executable file
6
exe/dyndnsd
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'dyndnsd'
|
||||
|
||||
Dyndnsd::Daemon.run!
|
17
lib/dyndnsd.rb
Executable file → Normal file
17
lib/dyndnsd.rb
Executable file → Normal file
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'etc'
|
||||
require 'logger'
|
||||
@@ -13,6 +13,7 @@ require 'rack/tracer'
|
||||
|
||||
require 'dyndnsd/generator/bind'
|
||||
require 'dyndnsd/updater/command_with_bind_zone'
|
||||
require 'dyndnsd/updater/zone_transfer_server'
|
||||
require 'dyndnsd/responder/dyndns_style'
|
||||
require 'dyndnsd/responder/rest_style'
|
||||
require 'dyndnsd/database'
|
||||
@@ -56,9 +57,9 @@ module Dyndnsd
|
||||
@db.load
|
||||
@db['serial'] ||= 1
|
||||
@db['hosts'] ||= {}
|
||||
@updater.update(@db)
|
||||
if @db.changed?
|
||||
@db.save
|
||||
@updater.update(@db)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -193,8 +194,8 @@ module Dyndnsd
|
||||
def update_db
|
||||
@db['serial'] += 1
|
||||
Dyndnsd.logger.info "Committing update ##{@db['serial']}"
|
||||
@db.save
|
||||
@updater.update(@db)
|
||||
@db.save
|
||||
Metriks.meter('updates.committed').mark
|
||||
end
|
||||
|
||||
@@ -249,16 +250,15 @@ module Dyndnsd
|
||||
|
||||
Dyndnsd.logger.progname = 'dyndnsd'
|
||||
Dyndnsd.logger.formatter = LogFormatter.new
|
||||
Dyndnsd.logger.level = config['debug'] ? Logger::DEBUG : Logger::INFO
|
||||
end
|
||||
|
||||
# @return [void]
|
||||
private_class_method def self.setup_traps
|
||||
Signal.trap('INT') do
|
||||
Dyndnsd.logger.info 'Quitting...'
|
||||
Rack::Handler::WEBrick.shutdown
|
||||
end
|
||||
Signal.trap('TERM') do
|
||||
Dyndnsd.logger.info 'Quitting...'
|
||||
Rack::Handler::WEBrick.shutdown
|
||||
end
|
||||
end
|
||||
@@ -313,7 +313,12 @@ module Dyndnsd
|
||||
private_class_method def self.setup_rack(config)
|
||||
# configure daemon
|
||||
db = Database.new(config['db'])
|
||||
updater = Updater::CommandWithBindZone.new(config['domain'], config.dig('updater', 'params')) if config.dig('updater', 'name') == 'command_with_bind_zone'
|
||||
case config.dig('updater', 'name')
|
||||
when 'command_with_bind_zone'
|
||||
updater = Updater::CommandWithBindZone.new(config['domain'], config.dig('updater', 'params'))
|
||||
when 'zone_transfer_server'
|
||||
updater = Updater::ZoneTransferServer.new(config['domain'], config.dig('updater', 'params'))
|
||||
end
|
||||
daemon = Daemon.new(config, db, updater)
|
||||
|
||||
# configure rack
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'forwardable'
|
||||
|
||||
|
@@ -1,15 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Dyndnsd
|
||||
module Generator
|
||||
class Bind
|
||||
# @param domain [String]
|
||||
# @param config [Hash{String => Object}]
|
||||
def initialize(domain, config)
|
||||
# @param updater_params [Hash{String => Object}]
|
||||
def initialize(domain, updater_params)
|
||||
@domain = domain
|
||||
@ttl = config['ttl']
|
||||
@dns = config['dns']
|
||||
@email_addr = config['email_addr']
|
||||
@additional_zone_content = config['additional_zone_content']
|
||||
@ttl = updater_params['ttl']
|
||||
@dns = updater_params['dns']
|
||||
@email_addr = updater_params['email_addr']
|
||||
@additional_zone_content = updater_params['additional_zone_content']
|
||||
end
|
||||
|
||||
# @param db [Dyndnsd::Database]
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'ipaddr'
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Dyndnsd
|
||||
module Responder
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Dyndnsd
|
||||
module Responder
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Adapted from https://github.com/eric/metriks-graphite/blob/master/lib/metriks/reporter/graphite.rb
|
||||
|
||||
|
@@ -1,18 +1,22 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Dyndnsd
|
||||
module Updater
|
||||
class CommandWithBindZone
|
||||
# @param domain [String]
|
||||
# @param config [Hash{String => Object}]
|
||||
def initialize(domain, config)
|
||||
@zone_file = config['zone_file']
|
||||
@command = config['command']
|
||||
@generator = Generator::Bind.new(domain, config)
|
||||
# @param updater_params [Hash{String => Object}]
|
||||
def initialize(domain, updater_params)
|
||||
@zone_file = updater_params['zone_file']
|
||||
@command = updater_params['command']
|
||||
@generator = Generator::Bind.new(domain, updater_params)
|
||||
end
|
||||
|
||||
# @param db [Dyndnsd::Database]
|
||||
# @return [void]
|
||||
def update(db)
|
||||
# do not regenerate zone file (assumed to be persistent) if DB did not change
|
||||
return if !db.changed?
|
||||
|
||||
Helper.span('updater_update') do |span|
|
||||
span.set_tag('dyndnsd.updater.name', self.class.name&.split('::')&.last || 'None')
|
||||
|
||||
|
158
lib/dyndnsd/updater/zone_transfer_server.rb
Normal file
158
lib/dyndnsd/updater/zone_transfer_server.rb
Normal file
@@ -0,0 +1,158 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'resolv'
|
||||
require 'securerandom'
|
||||
|
||||
require 'async/dns'
|
||||
|
||||
module Dyndnsd
|
||||
module Updater
|
||||
class ZoneTransferServer
|
||||
DEFAULT_SERVER_LISTENS = ['0.0.0.0@53'].freeze
|
||||
|
||||
# @param domain [String]
|
||||
# @param updater_params [Hash{String => Object}]
|
||||
def initialize(domain, updater_params)
|
||||
@domain = domain
|
||||
|
||||
@server_listens = self.class.parse_endpoints(updater_params['server_listens'] || DEFAULT_SERVER_LISTENS)
|
||||
@notify_targets = (updater_params['send_notifies'] || []).map { |e| self.class.parse_endpoints([e]) }
|
||||
|
||||
@zone_rr_ttl = updater_params['zone_ttl']
|
||||
@zone_nameservers = updater_params['zone_nameservers'].map { |n| Resolv::DNS::Name.create(n) }
|
||||
@zone_email_address = Resolv::DNS::Name.create(updater_params['zone_email_address'])
|
||||
@zone_additional_ips = updater_params['zone_additional_ips'] || []
|
||||
|
||||
@server = ZoneTransferServerHelper.new(@server_listens, @domain)
|
||||
|
||||
# run Async::DNS server in background thread
|
||||
Thread.new do
|
||||
@server.run
|
||||
end
|
||||
end
|
||||
|
||||
# @param db [Dyndnsd::Database]
|
||||
# @return [void]
|
||||
def update(db)
|
||||
Helper.span('updater_update') do |span|
|
||||
span.set_tag('dyndnsd.updater.name', self.class.name&.split('::')&.last || 'None')
|
||||
|
||||
soa_rr = Resolv::DNS::Resource::IN::SOA.new(
|
||||
@zone_nameservers[0], @zone_email_address,
|
||||
db['serial'],
|
||||
10_800, # 3h
|
||||
300, # 5m
|
||||
604_800, # 1w
|
||||
3_600 # 1h
|
||||
)
|
||||
|
||||
default_options = {ttl: @zone_rr_ttl}
|
||||
|
||||
# array containing all resource records for an AXFR request in the right order
|
||||
rrs = []
|
||||
# AXFR responses need to start with zone's SOA RR
|
||||
rrs << [soa_rr, default_options]
|
||||
|
||||
# return RRs for all of the zone's nameservers
|
||||
@zone_nameservers.each do |ns|
|
||||
rrs << [Resolv::DNS::Resource::IN::NS.new(ns), default_options]
|
||||
end
|
||||
|
||||
# return A/AAAA RRs for all additional IPv4s/IPv6s for the domain itself
|
||||
@zone_additional_ips.each do |ip|
|
||||
rrs << [create_addr_rr_for_ip(ip), default_options]
|
||||
end
|
||||
|
||||
# return A/AAAA RRs for the dyndns hostnames
|
||||
db['hosts'].each do |hostname, ips|
|
||||
ips.each do |ip|
|
||||
rrs << [create_addr_rr_for_ip(ip), default_options.merge({name: hostname})]
|
||||
end
|
||||
end
|
||||
|
||||
# AXFR responses need to end with zone's SOA RR again
|
||||
rrs << [soa_rr, default_options]
|
||||
|
||||
# point Async::DNS server thread's variable to this new RR array
|
||||
@server.axfr_rrs = rrs
|
||||
|
||||
# only send DNS NOTIFY if there really was a change
|
||||
if db.changed?
|
||||
send_dns_notify
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# converts into suitable parameter form for Async::DNS::Resolver or Async::DNS::Server
|
||||
#
|
||||
# @param endpoint_list [Array{String}]
|
||||
# @return [Array{Array{Object}}]
|
||||
def self.parse_endpoints(endpoint_list)
|
||||
endpoint_list.map { |addr_string| addr_string.split('@') }
|
||||
.map { |addr_parts| [addr_parts[0], addr_parts[1].to_i || 53] }
|
||||
.map { |addr| [:tcp, :udp].map { |type| [type] + addr } }
|
||||
.flatten(1)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# creates correct Resolv::DNS::Resource object for IP address type
|
||||
#
|
||||
# @param ip_string [String]
|
||||
# @return [Resolv::DNS::Resource::IN::A,Resolv::DNS::Resource::IN::AAAA]
|
||||
def create_addr_rr_for_ip(ip_string)
|
||||
ip = IPAddr.new(ip_string).native
|
||||
|
||||
if ip.ipv6?
|
||||
Resolv::DNS::Resource::IN::AAAA.new(ip.to_s)
|
||||
else
|
||||
Resolv::DNS::Resource::IN::A.new(ip.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
# https://tools.ietf.org/html/rfc1996
|
||||
#
|
||||
# @return [void]
|
||||
def send_dns_notify
|
||||
Async::Reactor.run do
|
||||
@notify_targets.each do |notify_target|
|
||||
target = Async::DNS::Resolver.new(notify_target)
|
||||
|
||||
# assemble DNS NOTIFY message
|
||||
request = Resolv::DNS::Message.new(SecureRandom.random_number(2**16))
|
||||
request.opcode = Resolv::DNS::OpCode::Notify
|
||||
request.add_question("#{@domain}.", Resolv::DNS::Resource::IN::SOA)
|
||||
|
||||
_response = target.dispatch_request(request)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ZoneTransferServerHelper < Async::DNS::Server
|
||||
attr_accessor :axfr_rrs
|
||||
|
||||
def initialize(endpoints, domain)
|
||||
super(endpoints, logger: Dyndnsd.logger)
|
||||
@domain = domain
|
||||
end
|
||||
|
||||
# @param name [String]
|
||||
# @param resource_class [Resolv::DNS::Resource]
|
||||
# @param transaction [Async::DNS::Transaction]
|
||||
# @return [void]
|
||||
def process(name, resource_class, transaction)
|
||||
if name != @domain || resource_class != Resolv::DNS::Resource::Generic::Type252_Class1
|
||||
transaction.fail!(:NXDomain)
|
||||
return
|
||||
end
|
||||
|
||||
# https://tools.ietf.org/html/rfc5936
|
||||
transaction.append_question!
|
||||
@axfr_rrs.each do |rr|
|
||||
transaction.add([rr[0]], rr[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@@ -1,4 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Dyndnsd
|
||||
VERSION = '2.1.1'.freeze
|
||||
VERSION = '2.3.1'
|
||||
end
|
||||
|
@@ -1,4 +1,6 @@
|
||||
require 'spec_helper'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe Dyndnsd::Daemon do
|
||||
include Rack::Test::Methods
|
||||
|
@@ -1,8 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rubygems'
|
||||
require 'bundler/setup'
|
||||
require 'rack/test'
|
||||
|
||||
require 'dyndnsd'
|
||||
require 'support/dummy_database'
|
||||
require 'support/dummy_updater'
|
||||
|
||||
require_relative 'support/dummy_database'
|
||||
require_relative 'support/dummy_updater'
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'forwardable'
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Dyndnsd
|
||||
module Updater
|
||||
|
Reference in New Issue
Block a user