Browse Source

update docs

master
Brett Langdon 10 years ago
parent
commit
67e82fba29
4 changed files with 37 additions and 29 deletions
  1. +18
    -10
      README.md
  2. +8
    -16
      doc.go
  3. +10
    -3
      registry.go
  4. +1
    -0
      zone.go

+ 18
- 10
README.md View File

@ -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 [<host>]:<port> 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 `[<host>]:<port>` 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
```

+ 8
- 16
doc.go View File

@ -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' '[<host>]:<port>' to bind too [$REALM_BIND]
--help, -h show help
--version, -v print the version
options:
--bind BIND [<host>]:<port> to bind too [default: :53]
--help, -h display this help and exit
*/
package realm

+ 10
- 3
registry.go View File

@ -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)


+ 1
- 0
zone.go View File

@ -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
}

Loading…
Cancel
Save