From 115fd06f03df2df01768c909556ccef1cadc84ff Mon Sep 17 00:00:00 2001 From: Thibaut Vandervelden Date: Thu, 12 Sep 2024 14:52:10 +0200 Subject: [PATCH] No panic if no valid src addr for DNS query Don't panic if there is no valid source address for the DNS query. The state of the query is set to `Failed` instead and the query is abandoned. --- src/socket/dns.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/socket/dns.rs b/src/socket/dns.rs index 3b9fb6555..1e35270c8 100644 --- a/src/socket/dns.rs +++ b/src/socket/dns.rs @@ -612,7 +612,15 @@ impl<'a> Socket<'a> { }; let dst_addr = servers[pq.server_idx]; - let src_addr = cx.get_source_address(&dst_addr).unwrap(); // TODO remove unwrap + let src_addr = match cx.get_source_address(&dst_addr) { + Some(src_addr) => src_addr, + None => { + net_trace!("no source address for destination {}", dst_addr); + q.set_state(State::Failure); + continue; + } + }; + let ip_repr = IpRepr::new( src_addr, dst_addr,