Add NSAP and NSAP-PTR record

This commit is contained in:
Miek Gieben 2013-10-13 12:25:08 +01:00
parent b7176f84ae
commit 961e137891
6 changed files with 95 additions and 4 deletions

View File

@ -72,6 +72,7 @@ Example programs can be found in the `github.com/miekg/exdns` repository.
*all of them*
* 103{4,5} - DNS standard
* 1348 - NSAP record
* 1982 - Serial Arithmetic
* 1876 - LOC record
* 1995 - IXFR

View File

@ -13,8 +13,6 @@
These are deprecated, or rarely used (or just a bitch to implement).
NSAP
NSAP-PTR
PX
GPOS
NIMLOC

2
msg.go
View File

@ -93,6 +93,8 @@ var TypeToString = map[uint16]string{
TypeWKS: "WKS",
TypeNS: "NS",
TypeNULL: "NULL",
TypeNSAP: "NSAP",
TypeNSAPPTR: "NSAP-PTR",
TypeAFSDB: "AFSDB",
TypeX25: "X25",
TypeISDN: "ISDN",

View File

@ -110,7 +110,7 @@ func TestParseDirectiveMisc(t *testing.T) {
}
}
func TestParseNSEC(t *testing.T) {
func TestNSEC(t *testing.T) {
nsectests := map[string]string{
"nl. IN NSEC3PARAM 1 0 5 30923C44C6CBBB8F": "nl.\t3600\tIN\tNSEC3PARAM\t1 0 5 30923C44C6CBBB8F",
"p2209hipbpnm681knjnu0m1febshlv4e.nl. IN NSEC3 1 1 5 30923C44C6CBBB8F P90DG1KE8QEAN0B01613LHQDG0SOJ0TA NS SOA TXT RRSIG DNSKEY NSEC3PARAM": "p2209hipbpnm681knjnu0m1febshlv4e.nl.\t3600\tIN\tNSEC3\t1 1 5 30923C44C6CBBB8F P90DG1KE8QEAN0B01613LHQDG0SOJ0TA NS SOA TXT RRSIG DNSKEY NSEC3PARAM",
@ -209,7 +209,7 @@ func TestQuotes(t *testing.T) {
}
}
func TestParseBrace(t *testing.T) {
func TestBrace(t *testing.T) {
tests := map[string]string{
"(miek.nl.) 3600 IN A 127.0.1.1": "miek.nl.\t3600\tIN\tA\t127.0.1.1",
"miek.nl. (3600) IN MX (10) elektron.atoom.net.": "miek.nl.\t3600\tIN\tMX\t10 elektron.atoom.net.",
@ -591,6 +591,28 @@ func TestILNP(t *testing.T) {
}
}
func TestNSAP(t *testing.T) {
dt := map[string]string{
"foo.bar.com. IN NSAP 21 47000580ffff000000321099991111222233334444": "foo.bar.com.\t3600\tIN\tNSAP\t21 47000580ffff000000321099991111222233334444",
"host.school.de IN NSAP 17 39276f3100111100002222333344449876": "host.school.de.\t3600\tIN\tNSAP\t17 39276f3100111100002222333344449876",
"444433332222111199990123000000ff. NSAP-PTR foo.bar.com.": "444433332222111199990123000000ff.\t3600\tIN\tNSAP-PTR\tfoo.bar.com.",
}
for i, o := range dt {
rr, e := NewRR(i)
if e != nil {
t.Log("Failed to parse RR: " + e.Error())
t.Fail()
continue
}
if rr.String() != o {
t.Logf("`%s' should be equal to\n`%s', but is `%s'\n", i, o, rr.String())
t.Fail()
} else {
t.Logf("RR is OK: `%s'", rr.String())
}
}
}
func TestComment(t *testing.T) {
// Comments we must see
comments := map[string]bool{"; this is comment 1": true,

View File

@ -46,6 +46,8 @@ const (
TypeX25 uint16 = 19
TypeISDN uint16 = 20
TypeRT uint16 = 21
TypeNSAP uint16 = 22
TypeNSAPPTR uint16 = 23
TypeSIG uint16 = 24
TypeKEY uint16 = 25
TypeAAAA uint16 = 28
@ -1011,6 +1013,27 @@ func (rr *RKEY) len() int {
base64.StdEncoding.DecodedLen(len(rr.PublicKey))
}
type NSAP struct {
Hdr RR_Header
Length uint8
Nsap string
}
func (rr *NSAP) Header() *RR_Header { return &rr.Hdr }
func (rr *NSAP) copy() RR { return &NSAP{*rr.Hdr.copyHeader(), rr.Length, rr.Nsap} }
func (rr *NSAP) String() string { return rr.Hdr.String() + strconv.Itoa(int(rr.Length)) + " " + rr.Nsap }
func (rr *NSAP) len() int { return rr.Hdr.len() + 1 + len(rr.Nsap) }
type NSAPPTR struct {
Hdr RR_Header
Ptr string `dns:"domain-name"`
}
func (rr *NSAPPTR) Header() *RR_Header { return &rr.Hdr }
func (rr *NSAPPTR) copy() RR { return &NSAPPTR{*rr.Hdr.copyHeader(), rr.Ptr} }
func (rr *NSAPPTR) String() string { return rr.Hdr.String() + rr.Ptr }
func (rr *NSAPPTR) len() int { return rr.Hdr.len() + len(rr.Ptr) }
type NSEC3 struct {
Hdr RR_Header
Hash uint8
@ -1504,6 +1527,8 @@ func euiToString(eui uint64, bits int) (hex string) {
var rr_mk = map[uint16]func() RR{
TypeCNAME: func() RR { return new(CNAME) },
TypeHINFO: func() RR { return new(HINFO) },
TypeNSAP: func() RR { return new(NSAP) },
TypeNSAPPTR: func() RR { return new(NSAPPTR) },
TypeMB: func() RR { return new(MB) },
TypeMG: func() RR { return new(MG) },
TypeMD: func() RR { return new(MD) },

View File

@ -122,9 +122,14 @@ func setRR(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
case TypeLOC:
r, e = setLOC(h, c, f)
goto Slurp
case TypeNSAPPTR:
r, e = setNSAPPTR(h, c, o, f)
goto Slurp
// These types have a variable ending: either chunks of txt or chunks/base64 or hex.
// They need to search for the end of the RR themselves, hence they look for the ending
// newline. Thus there is no need to slurp the remainder, because there is none.
case TypeNSAP:
return setNSAP(h, c, f)
case TypeDNSKEY:
return setDNSKEY(h, c, f)
case TypeRKEY:
@ -301,6 +306,26 @@ func setPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
return rr, nil
}
func setNSAPPTR(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
rr := new(NSAPPTR)
rr.Hdr = h
l := <-c
rr.Ptr = l.token
if l.token == "@" {
rr.Ptr = o
return rr, nil
}
_, ok := IsDomainName(l.token)
if !ok {
return nil, &ParseError{f, "bad NSAP-PTR Ptr", l}
}
if rr.Ptr[l.length-1] != '.' {
rr.Ptr = appendOrigin(rr.Ptr, o)
}
return rr, nil
}
func setRP(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
rr := new(RP)
rr.Hdr = h
@ -1530,6 +1555,24 @@ func setDS(h RR_Header, c chan lex, f string) (RR, *ParseError, string) {
return rr, nil, c1
}
func setNSAP(h RR_Header, c chan lex, f string) (RR, *ParseError, string) {
rr := new(NSAP)
rr.Hdr = h
l := <-c
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad NSAP Length", l}, ""
} else {
rr.Length = uint8(i)
}
<-c // _BLANK
s, e, c1 := endingToString(c, "bad NSAP Nsap", f)
if e != nil {
return nil, e, c1
}
rr.Nsap = s
return rr, nil, c1
}
func setCDS(h RR_Header, c chan lex, f string) (RR, *ParseError, string) {
rr := new(CDS)
rr.Hdr = h