mirror of
https://github.com/miekg/dns.git
synced 2025-08-12 04:26:58 +02:00
small cleanups
This commit is contained in:
parent
035dc7c1d0
commit
6a75e08368
@ -2,13 +2,12 @@ package main
|
|||||||
|
|
||||||
// This is a transparant proxy config. All recevied pkt are just forwarded to the
|
// 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
|
// nameserver, hardcoded to 127.0.0.1 and then return to the original querier
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"dns"
|
"dns"
|
||||||
"dns/resolver"
|
"dns/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
func matchOpcode(m *dns.Msg, d int) (*dns.Msg, bool) {
|
func match(m *dns.Msg, d int) (*dns.Msg, bool) {
|
||||||
// Matching criteria
|
// Matching criteria
|
||||||
switch d {
|
switch d {
|
||||||
case IN:
|
case IN:
|
||||||
@ -29,7 +28,7 @@ func matchOpcode(m *dns.Msg, d int) (*dns.Msg, bool) {
|
|||||||
return m, true
|
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 {
|
switch ok {
|
||||||
case true, false:
|
case true, false:
|
||||||
qr <- resolver.Msg{m, nil, nil}
|
qr <- resolver.Msg{m, nil, nil}
|
||||||
@ -52,9 +51,9 @@ func funkensturm() *Funkensturm {
|
|||||||
|
|
||||||
f.Matches = make([]Match, 1)
|
f.Matches = make([]Match, 1)
|
||||||
f.Matches[0].Op = AND
|
f.Matches[0].Op = AND
|
||||||
f.Matches[0].Func = matchOpcode
|
f.Matches[0].Func = match
|
||||||
|
|
||||||
f.Actions = make([]Action, 1)
|
f.Actions = make([]Action, 1)
|
||||||
f.Actions[0].Func = actionSend
|
f.Actions[0].Func = send
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
59
_examples/funkensturm/config_proxy.go
Normal file
59
_examples/funkensturm/config_proxy.go
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user