make the parsing compile - complete unusable atm

This commit is contained in:
Miek Gieben 2011-01-15 14:40:54 +01:00
parent 5e0315bd58
commit 508103a287
4 changed files with 42 additions and 13 deletions

View File

@ -17,10 +17,11 @@ GOFILES=\
string.go\ string.go\
y.go\ y.go\
include $(GOROOT)/src/Make.pkg
y.go: dns.y y.go: dns.y
goyacc dns.y goyacc dns.y
include $(GOROOT)/src/Make.pkg
all: package all: package
gomake -C resolver package gomake -C resolver package

29
dns.y
View File

@ -1,14 +1,20 @@
// Copyright Miek Gieben 2011
// Heavily influenced by the zone-parser from NSD
%{ %{
package dns package dns
import (
"fmt"
)
// A yacc parser for DNS Resource Records contained in strings // A yacc parser for DNS Resource Records contained in strings
%} %}
%union { %union {
string string val string
rrtype uint16 rrtype uint16
class uint16 class uint16
ttl uint16 ttl uint16
@ -18,16 +24,16 @@ package dns
/* /*
* Types known to package dns * Types known to package dns
*/ */
%token <rrtype> RR_A RR_NS RR_MX RR_CNAME RR_AAAA RR_DNSKEY RR_RRSIG RR_DS %token <rrtype> Y_A Y_NS
/* /*
* Other elements of the Resource Records * Other elements of the Resource Records
*/ */
%token <ttl> TTL %token <ttl> TTL
%token <class> CLASS %token <class> CLASS
%token <string> STR %token <val> VAL
%% %%
rr: name TTL CLASS rr: name TTL CLASS rrtype
{ {
}; };
@ -35,7 +41,20 @@ rr: name TTL CLASS
name: label name: label
| name '.' label | name '.' label
label: STR label: VAL
rrtype:
/* All supported RR types */
Y_A
| Y_NS
%% %%
type DnsLex int 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
}

21
msg.go
View File

@ -86,13 +86,15 @@ var Rr_str = map[uint16]string{
TypeNSEC: "NSEC", TypeNSEC: "NSEC",
TypeDNSKEY: "DNSKEY", TypeDNSKEY: "DNSKEY",
TypeNSEC3: "NSEC3", TypeNSEC3: "NSEC3",
TypeNSEC3PARAM: "NSEC3PARAM", TypeNSEC3PARAM: "NSEC3PARAM", // DNSSEC's bitch
TypeTKEY: "TKEY", TypeTKEY: "TKEY", // Meta RR
TypeTSIG: "TSIG", TypeTSIG: "TSIG", // Meta RR
TypeAXFR: "AXFR", // Not real RRs TypeAXFR: "AXFR", // Meta RR
TypeIXFR: "IXFR", 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. // Map of strings for each RR wire type.
var Class_str = map[uint16]string{ 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 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: // Convert a MsgHdr to a string, mimic the way Dig displays headers:
//;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48404 //;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48404

View File

@ -1,4 +1,4 @@
package strconv package dns
import ( "testing") import ( "testing")