mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-11 17:42:02 +00:00
update hickory-proto (DNS parser)
Some checks failed
Push or PR / build_n_test (macos-latest) (push) Has been cancelled
Push or PR / build_n_test (ubuntu-latest) (push) Has been cancelled
Push or PR / build_n_test (windows-latest) (push) Has been cancelled
Push or PR / build_n_test_android (push) Has been cancelled
Push or PR / build_n_test_ios (push) Has been cancelled
Push or PR / Check semver (push) Has been cancelled
Integration Tests / Proxy Tests (push) Has been cancelled
Some checks failed
Push or PR / build_n_test (macos-latest) (push) Has been cancelled
Push or PR / build_n_test (ubuntu-latest) (push) Has been cancelled
Push or PR / build_n_test (windows-latest) (push) Has been cancelled
Push or PR / build_n_test_android (push) Has been cancelled
Push or PR / build_n_test_ios (push) Has been cancelled
Push or PR / Check semver (push) Has been cancelled
Integration Tests / Proxy Tests (push) Has been cancelled
This commit is contained in:
parent
a2399c8b28
commit
a380817951
3 changed files with 10 additions and 17 deletions
|
@ -36,7 +36,7 @@ digest_auth = "0.3"
|
|||
dotenvy = "0.15"
|
||||
env_logger = "0.11"
|
||||
hashlink = "0.10"
|
||||
hickory-proto = "0.24"
|
||||
hickory-proto = "0.25"
|
||||
httparse = "1"
|
||||
ipstack = { version = "0.2" }
|
||||
log = { version = "0.4", features = ["std"] }
|
||||
|
|
23
src/dns.rs
23
src/dns.rs
|
@ -1,21 +1,16 @@
|
|||
use hickory_proto::{
|
||||
op::{Message, MessageType, ResponseCode},
|
||||
rr::{Name, RData, Record, record_type::RecordType},
|
||||
rr::{
|
||||
Name, RData, Record,
|
||||
rdata::{A, AAAA},
|
||||
},
|
||||
};
|
||||
use std::{net::IpAddr, str::FromStr};
|
||||
|
||||
pub fn build_dns_response(mut request: Message, domain: &str, ip: IpAddr, ttl: u32) -> Result<Message, String> {
|
||||
let record = match ip {
|
||||
IpAddr::V4(ip) => {
|
||||
let mut record = Record::with(Name::from_str(domain)?, RecordType::A, ttl);
|
||||
record.set_data(Some(RData::A(ip.into())));
|
||||
record
|
||||
}
|
||||
IpAddr::V6(ip) => {
|
||||
let mut record = Record::with(Name::from_str(domain)?, RecordType::AAAA, ttl);
|
||||
record.set_data(Some(RData::AAAA(ip.into())));
|
||||
record
|
||||
}
|
||||
IpAddr::V4(ip) => Record::from_rdata(Name::from_str(domain)?, ttl, RData::A(A(ip))),
|
||||
IpAddr::V6(ip) => Record::from_rdata(Name::from_str(domain)?, ttl, RData::AAAA(AAAA(ip))),
|
||||
};
|
||||
|
||||
// We must indicate that this message is a response. Otherwise, implementations may not
|
||||
|
@ -27,9 +22,7 @@ pub fn build_dns_response(mut request: Message, domain: &str, ip: IpAddr, ttl: u
|
|||
}
|
||||
|
||||
pub fn remove_ipv6_entries(message: &mut Message) {
|
||||
message
|
||||
.answers_mut()
|
||||
.retain(|answer| !matches!(answer.data(), Some(RData::AAAA(_))));
|
||||
message.answers_mut().retain(|answer| !matches!(answer.data(), RData::AAAA(_)));
|
||||
}
|
||||
|
||||
pub fn extract_ipaddr_from_dns_message(message: &Message) -> Result<IpAddr, String> {
|
||||
|
@ -38,7 +31,7 @@ pub fn extract_ipaddr_from_dns_message(message: &Message) -> Result<IpAddr, Stri
|
|||
}
|
||||
let mut cname = None;
|
||||
for answer in message.answers() {
|
||||
match answer.data().ok_or("DNS response not contains answer data")? {
|
||||
match answer.data() {
|
||||
RData::A(addr) => {
|
||||
return Ok(IpAddr::V4((*addr).into()));
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ pub enum Error {
|
|||
IpStack(#[from] ipstack::IpStackError),
|
||||
|
||||
#[error("DnsProtoError {0:?}")]
|
||||
DnsProto(#[from] hickory_proto::error::ProtoError),
|
||||
DnsProto(#[from] hickory_proto::ProtoError),
|
||||
|
||||
#[error("httparse::Error {0:?}")]
|
||||
Httparse(#[from] httparse::Error),
|
||||
|
|
Loading…
Add table
Reference in a new issue