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

icmp redux #89

Merged
merged 5 commits into from
Apr 27, 2020
Merged

icmp redux #89

merged 5 commits into from
Apr 27, 2020

Conversation

drunkirishcoder
Copy link
Contributor

Description

Rework the ICMP API for both v4 and v6. This change makes ICMP extendable from outside the Capsule crate. Users can implement custom messages and work with them using the same public API as provided messages.

Type of change

  • Breaking change

Checklist

  • Associated tests
  • Associated documentation

@codecov
Copy link

codecov bot commented Apr 23, 2020

Codecov Report

Merging #89 into master will increase coverage by 6.96%.
The diff coverage is 83.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #89      +/-   ##
==========================================
+ Coverage   61.35%   68.31%   +6.96%     
==========================================
  Files          60       60              
  Lines        4270     4621     +351     
==========================================
+ Hits         2620     3157     +537     
+ Misses       1650     1464     -186     
Impacted Files Coverage Δ
core/src/packets/ip/mod.rs 53.84% <0.00%> (ø)
core/src/dpdk/mbuf.rs 86.72% <39.13%> (-0.42%) ⬇️
core/src/packets/icmp/v6/ndp/router_solicit.rs 64.10% <61.11%> (+10.76%) ⬆️
core/src/packets/tcp.rs 86.12% <70.00%> (ø)
core/src/packets/icmp/v6/ndp/neighbor_solicit.rs 72.00% <73.91%> (+58.66%) ⬆️
core/src/packets/ethernet.rs 88.57% <78.94%> (ø)
core/src/packets/ip/v6/mod.rs 87.73% <78.94%> (+1.22%) ⬆️
core/src/packets/ip/v6/srh.rs 89.34% <79.16%> (ø)
core/src/packets/udp.rs 93.37% <80.00%> (ø)
core/src/packets/icmp/v4/echo_reply.rs 80.82% <80.35%> (+74.37%) ⬆️
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 565c40e...1d8ea81. Read the comment docs.

Copy link
Member

@zeeshanlakhani zeeshanlakhani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly minor changes or q's that can resolved and ready for :shipit:.

core/src/packets/icmp/v4/mod.rs Outdated Show resolved Hide resolved
///
/// The trait is used for conversion between the generic [ICMPv4] packet
/// and the more specific messages. Implementors can use this trait to
/// add custom message types. This trait should not be used directly. Use
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used or imported directly?

/// which also derives the implementation for the [`Packet`] trait.
/// This trait should be used with `#[derive]`. The struct must manually
/// implement [`Icmpv4Message`] trait. `#[derive]` will also provide an
/// implementation of [`Packet`] trait for the struct as well.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need as well and also. Same goes for icmpv6packet derive info.

}

#[capsule::test]
fn push_and_set_echo_reply() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe as a separate, smaller test, you can showcase set_code from within a message type. No biggie, as it's own, but just to exercise the setting on some field like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neither echo request or reply should have non-0 code. so doesn't make sense to include. I've added set_code to v6 time exceeded test cuz that message type can have different codes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i meant generally, just picked this for ease. But yeah, as per slack discussion, we should just notate set_code's usefulness only in very specific situations/specs.

/// Prepends an ICMPv4 packet to the beginning of the IPv4's payload.
///
/// [`Ipv4::protocol`] is set to [`ProtocolNumbers::Icmpv4`].
/// Cannot push an ICMPv4 header without a message body. This function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: link to types (echorequest/reply) that are message types? (maybe wording can be updated here b/c those messages have "bodies" per se.

let _ = self.envelope_mut().truncate(IPV6_MIN_MTU);
self.compute_checksum();
pub fn data(&self) -> &[u8] {
let offset = self.payload_offset() + TimeExceededBody::size_of();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In seeing https://github.com/capsule-rs/capsule/pull/89/files#diff-1925ff5cfe7a1e975f1b9e48f02a21edR92, maybe it'd be nice for this and PacketTooBig to have "fns" for data_offset and data_len?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those are just private fns anyway. they are used in echo request/reply by both the getter and the setter. here they are only used once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah its' minor/fine. I was trying to think of how these data fns could be made general, but obviously, only certain types work w/ "data" payloads, not all of them.

@@ -108,8 +108,7 @@
//! [`skeleton`]: https://github.com/capsule-rs/capsule/tree/master/examples/skeleton
//! [`syn-flood`]: https://github.com/capsule-rs/capsule/tree/master/examples/syn-flood

// alias for the test macro
#[cfg(test)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -23,144 +23,93 @@ pub fn gen_icmpv6(input: syn::DeriveInput) -> TokenStream {
let name = input.ident;

let expanded = quote! {
impl<E: Ipv6Packet> crate::packets::icmp::v6::Icmpv6Packet<E, #name> for Icmpv6<E, #name> {
impl<E: ::capsule::packets::ip::v6::Ipv6Packet> ::capsule::packets::icmp::v6::Icmpv6Packet for #name<E> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -419,11 +434,34 @@ mod tests {
let packet = Mbuf::from_bytes(&ICMPV4_PACKET).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: @drunkirishcoder for setting a good example (of how to add tests), do we want parse tests for each message type specifically, pulling in more byte arrays from one of these places: https://cloudshark.io/articles/how-to-get-sample-captures/? Know it's tedious, but sets a good example for adding more protocols, and you did something good by adding all these push_and_set* tests :).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think parsing each type is that interesting or error prone. and some types like time exceeded and packet too big require a large payload to be defined, not ideal as byte arrays.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drunkirishcoder yeah. that's fine. I guess more so for setting a good example for adding new types in the future (at least for ones more manageable than timeexceeded etc..., especially b/c many sites now have various packet examples. No biggie otherwise.

core/src/packets/icmp/v6/mod.rs Show resolved Hide resolved
///
/// Not all code values are applicable to all message types. This setter
/// does not perform any validation. It's the caller's responsibility to
/// ensure that the value provided follows the spec.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@drunkirishcoder drunkirishcoder merged commit 3d2830b into master Apr 27, 2020
@drunkirishcoder drunkirishcoder deleted the djin/icmp-redux branch April 27, 2020 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants