1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

LookupServer: Implement a DNS server :^)

LookupServer can now itself server as a DNS server! To service DNS clients, it
uses the exact same lookup logic as it does for LibIPC clients. Namely, it will
synthesize records for data from /etc/hosts on its own (you can use this to
configure host names for your domain!), and forward other questions to
configured upstream DNS servers. On top of that, it implements its own caching,
so once a DNS resource record has been obtained from an upstream server,
LookupServer will cache it locally for faster future lookups.

The DNS server part of LookupServer is disabled by default, because it requires
you to run it as root (for it to bind to the port 53) and on boot, and we don't
want either by default. If you want to try it, modify SystemServer.ini like so:

[LookupServer]
Socket=/tmp/portal/lookup
SocketPermissions=666
Priority=low
KeepAlive=1
User=root
BootModes=text,graphical

and enable server mode in LookupServer.ini like so:

[DNS]
Nameservers=...
EnableServer=1

If in the future we implement socket takeover for IP sockets, these limitations
may be lifted.
This commit is contained in:
Sergey Bugaev 2021-02-14 17:24:23 +03:00 committed by Andreas Kling
parent bc05ab47de
commit 373d135e74
8 changed files with 145 additions and 2 deletions

View file

@ -44,6 +44,13 @@ void DNSPacket::add_question(const DNSQuestion& question)
ASSERT(m_questions.size() <= UINT16_MAX);
}
void DNSPacket::add_answer(const DNSAnswer& answer)
{
m_answers.empend(answer);
ASSERT(m_answers.size() <= UINT16_MAX);
}
ByteBuffer DNSPacket::to_byte_buffer() const
{
DNSPacketHeader header;
@ -54,6 +61,7 @@ ByteBuffer DNSPacket::to_byte_buffer() const
header.set_is_response();
// FIXME: What should this be?
header.set_opcode(0);
header.set_response_code(m_code);
header.set_truncated(false); // hopefully...
header.set_recursion_desired(true);
// FIXME: what should the be for requests?