Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bortzmeyer/grong
Browse files Browse the repository at this point in the history
  • Loading branch information
bortzmeyer committed Nov 3, 2010
2 parents 552c0a1 + fe9d234 commit 8158667
Show file tree
Hide file tree
Showing 9 changed files with 742 additions and 62 deletions.
16 changes: 9 additions & 7 deletions Makefile
@@ -1,27 +1,29 @@
include $(GOROOT)/src/Make.$(GOARCH)
include $(GOROOT)/src/Make.inc

TARBALL=/tmp/grong.tar.gz
DEFAULTPORT=8053

all: server
all: grong

test: server
./server -debug=4
test: grong
@echo "Running server on port $(DEFAULTPORT)..."
./grong -debug=4 -nodaemon -address ":$(DEFAULTPORT)" -servername "grong.dns.test"

server.$O: responder.$O types.$O
server.$O: responder.$O types.$O myflag.$O

responder.$O: types.$O

%.$O: %.go
${GC} $<

server: server.$O
grong: server.$O
${LD} -o $@ server.$O

dist: distclean
(cd ..; tar czvf ${TARBALL} grong/*)

clean:
rm -f server *.$O *.a
rm -f grong *.$O *.a

distclean: clean
rm -f *~ responder.go
44 changes: 29 additions & 15 deletions README
Expand Up @@ -21,23 +21,28 @@ The official source is <http://github.com/bortzmeyer/grong>
Usage
*****

./dnsserver [-address="[ADDRESS]:PORT"] [-debug=N]
./grong [-address="[ADDRESS]:PORT"] [-debug=N] [-nodaemon] [-domain="DOMAIN NAME"]

Run with -h to see the defaults (and the other, less common, options)
Run with -help to see the defaults (and the other, less common, options)

The -address option takes either a port (in the syntax ":NNN"), in
that case GRONG listens on all IP addresses, or one address (in the
syntax "x.y.z.T:NNN" for IPv4 and "[xxxx:yyyy::zzzz]:NNN" for
IPv6). There is currently no way to listen on some (but not all) of the IP
addresses.

The -domain option takes a domain name, which will be the name of the
zone for which the name server will be authoritative for. Not all
responders use it.

The back-end is choosen at compile-time only (I have no idea about the
support for dynamic linking in Go)

Among the provided responders:
* rude-responder: responds REFUSED to every query
* reflector-responder: responds with the IP address of the client (for TXT
requests, in text form, for A or AAAA requests, as binary)
requests, in text form, for A or AAAA requests, as binary). -domain indicates
the zone name it uses (e.g. whoami.example.net)
* as112: an AS 112 name server (see <http://www.as112.net/>)

For the person who compiles
Expand Down Expand Up @@ -69,7 +74,8 @@ responder. The prototype is:
func Respond(query types.DNSquery, config map[string]interface{}) types.DNSresponse

To see what is available for you in the query, see the description of
type DNSquery.
type DNSquery. Important: the query name (Qname) is always in
lowercase, to ease comparisons.

In the DNSresponse, RRs (Resource Records) have to be in the wire
format (the front-end does not know the format of the RR, to keep it
Expand All @@ -85,7 +91,8 @@ code of server.go to find others) are:
debug, etc). Always set.
* servername: if set, a string identifying this specific name server
(for instance "cdg1.a.ns.example.net").
* zone: if set, the name of the zone currently served
* zonename: if set, the name of the zone currently served (for instance
"myself.example.net")

Since the map stores various types (the "interface{}", which means the
empty interface, something which is fulfilled by every possible
Expand All @@ -96,6 +103,14 @@ if exists {
debugi := reflect.NewValue(debug).(*reflect.IntValue).Get()
}

The responder must also provide a function:

func Init(firstoption int)

which will be called at server startup and which can be used to
process additional command-line flags (see as112.go for a good
example) or any other stuff.

Implementation notes
********************

Expand All @@ -106,12 +121,6 @@ are behind BIND.
TODO
****

Pass unknown command-line options to the responder. Options Qname for
the reflector and various TXT for as112. Or use the global config
object? For instance, config["zone"] should be common enough.

Use the log package

Finish the AS112 responder (SOA and NS records)

The ability to listen to more than one address (but not all). Can I
Expand All @@ -126,12 +135,17 @@ queryperf!

Test with gccgo

Implements id.server and version.bind
Implements version.server (and version.bind and hostname.bind ?)

See if we can replace a good part of package "types" by standard
package net/ <http://golang.org/src/pkg/net/dnsmsg.go>

Daemonize <http://groups.google.com/group/golang-nuts/browse_thread/thread/2b29d93b90501a4b/95242bfb7ae0549e>
package net/ <http://golang.org/src/pkg/net/dnsmsg.go> It does not
seem easy, the dns* files do not export anything outside of package
net, they are meant for internal use only.

Daemonizing seems very difficult with Go
<http://groups.google.com/group/golang-nuts/browse_thread/thread/2b29d93b90501a4b/95242bfb7ae0549e>
In the mean time, nohup + & + disown seems the only solution. Provide
an example at least for Debian, using start-stop-daemon?

A name server with data, for instance able to serve a zone with a
simple setup, one SOA, a few NS, and one A record for www.$ORIGIN. The
Expand Down
38 changes: 36 additions & 2 deletions as112.go
Expand Up @@ -2,14 +2,21 @@
Stephane Bortzmeyer <stephane+grong@bortzmeyer.org>
Example of use:
grong -servername "grong.cloud.as112.test" -- -email toto.example.net -hostname me.as112.net -location "In the cloud"
*/

package responder

import (
"regexp"
"strings"
"fmt"
"os"
"./types"
"./myflag"
)

const as112Regexp = "(168\\.192\\.in-addr\\.arpa|154\\.169\\.in-addr\\.arpa|16\\.172\\.in-addr\\.arpa|17\\.172\\.in-addr\\.arpa|18\\.172\\.in-addr\\.arpa|19\\.172\\.in-addr\\.arpa|20\\.172\\.in-addr\\.arpa|21\\.172\\.in-addr\\.arpa|22\\.172\\.in-addr\\.arpa|23\\.172\\.in-addr\\.arpa|24\\.172\\.in-addr\\.arpa|25\\.172\\.in-addr\\.arpa|26\\.172\\.in-addr\\.arpa|27\\.172\\.in-addr\\.arpa|28\\.172\\.in-addr\\.arpa|29\\.172\\.in-addr\\.arpa|30\\.172\\.in-addr\\.arpa|31\\.172\\.in-addr\\.arpa|10\\.in-addr\\.arpa)$"
Expand All @@ -33,8 +40,8 @@ var (
}

hostnamesoa = types.SOArecord{
Mname: "NOT-CONFIGURED.as112.example.net", // Put the real host name
Rname: "UNKNOWN.as112.example.net", // Put your email address (with @ replaced by .)
Mname: "NOT-CONFIGURED-use-hostname-option.as112.example.net", // Put the real hostname with the -hostname command-line option. We do not use -server which has lightly different semantics.
Rname: "UNKNOWN-use-email-option.as112.example.net", // Put your email address (with @ replaced by .) with the -email command-line option
Serial: 2003030100,
Refresh: 3600,
Retry: 600,
Expand Down Expand Up @@ -127,3 +134,30 @@ func Respond(query types.DNSquery, config map[string]interface{}) (result types.
}
return result
}

func Init(firstoption int) {
flag.Reinit(firstoption)
helpptr := flag.Bool("help", false, "Displays usage instructions")
emailptr := flag.String("email", "",
"Set the email address of the manager for this server (in DNS format, with . instead of @)")
locationptr := flag.String("location", "",
"Set the location of this server, for instance \"ALIX exchange point in Somewhere, Somestate\"")
hostnameptr := flag.String("hostname", "",
"Set the official host name for this server")
flag.Parse()
help := *helpptr
if help {
fmt.Printf("Usage of the AS112 responder:\n")
flag.PrintDefaults()
os.Exit(0)
}
if *emailptr != "" {
hostnamesoa.Rname = *emailptr
}
if *locationptr != "" {
hostnameAnswers[0] = *locationptr
}
if *hostnameptr != "" {
hostnamesoa.Mname = *hostnameptr
}
}

0 comments on commit 8158667

Please sign in to comment.