mirror of
https://github.com/miekg/dns.git
synced 2025-10-16 20:31:02 +02:00
small updates
This commit is contained in:
parent
98f1f80088
commit
aa7d08bc8a
21
Makefile
21
Makefile
@ -7,18 +7,19 @@ include $(GOROOT)/src/Make.inc
|
|||||||
|
|
||||||
TARG=dns
|
TARG=dns
|
||||||
GOFILES=\
|
GOFILES=\
|
||||||
dns.go\
|
|
||||||
msg.go\
|
|
||||||
types.go\
|
|
||||||
edns.go\
|
|
||||||
tsig.go\
|
|
||||||
dnssec.go\
|
|
||||||
keygen.go\
|
|
||||||
string.go\
|
|
||||||
resolver.go\
|
|
||||||
config.go\
|
config.go\
|
||||||
server.go \
|
dns.go\
|
||||||
|
dnssec.go\
|
||||||
|
edns.go\
|
||||||
|
keygen.go\
|
||||||
|
msg.go\
|
||||||
|
notify.go\
|
||||||
nsec3.go \
|
nsec3.go \
|
||||||
|
resolver.go\
|
||||||
|
server.go \
|
||||||
|
string.go\
|
||||||
|
tsig.go\
|
||||||
|
types.go\
|
||||||
# y.go\
|
# y.go\
|
||||||
|
|
||||||
include $(GOROOT)/src/Make.pkg
|
include $(GOROOT)/src/Make.pkg
|
||||||
|
20
notify.go
Normal file
20
notify.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package dns
|
||||||
|
|
||||||
|
// Create a notify request packet.
|
||||||
|
func (dns *Msg) SetNotifyRequest(z string, class uint16) {
|
||||||
|
dns.MsgHdr.Opcode = OpcodeNotify
|
||||||
|
dns.MsgHdr.Authoritative = true
|
||||||
|
dns.MsgHdr.Id = Id()
|
||||||
|
dns.Question = make([]Question, 1)
|
||||||
|
dns.Question[0] = Question{z, TypeSOA, class}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a notify reply packet.
|
||||||
|
func (dns *Msg) SetNotifyReply(z string, class, id uint16) {
|
||||||
|
dns.MsgHdr.Opcode = OpcodeNotify
|
||||||
|
dns.MsgHdr.Authoritative = true
|
||||||
|
dns.MsgHdr.Response = true
|
||||||
|
dns.MsgHdr.Id = id
|
||||||
|
dns.Question = make([]Question, 1)
|
||||||
|
dns.Question[0] = Question{z, TypeSOA, class}
|
||||||
|
}
|
@ -5,6 +5,7 @@
|
|||||||
// DNS resolver client: see RFC 1035.
|
// DNS resolver client: see RFC 1035.
|
||||||
|
|
||||||
package dns
|
package dns
|
||||||
|
// TODO: refacter this
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@ -31,6 +32,10 @@ type Resolver struct {
|
|||||||
Rrb int // Last used server (for round robin)
|
Rrb int // Last used server (for round robin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (res *Resolver) QueryTSIG(q *Msg, secret *string) (d *Msg, err os.Error) {
|
||||||
|
return nil,nil
|
||||||
|
}
|
||||||
|
|
||||||
// Basic usage pattern for setting up a resolver:
|
// Basic usage pattern for setting up a resolver:
|
||||||
//
|
//
|
||||||
// res := new(Resolver)
|
// res := new(Resolver)
|
||||||
|
85
server.go
85
server.go
@ -11,58 +11,65 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Server struct {
|
||||||
|
ServeUDP func(*net.UDPConn, net.Addr, *Msg) os.Error
|
||||||
|
ServeTCP func(*net.TCPConn, net.Addr, *Msg) os.Error
|
||||||
|
/* notify stuff here? */
|
||||||
|
/* tsig here */
|
||||||
|
}
|
||||||
|
|
||||||
func ServeUDP(l *net.UDPConn, f func(*net.UDPConn, net.Addr, *Msg)) os.Error {
|
func ServeUDP(l *net.UDPConn, f func(*net.UDPConn, net.Addr, *Msg)) os.Error {
|
||||||
for {
|
for {
|
||||||
m := make([]byte, DefaultMsgSize)
|
m := make([]byte, DefaultMsgSize)
|
||||||
n, radd, e := l.ReadFromUDP(m)
|
n, radd, e := l.ReadFromUDP(m)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
m = m[:n]
|
m = m[:n]
|
||||||
msg := new(Msg)
|
msg := new(Msg)
|
||||||
if ! msg.Unpack(m) {
|
if !msg.Unpack(m) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
go f(l, radd, msg)
|
go f(l, radd, msg)
|
||||||
}
|
}
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServeTCP(l *net.TCPListener, f func(*net.TCPConn, net.Addr, *Msg)) os.Error {
|
func ServeTCP(l *net.TCPListener, f func(*net.TCPConn, net.Addr, *Msg)) os.Error {
|
||||||
b := make([]byte, 2)
|
b := make([]byte, 2)
|
||||||
for {
|
for {
|
||||||
c, e := l.AcceptTCP()
|
c, e := l.AcceptTCP()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
n, e := c.Read(b)
|
n, e := c.Read(b)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
length := uint16(b[0])<<8 | uint16(b[1])
|
length := uint16(b[0])<<8 | uint16(b[1])
|
||||||
if length == 0 {
|
if length == 0 {
|
||||||
return &Error{Error: "received nil msg length"}
|
return &Error{Error: "received nil msg length"}
|
||||||
}
|
}
|
||||||
m := make([]byte, length)
|
m := make([]byte, length)
|
||||||
|
|
||||||
n, e = c.Read(m)
|
n, e = c.Read(m)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
i := n
|
i := n
|
||||||
if i < int(length) {
|
if i < int(length) {
|
||||||
n, e = c.Read(m[i:])
|
n, e = c.Read(m[i:])
|
||||||
if e != nil {
|
if e != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
i += n
|
i += n
|
||||||
}
|
}
|
||||||
msg := new(Msg)
|
msg := new(Msg)
|
||||||
if ! msg.Unpack(m) {
|
if !msg.Unpack(m) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
go f(c, c.RemoteAddr(), msg)
|
go f(c, c.RemoteAddr(), msg)
|
||||||
}
|
}
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
@ -76,7 +83,7 @@ func ListenAndServeTCP(addr string, f func(*net.TCPConn, net.Addr, *Msg)) os.Err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ServeTCP(l, f)
|
err = ServeTCP(l, f)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +96,7 @@ func ListenAndServeUDP(addr string, f func(*net.UDPConn, net.Addr, *Msg)) os.Err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ServeUDP(l, f)
|
err = ServeUDP(l, f)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,14 +115,14 @@ func SendTCP(m []byte, c *net.TCPConn, a net.Addr) os.Error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i := n
|
i := n
|
||||||
for i < len(m) {
|
for i < len(m) {
|
||||||
n, err = c.Write(m)
|
n, err = c.Write(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i += n
|
i += n
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user