diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-05-07 23:58:46 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-10 17:26:17 +0200 |
commit | 6e70888315f592aee793d9b64207b48142accb44 (patch) | |
tree | d995e6c981fcd6ee95ba4609b70046bf826ca295 /Userland | |
parent | 233a9554a5abfcd485322fc5f95c531ca3f13bcc (diff) | |
download | serenity-6e70888315f592aee793d9b64207b48142accb44.zip |
LookupServer: Split mDNS flags into separate field
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Services/LookupServer/DNSAnswer.cpp | 3 | ||||
-rw-r--r-- | Userland/Services/LookupServer/DNSAnswer.h | 7 | ||||
-rw-r--r-- | Userland/Services/LookupServer/DNSPacket.cpp | 12 | ||||
-rw-r--r-- | Userland/Services/LookupServer/DNSQuestion.h | 8 | ||||
-rw-r--r-- | Userland/Services/LookupServer/LookupServer.cpp | 7 | ||||
-rw-r--r-- | Userland/Services/LookupServer/MulticastDNS.cpp | 7 |
6 files changed, 31 insertions, 13 deletions
diff --git a/Userland/Services/LookupServer/DNSAnswer.cpp b/Userland/Services/LookupServer/DNSAnswer.cpp index d089d04732..167361ac3e 100644 --- a/Userland/Services/LookupServer/DNSAnswer.cpp +++ b/Userland/Services/LookupServer/DNSAnswer.cpp @@ -9,12 +9,13 @@ namespace LookupServer { -DNSAnswer::DNSAnswer(const DNSName& name, u16 type, u16 class_code, u32 ttl, const String& record_data) +DNSAnswer::DNSAnswer(const DNSName& name, u16 type, u16 class_code, u32 ttl, const String& record_data, bool mdns_cache_flush) : m_name(name) , m_type(type) , m_class_code(class_code) , m_ttl(ttl) , m_record_data(record_data) + , m_mdns_cache_flush(mdns_cache_flush) { auto now = time(nullptr); m_expiration_time = now + m_ttl; diff --git a/Userland/Services/LookupServer/DNSAnswer.h b/Userland/Services/LookupServer/DNSAnswer.h index c73a9f6a1f..d5dffe597c 100644 --- a/Userland/Services/LookupServer/DNSAnswer.h +++ b/Userland/Services/LookupServer/DNSAnswer.h @@ -12,15 +12,19 @@ namespace LookupServer { +#define MDNS_CACHE_FLUSH 0x8000 + class DNSAnswer { public: - DNSAnswer(const DNSName& name, u16 type, u16 class_code, u32 ttl, const String& record_data); + DNSAnswer(const DNSName& name, u16 type, u16 class_code, u32 ttl, const String& record_data, bool mdns_cache_flush); const DNSName& name() const { return m_name; } u16 type() const { return m_type; } u16 class_code() const { return m_class_code; } + u16 raw_class_code() const { return m_class_code | (m_mdns_cache_flush ? MDNS_CACHE_FLUSH : 0); } u32 ttl() const { return m_ttl; } const String& record_data() const { return m_record_data; } + bool mdns_cache_flush() const { return m_mdns_cache_flush; } bool has_expired() const; @@ -31,6 +35,7 @@ private: u32 m_ttl { 0 }; time_t m_expiration_time { 0 }; String m_record_data; + bool m_mdns_cache_flush { false }; }; } diff --git a/Userland/Services/LookupServer/DNSPacket.cpp b/Userland/Services/LookupServer/DNSPacket.cpp index e005a6ac9a..8cec959856 100644 --- a/Userland/Services/LookupServer/DNSPacket.cpp +++ b/Userland/Services/LookupServer/DNSPacket.cpp @@ -56,12 +56,12 @@ ByteBuffer DNSPacket::to_byte_buffer() const for (auto& question : m_questions) { stream << question.name(); stream << htons(question.record_type()); - stream << htons(question.class_code()); + stream << htons(question.raw_class_code()); } for (auto& answer : m_answers) { stream << answer.name(); stream << htons(answer.type()); - stream << htons(answer.class_code()); + stream << htons(answer.raw_class_code()); stream << htonl(answer.ttl()); if (answer.type() == T_PTR) { DNSName name { answer.record_data() }; @@ -129,7 +129,9 @@ Optional<DNSPacket> DNSPacket::from_raw_packet(const u8* raw_data, size_t raw_si NetworkOrdered<u16> class_code; }; auto& record_and_class = *(const RawDNSAnswerQuestion*)&raw_data[offset]; - packet.m_questions.empend(name, record_and_class.record_type, record_and_class.class_code); + u16 class_code = record_and_class.class_code & ~MDNS_WANTS_UNICAST_RESPONSE; + bool mdns_wants_unicast_response = record_and_class.class_code & MDNS_WANTS_UNICAST_RESPONSE; + packet.m_questions.empend(name, record_and_class.record_type, class_code, mdns_wants_unicast_response); offset += 4; auto& question = packet.m_questions.last(); dbgln_if(LOOKUPSERVER_DEBUG, "Question #{}: name=_{}_, type={}, class={}", i, question.name(), question.record_type(), question.class_code()); @@ -154,7 +156,9 @@ Optional<DNSPacket> DNSPacket::from_raw_packet(const u8* raw_data, size_t raw_si dbgln("data=(unimplemented record type {})", record.type()); } dbgln_if(LOOKUPSERVER_DEBUG, "Answer #{}: name=_{}_, type={}, ttl={}, length={}, data=_{}_", i, name, record.type(), record.ttl(), record.data_length(), data); - packet.m_answers.empend(name, record.type(), record.record_class(), record.ttl(), data); + u16 class_code = record.record_class() & ~MDNS_CACHE_FLUSH; + bool mdns_cache_flush = record.record_class() & MDNS_CACHE_FLUSH; + packet.m_answers.empend(name, record.type(), class_code, record.ttl(), data, mdns_cache_flush); offset += record.data_length(); } diff --git a/Userland/Services/LookupServer/DNSQuestion.h b/Userland/Services/LookupServer/DNSQuestion.h index 870ceec9e0..dfe5826b55 100644 --- a/Userland/Services/LookupServer/DNSQuestion.h +++ b/Userland/Services/LookupServer/DNSQuestion.h @@ -11,23 +11,29 @@ namespace LookupServer { +#define MDNS_WANTS_UNICAST_RESPONSE 0x8000 + class DNSQuestion { public: - DNSQuestion(const DNSName& name, u16 record_type, u16 class_code) + DNSQuestion(const DNSName& name, u16 record_type, u16 class_code, bool mdns_wants_unicast_response) : m_name(name) , m_record_type(record_type) , m_class_code(class_code) + , m_mdns_wants_unicast_response(mdns_wants_unicast_response) { } u16 record_type() const { return m_record_type; } u16 class_code() const { return m_class_code; } + u16 raw_class_code() const { return (u16)m_class_code | (m_mdns_wants_unicast_response ? MDNS_WANTS_UNICAST_RESPONSE : 0); } const DNSName& name() const { return m_name; } + bool mdns_wants_unicast_response() const { return m_mdns_wants_unicast_response; } private: DNSName m_name; u16 m_record_type { 0 }; u16 m_class_code { 0 }; + bool m_mdns_wants_unicast_response { false }; }; } diff --git a/Userland/Services/LookupServer/LookupServer.cpp b/Userland/Services/LookupServer/LookupServer.cpp index 4e2da925d8..e20e775a36 100644 --- a/Userland/Services/LookupServer/LookupServer.cpp +++ b/Userland/Services/LookupServer/LookupServer.cpp @@ -75,7 +75,7 @@ void LookupServer::load_etc_hosts() m_etc_hosts.set(name, {}); it = m_etc_hosts.find(name); } - it->value.empend(name, record_type, (u16)C_IN, static_ttl, data); + it->value.empend(name, record_type, (u16)C_IN, static_ttl, data, false); }; auto file = Core::File::construct("/etc/hosts"); @@ -123,7 +123,8 @@ Vector<DNSAnswer> LookupServer::lookup(const DNSName& name, unsigned short recor answer.type(), answer.class_code(), answer.ttl(), - answer.record_data() + answer.record_data(), + answer.mdns_cache_flush(), }; answers.append(answer_with_original_case); }; @@ -197,7 +198,7 @@ Vector<DNSAnswer> LookupServer::lookup(const DNSName& name, const String& namese DNSName name_in_question = name; if (should_randomize_case == ShouldRandomizeCase::Yes) name_in_question.randomize_case(); - request.add_question({ name_in_question, record_type, C_IN }); + request.add_question({ name_in_question, record_type, C_IN, false }); auto buffer = request.to_byte_buffer(); diff --git a/Userland/Services/LookupServer/MulticastDNS.cpp b/Userland/Services/LookupServer/MulticastDNS.cpp index 768679af1a..4e903c74ed 100644 --- a/Userland/Services/LookupServer/MulticastDNS.cpp +++ b/Userland/Services/LookupServer/MulticastDNS.cpp @@ -88,9 +88,10 @@ void MulticastDNS::announce() DNSAnswer answer { m_hostname, T_A, - C_IN | 0x8000, + C_IN, 120, - String { (const char*)&raw_addr, sizeof(raw_addr) } + String { (const char*)&raw_addr, sizeof(raw_addr) }, + true, }; response.add_answer(answer); } @@ -141,7 +142,7 @@ Vector<DNSAnswer> MulticastDNS::lookup(const DNSName& name, unsigned short recor { DNSPacket request; request.set_is_query(); - request.add_question({ name, record_type, C_IN }); + request.add_question({ name, record_type, C_IN, false }); if (emit_packet(request) < 0) { perror("failed to emit request packet"); |