Delaying pkt is working
This commit is contained in:
parent
52c9c3f15e
commit
5ba0733e31
|
@ -4,7 +4,7 @@
|
|||
include $(GOROOT)/src/Make.inc
|
||||
TARG=funkensturm
|
||||
GOFILES=funkensturm.go\
|
||||
config_sign.go\
|
||||
config_delay.go\
|
||||
|
||||
DEPS=../../
|
||||
include $(GOROOT)/src/Make.cmd
|
||||
|
|
|
@ -3,7 +3,7 @@ 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 (
|
||||
"fmt"
|
||||
"fmt"
|
||||
"dns"
|
||||
"dns/resolver"
|
||||
)
|
||||
|
|
|
@ -4,19 +4,38 @@ package main
|
|||
// nameserver, hardcoded to 127.0.0.1 and then return to the original querier
|
||||
import (
|
||||
"dns"
|
||||
"time"
|
||||
"dns/resolver"
|
||||
)
|
||||
|
||||
const (
|
||||
DELAY = 0.5 * 1e9 // half second
|
||||
)
|
||||
|
||||
var previous int64 // previous tick
|
||||
// Check the delay
|
||||
func checkDelay(nsecDelay int64) (ti int64, limitok bool) {
|
||||
current := time.Nanoseconds()
|
||||
tdiff := (current - previous)
|
||||
println("tdiff", tdiff)
|
||||
println("nsec", nsecDelay)
|
||||
if tdiff < nsecDelay {
|
||||
// too often
|
||||
return previous, false
|
||||
}
|
||||
return current, true
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
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 {
|
||||
|
@ -28,32 +47,40 @@ func match(m *dns.Msg, d int) (*dns.Msg, bool) {
|
|||
return m, true
|
||||
}
|
||||
|
||||
func send(m *dns.Msg, ok bool) (*dns.Msg, bool) {
|
||||
func delay(m *dns.Msg, ok bool) (*dns.Msg, bool) {
|
||||
var ok1 bool
|
||||
switch ok {
|
||||
case true, false:
|
||||
case true:
|
||||
previous, ok1 = checkDelay(DELAY)
|
||||
if !ok1 {
|
||||
println("dropping: too often")
|
||||
time.Sleep(DELAY)
|
||||
return nil, false
|
||||
} else {
|
||||
println("Ok: continue")
|
||||
qr <- resolver.Msg{m, nil, nil}
|
||||
in := <-qr
|
||||
return in.Dns, true
|
||||
}
|
||||
case false:
|
||||
qr <- resolver.Msg{m, nil, nil}
|
||||
in := <-qr
|
||||
return in.Dns, true
|
||||
}
|
||||
return nil, false // Bug in Go, yes BUG IN GO
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// 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.Setup = func() bool { previous = time.Nanoseconds(); 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
|
||||
f.Actions[0].Func = delay
|
||||
return f
|
||||
}
|
||||
|
|
|
@ -79,12 +79,13 @@ func (s *server) ResponderUDP(c *net.UDPConn, a net.Addr, i []byte) {
|
|||
}
|
||||
|
||||
// Loop through the Actions.Func* and do something with the
|
||||
// packet. Note there can only be one return packet. Intermidate
|
||||
// action function should return nil, to signal ... bla bla
|
||||
// packet. Note there can only be one returned packet.
|
||||
// We use 'ok' to signal what the above match did, true or false
|
||||
var resultpkt *dns.Msg
|
||||
for _, a := range f.Actions {
|
||||
resultpkt, ok1 = a.Func(pkt1, ok)
|
||||
}
|
||||
// what to do with the bool??
|
||||
|
||||
// loop again for matching, but now with OUT, this is done
|
||||
// for some last minute packet changing. Note the boolean return
|
||||
|
@ -95,6 +96,9 @@ func (s *server) ResponderUDP(c *net.UDPConn, a net.Addr, i []byte) {
|
|||
pkt1, _ = m.Func(pkt1, OUT)
|
||||
}
|
||||
|
||||
if pkt1 == nil {
|
||||
return
|
||||
}
|
||||
out, ok1 := pkt1.Pack()
|
||||
if !ok1 {
|
||||
println("Failed to pack")
|
||||
|
|
Loading…
Reference in New Issue