From 1e58ea2d5fcd05086845cc245bc9764d2eec49d5 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Tue, 7 Aug 2012 08:28:56 +0200 Subject: [PATCH] more sane logging --- ex/fksd/config.go | 20 ++++++++++---------- ex/fksd/log.go | 11 +++++++++++ ex/fksd/main.go | 2 +- ex/fksd/serve.go | 5 +---- msg.go | 1 + 5 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 ex/fksd/log.go diff --git a/ex/fksd/config.go b/ex/fksd/config.go index 28189592..b93396ca 100644 --- a/ex/fksd/config.go +++ b/ex/fksd/config.go @@ -2,7 +2,6 @@ package main import ( "dns" - "log" "strings" ) @@ -24,10 +23,15 @@ func config(w dns.ResponseWriter, req *dns.Msg, c *Config) { // SUBSYSTEM. IN TXT "OPERATIONOPTIONS..." // ZONE. IN TXT "READ origin /z/bloep" - absolute path in fs - // TODO: check tsig - if *l { - log.Printf("fksd: config commmand") + if !req.IsUpdate() { + logPrintf("non config command") + m := new(dns.Msg) + w.Write(m.SetRcode(req, dns.RcodeFormatError)) + return } + + // TODO: check tsig + logPrintf("config commmand") for _, rr := range req.Ns { t, ok := rr.(*dns.RR_TXT) @@ -53,13 +57,9 @@ func configZONE(t *dns.RR_TXT, c *Config) error { } switch strings.ToUpper(sx[0]) { case "READ": - if *l { - log.Printf("fksd: config: READ %s %s\n", dns.Fqdn(sx[1]), sx[2]) - } + logPrintf("config: READ %s %s\n", dns.Fqdn(sx[1]), sx[2]) if e := c.ReadZone(dns.Fqdn(sx[1]), sx[2]); e != nil { - if *l { - log.Printf("fksd: failed to read %s: %s\n", sx[2], e.Error()) - } + logPrintf("failed to read %s: %s\n", sx[2], e.Error()) return e } return nil diff --git a/ex/fksd/log.go b/ex/fksd/log.go new file mode 100644 index 00000000..f47e3bdb --- /dev/null +++ b/ex/fksd/log.go @@ -0,0 +1,11 @@ +package main + +import "log" + +const NAME = "fksd: " + +func logPrintf(format string, a ...interface{}) { + if *l { + log.Printf(NAME + format, a...) + } +} diff --git a/ex/fksd/main.go b/ex/fksd/main.go index 16204e56..e1b716d7 100644 --- a/ex/fksd/main.go +++ b/ex/fksd/main.go @@ -34,7 +34,7 @@ forever: for { select { case <-sig: - log.Printf("fksd: signal received, stopping\n") + logPrintf("signal received, stopping") break forever } } diff --git a/ex/fksd/serve.go b/ex/fksd/serve.go index b5f96a4e..7a27ea32 100644 --- a/ex/fksd/serve.go +++ b/ex/fksd/serve.go @@ -2,7 +2,6 @@ package main import ( "dns" - "log" ) // Create skeleton edns opt RR from the query and @@ -21,9 +20,7 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) { if z == nil { panic("fksd: no zone") } - if *l { - log.Printf("fksd: [zone %s] incoming %s %s %d from %s\n", z.Origin, req.Question[0].Name, dns.Rr_str[req.Question[0].Qtype], req.MsgHdr.Id, w.RemoteAddr()) - } + logPrintf("[zone %s] incoming %s %s %d from %s\n", z.Origin, req.Question[0].Name, dns.Rr_str[req.Question[0].Qtype], req.MsgHdr.Id, w.RemoteAddr()) // Ds Handling // Referral // if we find something with NonAuth = true, it means diff --git a/msg.go b/msg.go index 5f958443..19175b26 100644 --- a/msg.go +++ b/msg.go @@ -81,6 +81,7 @@ type Msg struct { MsgHdr Compress bool // If true, the message will be compressed when converted to wire format. Size int // Number of octects in the message received from the wire. + // Remote addr? back Question []Question // Holds the RR(s) of the question section. Answer []RR // Holds the RR(s) of the answer section. Ns []RR // Holds the RR(s) of the authority section.