0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-05 10:08:36 +02:00

modules/console: Add console command suite to view DNS caches.

This commit is contained in:
Jason Volk 2018-03-01 23:56:48 -08:00
parent d54d6b687c
commit 15ec746fc6

View file

@ -358,6 +358,7 @@ console_cmd__net(const string_view &line)
}
}
static bool console_cmd__net_host_cache(const string_view &line);
static bool console_cmd__net_host__default(const string_view &line);
bool
@ -370,6 +371,9 @@ console_cmd__net_host(const string_view &line)
switch(hash(token(line, " ", 0)))
{
case hash("cache"):
return console_cmd__net_host_cache(args);
default:
return console_cmd__net_host__default(line);
}
@ -377,6 +381,56 @@ console_cmd__net_host(const string_view &line)
return true;
}
bool
console_cmd__net_host_cache(const string_view &line)
{
switch(hash(token(line, " ", 0)))
{
case hash("A"):
{
for(const auto &pair : net::dns::cache.A)
{
const auto &host{pair.first};
const auto &record{pair.second};
const net::ipport ipp{record.ip4, 0};
out << std::setw(32) << host
<< " => " << ipp
<< " expires " << timestr(record.ttl, ircd::localtime)
<< " (" << record.ttl << ")"
<< std::endl;
}
return true;
}
case hash("SRV"):
{
for(const auto &pair : net::dns::cache.SRV)
{
const auto &key{pair.first};
const auto &record{pair.second};
const net::hostport hostport
{
record.tgt, record.port
};
out << std::setw(32) << key
<< " => " << hostport
<< " expires " << timestr(record.ttl, ircd::localtime)
<< " (" << record.ttl << ")"
<< std::endl;
}
return true;
}
default: throw bad_command
{
"Which cache?"
};
}
}
bool
console_cmd__net_host__default(const string_view &line)
{