-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUGFIX] do not break when TCP DNS answer exceeds 64k #3948
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
be39fb2
[BUGFIX] do not break when TCP DNS answer exceeds 64k
pierresouchay b77fd5c
64000 max limit to DNS messages since there is overhead
pierresouchay 7d59249
Avoid issue with compression of DNS messages causing overflow
pierresouchay ce3f47a
Performance optimization for services having more than 2k records
pierresouchay d0e45f2
Fixed wrong format of debug msg in unit test
pierresouchay 93fa1f6
Optimize size for SRV records, should improve performance a bit
pierresouchay aebfcb6
Fixed minor typo (+ travis tests is unstable)
pierresouchay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2740,6 +2740,97 @@ func TestDNS_ServiceLookup_Randomize(t *testing.T) { | |
} | ||
} | ||
|
||
func TestDNS_TCP_and_UDP_Truncate(t *testing.T) { | ||
t.Parallel() | ||
a := NewTestAgent(t.Name(), ` | ||
dns_config { | ||
enable_truncate = true | ||
} | ||
`) | ||
defer a.Shutdown() | ||
|
||
services := []string{"normal", "truncated"} | ||
for index, service := range services { | ||
numServices := (index * 5000) + 2 | ||
for i := 1; i < numServices; i++ { | ||
args := &structs.RegisterRequest{ | ||
Datacenter: "dc1", | ||
Node: fmt.Sprintf("%s-%d.acme.com", service, i), | ||
Address: fmt.Sprintf("127.%d.%d.%d", index, (i / 255), i%255), | ||
Service: &structs.NodeService{ | ||
Service: service, | ||
Port: 8000, | ||
}, | ||
} | ||
|
||
var out struct{} | ||
if err := a.RPC("Catalog.Register", args, &out); err != nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
} | ||
|
||
// Register an equivalent prepared query. | ||
var id string | ||
{ | ||
args := &structs.PreparedQueryRequest{ | ||
Datacenter: "dc1", | ||
Op: structs.PreparedQueryCreate, | ||
Query: &structs.PreparedQuery{ | ||
Name: service, | ||
Service: structs.ServiceQuery{ | ||
Service: service, | ||
}, | ||
}, | ||
} | ||
if err := a.RPC("PreparedQuery.Apply", args, &id); err != nil { | ||
t.Fatalf("err: %v", err) | ||
} | ||
} | ||
|
||
// Look up the service directly and via prepared query. Ensure the | ||
// response is truncated each time. | ||
questions := []string{ | ||
fmt.Sprintf("%s.service.consul.", service), | ||
id + ".query.consul.", | ||
} | ||
protocols := []string{ | ||
"tcp", | ||
"udp", | ||
} | ||
for _, qType := range []uint16{dns.TypeANY, dns.TypeA, dns.TypeSRV} { | ||
for _, question := range questions { | ||
for _, protocol := range protocols { | ||
for _, compress := range []bool{true, false} { | ||
t.Run(fmt.Sprintf("lookup %s %s (qType:=%d) compressed=%v", question, protocol, qType, compress), func(t *testing.T) { | ||
m := new(dns.Msg) | ||
m.SetQuestion(question, dns.TypeANY) | ||
if protocol == "udp" { | ||
m.SetEdns0(8192, true) | ||
} | ||
c := new(dns.Client) | ||
c.Net = protocol | ||
m.Compress = compress | ||
in, out, err := c.Exchange(m, a.DNSAddr()) | ||
if err != nil && err != dns.ErrTruncated { | ||
t.Fatalf("err: %v", err) | ||
} | ||
|
||
// Check for the truncate bit | ||
shouldBeTruncated := numServices > 4095 | ||
|
||
if shouldBeTruncated != in.Truncated { | ||
info := fmt.Sprintf("service %s question:=%s (%s) (%d total records) in %v", | ||
service, question, protocol, numServices, out) | ||
t.Fatalf("Should have truncate:=%v for %s", shouldBeTruncated, info) | ||
} | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also verify that the size of the answer is as expected when it was truncated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DONE |
||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestDNS_ServiceLookup_Truncate(t *testing.T) { | ||
t.Parallel() | ||
a := NewTestAgent(t.Name(), ` | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to apply the right max for SRV records, you can get that from the Qtype field
req.Question[0].Qtype == dns.TypeSRV
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DONE