diff --git a/Makefile b/Makefile index 4a1779d8..b1426861 100644 --- a/Makefile +++ b/Makefile @@ -17,10 +17,11 @@ GOFILES=\ string.go\ y.go\ +include $(GOROOT)/src/Make.pkg + y.go: dns.y goyacc dns.y -include $(GOROOT)/src/Make.pkg all: package gomake -C resolver package diff --git a/dns.y b/dns.y index 1fd92f31..9f684530 100644 --- a/dns.y +++ b/dns.y @@ -1,14 +1,20 @@ +// Copyright Miek Gieben 2011 +// Heavily influenced by the zone-parser from NSD %{ package dns +import ( + "fmt" +) + // A yacc parser for DNS Resource Records contained in strings %} %union { - string string + val string rrtype uint16 class uint16 ttl uint16 @@ -18,16 +24,16 @@ package dns /* * Types known to package dns */ -%token RR_A RR_NS RR_MX RR_CNAME RR_AAAA RR_DNSKEY RR_RRSIG RR_DS +%token Y_A Y_NS /* * Other elements of the Resource Records */ %token TTL %token CLASS -%token STR +%token VAL %% -rr: name TTL CLASS +rr: name TTL CLASS rrtype { }; @@ -35,7 +41,20 @@ rr: name TTL CLASS name: label | name '.' label -label: STR +label: VAL + +rrtype: + /* All supported RR types */ + Y_A + | Y_NS %% type DnsLex int + +func (DnsLex) Lex(yylval *yySymType) int { + + // yylval.rrtype = Str_rr($XX) //give back TypeA, TypeNS + // return Y_A this should be the token, another map? + + return 0 +} diff --git a/msg.go b/msg.go index cbee9fdd..37a21f85 100644 --- a/msg.go +++ b/msg.go @@ -86,13 +86,15 @@ var Rr_str = map[uint16]string{ TypeNSEC: "NSEC", TypeDNSKEY: "DNSKEY", TypeNSEC3: "NSEC3", - TypeNSEC3PARAM: "NSEC3PARAM", - TypeTKEY: "TKEY", - TypeTSIG: "TSIG", - TypeAXFR: "AXFR", // Not real RRs - TypeIXFR: "IXFR", + TypeNSEC3PARAM: "NSEC3PARAM", // DNSSEC's bitch + TypeTKEY: "TKEY", // Meta RR + TypeTSIG: "TSIG", // Meta RR + TypeAXFR: "AXFR", // Meta RR + TypeIXFR: "IXFR", // Meta RR } +// Reverse of Rr_str (needed for parsing) +var Str_rr = reverse(Rr_str) // Map of strings for each RR wire type. var Class_str = map[uint16]string{ @@ -667,7 +669,14 @@ func unpackRR(msg []byte, off int) (rr RR, off1 int, ok bool) { return rr, off, ok } -// Usable representation of a DNS packet. +func reverse(m map[uint16]string) map[string]uint16 { + n := make(map[string]uint16) + for u, s := range m { + n[s] = u + } + return n +} + // Convert a MsgHdr to a string, mimic the way Dig displays headers: //;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48404 diff --git a/ttl_test.go b/ttl_test.go index 821c8731..d2d975b2 100644 --- a/ttl_test.go +++ b/ttl_test.go @@ -1,4 +1,4 @@ -package strconv +package dns import ( "testing")