documentation
This commit is contained in:
parent
b37c5b4646
commit
95c1154930
|
@ -293,7 +293,7 @@ func (c *Client) exchangeBuffer(inbuf []byte, a string, outbuf []byte) (n int, w
|
||||||
// Exchange performs an synchronous query. It sends the message m to the address
|
// Exchange performs an synchronous query. It sends the message m to the address
|
||||||
// contained in a and waits for an reply. Basic use pattern with a *Client:
|
// contained in a and waits for an reply. Basic use pattern with a *Client:
|
||||||
//
|
//
|
||||||
// c := NewClient()
|
// c := dns.NewClient()
|
||||||
// in, err := c.Exchange(message, "127.0.0.1:53")
|
// in, err := c.Exchange(message, "127.0.0.1:53")
|
||||||
//
|
//
|
||||||
// See Client.ExchangeFull(...) to get the round trip time.
|
// See Client.ExchangeFull(...) to get the round trip time.
|
||||||
|
@ -305,7 +305,7 @@ func (c *Client) Exchange(m *Msg, a string) (r *Msg, err error) {
|
||||||
// ExchangeFull performs an synchronous query. It sends the message m to the address
|
// ExchangeFull performs an synchronous query. It sends the message m to the address
|
||||||
// contained in a and waits for an reply. Basic use pattern with a *Client:
|
// contained in a and waits for an reply. Basic use pattern with a *Client:
|
||||||
//
|
//
|
||||||
// c := NewClient()
|
// c := dns.NewClient()
|
||||||
// in, rtt, addr, err := c.Exchange(message, "127.0.0.1:53")
|
// in, rtt, addr, err := c.Exchange(message, "127.0.0.1:53")
|
||||||
//
|
//
|
||||||
// The 'addr' return value is superfluous in this case, but it is here to retain symmetry
|
// The 'addr' return value is superfluous in this case, but it is here to retain symmetry
|
||||||
|
|
24
dns.go
24
dns.go
|
@ -17,53 +17,53 @@
|
||||||
// Resource records are native types. They are not stored in wire format.
|
// Resource records are native types. They are not stored in wire format.
|
||||||
// Basic usage pattern for creating a new resource record:
|
// Basic usage pattern for creating a new resource record:
|
||||||
//
|
//
|
||||||
// r := new(RR_TXT)
|
// r := new(dns.RR_TXT)
|
||||||
// r.Hdr = RR_Header{Name: "miek.nl.", Rrtype: TypeMX, Class: ClassINET, Ttl: 3600}
|
// r.Hdr = dns.RR_Header{Name: "miek.nl.", Rrtype: dns.TypeMX, Class: dns.ClassINET, Ttl: 3600}
|
||||||
// r.Pref = 10
|
// r.Pref = 10
|
||||||
// r.Mx = "mx.miek.nl."
|
// r.Mx = "mx.miek.nl."
|
||||||
//
|
//
|
||||||
// Or directly from a string:
|
// Or directly from a string:
|
||||||
//
|
//
|
||||||
// mx, err := NewRR("miek.nl. 3600 IN MX 10 mx.miek.nl.")
|
// mx, err := dns.NewRR("miek.nl. 3600 IN MX 10 mx.miek.nl.")
|
||||||
//
|
//
|
||||||
// Or when the default TTL (3600) and class (IN) suit you:
|
// Or when the default TTL (3600) and class (IN) suit you:
|
||||||
//
|
//
|
||||||
// mx, err := NewRR("miek.nl. MX 10 mx.miek.nl.")
|
// mx, err := dns.NewRR("miek.nl. MX 10 mx.miek.nl.")
|
||||||
//
|
//
|
||||||
// Or even:
|
// Or even:
|
||||||
//
|
//
|
||||||
// mx, err := NewRR("$ORIGIN nl.\nmiek 1H IN MX 10 mx.miek")
|
// mx, err := dns.NewRR("$ORIGIN nl.\nmiek 1H IN MX 10 mx.miek")
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// In the DNS messages are exchanged, these messages contain resource
|
// In the DNS messages are exchanged, these messages contain resource
|
||||||
// records (sets). Use pattern for creating a message:
|
// records (sets). Use pattern for creating a message:
|
||||||
//
|
//
|
||||||
// m := new(Msg)
|
// m := dns.new(Msg)
|
||||||
// m.SetQuestion("miek.nl.", TypeMX)
|
// m.SetQuestion("miek.nl.", dns.TypeMX)
|
||||||
//
|
//
|
||||||
// The message m is now a message with the question section set to ask
|
// The message m is now a message with the question section set to ask
|
||||||
// the MX records for the miek.nl. zone.
|
// the MX records for the miek.nl. zone.
|
||||||
//
|
//
|
||||||
// The following is slightly more verbose, but more flexible:
|
// The following is slightly more verbose, but more flexible:
|
||||||
//
|
//
|
||||||
// m1 := new(Msg)
|
// m1 := new(dns.Msg)
|
||||||
// m1.MsgHdr.Id = Id()
|
// m1.MsgHdr.Id = Id()
|
||||||
// m1.MsgHdr.RecursionDesired = false
|
// m1.MsgHdr.RecursionDesired = false
|
||||||
// m1.Question = make([]Question, 1)
|
// m1.Question = make([]Question, 1)
|
||||||
// m1.Question[0] = Question{"miek.nl.", TypeMX, ClassINET}
|
// m1.Question[0] = dns.Question{"miek.nl.", dns.TypeMX, dns.ClassINET}
|
||||||
//
|
//
|
||||||
// After creating a message it can be send.
|
// After creating a message it can be send.
|
||||||
// Basic use pattern for synchronous querying the DNS at a
|
// Basic use pattern for synchronous querying the DNS at a
|
||||||
// server configured on 127.0.0.1 and port 53:
|
// server configured on 127.0.0.1 and port 53:
|
||||||
//
|
//
|
||||||
// c := NewClient()
|
// c := dns.NewClient()
|
||||||
// in, err := c.Exchange(m1, "127.0.0.1:53")
|
// in, err := c.Exchange(m1, "127.0.0.1:53")
|
||||||
//
|
//
|
||||||
// An asynchronous query is also possible, setting up is more elaborate then
|
// An asynchronous query is also possible, setting up is more elaborate then
|
||||||
// a synchronous query. The Basic use pattern is:
|
// a synchronous query. The Basic use pattern is:
|
||||||
//
|
//
|
||||||
// HandleQuery(".", handler)
|
// dns.HandleQuery(".", handler)
|
||||||
// ListenAndQuery(nil, nil)
|
// dns.ListenAndQuery(nil, nil)
|
||||||
// c.Do(m1, "127.0.0.1:53")
|
// c.Do(m1, "127.0.0.1:53")
|
||||||
// // Do something else
|
// // Do something else
|
||||||
// r := <- DefaultReplyChan
|
// r := <- DefaultReplyChan
|
||||||
|
|
|
@ -14,8 +14,6 @@ import (
|
||||||
|
|
||||||
type Handler interface {
|
type Handler interface {
|
||||||
ServeDNS(w ResponseWriter, r *Msg)
|
ServeDNS(w ResponseWriter, r *Msg)
|
||||||
// IP based ACL mapping. The contains the string representation
|
|
||||||
// of the IP address and a boolean saying it may connect (true) or not.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A ResponseWriter interface is used by an DNS handler to
|
// A ResponseWriter interface is used by an DNS handler to
|
||||||
|
@ -30,7 +28,7 @@ type ResponseWriter interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type conn struct {
|
type conn struct {
|
||||||
remoteAddr net.Addr // address of remote side
|
remoteAddr net.Addr // address of the client
|
||||||
handler Handler // request handler
|
handler Handler // request handler
|
||||||
request []byte // bytes read
|
request []byte // bytes read
|
||||||
_UDP *net.UDPConn // i/o connection if UDP was used
|
_UDP *net.UDPConn // i/o connection if UDP was used
|
||||||
|
@ -113,6 +111,7 @@ func (mux *ServeMux) match(zone string) Handler {
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle adds a handler to the ServeMux for pattern.
|
||||||
func (mux *ServeMux) Handle(pattern string, handler Handler) {
|
func (mux *ServeMux) Handle(pattern string, handler Handler) {
|
||||||
if pattern == "" {
|
if pattern == "" {
|
||||||
panic("dns: invalid pattern " + pattern)
|
panic("dns: invalid pattern " + pattern)
|
||||||
|
@ -120,10 +119,12 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
|
||||||
mux.m[pattern] = handler
|
mux.m[pattern] = handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle adds a handler to the ServeMux for pattern.
|
||||||
func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Msg)) {
|
func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Msg)) {
|
||||||
mux.Handle(pattern, HandlerFunc(handler))
|
mux.Handle(pattern, HandlerFunc(handler))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HandleRemove deregistrars the handler specific for pattern from the ServeMux.
|
||||||
func (mux *ServeMux) HandleRemove(pattern string) {
|
func (mux *ServeMux) HandleRemove(pattern string) {
|
||||||
if pattern == "" {
|
if pattern == "" {
|
||||||
panic("dns: invalid pattern " + pattern)
|
panic("dns: invalid pattern " + pattern)
|
||||||
|
@ -168,7 +169,7 @@ type Server struct {
|
||||||
TsigSecret map[string]string // secret(s) for Tsig map[<zonename>]<base64 secret>
|
TsigSecret map[string]string // secret(s) for Tsig map[<zonename>]<base64 secret>
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenAndServe starts a nameserver on the configured addressin *Server.
|
// ListenAndServe starts a nameserver on the configured address in *Server.
|
||||||
func (srv *Server) ListenAndServe() error {
|
func (srv *Server) ListenAndServe() error {
|
||||||
addr := srv.Addr
|
addr := srv.Addr
|
||||||
if addr == "" {
|
if addr == "" {
|
||||||
|
|
15
tsig.go
15
tsig.go
|
@ -6,11 +6,11 @@
|
||||||
// Basic use pattern when querying with a TSIG name "axfr." and the base64
|
// Basic use pattern when querying with a TSIG name "axfr." and the base64
|
||||||
// secret "so6ZGir4GPAqINNh9U5c3A==":
|
// secret "so6ZGir4GPAqINNh9U5c3A==":
|
||||||
//
|
//
|
||||||
// m := new(Msg)
|
// m := dns.new(Msg)
|
||||||
// c := NewClient()
|
// c := dns.NewClient()
|
||||||
// c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
// c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
||||||
// m.SetQuestion("miek.nl.", TypeMX)
|
// m.SetQuestion("miek.nl.", dns.TypeMX)
|
||||||
// m.SetTsig("axfr.", HmacMD5, 300, time.Now().Unix())
|
// m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
|
||||||
// ...
|
// ...
|
||||||
// // When sending the TSIG RR is calculated and filled in before sending
|
// // When sending the TSIG RR is calculated and filled in before sending
|
||||||
//
|
//
|
||||||
|
@ -19,11 +19,11 @@
|
||||||
// miek.nl. with TSIG key named "axfr." and secret "so6ZGir4GPAqINNh9U5c3A=="
|
// miek.nl. with TSIG key named "axfr." and secret "so6ZGir4GPAqINNh9U5c3A=="
|
||||||
// and using the server 85.223.71.124
|
// and using the server 85.223.71.124
|
||||||
//
|
//
|
||||||
// c := NewClient()
|
// c := dns.NewClient()
|
||||||
// c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
// c.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
|
||||||
// m := New(Msg)
|
// m := new(dns.Msg)
|
||||||
// m.SetAxfr("miek.nl.")
|
// m.SetAxfr("miek.nl.")
|
||||||
// m.SetTsig("axfr.", HmacMD5, 300, time.Now().Unix())
|
// m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
|
||||||
// err := c.XfrReceive(m, "85.223.71.124:53")
|
// err := c.XfrReceive(m, "85.223.71.124:53")
|
||||||
//
|
//
|
||||||
// You can now read the records from the AXFR as they come in. Each envelope is checked with TSIG.
|
// You can now read the records from the AXFR as they come in. Each envelope is checked with TSIG.
|
||||||
|
@ -88,6 +88,7 @@ func (rr *RR_TSIG) Header() *RR_Header {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TSIG has no official presentation format, but this will suffice.
|
// TSIG has no official presentation format, but this will suffice.
|
||||||
|
|
||||||
func (rr *RR_TSIG) String() string {
|
func (rr *RR_TSIG) String() string {
|
||||||
s := "\n;; TSIG PSEUDOSECTION:\n"
|
s := "\n;; TSIG PSEUDOSECTION:\n"
|
||||||
s += rr.Hdr.String() +
|
s += rr.Hdr.String() +
|
||||||
|
|
7
zscan.go
7
zscan.go
|
@ -57,7 +57,7 @@ const (
|
||||||
_EXPECT_DIRINCLUDE // Directive $INCLUDE
|
_EXPECT_DIRINCLUDE // Directive $INCLUDE
|
||||||
)
|
)
|
||||||
|
|
||||||
// ParseError contains the parse error and the location in the io.Reader
|
// ParseError is a parsing error. It contains the parse error and the location in the io.Reader
|
||||||
// where the error occured.
|
// where the error occured.
|
||||||
type ParseError struct {
|
type ParseError struct {
|
||||||
file string
|
file string
|
||||||
|
@ -119,7 +119,7 @@ func ReadRR(q io.Reader, filename string) (RR, error) {
|
||||||
// Basic usage pattern when reading from a string (z) containing the
|
// Basic usage pattern when reading from a string (z) containing the
|
||||||
// zone data:
|
// zone data:
|
||||||
//
|
//
|
||||||
// to := ParseZone(strings.NewReader(z), "", "testzone")
|
// to := dns.ParseZone(strings.NewReader(z), "", "testzone")
|
||||||
// for x := range to {
|
// for x := range to {
|
||||||
// if x.Error != nil {
|
// if x.Error != nil {
|
||||||
// // Do something with x.RR
|
// // Do something with x.RR
|
||||||
|
@ -410,6 +410,7 @@ func parseZone(r io.Reader, origin, f string, t chan Token, include int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func (l lex) _string() string {
|
func (l lex) _string() string {
|
||||||
switch l.value {
|
switch l.value {
|
||||||
case _STRING:
|
case _STRING:
|
||||||
|
@ -435,6 +436,7 @@ func (l lex) _string() string {
|
||||||
}
|
}
|
||||||
return "**"
|
return "**"
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// zlexer scans the sourcefile and returns tokens on the channel c.
|
// zlexer scans the sourcefile and returns tokens on the channel c.
|
||||||
func zlexer(s *scan, c chan lex) {
|
func zlexer(s *scan, c chan lex) {
|
||||||
|
@ -811,6 +813,7 @@ func locCheckEast(token string, longitude uint32) (uint32, bool) {
|
||||||
return longitude, false
|
return longitude, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "Eat" the rest of the "line"
|
||||||
func slurpRemainder(c chan lex, f string) *ParseError {
|
func slurpRemainder(c chan lex, f string) *ParseError {
|
||||||
l := <-c
|
l := <-c
|
||||||
switch l.value {
|
switch l.value {
|
||||||
|
|
Loading…
Reference in New Issue