Skip to content

Commit

Permalink
mdns: set authoritative bit for mDNS replies (#21108)
Browse files Browse the repository at this point in the history
According to RFC 6762 this bit must be set in multicast messages and is
harmless in unicast messages. The PR also fixes the wrong truncated flag
value.
  • Loading branch information
gjc13 authored and pull[bot] committed Oct 19, 2023
1 parent ebc6cb8 commit 3719830
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib/dnssd/minimal_mdns/ResponseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ResponseBuilder
mBuildOk = false;
}

mHeader.SetFlags(mHeader.GetFlags().SetResponse());
mHeader.SetFlags(mHeader.GetFlags().SetResponse().SetAuthoritative());

mEndianOutput =
chip::Encoding::BigEndian::BufferWriter(mPacket->Start(), mPacket->DataLength() + mPacket->AvailableDataLength());
Expand Down
13 changes: 8 additions & 5 deletions src/lib/dnssd/minimal_mdns/core/DnsHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class BitPackedFlags
bool IsResponse() const { return (mValue & kIsResponseMask) == kIsResponseMask; }
BitPackedFlags & SetResponse() { return SetMask(kIsResponseMask); }

bool IsAuthoritative() const { return (mValue & kAuthoritativeMask) == kAuthoritativeMask; }
BitPackedFlags & SetAuthoritative() { return SetMask(kAuthoritativeMask); }

bool IsTruncated() const { return (mValue & kTruncationMask) != 0; }
BitPackedFlags & SetTruncated(bool value) { return value ? SetMask(kTruncationMask) : ClearMask(kTruncationMask); }

Expand All @@ -79,11 +82,11 @@ class BitPackedFlags
// 1111 1110 0000 0000 = FE0F
// TODO(cecille): need to better document this value. Why is the comment different than the value?
static constexpr uint16_t kMdnsNonIgnoredMask = 0x8E08;

static constexpr uint16_t kIsResponseMask = 0x8000;
static constexpr uint16_t kOpcodeMask = 0x7000;
static constexpr uint16_t kTruncationMask = 0x0400;
static constexpr uint16_t kReturnCodeMask = 0x000F;
static constexpr uint16_t kAuthoritativeMask = 0x0400;
static constexpr uint16_t kIsResponseMask = 0x8000;
static constexpr uint16_t kOpcodeMask = 0x7000;
static constexpr uint16_t kTruncationMask = 0x0200;
static constexpr uint16_t kReturnCodeMask = 0x000F;
};

/**
Expand Down

0 comments on commit 3719830

Please sign in to comment.