Add DNS resolution to displayed flow IP addresses

This commit is contained in:
Herbert Wolverson 2023-03-31 17:10:43 +00:00
parent 9fce5d51de
commit 16721208e6
8 changed files with 48 additions and 3 deletions

14
src/rust/Cargo.lock generated
View File

@ -733,6 +733,18 @@ dependencies = [
"subtle",
]
[[package]]
name = "dns-lookup"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53ecafc952c4528d9b51a458d1a8904b81783feff9fde08ab6ed2545ff396872"
dependencies = [
"cfg-if",
"libc",
"socket2",
"winapi",
]
[[package]]
name = "either"
version = "1.8.1"
@ -1448,7 +1460,9 @@ name = "lqos_node_manager"
version = "0.1.0"
dependencies = [
"anyhow",
"dashmap",
"default-net",
"dns-lookup",
"jemallocator",
"lqos_bus",
"lqos_config",

View File

@ -19,6 +19,8 @@ sysinfo = "0"
default-net = "0"
nix = "0"
once_cell = "1"
dns-lookup = "1"
dashmap = "5"
# Support JemAlloc on supported platforms
[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dependencies]

View File

@ -77,6 +77,7 @@ fn rocket() -> _ {
queue_info::packet_dump,
queue_info::pcap,
queue_info::request_analysis,
queue_info::dns_query,
config_control::get_nic_list,
config_control::get_current_python_config,
config_control::get_current_lqosd_config,

View File

@ -1,6 +1,6 @@
use crate::auth_guard::AuthGuard;
use crate::cache_control::NoCache;
use crate::tracker::SHAPED_DEVICES;
use crate::tracker::{SHAPED_DEVICES, lookup_dns};
use lqos_bus::{bus_request, BusRequest, BusResponse, FlowTransport, PacketHeader, QueueStoreTransit};
use rocket::fs::NamedFile;
use rocket::http::Status;
@ -162,6 +162,15 @@ pub async fn pcap(id: usize, filename: String) -> Result<NoCache<NamedFile>, Sta
Err(Status::NotFound)
}
#[get("/api/dns/<ip>")]
pub async fn dns_query(ip: String) -> NoCache<String> {
if let Ok(ip) = ip.parse::<IpAddr>() {
NoCache::new(lookup_dns(ip))
} else {
NoCache::new(ip)
}
}
#[cfg(feature = "equinix_tests")]
#[get("/api/run_btest")]
pub async fn run_btest() -> NoCache<RawJson<String>> {

View File

@ -5,7 +5,9 @@
mod cpu_ram;
mod shaped_devices;
mod throughput;
mod dns_cache;
pub use cpu_ram::*;
pub use shaped_devices::*;
pub use throughput::THROUGHPUT_BUFFER;
pub use dns_cache::lookup_dns;

View File

@ -10,6 +10,7 @@ pub use cache::SHAPED_DEVICES;
pub use cache_manager::{update_tracking, update_total_throughput_buffer};
use lqos_bus::{bus_request, BusRequest, BusResponse, IpStats, TcHandle};
use rocket::serde::{Deserialize, Serialize, msgpack::MsgPack};
pub use cache::lookup_dns;
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(crate = "rocket::serde")]

View File

@ -813,13 +813,13 @@
}
html += "<tr>";
html += "<td>" + data[i][0][FlowTrans.proto] + "</td>";
html += "<td>" + data[i][0][FlowTrans.src] + "</td>";
html += "<td>" + ipToHostname(data[i][0][FlowTrans.src]) + "</td>";
if (data[i][0].proto == "ICMP") {
html += "<td>" + icmpType(data[i][0][FlowTrans.src_port]) + "</td>";
} else {
html += "<td>" + data[i][0][FlowTrans.src_port] + "</td>";
}
html += "<td>" + data[i][0][FlowTrans.dst] + "</td>";
html += "<td>" + ipToHostname(data[i][0][FlowTrans.dst]) + "</td>";
if (data[i][0][FlowTrans.proto] == "ICMP") {
if (data[i][1] != null) {
html += "<td>" + icmpType(data[i][1][FlowTrans.src_port]) + "</td>";

View File

@ -447,4 +447,20 @@ function zero_to_null(array) {
for (let i=0; i<array.length; ++i) {
if (array[i] == 0) array[i] = null;
}
}
var dnsCache = {};
function ipToHostname(ip) {
if (dnsCache.hasOwnProperty(ip)) {
if (dnsCache[ip] != ip) {
return ip + "<br /><span style='font-size: 6pt'>" + dnsCache[ip] + "</span>";
} else {
return ip;
}
}
$.get("/api/dns/" + encodeURI(ip), (hostname) => {
dnsCache[ip] = hostname;
})
return ip;
}