Bring funkensturm up to date for the new api

This commit is contained in:
Miek Gieben 2011-02-10 12:26:26 +01:00
parent dd6d245488
commit 61925e2002
7 changed files with 201 additions and 226 deletions

View File

@ -5,8 +5,8 @@ supported. DNSSEC types too.
EDNS0 is (see edns.go), UDP/TCP queries, TSIG, AXFR (and IXFR probably) EDNS0 is (see edns.go), UDP/TCP queries, TSIG, AXFR (and IXFR probably)
too. Both client and server side programming is supported. too. Both client and server side programming is supported.
Sample programs can be found in the _examples directory. They can Sample programs can be found in the `_examples` directory. They can
be build with: make examples (after the dns package has been installed) be build with: `make examples` (after the dns package has been installed)
The major omission at the moment is parsing Resource Records from The major omission at the moment is parsing Resource Records from
strings. (i.e. supporting the RFC 1035 zone file format). strings. (i.e. supporting the RFC 1035 zone file format).
@ -15,9 +15,10 @@ Also the IPv6 support needs to be tested
Everything else should be present and working. If not, drop me an email. Everything else should be present and working. If not, drop me an email.
Have fun! Have fun!
Miek Gieben - 2010, 2011 - miek@miek.nl Miek Gieben - 2010, 2011 - miek@miek.nl
Supported RFCs and features include: ## Supported RFCs and features include:
* 1034/1035 - DNS standard * 1034/1035 - DNS standard
* 1982 - Serial Arithmetic * 1982 - Serial Arithmetic
@ -37,11 +38,12 @@ Supported RFCs and features include:
* 4255 - SSHFP * 4255 - SSHFP
* 4408 - SPF * 4408 - SPF
* 5001 - NSID * 5001 - NSID
* 5155 - NSEC -- todo * 5155 - NSEC
* 5936 - AXFR * 5936 - AXFR
Loosely based upon: ## Loosely based upon:
* ldns
* NSD * `ldns`
* Net::DNS * `NSD`
* GRONG * `Net::DNS`
* `GRONG`

View File

