Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better handle dns #126

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading