Skip to content
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

dns: don't respond with FORMERR if message has ID 0 #35129

Merged
merged 6 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ minor_behavior_changes:

bug_fixes:
# *Changes expected to improve the state of the world and are unlikely to have negative effects*
- area: dns
change: |
The DNS filter no longer returns FORMERR if a message has an ID of 0.

removed_config_or_runtime:
# *Normally occurs at the end of the* :ref:`deprecation period <deprecated>`
Expand Down
4 changes: 0 additions & 4 deletions source/extensions/filters/udp/dns_filter/dns_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,6 @@ bool DnsMessageParser::parseDnsObject(DnsQueryContextPtr& context,
}

context->id_ = static_cast<uint16_t>(context->header_.id);
if (context->id_ == 0) {
ENVOY_LOG(debug, "No ID in DNS query");
return false;
}

// Almost always, we will have only one query here. Per the RFC, QDCOUNT is usually 1
context->queries_.reserve(context->header_.questions);
Expand Down
9 changes: 4 additions & 5 deletions test/extensions/filters/udp/dns_filter/dns_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1863,12 +1863,11 @@ TEST_F(DnsFilterTest, NotImplementedQueryTest) {
EXPECT_EQ(0, config_->stats().downstream_rx_invalid_queries_.value());
}

TEST_F(DnsFilterTest, NoTransactionIdTest) {
TEST_F(DnsFilterTest, ZeroTransactionIdTest) {
InSequence s;

setup(forward_query_off_config);
// This buffer has an invalid Transaction ID. We should return an error
// to the client
// This buffer has a Transaction ID of zero. This is not an error.
constexpr char dns_request[] = {
0x00, 0x00, // Transaction ID
0x01, 0x20, // Flags
Expand All @@ -1888,8 +1887,8 @@ TEST_F(DnsFilterTest, NoTransactionIdTest) {
sendQueryFromClient("10.0.0.1:1000", query);

response_ctx_ = ResponseValidator::createResponseContext(udp_response_, counters_);
EXPECT_FALSE(response_ctx_->parse_status_);
EXPECT_EQ(DNS_RESPONSE_CODE_FORMAT_ERROR, response_ctx_->getQueryResponseCode());
EXPECT_TRUE(response_ctx_->parse_status_);
EXPECT_EQ(DNS_RESPONSE_CODE_NOT_IMPLEMENTED, response_ctx_->getQueryResponseCode());
}

TEST_F(DnsFilterTest, InvalidShortBufferTest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ bool DnsResponseValidator::validateDnsResponseObject(DnsQueryContextPtr& context
}

context->id_ = static_cast<uint16_t>(context->header_.id);
if (context->id_ == 0) {
ENVOY_LOG(debug, "No ID in DNS Response");
return false;
}

// Almost always, we will have only one query here. Per the RFC, QDCOUNT is usually 1
context->queries_.reserve(context->header_.questions);
Expand Down