-
Notifications
You must be signed in to change notification settings - Fork 425
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
Update high ResponseCode in EDNS Section if required #1265
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,8 @@ impl Message { | |
|
||
/// Returns a Message constructed with error details to return to a client | ||
/// | ||
/// If the `response_code` requires an EDNS section, this function creates one if not already present. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `id` - message id should match the request message id | ||
|
@@ -212,6 +214,9 @@ impl Message { | |
/// see `Header::set_response_code` | ||
pub fn set_response_code(&mut self, response_code: ResponseCode) -> &mut Self { | ||
self.header.set_response_code(response_code); | ||
if response_code.high() != 0 { | ||
self.edns_mut().set_rcode_high(response_code.high()); | ||
} | ||
self | ||
} | ||
|
||
|
@@ -508,11 +513,7 @@ impl Message { | |
|
||
/// If edns is_none, this will create a new default Edns. | ||
pub fn edns_mut(&mut self) -> &mut Edns { | ||
if self.edns.is_none() { | ||
self.edns = Some(Edns::new()); | ||
} | ||
|
||
self.edns.as_mut().unwrap() | ||
self.edns.get_or_insert_with(Edns::new) | ||
} | ||
|
||
/// # Return value | ||
|
@@ -589,7 +590,7 @@ impl Message { | |
query_count: self.queries.len(), | ||
answer_count: self.answers.len(), | ||
nameserver_count: self.name_servers.len(), | ||
additional_count: self.additionals.len(), | ||
additional_count: self.additionals.len() + if self.edns.is_some() { 1 } else { 0 }, | ||
}, | ||
); | ||
self | ||
|
@@ -1054,6 +1055,21 @@ fn test_emit_and_read_records() { | |
test_emit_and_read(message); | ||
} | ||
|
||
#[test] | ||
fn test_extended_response_code() { | ||
let mut message = Message::new(); | ||
message.set_response_code(ResponseCode::BADCOOKIE); | ||
message.update_counts(); | ||
test_emit_and_read(message); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests currently fail, since the reparsed message does not contain an additional entry whereas the original message does contain one. This is the OPT record for EDNS. Some feedback why parsing a Message removes the OPT record but correctly extracts the EDNS data would be appreciated. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds a little confusing, I'm not sure why that would be different. Is it possible there is an ordering issue on calculating the counts? One possibility is that some of the processing logic is dropping EDNS due to mishandling this particular ResponseCode or something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked at the PR again and now found that I probably need to call |
||
} | ||
|
||
#[test] | ||
fn test_extended_response_code_error() { | ||
let mut message = Message::error_msg(0, OpCode::Query, ResponseCode::BADVERS); | ||
message.update_counts(); | ||
test_emit_and_read(message); | ||
} | ||
|
||
#[cfg(test)] | ||
fn test_emit_and_read(message: Message) { | ||
let mut byte_vec: Vec<u8> = Vec::with_capacity(512); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDNS is converted to an additional record, but on the Rust side not represented as one. So the counts here are off if this is not accounted for.