LookupServer: Move DNS related code into new LibDNS library

This allows other code to use the DNSPacket class, e.g. when sent
over IPC.
This commit is contained in:
Tom 2022-04-12 23:25:07 -06:00 committed by Linus Groh
parent 0a92dbd390
commit be4a4144f2
17 changed files with 51 additions and 40 deletions

View file

@ -15,6 +15,7 @@ add_subdirectory(LibDesktop)
add_subdirectory(LibDeviceTree)
add_subdirectory(LibDiff)
add_subdirectory(LibDl)
add_subdirectory(LibDNS)
add_subdirectory(LibDSP)
add_subdirectory(LibEDID)
add_subdirectory(LibELF)

View file

@ -0,0 +1,8 @@
set(SOURCES
DNSAnswer.cpp
DNSName.cpp
DNSPacket.cpp
)
serenity_lib(LibDNS dns)
target_link_libraries(LibDNS LibC)

View file

@ -8,7 +8,7 @@
#include <AK/Stream.h>
#include <time.h>
namespace LookupServer {
namespace DNS {
DNSAnswer::DNSAnswer(DNSName const& name, DNSRecordType type, DNSRecordClass class_code, u32 ttl, String const& record_data, bool mdns_cache_flush)
: m_name(name)
@ -28,26 +28,26 @@ bool DNSAnswer::has_expired() const
}
ErrorOr<void> AK::Formatter<LookupServer::DNSRecordType>::format(AK::FormatBuilder& builder, LookupServer::DNSRecordType value)
ErrorOr<void> AK::Formatter<DNS::DNSRecordType>::format(AK::FormatBuilder& builder, DNS::DNSRecordType value)
{
switch (value) {
case LookupServer::DNSRecordType::A:
case DNS::DNSRecordType::A:
return builder.put_string("A");
case LookupServer::DNSRecordType::NS:
case DNS::DNSRecordType::NS:
return builder.put_string("NS");
case LookupServer::DNSRecordType::CNAME:
case DNS::DNSRecordType::CNAME:
return builder.put_string("CNAME");
case LookupServer::DNSRecordType::SOA:
case DNS::DNSRecordType::SOA:
return builder.put_string("SOA");
case LookupServer::DNSRecordType::PTR:
case DNS::DNSRecordType::PTR:
return builder.put_string("PTR");
case LookupServer::DNSRecordType::MX:
case DNS::DNSRecordType::MX:
return builder.put_string("MX");
case LookupServer::DNSRecordType::TXT:
case DNS::DNSRecordType::TXT:
return builder.put_string("TXT");
case LookupServer::DNSRecordType::AAAA:
case DNS::DNSRecordType::AAAA:
return builder.put_string("AAAA");
case LookupServer::DNSRecordType::SRV:
case DNS::DNSRecordType::SRV:
return builder.put_string("SRV");
}
@ -56,10 +56,10 @@ ErrorOr<void> AK::Formatter<LookupServer::DNSRecordType>::format(AK::FormatBuild
return {};
}
ErrorOr<void> AK::Formatter<LookupServer::DNSRecordClass>::format(AK::FormatBuilder& builder, LookupServer::DNSRecordClass value)
ErrorOr<void> AK::Formatter<DNS::DNSRecordClass>::format(AK::FormatBuilder& builder, DNS::DNSRecordClass value)
{
switch (value) {
case LookupServer::DNSRecordClass::IN:
case DNS::DNSRecordClass::IN:
return builder.put_string("IN");
}

View file

@ -11,7 +11,7 @@
#include <AK/String.h>
#include <AK/Types.h>
namespace LookupServer {
namespace DNS {
enum class DNSRecordType : u16 {
A = 1,
@ -58,23 +58,23 @@ private:
}
template<>
struct AK::Formatter<LookupServer::DNSRecordType> : StandardFormatter {
struct AK::Formatter<DNS::DNSRecordType> : StandardFormatter {
Formatter() = default;
explicit Formatter(StandardFormatter formatter)
: StandardFormatter(formatter)
{
}
ErrorOr<void> format(AK::FormatBuilder&, LookupServer::DNSRecordType);
ErrorOr<void> format(AK::FormatBuilder&, DNS::DNSRecordType);
};
template<>
struct AK::Formatter<LookupServer::DNSRecordClass> : StandardFormatter {
struct AK::Formatter<DNS::DNSRecordClass> : StandardFormatter {
Formatter() = default;
explicit Formatter(StandardFormatter formatter)
: StandardFormatter(formatter)
{
}
ErrorOr<void> format(AK::FormatBuilder&, LookupServer::DNSRecordClass);
ErrorOr<void> format(AK::FormatBuilder&, DNS::DNSRecordClass);
};

View file

@ -10,7 +10,7 @@
#include <AK/Vector.h>
#include <ctype.h>
namespace LookupServer {
namespace DNS {
DNSName::DNSName(String const& name)
{

View file

@ -10,7 +10,7 @@
#include <AK/Forward.h>
#include <AK/String.h>
namespace LookupServer {
namespace DNS {
class DNSName {
public:
@ -40,8 +40,8 @@ OutputStream& operator<<(OutputStream& stream, DNSName const&);
}
template<>
struct AK::Formatter<LookupServer::DNSName> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, LookupServer::DNSName const& value)
struct AK::Formatter<DNS::DNSName> : Formatter<StringView> {
ErrorOr<void> format(FormatBuilder& builder, DNS::DNSName const& value)
{
return Formatter<StringView>::format(builder, value.as_string());
}

View file

@ -14,7 +14,7 @@
#include <arpa/inet.h>
#include <stdlib.h>
namespace LookupServer {
namespace DNS {
void DNSPacket::add_question(DNSQuestion const& question)
{

View file

@ -13,7 +13,7 @@
#include <AK/Types.h>
#include <AK/Vector.h>
namespace LookupServer {
namespace DNS {
enum class ShouldRandomizeCase {
No = 0,

View file

@ -9,7 +9,7 @@
#include <AK/Endian.h>
#include <AK/Types.h>
namespace LookupServer {
namespace DNS {
class [[gnu::packed]] DNSPacketHeader {
public:

View file

@ -9,7 +9,7 @@
#include "DNSName.h"
#include <AK/Types.h>
namespace LookupServer {
namespace DNS {
#define MDNS_WANTS_UNICAST_RESPONSE 0x8000

View file

@ -8,9 +8,6 @@ compile_ipc(LookupServer.ipc LookupServerEndpoint.h)
compile_ipc(LookupClient.ipc LookupClientEndpoint.h)
set(SOURCES
DNSAnswer.cpp
DNSName.cpp
DNSPacket.cpp
DNSServer.cpp
LookupServer.cpp
LookupServerEndpoint.h
@ -21,4 +18,4 @@ set(SOURCES
)
serenity_bin(LookupServer)
target_link_libraries(LookupServer LibCore LibIPC LibMain)
target_link_libraries(LookupServer LibCore LibDNS LibIPC LibMain)

View file

@ -5,12 +5,14 @@
*/
#include "ConnectionFromClient.h"
#include "DNSPacket.h"
#include "LookupServer.h"
#include <AK/IPv4Address.h>
#include <LibDNS/DNSPacket.h>
namespace LookupServer {
using namespace DNS;
static HashMap<int, RefPtr<ConnectionFromClient>> s_connections;
ConnectionFromClient::ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket, int client_id)

View file

@ -5,12 +5,14 @@
*/
#include "DNSServer.h"
#include "DNSPacket.h"
#include "LookupServer.h"
#include <AK/IPv4Address.h>
#include <LibDNS/DNSPacket.h>
namespace LookupServer {
using namespace DNS;
DNSServer::DNSServer(Object* parent)
: Core::UDPServer(parent)
{

View file

@ -6,7 +6,6 @@
#include "LookupServer.h"
#include "ConnectionFromClient.h"
#include "DNSPacket.h"
#include <AK/Debug.h>
#include <AK/HashMap.h>
#include <AK/Random.h>
@ -16,6 +15,7 @@
#include <LibCore/File.h>
#include <LibCore/LocalServer.h>
#include <LibCore/Stream.h>
#include <LibDNS/DNSPacket.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>

View file

@ -7,17 +7,17 @@
#pragma once
#include "ConnectionFromClient.h"
#include "DNSName.h"
#include "DNSPacket.h"
#include "DNSServer.h"
#include "MulticastDNS.h"
#include <LibCore/FileWatcher.h>
#include <LibCore/Object.h>
#include <LibDNS/DNSName.h>
#include <LibDNS/DNSPacket.h>
#include <LibIPC/MultiServer.h>
namespace LookupServer {
class DNSAnswer;
using namespace DNS;
class LookupServer final : public Core::Object {
C_OBJECT(LookupServer);

View file

@ -5,7 +5,6 @@
*/
#include "MulticastDNS.h"
#include "DNSPacket.h"
#include <AK/IPv4Address.h>
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>

View file

@ -6,15 +6,17 @@
#pragma once
#include "DNSAnswer.h"
#include "DNSName.h"
#include "DNSPacket.h"
#include <AK/IPv4Address.h>
#include <LibCore/UDPServer.h>
#include <LibDNS/DNSAnswer.h>
#include <LibDNS/DNSName.h>
#include <LibDNS/DNSPacket.h>
#include <netinet/in.h>
namespace LookupServer {
using namespace DNS;
class MulticastDNS : public Core::UDPServer {
C_OBJECT(MulticastDNS)
public: