From 9bee591bc0cd7251e69c75993e15a606bc2824ba Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 31 Jul 2011 16:09:48 +0200 Subject: [PATCH] Make Funkensturm somewhat better --- _examples/funkensturm/config_rproxy.go | 5 ++++- _examples/funkensturm/funkensturm.go | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/_examples/funkensturm/config_rproxy.go b/_examples/funkensturm/config_rproxy.go index d0ae5fe2..149f871f 100644 --- a/_examples/funkensturm/config_rproxy.go +++ b/_examples/funkensturm/config_rproxy.go @@ -55,7 +55,9 @@ func (c Cache) lookup(q *dns.Msg) []byte { if im, ok := c[q.Question[0].Name]; ok { // we have the name if d, ok := im[i]; ok { - return d + e := make([]byte, len(d)) + copy(e, d) + return e } } return nil @@ -73,6 +75,7 @@ func checkcache(m *dns.Msg, ok bool) (o []byte) { o[1] = byte(m.MsgHdr.Id) return } + println("Cache miss") var p *dns.Msg // nothing found for _, c := range qr { diff --git a/_examples/funkensturm/funkensturm.go b/_examples/funkensturm/funkensturm.go index 9deca8dc..a64939ef 100644 --- a/_examples/funkensturm/funkensturm.go +++ b/_examples/funkensturm/funkensturm.go @@ -99,15 +99,17 @@ func doFunkensturm(pkt *dns.Msg) ([]byte, os.Error) { // change is cumulative. ok, ok1 := true, true pkt1 := pkt - for _, m := range f.Matches { - pkt1, ok1 = m.Func(pkt1, IN) - switch m.Op { - case AND: - ok = ok && ok1 - case OR: - ok = ok || ok1 - } - } + if len(f.Matches) > 0 { + for _, m := range f.Matches { + pkt1, ok1 = m.Func(pkt1, IN) + switch m.Op { + case AND: + ok = ok && ok1 + case OR: + ok = ok || ok1 + } + } + } if *verbose { //modified verboseprint(pkt1, ">> ") }