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

Mutate edns & remove edns options #1363

Merged
merged 4 commits into from Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/tests/server_harness/mut_message_client.rs
Expand Up @@ -36,7 +36,7 @@ impl<C: ClientHandle + Unpin> DnsHandle for MutMessageHandle<C> {
edns.set_dnssec_ok(true);

if let Some(supported_algs) = self.support_algorithms {
edns.set_option(EdnsOption::DAU(supported_algs));
edns.options_mut().insert(EdnsOption::DAU(supported_algs));
}
}

Expand Down
15 changes: 14 additions & 1 deletion crates/proto/src/op/edns.rs
Expand Up @@ -88,6 +88,11 @@ impl Edns {
&self.options
}

/// Returns a mutable options portion of EDNS
pub fn options_mut(&mut self) -> &mut OPT {
&mut self.options
}

/// Set the high order bits for the result code.
pub fn set_rcode_high(&mut self, rcode_high: u8) {
self.rcode_high = rcode_high
Expand All @@ -110,6 +115,7 @@ impl Edns {
}

/// Set the specified EDNS option
#[deprecated(note = "Please use options_mut().insert() to modify")]
pub fn set_option(&mut self, option: EdnsOption) {
self.options.insert(option);
}
Expand Down Expand Up @@ -215,7 +221,8 @@ fn test_encode_decode() {
edns.set_max_payload(0x8008);
edns.set_version(0x40);
edns.set_rcode_high(0x01);
edns.set_option(EdnsOption::DAU(SupportedAlgorithms::all()));
edns.options_mut()
.insert(EdnsOption::DAU(SupportedAlgorithms::all()));

let record: Record = (&edns).into();
let edns_decode: Edns = (&record).into();
Expand All @@ -225,4 +232,10 @@ fn test_encode_decode() {
assert_eq!(edns.version(), edns_decode.version());
assert_eq!(edns.rcode_high(), edns_decode.rcode_high());
assert_eq!(edns.options(), edns_decode.options());

// re-insert and remove using mut
edns.options_mut()
.insert(EdnsOption::DAU(SupportedAlgorithms::all()));
edns.options_mut().remove(EdnsCode::DAU);
assert!(edns.option(EdnsCode::DAU).is_none());
}
5 changes: 5 additions & 0 deletions crates/proto/src/rr/rdata/opt.rs
Expand Up @@ -195,6 +195,11 @@ impl OPT {
pub fn insert(&mut self, option: EdnsOption) {
self.options.insert((&option).into(), option);
}

/// Remove an option, the key is derived from the `EdnsOption`
pub fn remove(&mut self, option: EdnsCode) {
self.options.remove(&option);
}
}

/// Read the RData from the given Decoder
Expand Down
4 changes: 2 additions & 2 deletions crates/proto/src/xfer/dnssec_dns_handle.rs
Expand Up @@ -152,8 +152,8 @@ where
let dau = EdnsOption::DAU(algorithms);
let dhu = EdnsOption::DHU(algorithms);

edns.set_option(dau);
edns.set_option(dhu);
edns.options_mut().insert(dau);
edns.options_mut().insert(dhu);
}

request.set_authentic_data(true);
Expand Down
4 changes: 2 additions & 2 deletions crates/server/src/authority/catalog.rs
Expand Up @@ -59,8 +59,8 @@ fn send_response<R: ResponseHandler>(
let dau = EdnsOption::DAU(algorithms);
let dhu = EdnsOption::DHU(algorithms);

resp_edns.set_option(dau);
resp_edns.set_option(dhu);
resp_edns.options_mut().insert(dau);
resp_edns.options_mut().insert(dhu);

response.set_edns(resp_edns);
}
Expand Down