initial stab at edns update lease http://files.dns-sd.org/draft-sekar-dns-ul.txt
This commit is contained in:
parent
89cb935efe
commit
ec8d3d51d1
|
@ -87,6 +87,7 @@ be build with: `make -C ex`, or also with the `go` tool.
|
||||||
* 5936 - AXFR
|
* 5936 - AXFR
|
||||||
* 6605 - ECDSA
|
* 6605 - ECDSA
|
||||||
* xxxx - URI record (draft)
|
* xxxx - URI record (draft)
|
||||||
|
* xxxx - Dns Update Lease (draft)
|
||||||
|
|
||||||
## Loosely based upon
|
## Loosely based upon
|
||||||
|
|
||||||
|
|
|
@ -99,3 +99,39 @@ func TestClientAXFRMultipleMessages(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// not really a test, but shows how to use update leases
|
||||||
|
func TestUpdateLeaseTSIG(t *testing.T) {
|
||||||
|
m := new(Msg)
|
||||||
|
m.SetUpdate("t.local.ip6.io.")
|
||||||
|
rr, _ := NewRR("t.local.ip6.io. 30 A 127.0.0.1")
|
||||||
|
rrs := make([]RR, 1)
|
||||||
|
rrs[0] = rr
|
||||||
|
m.AddRR(rrs)
|
||||||
|
|
||||||
|
lease_rr := new(RR_OPT)
|
||||||
|
lease_rr.Hdr.Name = "."
|
||||||
|
lease_rr.Hdr.Rrtype = TypeOPT
|
||||||
|
e := new(EDNS0_UPDATE_LEASE)
|
||||||
|
e.Code = EDNS0UPDATELEASE
|
||||||
|
e.Lease = 120
|
||||||
|
lease_rr.Option = append(lease_rr.Option, e)
|
||||||
|
m.Extra = append(m.Extra, lease_rr)
|
||||||
|
|
||||||
|
c := new(Client)
|
||||||
|
m.SetTsig("polvi.", HmacMD5, 300, time.Now().Unix())
|
||||||
|
c.TsigSecret = map[string]string{"polvi.": "pRZgBrBvI4NAHZYhxmhs/Q=="}
|
||||||
|
|
||||||
|
w := new(reply)
|
||||||
|
w.client = c
|
||||||
|
w.addr = "127.0.0.1:53"
|
||||||
|
w.req = m
|
||||||
|
|
||||||
|
if err := w.dial(); err != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
if err := w.send(m); err != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
43
edns.go
43
edns.go
|
@ -73,6 +73,8 @@ func (rr *RR_OPT) String() string {
|
||||||
}
|
}
|
||||||
case *EDNS0_SUBNET:
|
case *EDNS0_SUBNET:
|
||||||
s += "\n; SUBNET: " + o.String()
|
s += "\n; SUBNET: " + o.String()
|
||||||
|
case *EDNS0_UPDATE_LEASE:
|
||||||
|
s += "\n; LEASE: " + o.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
|
@ -278,3 +280,44 @@ func (e *EDNS0_SUBNET) String() (s string) {
|
||||||
s += "/" + strconv.Itoa(int(e.SourceNetmask)) + "/" + strconv.Itoa(int(e.SourceScope))
|
s += "/" + strconv.Itoa(int(e.SourceNetmask)) + "/" + strconv.Itoa(int(e.SourceScope))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The UPDATE_LEASE EDNS0 (draft RFC) option is used to tell the server to set
|
||||||
|
// an expiration on an update RR. This is helpful for clients that cannot clean
|
||||||
|
// up after themselves. This is a draft RFC and more information can be found at
|
||||||
|
// http://files.dns-sd.org/draft-sekar-dns-ul.txt
|
||||||
|
//
|
||||||
|
// o := new(dns.RR_OPT)
|
||||||
|
// o.Hdr.Name = "."
|
||||||
|
// o.Hdr.Rrtype = dns.TypeOPT
|
||||||
|
// e := new(dns.EDNS0_UPDATE_LEASE)
|
||||||
|
// e.Code = dns.EDNS0UPDATELEASE
|
||||||
|
// e.Lease = 120 // in seconds
|
||||||
|
// o.Option = append(o.Option, e)
|
||||||
|
const EDNS0UPDATELEASE = 0x02
|
||||||
|
|
||||||
|
type EDNS0_UPDATE_LEASE struct {
|
||||||
|
Code uint16 // Always EDNS0UPDATELEASE
|
||||||
|
Lease uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *EDNS0_UPDATE_LEASE) Option() uint16 {
|
||||||
|
return EDNS0UPDATELEASE
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied: http://golang.org/src/pkg/net/dnsmsg.go
|
||||||
|
func (e *EDNS0_UPDATE_LEASE) pack() ([]byte, error) {
|
||||||
|
lease_byte := make([]byte, 4)
|
||||||
|
lease_byte[0] = byte(e.Lease >> 24)
|
||||||
|
lease_byte[1] = byte(e.Lease >> 16)
|
||||||
|
lease_byte[2] = byte(e.Lease >> 8)
|
||||||
|
lease_byte[3] = byte(e.Lease)
|
||||||
|
return lease_byte, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *EDNS0_UPDATE_LEASE) unpack(b []byte) {
|
||||||
|
e.Lease = uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *EDNS0_UPDATE_LEASE) String() string {
|
||||||
|
return strconv.Itoa(int(e.Lease))
|
||||||
|
}
|
||||||
|
|
5
msg.go
5
msg.go
|
@ -699,6 +699,11 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, err er
|
||||||
e.unpack(msg[off1 : off1+int(optlen)])
|
e.unpack(msg[off1 : off1+int(optlen)])
|
||||||
edns = append(edns, e)
|
edns = append(edns, e)
|
||||||
off = off1 + int(optlen)
|
off = off1 + int(optlen)
|
||||||
|
case EDNS0UPDATELEASE:
|
||||||
|
e := new(EDNS0_UPDATE_LEASE)
|
||||||
|
e.unpack(msg[off1 : off1+int(optlen)])
|
||||||
|
edns = append(edns, e)
|
||||||
|
off = off1 + int(optlen)
|
||||||
}
|
}
|
||||||
fv.Set(reflect.ValueOf(edns))
|
fv.Set(reflect.ValueOf(edns))
|
||||||
// multiple EDNS codes?
|
// multiple EDNS codes?
|
||||||
|
|
Loading…
Reference in New Issue