Skip to content

Commit

Permalink
enforce strict mutability around ndp options
Browse files Browse the repository at this point in the history
  • Loading branch information
drunkirishcoder committed May 11, 2020
1 parent a985a1d commit 6b0ab55
Show file tree
Hide file tree
Showing 22 changed files with 1,897 additions and 701 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 42,9 @@ test:
@pushd core && cargo test --all-targets --features full && popd
@cargo test --all-targets --workspace --exclude capsule

compile-failure:
@pushd core && cargo test --features compile_failure && popd

watch:
ifdef WATCH
@cargo watch --poll -x build -w $(WATCH)
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 25,6 @@ capsule-macros = { version = "0.1.3", path = "../macros" }
clap = "2.33"
criterion = { version = "0.3", optional = true }
failure = "0.1"
fallible-iterator = "0.2"
futures-preview = "=0.3.0-alpha.19"
libc = "0.2"
metrics-core = { version = "0.5", optional = true }
Expand All @@ -47,6 46,7 @@ proptest = { version = "0.9", default-features = false, features = ["default-cod

[features]
default = ["metrics"]
compile_failure = [] # compiler tests to check mutability rules are followed
full = ["metrics", "pcap-dump", "testils"]
metrics = ["metrics-core", "metrics-runtime"]
pcap-dump = []
Expand Down
6 changes: 3 additions & 3 deletions core/src/packets/icmp/v4/echo_reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,7 @@ use failure::Fallible;
use std::fmt;
use std::ptr::NonNull;

/// Echo Reply Message defined in [`IETF RFC 792`].
/// Echo Reply Message defined in [IETF RFC 792].
///
/// ```
/// 0 1 2 3
Expand All @@ -44,7 44,7 @@ use std::ptr::NonNull;
///
/// *Data*: The data from the invoking Echo Request message.
///
/// [`IETF RFC 792`]: https://tools.ietf.org/html/rfc792
/// [IETF RFC 792]: https://tools.ietf.org/html/rfc792
#[derive(Icmpv4Packet)]
pub struct EchoReply {
icmp: Icmpv4,
Expand Down Expand Up @@ -125,7 125,7 @@ impl EchoReply {

impl fmt::Debug for EchoReply {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("icmpv4")
f.debug_struct("EchoReply")
.field("type", &format!("{}", self.msg_type()))
.field("code", &self.code())
.field("checksum", &format!("0x{:04x}", self.checksum()))
Expand Down
6 changes: 3 additions & 3 deletions core/src/packets/icmp/v4/echo_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,7 @@ use failure::Fallible;
use std::fmt;
use std::ptr::NonNull;

/// Echo Request Message defined in [`IETF RFC 792`].
/// Echo Request Message defined in [IETF RFC 792].
///
/// ```
/// 0 1 2 3
Expand All @@ -45,7 45,7 @@ use std::ptr::NonNull;
///
/// *Data*: Zero or more octets of arbitrary data.
///
/// [`IETF RFC 792`]: https://tools.ietf.org/html/rfc792
/// [IETF RFC 792]: https://tools.ietf.org/html/rfc792
#[derive(Icmpv4Packet)]
pub struct EchoRequest {
icmp: Icmpv4,
Expand Down Expand Up @@ -126,7 126,7 @@ impl EchoRequest {

impl fmt::Debug for EchoRequest {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("icmpv4")
f.debug_struct("EchoRequest")
.field("type", &format!("{}", self.msg_type()))
.field("code", &self.code())
.field("checksum", &format!("0x{:04x}", self.checksum()))
Expand Down
12 changes: 6 additions & 6 deletions core/src/packets/icmp/v4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 33,7 @@ use failure::{Fail, Fallible};
use std::fmt;
use std::ptr::NonNull;

/// Internet Control Message Protocol v4 packet based on [`IETF RFC 792`].
/// Internet Control Message Protocol v4 packet based on [IETF RFC 792].
///
/// ```
/// 0 1 2 3
Expand Down Expand Up @@ -65,7 65,7 @@ use std::ptr::NonNull;
/// }
/// ```
///
/// [`IETF RFC 792`]: https://tools.ietf.org/html/rfc792
/// [IETF RFC 792]: https://tools.ietf.org/html/rfc792
/// [`Icmpv4Message`]: Icmpv4Message
pub struct Icmpv4 {
envelope: Ipv4,
Expand Down Expand Up @@ -266,14 266,14 @@ impl Icmpv4Type {
pub mod Icmpv4Types {
use super::Icmpv4Type;

/// Message type for [`Echo Request`].
/// Message type for [Echo Request].
///
/// [`Echo Request`]: crate::packets::icmp::v4::EchoRequest
/// [Echo Request]: crate::packets::icmp::v4::EchoRequest
pub const EchoRequest: Icmpv4Type = Icmpv4Type(8);

/// Message type for [`Echo Reply`].
/// Message type for [Echo Reply].
///
/// [`Echo Reply`]: crate::packets::icmp::v4::EchoReply
/// [Echo Reply]: crate::packets::icmp::v4::EchoReply
pub const EchoReply: Icmpv4Type = Icmpv4Type(0);
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/packets/icmp/v6/echo_reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 24,7 @@ use failure::Fallible;
use std::fmt;
use std::ptr::NonNull;

/// Echo Reply Message defined in [`IETF RFC 4443`].
/// Echo Reply Message defined in [IETF RFC 4443].
///
/// ```
/// 0 1 2 3
Expand All @@ -45,7 45,7 @@ use std::ptr::NonNull;
///
/// - *Data*: The data from the invoking Echo Request message.
///
/// [`IETF RFC 4443`]: https://tools.ietf.org/html/rfc4443#section-4.2
/// [IETF RFC 4443]: https://tools.ietf.org/html/rfc4443#section-4.2
#[derive(Icmpv6Packet)]
pub struct EchoReply<E: Ipv6Packet> {
icmp: Icmpv6<E>,
Expand Down Expand Up @@ -126,7 126,7 @@ impl<E: Ipv6Packet> EchoReply<E> {

impl<E: Ipv6Packet> fmt::Debug for EchoReply<E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("icmpv6")
f.debug_struct("EchoReply")
.field("type", &format!("{}", self.msg_type()))
.field("code", &self.code())
.field("checksum", &format!("0x{:04x}", self.checksum()))
Expand Down
6 changes: 3 additions & 3 deletions core/src/packets/icmp/v6/echo_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 24,7 @@ use failure::Fallible;
use std::fmt;
use std::ptr::NonNull;

/// Echo Request Message defined in [`IETF RFC 4443`].
/// Echo Request Message defined in [IETF RFC 4443].
///
/// ```
/// 0 1 2 3
Expand All @@ -46,7 46,7 @@ use std::ptr::NonNull;
///
/// - *Data*: Zero or more octets of arbitrary data.
///
/// [`IETF RFC 4443`]: https://tools.ietf.org/html/rfc4443#section-4.1
/// [IETF RFC 4443]: https://tools.ietf.org/html/rfc4443#section-4.1
#[derive(Icmpv6Packet)]
pub struct EchoRequest<E: Ipv6Packet> {
icmp: Icmpv6<E>,
Expand Down Expand Up @@ -127,7 127,7 @@ impl<E: Ipv6Packet> EchoRequest<E> {

impl<E: Ipv6Packet> fmt::Debug for EchoRequest<E> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("icmpv6")
f.debug_struct("EchoRequest")
.field("type", &format!("{}", self.msg_type()))
.field("code", &self.code())
.field("checksum", &format!("0x{:04x}", self.checksum()))
Expand Down
46 changes: 23 additions & 23 deletions core/src/packets/icmp/v6/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 38,7 @@ use failure::{Fail, Fallible};
use std::fmt;
use std::ptr::NonNull;

/// Internet Control Message Protocol v6 packet based on [`IETF RFC 4443`].
/// Internet Control Message Protocol v6 packet based on [IETF RFC 4443].
///
/// ```
/// 0 1 2 3
Expand Down Expand Up @@ -72,7 72,7 @@ use std::ptr::NonNull;
/// }
/// ```
///
/// [`IETF RFC 4443`]: https://tools.ietf.org/html/rfc4443
/// [IETF RFC 4443]: https://tools.ietf.org/html/rfc4443
/// [`Icmpv6Message`]: Icmpv6Message
pub struct Icmpv6<E: Ipv6Packet> {
envelope: E,
Expand Down Expand Up @@ -263,7 263,7 @@ impl<E: Ipv6Packet> Packet for Icmpv6<E> {
///
/// A list of supported types is under [`Icmpv6Types`].
///
/// [IANA]: https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml
/// [IANA]: https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-2
/// [`Icmpv6Types`]: Icmpv6Types
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
#[repr(C, packed)]
Expand All @@ -282,47 282,49 @@ impl Icmpv6Type {
pub mod Icmpv6Types {
use super::Icmpv6Type;

/// Message type for [`Packet Too Big`].
/// Message type for [Packet Too Big].
///
/// [`Packet Too Big`]: crate::packets::icmp::v6::PacketTooBig
/// [Packet Too Big]: crate::packets::icmp::v6::PacketTooBig
pub const PacketTooBig: Icmpv6Type = Icmpv6Type(2);

/// Message type for [`Time Exceeded`].
/// Message type for [Time Exceeded].
///
/// [`Time Exceeded`]: crate::packets::icmp::v6::TimeExceeded
/// [Time Exceeded]: crate::packets::icmp::v6::TimeExceeded
pub const TimeExceeded: Icmpv6Type = Icmpv6Type(3);

/// Message type for [`Echo Request`].
/// Message type for [Echo Request].
///
/// [`Echo Request`]: crate::packets::icmp::v6::EchoRequest
/// [Echo Request]: crate::packets::icmp::v6::EchoRequest
pub const EchoRequest: Icmpv6Type = Icmpv6Type(128);

/// Message type for [`Echo Reply`].
/// Message type for [Echo Reply].
///
/// [`Echo Reply`]: crate::packets::icmp::v6::EchoReply
/// [Echo Reply]: crate::packets::icmp::v6::EchoReply
pub const EchoReply: Icmpv6Type = Icmpv6Type(129);

/// Message type for [`Router Solicitation`].
/// Message type for [Router Solicitation].
///
/// [`Router Solicitation`]: crate::packets::icmp::v6::ndp::RouterSolicitation
/// [Router Solicitation]: crate::packets::icmp::v6::ndp::RouterSolicitation
pub const RouterSolicitation: Icmpv6Type = Icmpv6Type(133);

/// Message type for [`Router Advertisement`].
/// Message type for [Router Advertisement].
///
/// [`Router Advertisement`]: crate::packets::icmp::v6::ndp::RouterAdvertisement
/// [Router Advertisement]: crate::packets::icmp::v6::ndp::RouterAdvertisement
pub const RouterAdvertisement: Icmpv6Type = Icmpv6Type(134);

/// Message type for [`Neighbor Solicitation`].
/// Message type for [Neighbor Solicitation].
///
/// [`Neighbor Solicitation`]: crate::packets::icmp::v6::ndp::NeighborSolicitation
/// [Neighbor Solicitation]: crate::packets::icmp::v6::ndp::NeighborSolicitation
pub const NeighborSolicitation: Icmpv6Type = Icmpv6Type(135);

/// Message type for [`Neighbor Advertisement`].
/// Message type for [Neighbor Advertisement].
///
/// [`Neighbor Advertisement`]: crate::packets::icmp::v6::ndp::NeighborAdvertisement
/// [Neighbor Advertisement]: crate::packets::icmp::v6::ndp::NeighborAdvertisement
pub const NeighborAdvertisement: Icmpv6Type = Icmpv6Type(136);

/// Message type for `Redirect`.
/// Message type for [Redirect].
///
/// [Redirect]: crate::packets::icmp::v6::ndp::Redirect
pub const Redirect: Icmpv6Type = Icmpv6Type(137);
}

Expand Down Expand Up @@ -378,9 380,7 @@ pub trait Icmpv6Message {
/// The preceding packet type that encapsulates this message.
type Envelope: Ipv6Packet;

/// Returns the [IANA] assigned message type.
///
/// [IANA]: https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml
/// Returns the assigned message type.
fn msg_type() -> Icmpv6Type;

/// Returns a reference to the generic ICMPv6 packet.
Expand Down
Loading

0 comments on commit 6b0ab55

Please sign in to comment.