-
Notifications
You must be signed in to change notification settings - Fork 35
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
redo neighbor discovery option parsing API #94
Conversation
d832bab
to
7f7da41
Compare
2a46238
to
fffb6f0
Compare
Codecov Report
@@ Coverage Diff @@
## master #94 +/- ##
==========================================
+ Coverage 66.50% 67.05% +0.55%
==========================================
Files 60 62 +2
Lines 4621 5260 +639
==========================================
+ Hits 3073 3527 +454
- Misses 1548 1733 +185
Continue to review full report at Codecov.
|
fffb6f0
to
fb40e48
Compare
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.
First set of pretty minor comments. Will continue reviewing the finished redirect and ndp/options/mod once more.
@@ -80,14 +80,14 @@ impl<E: Ipv6Packet> PacketTooBig<E> { | |||
if let Ok(data) = self.icmp().mbuf().read_data_slice(offset, len) { | |||
unsafe { &*data.as_ptr() } | |||
} else { | |||
unreachable!() | |||
&[] |
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.
👍 the move here to an empty array of bytes.
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.
yeah unreachable!()
is quite dangerous. if it's hit for whatever reason, it's a runtime panic. did not realize that.
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.
oh, i could have told you that haha, but i thought it was unreachable
hah
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.
well, just to be extra safe. 😃
/// that describes how to run IP over the | ||
/// particular link type). *MAY* be sent on | ||
/// other links. | ||
/// - *MTU*: SHOULD be sent on links that have a variable MTU |
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.
seems like all possible options, in this PR, start their comment on the next line, but this one doesn't?
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.
it's all spacing. if the label is too long rather than widen the line with more tabs, they just start the description on the new line to keep the width more compact.
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.
I get that, but all the other options start on the next line, but not this one. Just popped out in review is all.
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.
right, 👍 I maintained the line breaks and spacing from the rfc.
core/src/packets/icmp/v6/ndp/mod.rs
Outdated
/// | ||
/// [`NdpOptions::iter`]: NdpOptions::iter | ||
#[inline] | ||
fn options(&self) -> ImmutableNdpOptionsIterator<'_> { |
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.
@drunkirishcoder didn't we mention the move to options_iter
here?
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.
yep and I forgot.
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.
super minor stuff w/ some questions attached that are more general comments.
core/Cargo.toml
Outdated
@@ -47,6 +46,7 @@ proptest = { version = "0.9", default-features = false, features = ["default-cod | |||
|
|||
[features] | |||
default = ["metrics"] | |||
compile_failure = [] |
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.
minor: maybe an internal comment about this feature?
let _ = self.mbuf.truncate(trim_to); | ||
} | ||
|
||
self.fields_mut().length = (len / 8) as u8; |
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.
double-checking: Rust's integer divide always floors the value. Guessing we're banking on that here instead of using the adjusted len after the trim?
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.
yes integer division floors. fairly sure on that, it's definitely not a float.
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.
It def floors.
assert_eq!(&data, header.data()); | ||
|
||
// this will truncate the extra data byte | ||
header.set_length(); |
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.
should we notate/comment that creating a packet doesn't explicitly update the length field, and that you have to call the set_length
function?
feel like we made this explicit in similar cases (srh?)? I could be wrong. I do know you mention it more generally here: https://github.com/capsule-rs/capsule/pull/94/files#diff-f5850ec0e4de1b426c07d3c990bf8b34R488.
} | ||
|
||
#[inline] | ||
fn reconcile(&mut self) { |
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.
other reconciles, (during our doctopia) received nice comments about what reconcile fn captures for that packet type. Can we do that here?
/// field in the Neighbor Solicitation message that | ||
/// prompted this advertisement. For an unsolicited | ||
/// advertisement, the address whose link-layer address | ||
/// has changed. The Target Address MUST NOT be a |
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.
minor: Goes for everything here, though I'm ok w/ reformatting away from italics (and bolds in some cases by accident?) for these cap MUSTS
, SHOULDS
, etc..., shouldn't we make this consistent across the other packet comments? I'm guessing it'll be inconsistent now.
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.
yeah they are just result of copy-pasta. we will get around to fix the rest of the doc eventually. I just wanted to trim them down some while I'm touching all the ndp stuff. it's somewhat arbitrary for now what's trimmed. didn't really touch the formatting much other than cutting down the sentences copied over. keeping enough to give you a rough idea what the fields represent but not too tmi.
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.
Yeah. Just formatting consistency is all.
|
||
/// Prepends a new option `T` at the beginning of the options. | ||
#[inline] | ||
pub fn prepend<'a, T: NdpOption<'a>>(&'a mut self) -> Fallible<T> { |
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.
i know we have tests below, but may example these?
|
||
/// Appends a new option `T` at the end of the options. | ||
#[inline] | ||
pub fn append<'a, T: NdpOption<'a>>(&'a mut self) -> Fallible<T> { |
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.
👆
/// In other words, remove all options `o` such that f(o) returns false. | ||
/// If an error occurs, all removals done prior to the error cannot be | ||
/// undone. | ||
pub fn retain<F>(&mut self, mut f: F) -> Fallible<()> |
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.
I'd say, def example doc retain at least (if you don't want to for prepend/append).
core/src/packets/icmp/v6/ndp/mod.rs
Outdated
} | ||
} | ||
|
||
/// A trait all NDP options must implement. |
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.
A trait that all
NdpOptionTypes::PrefixInformation => prefix = true, | ||
NdpOptionTypes::Mtu => mtu = true, | ||
NdpOptionTypes::SourceLinkLayerAddress => source = true, | ||
_ => other = true, |
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.
minor: do we notate anywhere, interior comment, that this other is an option we don't currently handle? Maybe just for posterity?
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.
think we decided to punt on anything involving length in 8 octets, right? With that, great work.
right punting on |
Co-authored-by: Zeeshan Lakhani <202820+zeeshanlakhani@users.noreply.github.com>
db927be
to
bcb70ef
Compare
Description
The new API offers better memory safety around the NDP options. The options cannot be mutated separate from the main NDP packet. Another fix included here is the ability to immutably read through the options. This is useful when used in combination with
Packet::peek
.Fixes #83
Type of change
Checklist