make the parsing compile - complete unusable atm
This commit is contained in:
parent
5e0315bd58
commit
508103a287
3
Makefile
3
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
|
||||
|
|
29
dns.y
29
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 <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
|
||||
*/
|
||||
%token <ttl> TTL
|
||||
%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
|
||||
|
||||
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
|
||||
}
|
||||
|
|
21
msg.go
21
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
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package strconv
|
||||
package dns
|
||||
|
||||
import ( "testing")
|
||||
|
||||
|
|
Loading…
Reference in New Issue