Skip to content

Commit

Permalink
preserve upstream truncation state
Browse files Browse the repository at this point in the history
  • Loading branch information
timcharper committed Aug 26, 2016
1 parent b086677 commit 60bc1f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,10 @@ func truncate(m *dns.Msg, udp bool) *dns.Msg {
max = int(opt.UDPSize())
}

m.Truncated = m.Len() > max
if !m.Truncated {
furtherTruncation := m.Len() > max
m.Truncated = m.Truncated || furtherTruncation

if !furtherTruncation {
return m
}

Expand Down
13 changes: 11 additions & 2 deletions resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,17 +418,26 @@ func TestMultiError(t *testing.T) {
}

func TestTruncate(t *testing.T) {
tm := newTruncated()
tm := *newTruncated()
if !tm.Truncated {
t.Fatal("Message not truncated")
}
if l := tm.Len(); l > 512 {
t.Fatalf("Message to large: %d bytes", l)
t.Fatalf("Message too large: %d bytes", l)
}
tm2 := *truncate(&tm, true)
if !tm2.Truncated {
t.Fatal("Original truncation status was not preseved")
}
if tm2.Len() != tm.Len() {
t.Fatal("Further modification to already truncated message")
}

tm.Answer = append(tm.Answer, genA(1)...)
if l := tm.Len(); l < 512 {
t.Fatalf("Message to small after adding answers: %d bytes", l)
}

}

func BenchmarkTruncate(b *testing.B) {
Expand Down

0 comments on commit 60bc1f5

Please sign in to comment.