Skip to content

Commit

Permalink
better handle dns (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigbug authored Oct 18, 2023
1 parent 0c67dab commit 48266d1
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions clash_lib/src/app/dns/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl DnsHandler {
let mut m = Message::new();
m.set_op_code(request.op_code());
m.set_message_type(request.message_type());
m.set_recursion_desired(request.recursion_desired());
m.add_query(request.query().original().clone());
m.add_additionals(request.additionals().into_iter().map(Clone::clone));
m.add_name_servers(request.name_servers().into_iter().map(Clone::clone));
Expand All @@ -93,10 +94,20 @@ impl DnsHandler {
let mut rv =
builder.build(header, m.answers(), m.name_servers(), &[], m.additionals());

if let Some(edns) = m.extensions() {
rv.set_edns(edns.clone());
if let Some(edns) = request.edns() {
if edns.dnssec_ok() {
if let Some(edns) = m.extensions() {
rv.set_edns(edns.clone());
}
}
}

debug!(
"answering dns query {} with answer {:?}",
request.query().name(),
m.answers(),
);

Ok(response_handle.send_response(rv).await?)
}
Err(e) => {
Expand All @@ -115,9 +126,10 @@ impl RequestHandler for DnsHandler {
response_handle: R,
) -> ResponseInfo {
debug!(
"got dns request {}-{} from {}",
"got dns request [{}][{}][{}] from {}",
request.protocol(),
request.message_type(),
request.query().query_type(),
request.query().name(),
request.src()
);

Expand Down

0 comments on commit 48266d1

Please sign in to comment.