diff --git a/README.md b/README.md index 35e892e..8f9226b 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,18 @@ make ``` ## Usage +``` +$ realm --help +usage: realm [--bind BIND] [ZONE [ZONE ...]] + +positional arguments: + zone DNS zone files to serve from this server + +options: + --bind BIND []: to bind too [default: :53] + --help, -h display this help and exit +``` + ### Zone file To run a server you must have a DNS [zone file](https://en.wikipedia.org/wiki/Zone_file). @@ -47,17 +59,13 @@ Example taken from [here](https://en.wikipedia.org/wiki/Zone_file#File_format). ### Starting the server ``` -realm --zone ./domain.zone +realm ./domain.zone ``` -By default `realm` binds to port `53`, which usually requires root, so you may need to run `sudo realm --zone ./domain.zone`. +By default `realm` binds to port `53`, which usually requires root, so you may need to run `sudo realm ./domain.zone`. -### Options -* `--zone, -z` - the file file to load (e.g. `./domain.zone`), this argument is required - * You may instead specify the environment variable `REALM_ZONE="./domain.zone"` -* `--bind, -b` - the `[]:` to bind the server to (e.g. `0.0.0.0:53`), default is `:53` - * You may instead specify the environment variable `REALM_BIND=":53"` -* `--help, -h` - show help message -* `--version, -v` - show version information +You can also specify any number of zone files by providing multiple zone files. -To see the latest command usage run `realm --help`. +``` +realm ./first.domain.zone ./second.domain.zone +``` diff --git a/doc.go b/doc.go index f352a89..57f7289 100644 --- a/doc.go +++ b/doc.go @@ -13,26 +13,18 @@ Realm will parse your server configuration from a DNS zone file see https://en.w To start a server: - realm --zone ./domain.zone + realm ./domain.zone + realm --bind "127.0.0.1:1053" ./first.domain.zone ./second.domain.zone Full command usage: - NAME: - realm - A simple non-recursive DNS server + usage: realm [--bind BIND] [ZONE [ZONE ...]] - USAGE: - realm [global options] command [command options] [arguments...] + positional arguments: + zone DNS zone files to serve from this server - VERSION: - 0.1.0 - - COMMANDS: - help, h Shows a list of commands or help for one command - - GLOBAL OPTIONS: - --zone, -z location to DNS zone file [required] [$REALM_ZONE] - --bind, -b ':53' '[]:' to bind too [$REALM_BIND] - --help, -h show help - --version, -v print the version + options: + --bind BIND []: to bind too [default: :53] + --help, -h display this help and exit */ package realm diff --git a/registry.go b/registry.go index 5f1b046..cc1e233 100644 --- a/registry.go +++ b/registry.go @@ -2,8 +2,10 @@ package realm import "github.com/miekg/dns" +// RecordsEntry is used to hold a mapping of DNS request types to DNS records type RecordsEntry map[uint16][]dns.RR +// GetRecords will fetch the appropriate DNS records to the requested type func (entry RecordsEntry) GetRecords(rrType uint16) []dns.RR { var records []dns.RR records = make([]dns.RR, 0) @@ -19,8 +21,10 @@ func (entry RecordsEntry) GetRecords(rrType uint16) []dns.RR { return records } +// DomainEntry is used to hold a mapping of DNS request classes to RecordEntrys type DomainEntry map[uint16]RecordsEntry +// AddEntry is used to add a new DNS record to this mapping func (entry DomainEntry) AddEntry(record dns.RR) { var header *dns.RR_Header header = record.Header() @@ -35,6 +39,7 @@ func (entry DomainEntry) AddEntry(record dns.RR) { entry[header.Class][header.Rrtype] = append(entry[header.Class][header.Rrtype], record) } +// GetEntries is used to find the appropriate RecordEntrys for the requested DNS class func (entry DomainEntry) GetEntries(rrClass uint16) []RecordsEntry { var entries []RecordsEntry entries = make([]RecordsEntry, 0) @@ -50,16 +55,17 @@ func (entry DomainEntry) GetEntries(rrClass uint16) []RecordsEntry { return entries } -type Registry struct { - records map[string]DomainEntry -} +// Registry is a container for looking up DNS records for any request +type Registry map[string]DomainEntry +// NewRegistry will allocate and return a new *Registry func NewRegistry() *Registry { return &Registry{ records: make(map[string]DomainEntry), } } +// addRecord is used to add a new DNS record to this registry func (r *Registry) addRecord(record dns.RR) { var header *dns.RR_Header header = record.Header() @@ -84,6 +90,7 @@ func (r *Registry) addRecord(record dns.RR) { } } +// AddZone is used to add the records from a *Zone into this *Registry func (r *Registry) AddZone(z *Zone) { for _, record := range z.Records() { r.addRecord(record) diff --git a/zone.go b/zone.go index 13d0a8e..7223832 100644 --- a/zone.go +++ b/zone.go @@ -42,6 +42,7 @@ func ParseZone(filename string) (*Zone, error) { return zone, nil } +// Records will retrieve the DNS records for this zone func (zone *Zone) Records() []dns.RR { return zone.records }