aboutsummaryrefslogtreecommitdiffstats
path: root/http
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2019-12-28 15:09:30 +0100
committerMartin Polden <mpolden@mpolden.no>2019-12-28 15:09:30 +0100
commit879b6c409aa9510cb27de0bce288ad1ea8b44006 (patch)
treeb7a659f958faf00a93333a72195536467a94ce6a /http
parent57ebed75974685799017552693618d001ae5c8a5 (diff)
Log whether request was hijacked
Diffstat (limited to 'http')
-rw-r--r--http/http.go3
-rw-r--r--http/http_test.go10
2 files changed, 8 insertions, 5 deletions
diff --git a/http/http.go b/http/http.go
index a17fb7c..12d9e31 100644
--- a/http/http.go
+++ b/http/http.go
@@ -25,6 +25,7 @@ type entry struct {
Time string `json:"time"`
TTL int64 `json:"ttl,omitempty"`
RemoteAddr net.IP `json:"remote_addr,omitempty"`
+ Hijacked *bool `json:"hijacked,omitempty"`
Qtype string `json:"type"`
Question string `json:"question"`
Answers []string `json:"answers,omitempty"`
@@ -130,9 +131,11 @@ func (s *Server) logHandler(w http.ResponseWriter, r *http.Request) (interface{}
}
entries := make([]entry, 0, len(logEntries))
for _, le := range logEntries {
+ hijacked := le.Hijacked
entries = append(entries, entry{
Time: le.Time.UTC().Format(time.RFC3339),
RemoteAddr: le.RemoteAddr,
+ Hijacked: &hijacked,
Qtype: dns.TypeToString[le.Qtype],
Question: le.Question,
Answers: le.Answers,
diff --git a/http/http_test.go b/http/http_test.go
index 610f6f8..e964e3b 100644
--- a/http/http_test.go
+++ b/http/http_test.go
@@ -55,17 +55,17 @@ func httpGet(url string) (string, int, error) {
func TestRequests(t *testing.T) {
httpSrv, srv := testServer()
defer httpSrv.Close()
- srv.logger.Record(net.IPv4(127, 0, 0, 42), 1, "example.com.", "192.0.2.100", "192.0.2.101")
- srv.logger.Record(net.IPv4(127, 0, 0, 254), 28, "example.com.", "2001:db8::1")
+ srv.logger.Record(net.IPv4(127, 0, 0, 42), false, 1, "example.com.", "192.0.2.100", "192.0.2.101")
+ srv.logger.Record(net.IPv4(127, 0, 0, 254), true, 28, "example.com.", "2001:db8::1")
srv.cache.Set(1, newA("1.example.com.", 60, net.IPv4(192, 0, 2, 200)))
srv.cache.Set(2, newA("2.example.com.", 30, net.IPv4(192, 0, 2, 201)))
cr1 := `[{"time":"RFC3339","ttl":30,"type":"A","question":"2.example.com.","answers":["192.0.2.201"],"rcode":"NOERROR"},` +
`{"time":"RFC3339","ttl":60,"type":"A","question":"1.example.com.","answers":["192.0.2.200"],"rcode":"NOERROR"}]`
cr2 := `[{"time":"RFC3339","ttl":30,"type":"A","question":"2.example.com.","answers":["192.0.2.201"],"rcode":"NOERROR"}]`
- lr1 := `[{"time":"RFC3339","remote_addr":"127.0.0.254","type":"AAAA","question":"example.com.","answers":["2001:db8::1"]},` +
- `{"time":"RFC3339","remote_addr":"127.0.0.42","type":"A","question":"example.com.","answers":["192.0.2.101","192.0.2.100"]}]`
- lr2 := `[{"time":"RFC3339","remote_addr":"127.0.0.254","type":"AAAA","question":"example.com.","answers":["2001:db8::1"]}]`
+ lr1 := `[{"time":"RFC3339","remote_addr":"127.0.0.254","hijacked":true,"type":"AAAA","question":"example.com.","answers":["2001:db8::1"]},` +
+ `{"time":"RFC3339","remote_addr":"127.0.0.42","hijacked":false,"type":"A","question":"example.com.","answers":["192.0.2.101","192.0.2.100"]}]`
+ lr2 := `[{"time":"RFC3339","remote_addr":"127.0.0.254","hijacked":true,"type":"AAAA","question":"example.com.","answers":["2001:db8::1"]}]`
var tests = []struct {
method string