small cleanups

This commit is contained in:
Miek Gieben 2011-01-22 11:23:58 +01:00
parent 035dc7c1d0
commit 6a75e08368
2 changed files with 63 additions and 5 deletions

View File

@ -2,13 +2,12 @@ package main
// This is a transparant proxy config. All recevied pkt are just forwarded to the
// nameserver, hardcoded to 127.0.0.1 and then return to the original querier
import (
"dns"
"dns/resolver"
)
func matchOpcode(m *dns.Msg, d int) (*dns.Msg, bool) {
func match(m *dns.Msg, d int) (*dns.Msg, bool) {
// Matching criteria
switch d {
case IN:
@ -29,7 +28,7 @@ func matchOpcode(m *dns.Msg, d int) (*dns.Msg, bool) {
return m, true
}
func actionSend(m *dns.Msg, ok bool) (*dns.Msg, bool) {
func send(m *dns.Msg, ok bool) (*dns.Msg, bool) {
switch ok {
case true, false:
qr <- resolver.Msg{m, nil, nil}
@ -52,9 +51,9 @@ func funkensturm() *Funkensturm {
f.Matches = make([]Match, 1)
f.Matches[0].Op = AND
f.Matches[0].Func = matchOpcode
f.Matches[0].Func = match
f.Actions = make([]Action, 1)
f.Actions[0].Func = actionSend
f.Actions[0].Func = send
return f
}

View File

@ -0,0 +1,59 @@
package main
// This is a transparant proxy config. All recevied pkt are just forwarded to the
// nameserver, hardcoded to 127.0.0.1 and then return to the original querier
import (
"dns"
"dns/resolver"
)
func match(m *dns.Msg, d int) (*dns.Msg, bool) {
// Matching criteria
switch d {
case IN:
// nothing
case OUT:
// Note that when sending back only the mangling is important
// the actual return code of these function isn't checked by
// funkensturm
}
// Packet Mangling functions
switch d {
case IN:
// nothing
case OUT:
// nothing
}
return m, true
}
func send(m *dns.Msg, ok bool) (*dns.Msg, bool) {
switch ok {
case true, false:
qr <- resolver.Msg{m, nil, nil}
in := <-qr
return in.Dns, true
}
return nil, false // Bug in Go, yes BUG IN GO
}
// qr is global and started by Funkensturm. If you
// need 2 or more resolvers, you'll need to start
// them yourself. This needs to be a global variable
//var qr1 chan resolver.Msg
// Return the configration
func funkensturm() *Funkensturm {
f := new(Funkensturm)
f.Setup = func() bool { return true }
f.Matches = make([]Match, 1)
f.Matches[0].Op = AND
f.Matches[0].Func = match
f.Actions = make([]Action, 1)
f.Actions[0].Func = send
return f
}