Skip to content

Commit

Permalink
add TXT, OPT, and options API
Browse files Browse the repository at this point in the history
  • Loading branch information
LEXUGE committed Jun 23, 2022
1 parent 03c8ed4 commit e60da5a
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 18 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions droute/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ futures = "^0.3"
tokio = { version = "^1", features = ["rt-multi-thread", "net", "fs", "macros", "io-util"]}

# Logic-related dependencies
hex = "^0.4"
rhai = { version = "1.7.0", features = ["sync", "no_closure", "no_float", "only_i32", "no_module"]}
compact_str = { version = "^0.3", features = ["serde"]}
cidr-utils = { version = "^0.5", git = "https://github.com/compassd/cidr-utils", rev = "c5f5c2ef167b4de9856764fd6b3b84e784b98db2" }
Expand Down
20 changes: 17 additions & 3 deletions droute/src/router/script/message/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use super::{MessageError, MessageResult as Result};
use bytes::Bytes;
use domain::{
base::{Dname, ParsedDname, Record, ToDname},
base::{opt::AllOptData, Dname, ParsedDname, Record, ToDname},
rdata::{
AllRecordData, Cname, Dname as DnameRecord, Mb, Md, Mf, Minfo, Mr, Mx, Ns, Nsec, Ptr,
Rrsig, Soa, Srv, Tsig,
Expand All @@ -25,8 +25,7 @@ use domain::{

pub type DnsRecord = Record<Dname<Bytes>, AllRecordData<Bytes, Dname<Bytes>>>;

// Missing Opt and Other
pub(super) fn from_ref(
pub(super) fn dns_record_from_ref(
src: AllRecordData<Bytes, ParsedDname<&Bytes>>,
) -> Result<AllRecordData<Bytes, Dname<Bytes>>> {
Ok(match src {
Expand Down Expand Up @@ -59,6 +58,8 @@ pub(super) fn from_ref(
AllRecordData::Nsec3(nsec3) => nsec3.into(),
AllRecordData::Nsec3param(nsec3param) => nsec3param.into(),
AllRecordData::Null(null) => null.into(),
AllRecordData::Opt(opt) => opt.into(),
AllRecordData::Other(other) => other.into(),
AllRecordData::Ptr(ptr) => AllRecordData::Ptr(Ptr::new(ptr.ptrdname().to_dname()?)),
AllRecordData::Rrsig(rrsig) => AllRecordData::Rrsig(Rrsig::new(
rrsig.type_covered(),
Expand Down Expand Up @@ -113,3 +114,16 @@ impl IntoIterator for DnsRecordsIter {
self.0.into_iter()
}
}

// An iterator over Opt records
#[derive(Clone)]
pub struct OptRecordsIter(pub Vec<AllOptData<Bytes>>);

impl IntoIterator for OptRecordsIter {
type Item = AllOptData<Bytes>;
type IntoIter = std::vec::IntoIter<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
Loading

0 comments on commit e60da5a

Please sign in to comment.