@ -2,7 +2,6 @@ package main
import ( import (
"dns" "dns"
"dns/resolver"
) )
func match(m *dns.Msg, d int) (*dns.Msg, bool) { func match(m *dns.Msg, d int) (*dns.Msg, bool) {
@ -26,17 +25,15 @@ func match(m *dns.Msg, d int) (*dns.Msg, bool) {
return m, true return m, true
} }
func send(m *dns.Msg, ok bool) *dns.Msg { func send(m *dns.Msg, ok bool) (out *dns.Msg) {
switch ok { switch ok {
case true, false: case true, false:
var in resolver.Msg
for _, r := range qr { for _, r := range qr {
r <- resolver.Msg{m, nil, nil} out, _ = r.Query(m)
in = <-r
} }
return in.Dns // return the last return
} }
return nil return
} }
// Return the configration // Return the configration

View File

@ -7,7 +7,6 @@ import (
"dns" "dns"
"fmt" "fmt"
"time" "time"
"dns/resolver"
) )
const NSECDELAY = 1 * 1e9 // 1 second, meaning 1 qps (smaller means higher qps) const NSECDELAY = 1 * 1e9 // 1 second, meaning 1 qps (smaller means higher qps)
@ -47,7 +46,7 @@ func match(m *dns.Msg, d int) (*dns.Msg, bool) {
return m, ok return m, ok
} }
func delay(m *dns.Msg, ok bool) *dns.Msg { func delay(m *dns.Msg, ok bool) (out *dns.Msg) {
var ok1 bool var ok1 bool
switch ok { switch ok {
case true: case true:
@ -55,26 +54,21 @@ func delay(m *dns.Msg, ok bool) *dns.Msg {
if !ok1 { if !ok1 {
fmt.Fprintf(os.Stderr, "Info: Dropping: too often\n") fmt.Fprintf(os.Stderr, "Info: Dropping: too often\n")
time.Sleep(NSECDELAY) time.Sleep(NSECDELAY)
return nil return
} else { } else {
fmt.Fprintf(os.Stderr, "Info: Ok: let it through\n") fmt.Fprintf(os.Stderr, "Info: Ok: let it through\n")
var in resolver.Msg
for _, r := range qr { for _, r := range qr {
r <- resolver.Msg{m, nil, nil} out, _ = r.Query(m)
in = <-r
} }
return in.Dns return
} }
case false: case false:
var in resolver.Msg
for _, r := range qr { for _, r := range qr {
r <- resolver.Msg{m, nil, nil} out, _ = r.Query(m)
in = <-r
} }
return in.Dns return
return in.Dns
} }
return nil return
} }
// Return the configration // Return the configration

View File

@ -2,7 +2,6 @@ package main
import ( import (
"dns" "dns"
"dns/resolver"
) )
func match(m *dns.Msg, d int) (*dns.Msg, bool) { func match(m *dns.Msg, d int) (*dns.Msg, bool) {
@ -26,17 +25,15 @@ func match(m *dns.Msg, d int) (*dns.Msg, bool) {
return m, true return m, true
} }
func send(m *dns.Msg, ok bool) *dns.Msg { func send(m *dns.Msg, ok bool) (out *dns.Msg) {
switch ok { switch ok {
case true, false: case true, false:
var in resolver.Msg
for _, r := range qr { for _, r := range qr {
r <- resolver.Msg{m, nil, nil} out, _ = r.Query(m)
in = <-r
} }
return in.Dns return
} }
return nil return
} }
// Return the configration // Return the configration

View File

@ -7,7 +7,6 @@ package main
// We could also use one 1 key for multiple domains. // We could also use one 1 key for multiple domains.
import ( import (
"dns" "dns"
"dns/resolver"
"crypto/rsa" "crypto/rsa"
) )
@ -59,17 +58,15 @@ func match(m *dns.Msg, d int) (*dns.Msg, bool) {
return m, true return m, true
} }
func send(m *dns.Msg, ok bool) *dns.Msg { func send(m *dns.Msg, ok bool) (out *dns.Msg) {
switch ok { switch ok {
case true, false: case true, false:
var in resolver.Msg
for _, r := range qr { for _, r := range qr {
r <- resolver.Msg{m, nil, nil} out, _ = r.Query(m)
in = <-r
} }
return in.Dns // return the last return
} }
return nil return
} }
var pubkey *dns.RR_DNSKEY var pubkey *dns.RR_DNSKEY

View File

@ -21,7 +21,7 @@ import (
type server dns.Server type server dns.Server
// Define a slice of channels for the resolver for sending the queries somewhere else. // Define a slice of channels for the resolver for sending the queries somewhere else.
var qr []chan resolver.Msg var qr []*dns.Resolver
// The configuration of Funkensturm // The configuration of Funkensturm
var f *Funkensturm var f *Funkensturm
@ -151,7 +151,7 @@ func doFunkensturm(i []byte) ([]byte, os.Error) {
return out, nil return out, nil
} }
func (s *server) ResponderUDP(c *net.UDPConn, a net.Addr, i []byte) { func (s *server) ReplyUDP(c *net.UDPConn, a net.Addr, i []byte) {
out, err := doFunkensturm(i) out, err := doFunkensturm(i)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err.String()) fmt.Fprintf(os.Stderr, "Error: %s\n", err.String())
@ -159,12 +159,12 @@ func (s *server) ResponderUDP(c *net.UDPConn, a net.Addr, i []byte) {
} }
if out != nil { if out != nil {
responder.SendUDP(out, c, a) dns.SendUDP(out, c, a)
} }
// nothing is send back // nothing is send back
} }
func (s *server) ResponderTCP(c *net.TCPConn, i []byte) { func (s *server) ReplyTCP(c *net.TCPConn, a net.Addr, i []byte) {
out, err := doFunkensturm(i) out, err := doFunkensturm(i)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err.String()) fmt.Fprintf(os.Stderr, "Error: %s\n", err.String())
@ -172,7 +172,7 @@ func (s *server) ResponderTCP(c *net.TCPConn, i []byte) {
} }
if out != nil { if out != nil {
responder.SendTCP(out, c) dns.SendTCP(out, c, a)
} }
// nothing is send back // nothing is send back
} }
@ -197,15 +197,13 @@ func main() {
flag.Parse() flag.Parse()
resolvers := strings.Split(*rserver, ",", -1) resolvers := strings.Split(*rserver, ",", -1)
qr = make([]chan resolver.Msg, len(resolvers)) qr = make([]*dns.Resolver, len(resolvers))
for i, ra := range resolvers { for i, ra := range resolvers {
addr, port := splitAddrPort(ra) addr, port := splitAddrPort(ra)
// TODO error checking r := new(dns.Resolver)
// The resolver(s)
r := new(resolver.Resolver)
r.Servers = []string{addr} r.Servers = []string{addr}
r.Port = port r.Port = port
qr[i] = r.NewQuerier() // connect to global qr[i qr[i] = r
} }
f = funkensturm() f = funkensturm()
@ -215,14 +213,10 @@ func main() {
return return
} }
// The responder // The server
addr, port := splitAddrPort(*sserver)
s := new(responder.Server)
s.Address = addr
s.Port = port
var srv *server var srv *server
rs := make(chan os.Error) quit := make(chan bool)
go s.NewResponder(srv, rs) go dns.ListenAndServe(*sserver, srv, quit)
forever: forever:
for { for {
@ -230,15 +224,9 @@ forever:
select { select {
case <-signal.Incoming: case <-signal.Incoming:
println("Signal received, stopping") println("Signal received, stopping")
rs <- nil // shutdown responder quit <- true
break forever break forever
} }
} }
close(rs) close(quit)
// And the resolvers
for _, q := range qr {
q <- resolver.Msg{}
<-q
}
} }